1.\" 2.\" $FreeBSD$ 3.\" 4.Dd June 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 icmptypes Ar types 933Matches ICMP packets whose ICMP type is in the list 934.Ar types . 935The list may be specified as any combination of 936individual types (numeric) separated by commas. 937.Em Ranges are not allowed. 938The supported ICMP types are: 939.Pp 940echo reply 941.Pq Cm 0 , 942destination unreachable 943.Pq Cm 3 , 944source quench 945.Pq Cm 4 , 946redirect 947.Pq Cm 5 , 948echo request 949.Pq Cm 8 , 950router advertisement 951.Pq Cm 9 , 952router solicitation 953.Pq Cm 10 , 954time-to-live exceeded 955.Pq Cm 11 , 956IP header bad 957.Pq Cm 12 , 958timestamp request 959.Pq Cm 13 , 960timestamp reply 961.Pq Cm 14 , 962information request 963.Pq Cm 15 , 964information reply 965.Pq Cm 16 , 966address mask request 967.Pq Cm 17 968and address mask reply 969.Pq Cm 18 . 970.It Cm in | out 971Matches incoming or outgoing packets, respectively. 972.Cm in 973and 974.Cm out 975are mutually exclusive (in fact, 976.Cm out 977is implemented as 978.Cm not in Ns No ). 979.It Cm ipid Ar id-list 980Matches IP packets whose 981.Cm ip_id 982field has value included in 983.Ar id-list , 984which is either a single value or a list of values or ranges 985specified in the same way as 986.Ar ports . 987.It Cm iplen Ar len-list 988Matches IP packets whose total length, including header and data, is 989in the set 990.Ar len-list , 991which is either a single value or a list of values or ranges 992specified in the same way as 993.Ar ports . 994.It Cm ipoptions Ar spec 995Matches packets whose IP header contains the comma separated list of 996options specified in 997.Ar spec . 998The supported IP options are: 999.Pp 1000.Cm ssrr 1001(strict source route), 1002.Cm lsrr 1003(loose source route), 1004.Cm rr 1005(record packet route) and 1006.Cm ts 1007(timestamp). 1008The absence of a particular option may be denoted 1009with a 1010.Ql \&! . 1011.It Cm ipprecedence Ar precedence 1012Matches IP packets whose precedence field is equal to 1013.Ar precedence . 1014.It Cm ipsec 1015Matches packets that have IPSEC history associated with them 1016(i.e., the packet comes encapsulated in IPSEC, the kernel 1017has IPSEC support and IPSEC_FILTERGIF option, and can correctly 1018decapsulate it). 1019.Pp 1020Note that specifying 1021.Cm ipsec 1022is different from specifying 1023.Cm proto Ar ipsec 1024as the latter will only look at the specific IP protocol field, 1025irrespective of IPSEC kernel support and the validity of the IPSEC data. 1026.Pp 1027Further note that this flag is silently ignored in kernels without 1028IPSEC support. 1029It does not affect rule processing when given and the 1030rules are handled as if with no 1031.Cm ipsec 1032flag. 1033.It Cm iptos Ar spec 1034Matches IP packets whose 1035.Cm tos 1036field contains the comma separated list of 1037service types specified in 1038.Ar spec . 1039The supported IP types of service are: 1040.Pp 1041.Cm lowdelay 1042.Pq Dv IPTOS_LOWDELAY , 1043.Cm throughput 1044.Pq Dv IPTOS_THROUGHPUT , 1045.Cm reliability 1046.Pq Dv IPTOS_RELIABILITY , 1047.Cm mincost 1048.Pq Dv IPTOS_MINCOST , 1049.Cm congestion 1050.Pq Dv IPTOS_CE . 1051The absence of a particular type may be denoted 1052with a 1053.Ql \&! . 1054.It Cm ipttl Ar ttl-list 1055Matches IP packets whose time to live is included in 1056.Ar ttl-list , 1057which is either a single value or a list of values or ranges 1058specified in the same way as 1059.Ar ports . 1060.It Cm ipversion Ar ver 1061Matches IP packets whose IP version field is 1062.Ar ver . 1063.It Cm keep-state 1064Upon a match, the firewall will create a dynamic rule, whose 1065default behaviour is to match bidirectional traffic between 1066source and destination IP/port using the same protocol. 1067The rule has a limited lifetime (controlled by a set of 1068.Xr sysctl 8 1069variables), and the lifetime is refreshed every time a matching 1070packet is found. 1071.It Cm layer2 1072Matches only layer2 packets, i.e., those passed to 1073.Nm 1074from ether_demux() and ether_output_frame(). 1075.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N 1076The firewall will only allow 1077.Ar N 1078connections with the same 1079set of parameters as specified in the rule. 1080One or more 1081of source and destination addresses and ports can be 1082specified. 1083.It Cm { MAC | mac } Ar dst-mac src-mac 1084Match packets with a given 1085.Ar dst-mac 1086and 1087.Ar src-mac 1088addresses, specified as the 1089.Cm any 1090keyword (matching any MAC address), or six groups of hex digits 1091separated by colons, 1092and optionally followed by a mask indicating the significant bits. 1093The mask may be specified using either of the following methods: 1094.Bl -enum -width indent 1095.It 1096A slash 1097.Pq / 1098followed by the number of significant bits. 1099For example, an address with 33 significant bits could be specified as: 1100.Pp 1101.Dl "MAC 10:20:30:40:50:60/33 any" 1102.Pp 1103.It 1104An ampersand 1105.Pq & 1106followed by a bitmask specified as six groups of hex digits separated 1107by colons. 1108For example, an address in which the last 16 bits are significant could 1109be specified as: 1110.Pp 1111.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any" 1112.Pp 1113Note that the ampersand character has a special meaning in many shells 1114and should generally be escaped. 1115.Pp 1116.El 1117Note that the order of MAC addresses (destination first, 1118source second) is 1119the same as on the wire, but the opposite of the one used for 1120IP addresses. 1121.It Cm mac-type Ar mac-type 1122Matches packets whose Ethernet Type field 1123corresponds to one of those specified as argument. 1124.Ar mac-type 1125is specified in the same way as 1126.Cm port numbers 1127(i.e., one or more comma-separated single values or ranges). 1128You can use symbolic names for known values such as 1129.Em vlan , ipv4, ipv6 . 1130Values can be entered as decimal or hexadecimal (if prefixed by 0x), 1131and they are always printed as hexadecimal (unless the 1132.Cm -N 1133option is used, in which case symbolic resolution will be attempted). 1134.It Cm proto Ar protocol 1135Matches packets with the corresponding IPv4 protocol. 1136.It Cm recv | xmit | via Brq Ar ifX | Ar if Ns Cm * | Ar ipno | Ar any 1137Matches packets received, transmitted or going through, 1138respectively, the interface specified by exact name 1139.Ns No ( Ar ifX Ns No ), 1140by device name 1141.Ns No ( Ar if Ns Ar * Ns No ), 1142by IP address, or through some interface. 1143.Pp 1144The 1145.Cm via 1146keyword causes the interface to always be checked. 1147If 1148.Cm recv 1149or 1150.Cm xmit 1151is used instead of 1152.Cm via , 1153then only the receive or transmit interface (respectively) 1154is checked. 1155By specifying both, it is possible to match packets based on 1156both receive and transmit interface, e.g.: 1157.Pp 1158.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1" 1159.Pp 1160The 1161.Cm recv 1162interface can be tested on either incoming or outgoing packets, 1163while the 1164.Cm xmit 1165interface can only be tested on outgoing packets. 1166So 1167.Cm out 1168is required (and 1169.Cm in 1170is invalid) whenever 1171.Cm xmit 1172is used. 1173.Pp 1174A packet may not have a receive or transmit interface: packets 1175originating from the local host have no receive interface, 1176while packets destined for the local host have no transmit 1177interface. 1178.It Cm setup 1179Matches TCP packets that have the SYN bit set but no ACK bit. 1180This is the short form of 1181.Dq Li tcpflags\ syn,!ack . 1182.It Cm src-ip Ar ip-address 1183Matches IP packets whose source IP is one of the address(es) 1184specified as argument. 1185.It Cm src-port Ar ports 1186Matches IP packets whose source port is one of the port(s) 1187specified as argument. 1188.It Cm tcpack Ar ack 1189TCP packets only. 1190Match if the TCP header acknowledgment number field is set to 1191.Ar ack . 1192.It Cm tcpflags Ar spec 1193TCP packets only. 1194Match if the TCP header contains the comma separated list of 1195flags specified in 1196.Ar spec . 1197The supported TCP flags are: 1198.Pp 1199.Cm fin , 1200.Cm syn , 1201.Cm rst , 1202.Cm psh , 1203.Cm ack 1204and 1205.Cm urg . 1206The absence of a particular flag may be denoted 1207with a 1208.Ql \&! . 1209A rule which contains a 1210.Cm tcpflags 1211specification can never match a fragmented packet which has 1212a non-zero offset. 1213See the 1214.Cm frag 1215option for details on matching fragmented packets. 1216.It Cm tcpseq Ar seq 1217TCP packets only. 1218Match if the TCP header sequence number field is set to 1219.Ar seq . 1220.It Cm tcpwin Ar win 1221TCP packets only. 1222Match if the TCP header window field is set to 1223.Ar win . 1224.It Cm tcpoptions Ar spec 1225TCP packets only. 1226Match if the TCP header contains the comma separated list of 1227options specified in 1228.Ar spec . 1229The supported TCP options are: 1230.Pp 1231.Cm mss 1232(maximum segment size), 1233.Cm window 1234(tcp window advertisement), 1235.Cm sack 1236(selective ack), 1237.Cm ts 1238(rfc1323 timestamp) and 1239.Cm cc 1240(rfc1644 t/tcp connection count). 1241The absence of a particular option may be denoted 1242with a 1243.Ql \&! . 1244.It Cm uid Ar user 1245Match all TCP or UDP packets sent by or received for a 1246.Ar user . 1247A 1248.Ar user 1249may be matched by name or identification number. 1250.It Cm verrevpath 1251For incoming packets, 1252a routing table lookup is done on the packet's source address. 1253If the interface on which the packet entered the system matches the 1254outgoing interface for the route, 1255the packet matches. 1256If the interfaces do not match up, 1257the packet does not match. 1258All outgoing packets or packets with no incoming interface match. 1259.Pp 1260The name and functionality of the option is intentionally similar to 1261the Cisco IOS command: 1262.Pp 1263.Dl ip verify unicast reverse-path 1264.Pp 1265This option can be used to make anti-spoofing rules to reject all 1266packets with source addresses not from this interface. 1267.It Cm versrcreach 1268For incoming packets, 1269a routing table lookup is done on the packet's source address. 1270If a route to the source address exists, but not the default route 1271or a blackhole/reject route, the packet matches. 1272Otherwise the packet does not match. 1273All outgoing packets match. 1274.Pp 1275The name and functionality of the option is intentionally similar to 1276the Cisco IOS command: 1277.Pp 1278.Dl ip verify unicast source reachable-via any 1279.Pp 1280This option can be used to make anti-spoofing rules to reject all 1281packets whose source address is unreachable. 1282.El 1283.Sh LOOKUP TABLES 1284Lookup tables are useful to handle large sparse address sets, 1285typically from a hundred to several thousands of entries. 1286There could be 128 different lookup tables, numbered 0 to 127. 1287.Pp 1288Each entry is represented by an 1289.Ar addr Ns Op / Ns Ar masklen 1290and will match all addresses with base 1291.Ar addr 1292(specified as a dotted quad or a hostname) 1293and mask width of 1294.Ar masklen 1295bits. 1296If 1297.Ar masklen 1298is not specified, it defaults to 32. 1299When looking up an IP address in a table, the most specific 1300entry will match. 1301Associated with each entry is a 32-bit unsigned 1302.Ar value , 1303which can optionally be checked by a rule matching code. 1304When adding an entry, if 1305.Ar value 1306is not specified, it defaults to 0. 1307.Pp 1308An entry can be added to a table 1309.Pq Cm add , 1310removed from a table 1311.Pq Cm delete , 1312a table can be examined 1313.Pq Cm list 1314or flushed 1315.Pq Cm flush . 1316.Pp 1317Internally, each table is stored in a Radix tree, the same way as 1318the routing table (see 1319.Xr route 4 ) . 1320.Sh SETS OF RULES 1321Each rule belongs to one of 32 different 1322.Em sets 1323, numbered 0 to 31. 1324Set 31 is reserved for the default rule. 1325.Pp 1326By default, rules are put in set 0, unless you use the 1327.Cm set N 1328attribute when entering a new rule. 1329Sets can be individually and atomically enabled or disabled, 1330so this mechanism permits an easy way to store multiple configurations 1331of the firewall and quickly (and atomically) switch between them. 1332The command to enable/disable sets is 1333.Bd -ragged -offset indent 1334.Nm 1335.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 1336.Ed 1337.Pp 1338where multiple 1339.Cm enable 1340or 1341.Cm disable 1342sections can be specified. 1343Command execution is atomic on all the sets specified in the command. 1344By default, all sets are enabled. 1345.Pp 1346When you disable a set, its rules behave as if they do not exist 1347in the firewall configuration, with only one exception: 1348.Bd -ragged -offset indent 1349dynamic rules created from a rule before it had been disabled 1350will still be active until they expire. 1351In order to delete 1352dynamic rules you have to explicitly delete the parent rule 1353which generated them. 1354.Ed 1355.Pp 1356The set number of rules can be changed with the command 1357.Bd -ragged -offset indent 1358.Nm 1359.Cm set move 1360.Brq Cm rule Ar rule-number | old-set 1361.Cm to Ar new-set 1362.Ed 1363.Pp 1364Also, you can atomically swap two rulesets with the command 1365.Bd -ragged -offset indent 1366.Nm 1367.Cm set swap Ar first-set second-set 1368.Ed 1369.Pp 1370See the 1371.Sx EXAMPLES 1372Section on some possible uses of sets of rules. 1373.Sh STATEFUL FIREWALL 1374Stateful operation is a way for the firewall to dynamically 1375create rules for specific flows when packets that 1376match a given pattern are detected. 1377Support for stateful 1378operation comes through the 1379.Cm check-state , keep-state 1380and 1381.Cm limit 1382options of 1383.Nm rules. 1384.Pp 1385Dynamic rules are created when a packet matches a 1386.Cm keep-state 1387or 1388.Cm limit 1389rule, causing the creation of a 1390.Em dynamic 1391rule which will match all and only packets with 1392a given 1393.Em protocol 1394between a 1395.Em src-ip/src-port dst-ip/dst-port 1396pair of addresses ( 1397.Em src 1398and 1399.Em dst 1400are used here only to denote the initial match addresses, but they 1401are completely equivalent afterwards). 1402Dynamic rules will be checked at the first 1403.Cm check-state, keep-state 1404or 1405.Cm limit 1406occurrence, and the action performed upon a match will be the same 1407as in the parent rule. 1408.Pp 1409Note that no additional attributes other than protocol and IP addresses 1410and ports are checked on dynamic rules. 1411.Pp 1412The typical use of dynamic rules is to keep a closed firewall configuration, 1413but let the first TCP SYN packet from the inside network install a 1414dynamic rule for the flow so that packets belonging to that session 1415will be allowed through the firewall: 1416.Pp 1417.Dl "ipfw add check-state" 1418.Dl "ipfw add allow tcp from my-subnet to any setup keep-state" 1419.Dl "ipfw add deny tcp from any to any" 1420.Pp 1421A similar approach can be used for UDP, where an UDP packet coming 1422from the inside will install a dynamic rule to let the response through 1423the firewall: 1424.Pp 1425.Dl "ipfw add check-state" 1426.Dl "ipfw add allow udp from my-subnet to any keep-state" 1427.Dl "ipfw add deny udp from any to any" 1428.Pp 1429Dynamic rules expire after some time, which depends on the status 1430of the flow and the setting of some 1431.Cm sysctl 1432variables. 1433See Section 1434.Sx SYSCTL VARIABLES 1435for more details. 1436For TCP sessions, dynamic rules can be instructed to periodically 1437send keepalive packets to refresh the state of the rule when it is 1438about to expire. 1439.Pp 1440See Section 1441.Sx EXAMPLES 1442for more examples on how to use dynamic rules. 1443.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 1444.Nm 1445is also the user interface for the 1446.Xr dummynet 4 1447traffic shaper. 1448.Pp 1449.Nm dummynet 1450operates by first using the firewall to classify packets and divide them into 1451.Em flows , 1452using any match pattern that can be used in 1453.Nm 1454rules. 1455Depending on local policies, a flow can contain packets for a single 1456TCP connection, or from/to a given host, or entire subnet, or a 1457protocol type, etc. 1458.Pp 1459Packets belonging to the same flow are then passed to either of two 1460different objects, which implement the traffic regulation: 1461.Bl -hang -offset XXXX 1462.It Em pipe 1463A pipe emulates a link with given bandwidth, propagation delay, 1464queue size and packet loss rate. 1465Packets are queued in front of the pipe as they come out from the classifier, 1466and then transferred to the pipe according to the pipe's parameters. 1467.Pp 1468.It Em queue 1469A queue 1470is an abstraction used to implement the WF2Q+ 1471(Worst-case Fair Weighted Fair Queueing) policy, which is 1472an efficient variant of the WFQ policy. 1473.br 1474The queue associates a 1475.Em weight 1476and a reference pipe to each flow, and then all backlogged (i.e., 1477with packets queued) flows linked to the same pipe share the pipe's 1478bandwidth proportionally to their weights. 1479Note that weights are not priorities; a flow with a lower weight 1480is still guaranteed to get its fraction of the bandwidth even if a 1481flow with a higher weight is permanently backlogged. 1482.Pp 1483.El 1484In practice, 1485.Em pipes 1486can be used to set hard limits to the bandwidth that a flow can use, whereas 1487.Em queues 1488can be used to determine how different flow share the available bandwidth. 1489.Pp 1490The 1491.Em pipe 1492and 1493.Em queue 1494configuration commands are the following: 1495.Bd -ragged -offset indent 1496.Cm pipe Ar number Cm config Ar pipe-configuration 1497.Pp 1498.Cm queue Ar number Cm config Ar queue-configuration 1499.Ed 1500.Pp 1501The following parameters can be configured for a pipe: 1502.Pp 1503.Bl -tag -width indent -compact 1504.It Cm bw Ar bandwidth | device 1505Bandwidth, measured in 1506.Sm off 1507.Op Cm K | M 1508.Brq Cm bit/s | Byte/s . 1509.Sm on 1510.Pp 1511A value of 0 (default) means unlimited bandwidth. 1512The unit must immediately follow the number, as in 1513.Pp 1514.Dl "ipfw pipe 1 config bw 300Kbit/s" 1515.Pp 1516If a device name is specified instead of a numeric value, as in 1517.Pp 1518.Dl "ipfw pipe 1 config bw tun0" 1519.Pp 1520then the transmit clock is supplied by the specified device. 1521At the moment only the 1522.Xr tun 4 1523device supports this 1524functionality, for use in conjunction with 1525.Xr ppp 8 . 1526.Pp 1527.It Cm delay Ar ms-delay 1528Propagation delay, measured in milliseconds. 1529The value is rounded to the next multiple of the clock tick 1530(typically 10ms, but it is a good practice to run kernels 1531with 1532.Dq "options HZ=1000" 1533to reduce 1534the granularity to 1ms or less). 1535Default value is 0, meaning no delay. 1536.El 1537.Pp 1538The following parameters can be configured for a queue: 1539.Pp 1540.Bl -tag -width indent -compact 1541.It Cm pipe Ar pipe_nr 1542Connects a queue to the specified pipe. 1543Multiple queues (with the same or different weights) can be connected to 1544the same pipe, which specifies the aggregate rate for the set of queues. 1545.Pp 1546.It Cm weight Ar weight 1547Specifies the weight to be used for flows matching this queue. 1548The weight must be in the range 1..100, and defaults to 1. 1549.El 1550.Pp 1551Finally, the following parameters can be configured for both 1552pipes and queues: 1553.Pp 1554.Bl -tag -width XXXX -compact 1555.Pp 1556.It Cm buckets Ar hash-table-size 1557Specifies the size of the hash table used for storing the 1558various queues. 1559Default value is 64 controlled by the 1560.Xr sysctl 8 1561variable 1562.Em net.inet.ip.dummynet.hash_size , 1563allowed range is 16 to 65536. 1564.Pp 1565.It Cm mask Ar mask-specifier 1566Packets sent to a given pipe or queue by an 1567.Nm 1568rule can be further classified into multiple flows, each of which is then 1569sent to a different 1570.Em dynamic 1571pipe or queue. 1572A flow identifier is constructed by masking the IP addresses, 1573ports and protocol types as specified with the 1574.Cm mask 1575options in the configuration of the pipe or queue. 1576For each different flow identifier, a new pipe or queue is created 1577with the same parameters as the original object, and matching packets 1578are sent to it. 1579.Pp 1580Thus, when 1581.Em dynamic pipes 1582are used, each flow will get the same bandwidth as defined by the pipe, 1583whereas when 1584.Em dynamic queues 1585are used, each flow will share the parent's pipe bandwidth evenly 1586with other flows generated by the same queue (note that other queues 1587with different weights might be connected to the same pipe). 1588.br 1589Available mask specifiers are a combination of one or more of the following: 1590.Pp 1591.Cm dst-ip Ar mask , 1592.Cm src-ip Ar mask , 1593.Cm dst-port Ar mask , 1594.Cm src-port Ar mask , 1595.Cm proto Ar mask 1596or 1597.Cm all , 1598.Pp 1599where the latter means all bits in all fields are significant. 1600.Pp 1601.It Cm noerror 1602When a packet is dropped by a dummynet queue or pipe, the error 1603is normally reported to the caller routine in the kernel, in the 1604same way as it happens when a device queue fills up. 1605Setting this 1606option reports the packet as successfully delivered, which can be 1607needed for some experimental setups where you want to simulate 1608loss or congestion at a remote router. 1609.Pp 1610.It Cm plr Ar packet-loss-rate 1611Packet loss rate. 1612Argument 1613.Ar packet-loss-rate 1614is a floating-point number between 0 and 1, with 0 meaning no 1615loss, 1 meaning 100% loss. 1616The loss rate is internally represented on 31 bits. 1617.Pp 1618.It Cm queue Brq Ar slots | size Ns Cm Kbytes 1619Queue size, in 1620.Ar slots 1621or 1622.Cm KBytes . 1623Default value is 50 slots, which 1624is the typical queue size for Ethernet devices. 1625Note that for slow speed links you should keep the queue 1626size short or your traffic might be affected by a significant 1627queueing delay. 1628E.g., 50 max-sized ethernet packets (1500 bytes) mean 600Kbit 1629or 20s of queue on a 30Kbit/s pipe. 1630Even worse effects can result if you get packets from an 1631interface with a much larger MTU, e.g.\& the loopback interface 1632with its 16KB packets. 1633.Pp 1634.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p 1635Make use of the RED (Random Early Detection) queue management algorithm. 1636.Ar w_q 1637and 1638.Ar max_p 1639are floating 1640point numbers between 0 and 1 (0 not included), while 1641.Ar min_th 1642and 1643.Ar max_th 1644are integer numbers specifying thresholds for queue management 1645(thresholds are computed in bytes if the queue has been defined 1646in bytes, in slots otherwise). 1647The 1648.Xr dummynet 4 1649also supports the gentle RED variant (gred). 1650Three 1651.Xr sysctl 8 1652variables can be used to control the RED behaviour: 1653.Bl -tag -width indent 1654.It Em net.inet.ip.dummynet.red_lookup_depth 1655specifies the accuracy in computing the average queue 1656when the link is idle (defaults to 256, must be greater than zero) 1657.It Em net.inet.ip.dummynet.red_avg_pkt_size 1658specifies the expected average packet size (defaults to 512, must be 1659greater than zero) 1660.It Em net.inet.ip.dummynet.red_max_pkt_size 1661specifies the expected maximum packet size, only used when queue 1662thresholds are in bytes (defaults to 1500, must be greater than zero). 1663.El 1664.El 1665.Sh CHECKLIST 1666Here are some important points to consider when designing your 1667rules: 1668.Bl -bullet 1669.It 1670Remember that you filter both packets going 1671.Cm in 1672and 1673.Cm out . 1674Most connections need packets going in both directions. 1675.It 1676Remember to test very carefully. 1677It is a good idea to be near the console when doing this. 1678If you cannot be near the console, 1679use an auto-recovery script such as the one in 1680.Pa /usr/share/examples/ipfw/change_rules.sh . 1681.It 1682Don't forget the loopback interface. 1683.El 1684.Sh FINE POINTS 1685.Bl -bullet 1686.It 1687There are circumstances where fragmented datagrams are unconditionally 1688dropped. 1689TCP packets are dropped if they do not contain at least 20 bytes of 1690TCP header, UDP packets are dropped if they do not contain a full 8 1691byte UDP header, and ICMP packets are dropped if they do not contain 16924 bytes of ICMP header, enough to specify the ICMP type, code, and 1693checksum. 1694These packets are simply logged as 1695.Dq pullup failed 1696since there may not be enough good data in the packet to produce a 1697meaningful log entry. 1698.It 1699Another type of packet is unconditionally dropped, a TCP packet with a 1700fragment offset of one. 1701This is a valid packet, but it only has one use, to try 1702to circumvent firewalls. 1703When logging is enabled, these packets are 1704reported as being dropped by rule -1. 1705.It 1706If you are logged in over a network, loading the 1707.Xr kld 4 1708version of 1709.Nm 1710is probably not as straightforward as you would think. 1711I recommend the following command line: 1712.Bd -literal -offset indent 1713kldload ipfw && \e 1714ipfw add 32000 allow ip from any to any 1715.Ed 1716.Pp 1717Along the same lines, doing an 1718.Bd -literal -offset indent 1719ipfw flush 1720.Ed 1721.Pp 1722in similar surroundings is also a bad idea. 1723.It 1724The 1725.Nm 1726filter list may not be modified if the system security level 1727is set to 3 or higher 1728(see 1729.Xr init 8 1730for information on system security levels). 1731.El 1732.Sh PACKET DIVERSION 1733A 1734.Xr divert 4 1735socket bound to the specified port will receive all packets 1736diverted to that port. 1737If no socket is bound to the destination port, or if the kernel 1738wasn't compiled with divert socket support, the packets are 1739dropped. 1740.Sh SYSCTL VARIABLES 1741A set of 1742.Xr sysctl 8 1743variables controls the behaviour of the firewall and 1744associated modules ( 1745.Nm dummynet, bridge 1746). 1747These are shown below together with their default value 1748(but always check with the 1749.Xr sysctl 8 1750command what value is actually in use) and meaning: 1751.Bl -tag -width indent 1752.It Em net.inet.ip.dummynet.expire : No 1 1753Lazily delete dynamic pipes/queue once they have no pending traffic. 1754You can disable this by setting the variable to 0, in which case 1755the pipes/queues will only be deleted when the threshold is reached. 1756.It Em net.inet.ip.dummynet.hash_size : No 64 1757Default size of the hash table used for dynamic pipes/queues. 1758This value is used when no 1759.Cm buckets 1760option is specified when configuring a pipe/queue. 1761.It Em net.inet.ip.dummynet.max_chain_len : No 16 1762Target value for the maximum number of pipes/queues in a hash bucket. 1763The product 1764.Cm max_chain_len*hash_size 1765is used to determine the threshold over which empty pipes/queues 1766will be expired even when 1767.Cm net.inet.ip.dummynet.expire=0 . 1768.It Em net.inet.ip.dummynet.red_lookup_depth : No 256 1769.It Em net.inet.ip.dummynet.red_avg_pkt_size : No 512 1770.It Em net.inet.ip.dummynet.red_max_pkt_size : No 1500 1771Parameters used in the computations of the drop probability 1772for the RED algorithm. 1773.It Em net.inet.ip.fw.autoinc_step : No 100 1774Delta between rule numbers when auto-generating them. 1775The value must be in the range 1..1000. 1776This variable is only present in 1777.Nm ipfw2 , 1778the delta is hardwired to 100 in 1779.Nm ipfw1 . 1780.It Em net.inet.ip.fw.curr_dyn_buckets : Em net.inet.ip.fw.dyn_buckets 1781The current number of buckets in the hash table for dynamic rules 1782(readonly). 1783.It Em net.inet.ip.fw.debug : No 1 1784Controls debugging messages produced by 1785.Nm . 1786.It Em net.inet.ip.fw.dyn_buckets : No 256 1787The number of buckets in the hash table for dynamic rules. 1788Must be a power of 2, up to 65536. 1789It only takes effect when all dynamic rules have expired, so you 1790are advised to use a 1791.Cm flush 1792command to make sure that the hash table is resized. 1793.It Em net.inet.ip.fw.dyn_count : No 3 1794Current number of dynamic rules 1795(read-only). 1796.It Em net.inet.ip.fw.dyn_keepalive : No 1 1797Enables generation of keepalive packets for 1798.Cm keep-state 1799rules on TCP sessions. 1800A keepalive is generated to both 1801sides of the connection every 5 seconds for the last 20 1802seconds of the lifetime of the rule. 1803.It Em net.inet.ip.fw.dyn_max : No 8192 1804Maximum number of dynamic rules. 1805When you hit this limit, no more dynamic rules can be 1806installed until old ones expire. 1807.It Em net.inet.ip.fw.dyn_ack_lifetime : No 300 1808.It Em net.inet.ip.fw.dyn_syn_lifetime : No 20 1809.It Em net.inet.ip.fw.dyn_fin_lifetime : No 1 1810.It Em net.inet.ip.fw.dyn_rst_lifetime : No 1 1811.It Em net.inet.ip.fw.dyn_udp_lifetime : No 5 1812.It Em net.inet.ip.fw.dyn_short_lifetime : No 30 1813These variables control the lifetime, in seconds, of dynamic 1814rules. 1815Upon the initial SYN exchange the lifetime is kept short, 1816then increased after both SYN have been seen, then decreased 1817again during the final FIN exchange or when a RST is received. 1818Both 1819.Em dyn_fin_lifetime 1820and 1821.Em dyn_rst_lifetime 1822must be strictly lower than 5 seconds, the period of 1823repetition of keepalives. 1824The firewall enforces that. 1825.It Em net.inet.ip.fw.enable : No 1 1826Enables the firewall. 1827Setting this variable to 0 lets you run your machine without 1828firewall even if compiled in. 1829.It Em net.inet.ip.fw.one_pass : No 1 1830When set, the packet exiting from the 1831.Xr dummynet 4 1832pipe is not passed though the firewall again. 1833Otherwise, after a pipe action, the packet is 1834reinjected into the firewall at the next rule. 1835.It Em net.inet.ip.fw.verbose : No 1 1836Enables verbose messages. 1837.It Em net.inet.ip.fw.verbose_limit : No 0 1838Limits the number of messages produced by a verbose firewall. 1839.It Em net.link.ether.ipfw : No 0 1840Controls whether layer-2 packets are passed to 1841.Nm . 1842Default is no. 1843.It Em net.link.ether.bridge_ipfw : No 0 1844Controls whether bridged packets are passed to 1845.Nm . 1846Default is no. 1847.El 1848.Sh USING IPFW2 IN FreeBSD-STABLE 1849.Nm ipfw2 1850is standard in 1851.Fx 1852CURRENT, whereas 1853.Fx 1854STABLE still uses 1855.Nm ipfw1 1856unless the kernel is compiled with 1857.Cm options IPFW2 , 1858and 1859.Nm /sbin/ipfw 1860and 1861.Nm /usr/lib/libalias 1862are recompiled with 1863.Cm -DIPFW2 1864and reinstalled (the same effect can be achieved by adding 1865.Cm IPFW2=TRUE 1866to 1867.Nm /etc/make.conf 1868before a buildworld). 1869.Pp 1870.Sh IPFW2 ENHANCEMENTS 1871This Section lists the features that have been introduced in 1872.Nm ipfw2 1873which were not present in 1874.Nm ipfw1 . 1875They are listed in order of the potential impact that they can 1876have in writing your rulesets. 1877You might want to consider using these features in order to 1878write your rulesets in a more efficient way. 1879.Bl -tag -width indent 1880.It Syntax and flags 1881.Nm ipfw1 1882does not support the -n flag (only test syntax), 1883nor does it allow spaces after commas or support all 1884rule fields in a single argument. 1885.Nm ipfw1 1886does not allow the -f flag (force) in conjunction with 1887the -p flag (preprocessor). 1888.Nm ipfw1 1889does not support the -c (compact) flag. 1890.It Handling of non-IPv4 packets 1891.Nm ipfw1 1892will silently accept all non-IPv4 packets (which 1893.Nm ipfw1 1894will only see when 1895.Em net.link.ether.bridge_ipfw=1 Ns 1896). 1897.Nm ipfw2 1898will filter all packets (including non-IPv4 ones) according to the ruleset. 1899To achieve the same behaviour as 1900.Nm ipfw1 1901you can use the following as the very first rule in your ruleset: 1902.Pp 1903.Dl "ipfw add 1 allow layer2 not mac-type ip" 1904.Pp 1905The 1906.Cm layer2 1907option might seem redundant, but it is necessary -- packets 1908passed to the firewall from layer3 will not have a MAC header, 1909so the 1910.Cm mac-type ip 1911pattern will always fail on them, and the 1912.Cm not 1913operator will make this rule into a pass-all. 1914.It Addresses 1915.Nm ipfw1 1916does not support address sets or lists of addresses. 1917.Pp 1918.It Port specifications 1919.Nm ipfw1 1920only allows one port range when specifying TCP and UDP ports, and 1921is limited to 10 entries instead of the 30 allowed by 1922.Nm ipfw2 . 1923Also, in 1924.Nm ipfw1 1925you can only specify ports when the rule is requesting 1926.Cm tcp 1927or 1928.Cm udp 1929packets. 1930With 1931.Nm ipfw2 1932you can put port specifications in rules matching all packets, 1933and the match will be attempted only on those packets carrying 1934protocols which include port identifiers. 1935.Pp 1936Finally, 1937.Nm ipfw1 1938allowed the first port entry to be specified as 1939.Ar port:mask 1940where 1941.Ar mask 1942can be an arbitrary 16-bit mask. 1943This syntax is of questionable usefulness and it is not 1944supported anymore in 1945.Nm ipfw2 . 1946.It Or-blocks 1947.Nm ipfw1 1948does not support Or-blocks. 1949.It keepalives 1950.Nm ipfw1 1951does not generate keepalives for stateful sessions. 1952As a consequence, it might cause idle sessions to drop because 1953the lifetime of the dynamic rules expires. 1954.It Sets of rules 1955.Nm ipfw1 1956does not implement sets of rules. 1957.It MAC header filtering and Layer-2 firewalling. 1958.Nm ipfw1 1959does not implement filtering on MAC header fields, nor is it 1960invoked on packets from 1961.Cm ether_demux() 1962and 1963.Cm ether_output_frame(). 1964The sysctl variable 1965.Em net.link.ether.ipfw 1966has no effect there. 1967.It Options 1968In 1969.Nm ipfw1 , 1970the following options only accept a single value as an argument: 1971.Pp 1972.Cm ipid, iplen, ipttl 1973.Pp 1974The following options are not implemented by 1975.Nm ipfw1 : 1976.Pp 1977.Cm dst-ip, dst-port, layer2, mac, mac-type, src-ip, src-port. 1978.Pp 1979Additionally, the RELENG_4 version of 1980.Nm ipfw1 1981does not implement the following options: 1982.Pp 1983.Cm ipid, iplen, ipprecedence, iptos, ipttl, 1984.Cm ipversion, tcpack, tcpseq, tcpwin . 1985.It Dummynet options 1986The following option for 1987.Nm dummynet 1988pipes/queues is not supported: 1989.Cm noerror . 1990.El 1991.Sh EXAMPLES 1992There are far too many possible uses of 1993.Nm 1994so this Section will only give a small set of examples. 1995.Pp 1996.Ss BASIC PACKET FILTERING 1997This command adds an entry which denies all tcp packets from 1998.Em cracker.evil.org 1999to the telnet port of 2000.Em wolf.tambov.su 2001from being forwarded by the host: 2002.Pp 2003.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet" 2004.Pp 2005This one disallows any connection from the entire cracker's 2006network to my host: 2007.Pp 2008.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org" 2009.Pp 2010A first and efficient way to limit access (not using dynamic rules) 2011is the use of the following rules: 2012.Pp 2013.Dl "ipfw add allow tcp from any to any established" 2014.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup" 2015.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup" 2016.Dl "..." 2017.Dl "ipfw add deny tcp from any to any" 2018.Pp 2019The first rule will be a quick match for normal TCP packets, 2020but it will not match the initial SYN packet, which will be 2021matched by the 2022.Cm setup 2023rules only for selected source/destination pairs. 2024All other SYN packets will be rejected by the final 2025.Cm deny 2026rule. 2027.Pp 2028If you administer one or more subnets, you can take advantage of the 2029.Nm ipfw2 2030syntax to specify address sets and or-blocks and write extremely 2031compact rulesets which selectively enable services to blocks 2032of clients, as below: 2033.Pp 2034.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q" 2035.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q" 2036.Dl "" 2037.Dl "ipfw add allow ip from ${goodguys} to any" 2038.Dl "ipfw add deny ip from ${badguys} to any" 2039.Dl "... normal policies ..." 2040.Pp 2041The 2042.Nm ipfw1 2043syntax would require a separate rule for each IP in the above 2044example. 2045.Pp 2046The 2047.Cm verrevpath 2048option could be used to do automated anti-spoofing by adding the 2049following to the top of a ruleset: 2050.Pp 2051.Dl "ipfw add deny ip from any to any not verrevpath in" 2052.Pp 2053This rule drops all incoming packets that appear to be coming to the 2054system on the wrong interface. 2055For example, a packet with a source 2056address belonging to a host on a protected internal network would be 2057dropped if it tried to enter the system from an external interface. 2058.Ss DYNAMIC RULES 2059In order to protect a site from flood attacks involving fake 2060TCP packets, it is safer to use dynamic rules: 2061.Pp 2062.Dl "ipfw add check-state" 2063.Dl "ipfw add deny tcp from any to any established" 2064.Dl "ipfw add allow tcp from my-net to any setup keep-state" 2065.Pp 2066This will let the firewall install dynamic rules only for 2067those connection which start with a regular SYN packet coming 2068from the inside of our network. 2069Dynamic rules are checked when encountering the first 2070.Cm check-state 2071or 2072.Cm keep-state 2073rule. 2074A 2075.Cm check-state 2076rule should usually be placed near the beginning of the 2077ruleset to minimize the amount of work scanning the ruleset. 2078Your mileage may vary. 2079.Pp 2080To limit the number of connections a user can open 2081you can use the following type of rules: 2082.Pp 2083.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10" 2084.Dl "ipfw add allow tcp from any to me setup limit src-addr 4" 2085.Pp 2086The former (assuming it runs on a gateway) will allow each host 2087on a /24 network to open at most 10 TCP connections. 2088The latter can be placed on a server to make sure that a single 2089client does not use more than 4 simultaneous connections. 2090.Pp 2091.Em BEWARE : 2092stateful rules can be subject to denial-of-service attacks 2093by a SYN-flood which opens a huge number of dynamic rules. 2094The effects of such attacks can be partially limited by 2095acting on a set of 2096.Xr sysctl 8 2097variables which control the operation of the firewall. 2098.Pp 2099Here is a good usage of the 2100.Cm list 2101command to see accounting records and timestamp information: 2102.Pp 2103.Dl ipfw -at list 2104.Pp 2105or in short form without timestamps: 2106.Pp 2107.Dl ipfw -a list 2108.Pp 2109which is equivalent to: 2110.Pp 2111.Dl ipfw show 2112.Pp 2113Next rule diverts all incoming packets from 192.168.2.0/24 2114to divert port 5000: 2115.Pp 2116.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in 2117.Pp 2118.Ss TRAFFIC SHAPING 2119The following rules show some of the applications of 2120.Nm 2121and 2122.Xr dummynet 4 2123for simulations and the like. 2124.Pp 2125This rule drops random incoming packets with a probability 2126of 5%: 2127.Pp 2128.Dl "ipfw add prob 0.05 deny ip from any to any in" 2129.Pp 2130A similar effect can be achieved making use of dummynet pipes: 2131.Pp 2132.Dl "ipfw add pipe 10 ip from any to any" 2133.Dl "ipfw pipe 10 config plr 0.05" 2134.Pp 2135We can use pipes to artificially limit bandwidth, e.g.\& on a 2136machine acting as a router, if we want to limit traffic from 2137local clients on 192.168.2.0/24 we do: 2138.Pp 2139.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 2140.Dl "ipfw pipe 1 config bw 300Kbit/s queue 50KBytes" 2141.Pp 2142note that we use the 2143.Cm out 2144modifier so that the rule is not used twice. 2145Remember in fact that 2146.Nm 2147rules are checked both on incoming and outgoing packets. 2148.Pp 2149Should we want to simulate a bidirectional link with bandwidth 2150limitations, the correct way is the following: 2151.Pp 2152.Dl "ipfw add pipe 1 ip from any to any out" 2153.Dl "ipfw add pipe 2 ip from any to any in" 2154.Dl "ipfw pipe 1 config bw 64Kbit/s queue 10Kbytes" 2155.Dl "ipfw pipe 2 config bw 64Kbit/s queue 10Kbytes" 2156.Pp 2157The above can be very useful, e.g.\& if you want to see how 2158your fancy Web page will look for a residential user who 2159is connected only through a slow link. 2160You should not use only one pipe for both directions, unless 2161you want to simulate a half-duplex medium (e.g.\& AppleTalk, 2162Ethernet, IRDA). 2163It is not necessary that both pipes have the same configuration, 2164so we can also simulate asymmetric links. 2165.Pp 2166Should we want to verify network performance with the RED queue 2167management algorithm: 2168.Pp 2169.Dl "ipfw add pipe 1 ip from any to any" 2170.Dl "ipfw pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1" 2171.Pp 2172Another typical application of the traffic shaper is to 2173introduce some delay in the communication. 2174This can significantly affect applications which do a lot of Remote 2175Procedure Calls, and where the round-trip-time of the 2176connection often becomes a limiting factor much more than 2177bandwidth: 2178.Pp 2179.Dl "ipfw add pipe 1 ip from any to any out" 2180.Dl "ipfw add pipe 2 ip from any to any in" 2181.Dl "ipfw pipe 1 config delay 250ms bw 1Mbit/s" 2182.Dl "ipfw pipe 2 config delay 250ms bw 1Mbit/s" 2183.Pp 2184Per-flow queueing can be useful for a variety of purposes. 2185A very simple one is counting traffic: 2186.Pp 2187.Dl "ipfw add pipe 1 tcp from any to any" 2188.Dl "ipfw add pipe 1 udp from any to any" 2189.Dl "ipfw add pipe 1 ip from any to any" 2190.Dl "ipfw pipe 1 config mask all" 2191.Pp 2192The above set of rules will create queues (and collect 2193statistics) for all traffic. 2194Because the pipes have no limitations, the only effect is 2195collecting statistics. 2196Note that we need 3 rules, not just the last one, because 2197when 2198.Nm 2199tries to match IP packets it will not consider ports, so we 2200would not see connections on separate ports as different 2201ones. 2202.Pp 2203A more sophisticated example is limiting the outbound traffic 2204on a net with per-host limits, rather than per-network limits: 2205.Pp 2206.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 2207.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in" 2208.Dl "ipfw pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 2209.Dl "ipfw pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 2210.Ss SETS OF RULES 2211To add a set of rules atomically, e.g.\& set 18: 2212.Pp 2213.Dl "ipfw set disable 18" 2214.Dl "ipfw add NN set 18 ... # repeat as needed" 2215.Dl "ipfw set enable 18" 2216.Pp 2217To delete a set of rules atomically the command is simply: 2218.Pp 2219.Dl "ipfw delete set 18" 2220.Pp 2221To test a ruleset and disable it and regain control if something goes wrong: 2222.Pp 2223.Dl "ipfw set disable 18" 2224.Dl "ipfw add NN set 18 ... # repeat as needed" 2225.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18" 2226.Pp 2227Here if everything goes well, you press control-C before the "sleep" 2228terminates, and your ruleset will be left active. 2229Otherwise, e.g.\& if 2230you cannot access your box, the ruleset will be disabled after 2231the sleep terminates thus restoring the previous situation. 2232.Sh SEE ALSO 2233.Xr cpp 1 , 2234.Xr m4 1 , 2235.Xr bridge 4 , 2236.Xr divert 4 , 2237.Xr dummynet 4 , 2238.Xr ip 4 , 2239.Xr ipfirewall 4 , 2240.Xr protocols 5 , 2241.Xr services 5 , 2242.Xr init 8 , 2243.Xr kldload 8 , 2244.Xr reboot 8 , 2245.Xr sysctl 8 , 2246.Xr syslogd 8 2247.Sh BUGS 2248The syntax has grown over the years and sometimes it might be confusing. 2249Unfortunately, backward compatibility prevents cleaning up mistakes 2250made in the definition of the syntax. 2251.Pp 2252.Em !!! WARNING !!! 2253.Pp 2254Misconfiguring the firewall can put your computer in an unusable state, 2255possibly shutting down network services and requiring console access to 2256regain control of it. 2257.Pp 2258Incoming packet fragments diverted by 2259.Cm divert 2260or 2261.Cm tee 2262are reassembled before delivery to the socket. 2263The action used on those packet is the one from the 2264rule which matches the first fragment of the packet. 2265.Pp 2266Packets that match a 2267.Cm tee 2268rule should not be immediately accepted, but should continue 2269going through the rule list. 2270This may be fixed in a later version. 2271.Pp 2272Packets diverted to userland, and then reinserted by a userland process 2273may lose various packet attributes. 2274The packet source interface name 2275will be preserved if it is shorter than 8 bytes and the userland process 2276saves and reuses the sockaddr_in 2277(as does 2278.Xr natd 8 ) ; 2279otherwise, it may be lost. 2280If a packet is reinserted in this manner, later rules may be incorrectly 2281applied, making the order of 2282.Cm divert 2283rules in the rule sequence very important. 2284.Sh AUTHORS 2285.An Ugen J. S. Antsilevich , 2286.An Poul-Henning Kamp , 2287.An Alex Nash , 2288.An Archie Cobbs , 2289.An Luigi Rizzo . 2290.Pp 2291.An -nosplit 2292API based upon code written by 2293.An Daniel Boulet 2294for BSDI. 2295.Pp 2296Work on 2297.Xr dummynet 4 2298traffic shaper supported by Akamba Corp. 2299.Sh HISTORY 2300The 2301.Nm 2302utility first appeared in 2303.Fx 2.0 . 2304.Xr dummynet 4 2305was introduced in 2306.Fx 2.2.8 . 2307Stateful extensions were introduced in 2308.Fx 4.0 . 2309.Nm ipfw2 2310was introduced in Summer 2002. 2311