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