1.\" 2.\" $FreeBSD$ 3.\" 4.Dd August 9, 2004 5.Dt IPFW 8 6.Os 7.Sh NAME 8.Nm ipfw 9.Nd IP firewall and traffic shaper control program 10.Sh SYNOPSIS 11.Nm 12.Op Fl cq 13.Cm add 14.Ar rule 15.Nm 16.Op Fl acdefnNStT 17.Brq Cm list | show 18.Op Ar rule | first-last ... 19.Nm 20.Op Fl f | q 21.Cm flush 22.Nm 23.Op Fl q 24.Brq Cm delete | zero | resetlog 25.Op Cm set 26.Op Ar number ... 27.Nm 28.Cm enable 29.Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive 30.Nm 31.Cm disable 32.Brq Cm firewall | one_pass | debug | verbose | dyn_keepalive 33.Pp 34.Nm 35.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 36.Nm 37.Cm set move 38.Op Cm rule 39.Ar number Cm to Ar number 40.Nm 41.Cm set swap Ar number number 42.Nm 43.Cm set show 44.Pp 45.Nm 46.Cm table Ar number Cm add Ar addr Ns Oo / Ns Ar masklen Oc Op Ar value 47.Nm 48.Cm table Ar number Cm delete Ar addr Ns Op / Ns Ar masklen 49.Nm 50.Cm table Ar number Cm flush 51.Nm 52.Cm table Ar number Cm list 53.Pp 54.Nm 55.Brq Cm pipe | queue 56.Ar number 57.Cm config 58.Ar config-options 59.Nm 60.Op Fl s Op Ar field 61.Brq Cm pipe | queue 62.Brq Cm delete | list | show 63.Op Ar number ... 64.Pp 65.Nm 66.Op Fl cfnNqS 67.Oo 68.Fl p Ar preproc 69.Oo 70.Ar preproc-flags 71.Oc 72.Oc 73.Ar pathname 74.Sh DESCRIPTION 75The 76.Nm 77utility is the user interface for controlling the 78.Xr ipfw 4 79firewall and the 80.Xr dummynet 4 81traffic shaper in 82.Fx . 83.Pp 84.Bd -ragged -offset XXXX 85.Em NOTE: 86this manual page documents the newer version of 87.Nm 88introduced in 89.Fx 90CURRENT in July 2002, also known as 91.Nm ipfw2 . 92.Nm ipfw2 93is a superset of the old firewall, 94.Nm ipfw1 . 95The differences between the two are listed in Section 96.Sx IPFW2 ENHANCEMENTS , 97which you are encouraged to read to revise older rulesets and possibly 98write them more efficiently. 99See Section 100.Sx USING IPFW2 IN FreeBSD-STABLE 101for instructions on how to run 102.Nm ipfw2 103on 104.Fx 105STABLE. 106.Ed 107.Pp 108An 109.Nm 110configuration, or 111.Em ruleset , 112is made of a list of 113.Em rules 114numbered from 1 to 65535. 115Packets are passed to 116.Nm 117from a number of different places in the protocol stack 118(depending on the source and destination of the packet, 119it is possible that 120.Nm 121is invoked multiple times on the same packet). 122The packet passed to the firewall is compared 123against each of the rules in the firewall 124.Em ruleset . 125When a match is found, the action corresponding to the 126matching rule is performed. 127.Pp 128Depending on the action and certain system settings, packets 129can be reinjected into the firewall at some rule after the 130matching one for further processing. 131.Pp 132An 133.Nm 134ruleset always includes a 135.Em default 136rule (numbered 65535) which cannot be modified or deleted, 137and matches all packets. 138The action associated with the 139.Em default 140rule can be either 141.Cm deny 142or 143.Cm allow 144depending on how the kernel is configured. 145.Pp 146If the ruleset includes one or more rules with the 147.Cm keep-state 148or 149.Cm limit 150option, then 151.Nm 152assumes a 153.Em stateful 154behaviour, i.e., upon a match it will create dynamic rules matching 155the exact parameters (addresses and ports) of the matching packet. 156.Pp 157These dynamic rules, which have a limited lifetime, are checked 158at the first occurrence of a 159.Cm check-state , 160.Cm keep-state 161or 162.Cm limit 163rule, and are typically used to open the firewall on-demand to 164legitimate traffic only. 165See the 166.Sx STATEFUL FIREWALL 167and 168.Sx EXAMPLES 169Sections below for more information on the stateful behaviour of 170.Nm . 171.Pp 172All rules (including dynamic ones) have a few associated counters: 173a packet count, a byte count, a log count and a timestamp 174indicating the time of the last match. 175Counters can be displayed or reset with 176.Nm 177commands. 178.Pp 179Rules can be added with the 180.Cm add 181command; deleted individually or in groups with the 182.Cm delete 183command, and globally (except those in set 31) with the 184.Cm flush 185command; displayed, optionally with the content of the 186counters, using the 187.Cm show 188and 189.Cm list 190commands. 191Finally, counters can be reset with the 192.Cm zero 193and 194.Cm resetlog 195commands. 196.Pp 197Also, each rule belongs to one of 32 different 198.Em sets 199, and there are 200.Nm 201commands to atomically manipulate sets, such as enable, 202disable, swap sets, move all rules in a set to another 203one, delete all rules in a set. 204These can be useful to 205install temporary configurations, or to test them. 206See Section 207.Sx SETS OF RULES 208for more information on 209.Em sets . 210.Pp 211The following options are available: 212.Bl -tag -width indent 213.It Fl a 214While listing, show counter values. 215The 216.Cm show 217command just implies this option. 218.It Fl b 219Only show the action and the comment, not the body of a rule. 220Implies 221.Fl c . 222.It Fl c 223When entering or showing rules, print them in compact form, 224i.e., without the optional "ip from any to any" string 225when this does not carry any additional information. 226.It Fl d 227While listing, show dynamic rules in addition to static ones. 228.It Fl e 229While listing, if the 230.Fl d 231option was specified, also show expired dynamic rules. 232.It Fl f 233Don't ask for confirmation for commands that can cause problems 234if misused, 235.No i.e. Cm flush . 236If there is no tty associated with the process, this is implied. 237.It Fl n 238Only check syntax of the command strings, without actually passing 239them to the kernel. 240.It Fl N 241Try to resolve addresses and service names in output. 242.It Fl q 243While 244.Cm add Ns ing , 245.Cm zero Ns ing , 246.Cm resetlog Ns ging 247or 248.Cm flush Ns ing , 249be quiet about actions 250(implies 251.Fl f ) . 252This is useful for adjusting rules by executing multiple 253.Nm 254commands in a script 255(e.g., 256.Ql sh\ /etc/rc.firewall ) , 257or by processing a file of many 258.Nm 259rules across a remote login session. 260If a 261.Cm flush 262is performed in normal (verbose) mode (with the default kernel 263configuration), it prints a message. 264Because all rules are flushed, the message might not be delivered 265to the login session, causing the remote login session to be closed 266and the remainder of the ruleset to not be processed. 267Access to the console would then be required to recover. 268.It Fl S 269While listing rules, show the 270.Em set 271each rule belongs to. 272If this flag is not specified, disabled rules will not be 273listed. 274.It Fl s Op Ar field 275While listing pipes, sort according to one of the four 276counters (total or current packets or bytes). 277.It Fl t 278While listing, show last match timestamp (converted with ctime()). 279.It Fl T 280While listing, show last match timestamp (as seconds from the epoch). 281This form can be more convenient for postprocessing by scripts. 282.El 283.Pp 284To ease configuration, rules can be put into a file which is 285processed using 286.Nm 287as shown in the last synopsis line. 288An absolute 289.Ar pathname 290must be used. 291The file will be read line by line and applied as arguments to the 292.Nm 293utility. 294.Pp 295Optionally, a preprocessor can be specified using 296.Fl p Ar preproc 297where 298.Ar pathname 299is to be piped through. 300Useful preprocessors include 301.Xr cpp 1 302and 303.Xr m4 1 . 304If 305.Ar preproc 306doesn't start with a slash 307.Pq Ql / 308as its first character, the usual 309.Ev PATH 310name search is performed. 311Care should be taken with this in environments where not all 312file systems are mounted (yet) by the time 313.Nm 314is being run (e.g.\& when they are mounted over NFS). 315Once 316.Fl p 317has been specified, any additional arguments as passed on to the preprocessor 318for interpretation. 319This allows for flexible configuration files (like conditionalizing 320them on the local hostname) and the use of macros to centralize 321frequently required arguments like IP addresses. 322.Pp 323The 324.Nm 325.Cm pipe 326and 327.Cm queue 328commands are used to configure the traffic shaper, as shown in the 329.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 330Section below. 331.Pp 332If the world and the kernel get out of sync the 333.Nm 334ABI may break, preventing you from being able to add any rules. 335This can 336adversely effect the booting process. 337You can use 338.Nm 339.Cm disable 340.Cm firewall 341to temporarily disable the firewall to regain access to the network, 342allowing you to fix the problem. 343.Sh PACKET FLOW 344A packet is checked against the active ruleset in multiple places 345in the protocol stack, under control of several sysctl variables. 346These places and variables are shown below, and it is important to 347have this picture in mind in order to design a correct ruleset. 348.Bd -literal -offset indent 349 ^ to upper layers V 350 | | 351 +----------->-----------+ 352 ^ V 353 [ip_input] [ip_output] net.inet.ip.fw.enable=1 354 | | 355 ^ V 356[ether_demux] [ether_output_frame] net.link.ether.ipfw=1 357 | | 358 +-->--[bdg_forward]-->--+ net.link.ether.bridge_ipfw=1 359 ^ V 360 | to devices | 361.Ed 362.Pp 363As can be noted from the above picture, the number of 364times the same packet goes through the firewall can 365vary between 0 and 4 depending on packet source and 366destination, and system configuration. 367.Pp 368Note that as packets flow through the stack, headers can be 369stripped or added to it, and so they may or may not be available 370for inspection. 371E.g., incoming packets will include the MAC header when 372.Nm 373is invoked from 374.Cm ether_demux() , 375but the same packets will have the MAC header stripped off when 376.Nm 377is invoked from 378.Cm ip_input() . 379.Pp 380Also note that each packet is always checked against the complete ruleset, 381irrespective of the place where the check occurs, or the source of the packet. 382If a rule contains some match patterns or actions which are not valid 383for the place of invocation (e.g.\& trying to match a MAC header within 384.Cm ip_input() 385), the match pattern will not match, but a 386.Cm not 387operator in front of such patterns 388.Em will 389cause the pattern to 390.Em always 391match on those packets. 392It is thus the responsibility of 393the programmer, if necessary, to write a suitable ruleset to 394differentiate among the possible places. 395.Cm skipto 396rules can be useful here, as an example: 397.Bd -literal -offset indent 398# packets from ether_demux or bdg_forward 399ipfw add 10 skipto 1000 all from any to any layer2 in 400# packets from ip_input 401ipfw add 10 skipto 2000 all from any to any not layer2 in 402# packets from ip_output 403ipfw add 10 skipto 3000 all from any to any not layer2 out 404# packets from ether_output_frame 405ipfw add 10 skipto 4000 all from any to any layer2 out 406.Ed 407.Pp 408(yes, at the moment there is no way to differentiate between 409ether_demux and bdg_forward). 410.Sh SYNTAX 411In general, each keyword or argument must be provided as 412a separate command line argument, with no leading or trailing 413spaces. 414Keywords are case-sensitive, whereas arguments may 415or may not be case-sensitive depending on their nature 416(e.g.\& uid's are, hostnames are not). 417.Pp 418In 419.Nm ipfw2 420you can introduce spaces after commas ',' to make 421the line more readable. 422You can also put the entire 423command (including flags) into a single argument. 424E.g., the following forms are equivalent: 425.Bd -literal -offset indent 426ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8 427ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8 428ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8" 429.Ed 430.Sh RULE FORMAT 431The format of 432.Nm 433rules is the following: 434.Bd -ragged -offset indent 435.Op Ar rule_number 436.Op Cm set Ar set_number 437.Op Cm prob Ar match_probability 438.br 439.Ar " " action 440.Op Cm log Op Cm logamount Ar number 441.Ar body 442.Ed 443.Pp 444where the body of the rule specifies which information is used 445for filtering packets, among the following: 446.Pp 447.Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact 448.It Layer-2 header fields 449When available 450.It IPv4 Protocol 451TCP, UDP, ICMP, etc. 452.It Source and dest. addresses and ports 453.It Direction 454See Section 455.Sx PACKET FLOW 456.It Transmit and receive interface 457By name or address 458.It Misc. IP header fields 459Version, type of service, datagram length, identification, 460fragment flag (non-zero IP offset), 461Time To Live 462.It IP options 463.It Misc. TCP header fields 464TCP flags (SYN, FIN, ACK, RST, etc.), 465sequence number, acknowledgment number, 466window 467.It TCP options 468.It ICMP types 469for ICMP packets 470.It User/group ID 471When the packet can be associated with a local socket. 472.El 473.Pp 474Note that some of the above information, e.g.\& source MAC or IP addresses and 475TCP/UDP ports, could easily be spoofed, so filtering on those fields 476alone might not guarantee the desired results. 477.Bl -tag -width indent 478.It Ar rule_number 479Each rule is associated with a 480.Ar rule_number 481in the range 1..65535, with the latter reserved for the 482.Em default 483rule. 484Rules are checked sequentially by rule number. 485Multiple rules can have the same number, in which case they are 486checked (and listed) according to the order in which they have 487been added. 488If a rule is entered without specifying a number, the kernel will 489assign one in such a way that the rule becomes the last one 490before the 491.Em default 492rule. 493Automatic rule numbers are assigned by incrementing the last 494non-default rule number by the value of the sysctl variable 495.Ar net.inet.ip.fw.autoinc_step 496which defaults to 100. 497If this is not possible (e.g.\& because we would go beyond the 498maximum allowed rule number), the number of the last 499non-default value is used instead. 500.It Cm set Ar set_number 501Each rule is associated with a 502.Ar set_number 503in the range 0..31. 504Sets can be individually disabled and enabled, so this parameter 505is of fundamental importance for atomic ruleset manipulation. 506It can be also used to simplify deletion of groups of rules. 507If a rule is entered without specifying a set number, 508set 0 will be used. 509.br 510Set 31 is special in that it cannot be disabled, 511and rules in set 31 are not deleted by the 512.Nm ipfw flush 513command (but you can delete them with the 514.Nm ipfw delete set 31 515command). 516Set 31 is also used for the 517.Em default 518rule. 519.It Cm prob Ar match_probability 520A match is only declared with the specified probability 521(floating point number between 0 and 1). 522This can be useful for a number of applications such as 523random packet drop or 524(in conjunction with 525.Xr dummynet 4 ) 526to simulate the effect of multiple paths leading to out-of-order 527packet delivery. 528.Pp 529Note: this condition is checked before any other condition, including 530ones such as keep-state or check-state which might have side effects. 531.It Cm log Op Cm logamount Ar number 532When a packet matches a rule with the 533.Cm log 534keyword, a message will be 535logged to 536.Xr syslogd 8 537with a 538.Dv LOG_SECURITY 539facility. 540The logging only occurs if the sysctl variable 541.Em net.inet.ip.fw.verbose 542is set to 1 543(which is the default when the kernel is compiled with 544.Dv IPFIREWALL_VERBOSE 545) and the number of packets logged so far for that 546particular rule does not exceed the 547.Cm logamount 548parameter. 549If no 550.Cm logamount 551is specified, the limit is taken from the sysctl variable 552.Em net.inet.ip.fw.verbose_limit . 553In both cases, a value of 0 removes the logging limit. 554.Pp 555Once the limit is reached, logging can be re-enabled by 556clearing the logging counter or the packet counter for that entry, see the 557.Cm resetlog 558command. 559.Pp 560Note: logging is done after all other packet matching conditions 561have been successfully verified, and before performing the final 562action (accept, deny, etc.) on the packet. 563.El 564.Ss RULE ACTIONS 565A rule can be associated with one of the following actions, which 566will be executed when the packet matches the body of the rule. 567.Bl -tag -width indent 568.It Cm allow | accept | pass | permit 569Allow packets that match rule. 570The search terminates. 571.It Cm check-state 572Checks the packet against the dynamic ruleset. 573If a match is found, execute the action associated with 574the rule which generated this dynamic rule, otherwise 575move to the next rule. 576.br 577.Cm Check-state 578rules do not have a body. 579If no 580.Cm check-state 581rule is found, the dynamic ruleset is checked at the first 582.Cm keep-state 583or 584.Cm limit 585rule. 586.It Cm count 587Update counters for all packets that match rule. 588The search continues with the next rule. 589.It Cm deny | drop 590Discard packets that match this rule. 591The search terminates. 592.It Cm divert Ar port 593Divert packets that match this rule to the 594.Xr divert 4 595socket bound to port 596.Ar port . 597The search terminates. 598.It Cm fwd | forward Ar ipaddr Ns Op , Ns Ar port 599Change the next-hop on matching packets to 600.Ar ipaddr , 601which can be an IP address in dotted quad format or a host name. 602The search terminates if this rule matches. 603.Pp 604If 605.Ar ipaddr 606is a local address, then matching packets will be forwarded to 607.Ar port 608(or the port number in the packet if one is not specified in the rule) 609on the local machine. 610.br 611If 612.Ar ipaddr 613is not a local address, then the port number 614(if specified) is ignored, and the packet will be 615forwarded to the remote address, using the route as found in 616the local routing table for that IP. 617.br 618A 619.Ar fwd 620rule will not match layer-2 packets (those received 621on ether_input, ether_output, or bridged). 622.br 623The 624.Cm fwd 625action does not change the contents of the packet at all. 626In particular, the destination address remains unmodified, so 627packets forwarded to another system will usually be rejected by that system 628unless there is a matching rule on that system to capture them. 629For packets forwarded locally, 630the local address of the socket will be 631set to the original destination address of the packet. 632This makes the 633.Xr netstat 1 634entry look rather weird but is intended for 635use with transparent proxy servers. 636.It Cm pipe Ar pipe_nr 637Pass packet to a 638.Xr dummynet 4 639.Dq pipe 640(for bandwidth limitation, delay, etc.). 641See the 642.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 643Section for further information. 644The search terminates; however, on exit from the pipe and if 645the 646.Xr sysctl 8 647variable 648.Em net.inet.ip.fw.one_pass 649is not set, the packet is passed again to the firewall code 650starting from the next rule. 651.It Cm queue Ar queue_nr 652Pass packet to a 653.Xr dummynet 4 654.Dq queue 655(for bandwidth limitation using WF2Q+). 656.It Cm reject 657(Deprecated). 658Synonym for 659.Cm unreach host . 660.It Cm reset 661Discard packets that match this rule, and if the 662packet is a TCP packet, try to send a TCP reset (RST) notice. 663The search terminates. 664.It Cm skipto Ar number 665Skip all subsequent rules numbered less than 666.Ar number . 667The search continues with the first rule numbered 668.Ar number 669or higher. 670.It Cm tee Ar port 671Send a copy of packets matching this rule to the 672.Xr divert 4 673socket bound to port 674.Ar port . 675The search terminates and the original packet is accepted 676(but see Section 677.Sx BUGS 678below). 679.It Cm unreach Ar code 680Discard packets that match this rule, and try to send an ICMP 681unreachable notice with code 682.Ar code , 683where 684.Ar code 685is a number from 0 to 255, or one of these aliases: 686.Cm net , host , protocol , port , 687.Cm needfrag , srcfail , net-unknown , host-unknown , 688.Cm isolated , net-prohib , host-prohib , tosnet , 689.Cm toshost , filter-prohib , host-precedence 690or 691.Cm precedence-cutoff . 692The search terminates. 693.El 694.Ss RULE BODY 695The body of a rule contains zero or more patterns (such as 696specific source and destination addresses or ports, 697protocol options, incoming or outgoing interfaces, etc.) 698that the packet must match in order to be recognised. 699In general, the patterns are connected by (implicit) 700.Cm and 701operators -- i.e., all must match in order for the 702rule to match. 703Individual patterns can be prefixed by the 704.Cm not 705operator to reverse the result of the match, as in 706.Pp 707.Dl "ipfw add 100 allow ip from not 1.2.3.4 to any" 708.Pp 709Additionally, sets of alternative match patterns ( 710.Em or-blocks 711) can be constructed by putting the patterns in 712lists enclosed between parentheses ( ) or braces { }, and 713using the 714.Cm or 715operator as follows: 716.Pp 717.Dl "ipfw add 100 allow ip from { x or not y or z } to any" 718.Pp 719Only one level of parentheses is allowed. 720Beware that most shells have special meanings for parentheses 721or braces, so it is advisable to put a backslash \\ in front of them 722to prevent such interpretations. 723.Pp 724The body of a rule must in general include a source and destination 725address specifier. 726The keyword 727.Ar any 728can be used in various places to specify that the content of 729a required field is irrelevant. 730.Pp 731The rule body has the following format: 732.Bd -ragged -offset indent 733.Op Ar proto Cm from Ar src Cm to Ar dst 734.Op Ar options 735.Ed 736.Pp 737The first part (proto from src to dst) is for backward 738compatibility with 739.Nm ipfw1 . 740In 741.Nm ipfw2 742any match pattern (including MAC headers, IPv4 protocols, 743addresses and ports) can be specified in the 744.Ar options 745section. 746.Pp 747Rule fields have the following meaning: 748.Bl -tag -width indent 749.It Ar proto : protocol | Cm { Ar protocol Cm or ... } 750.It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number 751An IPv4 protocol specified by number or name 752(for a complete list see 753.Pa /etc/protocols ) . 754The 755.Cm ip 756or 757.Cm all 758keywords mean any protocol will match. 759.Pp 760The 761.Cm { Ar protocol Cm or ... } 762format (an 763.Em or-block ) 764is provided for convenience only but its use is deprecated. 765.It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports 766An address (or a list, see below) 767optionally followed by 768.Ar ports 769specifiers. 770.Pp 771The second format ( 772.Em or-block 773with multiple addresses) is provided for convenience only and 774its use is discouraged. 775.It Ar addr : Oo Cm not Oc Bro 776.Cm any | me | 777.Cm table Ns Pq Ar number Ns Op , Ns Ar value 778.Ar | addr-list | addr-set 779.Brc 780.It Cm any 781matches any IP address. 782.It Cm me 783matches any IP address configured on an interface in the system. 784The address list is evaluated at the time the packet is 785analysed. 786.It Cm table Ns Pq Ar number Ns Op , Ns Ar value 787Matches any IP address for which an entry exists in the lookup table 788.Ar number . 789If an optional 32-bit unsigned 790.Ar value 791is also specified, an entry will match only if it has this value. 792See the 793.Sx LOOKUP TABLES 794section below for more information on lookup tables. 795.It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list 796.It Ar ip-addr : 797A host or subnet address specified in one of the following ways: 798.Bl -tag -width indent 799.It Ar numeric-ip | hostname 800Matches a single IPv4 address, specified as dotted-quad or a hostname. 801Hostnames are resolved at the time the rule is added to the firewall list. 802.It Ar addr Ns / Ns Ar masklen 803Matches all addresses with base 804.Ar addr 805(specified as a dotted quad or a hostname) 806and mask width of 807.Cm masklen 808bits. 809As an example, 1.2.3.4/25 will match 810all IP numbers from 1.2.3.0 to 1.2.3.127 . 811.It Ar addr Ns : Ns Ar mask 812Matches all addresses with base 813.Ar addr 814(specified as a dotted quad or a hostname) 815and the mask of 816.Ar mask , 817specified as a dotted quad. 818As an example, 1.2.3.4:255.0.255.0 will match 8191.*.3.*. 820This form is advised only for non-contiguous 821masks. 822It is better to resort to the 823.Ar addr Ns / Ns Ar masklen 824format for contiguous masks, which is more compact and less 825error-prone. 826.El 827.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm } 828.It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list 829Matches all addresses with base address 830.Ar addr 831(specified as a dotted quad or a hostname) 832and whose last byte is in the list between braces { } . 833Note that there must be no spaces between braces and 834numbers (spaces after commas are allowed). 835Elements of the list can be specified as single entries 836or ranges. 837The 838.Ar masklen 839field is used to limit the size of the set of addresses, 840and can have any value between 24 and 32. 841If not specified, 842it will be assumed as 24. 843.br 844This format is particularly useful to handle sparse address sets 845within a single rule. 846Because the matching occurs using a 847bitmask, it takes constant time and dramatically reduces 848the complexity of rulesets. 849.br 850As an example, an address specified as 1.2.3.4/24{128,35-55,89} 851will match the following IP addresses: 852.br 8531.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 . 854.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports 855For protocols which support port numbers (such as TCP and UDP), optional 856.Cm ports 857may be specified as one or more ports or port ranges, separated 858by commas but no spaces, and an optional 859.Cm not 860operator. 861The 862.Ql \&- 863notation specifies a range of ports (including boundaries). 864.Pp 865Service names (from 866.Pa /etc/services ) 867may be used instead of numeric port values. 868The length of the port list is limited to 30 ports or ranges, 869though one can specify larger ranges by using an 870.Em or-block 871in the 872.Cm options 873section of the rule. 874.Pp 875A backslash 876.Pq Ql \e 877can be used to escape the dash 878.Pq Ql - 879character in a service name (from a shell, the backslash must be 880typed twice to avoid the shell itself interpreting it as an escape 881character). 882.Pp 883.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any" 884.Pp 885Fragmented packets which have a non-zero offset (i.e., not the first 886fragment) will never match a rule which has one or more port 887specifications. 888See the 889.Cm frag 890option for details on matching fragmented packets. 891.El 892.Ss RULE OPTIONS (MATCH PATTERNS) 893Additional match patterns can be used within 894rules. 895Zero or more of these so-called 896.Em options 897can be present in a rule, optionally prefixed by the 898.Cm not 899operand, and possibly grouped into 900.Em or-blocks . 901.Pp 902The following match patterns can be used (listed in alphabetical order): 903.Bl -tag -width indent 904.It Cm // this is a comment. 905Inserts the specified text as a comment in the rule. 906Everything following // is considered as a comment and stored in the rule. 907You can have comment-only rules, which are listed as having a 908.Cm count 909action followed by the comment. 910.It Cm bridged 911Matches only bridged packets. 912.It Cm dst-ip Ar ip-address 913Matches IP packets whose destination IP is one of the address(es) 914specified as argument. 915.It Cm dst-port Ar ports 916Matches IP packets whose destination port is one of the port(s) 917specified as argument. 918.It Cm established 919Matches TCP packets that have the RST or ACK bits set. 920.It Cm frag 921Matches packets that are fragments and not the first 922fragment of an IP datagram. 923Note that these packets will not have 924the next protocol header (e.g.\& TCP, UDP) so options that look into 925these headers cannot match. 926.It Cm gid Ar group 927Matches all TCP or UDP packets sent by or received for a 928.Ar group . 929A 930.Ar group 931may be specified by name or number. 932.It Cm jail Ar prisonID 933Matches all TCP or UDP packets sent by or received for the 934jail whos prison ID is 935.Ar prisonID . 936.It Cm icmptypes Ar types 937Matches ICMP packets whose ICMP type is in the list 938.Ar types . 939The list may be specified as any combination of 940individual types (numeric) separated by commas. 941.Em Ranges are not allowed. 942The supported ICMP types are: 943.Pp 944echo reply 945.Pq Cm 0 , 946destination unreachable 947.Pq Cm 3 , 948source quench 949.Pq Cm 4 , 950redirect 951.Pq Cm 5 , 952echo request 953.Pq Cm 8 , 954router advertisement 955.Pq Cm 9 , 956router solicitation 957.Pq Cm 10 , 958time-to-live exceeded 959.Pq Cm 11 , 960IP header bad 961.Pq Cm 12 , 962timestamp request 963.Pq Cm 13 , 964timestamp reply 965.Pq Cm 14 , 966information request 967.Pq Cm 15 , 968information reply 969.Pq Cm 16 , 970address mask request 971.Pq Cm 17 972and address mask reply 973.Pq Cm 18 . 974.It Cm in | out 975Matches incoming or outgoing packets, respectively. 976.Cm in 977and 978.Cm out 979are mutually exclusive (in fact, 980.Cm out 981is implemented as 982.Cm not in Ns No ). 983.It Cm ipid Ar id-list 984Matches IP packets whose 985.Cm ip_id 986field has value included in 987.Ar id-list , 988which is either a single value or a list of values or ranges 989specified in the same way as 990.Ar ports . 991.It Cm iplen Ar len-list 992Matches IP packets whose total length, including header and data, is 993in the set 994.Ar len-list , 995which is either a single value or a list of values or ranges 996specified in the same way as 997.Ar ports . 998.It Cm ipoptions Ar spec 999Matches packets whose IP header contains the comma separated list of 1000options specified in 1001.Ar spec . 1002The supported IP options are: 1003.Pp 1004.Cm ssrr 1005(strict source route), 1006.Cm lsrr 1007(loose source route), 1008.Cm rr 1009(record packet route) and 1010.Cm ts 1011(timestamp). 1012The absence of a particular option may be denoted 1013with a 1014.Ql \&! . 1015.It Cm ipprecedence Ar precedence 1016Matches IP packets whose precedence field is equal to 1017.Ar precedence . 1018.It Cm ipsec 1019Matches packets that have IPSEC history associated with them 1020(i.e., the packet comes encapsulated in IPSEC, the kernel 1021has IPSEC support and IPSEC_FILTERGIF option, and can correctly 1022decapsulate it). 1023.Pp 1024Note that specifying 1025.Cm ipsec 1026is different from specifying 1027.Cm proto Ar ipsec 1028as the latter will only look at the specific IP protocol field, 1029irrespective of IPSEC kernel support and the validity of the IPSEC data. 1030.Pp 1031Further note that this flag is silently ignored in kernels without 1032IPSEC support. 1033It does not affect rule processing when given and the 1034rules are handled as if with no 1035.Cm ipsec 1036flag. 1037.It Cm iptos Ar spec 1038Matches IP packets whose 1039.Cm tos 1040field contains the comma separated list of 1041service types specified in 1042.Ar spec . 1043The supported IP types of service are: 1044.Pp 1045.Cm lowdelay 1046.Pq Dv IPTOS_LOWDELAY , 1047.Cm throughput 1048.Pq Dv IPTOS_THROUGHPUT , 1049.Cm reliability 1050.Pq Dv IPTOS_RELIABILITY , 1051.Cm mincost 1052.Pq Dv IPTOS_MINCOST , 1053.Cm congestion 1054.Pq Dv IPTOS_CE . 1055The absence of a particular type may be denoted 1056with a 1057.Ql \&! . 1058.It Cm ipttl Ar ttl-list 1059Matches IP packets whose time to live is included in 1060.Ar ttl-list , 1061which is either a single value or a list of values or ranges 1062specified in the same way as 1063.Ar ports . 1064.It Cm ipversion Ar ver 1065Matches IP packets whose IP version field is 1066.Ar ver . 1067.It Cm keep-state 1068Upon a match, the firewall will create a dynamic rule, whose 1069default behaviour is to match bidirectional traffic between 1070source and destination IP/port using the same protocol. 1071The rule has a limited lifetime (controlled by a set of 1072.Xr sysctl 8 1073variables), and the lifetime is refreshed every time a matching 1074packet is found. 1075.It Cm layer2 1076Matches only layer2 packets, i.e., those passed to 1077.Nm 1078from ether_demux() and ether_output_frame(). 1079.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N 1080The firewall will only allow 1081.Ar N 1082connections with the same 1083set of parameters as specified in the rule. 1084One or more 1085of source and destination addresses and ports can be 1086specified. 1087.It Cm { MAC | mac } Ar dst-mac src-mac 1088Match packets with a given 1089.Ar dst-mac 1090and 1091.Ar src-mac 1092addresses, specified as the 1093.Cm any 1094keyword (matching any MAC address), or six groups of hex digits 1095separated by colons, 1096and optionally followed by a mask indicating the significant bits. 1097The mask may be specified using either of the following methods: 1098.Bl -enum -width indent 1099.It 1100A slash 1101.Pq / 1102followed by the number of significant bits. 1103For example, an address with 33 significant bits could be specified as: 1104.Pp 1105.Dl "MAC 10:20:30:40:50:60/33 any" 1106.Pp 1107.It 1108An ampersand 1109.Pq & 1110followed by a bitmask specified as six groups of hex digits separated 1111by colons. 1112For example, an address in which the last 16 bits are significant could 1113be specified as: 1114.Pp 1115.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any" 1116.Pp 1117Note that the ampersand character has a special meaning in many shells 1118and should generally be escaped. 1119.Pp 1120.El 1121Note that the order of MAC addresses (destination first, 1122source second) is 1123the same as on the wire, but the opposite of the one used for 1124IP addresses. 1125.It Cm mac-type Ar mac-type 1126Matches packets whose Ethernet Type field 1127corresponds to one of those specified as argument. 1128.Ar mac-type 1129is specified in the same way as 1130.Cm port numbers 1131(i.e., one or more comma-separated single values or ranges). 1132You can use symbolic names for known values such as 1133.Em vlan , ipv4, ipv6 . 1134Values can be entered as decimal or hexadecimal (if prefixed by 0x), 1135and they are always printed as hexadecimal (unless the 1136.Cm -N 1137option is used, in which case symbolic resolution will be attempted). 1138.It Cm proto Ar protocol 1139Matches packets with the corresponding IPv4 protocol. 1140.It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any 1141Matches packets received, transmitted or going through, 1142respectively, the interface specified by exact name 1143.Ns No ( Ar ifX Ns No ), 1144by device name 1145.Ns No ( Ar if Ns Ar * Ns No ), 1146by IP address, or through some interface. 1147.Pp 1148The 1149.Cm via 1150keyword causes the interface to always be checked. 1151If 1152.Cm recv 1153or 1154.Cm xmit 1155is used instead of 1156.Cm via , 1157then only the receive or transmit interface (respectively) 1158is checked. 1159By specifying both, it is possible to match packets based on 1160both receive and transmit interface, e.g.: 1161.Pp 1162.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1" 1163.Pp 1164The 1165.Cm recv 1166interface can be tested on either incoming or outgoing packets, 1167while the 1168.Cm xmit 1169interface can only be tested on outgoing packets. 1170So 1171.Cm out 1172is required (and 1173.Cm in 1174is invalid) whenever 1175.Cm xmit 1176is used. 1177.Pp 1178A packet may not have a receive or transmit interface: packets 1179originating from the local host have no receive interface, 1180while packets destined for the local host have no transmit 1181interface. 1182.It Cm setup 1183Matches TCP packets that have the SYN bit set but no ACK bit. 1184This is the short form of 1185.Dq Li tcpflags\ syn,!ack . 1186.It Cm src-ip Ar ip-address 1187Matches IP packets whose source IP is one of the address(es) 1188specified as argument. 1189.It Cm src-port Ar ports 1190Matches IP packets whose source port is one of the port(s) 1191specified as argument. 1192.It Cm tcpack Ar ack 1193TCP packets only. 1194Match if the TCP header acknowledgment number field is set to 1195.Ar ack . 1196.It Cm tcpflags Ar spec 1197TCP packets only. 1198Match if the TCP header contains the comma separated list of 1199flags specified in 1200.Ar spec . 1201The supported TCP flags are: 1202.Pp 1203.Cm fin , 1204.Cm syn , 1205.Cm rst , 1206.Cm psh , 1207.Cm ack 1208and 1209.Cm urg . 1210The absence of a particular flag may be denoted 1211with a 1212.Ql \&! . 1213A rule which contains a 1214.Cm tcpflags 1215specification can never match a fragmented packet which has 1216a non-zero offset. 1217See the 1218.Cm frag 1219option for details on matching fragmented packets. 1220.It Cm tcpseq Ar seq 1221TCP packets only. 1222Match if the TCP header sequence number field is set to 1223.Ar seq . 1224.It Cm tcpwin Ar win 1225TCP packets only. 1226Match if the TCP header window field is set to 1227.Ar win . 1228.It Cm tcpoptions Ar spec 1229TCP packets only. 1230Match if the TCP header contains the comma separated list of 1231options specified in 1232.Ar spec . 1233The supported TCP options are: 1234.Pp 1235.Cm mss 1236(maximum segment size), 1237.Cm window 1238(tcp window advertisement), 1239.Cm sack 1240(selective ack), 1241.Cm ts 1242(rfc1323 timestamp) and 1243.Cm cc 1244(rfc1644 t/tcp connection count). 1245The absence of a particular option may be denoted 1246with a 1247.Ql \&! . 1248.It Cm uid Ar user 1249Match all TCP or UDP packets sent by or received for a 1250.Ar user . 1251A 1252.Ar user 1253may be matched by name or identification number. 1254.It Cm verrevpath 1255For incoming packets, 1256a routing table lookup is done on the packet's source address. 1257If the interface on which the packet entered the system matches the 1258outgoing interface for the route, 1259the packet matches. 1260If the interfaces do not match up, 1261the packet does not match. 1262All outgoing packets or packets with no incoming interface match. 1263.Pp 1264The name and functionality of the option is intentionally similar to 1265the Cisco IOS command: 1266.Pp 1267.Dl ip verify unicast reverse-path 1268.Pp 1269This option can be used to make anti-spoofing rules to reject all 1270packets with source addresses not from this interface. 1271See also the option 1272.Cm antispoof . 1273.It Cm versrcreach 1274For incoming packets, 1275a routing table lookup is done on the packet's source address. 1276If a route to the source address exists, but not the default route 1277or a blackhole/reject route, the packet matches. 1278Otherwise, the packet does not match. 1279All outgoing packets match. 1280.Pp 1281The name and functionality of the option is intentionally similar to 1282the Cisco IOS command: 1283.Pp 1284.Dl ip verify unicast source reachable-via any 1285.Pp 1286This option can be used to make anti-spoofing rules to reject all 1287packets whose source address is unreachable. 1288.It Cm antispoof 1289For incoming packets, the packet's source address is checked if it 1290belongs to a directly connected network. 1291If the network is directly connected, then the interface the packet 1292came on in is compared to the interface the network is connected to. 1293When incoming interface and directly connected interface are not the 1294same, the packet does not match. 1295Otherwise, the packet does match. 1296All outgoing packets match. 1297.Pp 1298This option can be used to make anti-spoofing rules to reject all 1299packets that pretend to be from a directly connected network but do 1300not come in through that interface. 1301This option is similar to but more restricted than 1302.Cm verrevpath 1303because it engages only on packets with source addresses of directly 1304connected networks instead of all source addresses. 1305.El 1306.Sh LOOKUP TABLES 1307Lookup tables are useful to handle large sparse address sets, 1308typically from a hundred to several thousands of entries. 1309There could be 128 different lookup tables, numbered 0 to 127. 1310.Pp 1311Each entry is represented by an 1312.Ar addr Ns Op / Ns Ar masklen 1313and will match all addresses with base 1314.Ar addr 1315(specified as a dotted quad or a hostname) 1316and mask width of 1317.Ar masklen 1318bits. 1319If 1320.Ar masklen 1321is not specified, it defaults to 32. 1322When looking up an IP address in a table, the most specific 1323entry will match. 1324Associated with each entry is a 32-bit unsigned 1325.Ar value , 1326which can optionally be checked by a rule matching code. 1327When adding an entry, if 1328.Ar value 1329is not specified, it defaults to 0. 1330.Pp 1331An entry can be added to a table 1332.Pq Cm add , 1333removed from a table 1334.Pq Cm delete , 1335a table can be examined 1336.Pq Cm list 1337or flushed 1338.Pq Cm flush . 1339.Pp 1340Internally, each table is stored in a Radix tree, the same way as 1341the routing table (see 1342.Xr route 4 ) . 1343.Sh SETS OF RULES 1344Each rule belongs to one of 32 different 1345.Em sets 1346, numbered 0 to 31. 1347Set 31 is reserved for the default rule. 1348.Pp 1349By default, rules are put in set 0, unless you use the 1350.Cm set N 1351attribute when entering a new rule. 1352Sets can be individually and atomically enabled or disabled, 1353so this mechanism permits an easy way to store multiple configurations 1354of the firewall and quickly (and atomically) switch between them. 1355The command to enable/disable sets is 1356.Bd -ragged -offset indent 1357.Nm 1358.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 1359.Ed 1360.Pp 1361where multiple 1362.Cm enable 1363or 1364.Cm disable 1365sections can be specified. 1366Command execution is atomic on all the sets specified in the command. 1367By default, all sets are enabled. 1368.Pp 1369When you disable a set, its rules behave as if they do not exist 1370in the firewall configuration, with only one exception: 1371.Bd -ragged -offset indent 1372dynamic rules created from a rule before it had been disabled 1373will still be active until they expire. 1374In order to delete 1375dynamic rules you have to explicitly delete the parent rule 1376which generated them. 1377.Ed 1378.Pp 1379The set number of rules can be changed with the command 1380.Bd -ragged -offset indent 1381.Nm 1382.Cm set move 1383.Brq Cm rule Ar rule-number | old-set 1384.Cm to Ar new-set 1385.Ed 1386.Pp 1387Also, you can atomically swap two rulesets with the command 1388.Bd -ragged -offset indent 1389.Nm 1390.Cm set swap Ar first-set second-set 1391.Ed 1392.Pp 1393See the 1394.Sx EXAMPLES 1395Section on some possible uses of sets of rules. 1396.Sh STATEFUL FIREWALL 1397Stateful operation is a way for the firewall to dynamically 1398create rules for specific flows when packets that 1399match a given pattern are detected. 1400Support for stateful 1401operation comes through the 1402.Cm check-state , keep-state 1403and 1404.Cm limit 1405options of 1406.Nm rules. 1407.Pp 1408Dynamic rules are created when a packet matches a 1409.Cm keep-state 1410or 1411.Cm limit 1412rule, causing the creation of a 1413.Em dynamic 1414rule which will match all and only packets with 1415a given 1416.Em protocol 1417between a 1418.Em src-ip/src-port dst-ip/dst-port 1419pair of addresses ( 1420.Em src 1421and 1422.Em dst 1423are used here only to denote the initial match addresses, but they 1424are completely equivalent afterwards). 1425Dynamic rules will be checked at the first 1426.Cm check-state, keep-state 1427or 1428.Cm limit 1429occurrence, and the action performed upon a match will be the same 1430as in the parent rule. 1431.Pp 1432Note that no additional attributes other than protocol and IP addresses 1433and ports are checked on dynamic rules. 1434.Pp 1435The typical use of dynamic rules is to keep a closed firewall configuration, 1436but let the first TCP SYN packet from the inside network install a 1437dynamic rule for the flow so that packets belonging to that session 1438will be allowed through the firewall: 1439.Pp 1440.Dl "ipfw add check-state" 1441.Dl "ipfw add allow tcp from my-subnet to any setup keep-state" 1442.Dl "ipfw add deny tcp from any to any" 1443.Pp 1444A similar approach can be used for UDP, where an UDP packet coming 1445from the inside will install a dynamic rule to let the response through 1446the firewall: 1447.Pp 1448.Dl "ipfw add check-state" 1449.Dl "ipfw add allow udp from my-subnet to any keep-state" 1450.Dl "ipfw add deny udp from any to any" 1451.Pp 1452Dynamic rules expire after some time, which depends on the status 1453of the flow and the setting of some 1454.Cm sysctl 1455variables. 1456See Section 1457.Sx SYSCTL VARIABLES 1458for more details. 1459For TCP sessions, dynamic rules can be instructed to periodically 1460send keepalive packets to refresh the state of the rule when it is 1461about to expire. 1462.Pp 1463See Section 1464.Sx EXAMPLES 1465for more examples on how to use dynamic rules. 1466.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 1467.Nm 1468is also the user interface for the 1469.Xr dummynet 4 1470traffic shaper. 1471.Pp 1472.Nm dummynet 1473operates by first using the firewall to classify packets and divide them into 1474.Em flows , 1475using any match pattern that can be used in 1476.Nm 1477rules. 1478Depending on local policies, a flow can contain packets for a single 1479TCP connection, or from/to a given host, or entire subnet, or a 1480protocol type, etc. 1481.Pp 1482Packets belonging to the same flow are then passed to either of two 1483different objects, which implement the traffic regulation: 1484.Bl -hang -offset XXXX 1485.It Em pipe 1486A pipe emulates a link with given bandwidth, propagation delay, 1487queue size and packet loss rate. 1488Packets are queued in front of the pipe as they come out from the classifier, 1489and then transferred to the pipe according to the pipe's parameters. 1490.Pp 1491.It Em queue 1492A queue 1493is an abstraction used to implement the WF2Q+ 1494(Worst-case Fair Weighted Fair Queueing) policy, which is 1495an efficient variant of the WFQ policy. 1496.br 1497The queue associates a 1498.Em weight 1499and a reference pipe to each flow, and then all backlogged (i.e., 1500with packets queued) flows linked to the same pipe share the pipe's 1501bandwidth proportionally to their weights. 1502Note that weights are not priorities; a flow with a lower weight 1503is still guaranteed to get its fraction of the bandwidth even if a 1504flow with a higher weight is permanently backlogged. 1505.Pp 1506.El 1507In practice, 1508.Em pipes 1509can be used to set hard limits to the bandwidth that a flow can use, whereas 1510.Em queues 1511can be used to determine how different flow share the available bandwidth. 1512.Pp 1513The 1514.Em pipe 1515and 1516.Em queue 1517configuration commands are the following: 1518.Bd -ragged -offset indent 1519.Cm pipe Ar number Cm config Ar pipe-configuration 1520.Pp 1521.Cm queue Ar number Cm config Ar queue-configuration 1522.Ed 1523.Pp 1524The following parameters can be configured for a pipe: 1525.Pp 1526.Bl -tag -width indent -compact 1527.It Cm bw Ar bandwidth | device 1528Bandwidth, measured in 1529.Sm off 1530.Op Cm K | M 1531.Brq Cm bit/s | Byte/s . 1532.Sm on 1533.Pp 1534A value of 0 (default) means unlimited bandwidth. 1535The unit must immediately follow the number, as in 1536.Pp 1537.Dl "ipfw pipe 1 config bw 300Kbit/s" 1538.Pp 1539If a device name is specified instead of a numeric value, as in 1540.Pp 1541.Dl "ipfw pipe 1 config bw tun0" 1542.Pp 1543then the transmit clock is supplied by the specified device. 1544At the moment only the 1545.Xr tun 4 1546device supports this 1547functionality, for use in conjunction with 1548.Xr ppp 8 . 1549.Pp 1550.It Cm delay Ar ms-delay 1551Propagation delay, measured in milliseconds. 1552The value is rounded to the next multiple of the clock tick 1553(typically 10ms, but it is a good practice to run kernels 1554with 1555.Dq "options HZ=1000" 1556to reduce 1557the granularity to 1ms or less). 1558Default value is 0, meaning no delay. 1559.El 1560.Pp 1561The following parameters can be configured for a queue: 1562.Pp 1563.Bl -tag -width indent -compact 1564.It Cm pipe Ar pipe_nr 1565Connects a queue to the specified pipe. 1566Multiple queues (with the same or different weights) can be connected to 1567the same pipe, which specifies the aggregate rate for the set of queues. 1568.Pp 1569.It Cm weight Ar weight 1570Specifies the weight to be used for flows matching this queue. 1571The weight must be in the range 1..100, and defaults to 1. 1572.El 1573.Pp 1574Finally, the following parameters can be configured for both 1575pipes and queues: 1576.Pp 1577.Bl -tag -width XXXX -compact 1578.Pp 1579.It Cm buckets Ar hash-table-size 1580Specifies the size of the hash table used for storing the 1581various queues. 1582Default value is 64 controlled by the 1583.Xr sysctl 8 1584variable 1585.Em net.inet.ip.dummynet.hash_size , 1586allowed range is 16 to 65536. 1587.Pp 1588.It Cm mask Ar mask-specifier 1589Packets sent to a given pipe or queue by an 1590.Nm 1591rule can be further classified into multiple flows, each of which is then 1592sent to a different 1593.Em dynamic 1594pipe or queue. 1595A flow identifier is constructed by masking the IP addresses, 1596ports and protocol types as specified with the 1597.Cm mask 1598options in the configuration of the pipe or queue. 1599For each different flow identifier, a new pipe or queue is created 1600with the same parameters as the original object, and matching packets 1601are sent to it. 1602.Pp 1603Thus, when 1604.Em dynamic pipes 1605are used, each flow will get the same bandwidth as defined by the pipe, 1606whereas when 1607.Em dynamic queues 1608are used, each flow will share the parent's pipe bandwidth evenly 1609with other flows generated by the same queue (note that other queues 1610with different weights might be connected to the same pipe). 1611.br 1612Available mask specifiers are a combination of one or more of the following: 1613.Pp 1614.Cm dst-ip Ar mask , 1615.Cm src-ip Ar mask , 1616.Cm dst-port Ar mask , 1617.Cm src-port Ar mask , 1618.Cm proto Ar mask 1619or 1620.Cm all , 1621.Pp 1622where the latter means all bits in all fields are significant. 1623.Pp 1624.It Cm noerror 1625When a packet is dropped by a dummynet queue or pipe, the error 1626is normally reported to the caller routine in the kernel, in the 1627same way as it happens when a device queue fills up. 1628Setting this 1629option reports the packet as successfully delivered, which can be 1630needed for some experimental setups where you want to simulate 1631loss or congestion at a remote router. 1632.Pp 1633.It Cm plr Ar packet-loss-rate 1634Packet loss rate. 1635Argument 1636.Ar packet-loss-rate 1637is a floating-point number between 0 and 1, with 0 meaning no 1638loss, 1 meaning 100% loss. 1639The loss rate is internally represented on 31 bits. 1640.Pp 1641.It Cm queue Brq Ar slots | size Ns Cm Kbytes 1642Queue size, in 1643.Ar slots 1644or 1645.Cm KBytes . 1646Default value is 50 slots, which 1647is the typical queue size for Ethernet devices. 1648Note that for slow speed links you should keep the queue 1649size short or your traffic might be affected by a significant 1650queueing delay. 1651E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit 1652or 20s of queue on a 30Kbit/s pipe. 1653Even worse effects can result if you get packets from an 1654interface with a much larger MTU, e.g.\& the loopback interface 1655with its 16KB packets. 1656.Pp 1657.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p 1658Make use of the RED (Random Early Detection) queue management algorithm. 1659.Ar w_q 1660and 1661.Ar max_p 1662are floating 1663point numbers between 0 and 1 (0 not included), while 1664.Ar min_th 1665and 1666.Ar max_th 1667are integer numbers specifying thresholds for queue management 1668(thresholds are computed in bytes if the queue has been defined 1669in bytes, in slots otherwise). 1670The 1671.Xr dummynet 4 1672also supports the gentle RED variant (gred). 1673Three 1674.Xr sysctl 8 1675variables can be used to control the RED behaviour: 1676.Bl -tag -width indent 1677.It Em net.inet.ip.dummynet.red_lookup_depth 1678specifies the accuracy in computing the average queue 1679when the link is idle (defaults to 256, must be greater than zero) 1680.It Em net.inet.ip.dummynet.red_avg_pkt_size 1681specifies the expected average packet size (defaults to 512, must be 1682greater than zero) 1683.It Em net.inet.ip.dummynet.red_max_pkt_size 1684specifies the expected maximum packet size, only used when queue 1685thresholds are in bytes (defaults to 1500, must be greater than zero). 1686.El 1687.El 1688.Sh CHECKLIST 1689Here are some important points to consider when designing your 1690rules: 1691.Bl -bullet 1692.It 1693Remember that you filter both packets going 1694.Cm in 1695and 1696.Cm out . 1697Most connections need packets going in both directions. 1698.It 1699Remember to test very carefully. 1700It is a good idea to be near the console when doing this. 1701If you cannot be near the console, 1702use an auto-recovery script such as the one in 1703.Pa /usr/share/examples/ipfw/change_rules.sh . 1704.It 1705Don't forget the loopback interface. 1706.El 1707.Sh FINE POINTS 1708.Bl -bullet 1709.It 1710There are circumstances where fragmented datagrams are unconditionally 1711dropped. 1712TCP packets are dropped if they do not contain at least 20 bytes of 1713TCP header, UDP packets are dropped if they do not contain a full 8 1714byte UDP header, and ICMP packets are dropped if they do not contain 17154 bytes of ICMP header, enough to specify the ICMP type, code, and 1716checksum. 1717These packets are simply logged as 1718.Dq pullup failed 1719since there may not be enough good data in the packet to produce a 1720meaningful log entry. 1721.It 1722Another type of packet is unconditionally dropped, a TCP packet with a 1723fragment offset of one. 1724This is a valid packet, but it only has one use, to try 1725to circumvent firewalls. 1726When logging is enabled, these packets are 1727reported as being dropped by rule -1. 1728.It 1729If you are logged in over a network, loading the 1730.Xr kld 4 1731version of 1732.Nm 1733is probably not as straightforward as you would think. 1734I recommend the following command line: 1735.Bd -literal -offset indent 1736kldload ipfw && \e 1737ipfw add 32000 allow ip from any to any 1738.Ed 1739.Pp 1740Along the same lines, doing an 1741.Bd -literal -offset indent 1742ipfw flush 1743.Ed 1744.Pp 1745in similar surroundings is also a bad idea. 1746.It 1747The 1748.Nm 1749filter list may not be modified if the system security level 1750is set to 3 or higher 1751(see 1752.Xr init 8 1753for information on system security levels). 1754.El 1755.Sh PACKET DIVERSION 1756A 1757.Xr divert 4 1758socket bound to the specified port will receive all packets 1759diverted to that port. 1760If no socket is bound to the destination port, or if the kernel 1761wasn't compiled with divert socket support, the packets are 1762dropped. 1763.Sh SYSCTL VARIABLES 1764A set of 1765.Xr sysctl 8 1766variables controls the behaviour of the firewall and 1767associated modules ( 1768.Nm dummynet, bridge 1769). 1770These are shown below together with their default value 1771(but always check with the 1772.Xr sysctl 8 1773command what value is actually in use) and meaning: 1774.Bl -tag -width indent 1775.It Em net.inet.ip.dummynet.expire : No 1 1776Lazily delete dynamic pipes/queue once they have no pending traffic. 1777You can disable this by setting the variable to 0, in which case 1778the pipes/queues will only be deleted when the threshold is reached. 1779.It Em net.inet.ip.dummynet.hash_size : No 64 1780Default size of the hash table used for dynamic pipes/queues. 1781This value is used when no 1782.Cm buckets 1783option is specified when configuring a pipe/queue. 1784.It Em net.inet.ip.dummynet.max_chain_len : No 16 1785Target value for the maximum number of pipes/queues in a hash bucket. 1786The product 1787.Cm max_chain_len*hash_size 1788is used to determine the threshold over which empty pipes/queues 1789will be expired even when 1790.Cm net.inet.ip.dummynet.expire=0 . 1791.It Em net.inet.ip.dummynet.red_lookup_depth : No 256 1792.It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512 1793.It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500 1794Parameters used in the computations of the drop probability 1795for the RED algorithm. 1796.It Em net.inet.ip.fw.autoinc_step : No 100 1797Delta between rule numbers when auto-generating them. 1798The value must be in the range 1..1000. 1799This variable is only present in 1800.Nm ipfw2 , 1801the delta is hardwired to 100 in 1802.Nm ipfw1 . 1803.It Em net.inet.ip.fw.curr_dyn_buckets : Em net.inet.ip.fw.dyn_buckets 1804The current number of buckets in the hash table for dynamic rules 1805(readonly). 1806.It Em net.inet.ip.fw.debug : No 1 1807Controls debugging messages produced by 1808.Nm . 1809.It Em net.inet.ip.fw.dyn_buckets : No 256 1810The number of buckets in the hash table for dynamic rules. 1811Must be a power of 2, up to 65536. 1812It only takes effect when all dynamic rules have expired, so you 1813are advised to use a 1814.Cm flush 1815command to make sure that the hash table is resized. 1816.It Em net.inet.ip.fw.dyn_count : No 3 1817Current number of dynamic rules 1818(read-only). 1819.It Em net.inet.ip.fw.dyn_keepalive : No 1 1820Enables generation of keepalive packets for 1821.Cm keep-state 1822rules on TCP sessions. 1823A keepalive is generated to both 1824sides of the connection every 5 seconds for the last 20 1825seconds of the lifetime of the rule. 1826.It Em net.inet.ip.fw.dyn_max : No 8192 1827Maximum number of dynamic rules. 1828When you hit this limit, no more dynamic rules can be 1829installed until old ones expire. 1830.It Em net.inet.ip.fw.dyn_ack_lifetime : No 300 1831.It Em net.inet.ip.fw.dyn_syn_lifetime : No 20 1832.It Em net.inet.ip.fw.dyn_fin_lifetime : No 1 1833.It Em net.inet.ip.fw.dyn_rst_lifetime : No 1 1834.It Em net.inet.ip.fw.dyn_udp_lifetime : No 5 1835.It Em net.inet.ip.fw.dyn_short_lifetime : No 30 1836These variables control the lifetime, in seconds, of dynamic 1837rules. 1838Upon the initial SYN exchange the lifetime is kept short, 1839then increased after both SYN have been seen, then decreased 1840again during the final FIN exchange or when a RST is received. 1841Both 1842.Em dyn_fin_lifetime 1843and 1844.Em dyn_rst_lifetime 1845must be strictly lower than 5 seconds, the period of 1846repetition of keepalives. 1847The firewall enforces that. 1848.It Em net.inet.ip.fw.enable : No 1 1849Enables the firewall. 1850Setting this variable to 0 lets you run your machine without 1851firewall even if compiled in. 1852.It Em net.inet.ip.fw.one_pass : No 1 1853When set, the packet exiting from the 1854.Xr dummynet 4 1855pipe is not passed though the firewall again. 1856Otherwise, after a pipe action, the packet is 1857reinjected into the firewall at the next rule. 1858.It Em net.inet.ip.fw.verbose : No 1 1859Enables verbose messages. 1860.It Em net.inet.ip.fw.verbose_limit : No 0 1861Limits the number of messages produced by a verbose firewall. 1862.It Em net.link.ether.ipfw : No 0 1863Controls whether layer-2 packets are passed to 1864.Nm . 1865Default is no. 1866.It Em net.link.ether.bridge_ipfw : No 0 1867Controls whether bridged packets are passed to 1868.Nm . 1869Default is no. 1870.El 1871.Sh USING IPFW2 IN FreeBSD-STABLE 1872.Nm ipfw2 1873is standard in 1874.Fx 1875CURRENT, whereas 1876.Fx 1877STABLE still uses 1878.Nm ipfw1 1879unless the kernel is compiled with 1880.Cm options IPFW2 , 1881and 1882.Nm /sbin/ipfw 1883and 1884.Nm /usr/lib/libalias 1885are recompiled with 1886.Cm -DIPFW2 1887and reinstalled (the same effect can be achieved by adding 1888.Cm IPFW2=TRUE 1889to 1890.Nm /etc/make.conf 1891before a buildworld). 1892.Pp 1893.Sh IPFW2 ENHANCEMENTS 1894This Section lists the features that have been introduced in 1895.Nm ipfw2 1896which were not present in 1897.Nm ipfw1 . 1898They are listed in order of the potential impact that they can 1899have in writing your rulesets. 1900You might want to consider using these features in order to 1901write your rulesets in a more efficient way. 1902.Bl -tag -width indent 1903.It Syntax and flags 1904.Nm ipfw1 1905does not support the -n flag (only test syntax), 1906nor does it allow spaces after commas or support all 1907rule fields in a single argument. 1908.Nm ipfw1 1909does not allow the -f flag (force) in conjunction with 1910the -p flag (preprocessor). 1911.Nm ipfw1 1912does not support the -c (compact) flag. 1913.It Handling of non-IPv4 packets 1914.Nm ipfw1 1915will silently accept all non-IPv4 packets (which 1916.Nm ipfw1 1917will only see when 1918.Em net.link.ether.bridge_ipfw=1 Ns 1919). 1920.Nm ipfw2 1921will filter all packets (including non-IPv4 ones) according to the ruleset. 1922To achieve the same behaviour as 1923.Nm ipfw1 1924you can use the following as the very first rule in your ruleset: 1925.Pp 1926.Dl "ipfw add 1 allow layer2 not mac-type ip" 1927.Pp 1928The 1929.Cm layer2 1930option might seem redundant, but it is necessary -- packets 1931passed to the firewall from layer3 will not have a MAC header, 1932so the 1933.Cm mac-type ip 1934pattern will always fail on them, and the 1935.Cm not 1936operator will make this rule into a pass-all. 1937.It Addresses 1938.Nm ipfw1 1939does not support address sets or lists of addresses. 1940.Pp 1941.It Port specifications 1942.Nm ipfw1 1943only allows one port range when specifying TCP and UDP ports, and 1944is limited to 10 entries instead of the 30 allowed by 1945.Nm ipfw2 . 1946Also, in 1947.Nm ipfw1 1948you can only specify ports when the rule is requesting 1949.Cm tcp 1950or 1951.Cm udp 1952packets. 1953With 1954.Nm ipfw2 1955you can put port specifications in rules matching all packets, 1956and the match will be attempted only on those packets carrying 1957protocols which include port identifiers. 1958.Pp 1959Finally, 1960.Nm ipfw1 1961allowed the first port entry to be specified as 1962.Ar port:mask 1963where 1964.Ar mask 1965can be an arbitrary 16-bit mask. 1966This syntax is of questionable usefulness and it is not 1967supported anymore in 1968.Nm ipfw2 . 1969.It Or-blocks 1970.Nm ipfw1 1971does not support Or-blocks. 1972.It keepalives 1973.Nm ipfw1 1974does not generate keepalives for stateful sessions. 1975As a consequence, it might cause idle sessions to drop because 1976the lifetime of the dynamic rules expires. 1977.It Sets of rules 1978.Nm ipfw1 1979does not implement sets of rules. 1980.It MAC header filtering and Layer-2 firewalling. 1981.Nm ipfw1 1982does not implement filtering on MAC header fields, nor is it 1983invoked on packets from 1984.Cm ether_demux() 1985and 1986.Cm ether_output_frame(). 1987The sysctl variable 1988.Em net.link.ether.ipfw 1989has no effect there. 1990.It Options 1991In 1992.Nm ipfw1 , 1993the following options only accept a single value as an argument: 1994.Pp 1995.Cm ipid, iplen, ipttl 1996.Pp 1997The following options are not implemented by 1998.Nm ipfw1 : 1999.Pp 2000.Cm dst-ip, dst-port, layer2, mac, mac-type, src-ip, src-port. 2001.Pp 2002Additionally, the RELENG_4 version of 2003.Nm ipfw1 2004does not implement the following options: 2005.Pp 2006.Cm ipid, iplen, ipprecedence, iptos, ipttl, 2007.Cm ipversion, tcpack, tcpseq, tcpwin . 2008.It Dummynet options 2009The following option for 2010.Nm dummynet 2011pipes/queues is not supported: 2012.Cm noerror . 2013.El 2014.Sh EXAMPLES 2015There are far too many possible uses of 2016.Nm 2017so this Section will only give a small set of examples. 2018.Pp 2019.Ss BASIC PACKET FILTERING 2020This command adds an entry which denies all tcp packets from 2021.Em cracker.evil.org 2022to the telnet port of 2023.Em wolf.tambov.su 2024from being forwarded by the host: 2025.Pp 2026.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet" 2027.Pp 2028This one disallows any connection from the entire cracker's 2029network to my host: 2030.Pp 2031.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org" 2032.Pp 2033A first and efficient way to limit access (not using dynamic rules) 2034is the use of the following rules: 2035.Pp 2036.Dl "ipfw add allow tcp from any to any established" 2037.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup" 2038.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup" 2039.Dl "..." 2040.Dl "ipfw add deny tcp from any to any" 2041.Pp 2042The first rule will be a quick match for normal TCP packets, 2043but it will not match the initial SYN packet, which will be 2044matched by the 2045.Cm setup 2046rules only for selected source/destination pairs. 2047All other SYN packets will be rejected by the final 2048.Cm deny 2049rule. 2050.Pp 2051If you administer one or more subnets, you can take advantage of the 2052.Nm ipfw2 2053syntax to specify address sets and or-blocks and write extremely 2054compact rulesets which selectively enable services to blocks 2055of clients, as below: 2056.Pp 2057.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q" 2058.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q" 2059.Dl "" 2060.Dl "ipfw add allow ip from ${goodguys} to any" 2061.Dl "ipfw add deny ip from ${badguys} to any" 2062.Dl "... normal policies ..." 2063.Pp 2064The 2065.Nm ipfw1 2066syntax would require a separate rule for each IP in the above 2067example. 2068.Pp 2069The 2070.Cm verrevpath 2071option could be used to do automated anti-spoofing by adding the 2072following to the top of a ruleset: 2073.Pp 2074.Dl "ipfw add deny ip from any to any not verrevpath in" 2075.Pp 2076This rule drops all incoming packets that appear to be coming to the 2077system on the wrong interface. 2078For example, a packet with a source 2079address belonging to a host on a protected internal network would be 2080dropped if it tried to enter the system from an external interface. 2081.Pp 2082The 2083.Cm antispoof 2084option could be used to do similar but more restricted anti-spoofing 2085by adding the following to the top of a ruleset: 2086.Pp 2087.Dl "ipfw add deny ip from any to any not antispoof in" 2088.Pp 2089This rule drops all incoming packets that appear to be coming from another 2090directly connected system but on the wrong interface. 2091For example, a packet with a source address of 2092.Li 192.168.0.0/24 2093, configured on 2094.Li fxp0 2095, but coming in on 2096.Li fxp1 2097would be dropped. 2098.Ss DYNAMIC RULES 2099In order to protect a site from flood attacks involving fake 2100TCP packets, it is safer to use dynamic rules: 2101.Pp 2102.Dl "ipfw add check-state" 2103.Dl "ipfw add deny tcp from any to any established" 2104.Dl "ipfw add allow tcp from my-net to any setup keep-state" 2105.Pp 2106This will let the firewall install dynamic rules only for 2107those connection which start with a regular SYN packet coming 2108from the inside of our network. 2109Dynamic rules are checked when encountering the first 2110.Cm check-state 2111or 2112.Cm keep-state 2113rule. 2114A 2115.Cm check-state 2116rule should usually be placed near the beginning of the 2117ruleset to minimize the amount of work scanning the ruleset. 2118Your mileage may vary. 2119.Pp 2120To limit the number of connections a user can open 2121you can use the following type of rules: 2122.Pp 2123.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10" 2124.Dl "ipfw add allow tcp from any to me setup limit src-addr 4" 2125.Pp 2126The former (assuming it runs on a gateway) will allow each host 2127on a /24 network to open at most 10 TCP connections. 2128The latter can be placed on a server to make sure that a single 2129client does not use more than 4 simultaneous connections. 2130.Pp 2131.Em BEWARE : 2132stateful rules can be subject to denial-of-service attacks 2133by a SYN-flood which opens a huge number of dynamic rules. 2134The effects of such attacks can be partially limited by 2135acting on a set of 2136.Xr sysctl 8 2137variables which control the operation of the firewall. 2138.Pp 2139Here is a good usage of the 2140.Cm list 2141command to see accounting records and timestamp information: 2142.Pp 2143.Dl ipfw -at list 2144.Pp 2145or in short form without timestamps: 2146.Pp 2147.Dl ipfw -a list 2148.Pp 2149which is equivalent to: 2150.Pp 2151.Dl ipfw show 2152.Pp 2153Next rule diverts all incoming packets from 192.168.2.0/24 2154to divert port 5000: 2155.Pp 2156.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in 2157.Pp 2158.Ss TRAFFIC SHAPING 2159The following rules show some of the applications of 2160.Nm 2161and 2162.Xr dummynet 4 2163for simulations and the like. 2164.Pp 2165This rule drops random incoming packets with a probability 2166of 5%: 2167.Pp 2168.Dl "ipfw add prob 0.05 deny ip from any to any in" 2169.Pp 2170A similar effect can be achieved making use of dummynet pipes: 2171.Pp 2172.Dl "ipfw add pipe 10 ip from any to any" 2173.Dl "ipfw pipe 10 config plr 0.05" 2174.Pp 2175We can use pipes to artificially limit bandwidth, e.g.\& on a 2176machine acting as a router, if we want to limit traffic from 2177local clients on 192.168.2.0/24 we do: 2178.Pp 2179.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 2180.Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes" 2181.Pp 2182note that we use the 2183.Cm out 2184modifier so that the rule is not used twice. 2185Remember in fact that 2186.Nm 2187rules are checked both on incoming and outgoing packets. 2188.Pp 2189Should we want to simulate a bidirectional link with bandwidth 2190limitations, the correct way is the following: 2191.Pp 2192.Dl "ipfw add pipe 1 ip from any to any out" 2193.Dl "ipfw add pipe 2 ip from any to any in" 2194.Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes" 2195.Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes" 2196.Pp 2197The above can be very useful, e.g.\& if you want to see how 2198your fancy Web page will look for a residential user who 2199is connected only through a slow link. 2200You should not use only one pipe for both directions, unless 2201you want to simulate a half-duplex medium (e.g.\& AppleTalk, 2202Ethernet, IRDA). 2203It is not necessary that both pipes have the same configuration, 2204so we can also simulate asymmetric links. 2205.Pp 2206Should we want to verify network performance with the RED queue 2207management algorithm: 2208.Pp 2209.Dl "ipfw add pipe 1 ip from any to any" 2210.Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1" 2211.Pp 2212Another typical application of the traffic shaper is to 2213introduce some delay in the communication. 2214This can significantly affect applications which do a lot of Remote 2215Procedure Calls, and where the round-trip-time of the 2216connection often becomes a limiting factor much more than 2217bandwidth: 2218.Pp 2219.Dl "ipfw add pipe 1 ip from any to any out" 2220.Dl "ipfw add pipe 2 ip from any to any in" 2221.Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s" 2222.Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s" 2223.Pp 2224Per-flow queueing can be useful for a variety of purposes. 2225A very simple one is counting traffic: 2226.Pp 2227.Dl "ipfw add pipe 1 tcp from any to any" 2228.Dl "ipfw add pipe 1 udp from any to any" 2229.Dl "ipfw add pipe 1 ip from any to any" 2230.Dl "ipfw pipe 1 config mask all" 2231.Pp 2232The above set of rules will create queues (and collect 2233statistics) for all traffic. 2234Because the pipes have no limitations, the only effect is 2235collecting statistics. 2236Note that we need 3 rules, not just the last one, because 2237when 2238.Nm 2239tries to match IP packets it will not consider ports, so we 2240would not see connections on separate ports as different 2241ones. 2242.Pp 2243A more sophisticated example is limiting the outbound traffic 2244on a net with per-host limits, rather than per-network limits: 2245.Pp 2246.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 2247.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in" 2248.Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 2249.Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 2250.Ss SETS OF RULES 2251To add a set of rules atomically, e.g.\& set 18: 2252.Pp 2253.Dl "ipfw set disable 18" 2254.Dl "ipfw add NN set 18 ... # repeat as needed" 2255.Dl "ipfw set enable 18" 2256.Pp 2257To delete a set of rules atomically the command is simply: 2258.Pp 2259.Dl "ipfw delete set 18" 2260.Pp 2261To test a ruleset and disable it and regain control if something goes wrong: 2262.Pp 2263.Dl "ipfw set disable 18" 2264.Dl "ipfw add NN set 18 ... # repeat as needed" 2265.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18" 2266.Pp 2267Here if everything goes well, you press control-C before the "sleep" 2268terminates, and your ruleset will be left active. 2269Otherwise, e.g.\& if 2270you cannot access your box, the ruleset will be disabled after 2271the sleep terminates thus restoring the previous situation. 2272.Sh SEE ALSO 2273.Xr cpp 1 , 2274.Xr m4 1 , 2275.Xr bridge 4 , 2276.Xr divert 4 , 2277.Xr dummynet 4 , 2278.Xr ip 4 , 2279.Xr ipfirewall 4 , 2280.Xr protocols 5 , 2281.Xr services 5 , 2282.Xr init 8 , 2283.Xr kldload 8 , 2284.Xr reboot 8 , 2285.Xr sysctl 8 , 2286.Xr syslogd 8 2287.Sh BUGS 2288The syntax has grown over the years and sometimes it might be confusing. 2289Unfortunately, backward compatibility prevents cleaning up mistakes 2290made in the definition of the syntax. 2291.Pp 2292.Em !!! WARNING !!! 2293.Pp 2294Misconfiguring the firewall can put your computer in an unusable state, 2295possibly shutting down network services and requiring console access to 2296regain control of it. 2297.Pp 2298Incoming packet fragments diverted by 2299.Cm divert 2300or 2301.Cm tee 2302are reassembled before delivery to the socket. 2303The action used on those packet is the one from the 2304rule which matches the first fragment of the packet. 2305.Pp 2306Packets that match a 2307.Cm tee 2308rule should not be immediately accepted, but should continue 2309going through the rule list. 2310This may be fixed in a later version. 2311.Pp 2312Packets diverted to userland, and then reinserted by a userland process 2313may lose various packet attributes. 2314The packet source interface name 2315will be preserved if it is shorter than 8 bytes and the userland process 2316saves and reuses the sockaddr_in 2317(as does 2318.Xr natd 8 ) ; 2319otherwise, it may be lost. 2320If a packet is reinserted in this manner, later rules may be incorrectly 2321applied, making the order of 2322.Cm divert 2323rules in the rule sequence very important. 2324.Sh AUTHORS 2325.An Ugen J. S. Antsilevich , 2326.An Poul-Henning Kamp , 2327.An Alex Nash , 2328.An Archie Cobbs , 2329.An Luigi Rizzo . 2330.Pp 2331.An -nosplit 2332API based upon code written by 2333.An Daniel Boulet 2334for BSDI. 2335.Pp 2336Work on 2337.Xr dummynet 4 2338traffic shaper supported by Akamba Corp. 2339.Sh HISTORY 2340The 2341.Nm 2342utility first appeared in 2343.Fx 2.0 . 2344.Xr dummynet 4 2345was introduced in 2346.Fx 2.2.8 . 2347Stateful extensions were introduced in 2348.Fx 4.0 . 2349.Nm ipfw2 2350was introduced in Summer 2002. 2351