1.\" 2.\" $FreeBSD$ 3.\" 4.Dd April 25, 2023 5.Dt IPFW 8 6.Os 7.Sh NAME 8.Nm ipfw , dnctl 9.Nd User interface for firewall, traffic shaper, packet scheduler, 10in-kernel NAT. 11.Sh SYNOPSIS 12.Ss FIREWALL CONFIGURATION 13.Nm 14.Op Fl cq 15.Cm add 16.Ar rule 17.Nm 18.Op Fl acdefnNStT 19.Op Cm set Ar N 20.Brq Cm list | show 21.Op Ar rule | first-last ... 22.Nm 23.Op Fl f | q 24.Op Cm set Ar N 25.Cm flush 26.Nm 27.Op Fl q 28.Op Cm set Ar N 29.Brq Cm delete | zero | resetlog 30.Op Ar number ... 31.Pp 32.Nm 33.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 34.Nm 35.Cm set move 36.Op Cm rule 37.Ar number Cm to Ar number 38.Nm 39.Cm set swap Ar number number 40.Nm 41.Cm set show 42.Ss SYSCTL SHORTCUTS 43.Nm 44.Cm enable 45.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive 46.Nm 47.Cm disable 48.Brq Cm firewall | altq | one_pass | debug | verbose | dyn_keepalive 49.Ss LOOKUP TABLES 50.Nm 51.Oo Cm set Ar N Oc Cm table Ar name Cm create Ar create-options 52.Nm 53.Oo Cm set Ar N Oc Cm table 54.Brq Ar name | all 55.Cm destroy 56.Nm 57.Oo Cm set Ar N Oc Cm table Ar name Cm modify Ar modify-options 58.Nm 59.Oo Cm set Ar N Oc Cm table Ar name Cm swap Ar name 60.Nm 61.Oo Cm set Ar N Oc Cm table Ar name Cm add Ar table-key Op Ar value 62.Nm 63.Oo Cm set Ar N Oc Cm table Ar name Cm add Op Ar table-key Ar value ... 64.Nm 65.Oo Cm set Ar N Oc Cm table Ar name Cm atomic add Op Ar table-key Ar value ... 66.Nm 67.Oo Cm set Ar N Oc Cm table Ar name Cm delete Op Ar table-key ... 68.Nm 69.Oo Cm set Ar N Oc Cm table Ar name Cm lookup Ar addr 70.Nm 71.Oo Cm set Ar N Oc Cm table Ar name Cm lock 72.Nm 73.Oo Cm set Ar N Oc Cm table Ar name Cm unlock 74.Nm 75.Oo Cm set Ar N Oc Cm table 76.Brq Ar name | all 77.Cm list 78.Nm 79.Oo Cm set Ar N Oc Cm table 80.Brq Ar name | all 81.Cm info 82.Nm 83.Oo Cm set Ar N Oc Cm table 84.Brq Ar name | all 85.Cm detail 86.Nm 87.Oo Cm set Ar N Oc Cm table 88.Brq Ar name | all 89.Cm flush 90.Ss DUMMYNET CONFIGURATION (TRAFFIC SHAPER AND PACKET SCHEDULER) 91.Nm dnctl 92.Brq Cm pipe | queue | sched 93.Ar number 94.Cm config 95.Ar config-options 96.Nm dnctl 97.Op Fl s Op Ar field 98.Brq Cm pipe | queue | sched 99.Brq Cm delete | list | show 100.Op Ar number ... 101.Ss IN-KERNEL NAT 102.Nm 103.Op Fl q 104.Cm nat 105.Ar number 106.Cm config 107.Ar config-options 108.Nm 109.Cm nat 110.Ar number 111.Cm show 112.Brq Cm config | log 113.Ss STATEFUL IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 114.Nm 115.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm create Ar create-options 116.Nm 117.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm config Ar config-options 118.Nm 119.Oo Cm set Ar N Oc Cm nat64lsn 120.Brq Ar name | all 121.Brq Cm list | show 122.Op Cm states 123.Nm 124.Oo Cm set Ar N Oc Cm nat64lsn 125.Brq Ar name | all 126.Cm destroy 127.Nm 128.Oo Cm set Ar N Oc Cm nat64lsn Ar name Cm stats Op Cm reset 129.Ss STATELESS IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 130.Nm 131.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm create Ar create-options 132.Nm 133.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm config Ar config-options 134.Nm 135.Oo Cm set Ar N Oc Cm nat64stl 136.Brq Ar name | all 137.Brq Cm list | show 138.Nm 139.Oo Cm set Ar N Oc Cm nat64stl 140.Brq Ar name | all 141.Cm destroy 142.Nm 143.Oo Cm set Ar N Oc Cm nat64stl Ar name Cm stats Op Cm reset 144.Ss XLAT464 CLAT IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 145.Nm 146.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm create Ar create-options 147.Nm 148.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm config Ar config-options 149.Nm 150.Oo Cm set Ar N Oc Cm nat64clat 151.Brq Ar name | all 152.Brq Cm list | show 153.Nm 154.Oo Cm set Ar N Oc Cm nat64clat 155.Brq Ar name | all 156.Cm destroy 157.Nm 158.Oo Cm set Ar N Oc Cm nat64clat Ar name Cm stats Op Cm reset 159.Ss IPv6-to-IPv6 NETWORK PREFIX TRANSLATION 160.Nm 161.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm create Ar create-options 162.Nm 163.Oo Cm set Ar N Oc Cm nptv6 164.Brq Ar name | all 165.Brq Cm list | show 166.Nm 167.Oo Cm set Ar N Oc Cm nptv6 168.Brq Ar name | all 169.Cm destroy 170.Nm 171.Oo Cm set Ar N Oc Cm nptv6 Ar name Cm stats Op Cm reset 172.Ss INTERNAL DIAGNOSTICS 173.Nm 174.Cm internal iflist 175.Nm 176.Cm internal talist 177.Nm 178.Cm internal vlist 179.Ss LIST OF RULES AND PREPROCESSING 180.Nm 181.Op Fl cfnNqS 182.Oo 183.Fl p Ar preproc 184.Oo 185.Ar preproc-flags 186.Oc 187.Oc 188.Ar pathname 189.Sh DESCRIPTION 190The 191.Nm 192utility is the user interface for controlling the 193.Xr ipfw 4 194firewall, the 195.Xr dummynet 4 196traffic shaper/packet scheduler, and the 197in-kernel NAT services. 198.Pp 199A firewall configuration, or 200.Em ruleset , 201is made of a list of 202.Em rules 203numbered from 1 to 65535. 204Packets are passed to the firewall 205from a number of different places in the protocol stack 206(depending on the source and destination of the packet, 207it is possible for the firewall to be 208invoked multiple times on the same packet). 209The packet passed to the firewall is compared 210against each of the rules in the 211.Em ruleset , 212in rule-number order 213(multiple rules with the same number are permitted, in which case 214they are processed in order of insertion). 215When a match is found, the action corresponding to the 216matching rule is performed. 217.Pp 218Depending on the action and certain system settings, packets 219can be reinjected into the firewall at some rule after the 220matching one for further processing. 221.Pp 222A ruleset always includes a 223.Em default 224rule (numbered 65535) which cannot be modified or deleted, 225and matches all packets. 226The action associated with the 227.Em default 228rule can be either 229.Cm deny 230or 231.Cm allow 232depending on how the kernel is configured. 233.Pp 234If the ruleset includes one or more rules with the 235.Cm keep-state , 236.Cm record-state , 237.Cm limit 238or 239.Cm set-limit 240option, 241the firewall will have a 242.Em stateful 243behaviour, i.e., upon a match it will create 244.Em dynamic rules , 245i.e., rules that match packets with the same 5-tuple 246(protocol, source and destination addresses and ports) 247as the packet which caused their creation. 248Dynamic rules, which have a limited lifetime, are checked 249at the first occurrence of a 250.Cm check-state , 251.Cm keep-state 252or 253.Cm limit 254rule, and are typically used to open the firewall on-demand to 255legitimate traffic only. 256Please note, that 257.Cm keep-state 258and 259.Cm limit 260imply implicit 261.Cm check-state 262for all packets (not only these matched by the rule) but 263.Cm record-state 264and 265.Cm set-limit 266have no implicit 267.Cm check-state . 268See the 269.Sx STATEFUL FIREWALL 270and 271.Sx EXAMPLES 272Sections below for more information on the stateful behaviour of 273.Nm . 274.Pp 275All rules (including dynamic ones) have a few associated counters: 276a packet count, a byte count, a log count and a timestamp 277indicating the time of the last match. 278Counters can be displayed or reset with 279.Nm 280commands. 281.Pp 282Each rule belongs to one of 32 different 283.Em sets 284, and there are 285.Nm 286commands to atomically manipulate sets, such as enable, 287disable, swap sets, move all rules in a set to another 288one, delete all rules in a set. 289These can be useful to 290install temporary configurations, or to test them. 291See Section 292.Sx SETS OF RULES 293for more information on 294.Em sets . 295.Pp 296Rules can be added with the 297.Cm add 298command; deleted individually or in groups with the 299.Cm delete 300command, and globally (except those in set 31) with the 301.Cm flush 302command; displayed, optionally with the content of the 303counters, using the 304.Cm show 305and 306.Cm list 307commands. 308Finally, counters can be reset with the 309.Cm zero 310and 311.Cm resetlog 312commands. 313.Ss COMMAND OPTIONS 314The following general options are available when invoking 315.Nm : 316.Bl -tag -width indent 317.It Fl a 318Show counter values when listing rules. 319The 320.Cm show 321command implies this option. 322.It Fl b 323Only show the action and the comment, not the body of a rule. 324Implies 325.Fl c . 326.It Fl c 327When entering or showing rules, print them in compact form, 328i.e., omitting the "ip from any to any" string 329when this does not carry any additional information. 330.It Fl d 331When listing, show dynamic rules in addition to static ones. 332.It Fl D 333When listing, show only dynamic states. 334When deleting, delete only dynamic states. 335.It Fl f 336Run without prompting for confirmation for commands that can cause problems if misused, 337i.e., 338.Cm flush . 339If there is no tty associated with the process, this is implied. 340The 341.Cm delete 342command with this flag ignores possible errors, 343i.e., nonexistent rule number. 344And for batched commands execution continues with the next command. 345.It Fl i 346When listing a table (see the 347.Sx LOOKUP TABLES 348section below for more information on lookup tables), format values 349as IP addresses. 350By default, values are shown as integers. 351.It Fl n 352Only check syntax of the command strings, without actually passing 353them to the kernel. 354.It Fl N 355Try to resolve addresses and service names in output. 356.It Fl q 357Be quiet when executing the 358.Cm add , 359.Cm nat , 360.Cm zero , 361.Cm resetlog 362or 363.Cm flush 364commands; 365(implies 366.Fl f ) . 367This is useful when updating rulesets by executing multiple 368.Nm 369commands in a script 370(e.g., 371.Ql sh\ /etc/rc.firewall ) , 372or by processing a file with many 373.Nm 374rules across a remote login session. 375It also stops a table add or delete 376from failing if the entry already exists or is not present. 377.Pp 378The reason why this option may be important is that 379for some of these actions, 380.Nm 381may print a message; if the action results in blocking the 382traffic to the remote client, 383the remote login session will be closed 384and the rest of the ruleset will not be processed. 385Access to the console would then be required to recover. 386.It Fl S 387When listing rules, show the 388.Em set 389each rule belongs to. 390If this flag is not specified, disabled rules will not be 391listed. 392.It Fl s Op Ar field 393When listing pipes, sort according to one of the four 394counters (total or current packets or bytes). 395.It Fl t 396When listing, show last match timestamp converted with 397.Fn ctime . 398.It Fl T 399When listing, show last match timestamp as seconds from the epoch. 400This form can be more convenient for postprocessing by scripts. 401.El 402.Ss LIST OF RULES AND PREPROCESSING 403To ease configuration, rules can be put into a file which is 404processed using 405.Nm 406as shown in the last synopsis line. 407An absolute 408.Ar pathname 409must be used. 410The file will be read line by line and applied as arguments to the 411.Nm 412utility. 413.Pp 414Optionally, a preprocessor can be specified using 415.Fl p Ar preproc 416where 417.Ar pathname 418is to be piped through. 419Useful preprocessors include 420.Xr cpp 1 421and 422.Xr m4 1 . 423If 424.Ar preproc 425does not start with a slash 426.Pq Ql / 427as its first character, the usual 428.Ev PATH 429name search is performed. 430Care should be taken with this in environments where not all 431file systems are mounted (yet) by the time 432.Nm 433is being run (e.g.\& when they are mounted over NFS). 434Once 435.Fl p 436has been specified, any additional arguments are passed on to the preprocessor 437for interpretation. 438This allows for flexible configuration files (like conditionalizing 439them on the local hostname) and the use of macros to centralize 440frequently required arguments like IP addresses. 441.Ss TRAFFIC SHAPER CONFIGURATION 442The 443.Nm dnctl 444.Cm pipe , queue 445and 446.Cm sched 447commands are used to configure the traffic shaper and packet scheduler. 448See the 449.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 450Section below for details. 451.Pp 452If the world and the kernel get out of sync the 453.Nm 454ABI may break, preventing you from being able to add any rules. 455This can adversely affect the booting process. 456You can use 457.Nm 458.Cm disable 459.Cm firewall 460to temporarily disable the firewall to regain access to the network, 461allowing you to fix the problem. 462.Sh PACKET FLOW 463A packet is checked against the active ruleset in multiple places 464in the protocol stack, under control of several sysctl variables. 465These places and variables are shown below, and it is important to 466have this picture in mind in order to design a correct ruleset. 467.Bd -literal -offset indent 468 ^ to upper layers V 469 | | 470 +----------->-----------+ 471 ^ V 472 [ip(6)_input] [ip(6)_output] net.inet(6).ip(6).fw.enable=1 473 | | 474 ^ V 475 [ether_demux] [ether_output_frame] net.link.ether.ipfw=1 476 | | 477 +-->--[bdg_forward]-->--+ net.link.bridge.ipfw=1 478 ^ V 479 | to devices | 480.Ed 481.Pp 482The number of 483times the same packet goes through the firewall can 484vary between 0 and 4 depending on packet source and 485destination, and system configuration. 486.Pp 487Note that as packets flow through the stack, headers can be 488stripped or added to it, and so they may or may not be available 489for inspection. 490E.g., incoming packets will include the MAC header when 491.Nm 492is invoked from 493.Cm ether_demux() , 494but the same packets will have the MAC header stripped off when 495.Nm 496is invoked from 497.Cm ip_input() 498or 499.Cm ip6_input() . 500.Pp 501Also note that each packet is always checked against the complete ruleset, 502irrespective of the place where the check occurs, or the source of the packet. 503If a rule contains some match patterns or actions which are not valid 504for the place of invocation (e.g.\& trying to match a MAC header within 505.Cm ip_input 506or 507.Cm ip6_input ), 508the match pattern will not match, but a 509.Cm not 510operator in front of such patterns 511.Em will 512cause the pattern to 513.Em always 514match on those packets. 515It is thus the responsibility of 516the programmer, if necessary, to write a suitable ruleset to 517differentiate among the possible places. 518.Cm skipto 519rules can be useful here, as an example: 520.Bd -literal -offset indent 521# packets from ether_demux or bdg_forward 522ipfw add 10 skipto 1000 all from any to any layer2 in 523# packets from ip_input 524ipfw add 10 skipto 2000 all from any to any not layer2 in 525# packets from ip_output 526ipfw add 10 skipto 3000 all from any to any not layer2 out 527# packets from ether_output_frame 528ipfw add 10 skipto 4000 all from any to any layer2 out 529.Ed 530.Pp 531(yes, at the moment there is no way to differentiate between 532ether_demux and bdg_forward). 533.Pp 534Also note that only actions 535.Cm allow , 536.Cm deny , 537.Cm netgraph , 538.Cm ngtee 539and related to 540.Cm dummynet 541are processed for 542.Cm layer2 543frames and all other actions act as if they were 544.Cm allow 545for such frames. 546Full set of actions is supported for IP packets without 547.Cm layer2 548headers only. 549For example, 550.Cm divert 551action does not divert 552.Cm layer2 553frames. 554.Sh SYNTAX 555In general, each keyword or argument must be provided as 556a separate command line argument, with no leading or trailing 557spaces. 558Keywords are case-sensitive, whereas arguments may 559or may not be case-sensitive depending on their nature 560(e.g.\& uid's are, hostnames are not). 561.Pp 562Some arguments (e.g., port or address lists) are comma-separated 563lists of values. 564In this case, spaces after commas ',' are allowed to make 565the line more readable. 566You can also put the entire 567command (including flags) into a single argument. 568E.g., the following forms are equivalent: 569.Bd -literal -offset indent 570ipfw -q add deny src-ip 10.0.0.0/24,127.0.0.1/8 571ipfw -q add deny src-ip 10.0.0.0/24, 127.0.0.1/8 572ipfw "-q add deny src-ip 10.0.0.0/24, 127.0.0.1/8" 573.Ed 574.Sh RULE FORMAT 575The format of firewall rules is the following: 576.Bd -ragged -offset indent 577.Bk -words 578.Op Ar rule_number 579.Op Cm set Ar set_number 580.Op Cm prob Ar match_probability 581.Ar action 582.Op Cm log Op Cm logamount Ar number 583.Op Cm altq Ar queue 584.Oo 585.Bro Cm tag | untag 586.Brc Ar number 587.Oc 588.Ar body 589.Ek 590.Ed 591.Pp 592where the body of the rule specifies which information is used 593for filtering packets, among the following: 594.Pp 595.Bl -tag -width "Source and dest. addresses and ports" -offset XXX -compact 596.It Layer2 header fields 597When available 598.It IPv4 and IPv6 Protocol 599SCTP, TCP, UDP, ICMP, etc. 600.It Source and dest. addresses and ports 601.It Direction 602See Section 603.Sx PACKET FLOW 604.It Transmit and receive interface 605By name or address 606.It Misc. IP header fields 607Version, type of service, datagram length, identification, 608fragmentation flags, 609Time To Live 610.It IP options 611.It IPv6 Extension headers 612Fragmentation, Hop-by-Hop options, 613Routing Headers, Source routing rthdr0, Mobile IPv6 rthdr2, IPSec options. 614.It IPv6 Flow-ID 615.It Misc. TCP header fields 616TCP flags (SYN, FIN, ACK, RST, etc.), 617sequence number, acknowledgment number, 618window 619.It TCP options 620.It ICMP types 621for ICMP packets 622.It ICMP6 types 623for ICMP6 packets 624.It User/group ID 625When the packet can be associated with a local socket. 626.It Divert status 627Whether a packet came from a divert socket (e.g., 628.Xr natd 8 ) . 629.It Fib annotation state 630Whether a packet has been tagged for using a specific FIB (routing table) 631in future forwarding decisions. 632.El 633.Pp 634Note that some of the above information, e.g.\& source MAC or IP addresses and 635TCP/UDP ports, can be easily spoofed, so filtering on those fields 636alone might not guarantee the desired results. 637.Bl -tag -width indent 638.It Ar rule_number 639Each rule is associated with a 640.Ar rule_number 641in the range 1..65535, with the latter reserved for the 642.Em default 643rule. 644Rules are checked sequentially by rule number. 645Multiple rules can have the same number, in which case they are 646checked (and listed) according to the order in which they have 647been added. 648If a rule is entered without specifying a number, the kernel will 649assign one in such a way that the rule becomes the last one 650before the 651.Em default 652rule. 653Automatic rule numbers are assigned by incrementing the last 654non-default rule number by the value of the sysctl variable 655.Ar net.inet.ip.fw.autoinc_step 656which defaults to 100. 657If this is not possible (e.g.\& because we would go beyond the 658maximum allowed rule number), the number of the last 659non-default value is used instead. 660.It Cm set Ar set_number 661Each rule is associated with a 662.Ar set_number 663in the range 0..31. 664Sets can be individually disabled and enabled, so this parameter 665is of fundamental importance for atomic ruleset manipulation. 666It can be also used to simplify deletion of groups of rules. 667If a rule is entered without specifying a set number, 668set 0 will be used. 669.br 670Set 31 is special in that it cannot be disabled, 671and rules in set 31 are not deleted by the 672.Nm ipfw flush 673command (but you can delete them with the 674.Nm ipfw delete set 31 675command). 676Set 31 is also used for the 677.Em default 678rule. 679.It Cm prob Ar match_probability 680A match is only declared with the specified probability 681(floating point number between 0 and 1). 682This can be useful for a number of applications such as 683random packet drop or 684(in conjunction with 685.Nm dummynet ) 686to simulate the effect of multiple paths leading to out-of-order 687packet delivery. 688.Pp 689Note: this condition is checked before any other condition, including 690ones such as 691.Cm keep-state 692or 693.Cm check-state 694which might have 695side effects. 696.It Cm log Op Cm logamount Ar number 697Packets matching a rule with the 698.Cm log 699keyword will be made available for logging in two ways: 700if the sysctl variable 701.Va net.inet.ip.fw.verbose 702is set to 0 (default), one can use 703.Xr bpf 4 704attached to the 705.Li ipfw0 706pseudo interface. 707This pseudo interface can be created manually after a system 708boot by using the following command: 709.Bd -literal -offset indent 710# ifconfig ipfw0 create 711.Ed 712.Pp 713Or, automatically at boot time by adding the following 714line to the 715.Xr rc.conf 5 716file: 717.Bd -literal -offset indent 718firewall_logif="YES" 719.Ed 720.Pp 721There is zero overhead when no 722.Xr bpf 4 723is attached to the pseudo interface. 724.Pp 725If 726.Va net.inet.ip.fw.verbose 727is set to 1, packets will be logged to 728.Xr syslogd 8 729with a 730.Dv LOG_SECURITY 731facility up to a maximum of 732.Cm logamount 733packets. 734If no 735.Cm logamount 736is specified, the limit is taken from the sysctl variable 737.Va net.inet.ip.fw.verbose_limit . 738In both cases, a value of 0 means unlimited logging. 739.Pp 740Once the limit is reached, logging can be re-enabled by 741clearing the logging counter or the packet counter for that entry, see the 742.Cm resetlog 743command. 744.Pp 745Note: logging is done after all other packet matching conditions 746have been successfully verified, and before performing the final 747action (accept, deny, etc.) on the packet. 748.It Cm tag Ar number 749When a packet matches a rule with the 750.Cm tag 751keyword, the numeric tag for the given 752.Ar number 753in the range 1..65534 will be attached to the packet. 754The tag acts as an internal marker (it is not sent out over 755the wire) that can be used to identify these packets later on. 756This can be used, for example, to provide trust between interfaces 757and to start doing policy-based filtering. 758A packet can have multiple tags at the same time. 759Tags are "sticky", meaning once a tag is applied to a packet by a 760matching rule it exists until explicit removal. 761Tags are kept with the packet everywhere within the kernel, but are 762lost when the packet leaves the kernel, for example, on transmitting 763packet out to the network or sending packet to a 764.Xr divert 4 765socket. 766.Pp 767To check for previously applied tags, use the 768.Cm tagged 769rule option. 770To delete previously applied tag, use the 771.Cm untag 772keyword. 773.Pp 774Note: since tags are kept with the packet everywhere in kernelspace, 775they can be set and unset anywhere in the kernel network subsystem 776(using the 777.Xr mbuf_tags 9 778facility), not only by means of the 779.Xr ipfw 4 780.Cm tag 781and 782.Cm untag 783keywords. 784For example, there can be a specialized 785.Xr netgraph 4 786node doing traffic analyzing and tagging for later inspecting 787in firewall. 788.It Cm untag Ar number 789When a packet matches a rule with the 790.Cm untag 791keyword, the tag with the number 792.Ar number 793is searched among the tags attached to this packet and, 794if found, removed from it. 795Other tags bound to packet, if present, are left untouched. 796.It Cm setmark Ar value | tablearg 797When a packet matches a rule with the 798.Cm setmark 799keyword, a 32-bit numeric mark is assigned to the packet. 800The mark is an extension to the tags. 801As tags, mark is "sticky" so the value is kept the same within the kernel and 802is lost when the packet leaves the kernel. 803Unlike tags, mark can be matched as a lookup table key or compared with bitwise 804mask applied against another value. 805Each packet can have only one mark, so 806.Cm setmark 807always overwrites the previous mark value. 808.Pp 809The initial mark value is 0. 810To check the current mark value, use the 811.Cm mark 812rule option. 813Mark 814.Ar value 815can be entered as decimal or hexadecimal (if prefixed by 0x), and they 816are always printed as hexadecimal. 817.It Cm altq Ar queue 818When a packet matches a rule with the 819.Cm altq 820keyword, the ALTQ identifier for the given 821.Ar queue 822(see 823.Xr altq 4 ) 824will be attached. 825Note that this ALTQ tag is only meaningful for packets going "out" of IPFW, 826and not being rejected or going to divert sockets. 827Note that if there is insufficient memory at the time the packet is 828processed, it will not be tagged, so it is wise to make your ALTQ 829"default" queue policy account for this. 830If multiple 831.Cm altq 832rules match a single packet, only the first one adds the ALTQ classification 833tag. 834In doing so, traffic may be shaped by using 835.Cm count Cm altq Ar queue 836rules for classification early in the ruleset, then later applying 837the filtering decision. 838For example, 839.Cm check-state 840and 841.Cm keep-state 842rules may come later and provide the actual filtering decisions in 843addition to the fallback ALTQ tag. 844.Pp 845You must run 846.Xr pfctl 8 847to set up the queues before IPFW will be able to look them up by name, 848and if the ALTQ disciplines are rearranged, the rules in containing the 849queue identifiers in the kernel will likely have gone stale and need 850to be reloaded. 851Stale queue identifiers will probably result in misclassification. 852.Pp 853All system ALTQ processing can be turned on or off via 854.Nm 855.Cm enable Ar altq 856and 857.Nm 858.Cm disable Ar altq . 859The usage of 860.Va net.inet.ip.fw.one_pass 861is irrelevant to ALTQ traffic shaping, as the actual rule action is followed 862always after adding an ALTQ tag. 863.El 864.Ss RULE ACTIONS 865A rule can be associated with one of the following actions, which 866will be executed when the packet matches the body of the rule. 867.Bl -tag -width indent 868.It Cm allow | accept | pass | permit 869Allow packets that match rule. 870The search terminates. 871.It Cm check-state Op Ar :flowname | Cm :any 872Checks the packet against the dynamic ruleset. 873If a match is found, execute the action associated with 874the rule which generated this dynamic rule, otherwise 875move to the next rule. 876.br 877.Cm Check-state 878rules do not have a body. 879If no 880.Cm check-state 881rule is found, the dynamic ruleset is checked at the first 882.Cm keep-state 883or 884.Cm limit 885rule. 886The 887.Ar :flowname 888is symbolic name assigned to dynamic rule by 889.Cm keep-state 890opcode. 891The special flowname 892.Cm :any 893can be used to ignore states flowname when matching. 894The 895.Cm :default 896keyword is special name used for compatibility with old rulesets. 897.It Cm count 898Update counters for all packets that match rule. 899The search continues with the next rule. 900.It Cm deny | drop 901Discard packets that match this rule. 902The search terminates. 903.It Cm divert Ar port 904Divert packets that match this rule to the 905.Xr divert 4 906socket bound to port 907.Ar port . 908The search terminates. 909.It Cm fwd | forward Ar ipaddr | tablearg Ns Op , Ns Ar port 910Change the next-hop on matching packets to 911.Ar ipaddr , 912which can be an IP address or a host name. 913The next hop can also be supplied by the last table 914looked up for the packet by using the 915.Cm tablearg 916keyword instead of an explicit address. 917The search terminates if this rule matches. 918.Pp 919If 920.Ar ipaddr 921is a local address, then matching packets will be forwarded to 922.Ar port 923(or the port number in the packet if one is not specified in the rule) 924on the local machine. 925.br 926If 927.Ar ipaddr 928is not a local address, then the port number 929(if specified) is ignored, and the packet will be 930forwarded to the remote address, using the route as found in 931the local routing table for that IP. 932.br 933A 934.Ar fwd 935rule will not match layer2 packets (those received 936on ether_input, ether_output, or bridged). 937.br 938The 939.Cm fwd 940action does not change the contents of the packet at all. 941In particular, the destination address remains unmodified, so 942packets forwarded to another system will usually be rejected by that system 943unless there is a matching rule on that system to capture them. 944For packets forwarded locally, 945the local address of the socket will be 946set to the original destination address of the packet. 947This makes the 948.Xr netstat 1 949entry look rather weird but is intended for 950use with transparent proxy servers. 951.It Cm nat Ar nat_nr | global | tablearg 952Pass packet to a 953nat instance 954(for network address translation, address redirect, etc.): 955see the 956.Sx NETWORK ADDRESS TRANSLATION (NAT) 957Section for further information. 958.It Cm nat64lsn Ar name 959Pass packet to a stateful NAT64 instance (for IPv6/IPv4 network address and 960protocol translation): see the 961.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 962Section for further information. 963.It Cm nat64stl Ar name 964Pass packet to a stateless NAT64 instance (for IPv6/IPv4 network address and 965protocol translation): see the 966.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 967Section for further information. 968.It Cm nat64clat Ar name 969Pass packet to a CLAT NAT64 instance (for client-side IPv6/IPv4 network address and 970protocol translation): see the 971.Sx IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 972Section for further information. 973.It Cm nptv6 Ar name 974Pass packet to a NPTv6 instance (for IPv6-to-IPv6 network prefix translation): 975see the 976.Sx IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6) 977Section for further information. 978.It Cm pipe Ar pipe_nr 979Pass packet to a 980.Nm dummynet 981.Dq pipe 982(for bandwidth limitation, delay, etc.). 983See the 984.Sx TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 985Section for further information. 986The search terminates; however, on exit from the pipe and if 987the 988.Xr sysctl 8 989variable 990.Va net.inet.ip.fw.one_pass 991is not set, the packet is passed again to the firewall code 992starting from the next rule. 993.It Cm queue Ar queue_nr 994Pass packet to a 995.Nm dummynet 996.Dq queue 997(for bandwidth limitation using WF2Q+). 998.It Cm reject 999(Deprecated). 1000Synonym for 1001.Cm unreach host . 1002.It Cm reset 1003Discard packets that match this rule, and if the 1004packet is a TCP packet, try to send a TCP reset (RST) notice. 1005The search terminates. 1006.It Cm reset6 1007Discard packets that match this rule, and if the 1008packet is a TCP packet, try to send a TCP reset (RST) notice. 1009The search terminates. 1010.It Cm skipto Ar number | tablearg 1011Skip all subsequent rules numbered less than 1012.Ar number . 1013The search continues with the first rule numbered 1014.Ar number 1015or higher. 1016It is possible to use the 1017.Cm tablearg 1018keyword with a skipto for a 1019.Em computed 1020skipto. 1021Skipto may work either in O(log(N)) or in O(1) depending 1022on amount of memory and/or sysctl variables. 1023See the 1024.Sx SYSCTL VARIABLES 1025section for more details. 1026.It Cm call Ar number | tablearg 1027The current rule number is saved in the internal stack and 1028ruleset processing continues with the first rule numbered 1029.Ar number 1030or higher. 1031If later a rule with the 1032.Cm return 1033action is encountered, the processing returns to the first rule 1034with number of this 1035.Cm call 1036rule plus one or higher 1037(the same behaviour as with packets returning from 1038.Xr divert 4 1039socket after a 1040.Cm divert 1041action). 1042This could be used to make somewhat like an assembly language 1043.Dq subroutine 1044calls to rules with common checks for different interfaces, etc. 1045.Pp 1046Rule with any number could be called, not just forward jumps as with 1047.Cm skipto . 1048So, to prevent endless loops in case of mistakes, both 1049.Cm call 1050and 1051.Cm return 1052actions don't do any jumps and simply go to the next rule if memory 1053cannot be allocated or stack overflowed/underflowed. 1054.Pp 1055Internally stack for rule numbers is implemented using 1056.Xr mbuf_tags 9 1057facility and currently has size of 16 entries. 1058As mbuf tags are lost when packet leaves the kernel, 1059.Cm divert 1060should not be used in subroutines to avoid endless loops 1061and other undesired effects. 1062.It Cm return 1063Takes rule number saved to internal stack by the last 1064.Cm call 1065action and returns ruleset processing to the first rule 1066with number greater than number of corresponding 1067.Cm call 1068rule. 1069See description of the 1070.Cm call 1071action for more details. 1072.Pp 1073Note that 1074.Cm return 1075rules usually end a 1076.Dq subroutine 1077and thus are unconditional, but 1078.Nm 1079command-line utility currently requires every action except 1080.Cm check-state 1081to have body. 1082While it is sometimes useful to return only on some packets, 1083usually you want to print just 1084.Dq return 1085for readability. 1086A workaround for this is to use new syntax and 1087.Fl c 1088switch: 1089.Bd -literal -offset indent 1090# Add a rule without actual body 1091ipfw add 2999 return via any 1092 1093# List rules without "from any to any" part 1094ipfw -c list 1095.Ed 1096.Pp 1097This cosmetic annoyance may be fixed in future releases. 1098.It Cm tee Ar port 1099Send a copy of packets matching this rule to the 1100.Xr divert 4 1101socket bound to port 1102.Ar port . 1103The search continues with the next rule. 1104.It Cm unreach Ar code Op mtu 1105Discard packets that match this rule, and try to send an ICMP 1106unreachable notice with code 1107.Ar code , 1108where 1109.Ar code 1110is a number from 0 to 255, or one of these aliases: 1111.Cm net , host , protocol , port , 1112.Cm needfrag , srcfail , net-unknown , host-unknown , 1113.Cm isolated , net-prohib , host-prohib , tosnet , 1114.Cm toshost , filter-prohib , host-precedence 1115or 1116.Cm precedence-cutoff . 1117The 1118.Cm needfrag 1119code may have an optional 1120.Ar mtu 1121parameter. 1122If specified, the MTU value will be put into generated ICMP packet. 1123The search terminates. 1124.It Cm unreach6 Ar code 1125Discard packets that match this rule, and try to send an ICMPv6 1126unreachable notice with code 1127.Ar code , 1128where 1129.Ar code 1130is a number from 0, 1, 3 or 4, or one of these aliases: 1131.Cm no-route, admin-prohib, address 1132or 1133.Cm port . 1134The search terminates. 1135.It Cm netgraph Ar cookie 1136Divert packet into netgraph with given 1137.Ar cookie . 1138The search terminates. 1139If packet is later returned from netgraph it is either 1140accepted or continues with the next rule, depending on 1141.Va net.inet.ip.fw.one_pass 1142sysctl variable. 1143.It Cm ngtee Ar cookie 1144A copy of packet is diverted into netgraph, original 1145packet continues with the next rule. 1146See 1147.Xr ng_ipfw 4 1148for more information on 1149.Cm netgraph 1150and 1151.Cm ngtee 1152actions. 1153.It Cm setfib Ar fibnum | tablearg 1154The packet is tagged so as to use the FIB (routing table) 1155.Ar fibnum 1156in any subsequent forwarding decisions. 1157In the current implementation, this is limited to the values 0 through 15, see 1158.Xr setfib 2 . 1159Processing continues at the next rule. 1160It is possible to use the 1161.Cm tablearg 1162keyword with setfib. 1163If the tablearg value is not within the compiled range of fibs, 1164the packet's fib is set to 0. 1165.It Cm setdscp Ar DSCP | number | tablearg 1166Set specified DiffServ codepoint for an IPv4/IPv6 packet. 1167Processing continues at the next rule. 1168Supported values are: 1169.Pp 1170.Cm cs0 1171.Pq Dv 000000 , 1172.Cm cs1 1173.Pq Dv 001000 , 1174.Cm cs2 1175.Pq Dv 010000 , 1176.Cm cs3 1177.Pq Dv 011000 , 1178.Cm cs4 1179.Pq Dv 100000 , 1180.Cm cs5 1181.Pq Dv 101000 , 1182.Cm cs6 1183.Pq Dv 110000 , 1184.Cm cs7 1185.Pq Dv 111000 , 1186.Cm af11 1187.Pq Dv 001010 , 1188.Cm af12 1189.Pq Dv 001100 , 1190.Cm af13 1191.Pq Dv 001110 , 1192.Cm af21 1193.Pq Dv 010010 , 1194.Cm af22 1195.Pq Dv 010100 , 1196.Cm af23 1197.Pq Dv 010110 , 1198.Cm af31 1199.Pq Dv 011010 , 1200.Cm af32 1201.Pq Dv 011100 , 1202.Cm af33 1203.Pq Dv 011110 , 1204.Cm af41 1205.Pq Dv 100010 , 1206.Cm af42 1207.Pq Dv 100100 , 1208.Cm af43 1209.Pq Dv 100110 , 1210.Cm va 1211.Pq Dv 101100 , 1212.Cm ef 1213.Pq Dv 101110 , 1214.Cm be 1215.Pq Dv 000000 . 1216Additionally, DSCP value can be specified by number (0..63). 1217It is also possible to use the 1218.Cm tablearg 1219keyword with setdscp. 1220If the tablearg value is not within the 0..63 range, lower 6 bits of supplied 1221value are used. 1222.It Cm tcp-setmss Ar mss 1223Set the Maximum Segment Size (MSS) in the TCP segment to value 1224.Ar mss . 1225The kernel module 1226.Cm ipfw_pmod 1227should be loaded or kernel should have 1228.Cm options IPFIREWALL_PMOD 1229to be able use this action. 1230This command does not change a packet if original MSS value is lower than 1231specified value. 1232Both TCP over IPv4 and over IPv6 are supported. 1233Regardless of matched a packet or not by the 1234.Cm tcp-setmss 1235rule, the search continues with the next rule. 1236.It Cm reass 1237Queue and reassemble IPv4 fragments. 1238If the packet is not fragmented, counters are updated and 1239processing continues with the next rule. 1240If the packet is the last logical fragment, the packet is reassembled and, if 1241.Va net.inet.ip.fw.one_pass 1242is set to 0, processing continues with the next rule. 1243Otherwise, the packet is allowed to pass and the search terminates. 1244If the packet is a fragment in the middle of a logical group of fragments, 1245it is consumed and 1246processing stops immediately. 1247.Pp 1248Fragment handling can be tuned via 1249.Va net.inet.ip.maxfragpackets 1250and 1251.Va net.inet.ip.maxfragsperpacket 1252which limit, respectively, the maximum number of processable 1253fragments (default: 800) and 1254the maximum number of fragments per packet (default: 16). 1255.Pp 1256NOTA BENE: since fragments do not contain port numbers, 1257they should be avoided with the 1258.Nm reass 1259rule. 1260Alternatively, direction-based (like 1261.Nm in 1262/ 1263.Nm out 1264) and source-based (like 1265.Nm via 1266) match patterns can be used to select fragments. 1267.Pp 1268Usually a simple rule like: 1269.Bd -literal -offset indent 1270# reassemble incoming fragments 1271ipfw add reass all from any to any in 1272.Ed 1273.Pp 1274is all you need at the beginning of your ruleset. 1275.It Cm abort 1276Discard packets that match this rule, and if the packet is an SCTP packet, 1277try to send an SCTP packet containing an ABORT chunk. 1278The search terminates. 1279.It Cm abort6 1280Discard packets that match this rule, and if the packet is an SCTP packet, 1281try to send an SCTP packet containing an ABORT chunk. 1282The search terminates. 1283.El 1284.Ss RULE BODY 1285The body of a rule contains zero or more patterns (such as 1286specific source and destination addresses or ports, 1287protocol options, incoming or outgoing interfaces, etc.) 1288that the packet must match in order to be recognised. 1289In general, the patterns are connected by (implicit) 1290.Cm and 1291operators -- i.e., all must match in order for the 1292rule to match. 1293Individual patterns can be prefixed by the 1294.Cm not 1295operator to reverse the result of the match, as in 1296.Pp 1297.Dl "ipfw add 100 allow ip from not 1.2.3.4 to any" 1298.Pp 1299Additionally, sets of alternative match patterns 1300.Pq Em or-blocks 1301can be constructed by putting the patterns in 1302lists enclosed between parentheses ( ) or braces { }, and 1303using the 1304.Cm or 1305operator as follows: 1306.Pp 1307.Dl "ipfw add 100 allow ip from { x or not y or z } to any" 1308.Pp 1309Only one level of parentheses is allowed. 1310Beware that most shells have special meanings for parentheses 1311or braces, so it is advisable to put a backslash \\ in front of them 1312to prevent such interpretations. 1313.Pp 1314The body of a rule must in general include a source and destination 1315address specifier. 1316The keyword 1317.Ar any 1318can be used in various places to specify that the content of 1319a required field is irrelevant. 1320.Pp 1321The rule body has the following format: 1322.Bd -ragged -offset indent 1323.Op Ar proto Cm from Ar src Cm to Ar dst 1324.Op Ar options 1325.Ed 1326.Pp 1327The first part (proto from src to dst) is for backward 1328compatibility with earlier versions of 1329.Fx . 1330In modern 1331.Fx 1332any match pattern (including MAC headers, IP protocols, 1333addresses and ports) can be specified in the 1334.Ar options 1335section. 1336.Pp 1337Rule fields have the following meaning: 1338.Bl -tag -width indent 1339.It Ar proto : protocol | Cm { Ar protocol Cm or ... } 1340.It Ar protocol : Oo Cm not Oc Ar protocol-name | protocol-number 1341An IP protocol specified by number or name 1342(for a complete list see 1343.Pa /etc/protocols ) , 1344or one of the following keywords: 1345.Bl -tag -width indent 1346.It Cm ip4 | ipv4 1347Matches IPv4 packets. 1348.It Cm ip6 | ipv6 1349Matches IPv6 packets. 1350.It Cm ip | all 1351Matches any packet. 1352.El 1353.Pp 1354The 1355.Cm ipv6 1356in 1357.Cm proto 1358option will be treated as inner protocol. 1359And, the 1360.Cm ipv4 1361is not available in 1362.Cm proto 1363option. 1364.Pp 1365The 1366.Cm { Ar protocol Cm or ... } 1367format (an 1368.Em or-block ) 1369is provided for convenience only but its use is deprecated. 1370.It Ar src No and Ar dst : Bro Cm addr | Cm { Ar addr Cm or ... } Brc Op Oo Cm not Oc Ar ports 1371An address (or a list, see below) 1372optionally followed by 1373.Ar ports 1374specifiers. 1375.Pp 1376The second format 1377.Em ( or-block 1378with multiple addresses) is provided for convenience only and 1379its use is discouraged. 1380.It Ar addr : Oo Cm not Oc Bro 1381.Cm any | me | me6 | 1382.Cm table Ns Pq Ar name Ns Op , Ns Ar value 1383.Ar | addr-list | addr-set 1384.Brc 1385.Bl -tag -width indent 1386.It Cm any 1387Matches any IP address. 1388.It Cm me 1389Matches any IP address configured on an interface in the system. 1390.It Cm me6 1391Matches any IPv6 address configured on an interface in the system. 1392The address list is evaluated at the time the packet is 1393analysed. 1394.It Cm table Ns Pq Ar name Ns Op , Ns Ar value 1395Matches any IPv4 or IPv6 address for which an entry exists in the lookup table 1396.Ar number . 1397If an optional 32-bit unsigned 1398.Ar value 1399is also specified, an entry will match only if it has this value. 1400See the 1401.Sx LOOKUP TABLES 1402section below for more information on lookup tables. 1403.El 1404.It Ar addr-list : ip-addr Ns Op Ns , Ns Ar addr-list 1405.It Ar ip-addr : 1406A host or subnet address specified in one of the following ways: 1407.Bl -tag -width indent 1408.It Ar numeric-ip | hostname 1409Matches a single IPv4 address, specified as dotted-quad or a hostname. 1410Hostnames are resolved at the time the rule is added to the firewall list. 1411.It Ar addr Ns / Ns Ar masklen 1412Matches all addresses with base 1413.Ar addr 1414(specified as an IP address, a network number, or a hostname) 1415and mask width of 1416.Cm masklen 1417bits. 1418As an example, 1.2.3.4/25 or 1.2.3.0/25 will match 1419all IP numbers from 1.2.3.0 to 1.2.3.127 . 1420.It Ar addr Ns : Ns Ar mask 1421Matches all addresses with base 1422.Ar addr 1423(specified as an IP address, a network number, or a hostname) 1424and the mask of 1425.Ar mask , 1426specified as a dotted quad. 1427As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match 14281.*.3.*. 1429This form is advised only for non-contiguous 1430masks. 1431It is better to resort to the 1432.Ar addr Ns / Ns Ar masklen 1433format for contiguous masks, which is more compact and less 1434error-prone. 1435.El 1436.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm } 1437.It Ar list : Bro Ar num | num-num Brc Ns Op Ns , Ns Ar list 1438Matches all addresses with base address 1439.Ar addr 1440(specified as an IP address, a network number, or a hostname) 1441and whose last byte is in the list between braces { } . 1442Note that there must be no spaces between braces and 1443numbers (spaces after commas are allowed). 1444Elements of the list can be specified as single entries 1445or ranges. 1446The 1447.Ar masklen 1448field is used to limit the size of the set of addresses, 1449and can have any value between 24 and 32. 1450If not specified, 1451it will be assumed as 24. 1452.br 1453This format is particularly useful to handle sparse address sets 1454within a single rule. 1455Because the matching occurs using a 1456bitmask, it takes constant time and dramatically reduces 1457the complexity of rulesets. 1458.br 1459As an example, an address specified as 1.2.3.4/24{128,35-55,89} 1460or 1.2.3.0/24{128,35-55,89} 1461will match the following IP addresses: 1462.br 14631.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 . 1464.It Ar addr6-list : ip6-addr Ns Op Ns , Ns Ar addr6-list 1465.It Ar ip6-addr : 1466A host or subnet specified one of the following ways: 1467.Bl -tag -width indent 1468.It Ar numeric-ip | hostname 1469Matches a single IPv6 address as allowed by 1470.Xr inet_pton 3 1471or a hostname. 1472Hostnames are resolved at the time the rule is added to the firewall 1473list. 1474.It Ar addr Ns / Ns Ar masklen 1475Matches all IPv6 addresses with base 1476.Ar addr 1477(specified as allowed by 1478.Xr inet_pton 3 1479or a hostname) 1480and mask width of 1481.Cm masklen 1482bits. 1483.It Ar addr Ns / Ns Ar mask 1484Matches all IPv6 addresses with base 1485.Ar addr 1486(specified as allowed by 1487.Xr inet_pton 3 1488or a hostname) 1489and the mask of 1490.Ar mask , 1491specified as allowed by 1492.Xr inet_pton 3 . 1493As an example, fe::640:0:0/ffff::ffff:ffff:0:0 will match 1494fe:*:*:*:0:640:*:*. 1495This form is advised only for non-contiguous 1496masks. 1497It is better to resort to the 1498.Ar addr Ns / Ns Ar masklen 1499format for contiguous masks, which is more compact and less 1500error-prone. 1501.El 1502.Pp 1503No support for sets of IPv6 addresses is provided because IPv6 addresses 1504are typically random past the initial prefix. 1505.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports 1506For protocols which support port numbers (such as SCTP, TCP and UDP), optional 1507.Cm ports 1508may be specified as one or more ports or port ranges, separated 1509by commas but no spaces, and an optional 1510.Cm not 1511operator. 1512The 1513.Ql \&- 1514notation specifies a range of ports (including boundaries). 1515.Pp 1516Service names (from 1517.Pa /etc/services ) 1518may be used instead of numeric port values. 1519The length of the port list is limited to 30 ports or ranges, 1520though one can specify larger ranges by using an 1521.Em or-block 1522in the 1523.Cm options 1524section of the rule. 1525.Pp 1526A backslash 1527.Pq Ql \e 1528can be used to escape the dash 1529.Pq Ql - 1530character in a service name (from a shell, the backslash must be 1531typed twice to avoid the shell itself interpreting it as an escape 1532character). 1533.Pp 1534.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any" 1535.Pp 1536Fragmented packets which have a non-zero offset (i.e., not the first 1537fragment) will never match a rule which has one or more port 1538specifications. 1539See the 1540.Cm frag 1541option for details on matching fragmented packets. 1542.El 1543.Ss RULE OPTIONS (MATCH PATTERNS) 1544Additional match patterns can be used within 1545rules. 1546Zero or more of these so-called 1547.Em options 1548can be present in a rule, optionally prefixed by the 1549.Cm not 1550operand, and possibly grouped into 1551.Em or-blocks . 1552.Pp 1553The following match patterns can be used (listed in alphabetical order): 1554.Bl -tag -width indent 1555.It Cm // this is a comment . 1556Inserts the specified text as a comment in the rule. 1557Everything following // is considered as a comment and stored in the rule. 1558You can have comment-only rules, which are listed as having a 1559.Cm count 1560action followed by the comment. 1561.It Cm bridged 1562Alias for 1563.Cm layer2 . 1564.It Cm defer-immediate-action | defer-action 1565A rule with this option will not perform normal action 1566upon a match. 1567This option is intended to be used with 1568.Cm record-state 1569or 1570.Cm keep-state 1571as the dynamic rule, created but ignored on match, will work 1572as intended. 1573Rules with both 1574.Cm record-state 1575and 1576.Cm defer-immediate-action 1577create a dynamic rule and continue with the next rule without actually 1578performing the action part of this rule. 1579When the rule is later activated via the state table, the action is 1580performed as usual. 1581.It Cm diverted 1582Matches only packets generated by a divert socket. 1583.It Cm diverted-loopback 1584Matches only packets coming from a divert socket back into the IP stack 1585input for delivery. 1586.It Cm diverted-output 1587Matches only packets going from a divert socket back outward to the IP 1588stack output for delivery. 1589.It Cm dst-ip Ar ip-address 1590Matches IPv4 packets whose destination IP is one of the address(es) 1591specified as argument. 1592.It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address 1593Matches IPv6 packets whose destination IP is one of the address(es) 1594specified as argument. 1595.It Cm dst-port Ar ports 1596Matches IP packets whose destination port is one of the port(s) 1597specified as argument. 1598.It Cm established 1599Matches TCP packets that have the RST or ACK bits set. 1600.It Cm ext6hdr Ar header 1601Matches IPv6 packets containing the extended header given by 1602.Ar header . 1603Supported headers are: 1604.Pp 1605Fragment, 1606.Pq Cm frag , 1607Hop-to-hop options 1608.Pq Cm hopopt , 1609any type of Routing Header 1610.Pq Cm route , 1611Source routing Routing Header Type 0 1612.Pq Cm rthdr0 , 1613Mobile IPv6 Routing Header Type 2 1614.Pq Cm rthdr2 , 1615Destination options 1616.Pq Cm dstopt , 1617IPSec authentication headers 1618.Pq Cm ah , 1619and IPsec encapsulated security payload headers 1620.Pq Cm esp . 1621.It Cm fib Ar fibnum 1622Matches a packet that has been tagged to use 1623the given FIB (routing table) number. 1624.It Cm flow Ar table Ns Pq Ar name Ns Op , Ns Ar value 1625Search for the flow entry in lookup table 1626.Ar name . 1627If not found, the match fails. 1628Otherwise, the match succeeds and 1629.Cm tablearg 1630is set to the value extracted from the table. 1631.Pp 1632This option can be useful to quickly dispatch traffic based on 1633certain packet fields. 1634See the 1635.Sx LOOKUP TABLES 1636section below for more information on lookup tables. 1637.It Cm flow-id Ar labels 1638Matches IPv6 packets containing any of the flow labels given in 1639.Ar labels . 1640.Ar labels 1641is a comma separated list of numeric flow labels. 1642.It Cm dst-mac Ar table Ns Pq Ar name Ns Op , Ns Ar value 1643Search for the destination MAC address entry in lookup table 1644.Ar name . 1645If not found, the match fails. 1646Otherwise, the match succeeds and 1647.Cm tablearg 1648is set to the value extracted from the table. 1649.It Cm src-mac Ar table Ns Pq Ar name Ns Op , Ns Ar value 1650Search for the source MAC address entry in lookup table 1651.Ar name . 1652If not found, the match fails. 1653Otherwise, the match succeeds and 1654.Cm tablearg 1655is set to the value extracted from the table. 1656.It Cm frag Ar spec 1657Matches IPv4 packets whose 1658.Cm ip_off 1659field contains the comma separated list of IPv4 fragmentation 1660options specified in 1661.Ar spec . 1662The recognized options are: 1663.Cm df 1664.Pq Dv don't fragment , 1665.Cm mf 1666.Pq Dv more fragments , 1667.Cm rf 1668.Pq Dv reserved fragment bit 1669.Cm offset 1670.Pq Dv non-zero fragment offset . 1671The absence of a particular options may be denoted 1672with a 1673.Ql \&! . 1674.Pp 1675Empty list of options defaults to matching on non-zero fragment offset. 1676Such rule would match all not the first fragment datagrams, 1677both IPv4 and IPv6. 1678This is a backward compatibility with older rulesets. 1679.It Cm gid Ar group 1680Matches all TCP or UDP packets sent by or received for a 1681.Ar group . 1682A 1683.Ar group 1684may be specified by name or number. 1685.It Cm jail Ar jail 1686Matches all TCP or UDP packets sent by or received for the 1687jail whose ID or name is 1688.Ar jail . 1689.It Cm icmptypes Ar types 1690Matches ICMP packets whose ICMP type is in the list 1691.Ar types . 1692The list may be specified as any combination of 1693individual types (numeric) separated by commas. 1694.Em Ranges are not allowed . 1695The supported ICMP types are: 1696.Pp 1697echo reply 1698.Pq Cm 0 , 1699destination unreachable 1700.Pq Cm 3 , 1701source quench 1702.Pq Cm 4 , 1703redirect 1704.Pq Cm 5 , 1705echo request 1706.Pq Cm 8 , 1707router advertisement 1708.Pq Cm 9 , 1709router solicitation 1710.Pq Cm 10 , 1711time-to-live exceeded 1712.Pq Cm 11 , 1713IP header bad 1714.Pq Cm 12 , 1715timestamp request 1716.Pq Cm 13 , 1717timestamp reply 1718.Pq Cm 14 , 1719information request 1720.Pq Cm 15 , 1721information reply 1722.Pq Cm 16 , 1723address mask request 1724.Pq Cm 17 1725and address mask reply 1726.Pq Cm 18 . 1727.It Cm icmp6types Ar types 1728Matches ICMP6 packets whose ICMP6 type is in the list of 1729.Ar types . 1730The list may be specified as any combination of 1731individual types (numeric) separated by commas. 1732.Em Ranges are not allowed . 1733.It Cm in | out 1734Matches incoming or outgoing packets, respectively. 1735.Cm in 1736and 1737.Cm out 1738are mutually exclusive (in fact, 1739.Cm out 1740is implemented as 1741.Cm not in Ns No ). 1742.It Cm ipid Ar id-list 1743Matches IPv4 packets whose 1744.Cm ip_id 1745field has value included in 1746.Ar id-list , 1747which is either a single value or a list of values or ranges 1748specified in the same way as 1749.Ar ports . 1750.It Cm iplen Ar len-list 1751Matches IP packets whose total length, including header and data, is 1752in the set 1753.Ar len-list , 1754which is either a single value or a list of values or ranges 1755specified in the same way as 1756.Ar ports . 1757.It Cm ipoptions Ar spec 1758Matches packets whose IPv4 header contains the comma separated list of 1759options specified in 1760.Ar spec . 1761The supported IP options are: 1762.Pp 1763.Cm ssrr 1764(strict source route), 1765.Cm lsrr 1766(loose source route), 1767.Cm rr 1768(record packet route) and 1769.Cm ts 1770(timestamp). 1771The absence of a particular option may be denoted 1772with a 1773.Ql \&! . 1774.It Cm ipprecedence Ar precedence 1775Matches IPv4 packets whose precedence field is equal to 1776.Ar precedence . 1777.It Cm ipsec 1778Matches packets that have IPSEC history associated with them 1779(i.e., the packet comes encapsulated in IPSEC, the kernel 1780has IPSEC support, and can correctly decapsulate it). 1781.Pp 1782Note that specifying 1783.Cm ipsec 1784is different from specifying 1785.Cm proto Ar ipsec 1786as the latter will only look at the specific IP protocol field, 1787irrespective of IPSEC kernel support and the validity of the IPSEC data. 1788.Pp 1789Further note that this flag is silently ignored in kernels without 1790IPSEC support. 1791It does not affect rule processing when given and the 1792rules are handled as if with no 1793.Cm ipsec 1794flag. 1795.It Cm iptos Ar spec 1796Matches IPv4 packets whose 1797.Cm tos 1798field contains the comma separated list of 1799service types specified in 1800.Ar spec . 1801The supported IP types of service are: 1802.Pp 1803.Cm lowdelay 1804.Pq Dv IPTOS_LOWDELAY , 1805.Cm throughput 1806.Pq Dv IPTOS_THROUGHPUT , 1807.Cm reliability 1808.Pq Dv IPTOS_RELIABILITY , 1809.Cm mincost 1810.Pq Dv IPTOS_MINCOST , 1811.Cm congestion 1812.Pq Dv IPTOS_ECN_CE . 1813The absence of a particular type may be denoted 1814with a 1815.Ql \&! . 1816.It Cm dscp spec Ns Op , Ns Ar spec 1817Matches IPv4/IPv6 packets whose 1818.Cm DS 1819field value is contained in 1820.Ar spec 1821mask. 1822Multiple values can be specified via 1823the comma separated list. 1824Value can be one of keywords used in 1825.Cm setdscp 1826action or exact number. 1827.It Cm ipttl Ar ttl-list 1828Matches IPv4 packets whose time to live is included in 1829.Ar ttl-list , 1830which is either a single value or a list of values or ranges 1831specified in the same way as 1832.Ar ports . 1833.It Cm ipversion Ar ver 1834Matches IP packets whose IP version field is 1835.Ar ver . 1836.It Cm keep-state Op Ar :flowname 1837Upon a match, the firewall will create a dynamic rule, whose 1838default behaviour is to match bidirectional traffic between 1839source and destination IP/port using the same protocol. 1840The rule has a limited lifetime (controlled by a set of 1841.Xr sysctl 8 1842variables), and the lifetime is refreshed every time a matching 1843packet is found. 1844The 1845.Ar :flowname 1846is used to assign additional to addresses, ports and protocol parameter 1847to dynamic rule. 1848It can be used for more accurate matching by 1849.Cm check-state 1850rule. 1851The 1852.Cm :default 1853keyword is special name used for compatibility with old rulesets. 1854.It Cm layer2 1855Matches only layer2 packets, i.e., those passed to 1856.Nm 1857from 1858.Fn ether_demux 1859and 1860.Fn ether_output_frame . 1861.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N Op Ar :flowname 1862The firewall will only allow 1863.Ar N 1864connections with the same 1865set of parameters as specified in the rule. 1866One or more 1867of source and destination addresses and ports can be 1868specified. 1869.It Cm lookup Bro Cm dst-ip | dst-port | dst-mac | src-ip | src-port | src-mac | uid | 1870.Cm jail | dscp | mark Brc Ar name 1871Search an entry in lookup table 1872.Ar name 1873that matches the field specified as argument. 1874If not found, the match fails. 1875Otherwise, the match succeeds and 1876.Cm tablearg 1877is set to the value extracted from the table. 1878.Pp 1879This option can be useful to quickly dispatch traffic based on 1880certain packet fields. 1881See the 1882.Sx LOOKUP TABLES 1883section below for more information on lookup tables. 1884.It Cm { MAC | mac } Ar dst-mac src-mac 1885Match packets with a given 1886.Ar dst-mac 1887and 1888.Ar src-mac 1889addresses, specified as the 1890.Cm any 1891keyword (matching any MAC address), or six groups of hex digits 1892separated by colons, 1893and optionally followed by a mask indicating the significant bits. 1894The mask may be specified using either of the following methods: 1895.Bl -enum -width indent 1896.It 1897A slash 1898.Pq / 1899followed by the number of significant bits. 1900For example, an address with 33 significant bits could be specified as: 1901.Pp 1902.Dl "MAC 10:20:30:40:50:60/33 any" 1903.It 1904An ampersand 1905.Pq & 1906followed by a bitmask specified as six groups of hex digits separated 1907by colons. 1908For example, an address in which the last 16 bits are significant could 1909be specified as: 1910.Pp 1911.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any" 1912.Pp 1913Note that the ampersand character has a special meaning in many shells 1914and should generally be escaped. 1915.El 1916Note that the order of MAC addresses (destination first, 1917source second) is 1918the same as on the wire, but the opposite of the one used for 1919IP addresses. 1920.It Cm mac-type Ar mac-type 1921Matches packets whose Ethernet Type field 1922corresponds to one of those specified as argument. 1923.Ar mac-type 1924is specified in the same way as 1925.Cm port numbers 1926(i.e., one or more comma-separated single values or ranges). 1927You can use symbolic names for known values such as 1928.Em vlan , ipv4, ipv6 . 1929Values can be entered as decimal or hexadecimal (if prefixed by 0x), 1930and they are always printed as hexadecimal (unless the 1931.Cm -N 1932option is used, in which case symbolic resolution will be attempted). 1933.It Cm proto Ar protocol 1934Matches packets with the corresponding IP protocol. 1935.It Cm record-state 1936Upon a match, the firewall will create a dynamic rule as if 1937.Cm keep-state 1938was specified. 1939However, this option doesn't imply an implicit 1940.Cm check-state 1941in contrast to 1942.Cm keep-state . 1943.It Cm recv | xmit | via Brq Ar ifX | Ar ifmask | Ar table Ns Po Ar name Ns Oo , Ns Ar value Oc Pc | Ar ipno | Ar any 1944Matches packets received, transmitted or going through, 1945respectively, the interface specified by exact name 1946.Po Ar ifX Pc , 1947by device mask 1948.Po Ar ifmask Pc , 1949by IP address, or through some interface. 1950.Pp 1951Interface 1952name may be matched against 1953.Ar ifmask 1954with 1955.Xr fnmatch 3 1956according to the rules used by the shell (f.e. tun*). 1957See also the 1958.Sx EXAMPLES 1959section. 1960.Pp 1961Table 1962.Ar name 1963may be used to match interface by its kernel ifindex. 1964See the 1965.Sx LOOKUP TABLES 1966section below for more information on lookup tables. 1967.Pp 1968The 1969.Cm via 1970keyword causes the interface to always be checked. 1971If 1972.Cm recv 1973or 1974.Cm xmit 1975is used instead of 1976.Cm via , 1977then only the receive or transmit interface (respectively) 1978is checked. 1979By specifying both, it is possible to match packets based on 1980both receive and transmit interface, e.g.: 1981.Pp 1982.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1" 1983.Pp 1984The 1985.Cm recv 1986interface can be tested on either incoming or outgoing packets, 1987while the 1988.Cm xmit 1989interface can only be tested on outgoing packets. 1990So 1991.Cm out 1992is required (and 1993.Cm in 1994is invalid) whenever 1995.Cm xmit 1996is used. 1997.Pp 1998A packet might not have a receive or transmit interface: packets 1999originating from the local host have no receive interface, 2000while packets destined for the local host have no transmit 2001interface. 2002.It Cm set-limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N 2003Works like 2004.Cm limit 2005but does not have an implicit 2006.Cm check-state 2007attached to it. 2008.It Cm setup 2009Matches TCP packets that have the SYN bit set but no ACK bit. 2010This is the short form of 2011.Dq Li tcpflags\ syn,!ack . 2012.It Cm sockarg 2013Matches packets that are associated to a local socket and 2014for which the SO_USER_COOKIE socket option has been set 2015to a non-zero value. 2016As a side effect, the value of the 2017option is made available as 2018.Cm tablearg 2019value, which in turn can be used as 2020.Cm skipto 2021or 2022.Cm pipe 2023number. 2024.It Cm src-ip Ar ip-address 2025Matches IPv4 packets whose source IP is one of the address(es) 2026specified as an argument. 2027.It Cm src-ip6 Ar ip6-address 2028Matches IPv6 packets whose source IP is one of the address(es) 2029specified as an argument. 2030.It Cm src-port Ar ports 2031Matches IP packets whose source port is one of the port(s) 2032specified as argument. 2033.It Cm tagged Ar tag-list 2034Matches packets whose tags are included in 2035.Ar tag-list , 2036which is either a single value or a list of values or ranges 2037specified in the same way as 2038.Ar ports . 2039Tags can be applied to the packet using 2040.Cm tag 2041rule action parameter (see it's description for details on tags). 2042.It Cm mark Ar value[:bitmask] | tablearg[:bitmask] 2043Matches packets whose mark is equal to 2044.Ar value 2045with optional 2046.Ar bitmask 2047applied to it. 2048.Cm tablearg 2049can also be used instead of an explicit 2050.Ar value 2051to match a value supplied by the last table lookup. 2052.Pp 2053Both 2054.Ar value 2055and 2056.Ar bitmask 2057can be entered as decimal or hexadecimal (if prefixed by 0x), and they 2058are always printed as hexadecimal. 2059.It Cm tcpack Ar ack 2060TCP packets only. 2061Match if the TCP header acknowledgment number field is set to 2062.Ar ack . 2063.It Cm tcpdatalen Ar tcpdatalen-list 2064Matches TCP packets whose length of TCP data is 2065.Ar tcpdatalen-list , 2066which is either a single value or a list of values or ranges 2067specified in the same way as 2068.Ar ports . 2069.It Cm tcpflags Ar spec 2070TCP packets only. 2071Match if the TCP header contains the comma separated list of 2072flags specified in 2073.Ar spec . 2074The supported TCP flags are: 2075.Pp 2076.Cm fin , 2077.Cm syn , 2078.Cm rst , 2079.Cm psh , 2080.Cm ack 2081and 2082.Cm urg . 2083The absence of a particular flag may be denoted 2084with a 2085.Ql \&! . 2086A rule which contains a 2087.Cm tcpflags 2088specification can never match a fragmented packet which has 2089a non-zero offset. 2090See the 2091.Cm frag 2092option for details on matching fragmented packets. 2093.It Cm tcpmss Ar tcpmss-list 2094Matches TCP packets whose MSS (maximum segment size) value is set to 2095.Ar tcpmss-list , 2096which is either a single value or a list of values or ranges 2097specified in the same way as 2098.Ar ports . 2099.It Cm tcpseq Ar seq 2100TCP packets only. 2101Match if the TCP header sequence number field is set to 2102.Ar seq . 2103.It Cm tcpwin Ar tcpwin-list 2104Matches TCP packets whose header window field is set to 2105.Ar tcpwin-list , 2106which is either a single value or a list of values or ranges 2107specified in the same way as 2108.Ar ports . 2109.It Cm tcpoptions Ar spec 2110TCP packets only. 2111Match if the TCP header contains the comma separated list of 2112options specified in 2113.Ar spec . 2114The supported TCP options are: 2115.Pp 2116.Cm mss 2117(maximum segment size), 2118.Cm window 2119(tcp window advertisement), 2120.Cm sack 2121(selective ack), 2122.Cm ts 2123(rfc1323 timestamp) and 2124.Cm cc 2125(rfc1644 t/tcp connection count). 2126The absence of a particular option may be denoted 2127with a 2128.Ql \&! . 2129.It Cm uid Ar user 2130Match all TCP or UDP packets sent by or received for a 2131.Ar user . 2132A 2133.Ar user 2134may be matched by name or identification number. 2135.It Cm verrevpath 2136For incoming packets, 2137a routing table lookup is done on the packet's source address. 2138If the interface on which the packet entered the system matches the 2139outgoing interface for the route, 2140the packet matches. 2141If the interfaces do not match up, 2142the packet does not match. 2143All outgoing packets or packets with no incoming interface match. 2144.Pp 2145The name and functionality of the option is intentionally similar to 2146the Cisco IOS command: 2147.Pp 2148.Dl ip verify unicast reverse-path 2149.Pp 2150This option can be used to make anti-spoofing rules to reject all 2151packets with source addresses not from this interface. 2152See also the option 2153.Cm antispoof . 2154.It Cm versrcreach 2155For incoming packets, 2156a routing table lookup is done on the packet's source address. 2157If a route to the source address exists, but not the default route 2158or a blackhole/reject route, the packet matches. 2159Otherwise, the packet does not match. 2160All outgoing packets match. 2161.Pp 2162The name and functionality of the option is intentionally similar to 2163the Cisco IOS command: 2164.Pp 2165.Dl ip verify unicast source reachable-via any 2166.Pp 2167This option can be used to make anti-spoofing rules to reject all 2168packets whose source address is unreachable. 2169.It Cm antispoof 2170For incoming packets, the packet's source address is checked if it 2171belongs to a directly connected network. 2172If the network is directly connected, then the interface the packet 2173came on in is compared to the interface the network is connected to. 2174When incoming interface and directly connected interface are not the 2175same, the packet does not match. 2176Otherwise, the packet does match. 2177All outgoing packets match. 2178.Pp 2179This option can be used to make anti-spoofing rules to reject all 2180packets that pretend to be from a directly connected network but do 2181not come in through that interface. 2182This option is similar to but more restricted than 2183.Cm verrevpath 2184because it engages only on packets with source addresses of directly 2185connected networks instead of all source addresses. 2186.El 2187.Sh LOOKUP TABLES 2188Lookup tables are useful to handle large sparse sets of 2189addresses or other search keys (e.g., ports, jail IDs, interface names). 2190In the rest of this section we will use the term ``key''. 2191Table name needs to match the following spec: 2192.Ar table-name . 2193Tables with the same name can be created in different 2194.Ar sets . 2195However, rule links to the tables in 2196.Ar set 0 2197by default. 2198This behavior can be controlled by 2199.Va net.inet.ip.fw.tables_sets 2200variable. 2201See the 2202.Sx SETS OF RULES 2203section for more information. 2204There may be up to 65535 different lookup tables. 2205.Pp 2206The following table types are supported: 2207.Bl -tag -width indent 2208.It Ar table-type : Ar addr | iface | number | flow | mac 2209.It Ar table-key : Ar addr Ns Oo / Ns Ar masklen Oc | iface-name | number | flow-spec 2210.It Ar flow-spec : Ar flow-field Ns Op , Ns Ar flow-spec 2211.It Ar flow-field : src-ip | proto | src-port | dst-ip | dst-port 2212.It Cm addr 2213Matches IPv4 or IPv6 address. 2214Each entry is represented by an 2215.Ar addr Ns Op / Ns Ar masklen 2216and will match all addresses with base 2217.Ar addr 2218(specified as an IPv4/IPv6 address, or a hostname) and mask width of 2219.Ar masklen 2220bits. 2221If 2222.Ar masklen 2223is not specified, it defaults to 32 for IPv4 and 128 for IPv6. 2224When looking up an IP address in a table, the most specific 2225entry will match. 2226.It Cm iface 2227Matches interface names. 2228Each entry is represented by string treated as interface name. 2229Wildcards are not supported. 2230.It Cm number 2231Matches protocol ports, uids/gids or jail IDs. 2232Each entry is represented by 32-bit unsigned integer. 2233Ranges are not supported. 2234.It Cm flow 2235Matches packet fields specified by 2236.Ar flow 2237type suboptions with table entries. 2238.It Cm mac 2239Matches MAC address. 2240Each entry is represented by an 2241.Ar addr Ns Op / Ns Ar masklen 2242and will match all addresses with base 2243.Ar addr 2244and mask width of 2245.Ar masklen 2246bits. 2247If 2248.Ar masklen 2249is not specified, it defaults to 48. 2250When looking up an MAC address in a table, the most specific 2251entry will match. 2252.El 2253.Pp 2254Tables require explicit creation via 2255.Cm create 2256before use. 2257.Pp 2258The following creation options are supported: 2259.Bl -tag -width indent 2260.It Ar create-options : Ar create-option | create-options 2261.It Ar create-option : Cm type Ar table-type | Cm valtype Ar value-mask | Cm algo Ar algo-desc | 2262.Cm limit Ar number | Cm locked | Cm missing | Cm or-flush 2263.It Cm type 2264Table key type. 2265.It Cm valtype 2266Table value mask. 2267.It Cm algo 2268Table algorithm to use (see below). 2269.It Cm limit 2270Maximum number of items that may be inserted into table. 2271.It Cm locked 2272Restrict any table modifications. 2273.It Cm missing 2274Do not fail if table already exists and has exactly same options as new one. 2275.It Cm or-flush 2276Flush existing table with same name instead of returning error. 2277Implies 2278.Cm missing 2279so existing table must be compatible with new one. 2280.El 2281.Pp 2282Some of these options may be modified later via 2283.Cm modify 2284keyword. 2285The following options can be changed: 2286.Bl -tag -width indent 2287.It Ar modify-options : Ar modify-option | modify-options 2288.It Ar modify-option : Cm limit Ar number 2289.It Cm limit 2290Alter maximum number of items that may be inserted into table. 2291.El 2292.Pp 2293Additionally, table can be locked or unlocked using 2294.Cm lock 2295or 2296.Cm unlock 2297commands. 2298.Pp 2299Tables of the same 2300.Ar type 2301can be swapped with each other using 2302.Cm swap Ar name 2303command. 2304Swap may fail if tables limits are set and data exchange 2305would result in limits hit. 2306Operation is performed atomically. 2307.Pp 2308One or more entries can be added to a table at once using 2309.Cm add 2310command. 2311Addition of all items are performed atomically. 2312By default, error in addition of one entry does not influence 2313addition of other entries. 2314However, non-zero error code is returned in that case. 2315Special 2316.Cm atomic 2317keyword may be specified before 2318.Cm add 2319to indicate all-or-none add request. 2320.Pp 2321One or more entries can be removed from a table at once using 2322.Cm delete 2323command. 2324By default, error in removal of one entry does not influence 2325removing of other entries. 2326However, non-zero error code is returned in that case. 2327.Pp 2328It may be possible to check what entry will be found on particular 2329.Ar table-key 2330using 2331.Cm lookup 2332.Ar table-key 2333command. 2334This functionality is optional and may be unsupported in some algorithms. 2335.Pp 2336The following operations can be performed on 2337.Ar one 2338or 2339.Cm all 2340tables: 2341.Bl -tag -width indent 2342.It Cm list 2343List all entries. 2344.It Cm flush 2345Removes all entries. 2346.It Cm info 2347Shows generic table information. 2348.It Cm detail 2349Shows generic table information and algo-specific data. 2350.El 2351.Pp 2352The following lookup algorithms are supported: 2353.Bl -tag -width indent 2354.It Ar algo-desc : algo-name | "algo-name algo-data" 2355.It Ar algo-name : Ar addr: radix | addr: hash | iface: array | number: array | flow: hash | mac: radix 2356.It Cm addr: radix 2357Separate Radix trees for IPv4 and IPv6, the same way as the routing table (see 2358.Xr route 4 ) . 2359Default choice for 2360.Ar addr 2361type. 2362.It Cm addr:hash 2363Separate auto-growing hashes for IPv4 and IPv6. 2364Accepts entries with the same mask length specified initially via 2365.Cm "addr:hash masks=/v4,/v6" 2366algorithm creation options. 2367Assume /32 and /128 masks by default. 2368Search removes host bits (according to mask) from supplied address and checks 2369resulting key in appropriate hash. 2370Mostly optimized for /64 and byte-ranged IPv6 masks. 2371.It Cm iface:array 2372Array storing sorted indexes for entries which are presented in the system. 2373Optimized for very fast lookup. 2374.It Cm number:array 2375Array storing sorted u32 numbers. 2376.It Cm flow:hash 2377Auto-growing hash storing flow entries. 2378Search calculates hash on required packet fields and searches for matching 2379entries in selected bucket. 2380.It Cm mac: radix 2381Radix tree for MAC address 2382.El 2383.Pp 2384The 2385.Cm tablearg 2386feature provides the ability to use a value, looked up in the table, as 2387the argument for a rule action, action parameter or rule option. 2388This can significantly reduce number of rules in some configurations. 2389If two tables are used in a rule, the result of the second (destination) 2390is used. 2391.Pp 2392Each record may hold one or more values according to 2393.Ar value-mask . 2394This mask is set on table creation via 2395.Cm valtype 2396option. 2397The following value types are supported: 2398.Bl -tag -width indent 2399.It Ar value-mask : Ar value-type Ns Op , Ns Ar value-mask 2400.It Ar value-type : Ar skipto | pipe | fib | nat | dscp | tag | divert | 2401.Ar netgraph | limit | ipv4 | ipv6 | mark 2402.It Cm skipto 2403rule number to jump to. 2404.It Cm pipe 2405Pipe number to use. 2406.It Cm fib 2407fib number to match/set. 2408.It Cm nat 2409nat number to jump to. 2410.It Cm dscp 2411dscp value to match/set. 2412.It Cm tag 2413tag number to match/set. 2414.It Cm divert 2415port number to divert traffic to. 2416.It Cm netgraph 2417hook number to move packet to. 2418.It Cm limit 2419maximum number of connections. 2420.It Cm ipv4 2421IPv4 nexthop to fwd packets to. 2422.It Cm ipv6 2423IPv6 nexthop to fwd packets to. 2424.It Cm mark 2425mark value to match/set. 2426.El 2427.Pp 2428The 2429.Cm tablearg 2430argument can be used with the following actions: 2431.Cm nat, pipe, queue, divert, tee, netgraph, ngtee, fwd, skipto, setfib , 2432.Cm setmark , 2433action parameters: 2434.Cm tag, untag , 2435rule options: 2436.Cm limit, tagged, mark . 2437.Pp 2438When used with the 2439.Cm skipto 2440action, the user should be aware that the code will walk the ruleset 2441up to a rule equal to, or past, the given number. 2442.Pp 2443See the 2444.Sx EXAMPLES 2445Section for example usage of tables and the tablearg keyword. 2446.Sh SETS OF RULES 2447Each rule or table belongs to one of 32 different 2448.Em sets 2449, numbered 0 to 31. 2450Set 31 is reserved for the default rule. 2451.Pp 2452By default, rules or tables are put in set 0, unless you use the 2453.Cm set N 2454attribute when adding a new rule or table. 2455Sets can be individually and atomically enabled or disabled, 2456so this mechanism permits an easy way to store multiple configurations 2457of the firewall and quickly (and atomically) switch between them. 2458.Pp 2459By default, tables from set 0 are referenced when adding rule with 2460table opcodes regardless of rule set. 2461This behavior can be changed by setting 2462.Va net.inet.ip.fw.tables_sets 2463variable to 1. 2464Rule's set will then be used for table references. 2465.Pp 2466The command to enable/disable sets is 2467.Bd -ragged -offset indent 2468.Nm 2469.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 2470.Ed 2471.Pp 2472where multiple 2473.Cm enable 2474or 2475.Cm disable 2476sections can be specified. 2477Command execution is atomic on all the sets specified in the command. 2478By default, all sets are enabled. 2479.Pp 2480When you disable a set, its rules behave as if they do not exist 2481in the firewall configuration, with only one exception: 2482.Bd -ragged -offset indent 2483dynamic rules created from a rule before it had been disabled 2484will still be active until they expire. 2485In order to delete 2486dynamic rules you have to explicitly delete the parent rule 2487which generated them. 2488.Ed 2489.Pp 2490The set number of rules can be changed with the command 2491.Bd -ragged -offset indent 2492.Nm 2493.Cm set move 2494.Brq Cm rule Ar rule-number | old-set 2495.Cm to Ar new-set 2496.Ed 2497.Pp 2498Also, you can atomically swap two rulesets with the command 2499.Bd -ragged -offset indent 2500.Nm 2501.Cm set swap Ar first-set second-set 2502.Ed 2503.Pp 2504See the 2505.Sx EXAMPLES 2506Section on some possible uses of sets of rules. 2507.Sh STATEFUL FIREWALL 2508Stateful operation is a way for the firewall to dynamically 2509create rules for specific flows when packets that 2510match a given pattern are detected. 2511Support for stateful 2512operation comes through the 2513.Cm check-state , keep-state , record-state , limit 2514and 2515.Cm set-limit 2516options of 2517.Nm rules . 2518.Pp 2519Dynamic rules are created when a packet matches a 2520.Cm keep-state , 2521.Cm record-state , 2522.Cm limit 2523or 2524.Cm set-limit 2525rule, causing the creation of a 2526.Em dynamic 2527rule which will match all and only packets with 2528a given 2529.Em protocol 2530between a 2531.Em src-ip/src-port dst-ip/dst-port 2532pair of addresses 2533.Em ( src 2534and 2535.Em dst 2536are used here only to denote the initial match addresses, but they 2537are completely equivalent afterwards). 2538Rules created by 2539.Cm keep-state 2540option also have a 2541.Ar :flowname 2542taken from it. 2543This name is used in matching together with addresses, ports and protocol. 2544Dynamic rules will be checked at the first 2545.Cm check-state, keep-state 2546or 2547.Cm limit 2548occurrence, and the action performed upon a match will be the same 2549as in the parent rule. 2550.Pp 2551Note that no additional attributes other than protocol and IP addresses 2552and ports and :flowname are checked on dynamic rules. 2553.Pp 2554The typical use of dynamic rules is to keep a closed firewall configuration, 2555but let the first TCP SYN packet from the inside network install a 2556dynamic rule for the flow so that packets belonging to that session 2557will be allowed through the firewall: 2558.Pp 2559.Dl "ipfw add check-state :OUTBOUND" 2560.Dl "ipfw add allow tcp from my-subnet to any setup keep-state :OUTBOUND" 2561.Dl "ipfw add deny tcp from any to any" 2562.Pp 2563A similar approach can be used for UDP, where an UDP packet coming 2564from the inside will install a dynamic rule to let the response through 2565the firewall: 2566.Pp 2567.Dl "ipfw add check-state :OUTBOUND" 2568.Dl "ipfw add allow udp from my-subnet to any keep-state :OUTBOUND" 2569.Dl "ipfw add deny udp from any to any" 2570.Pp 2571Dynamic rules expire after some time, which depends on the status 2572of the flow and the setting of some 2573.Cm sysctl 2574variables. 2575See Section 2576.Sx SYSCTL VARIABLES 2577for more details. 2578For TCP sessions, dynamic rules can be instructed to periodically 2579send keepalive packets to refresh the state of the rule when it is 2580about to expire. 2581.Pp 2582See Section 2583.Sx EXAMPLES 2584for more examples on how to use dynamic rules. 2585.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 2586.Nm 2587is also the user interface for the 2588.Nm dummynet 2589traffic shaper, packet scheduler and network emulator, a subsystem that 2590can artificially queue, delay or drop packets 2591emulating the behaviour of certain network links 2592or queueing systems. 2593.Pp 2594.Nm dummynet 2595operates by first using the firewall to select packets 2596using any match pattern that can be used in 2597.Nm 2598rules. 2599Matching packets are then passed to either of two 2600different objects, which implement the traffic regulation: 2601.Bl -hang -offset XXXX 2602.It Em pipe 2603A 2604.Em pipe 2605emulates a 2606.Em link 2607with given bandwidth and propagation delay, 2608driven by a FIFO scheduler and a single queue with programmable 2609queue size and packet loss rate. 2610Packets are appended to the queue as they come out from 2611.Nm ipfw , 2612and then transferred in FIFO order to the link at the desired rate. 2613.It Em queue 2614A 2615.Em queue 2616is an abstraction used to implement packet scheduling 2617using one of several packet scheduling algorithms. 2618Packets sent to a 2619.Em queue 2620are first grouped into flows according to a mask on the 5-tuple. 2621Flows are then passed to the scheduler associated to the 2622.Em queue , 2623and each flow uses scheduling parameters (weight and others) 2624as configured in the 2625.Em queue 2626itself. 2627A scheduler in turn is connected to an emulated link, 2628and arbitrates the link's bandwidth among backlogged flows according to 2629weights and to the features of the scheduling algorithm in use. 2630.El 2631.Pp 2632In practice, 2633.Em pipes 2634can be used to set hard limits to the bandwidth that a flow can use, whereas 2635.Em queues 2636can be used to determine how different flows share the available bandwidth. 2637.Pp 2638A graphical representation of the binding of queues, 2639flows, schedulers and links is below. 2640.Bd -literal -offset indent 2641 (flow_mask|sched_mask) sched_mask 2642 +---------+ weight Wx +-------------+ 2643 | |->-[flow]-->--| |-+ 2644 -->--| QUEUE x | ... | | | 2645 | |->-[flow]-->--| SCHEDuler N | | 2646 +---------+ | | | 2647 ... | +--[LINK N]-->-- 2648 +---------+ weight Wy | | +--[LINK N]-->-- 2649 | |->-[flow]-->--| | | 2650 -->--| QUEUE y | ... | | | 2651 | |->-[flow]-->--| | | 2652 +---------+ +-------------+ | 2653 +-------------+ 2654.Ed 2655It is important to understand the role of the SCHED_MASK 2656and FLOW_MASK, which are configured through the commands 2657.Dl "ipfw sched N config mask SCHED_MASK ..." 2658and 2659.Dl "ipfw queue X config mask FLOW_MASK ..." . 2660.Pp 2661The SCHED_MASK is used to assign flows to one or more 2662scheduler instances, one for each 2663value of the packet's 5-tuple after applying SCHED_MASK. 2664As an example, using ``src-ip 0xffffff00'' creates one instance 2665for each /24 destination subnet. 2666.Pp 2667The FLOW_MASK, together with the SCHED_MASK, is used to split 2668packets into flows. 2669As an example, using 2670``src-ip 0x000000ff'' 2671together with the previous SCHED_MASK makes a flow for 2672each individual source address. 2673In turn, flows for each /24 2674subnet will be sent to the same scheduler instance. 2675.Pp 2676The above diagram holds even for the 2677.Em pipe 2678case, with the only restriction that a 2679.Em pipe 2680only supports a SCHED_MASK, and forces the use of a FIFO 2681scheduler (these are for backward compatibility reasons; 2682in fact, internally, a 2683.Nm dummynet's 2684pipe is implemented exactly as above). 2685.Pp 2686There are two modes of 2687.Nm dummynet 2688operation: 2689.Dq normal 2690and 2691.Dq fast . 2692The 2693.Dq normal 2694mode tries to emulate a real link: the 2695.Nm dummynet 2696scheduler ensures that the packet will not leave the pipe faster than it 2697would on the real link with a given bandwidth. 2698The 2699.Dq fast 2700mode allows certain packets to bypass the 2701.Nm dummynet 2702scheduler (if packet flow does not exceed pipe's bandwidth). 2703This is the reason why the 2704.Dq fast 2705mode requires less CPU cycles per packet (on average) and packet latency 2706can be significantly lower in comparison to a real link with the same 2707bandwidth. 2708The default mode is 2709.Dq normal . 2710The 2711.Dq fast 2712mode can be enabled by setting the 2713.Va net.inet.ip.dummynet.io_fast 2714.Xr sysctl 8 2715variable to a non-zero value. 2716.Ss PIPE, QUEUE AND SCHEDULER CONFIGURATION 2717The 2718.Em pipe , 2719.Em queue 2720and 2721.Em scheduler 2722configuration commands are the following: 2723.Bd -ragged -offset indent 2724.Cm pipe Ar number Cm config Ar pipe-configuration 2725.Pp 2726.Cm queue Ar number Cm config Ar queue-configuration 2727.Pp 2728.Cm sched Ar number Cm config Ar sched-configuration 2729.Ed 2730.Pp 2731The following parameters can be configured for a pipe: 2732.Pp 2733.Bl -tag -width indent -compact 2734.It Cm bw Ar bandwidth | device 2735Bandwidth, measured in 2736.Sm off 2737.Op Cm K | M | G 2738.Brq Cm bit/s | Byte/s . 2739.Sm on 2740.Pp 2741A value of 0 (default) means unlimited bandwidth. 2742The unit must immediately follow the number, as in 2743.Pp 2744.Dl "dnctl pipe 1 config bw 300Kbit/s" 2745.Pp 2746If a device name is specified instead of a numeric value, as in 2747.Pp 2748.Dl "dnctl pipe 1 config bw tun0" 2749.Pp 2750then the transmit clock is supplied by the specified device. 2751At the moment only the 2752.Xr tun 4 2753device supports this 2754functionality, for use in conjunction with 2755.Xr ppp 8 . 2756.Pp 2757.It Cm delay Ar ms-delay 2758Propagation delay, measured in milliseconds. 2759The value is rounded to the next multiple of the clock tick 2760(typically 10ms, but it is a good practice to run kernels 2761with 2762.Dq "options HZ=1000" 2763to reduce 2764the granularity to 1ms or less). 2765The default value is 0, meaning no delay. 2766.Pp 2767.It Cm burst Ar size 2768If the data to be sent exceeds the pipe's bandwidth limit 2769(and the pipe was previously idle), up to 2770.Ar size 2771bytes of data are allowed to bypass the 2772.Nm dummynet 2773scheduler, and will be sent as fast as the physical link allows. 2774Any additional data will be transmitted at the rate specified 2775by the 2776.Nm pipe 2777bandwidth. 2778The burst size depends on how long the pipe has been idle; 2779the effective burst size is calculated as follows: 2780MAX( 2781.Ar size 2782, 2783.Nm bw 2784* pipe_idle_time). 2785.Pp 2786.It Cm profile Ar filename 2787A file specifying the additional overhead incurred in the transmission 2788of a packet on the link. 2789.Pp 2790Some link types introduce extra delays in the transmission 2791of a packet, e.g., because of MAC level framing, contention on 2792the use of the channel, MAC level retransmissions and so on. 2793From our point of view, the channel is effectively unavailable 2794for this extra time, which is constant or variable depending 2795on the link type. 2796Additionally, packets may be dropped after this 2797time (e.g., on a wireless link after too many retransmissions). 2798We can model the additional delay with an empirical curve 2799that represents its distribution. 2800.Bd -literal -offset indent 2801 cumulative probability 2802 1.0 ^ 2803 | 2804 L +-- loss-level x 2805 | ****** 2806 | * 2807 | ***** 2808 | * 2809 | ** 2810 | * 2811 +-------*-------------------> 2812 delay 2813.Ed 2814The empirical curve may have both vertical and horizontal lines. 2815Vertical lines represent constant delay for a range of 2816probabilities. 2817Horizontal lines correspond to a discontinuity in the delay 2818distribution: the pipe will use the largest delay for a 2819given probability. 2820.Pp 2821The file format is the following, with whitespace acting as 2822a separator and '#' indicating the beginning a comment: 2823.Bl -tag -width indent 2824.It Cm name Ar identifier 2825optional name (listed by "dnctl pipe show") 2826to identify the delay distribution; 2827.It Cm bw Ar value 2828the bandwidth used for the pipe. 2829If not specified here, it must be present 2830explicitly as a configuration parameter for the pipe; 2831.It Cm loss-level Ar L 2832the probability above which packets are lost. 2833(0.0 <= L <= 1.0, default 1.0 i.e., no loss); 2834.It Cm samples Ar N 2835the number of samples used in the internal 2836representation of the curve (2..1024; default 100); 2837.It Cm "delay prob" | "prob delay" 2838One of these two lines is mandatory and defines 2839the format of the following lines with data points. 2840.It Ar XXX Ar YYY 28412 or more lines representing points in the curve, 2842with either delay or probability first, according 2843to the chosen format. 2844The unit for delay is milliseconds. 2845Data points do not need to be sorted. 2846Also, the number of actual lines can be different 2847from the value of the "samples" parameter: 2848.Nm 2849utility will sort and interpolate 2850the curve as needed. 2851.El 2852.Pp 2853Example of a profile file: 2854.Bd -literal -offset indent 2855name bla_bla_bla 2856samples 100 2857loss-level 0.86 2858prob delay 28590 200 # minimum overhead is 200ms 28600.5 200 28610.5 300 28620.8 1000 28630.9 1300 28641 1300 2865#configuration file end 2866.Ed 2867.El 2868.Pp 2869The following parameters can be configured for a queue: 2870.Pp 2871.Bl -tag -width indent -compact 2872.It Cm pipe Ar pipe_nr 2873Connects a queue to the specified pipe. 2874Multiple queues (with the same or different weights) can be connected to 2875the same pipe, which specifies the aggregate rate for the set of queues. 2876.Pp 2877.It Cm weight Ar weight 2878Specifies the weight to be used for flows matching this queue. 2879The weight must be in the range 1..100, and defaults to 1. 2880.El 2881.Pp 2882The following case-insensitive parameters can be configured for a 2883scheduler: 2884.Pp 2885.Bl -tag -width indent -compact 2886.It Cm type Ar {fifo | wf2q+ | rr | qfq | fq_codel | fq_pie} 2887specifies the scheduling algorithm to use. 2888.Bl -tag -width indent -compact 2889.It Cm fifo 2890is just a FIFO scheduler (which means that all packets 2891are stored in the same queue as they arrive to the scheduler). 2892FIFO has O(1) per-packet time complexity, with very low 2893constants (estimate 60-80ns on a 2GHz desktop machine) 2894but gives no service guarantees. 2895.It Cm wf2q+ 2896implements the WF2Q+ algorithm, which is a Weighted Fair Queueing 2897algorithm which permits flows to share bandwidth according to 2898their weights. 2899Note that weights are not priorities; even a flow 2900with a minuscule weight will never starve. 2901WF2Q+ has O(log N) per-packet processing cost, where N is the number 2902of flows, and is the default algorithm used by previous versions 2903dummynet's queues. 2904.It Cm rr 2905implements the Deficit Round Robin algorithm, which has O(1) processing 2906costs (roughly, 100-150ns per packet) 2907and permits bandwidth allocation according to weights, but 2908with poor service guarantees. 2909.It Cm qfq 2910implements the QFQ algorithm, which is a very fast variant of 2911WF2Q+, with similar service guarantees and O(1) processing 2912costs (roughly, 200-250ns per packet). 2913.It Cm fq_codel 2914implements the FQ-CoDel (FlowQueue-CoDel) scheduler/AQM algorithm, which 2915uses a modified Deficit Round Robin scheduler to manage two lists of sub-queues 2916(old sub-queues and new sub-queues) for providing brief periods of priority to 2917lightweight or short burst flows. 2918By default, the total number of sub-queues is 1024. 2919FQ-CoDel's internal, dynamically 2920created sub-queues are controlled by separate instances of CoDel AQM. 2921.It Cm fq_pie 2922implements the FQ-PIE (FlowQueue-PIE) scheduler/AQM algorithm, which similar to 2923.Cm fq_codel 2924but uses per sub-queue PIE AQM instance to control the queue delay. 2925.El 2926.Pp 2927.Cm fq_codel 2928inherits AQM parameters and options from 2929.Cm codel 2930(see below), and 2931.Cm fq_pie 2932inherits AQM parameters and options from 2933.Cm pie 2934(see below). 2935Additionally, both of 2936.Cm fq_codel 2937and 2938.Cm fq_pie 2939have shared scheduler parameters which are: 2940.Bl -tag -width indent 2941.It Cm quantum 2942.Ar m 2943specifies the quantum (credit) of the scheduler. 2944.Ar m 2945is the number of bytes a queue can serve before being moved to the tail 2946of old queues list. 2947The default is 1514 bytes, and the maximum acceptable value 2948is 9000 bytes. 2949.It Cm limit 2950.Ar m 2951specifies the hard size limit (in unit of packets) of all queues managed by an 2952instance of the scheduler. 2953The default value of 2954.Ar m 2955is 10240 packets, and the maximum acceptable value is 20480 packets. 2956.It Cm flows 2957.Ar m 2958specifies the total number of flow queues (sub-queues) that fq_* 2959creates and manages. 2960By default, 1024 sub-queues are created when an instance 2961of the fq_{codel/pie} scheduler is created. 2962The maximum acceptable value is 296365536. 2964.El 2965.Pp 2966Note that any token after 2967.Cm fq_codel 2968or 2969.Cm fq_pie 2970is considered a parameter for fq_{codel/pie}. 2971So, ensure all scheduler 2972configuration options not related to fq_{codel/pie} are written before 2973.Cm fq_codel/fq_pie 2974tokens. 2975.El 2976.Pp 2977In addition to the type, all parameters allowed for a pipe can also 2978be specified for a scheduler. 2979.Pp 2980Finally, the following parameters can be configured for both 2981pipes and queues: 2982.Pp 2983.Bl -tag -width XXXX -compact 2984.It Cm buckets Ar hash-table-size 2985Specifies the size of the hash table used for storing the 2986various queues. 2987Default value is 64 controlled by the 2988.Xr sysctl 8 2989variable 2990.Va net.inet.ip.dummynet.hash_size , 2991allowed range is 16 to 65536. 2992.Pp 2993.It Cm mask Ar mask-specifier 2994Packets sent to a given pipe or queue by an 2995.Nm 2996rule can be further classified into multiple flows, each of which is then 2997sent to a different 2998.Em dynamic 2999pipe or queue. 3000A flow identifier is constructed by masking the IP addresses, 3001ports and protocol types as specified with the 3002.Cm mask 3003options in the configuration of the pipe or queue. 3004For each different flow identifier, a new pipe or queue is created 3005with the same parameters as the original object, and matching packets 3006are sent to it. 3007.Pp 3008Thus, when 3009.Em dynamic pipes 3010are used, each flow will get the same bandwidth as defined by the pipe, 3011whereas when 3012.Em dynamic queues 3013are used, each flow will share the parent's pipe bandwidth evenly 3014with other flows generated by the same queue (note that other queues 3015with different weights might be connected to the same pipe). 3016.br 3017Available mask specifiers are a combination of one or more of the following: 3018.Pp 3019.Cm dst-ip Ar mask , 3020.Cm dst-ip6 Ar mask , 3021.Cm src-ip Ar mask , 3022.Cm src-ip6 Ar mask , 3023.Cm dst-port Ar mask , 3024.Cm src-port Ar mask , 3025.Cm flow-id Ar mask , 3026.Cm proto Ar mask 3027or 3028.Cm all , 3029.Pp 3030where the latter means all bits in all fields are significant. 3031.Pp 3032.It Cm noerror 3033When a packet is dropped by a 3034.Nm dummynet 3035queue or pipe, the error 3036is normally reported to the caller routine in the kernel, in the 3037same way as it happens when a device queue fills up. 3038Setting this 3039option reports the packet as successfully delivered, which can be 3040needed for some experimental setups where you want to simulate 3041loss or congestion at a remote router. 3042.Pp 3043.It Cm plr Ar packet-loss-rate 3044Packet loss rate. 3045Argument 3046.Ar packet-loss-rate 3047is a floating-point number between 0 and 1, with 0 meaning no 3048loss, 1 meaning 100% loss. 3049The loss rate is internally represented on 31 bits. 3050.Pp 3051.It Cm queue Brq Ar slots | size Ns Cm Kbytes 3052Queue size, in 3053.Ar slots 3054or 3055.Cm KBytes . 3056Default value is 50 slots, which 3057is the typical queue size for Ethernet devices. 3058Note that for slow speed links you should keep the queue 3059size short or your traffic might be affected by a significant 3060queueing delay. 3061E.g., 50 max-sized Ethernet packets (1500 bytes) mean 600Kbit 3062or 20s of queue on a 30Kbit/s pipe. 3063Even worse effects can result if you get packets from an 3064interface with a much larger MTU, e.g.\& the loopback interface 3065with its 16KB packets. 3066The 3067.Xr sysctl 8 3068variables 3069.Em net.inet.ip.dummynet.pipe_byte_limit 3070and 3071.Em net.inet.ip.dummynet.pipe_slot_limit 3072control the maximum lengths that can be specified. 3073.Pp 3074.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p 3075[ecn] 3076Make use of the RED (Random Early Detection) queue management algorithm. 3077.Ar w_q 3078and 3079.Ar max_p 3080are floating 3081point numbers between 0 and 1 (inclusive), while 3082.Ar min_th 3083and 3084.Ar max_th 3085are integer numbers specifying thresholds for queue management 3086(thresholds are computed in bytes if the queue has been defined 3087in bytes, in slots otherwise). 3088The two parameters can also be of the same value if needed. 3089The 3090.Nm dummynet 3091also supports the gentle RED variant (gred) and ECN (Explicit Congestion 3092Notification) as optional. 3093Three 3094.Xr sysctl 8 3095variables can be used to control the RED behaviour: 3096.Bl -tag -width indent 3097.It Va net.inet.ip.dummynet.red_lookup_depth 3098specifies the accuracy in computing the average queue 3099when the link is idle (defaults to 256, must be greater than zero) 3100.It Va net.inet.ip.dummynet.red_avg_pkt_size 3101specifies the expected average packet size (defaults to 512, must be 3102greater than zero) 3103.It Va net.inet.ip.dummynet.red_max_pkt_size 3104specifies the expected maximum packet size, only used when queue 3105thresholds are in bytes (defaults to 1500, must be greater than zero). 3106.El 3107.Pp 3108.It Cm codel Oo Cm target Ar time Oc Oo Cm interval Ar time Oc Oo Cm ecn | 3109.Cm noecn Oc 3110Make use of the CoDel (Controlled-Delay) queue management algorithm. 3111.Ar time 3112is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or 3113microseconds (us) can be specified instead. 3114CoDel drops or marks (ECN) packets 3115depending on packet sojourn time in the queue. 3116.Cm target 3117.Ar time 3118(5ms by default) is the minimum acceptable persistent queue delay that CoDel 3119allows. 3120CoDel does not drop packets directly after packets sojourn time becomes 3121higher than 3122.Cm target 3123.Ar time 3124but waits for 3125.Cm interval 3126.Ar time 3127(100ms default) before dropping. 3128.Cm interval 3129.Ar time 3130should be set to maximum RTT for all expected connections. 3131.Cm ecn 3132enables (disabled by default) packet marking (instead of dropping) for 3133ECN-enabled TCP flows when queue delay becomes high. 3134.Pp 3135Note that any token after 3136.Cm codel 3137is considered a parameter for CoDel. 3138So, ensure all pipe/queue 3139configuration options are written before 3140.Cm codel 3141token. 3142.Pp 3143The 3144.Xr sysctl 8 3145variables 3146.Va net.inet.ip.dummynet.codel.target 3147and 3148.Va net.inet.ip.dummynet.codel.interval 3149can be used to set CoDel default parameters. 3150.Pp 3151.It Cm pie Oo Cm target Ar time Oc Oo Cm tupdate Ar time Oc Oo 3152.Cm alpha Ar n Oc Oo Cm beta Ar n Oc Oo Cm max_burst Ar time Oc Oo 3153.Cm max_ecnth Ar n Oc Oo Cm ecn | Cm noecn Oc Oo Cm capdrop | 3154.Cm nocapdrop Oc Oo Cm drand | Cm nodrand Oc Oo Cm onoff 3155.Oc Oo Cm dre | Cm ts Oc 3156Make use of the PIE (Proportional Integral controller Enhanced) queue management 3157algorithm. 3158PIE drops or marks packets depending on a calculated drop probability during 3159en-queue process, with the aim of achieving high throughput while keeping queue 3160delay low. 3161At regular time intervals of 3162.Cm tupdate 3163.Ar time 3164(15ms by default) a background process (re)calculates the probability based on queue delay 3165deviations from 3166.Cm target 3167.Ar time 3168(15ms by default) and queue delay trends. 3169PIE approximates current queue 3170delay by using a departure rate estimation method, or (optionally) by using a 3171packet timestamp method similar to CoDel. 3172.Ar time 3173is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or 3174microseconds (us) can be specified instead. 3175The other PIE parameters and options are as follows: 3176.Bl -tag -width indent 3177.It Cm alpha Ar n 3178.Ar n 3179is a floating point number between 0 and 7 which specifies the weight of queue 3180delay deviations that is used in drop probability calculation. 31810.125 is the default. 3182.It Cm beta Ar n 3183.Ar n 3184is a floating point number between 0 and 7 which specifies is the weight of queue 3185delay trend that is used in drop probability calculation. 31861.25 is the default. 3187.It Cm max_burst Ar time 3188The maximum period of time that PIE does not drop/mark packets. 3189150ms is the 3190default and 10s is the maximum value. 3191.It Cm max_ecnth Ar n 3192Even when ECN is enabled, PIE drops packets instead of marking them when drop 3193probability becomes higher than ECN probability threshold 3194.Cm max_ecnth Ar n 3195, the default is 0.1 (i.e 10%) and 1 is the maximum value. 3196.It Cm ecn | noecn 3197enable or disable ECN marking for ECN-enabled TCP flows. 3198Disabled by default. 3199.It Cm capdrop | nocapdrop 3200enable or disable cap drop adjustment. 3201Cap drop adjustment is enabled by default. 3202.It Cm drand | nodrand 3203enable or disable drop probability de-randomisation. 3204De-randomisation eliminates 3205the problem of dropping packets too close or too far. 3206De-randomisation is enabled by default. 3207.It Cm onoff 3208enable turning PIE on and off depending on queue load. 3209If this option is enabled, 3210PIE turns on when over 1/3 of queue becomes full. 3211This option is disabled by 3212default. 3213.It Cm dre | ts 3214Calculate queue delay using departure rate estimation 3215.Cm dre 3216or timestamps 3217.Cm ts . 3218.Cm dre 3219is used by default. 3220.El 3221.Pp 3222Note that any token after 3223.Cm pie 3224is considered a parameter for PIE. 3225So ensure all pipe/queue 3226the configuration options are written before 3227.Cm pie 3228token. 3229.Xr sysctl 8 3230variables can be used to control the 3231.Cm pie 3232default parameters. 3233See the 3234.Sx SYSCTL VARIABLES 3235section for more details. 3236.El 3237.Pp 3238When used with IPv6 data, 3239.Nm dummynet 3240currently has several limitations. 3241Information necessary to route link-local packets to an 3242interface is not available after processing by 3243.Nm dummynet 3244so those packets are dropped in the output path. 3245Care should be taken to ensure that link-local packets are not passed to 3246.Nm dummynet . 3247.Sh CHECKLIST 3248Here are some important points to consider when designing your 3249rules: 3250.Bl -bullet 3251.It 3252Remember that you filter both packets going 3253.Cm in 3254and 3255.Cm out . 3256Most connections need packets going in both directions. 3257.It 3258Remember to test very carefully. 3259It is a good idea to be near the console when doing this. 3260If you cannot be near the console, 3261use an auto-recovery script such as the one in 3262.Pa /usr/share/examples/ipfw/change_rules.sh . 3263.It 3264Do not forget the loopback interface. 3265.El 3266.Sh FINE POINTS 3267.Bl -bullet 3268.It 3269There are circumstances where fragmented datagrams are unconditionally 3270dropped. 3271TCP packets are dropped if they do not contain at least 20 bytes of 3272TCP header, UDP packets are dropped if they do not contain a full 8 3273byte UDP header, and ICMP packets are dropped if they do not contain 32744 bytes of ICMP header, enough to specify the ICMP type, code, and 3275checksum. 3276These packets are simply logged as 3277.Dq pullup failed 3278since there may not be enough good data in the packet to produce a 3279meaningful log entry. 3280.It 3281Another type of packet is unconditionally dropped, a TCP packet with a 3282fragment offset of one. 3283This is a valid packet, but it only has one use, to try 3284to circumvent firewalls. 3285When logging is enabled, these packets are 3286reported as being dropped by rule -1. 3287.It 3288If you are logged in over a network, loading the 3289.Xr kld 4 3290version of 3291.Nm 3292is probably not as straightforward as you would think. 3293The following command line is recommended: 3294.Bd -literal -offset indent 3295kldload ipfw && \e 3296ipfw add 32000 allow ip from any to any 3297.Ed 3298.Pp 3299Along the same lines, doing an 3300.Bd -literal -offset indent 3301ipfw flush 3302.Ed 3303.Pp 3304in similar surroundings is also a bad idea. 3305.It 3306The 3307.Nm 3308filter list may not be modified if the system security level 3309is set to 3 or higher 3310(see 3311.Xr init 8 3312for information on system security levels). 3313.El 3314.Sh PACKET DIVERSION 3315A 3316.Xr divert 4 3317socket bound to the specified port will receive all packets 3318diverted to that port. 3319If no socket is bound to the destination port, or if the divert module is 3320not loaded, or if the kernel was not compiled with divert socket support, 3321the packets are dropped. 3322.Sh NETWORK ADDRESS TRANSLATION (NAT) 3323.Nm 3324support in-kernel NAT using the kernel version of 3325.Xr libalias 3 . 3326The kernel module 3327.Cm ipfw_nat 3328should be loaded or kernel should have 3329.Cm options IPFIREWALL_NAT 3330to be able use NAT. 3331.Pp 3332The nat configuration command is the following: 3333.Bd -ragged -offset indent 3334.Bk -words 3335.Cm nat 3336.Ar nat_number 3337.Cm config 3338.Ar nat-configuration 3339.Ek 3340.Ed 3341.Pp 3342The following parameters can be configured: 3343.Bl -tag -width indent 3344.It Cm ip Ar ip_address 3345Define an ip address to use for aliasing. 3346.It Cm if Ar nic 3347Use ip address of NIC for aliasing, dynamically changing 3348it if NIC's ip address changes. 3349.It Cm log 3350Enable logging on this nat instance. 3351.It Cm deny_in 3352Deny any incoming connection from outside world. 3353.It Cm same_ports 3354Try to leave the alias port numbers unchanged from 3355the actual local port numbers. 3356.It Cm unreg_only 3357Traffic on the local network not originating from a RFC 1918 3358unregistered address spaces will be ignored. 3359.It Cm unreg_cgn 3360Like unreg_only, but includes the RFC 6598 (Carrier Grade NAT) 3361address range. 3362.It Cm reset 3363Reset table of the packet aliasing engine on address change. 3364.It Cm reverse 3365Reverse the way libalias handles aliasing. 3366.It Cm proxy_only 3367Obey transparent proxy rules only, packet aliasing is not performed. 3368.It Cm skip_global 3369Skip instance in case of global state lookup (see below). 3370.It Cm port_range Ar lower-upper 3371Set the aliasing ports between the ranges given. 3372Upper port has to be greater than lower. 3373.El 3374.Pp 3375Some special values can be supplied instead of 3376.Va nat_number 3377in nat rule actions: 3378.Bl -tag -width indent 3379.It Cm global 3380Looks up translation state in all configured nat instances. 3381If an entry is found, packet is aliased according to that entry. 3382If no entry was found in any of the instances, packet is passed unchanged, 3383and no new entry will be created. 3384See section 3385.Sx MULTIPLE INSTANCES 3386in 3387.Xr natd 8 3388for more information. 3389.It Cm tablearg 3390Uses argument supplied in lookup table. 3391See 3392.Sx LOOKUP TABLES 3393section below for more information on lookup tables. 3394.El 3395.Pp 3396To let the packet continue after being (de)aliased, set the sysctl variable 3397.Va net.inet.ip.fw.one_pass 3398to 0. 3399For more information about aliasing modes, refer to 3400.Xr libalias 3 . 3401See Section 3402.Sx EXAMPLES 3403for some examples of nat usage. 3404.Ss REDIRECT AND LSNAT SUPPORT IN IPFW 3405Redirect and LSNAT support follow closely the syntax used in 3406.Xr natd 8 . 3407See Section 3408.Sx EXAMPLES 3409for some examples on how to do redirect and lsnat. 3410.Ss SCTP NAT SUPPORT 3411SCTP nat can be configured in a similar manner to TCP through the 3412.Nm 3413command line tool. 3414The main difference is that 3415.Nm sctp nat 3416does not do port translation. 3417Since the local and global side ports will be the same, 3418there is no need to specify both. 3419Ports are redirected as follows: 3420.Bd -ragged -offset indent 3421.Bk -words 3422.Cm nat 3423.Ar nat_number 3424.Cm config if 3425.Ar nic 3426.Cm redirect_port sctp 3427.Ar ip_address [,addr_list] {[port | port-port] [,ports]} 3428.Ek 3429.Ed 3430.Pp 3431Most 3432.Nm sctp nat 3433configuration can be done in real-time through the 3434.Xr sysctl 8 3435interface. 3436All may be changed dynamically, though the hash_table size will only 3437change for new 3438.Nm nat 3439instances. 3440See 3441.Sx SYSCTL VARIABLES 3442for more info. 3443.Sh IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 3444.Ss Stateful translation 3445.Nm 3446supports in-kernel IPv6/IPv4 network address and protocol translation. 3447Stateful NAT64 translation allows IPv6-only clients to contact IPv4 servers 3448using unicast TCP, UDP or ICMP protocols. 3449One or more IPv4 addresses assigned to a stateful NAT64 translator are shared 3450among several IPv6-only clients. 3451When stateful NAT64 is used in conjunction with DNS64, no changes are usually 3452required in the IPv6 client or the IPv4 server. 3453The kernel module 3454.Cm ipfw_nat64 3455should be loaded or kernel should have 3456.Cm options IPFIREWALL_NAT64 3457to be able use stateful NAT64 translator. 3458.Pp 3459Stateful NAT64 uses a bunch of memory for several types of objects. 3460When IPv6 client initiates connection, NAT64 translator creates a host entry 3461in the states table. 3462Each host entry uses preallocated IPv4 alias entry. 3463Each alias entry has a number of ports group entries allocated on demand. 3464Ports group entries contains connection state entries. 3465There are several options to control limits and lifetime for these objects. 3466.Pp 3467NAT64 translator follows RFC7915 when does ICMPv6/ICMP translation, 3468unsupported message types will be silently dropped. 3469IPv6 needs several ICMPv6 message types to be explicitly allowed for correct 3470operation. 3471Make sure that ND6 neighbor solicitation (ICMPv6 type 135) and neighbor 3472advertisement (ICMPv6 type 136) messages will not be handled by translation 3473rules. 3474.Pp 3475After translation NAT64 translator by default sends packets through 3476corresponding netisr queue. 3477Thus translator host should be configured as IPv4 and IPv6 router. 3478Also this means, that a packet is handled by firewall twice. 3479First time an original packet is handled and consumed by translator, 3480and then it is handled again as translated packet. 3481This behavior can be changed by sysctl variable 3482.Va net.inet.ip.fw.nat64_direct_output . 3483Also translated packet can be tagged using 3484.Cm tag 3485rule action, and then matched by 3486.Cm tagged 3487opcode to avoid loops and extra overhead. 3488.Pp 3489The stateful NAT64 configuration command is the following: 3490.Bd -ragged -offset indent 3491.Bk -words 3492.Cm nat64lsn 3493.Ar name 3494.Cm create 3495.Ar create-options 3496.Ek 3497.Ed 3498.Pp 3499The following parameters can be configured: 3500.Bl -tag -width indent 3501.It Cm prefix4 Ar ipv4_prefix/plen 3502The IPv4 prefix with mask defines the pool of IPv4 addresses used as 3503source address after translation. 3504Stateful NAT64 module translates IPv6 source address of client to one 3505IPv4 address from this pool. 3506Note that incoming IPv4 packets that don't have corresponding state entry 3507in the states table will be dropped by translator. 3508Make sure that translation rules handle packets, destined to configured prefix. 3509.It Cm prefix6 Ar ipv6_prefix/length 3510The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3511to represent IPv4 addresses. 3512This IPv6 prefix should be configured in DNS64. 3513The translator implementation follows RFC6052, that restricts the length of 3514prefixes to one of following: 32, 40, 48, 56, 64, or 96. 3515The Well-Known IPv6 Prefix 64:ff9b:: must be 96 bits long. 3516The special 3517.Ar ::/length 3518prefix can be used to handle several IPv6 prefixes with one NAT64 instance. 3519The NAT64 instance will determine a destination IPv4 address from prefix 3520.Ar length . 3521.It Cm states_chunks Ar number 3522The number of states chunks in single ports group. 3523Each ports group by default can keep 64 state entries in single chunk. 3524The above value affects the maximum number of states that can be associated with single IPv4 alias address and port. 3525The value must be power of 2, and up to 128. 3526.It Cm host_del_age Ar seconds 3527The number of seconds until the host entry for a IPv6 client will be deleted 3528and all its resources will be released due to inactivity. 3529Default value is 3530.Ar 3600 . 3531.It Cm pg_del_age Ar seconds 3532The number of seconds until a ports group with unused state entries will 3533be released. 3534Default value is 3535.Ar 900 . 3536.It Cm tcp_syn_age Ar seconds 3537The number of seconds while a state entry for TCP connection with only SYN 3538sent will be kept. 3539If TCP connection establishing will not be finished, 3540state entry will be deleted. 3541Default value is 3542.Ar 10 . 3543.It Cm tcp_est_age Ar seconds 3544The number of seconds while a state entry for established TCP connection 3545will be kept. 3546Default value is 3547.Ar 7200 . 3548.It Cm tcp_close_age Ar seconds 3549The number of seconds while a state entry for closed TCP connection 3550will be kept. 3551Keeping state entries for closed connections is needed, because IPv4 servers 3552typically keep closed connections in a TIME_WAIT state for a several minutes. 3553Since translator's IPv4 addresses are shared among all IPv6 clients, 3554new connections from the same addresses and ports may be rejected by server, 3555because these connections are still in a TIME_WAIT state. 3556Keeping them in translator's state table protects from such rejects. 3557Default value is 3558.Ar 180 . 3559.It Cm udp_age Ar seconds 3560The number of seconds while translator keeps state entry in a waiting for 3561reply to the sent UDP datagram. 3562Default value is 3563.Ar 120 . 3564.It Cm icmp_age Ar seconds 3565The number of seconds while translator keeps state entry in a waiting for 3566reply to the sent ICMP message. 3567Default value is 3568.Ar 60 . 3569.It Cm log 3570Turn on logging of all handled packets via BPF through 3571.Ar ipfwlog0 3572interface. 3573.Ar ipfwlog0 3574is a pseudo interface and can be created after a boot manually with 3575.Cm ifconfig 3576command. 3577Note that it has different purpose than 3578.Ar ipfw0 3579interface. 3580Translators sends to BPF an additional information with each packet. 3581With 3582.Cm tcpdump 3583you are able to see each handled packet before and after translation. 3584.It Cm -log 3585Turn off logging of all handled packets via BPF. 3586.It Cm allow_private 3587Turn on processing private IPv4 addresses. 3588By default IPv6 packets with destinations mapped to private address ranges 3589defined by RFC1918 are not processed. 3590.It Cm -allow_private 3591Turn off private address handling in 3592.Nm nat64 3593instance. 3594.El 3595.Pp 3596To inspect a states table of stateful NAT64 the following command can be used: 3597.Bd -ragged -offset indent 3598.Bk -words 3599.Cm nat64lsn 3600.Ar name 3601.Cm show Cm states 3602.Ek 3603.Ed 3604.Pp 3605Stateless NAT64 translator doesn't use a states table for translation 3606and converts IPv4 addresses to IPv6 and vice versa solely based on the 3607mappings taken from configured lookup tables. 3608Since a states table doesn't used by stateless translator, 3609it can be configured to pass IPv4 clients to IPv6-only servers. 3610.Pp 3611The stateless NAT64 configuration command is the following: 3612.Bd -ragged -offset indent 3613.Bk -words 3614.Cm nat64stl 3615.Ar name 3616.Cm create 3617.Ar create-options 3618.Ek 3619.Ed 3620.Pp 3621The following parameters can be configured: 3622.Bl -tag -width indent 3623.It Cm prefix6 Ar ipv6_prefix/length 3624The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3625to represent IPv4 addresses. 3626This IPv6 prefix should be configured in DNS64. 3627.It Cm table4 Ar table46 3628The lookup table 3629.Ar table46 3630contains mapping how IPv4 addresses should be translated to IPv6 addresses. 3631.It Cm table6 Ar table64 3632The lookup table 3633.Ar table64 3634contains mapping how IPv6 addresses should be translated to IPv4 addresses. 3635.It Cm log 3636Turn on logging of all handled packets via BPF through 3637.Ar ipfwlog0 3638interface. 3639.It Cm -log 3640Turn off logging of all handled packets via BPF. 3641.It Cm allow_private 3642Turn on processing private IPv4 addresses. 3643By default IPv6 packets with destinations mapped to private address ranges 3644defined by RFC1918 are not processed. 3645.It Cm -allow_private 3646Turn off private address handling in 3647.Nm nat64 3648instance. 3649.El 3650.Pp 3651Note that the behavior of stateless translator with respect to not matched 3652packets differs from stateful translator. 3653If corresponding addresses was not found in the lookup tables, the packet 3654will not be dropped and the search continues. 3655.Ss XLAT464 CLAT translation 3656XLAT464 CLAT NAT64 translator implements client-side stateless translation as 3657defined in RFC6877 and is very similar to statless NAT64 translator 3658explained above. 3659Instead of lookup tables it uses one-to-one mapping between IPv4 and IPv6 3660addresses using configured prefixes. 3661This mode can be used as a replacement of DNS64 service for applications 3662that are not using it (e.g. VoIP) allowing them to access IPv4-only Internet 3663over IPv6-only networks with help of remote NAT64 translator. 3664.Pp 3665The CLAT NAT64 configuration command is the following: 3666.Bd -ragged -offset indent 3667.Bk -words 3668.Cm nat64clat 3669.Ar name 3670.Cm create 3671.Ar create-options 3672.Ek 3673.Ed 3674.Pp 3675The following parameters can be configured: 3676.Bl -tag -width indent 3677.It Cm clat_prefix Ar ipv6_prefix/length 3678The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3679to represent source IPv4 addresses. 3680.It Cm plat_prefix Ar ipv6_prefix/length 3681The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3682to represent destination IPv4 addresses. 3683This IPv6 prefix should be configured on a remote NAT64 translator. 3684.It Cm log 3685Turn on logging of all handled packets via BPF through 3686.Ar ipfwlog0 3687interface. 3688.It Cm -log 3689Turn off logging of all handled packets via BPF. 3690.It Cm allow_private 3691Turn on processing private IPv4 addresses. 3692By default 3693.Nm nat64clat 3694instance will not process IPv4 packets with destination address from private 3695ranges as defined in RFC1918. 3696.It Cm -allow_private 3697Turn off private address handling in 3698.Nm nat64clat 3699instance. 3700.El 3701.Pp 3702Note that the behavior of CLAT translator with respect to not matched 3703packets differs from stateful translator. 3704If corresponding addresses were not matched against prefixes configured, 3705the packet will not be dropped and the search continues. 3706.Sh IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6) 3707.Nm 3708supports in-kernel IPv6-to-IPv6 network prefix translation as described 3709in RFC6296. 3710The kernel module 3711.Cm ipfw_nptv6 3712should be loaded or kernel should has 3713.Cm options IPFIREWALL_NPTV6 3714to be able use NPTv6 translator. 3715.Pp 3716The NPTv6 configuration command is the following: 3717.Bd -ragged -offset indent 3718.Bk -words 3719.Cm nptv6 3720.Ar name 3721.Cm create 3722.Ar create-options 3723.Ek 3724.Ed 3725.Pp 3726The following parameters can be configured: 3727.Bl -tag -width indent 3728.It Cm int_prefix Ar ipv6_prefix 3729IPv6 prefix used in internal network. 3730NPTv6 module translates source address when it matches this prefix. 3731.It Cm ext_prefix Ar ipv6_prefix 3732IPv6 prefix used in external network. 3733NPTv6 module translates destination address when it matches this prefix. 3734.It Cm ext_if Ar nic 3735The NPTv6 module will use first global IPv6 address from interface 3736.Ar nic 3737as external prefix. 3738It can be useful when IPv6 prefix of external network is dynamically obtained. 3739.Cm ext_prefix 3740and 3741.Cm ext_if 3742options are mutually exclusive. 3743.It Cm prefixlen Ar length 3744The length of specified IPv6 prefixes. 3745It must be in range from 8 to 64. 3746.El 3747.Pp 3748Note that the prefix translation rules are silently ignored when IPv6 packet 3749forwarding is disabled. 3750To enable the packet forwarding, set the sysctl variable 3751.Va net.inet6.ip6.forwarding 3752to 1. 3753.Pp 3754To let the packet continue after being translated, set the sysctl variable 3755.Va net.inet.ip.fw.one_pass 3756to 0. 3757.Sh LOADER TUNABLES 3758Tunables can be set in 3759.Xr loader 8 3760prompt, 3761.Xr loader.conf 5 3762or 3763.Xr kenv 1 3764before ipfw module gets loaded. 3765.Bl -tag -width indent 3766.It Va net.inet.ip.fw.default_to_accept : No 0 3767Defines ipfw last rule behavior. 3768This value overrides 3769.Cd "options IPFW_DEFAULT_TO_(ACCEPT|DENY)" 3770from kernel configuration file. 3771.It Va net.inet.ip.fw.tables_max : No 128 3772Defines number of tables available in ipfw. 3773Number cannot exceed 65534. 3774.El 3775.Sh SYSCTL VARIABLES 3776A set of 3777.Xr sysctl 8 3778variables controls the behaviour of the firewall and 3779associated modules 3780.Pq Nm dummynet , bridge , sctp nat . 3781These are shown below together with their default value 3782(but always check with the 3783.Xr sysctl 8 3784command what value is actually in use) and meaning: 3785.Bl -tag -width indent 3786.It Va net.inet.ip.alias.sctp.accept_global_ootb_addip : No 0 3787Defines how the 3788.Nm nat 3789responds to receipt of global OOTB ASCONF-AddIP: 3790.Bl -tag -width indent 3791.It Cm 0 3792No response (unless a partially matching association exists - 3793ports and vtags match but global address does not) 3794.It Cm 1 3795.Nm nat 3796will accept and process all OOTB global AddIP messages. 3797.El 3798.Pp 3799Option 1 should never be selected as this forms a security risk. 3800An attacker can 3801establish multiple fake associations by sending AddIP messages. 3802.It Va net.inet.ip.alias.sctp.chunk_proc_limit : No 5 3803Defines the maximum number of chunks in an SCTP packet that will be 3804parsed for a 3805packet that matches an existing association. 3806This value is enforced to be greater or equal than 3807.Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit . 3808A high value is 3809a DoS risk yet setting too low a value may result in 3810important control chunks in 3811the packet not being located and parsed. 3812.It Va net.inet.ip.alias.sctp.error_on_ootb : No 1 3813Defines when the 3814.Nm nat 3815responds to any Out-of-the-Blue (OOTB) packets with ErrorM packets. 3816An OOTB packet is a packet that arrives with no existing association 3817registered in the 3818.Nm nat 3819and is not an INIT or ASCONF-AddIP packet: 3820.Bl -tag -width indent 3821.It Cm 0 3822ErrorM is never sent in response to OOTB packets. 3823.It Cm 1 3824ErrorM is only sent to OOTB packets received on the local side. 3825.It Cm 2 3826ErrorM is sent to the local side and on the global side ONLY if there is a 3827partial match (ports and vtags match but the source global IP does not). 3828This value is only useful if the 3829.Nm nat 3830is tracking global IP addresses. 3831.It Cm 3 3832ErrorM is sent in response to all OOTB packets on both 3833the local and global side 3834(DoS risk). 3835.El 3836.Pp 3837At the moment the default is 0, since the ErrorM packet is not yet 3838supported by most SCTP stacks. 3839When it is supported, and if not tracking 3840global addresses, we recommend setting this value to 1 to allow 3841multi-homed local hosts to function with the 3842.Nm nat . 3843To track global addresses, we recommend setting this value to 2 to 3844allow global hosts to be informed when they need to (re)send an 3845ASCONF-AddIP. 3846Value 3 should never be chosen (except for debugging) as the 3847.Nm nat 3848will respond to all OOTB global packets (a DoS risk). 3849.It Va net.inet.ip.alias.sctp.hashtable_size : No 2003 3850Size of hash tables used for 3851.Nm nat 3852lookups (100 < prime_number > 1000001). 3853This value sets the 3854.Nm hash table 3855size for any future created 3856.Nm nat 3857instance and therefore must be set prior to creating a 3858.Nm nat 3859instance. 3860The table sizes may be changed to suit specific needs. 3861If there will be few 3862concurrent associations, and memory is scarce, you may make these smaller. 3863If there will be many thousands (or millions) of concurrent associations, you 3864should make these larger. 3865A prime number is best for the table size. 3866The sysctl 3867update function will adjust your input value to the next highest prime number. 3868.It Va net.inet.ip.alias.sctp.holddown_time : No 0 3869Hold association in table for this many seconds after receiving a 3870SHUTDOWN-COMPLETE. 3871This allows endpoints to correct shutdown gracefully if a 3872shutdown_complete is lost and retransmissions are required. 3873.It Va net.inet.ip.alias.sctp.init_timer : No 15 3874Timeout value while waiting for (INIT-ACK|AddIP-ACK). 3875This value cannot be 0. 3876.It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit : No 2 3877Defines the maximum number of chunks in an SCTP packet that will be parsed when 3878no existing association exists that matches that packet. 3879Ideally this packet 3880will only be an INIT or ASCONF-AddIP packet. 3881A higher value may become a DoS 3882risk as malformed packets can consume processing resources. 3883.It Va net.inet.ip.alias.sctp.param_proc_limit : No 25 3884Defines the maximum number of parameters within a chunk that will be 3885parsed in a 3886packet. 3887As for other similar sysctl variables, larger values pose a DoS risk. 3888.It Va net.inet.ip.alias.sctp.log_level : No 0 3889Level of detail in the system log messages (0 \- minimal, 1 \- event, 38902 \- info, 3 \- detail, 4 \- debug, 5 \- max debug). 3891May be a good 3892option in high loss environments. 3893.It Va net.inet.ip.alias.sctp.shutdown_time : No 15 3894Timeout value while waiting for SHUTDOWN-COMPLETE. 3895This value cannot be 0. 3896.It Va net.inet.ip.alias.sctp.track_global_addresses : No 0 3897Enables/disables global IP address tracking within the 3898.Nm nat 3899and places an 3900upper limit on the number of addresses tracked for each association: 3901.Bl -tag -width indent 3902.It Cm 0 3903Global tracking is disabled 3904.It Cm >1 3905Enables tracking, the maximum number of addresses tracked for each 3906association is limited to this value 3907.El 3908.Pp 3909This variable is fully dynamic, the new value will be adopted for all newly 3910arriving associations, existing associations are treated 3911as they were previously. 3912Global tracking will decrease the number of collisions within the 3913.Nm nat 3914at a cost 3915of increased processing load, memory usage, complexity, and possible 3916.Nm nat 3917state 3918problems in complex networks with multiple 3919.Nm nats . 3920We recommend not tracking 3921global IP addresses, this will still result in a fully functional 3922.Nm nat . 3923.It Va net.inet.ip.alias.sctp.up_timer : No 300 3924Timeout value to keep an association up with no traffic. 3925This value cannot be 0. 3926.It Va net.inet.ip.dummynet.codel.interval : No 100000 3927Default 3928.Cm codel 3929AQM interval in microseconds. 3930The value must be in the range 1..5000000. 3931.It Va net.inet.ip.dummynet.codel.target : No 5000 3932Default 3933.Cm codel 3934AQM target delay time in microseconds (the minimum acceptable persistent queue 3935delay). 3936The value must be in the range 1..5000000. 3937.It Va net.inet.ip.dummynet.expire : No 1 3938Lazily delete dynamic pipes/queue once they have no pending traffic. 3939You can disable this by setting the variable to 0, in which case 3940the pipes/queues will only be deleted when the threshold is reached. 3941.It Va net.inet.ip.dummynet.fqcodel.flows : No 1024 3942Defines the default total number of flow queues (sub-queues) that 3943.Cm fq_codel 3944creates and manages. 3945The value must be in the range 1..65536. 3946.It Va net.inet.ip.dummynet.fqcodel.interval : No 100000 3947Default 3948.Cm fq_codel 3949scheduler/AQM interval in microseconds. 3950The value must be in the range 1..5000000. 3951.It Va net.inet.ip.dummynet.fqcodel.limit : No 10240 3952The default hard size limit (in unit of packet) of all queues managed by an 3953instance of the 3954.Cm fq_codel 3955scheduler. 3956The value must be in the range 1..20480. 3957.It Va net.inet.ip.dummynet.fqcodel.quantum : No 1514 3958The default quantum (credit) of the 3959.Cm fq_codel 3960in unit of byte. 3961The value must be in the range 1..9000. 3962.It Va net.inet.ip.dummynet.fqcodel.target : No 5000 3963Default 3964.Cm fq_codel 3965scheduler/AQM target delay time in microseconds (the minimum acceptable 3966persistent queue delay). 3967The value must be in the range 1..5000000. 3968.It Va net.inet.ip.dummynet.fqpie.alpha : No 125 3969The default 3970.Ar alpha 3971parameter (scaled by 1000) for 3972.Cm fq_pie 3973scheduler/AQM. 3974The value must be in the range 1..7000. 3975.It Va net.inet.ip.dummynet.fqpie.beta : No 1250 3976The default 3977.Ar beta 3978parameter (scaled by 1000) for 3979.Cm fq_pie 3980scheduler/AQM. 3981The value must be in the range 1..7000. 3982.It Va net.inet.ip.dummynet.fqpie.flows : No 1024 3983Defines the default total number of flow queues (sub-queues) that 3984.Cm fq_pie 3985creates and manages. 3986The value must be in the range 1..65536. 3987.It Va net.inet.ip.dummynet.fqpie.limit : No 10240 3988The default hard size limit (in unit of packet) of all queues managed by an 3989instance of the 3990.Cm fq_pie 3991scheduler. 3992The value must be in the range 1..20480. 3993.It Va net.inet.ip.dummynet.fqpie.max_burst : No 150000 3994The default maximum period of microseconds that 3995.Cm fq_pie 3996scheduler/AQM does not drop/mark packets. 3997The value must be in the range 1..10000000. 3998.It Va net.inet.ip.dummynet.fqpie.max_ecnth : No 99 3999The default maximum ECN probability threshold (scaled by 1000) for 4000.Cm fq_pie 4001scheduler/AQM. 4002The value must be in the range 1..7000. 4003.It Va net.inet.ip.dummynet.fqpie.quantum : No 1514 4004The default quantum (credit) of the 4005.Cm fq_pie 4006in unit of byte. 4007The value must be in the range 1..9000. 4008.It Va net.inet.ip.dummynet.fqpie.target : No 15000 4009The default 4010.Cm target 4011delay of the 4012.Cm fq_pie 4013in unit of microsecond. 4014The value must be in the range 1..5000000. 4015.It Va net.inet.ip.dummynet.fqpie.tupdate : No 15000 4016The default 4017.Cm tupdate 4018of the 4019.Cm fq_pie 4020in unit of microsecond. 4021The value must be in the range 1..5000000. 4022.It Va net.inet.ip.dummynet.hash_size : No 64 4023Default size of the hash table used for dynamic pipes/queues. 4024This value is used when no 4025.Cm buckets 4026option is specified when configuring a pipe/queue. 4027.It Va net.inet.ip.dummynet.io_fast : No 0 4028If set to a non-zero value, 4029the 4030.Dq fast 4031mode of 4032.Nm dummynet 4033operation (see above) is enabled. 4034.It Va net.inet.ip.dummynet.io_pkt 4035Number of packets passed to 4036.Nm dummynet . 4037.It Va net.inet.ip.dummynet.io_pkt_drop 4038Number of packets dropped by 4039.Nm dummynet . 4040.It Va net.inet.ip.dummynet.io_pkt_fast 4041Number of packets bypassed by the 4042.Nm dummynet 4043scheduler. 4044.It Va net.inet.ip.dummynet.max_chain_len : No 16 4045Target value for the maximum number of pipes/queues in a hash bucket. 4046The product 4047.Cm max_chain_len*hash_size 4048is used to determine the threshold over which empty pipes/queues 4049will be expired even when 4050.Cm net.inet.ip.dummynet.expire=0 . 4051.It Va net.inet.ip.dummynet.red_lookup_depth : No 256 4052.It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512 4053.It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500 4054Parameters used in the computations of the drop probability 4055for the RED algorithm. 4056.It Va net.inet.ip.dummynet.pie.alpha : No 125 4057The default 4058.Ar alpha 4059parameter (scaled by 1000) for 4060.Cm pie 4061AQM. 4062The value must be in the range 1..7000. 4063.It Va net.inet.ip.dummynet.pie.beta : No 1250 4064The default 4065.Ar beta 4066parameter (scaled by 1000) for 4067.Cm pie 4068AQM. 4069The value must be in the range 1..7000. 4070.It Va net.inet.ip.dummynet.pie.max_burst : No 150000 4071The default maximum period of microseconds that 4072.Cm pie 4073AQM does not drop/mark packets. 4074The value must be in the range 1..10000000. 4075.It Va net.inet.ip.dummynet.pie.max_ecnth : No 99 4076The default maximum ECN probability threshold (scaled by 1000) for 4077.Cm pie 4078AQM. 4079The value must be in the range 1..7000. 4080.It Va net.inet.ip.dummynet.pie.target : No 15000 4081The default 4082.Cm target 4083delay of 4084.Cm pie 4085AQM in unit of microsecond. 4086The value must be in the range 1..5000000. 4087.It Va net.inet.ip.dummynet.pie.tupdate : No 15000 4088The default 4089.Cm tupdate 4090of 4091.Cm pie 4092AQM in unit of microsecond. 4093The value must be in the range 1..5000000. 4094.It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576 4095.It Va net.inet.ip.dummynet.pipe_slot_limit : No 100 4096The maximum queue size that can be specified in bytes or packets. 4097These limits prevent accidental exhaustion of resources such as mbufs. 4098If you raise these limits, 4099you should make sure the system is configured so that sufficient resources 4100are available. 4101.It Va net.inet.ip.fw.autoinc_step : No 100 4102Delta between rule numbers when auto-generating them. 4103The value must be in the range 1..1000. 4104.It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets 4105The current number of buckets in the hash table for dynamic rules 4106(readonly). 4107.It Va net.inet.ip.fw.debug : No 1 4108Controls debugging messages produced by 4109.Nm . 4110.It Va net.inet.ip.fw.default_rule : No 65535 4111The default rule number (read-only). 4112By the design of 4113.Nm , the default rule is the last one, so its number 4114can also serve as the highest number allowed for a rule. 4115.It Va net.inet.ip.fw.dyn_buckets : No 256 4116The number of buckets in the hash table for dynamic rules. 4117Must be a power of 2, up to 65536. 4118It only takes effect when all dynamic rules have expired, so you 4119are advised to use a 4120.Cm flush 4121command to make sure that the hash table is resized. 4122.It Va net.inet.ip.fw.dyn_count : No 3 4123Current number of dynamic rules 4124(read-only). 4125.It Va net.inet.ip.fw.dyn_keepalive : No 1 4126Enables generation of keepalive packets for 4127.Cm keep-state 4128rules on TCP sessions. 4129A keepalive is generated to both 4130sides of the connection every 5 seconds for the last 20 4131seconds of the lifetime of the rule. 4132.It Va net.inet.ip.fw.dyn_max : No 8192 4133Maximum number of dynamic rules. 4134When you hit this limit, no more dynamic rules can be 4135installed until old ones expire. 4136.It Va net.inet.ip.fw.dyn_ack_lifetime : No 300 4137.It Va net.inet.ip.fw.dyn_syn_lifetime : No 20 4138.It Va net.inet.ip.fw.dyn_fin_lifetime : No 1 4139.It Va net.inet.ip.fw.dyn_rst_lifetime : No 1 4140.It Va net.inet.ip.fw.dyn_udp_lifetime : No 5 4141.It Va net.inet.ip.fw.dyn_short_lifetime : No 30 4142These variables control the lifetime, in seconds, of dynamic 4143rules. 4144Upon the initial SYN exchange the lifetime is kept short, 4145then increased after both SYN have been seen, then decreased 4146again during the final FIN exchange or when a RST is received. 4147Both 4148.Em dyn_fin_lifetime 4149and 4150.Em dyn_rst_lifetime 4151must be strictly lower than 5 seconds, the period of 4152repetition of keepalives. 4153The firewall enforces that. 4154.It Va net.inet.ip.fw.dyn_keep_states : No 0 4155Keep dynamic states on rule/set deletion. 4156States are relinked to default rule (65535). 4157This can be handly for ruleset reload. 4158Turned off by default. 4159.It Va net.inet.ip.fw.enable : No 1 4160Enables the firewall. 4161Setting this variable to 0 lets you run your machine without 4162firewall even if compiled in. 4163.It Va net.inet6.ip6.fw.enable : No 1 4164provides the same functionality as above for the IPv6 case. 4165.It Va net.inet.ip.fw.one_pass : No 1 4166When set, the packet exiting from the 4167.Nm dummynet 4168pipe or from 4169.Xr ng_ipfw 4 4170node is not passed though the firewall again. 4171Otherwise, after an action, the packet is 4172reinjected into the firewall at the next rule. 4173.It Va net.inet.ip.fw.tables_max : No 128 4174Maximum number of tables. 4175.It Va net.inet.ip.fw.verbose : No 1 4176Enables verbose messages. 4177.It Va net.inet.ip.fw.verbose_limit : No 0 4178Limits the number of messages produced by a verbose firewall. 4179.It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1 4180If enabled packets with unknown IPv6 Extension Headers will be denied. 4181.It Va net.link.ether.ipfw : No 0 4182Controls whether layer2 packets are passed to 4183.Nm . 4184Default is no. 4185.It Va net.link.bridge.ipfw : No 0 4186Controls whether bridged packets are passed to 4187.Nm . 4188Default is no. 4189.It Va net.inet.ip.fw.nat64_debug : No 0 4190Controls debugging messages produced by 4191.Nm ipfw_nat64 4192module. 4193.It Va net.inet.ip.fw.nat64_direct_output : No 0 4194Controls the output method used by 4195.Nm ipfw_nat64 4196module: 4197.Bl -tag -width indent 4198.It Cm 0 4199A packet is handled by 4200.Nm ipfw 4201twice. 4202First time an original packet is handled by 4203.Nm ipfw 4204and consumed by 4205.Nm ipfw_nat64 4206translator. 4207Then translated packet is queued via netisr to input processing again. 4208.It Cm 1 4209A packet is handled by 4210.Nm ipfw 4211only once, and after translation it will be pushed directly to outgoing 4212interface. 4213.El 4214.El 4215.Sh INTERNAL DIAGNOSTICS 4216There are some commands that may be useful to understand current state 4217of certain subsystems inside kernel module. 4218These commands provide debugging output which may change without notice. 4219.Pp 4220Currently the following commands are available as 4221.Cm internal 4222sub-options: 4223.Bl -tag -width indent 4224.It Cm iflist 4225Lists all interface which are currently tracked by 4226.Nm 4227with their in-kernel status. 4228.It Cm talist 4229List all table lookup algorithms currently available. 4230.El 4231.Sh EXAMPLES 4232There are far too many possible uses of 4233.Nm 4234so this Section will only give a small set of examples. 4235.Ss BASIC PACKET FILTERING 4236This command adds an entry which denies all tcp packets from 4237.Em cracker.evil.org 4238to the telnet port of 4239.Em wolf.tambov.su 4240from being forwarded by the host: 4241.Pp 4242.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet" 4243.Pp 4244This one disallows any connection from the entire cracker's 4245network to my host: 4246.Pp 4247.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org" 4248.Pp 4249A first and efficient way to limit access (not using dynamic rules) 4250is the use of the following rules: 4251.Pp 4252.Dl "ipfw add allow tcp from any to any established" 4253.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup" 4254.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup" 4255.Dl "..." 4256.Dl "ipfw add deny tcp from any to any" 4257.Pp 4258The first rule will be a quick match for normal TCP packets, 4259but it will not match the initial SYN packet, which will be 4260matched by the 4261.Cm setup 4262rules only for selected source/destination pairs. 4263All other SYN packets will be rejected by the final 4264.Cm deny 4265rule. 4266.Pp 4267If you administer one or more subnets, you can take advantage 4268of the address sets and or-blocks and write extremely 4269compact rulesets which selectively enable services to blocks 4270of clients, as below: 4271.Pp 4272.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q" 4273.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q" 4274.Dl "" 4275.Dl "ipfw add allow ip from ${goodguys} to any" 4276.Dl "ipfw add deny ip from ${badguys} to any" 4277.Dl "... normal policies ..." 4278.Pp 4279Allow any transit packets coming from single vlan 10 and 4280going out to vlans 100-1000: 4281.Pp 4282.Dl "ipfw add 10 allow out recv vlan10 \e" 4283.Dl "{ xmit vlan1000 or xmit \*qvlan[1-9]??\*q }" 4284.Pp 4285The 4286.Cm verrevpath 4287option could be used to do automated anti-spoofing by adding the 4288following to the top of a ruleset: 4289.Pp 4290.Dl "ipfw add deny ip from any to any not verrevpath in" 4291.Pp 4292This rule drops all incoming packets that appear to be coming to the 4293system on the wrong interface. 4294For example, a packet with a source 4295address belonging to a host on a protected internal network would be 4296dropped if it tried to enter the system from an external interface. 4297.Pp 4298The 4299.Cm antispoof 4300option could be used to do similar but more restricted anti-spoofing 4301by adding the following to the top of a ruleset: 4302.Pp 4303.Dl "ipfw add deny ip from any to any not antispoof in" 4304.Pp 4305This rule drops all incoming packets that appear to be coming from another 4306directly connected system but on the wrong interface. 4307For example, a packet with a source address of 4308.Li 192.168.0.0/24 , 4309configured on 4310.Li fxp0 , 4311but coming in on 4312.Li fxp1 4313would be dropped. 4314.Pp 4315The 4316.Cm setdscp 4317option could be used to (re)mark user traffic, 4318by adding the following to the appropriate place in ruleset: 4319.Pp 4320.Dl "ipfw add setdscp be ip from any to any dscp af11,af21" 4321.Ss SELECTIVE MIRRORING 4322If your network has network traffic analyzer 4323connected to your host directly via dedicated interface 4324or remotely via RSPAN vlan, you can selectively mirror 4325some Ethernet layer2 frames to the analyzer. 4326.Pp 4327First, make sure your firewall is already configured and runs. 4328Then, enable layer2 processing if not already enabled: 4329.Pp 4330.Dl "sysctl net.link.ether.ipfw=1" 4331.Pp 4332Next, load needed additional kernel modules: 4333.Pp 4334.Dl "kldload ng_ether ng_ipfw" 4335.Pp 4336Optionally, make system load these modules automatically 4337at startup: 4338.Pp 4339.Dl sysrc kld_list+="ng_ether ng_ipfw" 4340.Pp 4341Next, configure 4342.Xr ng_ipfw 4 4343kernel module to transmit mirrored copies of layer2 frames 4344out via vlan900 interface: 4345.Pp 4346.Dl "ngctl connect ipfw: vlan900: 1 lower" 4347.Pp 4348Think of "1" here as of "mirroring instance index" and vlan900 is its 4349destination. 4350You can have arbitrary number of instances. 4351Refer to 4352.Xr ng_ipfw 4 4353for details. 4354.Pp 4355At last, actually start mirroring of selected frames using "instance 1". 4356For frames incoming from em0 interface: 4357.Pp 4358.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 in recv em0" 4359.Pp 4360For frames outgoing to em0 interface: 4361.Pp 4362.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 out xmit em0" 4363.Pp 4364For both incoming and outgoing frames while flowing through em0: 4365.Pp 4366.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 via em0" 4367.Pp 4368Make sure you do not perform mirroring for already duplicated frames 4369or kernel may hang as there is no safety net. 4370.Ss DYNAMIC RULES 4371In order to protect a site from flood attacks involving fake 4372TCP packets, it is safer to use dynamic rules: 4373.Pp 4374.Dl "ipfw add check-state" 4375.Dl "ipfw add deny tcp from any to any established" 4376.Dl "ipfw add allow tcp from my-net to any setup keep-state" 4377.Pp 4378This will let the firewall install dynamic rules only for 4379those connection which start with a regular SYN packet coming 4380from the inside of our network. 4381Dynamic rules are checked when encountering the first 4382occurrence of a 4383.Cm check-state , 4384.Cm keep-state 4385or 4386.Cm limit 4387rule. 4388A 4389.Cm check-state 4390rule should usually be placed near the beginning of the 4391ruleset to minimize the amount of work scanning the ruleset. 4392Your mileage may vary. 4393.Pp 4394For more complex scenarios with dynamic rules 4395.Cm record-state 4396and 4397.Cm defer-action 4398can be used to precisely control creation and checking of dynamic rules. 4399Example of usage of these options are provided in 4400.Sx NETWORK ADDRESS TRANSLATION (NAT) 4401Section. 4402.Pp 4403To limit the number of connections a user can open 4404you can use the following type of rules: 4405.Pp 4406.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10" 4407.Dl "ipfw add allow tcp from any to me setup limit src-addr 4" 4408.Pp 4409The former (assuming it runs on a gateway) will allow each host 4410on a /24 network to open at most 10 TCP connections. 4411The latter can be placed on a server to make sure that a single 4412client does not use more than 4 simultaneous connections. 4413.Pp 4414.Em BEWARE : 4415stateful rules can be subject to denial-of-service attacks 4416by a SYN-flood which opens a huge number of dynamic rules. 4417The effects of such attacks can be partially limited by 4418acting on a set of 4419.Xr sysctl 8 4420variables which control the operation of the firewall. 4421.Pp 4422Here is a good usage of the 4423.Cm list 4424command to see accounting records and timestamp information: 4425.Pp 4426.Dl ipfw -at list 4427.Pp 4428or in short form without timestamps: 4429.Pp 4430.Dl ipfw -a list 4431.Pp 4432which is equivalent to: 4433.Pp 4434.Dl ipfw show 4435.Pp 4436Next rule diverts all incoming packets from 192.168.2.0/24 4437to divert port 5000: 4438.Pp 4439.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in 4440.Ss TRAFFIC SHAPING 4441The following rules show some of the applications of 4442.Nm 4443and 4444.Nm dummynet 4445for simulations and the like. 4446.Pp 4447This rule drops random incoming packets with a probability 4448of 5%: 4449.Pp 4450.Dl "ipfw add prob 0.05 deny ip from any to any in" 4451.Pp 4452A similar effect can be achieved making use of 4453.Nm dummynet 4454pipes: 4455.Pp 4456.Dl "dnctl add pipe 10 ip from any to any" 4457.Dl "dnctl pipe 10 config plr 0.05" 4458.Pp 4459We can use pipes to artificially limit bandwidth, e.g.\& on a 4460machine acting as a router, if we want to limit traffic from 4461local clients on 192.168.2.0/24 we do: 4462.Pp 4463.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 4464.Dl "dnctl pipe 1 config bw 300Kbit/s queue 50KBytes" 4465.Pp 4466note that we use the 4467.Cm out 4468modifier so that the rule is not used twice. 4469Remember in fact that 4470.Nm 4471rules are checked both on incoming and outgoing packets. 4472.Pp 4473Should we want to simulate a bidirectional link with bandwidth 4474limitations, the correct way is the following: 4475.Pp 4476.Dl "ipfw add pipe 1 ip from any to any out" 4477.Dl "ipfw add pipe 2 ip from any to any in" 4478.Dl "dnctl pipe 1 config bw 64Kbit/s queue 10Kbytes" 4479.Dl "dnctl pipe 2 config bw 64Kbit/s queue 10Kbytes" 4480.Pp 4481The above can be very useful, e.g.\& if you want to see how 4482your fancy Web page will look for a residential user who 4483is connected only through a slow link. 4484You should not use only one pipe for both directions, unless 4485you want to simulate a half-duplex medium (e.g.\& AppleTalk, 4486Ethernet, IRDA). 4487It is not necessary that both pipes have the same configuration, 4488so we can also simulate asymmetric links. 4489.Pp 4490Should we want to verify network performance with the RED queue 4491management algorithm: 4492.Pp 4493.Dl "ipfw add pipe 1 ip from any to any" 4494.Dl "dnctl pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1" 4495.Pp 4496Another typical application of the traffic shaper is to 4497introduce some delay in the communication. 4498This can significantly affect applications which do a lot of Remote 4499Procedure Calls, and where the round-trip-time of the 4500connection often becomes a limiting factor much more than 4501bandwidth: 4502.Pp 4503.Dl "ipfw add pipe 1 ip from any to any out" 4504.Dl "ipfw add pipe 2 ip from any to any in" 4505.Dl "dnctl pipe 1 config delay 250ms bw 1Mbit/s" 4506.Dl "dnctl pipe 2 config delay 250ms bw 1Mbit/s" 4507.Pp 4508Per-flow queueing can be useful for a variety of purposes. 4509A very simple one is counting traffic: 4510.Pp 4511.Dl "ipfw add pipe 1 tcp from any to any" 4512.Dl "ipfw add pipe 1 udp from any to any" 4513.Dl "ipfw add pipe 1 ip from any to any" 4514.Dl "dnctl pipe 1 config mask all" 4515.Pp 4516The above set of rules will create queues (and collect 4517statistics) for all traffic. 4518Because the pipes have no limitations, the only effect is 4519collecting statistics. 4520Note that we need 3 rules, not just the last one, because 4521when 4522.Nm 4523tries to match IP packets it will not consider ports, so we 4524would not see connections on separate ports as different 4525ones. 4526.Pp 4527A more sophisticated example is limiting the outbound traffic 4528on a net with per-host limits, rather than per-network limits: 4529.Pp 4530.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 4531.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in" 4532.Dl "dnctl pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 4533.Dl "dnctl pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 4534.Ss LOOKUP TABLES 4535In the following example, we need to create several traffic bandwidth 4536classes and we need different hosts/networks to fall into different classes. 4537We create one pipe for each class and configure them accordingly. 4538Then we create a single table and fill it with IP subnets and addresses. 4539For each subnet/host we set the argument equal to the number of the pipe 4540that it should use. 4541Then we classify traffic using a single rule: 4542.Pp 4543.Dl "dnctl pipe 1 config bw 1000Kbyte/s" 4544.Dl "dnctl pipe 4 config bw 4000Kbyte/s" 4545.Dl "..." 4546.Dl "ipfw table T1 create type addr" 4547.Dl "ipfw table T1 add 192.168.2.0/24 1" 4548.Dl "ipfw table T1 add 192.168.0.0/27 4" 4549.Dl "ipfw table T1 add 192.168.0.2 1" 4550.Dl "..." 4551.Dl "ipfw add pipe tablearg ip from 'table(T1)' to any" 4552.Pp 4553Using the 4554.Cm fwd 4555action, the table entries may include hostnames and IP addresses. 4556.Pp 4557.Dl "ipfw table T2 create type addr valtype ipv4" 4558.Dl "ipfw table T2 add 192.168.2.0/24 10.23.2.1" 4559.Dl "ipfw table T2 add 192.168.0.0/27 router1.dmz" 4560.Dl "..." 4561.Dl "ipfw add 100 fwd tablearg ip from any to 'table(T2)'" 4562.Pp 4563In the following example per-interface firewall is created: 4564.Pp 4565.Dl "ipfw table IN create type iface valtype skipto,fib" 4566.Dl "ipfw table IN add vlan20 12000,12" 4567.Dl "ipfw table IN add vlan30 13000,13" 4568.Dl "ipfw table OUT create type iface valtype skipto" 4569.Dl "ipfw table OUT add vlan20 22000" 4570.Dl "ipfw table OUT add vlan30 23000" 4571.Dl ".." 4572.Dl "ipfw add 100 setfib tablearg ip from any to any recv 'table(IN)' in" 4573.Dl "ipfw add 200 skipto tablearg ip from any to any recv 'table(IN)' in" 4574.Dl "ipfw add 300 skipto tablearg ip from any to any xmit 'table(OUT)' out" 4575.Pp 4576The following example illustrate usage of flow tables: 4577.Pp 4578.Dl "ipfw table fl create type flow:src-ip,proto,dst-ip,dst-port" 4579.Dl "ipfw table fl add 2a02:6b8:77::88,tcp,2a02:6b8:77::99,80 11" 4580.Dl "ipfw table fl add 10.0.0.1,udp,10.0.0.2,53 12" 4581.Dl ".." 4582.Dl "ipfw add 100 allow ip from any to any flow 'table(fl,11)' recv ix0" 4583.Ss SETS OF RULES 4584To add a set of rules atomically, e.g.\& set 18: 4585.Pp 4586.Dl "ipfw set disable 18" 4587.Dl "ipfw add NN set 18 ... # repeat as needed" 4588.Dl "ipfw set enable 18" 4589.Pp 4590To delete a set of rules atomically the command is simply: 4591.Pp 4592.Dl "ipfw delete set 18" 4593.Pp 4594To test a ruleset and disable it and regain control if something goes wrong: 4595.Pp 4596.Dl "ipfw set disable 18" 4597.Dl "ipfw add NN set 18 ... # repeat as needed" 4598.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18" 4599.Pp 4600Here if everything goes well, you press control-C before the "sleep" 4601terminates, and your ruleset will be left active. 4602Otherwise, e.g.\& if 4603you cannot access your box, the ruleset will be disabled after 4604the sleep terminates thus restoring the previous situation. 4605.Pp 4606To show rules of the specific set: 4607.Pp 4608.Dl "ipfw set 18 show" 4609.Pp 4610To show rules of the disabled set: 4611.Pp 4612.Dl "ipfw -S set 18 show" 4613.Pp 4614To clear a specific rule counters of the specific set: 4615.Pp 4616.Dl "ipfw set 18 zero NN" 4617.Pp 4618To delete a specific rule of the specific set: 4619.Pp 4620.Dl "ipfw set 18 delete NN" 4621.Ss NAT, REDIRECT AND LSNAT 4622First redirect all the traffic to nat instance 123: 4623.Pp 4624.Dl "ipfw add nat 123 all from any to any" 4625.Pp 4626Then to configure nat instance 123 to alias all the outgoing traffic with ip 4627192.168.0.123, blocking all incoming connections, trying to keep 4628same ports on both sides, clearing aliasing table on address change 4629and keeping a log of traffic/link statistics: 4630.Pp 4631.Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports" 4632.Pp 4633Or to change address of instance 123, aliasing table will be cleared (see 4634reset option): 4635.Pp 4636.Dl "ipfw nat 123 config ip 10.0.0.1" 4637.Pp 4638To see configuration of nat instance 123: 4639.Pp 4640.Dl "ipfw nat 123 show config" 4641.Pp 4642To show logs of all instances: 4643.Pp 4644.Dl "ipfw nat show log" 4645.Pp 4646To see configurations of all instances: 4647.Pp 4648.Dl "ipfw nat show config" 4649.Pp 4650Or a redirect rule with mixed modes could looks like: 4651.Bd -literal -offset 2n 4652ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66 4653 redirect_port tcp 192.168.0.1:80 500 4654 redirect_proto udp 192.168.1.43 192.168.1.1 4655 redirect_addr 192.168.0.10,192.168.0.11 4656 10.0.0.100 # LSNAT 4657 redirect_port tcp 192.168.0.1:80,192.168.0.10:22 4658 500 # LSNAT 4659.Ed 4660.Pp 4661or it could be split in: 4662.Bd -literal -offset 2n 4663ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66 4664ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500 4665ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1 4666ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12 4667 10.0.0.100 4668ipfw nat 5 config redirect_port tcp 4669 192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500 4670.Ed 4671.Pp 4672Sometimes you may want to mix NAT and dynamic rules. 4673It could be achieved with 4674.Cm record-state 4675and 4676.Cm defer-action 4677options. 4678Problem is, you need to create dynamic rule before NAT and check it 4679after NAT actions (or vice versa) to have consistent addresses and ports. 4680Rule with 4681.Cm keep-state 4682option will trigger activation of existing dynamic state, and action of such 4683rule will be performed as soon as rule is matched. 4684In case of NAT and 4685.Cm allow 4686rule packet need to be passed to NAT, not allowed as soon is possible. 4687.Pp 4688There is example of set of rules to achieve this. 4689Bear in mind that this is example only and it is not very useful by itself. 4690.Pp 4691On way out, after all checks place this rules: 4692.Pp 4693.Dl "ipfw add allow record-state defer-action" 4694.Dl "ipfw add nat 1" 4695.Pp 4696And on way in there should be something like this: 4697.Pp 4698.Dl "ipfw add nat 1" 4699.Dl "ipfw add check-state" 4700.Pp 4701Please note, that first rule on way out doesn't allow packet and doesn't 4702execute existing dynamic rules. 4703All it does, create new dynamic rule with 4704.Cm allow 4705action, if it is not created yet. 4706Later, this dynamic rule is used on way in by 4707.Cm check-state 4708rule. 4709.Ss CONFIGURING CODEL, PIE, FQ-CODEL and FQ-PIE AQM 4710.Cm codel 4711and 4712.Cm pie 4713AQM can be configured for 4714.Nm dummynet 4715.Cm pipe 4716or 4717.Cm queue . 4718.Pp 4719To configure a 4720.Cm pipe 4721with 4722.Cm codel 4723AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s 4724rate limit, we do: 4725.Pp 4726.Dl "dnctl pipe 1 config bw 1mbits/s codel" 4727.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any" 4728.Pp 4729To configure a 4730.Cm queue 4731with 4732.Cm codel 4733AQM using different configurations parameters for traffic from 4734192.168.0.0/24 and 1Mbits/s rate limit, we do: 4735.Pp 4736.Dl "dnctl pipe 1 config bw 1mbits/s" 4737.Dl "dnctl queue 1 config pipe 1 codel target 8ms interval 160ms ecn" 4738.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4739.Pp 4740To configure a 4741.Cm pipe 4742with 4743.Cm pie 4744AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s 4745rate limit, we do: 4746.Pp 4747.Dl "dnctl pipe 1 config bw 1mbits/s pie" 4748.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any" 4749.Pp 4750To configure a 4751.Cm queue 4752with 4753.Cm pie 4754AQM using different configuration parameters for traffic from 4755192.168.0.0/24 and 1Mbits/s rate limit, we do: 4756.Pp 4757.Dl "dnctl pipe 1 config bw 1mbits/s" 4758.Dl "dnctl queue 1 config pipe 1 pie target 20ms tupdate 30ms ecn" 4759.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4760.Pp 4761.Cm fq_codel 4762and 4763.Cm fq_pie 4764AQM can be configured for 4765.Nm dummynet 4766schedulers. 4767.Pp 4768To configure 4769.Cm fq_codel 4770scheduler using different configurations parameters for traffic from 4771192.168.0.0/24 and 1Mbits/s rate limit, we do: 4772.Pp 4773.Dl "dnctl pipe 1 config bw 1mbits/s" 4774.Dl "dnctl sched 1 config pipe 1 type fq_codel" 4775.Dl "dnctl queue 1 config sched 1" 4776.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4777.Pp 4778To change 4779.Cm fq_codel 4780default configuration for a 4781.Cm sched 4782such as disable ECN and change the 4783.Ar target 4784to 10ms, we do: 4785.Pp 4786.Dl "dnctl sched 1 config pipe 1 type fq_codel target 10ms noecn" 4787.Pp 4788Similar to 4789.Cm fq_codel , 4790to configure 4791.Cm fq_pie 4792scheduler using different configurations parameters for traffic from 4793192.168.0.0/24 and 1Mbits/s rate limit, we do: 4794.Pp 4795.Dl "dnctl pipe 1 config bw 1mbits/s" 4796.Dl "dnctl sched 1 config pipe 1 type fq_pie" 4797.Dl "dnctl queue 1 config sched 1" 4798.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4799.Pp 4800The configurations of 4801.Cm fq_pie 4802.Cm sched 4803can be changed in a similar way as for 4804.Cm fq_codel 4805.Sh SEE ALSO 4806.Xr cpp 1 , 4807.Xr m4 1 , 4808.Xr fnmatch 3 , 4809.Xr altq 4 , 4810.Xr divert 4 , 4811.Xr dummynet 4 , 4812.Xr if_bridge 4 , 4813.Xr ip 4 , 4814.Xr ipfirewall 4 , 4815.Xr ng_ether 4 , 4816.Xr ng_ipfw 4 , 4817.Xr protocols 5 , 4818.Xr services 5 , 4819.Xr init 8 , 4820.Xr kldload 8 , 4821.Xr reboot 8 , 4822.Xr sysctl 8 , 4823.Xr syslogd 8 , 4824.Xr sysrc 8 4825.Sh HISTORY 4826The 4827.Nm 4828utility first appeared in 4829.Fx 2.0 . 4830.Nm dummynet 4831was introduced in 4832.Fx 2.2.8 . 4833Stateful extensions were introduced in 4834.Fx 4.0 . 4835.Nm ipfw2 4836was introduced in Summer 2002. 4837.Sh AUTHORS 4838.An Ugen J. S. Antsilevich , 4839.An Poul-Henning Kamp , 4840.An Alex Nash , 4841.An Archie Cobbs , 4842.An Luigi Rizzo , 4843.An Rasool Al-Saadi . 4844.Pp 4845.An -nosplit 4846API based upon code written by 4847.An Daniel Boulet 4848for BSDI. 4849.Pp 4850Dummynet has been introduced by Luigi Rizzo in 1997-1998. 4851.Pp 4852Some early work (1999-2000) on the 4853.Nm dummynet 4854traffic shaper supported by Akamba Corp. 4855.Pp 4856The ipfw core (ipfw2) has been completely redesigned and 4857reimplemented by Luigi Rizzo in summer 2002. 4858Further 4859actions and 4860options have been added by various developers over the years. 4861.Pp 4862.An -nosplit 4863In-kernel NAT support written by 4864.An Paolo Pisati Aq Mt piso@FreeBSD.org 4865as part of a Summer of Code 2005 project. 4866.Pp 4867SCTP 4868.Nm nat 4869support has been developed by 4870.An The Centre for Advanced Internet Architectures (CAIA) Aq http://www.caia.swin.edu.au . 4871The primary developers and maintainers are David Hayes and Jason But. 4872For further information visit: 4873.Aq http://www.caia.swin.edu.au/urp/SONATA 4874.Pp 4875Delay profiles have been developed by Alessandro Cerri and 4876Luigi Rizzo, supported by the 4877European Commission within Projects Onelab and Onelab2. 4878.Pp 4879CoDel, PIE, FQ-CoDel and FQ-PIE AQM for Dummynet have been implemented by 4880.An The Centre for Advanced Internet Architectures (CAIA) 4881in 2016, supported by The Comcast Innovation Fund. 4882The primary developer is 4883Rasool Al-Saadi. 4884.Sh BUGS 4885The syntax has grown over the years and sometimes it might be confusing. 4886Unfortunately, backward compatibility prevents cleaning up mistakes 4887made in the definition of the syntax. 4888.Pp 4889.Em !!! WARNING !!! 4890.Pp 4891Misconfiguring the firewall can put your computer in an unusable state, 4892possibly shutting down network services and requiring console access to 4893regain control of it. 4894.Pp 4895Incoming packet fragments diverted by 4896.Cm divert 4897are reassembled before delivery to the socket. 4898The action used on those packet is the one from the 4899rule which matches the first fragment of the packet. 4900.Pp 4901Packets diverted to userland, and then reinserted by a userland process 4902may lose various packet attributes. 4903The packet source interface name 4904will be preserved if it is shorter than 8 bytes and the userland process 4905saves and reuses the sockaddr_in 4906(as does 4907.Xr natd 8 ) ; 4908otherwise, it may be lost. 4909If a packet is reinserted in this manner, later rules may be incorrectly 4910applied, making the order of 4911.Cm divert 4912rules in the rule sequence very important. 4913.Pp 4914Dummynet drops all packets with IPv6 link-local addresses. 4915.Pp 4916Rules using 4917.Cm uid 4918or 4919.Cm gid 4920may not behave as expected. 4921In particular, incoming SYN packets may 4922have no uid or gid associated with them since they do not yet belong 4923to a TCP connection, and the uid/gid associated with a packet may not 4924be as expected if the associated process calls 4925.Xr setuid 2 4926or similar system calls. 4927.Pp 4928Rule syntax is subject to the command line environment and some patterns 4929may need to be escaped with the backslash character 4930or quoted appropriately. 4931.Pp 4932Due to the architecture of 4933.Xr libalias 3 , 4934ipfw nat is not compatible with the TCP segmentation offloading (TSO). 4935Thus, to reliably nat your network traffic, please disable TSO 4936on your NICs using 4937.Xr ifconfig 8 . 4938.Pp 4939ICMP error messages are not implicitly matched by dynamic rules 4940for the respective conversations. 4941To avoid failures of network error detection and path MTU discovery, 4942ICMP error messages may need to be allowed explicitly through static 4943rules. 4944.Pp 4945Rules using 4946.Cm call 4947and 4948.Cm return 4949actions may lead to confusing behaviour if ruleset has mistakes, 4950and/or interaction with other subsystems (netgraph, dummynet, etc.) is used. 4951One possible case for this is packet leaving 4952.Nm 4953in subroutine on the input pass, while later on output encountering unpaired 4954.Cm return 4955first. 4956As the call stack is kept intact after input pass, packet will suddenly 4957return to the rule number used on input pass, not on output one. 4958Order of processing should be checked carefully to avoid such mistakes. 4959