1.\" 2.Dd December 29, 2025 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 | 1432.Cm table Ns Pq Ar name Ns Op , Ns Ar value 1433.Ar | addr-list | addr-set 1434.Brc 1435.Bl -tag -width indent 1436.It Cm any 1437Matches any IP address. 1438.It Cm me 1439Matches any IP address configured on an interface in the system. 1440.It Cm me6 1441Matches any IPv6 address configured on an interface in the system. 1442The address list is evaluated at the time the packet is 1443analysed. 1444.It Cm table Ns Pq Ar name Ns Op , Ns Ar value 1445Matches any IPv4 or IPv6 address for which an entry exists in the lookup table 1446.Ar number . 1447If an optional 32-bit unsigned 1448.Ar value 1449is also specified, an entry will match only if it has this value. 1450If 1451.Ar value 1452is specified in form 1453.Ar valtype=value , 1454then specified value type field will be checked. 1455It can be 1456.Ar skipto, pipe, fib, nat, dscp, tag, divert, netgraph, limit, nh4 1457and 1458.Ar mark. 1459 1460See the 1461.Sx LOOKUP TABLES 1462section below for more information on lookup tables. 1463.El 1464.It Ar addr-list : ip-addr Ns Op , Ns Ar addr-list 1465.It Ar ip-addr : 1466A host or subnet address specified in one of the following ways: 1467.Bl -tag -width indent 1468.It Ar numeric-ip | hostname 1469Matches a single IPv4 address, specified as dotted-quad or a hostname. 1470Hostnames are resolved at the time the rule is added to the firewall list. 1471.It Ar addr Ns / Ns Ar masklen 1472Matches all addresses with base 1473.Ar addr 1474(specified as an IP address, a network number, or a hostname) 1475and mask width of 1476.Cm masklen 1477bits. 1478As an example, 1.2.3.4/25 or 1.2.3.0/25 will match 1479all IP numbers from 1.2.3.0 to 1.2.3.127 . 1480.It Ar addr : Ns Ar mask 1481Matches all addresses with base 1482.Ar addr 1483(specified as an IP address, a network number, or a hostname) 1484and the mask of 1485.Ar mask , 1486specified as a dotted quad. 1487As an example, 1.2.3.4:255.0.255.0 or 1.0.3.0:255.0.255.0 will match 14881.*.3.*. 1489This form is advised only for non-contiguous 1490masks. 1491It is better to resort to the 1492.Ar addr Ns / Ns Ar masklen 1493format for contiguous masks, which is more compact and less 1494error-prone. 1495.El 1496.It Ar addr-set : addr Ns Oo Ns / Ns Ar masklen Oc Ns Cm { Ns Ar list Ns Cm } 1497.It Ar list : Bro Ar num | num-num Brc Ns Op , Ns Ar list 1498Matches all addresses with base address 1499.Ar addr 1500(specified as an IP address, a network number, or a hostname) 1501and whose last byte is in the list between braces { } . 1502Note that there must be no spaces between braces and 1503numbers (spaces after commas are allowed). 1504Elements of the list can be specified as single entries 1505or ranges. 1506The 1507.Ar masklen 1508field is used to limit the size of the set of addresses, 1509and can have any value between 24 and 32. 1510If not specified, 1511it will be assumed as 24. 1512.br 1513This format is particularly useful to handle sparse address sets 1514within a single rule. 1515Because the matching occurs using a 1516bitmask, it takes constant time and dramatically reduces 1517the complexity of rulesets. 1518.br 1519As an example, an address specified as 1.2.3.4/24{128,35-55,89} 1520or 1.2.3.0/24{128,35-55,89} 1521will match the following IP addresses: 1522.br 15231.2.3.128, 1.2.3.35 to 1.2.3.55, 1.2.3.89 . 1524.It Ar addr6-list : ip6-addr Ns Op , Ns Ar addr6-list 1525.It Ar ip6-addr : 1526A host or subnet specified one of the following ways: 1527.Bl -tag -width indent 1528.It Ar numeric-ip | hostname 1529Matches a single IPv6 address as allowed by 1530.Xr inet_pton 3 1531or a hostname. 1532Hostnames are resolved at the time the rule is added to the firewall 1533list. 1534.It Ar addr Ns / Ns Ar masklen 1535Matches all IPv6 addresses with base 1536.Ar addr 1537(specified as allowed by 1538.Xr inet_pton 3 1539or a hostname) 1540and mask width of 1541.Cm masklen 1542bits. 1543.It Ar addr Ns / Ns Ar mask 1544Matches all IPv6 addresses with base 1545.Ar addr 1546(specified as allowed by 1547.Xr inet_pton 3 1548or a hostname) 1549and the mask of 1550.Ar mask , 1551specified as allowed by 1552.Xr inet_pton 3 . 1553As an example, fe::640:0:0/ffff::ffff:ffff:0:0 will match 1554fe:*:*:*:0:640:*:*. 1555This form is advised only for non-contiguous 1556masks. 1557It is better to resort to the 1558.Ar addr Ns / Ns Ar masklen 1559format for contiguous masks, which is more compact and less 1560error-prone. 1561.El 1562.Pp 1563No support for sets of IPv6 addresses is provided because IPv6 addresses 1564are typically random past the initial prefix. 1565.It Ar ports : Bro Ar port | port Ns \&- Ns Ar port Ns Brc Ns Op , Ns Ar ports 1566For protocols which support port numbers (such as SCTP, TCP and UDP), optional 1567.Cm ports 1568may be specified as one or more ports or port ranges, separated 1569by commas but no spaces, and an optional 1570.Cm not 1571operator. 1572The 1573.Ql \&- 1574notation specifies a range of ports (including boundaries). 1575.Pp 1576Service names (from 1577.Pa /etc/services ) 1578may be used instead of numeric port values. 1579The length of the port list is limited to 30 ports or ranges, 1580though one can specify larger ranges by using an 1581.Em or-block 1582in the 1583.Cm options 1584section of the rule. 1585.Pp 1586A backslash 1587.Pq Ql \e 1588can be used to escape the dash 1589.Pq Ql - 1590character in a service name (from a shell, the backslash must be 1591typed twice to avoid the shell itself interpreting it as an escape 1592character). 1593.Pp 1594.Dl "ipfw add count tcp from any ftp\e\e-data-ftp to any" 1595.Pp 1596Fragmented packets which have a non-zero offset (i.e., not the first 1597fragment) will never match a rule which has one or more port 1598specifications. 1599See the 1600.Cm frag 1601option for details on matching fragmented packets. 1602.El 1603.Ss RULE OPTIONS (MATCH PATTERNS) 1604Additional match patterns can be used within 1605rules. 1606Zero or more of these so-called 1607.Em options 1608can be present in a rule, optionally prefixed by the 1609.Cm not 1610operand, and possibly grouped into 1611.Em or-blocks . 1612.Pp 1613The following match patterns can be used (listed in alphabetical order): 1614.Bl -tag -width indent 1615.It Cm // this is a comment . 1616Inserts the specified text as a comment in the rule. 1617Everything following // is considered as a comment and stored in the rule. 1618You can have comment-only rules, which are listed as having a 1619.Cm count 1620action followed by the comment. 1621.It Cm bridged 1622Alias for 1623.Cm layer2 . 1624.It Cm defer-immediate-action | defer-action 1625A rule with this option will not perform normal action 1626upon a match. 1627This option is intended to be used with 1628.Cm record-state 1629or 1630.Cm keep-state 1631as the dynamic rule, created but ignored on match, will work 1632as intended. 1633Rules with both 1634.Cm record-state 1635and 1636.Cm defer-immediate-action 1637create a dynamic rule and continue with the next rule without actually 1638performing the action part of this rule. 1639When the rule is later activated via the state table, the action is 1640performed as usual. 1641.It Cm diverted 1642Matches only packets generated by a divert socket. 1643.It Cm diverted-loopback 1644Matches only packets coming from a divert socket back into the IP stack 1645input for delivery. 1646.It Cm diverted-output 1647Matches only packets going from a divert socket back outward to the IP 1648stack output for delivery. 1649.It Cm dst-ip Ar ip-address 1650Matches IPv4 packets whose destination IP is one of the address(es) 1651specified as argument. 1652.It Bro Cm dst-ip6 | dst-ipv6 Brc Ar ip6-address 1653Matches IPv6 packets whose destination IP is one of the address(es) 1654specified as argument. 1655.It Cm dst-port Ar ports 1656Matches IP packets whose destination port is one of the port(s) 1657specified as argument. 1658.It Cm established 1659Matches TCP packets that have the RST or ACK bits set. 1660.It Cm ext6hdr Ar header 1661Matches IPv6 packets containing the extended header given by 1662.Ar header . 1663Supported headers are: 1664.Pp 1665Fragment, 1666.Pq Cm frag , 1667Hop-to-hop options 1668.Pq Cm hopopt , 1669any type of Routing Header 1670.Pq Cm route , 1671Source routing Routing Header Type 0 1672.Pq Cm rthdr0 , 1673Mobile IPv6 Routing Header Type 2 1674.Pq Cm rthdr2 , 1675Destination options 1676.Pq Cm dstopt , 1677IPSec authentication headers 1678.Pq Cm ah , 1679and IPsec encapsulating security payload headers 1680.Pq Cm esp . 1681.It Cm fib Ar fibnum 1682Matches a packet that has been tagged to use 1683the given FIB (routing table) number. 1684.It Cm flow Ar table Ns Pq Ar name Ns Op , Ns Ar value 1685Search for the flow entry in lookup table 1686.Ar name . 1687If not found, the match fails. 1688Otherwise, the match succeeds and 1689.Cm tablearg 1690is set to the value extracted from the table. 1691.Pp 1692This option can be useful to quickly dispatch traffic based on 1693certain packet fields. 1694See the 1695.Sx LOOKUP TABLES 1696section below for more information on lookup tables. 1697.It Cm flow-id Ar labels 1698Matches IPv6 packets containing any of the flow labels given in 1699.Ar labels . 1700.Ar labels 1701is a comma separated list of numeric flow labels. 1702.It Cm dst-mac Ar table Ns Pq Ar name Ns Op , Ns Ar value 1703Search for the destination MAC address entry in lookup table 1704.Ar name . 1705If not found, the match fails. 1706Otherwise, the match succeeds and 1707.Cm tablearg 1708is set to the value extracted from the table. 1709.It Cm src-mac Ar table Ns Pq Ar name Ns Op , Ns Ar value 1710Search for the source MAC address entry in lookup table 1711.Ar name . 1712If not found, the match fails. 1713Otherwise, the match succeeds and 1714.Cm tablearg 1715is set to the value extracted from the table. 1716.It Cm frag Ar spec 1717Matches IPv4 packets whose 1718.Cm ip_off 1719field contains the comma separated list of IPv4 fragmentation 1720options specified in 1721.Ar spec . 1722The recognized options are: 1723.Cm df 1724.Pq Dv don't fragment , 1725.Cm mf 1726.Pq Dv more fragments , 1727.Cm rf 1728.Pq Dv reserved fragment bit 1729.Cm offset 1730.Pq Dv non-zero fragment offset . 1731The absence of a particular options may be denoted 1732with a 1733.Ql \&! . 1734.Pp 1735Empty list of options defaults to matching on non-zero fragment offset. 1736Such rule would match all not the first fragment datagrams, 1737both IPv4 and IPv6. 1738This is a backward compatibility with older rulesets. 1739.It Cm gid Ar group 1740Matches all TCP or UDP packets sent by or received for a 1741.Ar group . 1742A 1743.Ar group 1744may be specified by name or number. 1745.It Cm jail Ar jail 1746Matches all TCP or UDP packets sent by or received for the 1747jail whose ID or name is 1748.Ar jail . 1749.It Cm icmptypes Ar types 1750Matches ICMP packets whose ICMP type is in the list 1751.Ar types . 1752The list may be specified as any combination of 1753individual types (numeric) separated by commas. 1754.Em Ranges are not allowed . 1755The supported ICMP types are: 1756.Pp 1757echo reply 1758.Pq Cm 0 , 1759destination unreachable 1760.Pq Cm 3 , 1761source quench 1762.Pq Cm 4 , 1763redirect 1764.Pq Cm 5 , 1765echo request 1766.Pq Cm 8 , 1767router advertisement 1768.Pq Cm 9 , 1769router solicitation 1770.Pq Cm 10 , 1771time-to-live exceeded 1772.Pq Cm 11 , 1773IP header bad 1774.Pq Cm 12 , 1775timestamp request 1776.Pq Cm 13 , 1777timestamp reply 1778.Pq Cm 14 , 1779information request 1780.Pq Cm 15 , 1781information reply 1782.Pq Cm 16 , 1783address mask request 1784.Pq Cm 17 1785and address mask reply 1786.Pq Cm 18 . 1787.It Cm icmp6types Ar types 1788Matches ICMP6 packets whose ICMP6 type is in the list of 1789.Ar types . 1790The list may be specified as any combination of 1791individual types (numeric) separated by commas. 1792.Em Ranges are not allowed . 1793.It Cm in | out 1794Matches incoming or outgoing packets, respectively. 1795.Cm in 1796and 1797.Cm out 1798are mutually exclusive (in fact, 1799.Cm out 1800is implemented as 1801.Cm not in Ns No ). 1802.It Cm ipid Ar id-list 1803Matches IPv4 packets whose 1804.Cm ip_id 1805field has value included in 1806.Ar id-list , 1807which is either a single value or a list of values or ranges 1808specified in the same way as 1809.Ar ports . 1810.It Cm iplen Ar len-list 1811Matches IP packets whose total length, including header and data, is 1812in the set 1813.Ar len-list , 1814which is either a single value or a list of values or ranges 1815specified in the same way as 1816.Ar ports . 1817.It Cm ipoptions Ar spec 1818Matches packets whose IPv4 header contains the comma separated list of 1819options specified in 1820.Ar spec . 1821The supported IP options are: 1822.Pp 1823.Cm ssrr 1824(strict source route), 1825.Cm lsrr 1826(loose source route), 1827.Cm rr 1828(record packet route) and 1829.Cm ts 1830(timestamp). 1831The absence of a particular option may be denoted 1832with a 1833.Ql \&! . 1834.It Cm ipprecedence Ar precedence 1835Matches IPv4 packets whose precedence field is equal to 1836.Ar precedence . 1837.It Cm ipsec 1838Matches packets that have IPSEC history associated with them 1839(i.e., the packet comes encapsulated in IPSEC, the kernel 1840has IPSEC support, and can correctly decapsulate it). 1841.Pp 1842Note that specifying 1843.Cm ipsec 1844is different from specifying 1845.Cm proto Ar ipsec 1846as the latter will only look at the specific IP protocol field, 1847irrespective of IPSEC kernel support and the validity of the IPSEC data. 1848.Pp 1849Further note that this flag is silently ignored in kernels without 1850IPSEC support. 1851It does not affect rule processing when given and the 1852rules are handled as if with no 1853.Cm ipsec 1854flag. 1855.It Cm iptos Ar spec 1856Matches IPv4 packets whose 1857.Cm tos 1858field contains the comma separated list of 1859service types specified in 1860.Ar spec . 1861The supported IP types of service are: 1862.Pp 1863.Cm lowdelay 1864.Pq Dv IPTOS_LOWDELAY , 1865.Cm throughput 1866.Pq Dv IPTOS_THROUGHPUT , 1867.Cm reliability 1868.Pq Dv IPTOS_RELIABILITY , 1869.Cm mincost 1870.Pq Dv IPTOS_MINCOST , 1871.Cm congestion 1872.Pq Dv IPTOS_ECN_CE . 1873The absence of a particular type may be denoted 1874with a 1875.Ql \&! . 1876.It Cm dscp spec Ns Op , Ns Ar spec 1877Matches IPv4/IPv6 packets whose 1878.Cm DS 1879field value is contained in 1880.Ar spec 1881mask. 1882Multiple values can be specified via 1883the comma separated list. 1884Value can be one of keywords used in 1885.Cm setdscp 1886action or exact number. 1887.It Cm ipttl Ar ttl-list 1888Matches IPv4 packets whose time to live is included in 1889.Ar ttl-list , 1890which is either a single value or a list of values or ranges 1891specified in the same way as 1892.Ar ports . 1893.It Cm ipversion Ar ver 1894Matches IP packets whose IP version field is 1895.Ar ver . 1896.It Cm keep-state Op Ar :flowname 1897Upon a match, the firewall will create a dynamic rule, whose 1898default behaviour is to match bidirectional traffic between 1899source and destination IP/port using the same protocol. 1900The rule has a limited lifetime (controlled by a set of 1901.Xr sysctl 8 1902variables), and the lifetime is refreshed every time a matching 1903packet is found. 1904The 1905.Ar :flowname 1906is used to assign additional to addresses, ports and protocol parameter 1907to dynamic rule. 1908It can be used for more accurate matching by 1909.Cm check-state 1910rule. 1911The 1912.Cm :default 1913keyword is special name used for compatibility with old rulesets. 1914.It Cm layer2 1915Matches only layer2 packets, i.e., those passed to 1916.Nm 1917from 1918.Fn ether_demux 1919and 1920.Fn ether_output_frame . 1921.It Cm limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N Op Ar :flowname 1922The firewall will only allow 1923.Ar N 1924connections with the same 1925set of parameters as specified in the rule. 1926One or more 1927of source and destination addresses and ports can be 1928specified. 1929.It Cm lookup Bro Cm dst-ip | dst-port | dst-mac | src-ip | src-port | src-mac | uid | 1930.Cm jail | dscp | mark | rulenum Brc Ar name 1931Search an entry in lookup table 1932.Ar name 1933that matches the field specified as argument. 1934If not found, the match fails. 1935Otherwise, the match succeeds and 1936.Cm tablearg 1937is set to the value extracted from the table. 1938.Pp 1939This option can be useful to quickly dispatch traffic based on 1940certain packet fields. 1941See the 1942.Sx LOOKUP TABLES 1943section below for more information on lookup tables. 1944.It Cm { MAC | mac } Ar dst-mac src-mac 1945Match packets with a given 1946.Ar dst-mac 1947and 1948.Ar src-mac 1949addresses, specified as the 1950.Cm any 1951keyword (matching any MAC address), or six groups of hex digits 1952separated by colons, 1953and optionally followed by a mask indicating the significant bits. 1954The mask may be specified using either of the following methods: 1955.Bl -enum -width indent 1956.It 1957A slash 1958.Pq / 1959followed by the number of significant bits. 1960For example, an address with 33 significant bits could be specified as: 1961.Pp 1962.Dl "MAC 10:20:30:40:50:60/33 any" 1963.It 1964An ampersand 1965.Pq & 1966followed by a bitmask specified as six groups of hex digits separated 1967by colons. 1968For example, an address in which the last 16 bits are significant could 1969be specified as: 1970.Pp 1971.Dl "MAC 10:20:30:40:50:60&00:00:00:00:ff:ff any" 1972.Pp 1973Note that the ampersand character has a special meaning in many shells 1974and should generally be escaped. 1975.El 1976Note that the order of MAC addresses (destination first, 1977source second) is 1978the same as on the wire, but the opposite of the one used for 1979IP addresses. 1980.It Cm mac-type Ar mac-type 1981Matches packets whose Ethernet Type field 1982corresponds to one of those specified as argument. 1983.Ar mac-type 1984is specified in the same way as 1985.Cm port numbers 1986(i.e., one or more comma-separated single values or ranges). 1987You can use symbolic names for known values such as 1988.Em vlan , ipv4, ipv6 . 1989Values can be entered as decimal or hexadecimal (if prefixed by 0x), 1990and they are always printed as hexadecimal (unless the 1991.Cm -N 1992option is used, in which case symbolic resolution will be attempted). 1993.It Cm proto Ar protocol 1994Matches packets with the corresponding IP protocol. 1995.It Cm record-state 1996Upon a match, the firewall will create a dynamic rule as if 1997.Cm keep-state 1998was specified. 1999However, this option doesn't imply an implicit 2000.Cm check-state 2001in contrast to 2002.Cm keep-state . 2003.It Cm recv | xmit | via Brq Ar ifX | Ar ifmask | Ar table Ns Po Ar name Ns Oo , Ns Ar value Oc Pc | Ar ipno | Ar any 2004Matches packets received, transmitted or going through, 2005respectively, the interface specified by exact name 2006.Po Ar ifX Pc , 2007by device mask 2008.Po Ar ifmask Pc , 2009by IP address, or through some interface. 2010.Pp 2011Interface 2012name may be matched against 2013.Ar ifmask 2014with 2015.Xr fnmatch 3 2016according to the rules used by the shell (f.e. tun*). 2017See also the 2018.Sx EXAMPLES 2019section. 2020.Pp 2021Table 2022.Ar name 2023may be used to match interface by its kernel ifindex. 2024See the 2025.Sx LOOKUP TABLES 2026section below for more information on lookup tables. 2027.Pp 2028The 2029.Cm via 2030keyword causes the interface to always be checked. 2031If 2032.Cm recv 2033or 2034.Cm xmit 2035is used instead of 2036.Cm via , 2037then only the receive or transmit interface (respectively) 2038is checked. 2039By specifying both, it is possible to match packets based on 2040both receive and transmit interface, e.g.: 2041.Pp 2042.Dl "ipfw add deny ip from any to any out recv ed0 xmit ed1" 2043.Pp 2044The 2045.Cm recv 2046interface can be tested on either incoming or outgoing packets, 2047while the 2048.Cm xmit 2049interface can only be tested on outgoing packets. 2050So 2051.Cm out 2052is required (and 2053.Cm in 2054is invalid) whenever 2055.Cm xmit 2056is used. 2057.Pp 2058A packet might not have a receive or transmit interface: packets 2059originating from the local host have no receive interface, 2060while packets destined for the local host have no transmit 2061interface. 2062.It Cm set-limit Bro Cm src-addr | src-port | dst-addr | dst-port Brc Ar N 2063Works like 2064.Cm limit 2065but does not have an implicit 2066.Cm check-state 2067attached to it. 2068.It Cm setup 2069Matches TCP packets that have the SYN bit set but no ACK bit. 2070This is the short form of 2071.Dq Li tcpflags\ syn,!ack . 2072.It Cm sockarg 2073Matches packets that are associated to a local socket and 2074for which the SO_USER_COOKIE socket option has been set 2075to a non-zero value. 2076As a side effect, the value of the 2077option is made available as 2078.Cm tablearg 2079value, which in turn can be used as 2080.Cm skipto 2081or 2082.Cm pipe 2083number. 2084.It Cm src-ip Ar ip-address 2085Matches IPv4 packets whose source IP is one of the address(es) 2086specified as an argument. 2087.It Cm src-ip6 Ar ip6-address 2088Matches IPv6 packets whose source IP is one of the address(es) 2089specified as an argument. 2090.It Cm src-port Ar ports 2091Matches IP packets whose source port is one of the port(s) 2092specified as argument. 2093.It Cm tagged Ar tag-list 2094Matches packets whose tags are included in 2095.Ar tag-list , 2096which is either a single value or a list of values or ranges 2097specified in the same way as 2098.Ar ports . 2099Tags can be applied to the packet using 2100.Cm tag 2101rule action parameter (see it's description for details on tags). 2102.It Cm mark Ar value[:bitmask] | tablearg[:bitmask] 2103Matches packets whose mark is equal to 2104.Ar value 2105with optional 2106.Ar bitmask 2107applied to it. 2108.Cm tablearg 2109can also be used instead of an explicit 2110.Ar value 2111to match a value supplied by the last table lookup. 2112.Pp 2113Both 2114.Ar value 2115and 2116.Ar bitmask 2117can be entered as decimal or hexadecimal (if prefixed by 0x), and they 2118are always printed as hexadecimal. 2119.It Cm tcpack Ar ack 2120TCP packets only. 2121Match if the TCP header acknowledgment number field is set to 2122.Ar ack . 2123.It Cm tcpdatalen Ar tcpdatalen-list 2124Matches TCP packets whose length of TCP data is 2125.Ar tcpdatalen-list , 2126which is either a single value or a list of values or ranges 2127specified in the same way as 2128.Ar ports . 2129.It Cm tcpflags Ar spec 2130TCP packets only. 2131Match if the TCP header contains the comma separated list of 2132flags specified in 2133.Ar spec . 2134The supported TCP flags are: 2135.Pp 2136.Cm fin , 2137.Cm syn , 2138.Cm rst , 2139.Cm psh , 2140.Cm ack 2141and 2142.Cm urg . 2143The absence of a particular flag may be denoted 2144with a 2145.Ql \&! . 2146A rule which contains a 2147.Cm tcpflags 2148specification can never match a fragmented packet which has 2149a non-zero offset. 2150See the 2151.Cm frag 2152option for details on matching fragmented packets. 2153.It Cm tcpmss Ar tcpmss-list 2154Matches TCP packets whose MSS (maximum segment size) value is set to 2155.Ar tcpmss-list , 2156which is either a single value or a list of values or ranges 2157specified in the same way as 2158.Ar ports . 2159.It Cm tcpseq Ar seq 2160TCP packets only. 2161Match if the TCP header sequence number field is set to 2162.Ar seq . 2163.It Cm tcpwin Ar tcpwin-list 2164Matches TCP packets whose header window field is set to 2165.Ar tcpwin-list , 2166which is either a single value or a list of values or ranges 2167specified in the same way as 2168.Ar ports . 2169.It Cm tcpoptions Ar spec 2170TCP packets only. 2171Match if the TCP header contains the comma separated list of 2172options specified in 2173.Ar spec . 2174The supported TCP options are: 2175.Pp 2176.Cm mss 2177(maximum segment size), 2178.Cm window 2179(tcp window advertisement), 2180.Cm sack 2181(selective ack), 2182.Cm ts 2183(rfc1323 timestamp) and 2184.Cm cc 2185(rfc1644 t/tcp connection count). 2186The absence of a particular option may be denoted 2187with a 2188.Ql \&! . 2189.It Cm uid Ar user 2190Match all TCP or UDP packets sent by or received for a 2191.Ar user . 2192A 2193.Ar user 2194may be matched by name or identification number. 2195.It Cm verrevpath 2196For incoming packets, 2197a routing table lookup is done on the packet's source address. 2198If the interface on which the packet entered the system matches the 2199outgoing interface for the route, 2200the packet matches. 2201If the interfaces do not match up, 2202the packet does not match. 2203All outgoing packets or packets with no incoming interface match. 2204.Pp 2205The name and functionality of the option is intentionally similar to 2206the Cisco IOS command: 2207.Pp 2208.Dl ip verify unicast reverse-path 2209.Pp 2210This option can be used to make anti-spoofing rules to reject all 2211packets with source addresses not from this interface. 2212See also the option 2213.Cm antispoof . 2214.It Cm versrcreach 2215For incoming packets, 2216a routing table lookup is done on the packet's source address. 2217If a route to the source address exists, but not the default route 2218or a blackhole/reject route, the packet matches. 2219Otherwise, the packet does not match. 2220All outgoing packets match. 2221.Pp 2222The name and functionality of the option is intentionally similar to 2223the Cisco IOS command: 2224.Pp 2225.Dl ip verify unicast source reachable-via any 2226.Pp 2227This option can be used to make anti-spoofing rules to reject all 2228packets whose source address is unreachable. 2229.It Cm antispoof 2230For incoming packets, the packet's source address is checked if it 2231belongs to a directly connected network. 2232If the network is directly connected, then the interface the packet 2233came on in is compared to the interface the network is connected to. 2234When incoming interface and directly connected interface are not the 2235same, the packet does not match. 2236Otherwise, the packet does match. 2237All outgoing packets match. 2238.Pp 2239This option can be used to make anti-spoofing rules to reject all 2240packets that pretend to be from a directly connected network but do 2241not come in through that interface. 2242This option is similar to but more restricted than 2243.Cm verrevpath 2244because it engages only on packets with source addresses of directly 2245connected networks instead of all source addresses. 2246.El 2247.Sh LOOKUP TABLES 2248Lookup tables are useful to handle large sparse sets of 2249addresses or other search keys (e.g., ports, jail IDs, interface names). 2250In the rest of this section we will use the term ``key''. 2251Table name needs to match the following spec: 2252.Ar table-name . 2253Tables with the same name can be created in different 2254.Ar sets . 2255However, rule links to the tables in 2256.Ar set 0 2257by default. 2258This behavior can be controlled by 2259.Va net.inet.ip.fw.tables_sets 2260variable. 2261See the 2262.Sx SETS OF RULES 2263section for more information. 2264There may be up to 65535 different lookup tables. 2265.Pp 2266The following table types are supported: 2267.Bl -tag -width indent 2268.It Ar table-type : Ar addr | iface | number | flow | mac 2269.It Ar table-key : Ar addr Ns Oo / Ns Ar masklen Oc | iface-name | number | flow-spec 2270.It Ar flow-spec : Ar flow-field Ns Op , Ns Ar flow-spec 2271.It Ar flow-field : src-ip | proto | src-port | dst-ip | dst-port 2272.It Cm addr 2273Matches IPv4 or IPv6 address. 2274Each entry is represented by an 2275.Ar addr Ns Op / Ns Ar masklen 2276and will match all addresses with base 2277.Ar addr 2278(specified as an IPv4/IPv6 address, or a hostname) and mask width of 2279.Ar masklen 2280bits. 2281If 2282.Ar masklen 2283is not specified, it defaults to 32 for IPv4 and 128 for IPv6. 2284When looking up an IP address in a table, the most specific 2285entry will match. 2286.It Cm iface 2287Matches interface names. 2288Each entry is represented by string treated as interface name. 2289Wildcards are not supported. 2290.It Cm number 2291Matches protocol ports, uids/gids or jail IDs. 2292Each entry is represented by 32-bit unsigned integer. 2293Ranges are not supported. 2294.It Cm flow 2295Matches packet fields specified by 2296.Ar flow 2297type suboptions with table entries. 2298.It Cm mac 2299Matches MAC address. 2300Each entry is represented by an 2301.Ar addr Ns Op / Ns Ar masklen 2302and will match all addresses with base 2303.Ar addr 2304and mask width of 2305.Ar masklen 2306bits. 2307If 2308.Ar masklen 2309is not specified, it defaults to 48. 2310When looking up an MAC address in a table, the most specific 2311entry will match. 2312.El 2313.Pp 2314Tables require explicit creation via 2315.Cm create 2316before use. 2317.Pp 2318The following creation options are supported: 2319.Bl -tag -width indent 2320.It Ar create-options : Ar create-option | create-options 2321.It Ar create-option : Cm type Ar table-type | Cm valtype Ar value-mask | Cm algo Ar algo-desc | 2322.Cm limit Ar number | Cm locked | Cm missing | Cm or-flush 2323.It Cm type 2324Table key type. 2325.It Cm valtype 2326Table value mask. 2327.It Cm algo 2328Table algorithm to use (see below). 2329.It Cm limit 2330Maximum number of items that may be inserted into table. 2331.It Cm locked 2332Restrict any table modifications. 2333.It Cm missing 2334Do not fail if table already exists and has exactly same options as new one. 2335.It Cm or-flush 2336Flush existing table with same name instead of returning error. 2337Implies 2338.Cm missing 2339so existing table must be compatible with new one. 2340.El 2341.Pp 2342Some of these options may be modified later via 2343.Cm modify 2344keyword. 2345The following options can be changed: 2346.Bl -tag -width indent 2347.It Ar modify-options : Ar modify-option | modify-options 2348.It Ar modify-option : Cm limit Ar number 2349.It Cm limit 2350Alter maximum number of items that may be inserted into table. 2351.El 2352.Pp 2353Additionally, table can be locked or unlocked using 2354.Cm lock 2355or 2356.Cm unlock 2357commands. 2358.Pp 2359Tables of the same 2360.Ar type 2361can be swapped with each other using 2362.Cm swap Ar name 2363command. 2364Swap may fail if tables limits are set and data exchange 2365would result in limits hit. 2366Operation is performed atomically. 2367.Pp 2368One or more entries can be added to a table at once using 2369.Cm add 2370command. 2371Addition of all items are performed atomically. 2372By default, error in addition of one entry does not influence 2373addition of other entries. 2374However, non-zero error code is returned in that case. 2375Special 2376.Cm atomic 2377keyword may be specified before 2378.Cm add 2379to indicate all-or-none add request. 2380.Pp 2381One or more entries can be removed from a table at once using 2382.Cm delete 2383command. 2384By default, error in removal of one entry does not influence 2385removing of other entries. 2386However, non-zero error code is returned in that case. 2387.Pp 2388It may be possible to check what entry will be found on particular 2389.Ar table-key 2390using 2391.Cm lookup 2392.Ar table-key 2393command. 2394This functionality is optional and may be unsupported in some algorithms. 2395.Pp 2396The following operations can be performed on 2397.Ar one 2398or 2399.Cm all 2400tables: 2401.Bl -tag -width indent 2402.It Cm list 2403List all entries. 2404.It Cm flush 2405Removes all entries. 2406.It Cm info 2407Shows generic table information. 2408.It Cm detail 2409Shows generic table information and algo-specific data. 2410.El 2411.Pp 2412The following lookup algorithms are supported: 2413.Bl -tag -width indent 2414.It Ar algo-desc : algo-name | "algo-name algo-data" 2415.It Ar algo-name : Ar addr: radix | addr: hash | iface: array | number: array | flow: hash | mac: radix 2416.It Cm addr: radix 2417Separate Radix trees for IPv4 and IPv6, the same way as the routing table (see 2418.Xr route 4 ) . 2419Default choice for 2420.Ar addr 2421type. 2422.It Cm addr:hash 2423Separate auto-growing hashes for IPv4 and IPv6. 2424Accepts entries with the same mask length specified initially via 2425.Cm "addr:hash masks=/v4,/v6" 2426algorithm creation options. 2427Assume /32 and /128 masks by default. 2428Search removes host bits (according to mask) from supplied address and checks 2429resulting key in appropriate hash. 2430Mostly optimized for /64 and byte-ranged IPv6 masks. 2431.It Cm iface:array 2432Array storing sorted indexes for entries which are presented in the system. 2433Optimized for very fast lookup. 2434.It Cm number:array 2435Array storing sorted u32 numbers. 2436.It Cm flow:hash 2437Auto-growing hash storing flow entries. 2438Search calculates hash on required packet fields and searches for matching 2439entries in selected bucket. 2440.It Cm mac: radix 2441Radix tree for MAC address 2442.El 2443.Pp 2444The 2445.Cm tablearg 2446feature provides the ability to use a value, looked up in the table, as 2447the argument for a rule action, action parameter or rule option. 2448This can significantly reduce number of rules in some configurations. 2449If two tables are used in a rule, the result of the second (destination) 2450is used. 2451.Pp 2452Each record may hold one or more values according to 2453.Ar value-mask . 2454This mask is set on table creation via 2455.Cm valtype 2456option. 2457The following value types are supported: 2458.Bl -tag -width indent 2459.It Ar value-mask : Ar value-type Ns Op , Ns Ar value-mask 2460.It Ar value-type : Ar skipto | pipe | fib | nat | dscp | tag | divert | 2461.Ar netgraph | limit | ipv4 | ipv6 | mark 2462.It Cm skipto 2463rule number to jump to. 2464.It Cm pipe 2465Pipe number to use. 2466.It Cm fib 2467fib number to match/set. 2468.It Cm nat 2469nat number to jump to. 2470.It Cm dscp 2471dscp value to match/set. 2472.It Cm tag 2473tag number to match/set. 2474.It Cm divert 2475port number to divert traffic to. 2476.It Cm netgraph 2477hook number to move packet to. 2478.It Cm limit 2479maximum number of connections. 2480.It Cm ipv4 2481IPv4 nexthop to fwd packets to. 2482.It Cm ipv6 2483IPv6 nexthop to fwd packets to. 2484.It Cm mark 2485mark value to match/set. 2486.El 2487.Pp 2488The 2489.Cm tablearg 2490argument can be used with the following actions: 2491.Cm nat, pipe, queue, divert, tee, netgraph, ngtee, fwd, skipto, setfib , 2492.Cm setmark , 2493action parameters: 2494.Cm tag, untag , 2495rule options: 2496.Cm limit, tagged, mark . 2497.Pp 2498When used with the 2499.Cm skipto 2500action, the user should be aware that the code will walk the ruleset 2501up to a rule equal to, or past, the given number. 2502.Pp 2503See the 2504.Sx EXAMPLES 2505Section for example usage of tables and the tablearg keyword. 2506.Sh SETS OF RULES 2507Each rule or table belongs to one of 32 different 2508.Em sets 2509, numbered 0 to 31. 2510Set 31 is reserved for the default rule. 2511.Pp 2512By default, rules or tables are put in set 0, unless you use the 2513.Cm set N 2514attribute when adding a new rule or table. 2515Sets can be individually and atomically enabled or disabled, 2516so this mechanism permits an easy way to store multiple configurations 2517of the firewall and quickly (and atomically) switch between them. 2518.Pp 2519By default, tables from set 0 are referenced when adding rule with 2520table opcodes regardless of rule set. 2521This behavior can be changed by setting 2522.Va net.inet.ip.fw.tables_sets 2523variable to 1. 2524Rule's set will then be used for table references. 2525.Pp 2526The command to enable/disable sets is 2527.Bd -ragged -offset indent 2528.Nm 2529.Cm set Oo Cm disable Ar number ... Oc Op Cm enable Ar number ... 2530.Ed 2531.Pp 2532where multiple 2533.Cm enable 2534or 2535.Cm disable 2536sections can be specified. 2537Command execution is atomic on all the sets specified in the command. 2538By default, all sets are enabled. 2539.Pp 2540When you disable a set, its rules behave as if they do not exist 2541in the firewall configuration, with only one exception: 2542.Bd -ragged -offset indent 2543dynamic rules created from a rule before it had been disabled 2544will still be active until they expire. 2545In order to delete 2546dynamic rules you have to explicitly delete the parent rule 2547which generated them. 2548.Ed 2549.Pp 2550The set number of rules can be changed with the command 2551.Bd -ragged -offset indent 2552.Nm 2553.Cm set move 2554.Brq Cm rule Ar rule-number | old-set 2555.Cm to Ar new-set 2556.Ed 2557.Pp 2558Also, you can atomically swap two rulesets with the command 2559.Bd -ragged -offset indent 2560.Nm 2561.Cm set swap Ar first-set second-set 2562.Ed 2563.Pp 2564See the 2565.Sx EXAMPLES 2566Section on some possible uses of sets of rules. 2567.Sh STATEFUL FIREWALL 2568Stateful operation is a way for the firewall to dynamically 2569create rules for specific flows when packets that 2570match a given pattern are detected. 2571Support for stateful 2572operation comes through the 2573.Cm check-state , keep-state , record-state , limit 2574and 2575.Cm set-limit 2576options of 2577.Nm rules . 2578.Pp 2579Dynamic rules are created when a packet matches a 2580.Cm keep-state , 2581.Cm record-state , 2582.Cm limit 2583or 2584.Cm set-limit 2585rule, causing the creation of a 2586.Em dynamic 2587rule which will match all and only packets with 2588a given 2589.Em protocol 2590between a 2591.Em src-ip/src-port dst-ip/dst-port 2592pair of addresses 2593.Em ( src 2594and 2595.Em dst 2596are used here only to denote the initial match addresses, but they 2597are completely equivalent afterwards). 2598Rules created by 2599.Cm keep-state 2600option also have a 2601.Ar :flowname 2602taken from it. 2603This name is used in matching together with addresses, ports and protocol. 2604Dynamic rules will be checked at the first 2605.Cm check-state, keep-state 2606or 2607.Cm limit 2608occurrence, and the action performed upon a match will be the same 2609as in the parent rule. 2610.Pp 2611Note that no additional attributes other than protocol and IP addresses 2612and ports and :flowname are checked on dynamic rules. 2613.Pp 2614The typical use of dynamic rules is to keep a closed firewall configuration, 2615but let the first TCP SYN packet from the inside network install a 2616dynamic rule for the flow so that packets belonging to that session 2617will be allowed through the firewall: 2618.Pp 2619.Dl "ipfw add check-state :OUTBOUND" 2620.Dl "ipfw add allow tcp from my-subnet to any setup keep-state :OUTBOUND" 2621.Dl "ipfw add deny tcp from any to any" 2622.Pp 2623A similar approach can be used for UDP, where an UDP packet coming 2624from the inside will install a dynamic rule to let the response through 2625the firewall: 2626.Pp 2627.Dl "ipfw add check-state :OUTBOUND" 2628.Dl "ipfw add allow udp from my-subnet to any keep-state :OUTBOUND" 2629.Dl "ipfw add deny udp from any to any" 2630.Pp 2631Dynamic rules expire after some time, which depends on the status 2632of the flow and the setting of some 2633.Cm sysctl 2634variables. 2635See Section 2636.Sx SYSCTL VARIABLES 2637for more details. 2638For TCP sessions, dynamic rules can be instructed to periodically 2639send keepalive packets to refresh the state of the rule when it is 2640about to expire. 2641.Pp 2642See Section 2643.Sx EXAMPLES 2644for more examples on how to use dynamic rules. 2645.Sh TRAFFIC SHAPER (DUMMYNET) CONFIGURATION 2646.Nm 2647is also the user interface for the 2648.Nm dummynet 2649traffic shaper, packet scheduler and network emulator, a subsystem that 2650can artificially queue, delay or drop packets 2651emulating the behaviour of certain network links 2652or queueing systems. 2653.Pp 2654.Nm dummynet 2655operates by first using the firewall to select packets 2656using any match pattern that can be used in 2657.Nm 2658rules. 2659Matching packets are then passed to either of two 2660different objects, which implement the traffic regulation: 2661.Bl -hang -offset XXXX 2662.It Em pipe 2663A 2664.Em pipe 2665emulates a 2666.Em link 2667with given bandwidth and propagation delay, 2668driven by a FIFO scheduler and a single queue with programmable 2669queue size and packet loss rate. 2670Packets are appended to the queue as they come out from 2671.Nm ipfw , 2672and then transferred in FIFO order to the link at the desired rate. 2673.It Em queue 2674A 2675.Em queue 2676is an abstraction used to implement packet scheduling 2677using one of several packet scheduling algorithms. 2678Packets sent to a 2679.Em queue 2680are first grouped into flows according to a mask on the 5-tuple. 2681Flows are then passed to the scheduler associated to the 2682.Em queue , 2683and each flow uses scheduling parameters (weight and others) 2684as configured in the 2685.Em queue 2686itself. 2687A scheduler in turn is connected to an emulated link, 2688and arbitrates the link's bandwidth among backlogged flows according to 2689weights and to the features of the scheduling algorithm in use. 2690.El 2691.Pp 2692In practice, 2693.Em pipes 2694can be used to set hard limits to the bandwidth that a flow can use, whereas 2695.Em queues 2696can be used to determine how different flows share the available bandwidth. 2697.Pp 2698A graphical representation of the binding of queues, 2699flows, schedulers and links is below. 2700.Bd -literal -offset indent 2701 (flow_mask|sched_mask) sched_mask 2702 +---------+ weight Wx +-------------+ 2703 | |->-[flow]-->--| |-+ 2704 -->--| QUEUE x | ... | | | 2705 | |->-[flow]-->--| SCHEDuler N | | 2706 +---------+ | | | 2707 ... | +--[LINK N]-->-- 2708 +---------+ weight Wy | | +--[LINK N]-->-- 2709 | |->-[flow]-->--| | | 2710 -->--| QUEUE y | ... | | | 2711 | |->-[flow]-->--| | | 2712 +---------+ +-------------+ | 2713 +-------------+ 2714.Ed 2715It is important to understand the role of the SCHED_MASK 2716and FLOW_MASK, which are configured through the commands 2717.Dl "ipfw sched N config mask SCHED_MASK ..." 2718and 2719.Dl "ipfw queue X config mask FLOW_MASK ..." . 2720.Pp 2721The SCHED_MASK is used to assign flows to one or more 2722scheduler instances, one for each 2723value of the packet's 5-tuple after applying SCHED_MASK. 2724As an example, using ``src-ip 0xffffff00'' creates one instance 2725for each /24 destination subnet. 2726.Pp 2727The FLOW_MASK, together with the SCHED_MASK, is used to split 2728packets into flows. 2729As an example, using 2730``src-ip 0x000000ff'' 2731together with the previous SCHED_MASK makes a flow for 2732each individual source address. 2733In turn, flows for each /24 2734subnet will be sent to the same scheduler instance. 2735.Pp 2736The above diagram holds even for the 2737.Em pipe 2738case, with the only restriction that a 2739.Em pipe 2740only supports a SCHED_MASK, and forces the use of a FIFO 2741scheduler (these are for backward compatibility reasons; 2742in fact, internally, a 2743.Nm dummynet's 2744pipe is implemented exactly as above). 2745.Pp 2746There are two modes of 2747.Nm dummynet 2748operation: 2749.Dq normal 2750and 2751.Dq fast . 2752The 2753.Dq normal 2754mode tries to emulate a real link: the 2755.Nm dummynet 2756scheduler ensures that the packet will not leave the pipe faster than it 2757would on the real link with a given bandwidth. 2758The 2759.Dq fast 2760mode allows certain packets to bypass the 2761.Nm dummynet 2762scheduler (if packet flow does not exceed pipe's bandwidth). 2763This is the reason why the 2764.Dq fast 2765mode requires less CPU cycles per packet (on average) and packet latency 2766can be significantly lower in comparison to a real link with the same 2767bandwidth. 2768The default mode is 2769.Dq normal . 2770The 2771.Dq fast 2772mode can be enabled by setting the 2773.Va net.inet.ip.dummynet.io_fast 2774.Xr sysctl 8 2775variable to a non-zero value. 2776.Ss PIPE, QUEUE AND SCHEDULER CONFIGURATION 2777The 2778.Em pipe , 2779.Em queue 2780and 2781.Em scheduler 2782configuration commands are the following: 2783.Bd -ragged -offset indent 2784.Cm pipe Ar number Cm config Ar pipe-configuration 2785.Pp 2786.Cm queue Ar number Cm config Ar queue-configuration 2787.Pp 2788.Cm sched Ar number Cm config Ar sched-configuration 2789.Ed 2790.Pp 2791The following parameters can be configured for a pipe: 2792.Pp 2793.Bl -tag -width indent -compact 2794.It Cm bw Ar bandwidth | device 2795Bandwidth, measured in 2796.Sm off 2797.Op Cm K | M | G 2798.Brq Cm bit/s | Byte/s . 2799.Sm on 2800.Pp 2801A value of 0 (default) means unlimited bandwidth. 2802The unit must immediately follow the number, as in 2803.Pp 2804.Dl "dnctl pipe 1 config bw 300Kbit/s" 2805.Pp 2806If a device name is specified instead of a numeric value, as in 2807.Pp 2808.Dl "dnctl pipe 1 config bw tun0" 2809.Pp 2810then the transmit clock is supplied by the specified device. 2811At the moment only the 2812.Xr tun 4 2813device supports this 2814functionality, for use in conjunction with 2815.Xr ppp 8 . 2816.Pp 2817.It Cm delay Ar ms-delay 2818Propagation delay, measured in milliseconds. 2819The value is rounded to the next multiple of the clock tick 2820(typically 10ms, but it is a good practice to run kernels 2821with 2822.Dq "options HZ=1000" 2823to reduce 2824the granularity to 1ms or less). 2825The default value is 0, meaning no delay. 2826.Pp 2827.It Cm burst Ar size 2828If the data to be sent exceeds the pipe's bandwidth limit 2829(and the pipe was previously idle), up to 2830.Ar size 2831bytes of data are allowed to bypass the 2832.Nm dummynet 2833scheduler, and will be sent as fast as the physical link allows. 2834Any additional data will be transmitted at the rate specified 2835by the 2836.Nm pipe 2837bandwidth. 2838The burst size depends on how long the pipe has been idle; 2839the effective burst size is calculated as follows: 2840MAX( 2841.Ar size 2842, 2843.Nm bw 2844* pipe_idle_time). 2845.Pp 2846.It Cm profile Ar filename 2847A file specifying the additional overhead incurred in the transmission 2848of a packet on the link. 2849.Pp 2850Some link types introduce extra delays in the transmission 2851of a packet, e.g., because of MAC level framing, contention on 2852the use of the channel, MAC level retransmissions and so on. 2853From our point of view, the channel is effectively unavailable 2854for this extra time, which is constant or variable depending 2855on the link type. 2856Additionally, packets may be dropped after this 2857time (e.g., on a wireless link after too many retransmissions). 2858We can model the additional delay with an empirical curve 2859that represents its distribution. 2860.Bd -literal -offset indent 2861 cumulative probability 2862 1.0 ^ 2863 | 2864 L +-- loss-level x 2865 | ****** 2866 | * 2867 | ***** 2868 | * 2869 | ** 2870 | * 2871 +-------*-------------------> 2872 delay 2873.Ed 2874The empirical curve may have both vertical and horizontal lines. 2875Vertical lines represent constant delay for a range of 2876probabilities. 2877Horizontal lines correspond to a discontinuity in the delay 2878distribution: the pipe will use the largest delay for a 2879given probability. 2880.Pp 2881The file format is the following, with whitespace acting as 2882a separator and '#' indicating the beginning a comment: 2883.Bl -tag -width indent 2884.It Cm name Ar identifier 2885optional name (listed by "dnctl pipe show") 2886to identify the delay distribution; 2887.It Cm bw Ar value 2888the bandwidth used for the pipe. 2889If not specified here, it must be present 2890explicitly as a configuration parameter for the pipe; 2891.It Cm loss-level Ar L 2892the probability above which packets are lost. 2893(0.0 <= L <= 1.0, default 1.0 i.e., no loss); 2894.It Cm samples Ar N 2895the number of samples used in the internal 2896representation of the curve (2..1024; default 100); 2897.It Cm "delay prob" | "prob delay" 2898One of these two lines is mandatory and defines 2899the format of the following lines with data points. 2900.It Ar XXX Ar YYY 29012 or more lines representing points in the curve, 2902with either delay or probability first, according 2903to the chosen format. 2904The unit for delay is milliseconds. 2905Data points do not need to be sorted. 2906Also, the number of actual lines can be different 2907from the value of the "samples" parameter: 2908.Nm 2909utility will sort and interpolate 2910the curve as needed. 2911.El 2912.Pp 2913Example of a profile file: 2914.Bd -literal -offset indent 2915name bla_bla_bla 2916samples 100 2917loss-level 0.86 2918prob delay 29190 200 # minimum overhead is 200ms 29200.5 200 29210.5 300 29220.8 1000 29230.9 1300 29241 1300 2925#configuration file end 2926.Ed 2927.El 2928.Pp 2929The following parameters can be configured for a queue: 2930.Pp 2931.Bl -tag -width indent -compact 2932.It Cm pipe Ar pipe_nr 2933Connects a queue to the specified pipe. 2934Multiple queues (with the same or different weights) can be connected to 2935the same pipe, which specifies the aggregate rate for the set of queues. 2936.Pp 2937.It Cm weight Ar weight 2938Specifies the weight to be used for flows matching this queue. 2939The weight must be in the range 1..100, and defaults to 1. 2940.El 2941.Pp 2942The following case-insensitive parameters can be configured for a 2943scheduler: 2944.Pp 2945.Bl -tag -width indent -compact 2946.It Cm type Ar {fifo | wf2q+ | rr | qfq | fq_codel | fq_pie} 2947specifies the scheduling algorithm to use. 2948.Bl -tag -width indent -compact 2949.It Cm fifo 2950is just a FIFO scheduler (which means that all packets 2951are stored in the same queue as they arrive to the scheduler). 2952FIFO has O(1) per-packet time complexity, with very low 2953constants (estimate 60-80ns on a 2GHz desktop machine) 2954but gives no service guarantees. 2955.It Cm wf2q+ 2956implements the WF2Q+ algorithm, which is a Weighted Fair Queueing 2957algorithm which permits flows to share bandwidth according to 2958their weights. 2959Note that weights are not priorities; even a flow 2960with a minuscule weight will never starve. 2961WF2Q+ has O(log N) per-packet processing cost, where N is the number 2962of flows, and is the default algorithm used by previous versions 2963dummynet's queues. 2964.It Cm rr 2965implements the Deficit Round Robin algorithm, which has O(1) processing 2966costs (roughly, 100-150ns per packet) 2967and permits bandwidth allocation according to weights, but 2968with poor service guarantees. 2969.It Cm qfq 2970implements the QFQ algorithm, which is a very fast variant of 2971WF2Q+, with similar service guarantees and O(1) processing 2972costs (roughly, 200-250ns per packet). 2973.It Cm fq_codel 2974implements the FQ-CoDel (FlowQueue-CoDel) scheduler/AQM algorithm, which 2975uses a modified Deficit Round Robin scheduler to manage two lists of sub-queues 2976(old sub-queues and new sub-queues) for providing brief periods of priority to 2977lightweight or short burst flows. 2978By default, the total number of sub-queues is 1024. 2979FQ-CoDel's internal, dynamically 2980created sub-queues are controlled by separate instances of CoDel AQM. 2981.It Cm fq_pie 2982implements the FQ-PIE (FlowQueue-PIE) scheduler/AQM algorithm, which similar to 2983.Cm fq_codel 2984but uses per sub-queue PIE AQM instance to control the queue delay. 2985.El 2986.Pp 2987.Cm fq_codel 2988inherits AQM parameters and options from 2989.Cm codel 2990(see below), and 2991.Cm fq_pie 2992inherits AQM parameters and options from 2993.Cm pie 2994(see below). 2995Additionally, both of 2996.Cm fq_codel 2997and 2998.Cm fq_pie 2999have shared scheduler parameters which are: 3000.Bl -tag -width indent 3001.It Cm quantum 3002.Ar m 3003specifies the quantum (credit) of the scheduler. 3004.Ar m 3005is the number of bytes a queue can serve before being moved to the tail 3006of old queues list. 3007The default is 1514 bytes, and the maximum acceptable value 3008is 9000 bytes. 3009.It Cm limit 3010.Ar m 3011specifies the hard size limit (in unit of packets) of all queues managed by an 3012instance of the scheduler. 3013The default value of 3014.Ar m 3015is 10240 packets, and the maximum acceptable value is 20480 packets. 3016.It Cm flows 3017.Ar m 3018specifies the total number of flow queues (sub-queues) that fq_* 3019creates and manages. 3020By default, 1024 sub-queues are created when an instance 3021of the fq_{codel/pie} scheduler is created. 3022The maximum acceptable value is 302365536. 3024.El 3025.Pp 3026Note that any token after 3027.Cm fq_codel 3028or 3029.Cm fq_pie 3030is considered a parameter for fq_{codel/pie}. 3031So, ensure all scheduler 3032configuration options not related to fq_{codel/pie} are written before 3033.Cm fq_codel/fq_pie 3034tokens. 3035.El 3036.Pp 3037In addition to the type, all parameters allowed for a pipe can also 3038be specified for a scheduler. 3039.Pp 3040Finally, the following parameters can be configured for both 3041pipes and queues: 3042.Pp 3043.Bl -tag -width XXXX -compact 3044.It Cm buckets Ar hash-table-size 3045Specifies the size of the hash table used for storing the 3046various queues. 3047Default value is 64 controlled by the 3048.Xr sysctl 8 3049variable 3050.Va net.inet.ip.dummynet.hash_size , 3051allowed range is 16 to 65536. 3052.Pp 3053.It Cm mask Ar mask-specifier 3054Packets sent to a given pipe or queue by an 3055.Nm 3056rule can be further classified into multiple flows, each of which is then 3057sent to a different 3058.Em dynamic 3059pipe or queue. 3060A flow identifier is constructed by masking the IP addresses, 3061ports and protocol types as specified with the 3062.Cm mask 3063options in the configuration of the pipe or queue. 3064For each different flow identifier, a new pipe or queue is created 3065with the same parameters as the original object, and matching packets 3066are sent to it. 3067.Pp 3068Thus, when 3069.Em dynamic pipes 3070are used, each flow will get the same bandwidth as defined by the pipe, 3071whereas when 3072.Em dynamic queues 3073are used, each flow will share the parent's pipe bandwidth evenly 3074with other flows generated by the same queue (note that other queues 3075with different weights might be connected to the same pipe). 3076.br 3077Available mask specifiers are a combination of one or more of the following: 3078.Pp 3079.Cm dst-ip Ar mask , 3080.Cm dst-ip6 Ar mask , 3081.Cm src-ip Ar mask , 3082.Cm src-ip6 Ar mask , 3083.Cm dst-port Ar mask , 3084.Cm src-port Ar mask , 3085.Cm flow-id Ar mask , 3086.Cm proto Ar mask 3087or 3088.Cm all , 3089.Pp 3090where the latter means all bits in all fields are significant. 3091.Pp 3092.It Cm noerror 3093When a packet is dropped by a 3094.Nm dummynet 3095queue or pipe, the error 3096is normally reported to the caller routine in the kernel, in the 3097same way as it happens when a device queue fills up. 3098Setting this 3099option reports the packet as successfully delivered, which can be 3100needed for some experimental setups where you want to simulate 3101loss or congestion at a remote router. 3102.Pp 3103.It Cm plr Ar packet-loss-rate 3104.It Cm plr Ar K,p,H,r 3105Packet loss rate. 3106Argument 3107.Ar packet-loss-rate 3108is a floating-point number between 0 and 1, with 0 meaning no 3109loss, 1 meaning 100% loss. 3110.Pp 3111When invoked with four arguments, the simple Gilbert-Elliott 3112channel model with two states (Good and Bad) is used. 3113.Bd -literal -offset indent 3114 r 3115 .----------------. 3116 v | 3117 .------------. .------------. 3118 | G | | B | 3119 | drop (K) | | drop (H) | 3120 '------------' '------------' 3121 | ^ 3122 '----------------' 3123 p 3124 3125.Ed 3126This has the associated probabilities 3127.Po Ar K 3128and 3129.Ar H Pc 3130for the loss probability. 3131This is different from the literature, where this model is described with 3132probabilities of successful transmission k and h. 3133However, converting from literature is easy: 3134.Pp 3135K = 1 - k ; H = 1 - h 3136.Pp 3137This is to retain consistency within the interface and allow the 3138quick re-use of loss probability when giving only a single argument. 3139In addition the state change probabilities 3140.Po Ar p 3141and 3142.Ar r Pc 3143are given. 3144All of the above probabilities are internally represented on 31 bits. 3145.Pp 3146.It Cm queue Brq Ar slots | size Ns Cm Kbytes 3147Queue size, in 3148.Ar slots 3149or 3150.Cm KBytes . 3151Default value is 50 slots, which 3152is the typical queue size for Ethernet devices. 3153Note that for slow speed links you should keep the queue 3154size short or your traffic might be affected by a significant 3155queueing delay. 3156E.g., 50 max-sized Ethernet packets (1500 bytes) mean 600Kbit 3157or 20s of queue on a 30Kbit/s pipe. 3158Even worse effects can result if you get packets from an 3159interface with a much larger MTU, e.g.\& the loopback interface 3160with its 16KB packets. 3161The 3162.Xr sysctl 8 3163variables 3164.Em net.inet.ip.dummynet.pipe_byte_limit 3165and 3166.Em net.inet.ip.dummynet.pipe_slot_limit 3167control the maximum lengths that can be specified. 3168.Pp 3169.It Cm red | gred Ar w_q Ns / Ns Ar min_th Ns / Ns Ar max_th Ns / Ns Ar max_p 3170[ecn] 3171Make use of the RED (Random Early Detection) queue management algorithm. 3172.Ar w_q 3173and 3174.Ar max_p 3175are floating 3176point numbers between 0 and 1 (inclusive), while 3177.Ar min_th 3178and 3179.Ar max_th 3180are integer numbers specifying thresholds for queue management 3181(thresholds are computed in bytes if the queue has been defined 3182in bytes, in slots otherwise). 3183The two parameters can also be of the same value if needed. 3184The 3185.Nm dummynet 3186also supports the gentle RED variant (gred) and ECN (Explicit Congestion 3187Notification) as optional. 3188Three 3189.Xr sysctl 8 3190variables can be used to control the RED behaviour: 3191.Bl -tag -width indent 3192.It Va net.inet.ip.dummynet.red_lookup_depth 3193specifies the accuracy in computing the average queue 3194when the link is idle (defaults to 256, must be greater than zero) 3195.It Va net.inet.ip.dummynet.red_avg_pkt_size 3196specifies the expected average packet size (defaults to 512, must be 3197greater than zero) 3198.It Va net.inet.ip.dummynet.red_max_pkt_size 3199specifies the expected maximum packet size, only used when queue 3200thresholds are in bytes (defaults to 1500, must be greater than zero). 3201.El 3202.Pp 3203.It Cm codel Oo Cm target Ar time Oc Oo Cm interval Ar time Oc Oo Cm ecn | 3204.Cm noecn Oc 3205Make use of the CoDel (Controlled-Delay) queue management algorithm. 3206.Ar time 3207is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or 3208microseconds (us) can be specified instead. 3209CoDel drops or marks (ECN) packets 3210depending on packet sojourn time in the queue. 3211.Cm target 3212.Ar time 3213(5ms by default) is the minimum acceptable persistent queue delay that CoDel 3214allows. 3215CoDel does not drop packets directly after packets sojourn time becomes 3216higher than 3217.Cm target 3218.Ar time 3219but waits for 3220.Cm interval 3221.Ar time 3222(100ms default) before dropping. 3223.Cm interval 3224.Ar time 3225should be set to maximum RTT for all expected connections. 3226.Cm ecn 3227enables (disabled by default) packet marking (instead of dropping) for 3228ECN-enabled TCP flows when queue delay becomes high. 3229.Pp 3230Note that any token after 3231.Cm codel 3232is considered a parameter for CoDel. 3233So, ensure all pipe/queue 3234configuration options are written before 3235.Cm codel 3236token. 3237.Pp 3238The 3239.Xr sysctl 8 3240variables 3241.Va net.inet.ip.dummynet.codel.target 3242and 3243.Va net.inet.ip.dummynet.codel.interval 3244can be used to set CoDel default parameters. 3245.Pp 3246.It Cm pie Oo Cm target Ar time Oc Oo Cm tupdate Ar time Oc Oo 3247.Cm alpha Ar n Oc Oo Cm beta Ar n Oc Oo Cm max_burst Ar time Oc Oo 3248.Cm max_ecnth Ar n Oc Oo Cm ecn | Cm noecn Oc Oo Cm capdrop | 3249.Cm nocapdrop Oc Oo Cm drand | Cm nodrand Oc Oo Cm onoff 3250.Oc Oo Cm dre | Cm ts Oc 3251Make use of the PIE (Proportional Integral controller Enhanced) queue management 3252algorithm. 3253PIE drops or marks packets depending on a calculated drop probability during 3254en-queue process, with the aim of achieving high throughput while keeping queue 3255delay low. 3256At regular time intervals of 3257.Cm tupdate 3258.Ar time 3259(15ms by default) a background process (re)calculates the probability based on 3260queue delay deviations from 3261.Cm target 3262.Ar time 3263(15ms by default) and queue delay trends. 3264PIE approximates current queue 3265delay by using a departure rate estimation method, or (optionally) by using a 3266packet timestamp method similar to CoDel. 3267.Ar time 3268is interpreted as milliseconds by default but seconds (s), milliseconds (ms) or 3269microseconds (us) can be specified instead. 3270The other PIE parameters and options are as follows: 3271.Bl -tag -width indent 3272.It Cm alpha Ar n 3273.Ar n 3274is a floating point number between 0 and 7 which specifies the weight of queue 3275delay deviations that is used in drop probability calculation. 32760.125 is the default. 3277.It Cm beta Ar n 3278.Ar n 3279is a floating point number between 0 and 7 which specifies is the weight of 3280queue delay trend that is used in drop probability calculation. 32811.25 is the default. 3282.It Cm max_burst Ar time 3283The maximum period of time that PIE does not drop/mark packets. 3284150ms is the 3285default and 10s is the maximum value. 3286.It Cm max_ecnth Ar n 3287Even when ECN is enabled, PIE drops packets instead of marking them when drop 3288probability becomes higher than ECN probability threshold 3289.Cm max_ecnth Ar n 3290, the default is 0.1 (i.e 10%) and 1 is the maximum value. 3291.It Cm ecn | noecn 3292enable or disable ECN marking for ECN-enabled TCP flows. 3293Disabled by default. 3294.It Cm capdrop | nocapdrop 3295enable or disable cap drop adjustment. 3296Cap drop adjustment is enabled by default. 3297.It Cm drand | nodrand 3298enable or disable drop probability de-randomisation. 3299De-randomisation eliminates 3300the problem of dropping packets too close or too far. 3301De-randomisation is enabled by default. 3302.It Cm onoff 3303enable turning PIE on and off depending on queue load. 3304If this option is enabled, 3305PIE turns on when over 1/3 of queue becomes full. 3306This option is disabled by 3307default. 3308.It Cm dre | ts 3309Calculate queue delay using departure rate estimation 3310.Cm dre 3311or timestamps 3312.Cm ts . 3313.Cm dre 3314is used by default. 3315.El 3316.Pp 3317Note that any token after 3318.Cm pie 3319is considered a parameter for PIE. 3320So ensure all pipe/queue 3321the configuration options are written before 3322.Cm pie 3323token. 3324.Xr sysctl 8 3325variables can be used to control the 3326.Cm pie 3327default parameters. 3328See the 3329.Sx SYSCTL VARIABLES 3330section for more details. 3331.El 3332.Pp 3333When used with IPv6 data, 3334.Nm dummynet 3335currently has several limitations. 3336Information necessary to route link-local packets to an 3337interface is not available after processing by 3338.Nm dummynet 3339so those packets are dropped in the output path. 3340Care should be taken to ensure that link-local packets are not passed to 3341.Nm dummynet . 3342.Sh CHECKLIST 3343Here are some important points to consider when designing your 3344rules: 3345.Bl -bullet 3346.It 3347Remember that you filter both packets going 3348.Cm in 3349and 3350.Cm out . 3351Most connections need packets going in both directions. 3352.It 3353Remember to test very carefully. 3354It is a good idea to be near the console when doing this. 3355If you cannot be near the console, 3356use an auto-recovery script such as the one in 3357.Pa /usr/share/examples/ipfw/change_rules.sh . 3358.It 3359Do not forget the loopback interface. 3360.El 3361.Sh FINE POINTS 3362.Bl -bullet 3363.It 3364There are circumstances where fragmented datagrams are unconditionally 3365dropped. 3366TCP packets are dropped if they do not contain at least 20 bytes of 3367TCP header, UDP packets are dropped if they do not contain a full 8 3368byte UDP header, and ICMP packets are dropped if they do not contain 33694 bytes of ICMP header, enough to specify the ICMP type, code, and 3370checksum. 3371These packets are simply logged as 3372.Dq pullup failed 3373since there may not be enough good data in the packet to produce a 3374meaningful log entry. 3375.It 3376Another type of packet is unconditionally dropped, a TCP packet with a 3377fragment offset of one. 3378This is a valid packet, but it only has one use, to try 3379to circumvent firewalls. 3380When logging is enabled, these packets are 3381reported as being dropped by rule -1. 3382.It 3383If you are logged in over a network, loading the 3384.Xr kld 4 3385version of 3386.Nm 3387is probably not as straightforward as you would think. 3388The following command line is recommended: 3389.Bd -literal -offset indent 3390kldload ipfw && \e 3391ipfw add 32000 allow ip from any to any 3392.Ed 3393.Pp 3394Along the same lines, doing an 3395.Bd -literal -offset indent 3396ipfw flush 3397.Ed 3398.Pp 3399in similar surroundings is also a bad idea. 3400.It 3401The 3402.Nm 3403filter list may not be modified if the system security level 3404is set to 3 or higher 3405(see 3406.Xr init 8 3407for information on system security levels). 3408.El 3409.Sh PACKET DIVERSION 3410A 3411.Xr divert 4 3412socket bound to the specified port will receive all packets 3413diverted to that port. 3414If no socket is bound to the destination port, or if the divert module is 3415not loaded, or if the kernel was not compiled with divert socket support, 3416the packets are dropped. 3417.Sh NETWORK ADDRESS TRANSLATION (NAT) 3418.Nm 3419support in-kernel NAT using the kernel version of 3420.Xr libalias 3 . 3421The kernel module 3422.Cm ipfw_nat 3423should be loaded or kernel should have 3424.Cm options IPFIREWALL_NAT 3425to be able use NAT. 3426.Pp 3427The nat configuration command is the following: 3428.Bd -ragged -offset indent 3429.Bk -words 3430.Cm nat 3431.Ar nat_number 3432.Cm config 3433.Ar nat-configuration 3434.Ek 3435.Ed 3436.Pp 3437The following parameters can be configured: 3438.Bl -tag -width indent 3439.It Cm ip Ar ip_address 3440Define an ip address to use for aliasing. 3441.It Cm if Ar nic 3442Use ip address of NIC for aliasing, dynamically changing 3443it if NIC's ip address changes. 3444.It Cm log 3445Enable logging on this nat instance. 3446.It Cm deny_in 3447Deny any incoming connection from outside world. 3448.It Cm same_ports 3449Try to leave the alias port numbers unchanged from 3450the actual local port numbers. 3451.It Cm unreg_only 3452Traffic on the local network not originating from a RFC 1918 3453unregistered address spaces will be ignored. 3454.It Cm unreg_cgn 3455Like unreg_only, but includes the RFC 6598 (Carrier Grade NAT) 3456address range. 3457.It Cm reset 3458Reset table of the packet aliasing engine on address change. 3459.It Cm reverse 3460Reverse the way libalias handles aliasing. 3461.It Cm proxy_only 3462Obey transparent proxy rules only, packet aliasing is not performed. 3463.It Cm skip_global 3464Skip instance in case of global state lookup (see below). 3465.It Cm port_range Ar lower-upper 3466Set the aliasing ports between the ranges given. 3467Upper port has to be greater than lower. 3468.It Cm udp_eim 3469When enabled, UDP packets use endpoint-independent mapping (EIM) from RFC 4787 3470("full cone" NAT of RFC 3489). 3471All packets from the same internal address:port are mapped to the same NAT 3472address:port, regardless of their destination address:port. 3473If filtering rules allow, and if 3474.Em deny_in 3475is unset, any other external address:port can 3476also send to the internal address:port through its mapped NAT address:port. 3477This is more compatible with applications, and can reduce the need for port 3478forwarding, but less scalable as each NAT address:port can only be 3479concurrently used by at most one internal address:port. 3480.Pp 3481When disabled, UDP packets use endpoint-dependent mapping (EDM) ("symmetric" 3482NAT). 3483Each connection from a particular internal address:port to different 3484external addresses:ports is mapped to a random and unpredictable NAT 3485address:port. 3486Two appplications behind EDM NATs can only connect to each other 3487by port forwarding on the NAT, or tunnelling through an in-between server. 3488.El 3489.Pp 3490Some special values can be supplied instead of 3491.Va nat_number 3492in nat rule actions: 3493.Bl -tag -width indent 3494.It Cm global 3495Looks up translation state in all configured nat instances. 3496If an entry is found, packet is aliased according to that entry. 3497If no entry was found in any of the instances, packet is passed unchanged, 3498and no new entry will be created. 3499See section 3500.Sx MULTIPLE INSTANCES 3501in 3502.Xr natd 8 3503for more information. 3504.It Cm tablearg 3505Uses argument supplied in lookup table. 3506See 3507.Sx LOOKUP TABLES 3508section below for more information on lookup tables. 3509.El 3510.Pp 3511To let the packet continue after being (de)aliased, set the sysctl variable 3512.Va net.inet.ip.fw.one_pass 3513to 0. 3514For more information about aliasing modes, refer to 3515.Xr libalias 3 . 3516See Section 3517.Sx EXAMPLES 3518for some examples of nat usage. 3519.Pp 3520To delete specific nat configuration instance, use the following command: 3521.Bd -ragged -offset indent 3522.Bk -words 3523.Cm nat 3524.Ar nat_number 3525.Cm delete 3526.Ek 3527.Ed 3528.Ss REDIRECT AND LSNAT SUPPORT IN IPFW 3529Redirect and LSNAT support follow closely the syntax used in 3530.Xr natd 8 . 3531See Section 3532.Sx EXAMPLES 3533for some examples on how to do redirect and lsnat. 3534.Ss SCTP NAT SUPPORT 3535SCTP nat can be configured in a similar manner to TCP through the 3536.Nm 3537command line tool. 3538The main difference is that 3539.Nm sctp nat 3540does not do port translation. 3541Since the local and global side ports will be the same, 3542there is no need to specify both. 3543Ports are redirected as follows: 3544.Bd -ragged -offset indent 3545.Bk -words 3546.Cm nat 3547.Ar nat_number 3548.Cm config if 3549.Ar nic 3550.Cm redirect_port sctp 3551.Ar ip_address [,addr_list] {[port | port-port] [,ports]} 3552.Ek 3553.Ed 3554.Pp 3555Most 3556.Nm sctp nat 3557configuration can be done in real-time through the 3558.Xr sysctl 8 3559interface. 3560All may be changed dynamically, though the hash_table size will only 3561change for new 3562.Nm nat 3563instances. 3564See 3565.Sx SYSCTL VARIABLES 3566for more info. 3567.Sh IPv6/IPv4 NETWORK ADDRESS AND PROTOCOL TRANSLATION 3568.Ss Stateful translation 3569.Nm 3570supports in-kernel IPv6/IPv4 network address and protocol translation. 3571Stateful NAT64 translation allows IPv6-only clients to contact IPv4 servers 3572using unicast TCP, UDP or ICMP protocols. 3573One or more IPv4 addresses assigned to a stateful NAT64 translator are shared 3574among several IPv6-only clients. 3575When stateful NAT64 is used in conjunction with DNS64, no changes are usually 3576required in the IPv6 client or the IPv4 server. 3577The kernel module 3578.Cm ipfw_nat64 3579should be loaded or kernel should have 3580.Cm options IPFIREWALL_NAT64 3581to be able use stateful NAT64 translator. 3582.Pp 3583Stateful NAT64 uses a bunch of memory for several types of objects. 3584When IPv6 client initiates connection, NAT64 translator creates a host entry 3585in the states table. 3586Each host entry uses preallocated IPv4 alias entry. 3587Each alias entry has a number of ports group entries allocated on demand. 3588Ports group entries contains connection state entries. 3589There are several options to control limits and lifetime for these objects. 3590.Pp 3591NAT64 translator follows RFC7915 when does ICMPv6/ICMP translation, 3592unsupported message types will be silently dropped. 3593IPv6 needs several ICMPv6 message types to be explicitly allowed for correct 3594operation. 3595Make sure that ND6 neighbor solicitation (ICMPv6 type 135) and neighbor 3596advertisement (ICMPv6 type 136) messages will not be handled by translation 3597rules. 3598.Pp 3599After translation NAT64 translator by default sends packets through 3600corresponding netisr queue. 3601Thus translator host should be configured as IPv4 and IPv6 router. 3602Also this means, that a packet is handled by firewall twice. 3603First time an original packet is handled and consumed by translator, 3604and then it is handled again as translated packet. 3605This behavior can be changed by sysctl variable 3606.Va net.inet.ip.fw.nat64_direct_output . 3607Also translated packet can be tagged using 3608.Cm tag 3609rule action, and then matched by 3610.Cm tagged 3611opcode to avoid loops and extra overhead. 3612.Pp 3613The stateful NAT64 configuration command is the following: 3614.Bd -ragged -offset indent 3615.Bk -words 3616.Cm nat64lsn 3617.Ar name 3618.Cm create 3619.Ar create-options 3620.Ek 3621.Ed 3622.Pp 3623The following parameters can be configured: 3624.Bl -tag -width indent 3625.It Cm prefix4 Ar ipv4_prefix/plen 3626The IPv4 prefix with mask defines the pool of IPv4 addresses used as 3627source address after translation. 3628Stateful NAT64 module translates IPv6 source address of client to one 3629IPv4 address from this pool. 3630Note that incoming IPv4 packets that don't have corresponding state entry 3631in the states table will be dropped by translator. 3632Make sure that translation rules handle packets, destined to configured prefix. 3633.It Cm prefix6 Ar ipv6_prefix/length 3634The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3635to represent IPv4 addresses. 3636This IPv6 prefix should be configured in DNS64. 3637The translator implementation follows RFC6052, that restricts the length of 3638prefixes to one of following: 32, 40, 48, 56, 64, or 96. 3639The Well-Known IPv6 Prefix 64:ff9b:: must be 96 bits long. 3640The special 3641.Ar ::/length 3642prefix can be used to handle several IPv6 prefixes with one NAT64 instance. 3643The NAT64 instance will determine a destination IPv4 address from prefix 3644.Ar length . 3645.It Cm states_chunks Ar number 3646The number of states chunks in single ports group. 3647Each ports group by default can keep 64 state entries in single chunk. 3648The above value affects the maximum number of states that can be associated with 3649a single IPv4 alias address and port. 3650The value must be power of 2, and up to 128. 3651.It Cm host_del_age Ar seconds 3652The number of seconds until the host entry for a IPv6 client will be deleted 3653and all its resources will be released due to inactivity. 3654Default value is 3655.Ar 3600 . 3656.It Cm pg_del_age Ar seconds 3657The number of seconds until a ports group with unused state entries will 3658be released. 3659Default value is 3660.Ar 900 . 3661.It Cm tcp_syn_age Ar seconds 3662The number of seconds while a state entry for TCP connection with only SYN 3663sent will be kept. 3664If TCP connection establishing will not be finished, 3665state entry will be deleted. 3666Default value is 3667.Ar 10 . 3668.It Cm tcp_est_age Ar seconds 3669The number of seconds while a state entry for established TCP connection 3670will be kept. 3671Default value is 3672.Ar 7200 . 3673.It Cm tcp_close_age Ar seconds 3674The number of seconds while a state entry for closed TCP connection 3675will be kept. 3676Keeping state entries for closed connections is needed, because IPv4 servers 3677typically keep closed connections in a TIME_WAIT state for a several minutes. 3678Since translator's IPv4 addresses are shared among all IPv6 clients, 3679new connections from the same addresses and ports may be rejected by server, 3680because these connections are still in a TIME_WAIT state. 3681Keeping them in translator's state table protects from such rejects. 3682Default value is 3683.Ar 180 . 3684.It Cm udp_age Ar seconds 3685The number of seconds while translator keeps state entry in a waiting for 3686reply to the sent UDP datagram. 3687Default value is 3688.Ar 120 . 3689.It Cm icmp_age Ar seconds 3690The number of seconds while translator keeps state entry in a waiting for 3691reply to the sent ICMP message. 3692Default value is 3693.Ar 60 . 3694.It Cm log 3695Turn on logging of all handled packets via BPF tap named 3696.Ar ipfwlog0 . 3697Note that it has different purpose than per-rule 3698.Xr bpf 4 3699taps. 3700Translators sends to BPF an additional information with each packet. 3701With 3702.Cm tcpdump 3703you are able to see each handled packet before and after translation. 3704.It Cm -log 3705Turn off logging of all handled packets via BPF. 3706.It Cm allow_private 3707Turn on processing private IPv4 addresses. 3708By default IPv6 packets with destinations mapped to private address ranges 3709defined by RFC1918 are not processed. 3710.It Cm -allow_private 3711Turn off private address handling in 3712.Nm nat64 3713instance. 3714.El 3715.Pp 3716To inspect a states table of stateful NAT64 the following command can be used: 3717.Bd -ragged -offset indent 3718.Bk -words 3719.Cm nat64lsn 3720.Ar name 3721.Cm show Cm states 3722.Ek 3723.Ed 3724.Pp 3725Stateless NAT64 translator doesn't use a states table for translation 3726and converts IPv4 addresses to IPv6 and vice versa solely based on the 3727mappings taken from configured lookup tables. 3728Since a states table doesn't used by stateless translator, 3729it can be configured to pass IPv4 clients to IPv6-only servers. 3730.Pp 3731The stateless NAT64 configuration command is the following: 3732.Bd -ragged -offset indent 3733.Bk -words 3734.Cm nat64stl 3735.Ar name 3736.Cm create 3737.Ar create-options 3738.Ek 3739.Ed 3740.Pp 3741The following parameters can be configured: 3742.Bl -tag -width indent 3743.It Cm prefix6 Ar ipv6_prefix/length 3744The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3745to represent IPv4 addresses. 3746This IPv6 prefix should be configured in DNS64. 3747.It Cm table4 Ar table46 3748The lookup table 3749.Ar table46 3750contains mapping how IPv4 addresses should be translated to IPv6 addresses. 3751.It Cm table6 Ar table64 3752The lookup table 3753.Ar table64 3754contains mapping how IPv6 addresses should be translated to IPv4 addresses. 3755.It Cm log 3756Turn on logging of all handled packets via BPF through 3757.Ar ipfwlog0 3758tap. 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 3771Note that the behavior of stateless translator with respect to not matched 3772packets differs from stateful translator. 3773If corresponding addresses was not found in the lookup tables, the packet 3774will not be dropped and the search continues. 3775.Ss XLAT464 CLAT translation 3776XLAT464 CLAT NAT64 translator implements client-side stateless translation as 3777defined in RFC6877 and is very similar to statless NAT64 translator 3778explained above. 3779Instead of lookup tables it uses one-to-one mapping between IPv4 and IPv6 3780addresses using configured prefixes. 3781This mode can be used as a replacement of DNS64 service for applications 3782that are not using it (e.g. VoIP) allowing them to access IPv4-only Internet 3783over IPv6-only networks with help of remote NAT64 translator. 3784.Pp 3785The CLAT NAT64 configuration command is the following: 3786.Bd -ragged -offset indent 3787.Bk -words 3788.Cm nat64clat 3789.Ar name 3790.Cm create 3791.Ar create-options 3792.Ek 3793.Ed 3794.Pp 3795The following parameters can be configured: 3796.Bl -tag -width indent 3797.It Cm clat_prefix Ar ipv6_prefix/length 3798The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3799to represent source IPv4 addresses. 3800.It Cm plat_prefix Ar ipv6_prefix/length 3801The IPv6 prefix defines IPv4-embedded IPv6 addresses used by translator 3802to represent destination IPv4 addresses. 3803This IPv6 prefix should be configured on a remote NAT64 translator. 3804.It Cm log 3805Turn on logging of all handled packets via BPF through 3806.Ar ipfwlog0 3807tap. 3808.It Cm -log 3809Turn off logging of all handled packets via BPF. 3810.It Cm allow_private 3811Turn on processing private IPv4 addresses. 3812By default 3813.Nm nat64clat 3814instance will not process IPv4 packets with destination address from private 3815ranges as defined in RFC1918. 3816.It Cm -allow_private 3817Turn off private address handling in 3818.Nm nat64clat 3819instance. 3820.El 3821.Pp 3822Note that the behavior of CLAT translator with respect to not matched 3823packets differs from stateful translator. 3824If corresponding addresses were not matched against prefixes configured, 3825the packet will not be dropped and the search continues. 3826.Sh IPv6-to-IPv6 NETWORK PREFIX TRANSLATION (NPTv6) 3827.Nm 3828supports in-kernel IPv6-to-IPv6 network prefix translation as described 3829in RFC6296. 3830The kernel module 3831.Cm ipfw_nptv6 3832should be loaded or kernel should has 3833.Cm options IPFIREWALL_NPTV6 3834to be able use NPTv6 translator. 3835.Pp 3836The NPTv6 configuration command is the following: 3837.Bd -ragged -offset indent 3838.Bk -words 3839.Cm nptv6 3840.Ar name 3841.Cm create 3842.Ar create-options 3843.Ek 3844.Ed 3845.Pp 3846The following parameters can be configured: 3847.Bl -tag -width indent 3848.It Cm int_prefix Ar ipv6_prefix 3849IPv6 prefix used in internal network. 3850NPTv6 module translates source address when it matches this prefix. 3851.It Cm ext_prefix Ar ipv6_prefix 3852IPv6 prefix used in external network. 3853NPTv6 module translates destination address when it matches this prefix. 3854.It Cm ext_if Ar nic 3855The NPTv6 module will use first global IPv6 address from interface 3856.Ar nic 3857as external prefix. 3858It can be useful when IPv6 prefix of external network is dynamically obtained. 3859.Cm ext_prefix 3860and 3861.Cm ext_if 3862options are mutually exclusive. 3863.It Cm prefixlen Ar length 3864The length of specified IPv6 prefixes. 3865It must be in range from 8 to 64. 3866.El 3867.Pp 3868Note that the prefix translation rules are silently ignored when IPv6 packet 3869forwarding is disabled. 3870To enable the packet forwarding, set the sysctl variable 3871.Va net.inet6.ip6.forwarding 3872to 1. 3873.Pp 3874To let the packet continue after being translated, set the sysctl variable 3875.Va net.inet.ip.fw.one_pass 3876to 0. 3877.Sh LOADER TUNABLES 3878Tunables can be set in 3879.Xr loader 8 3880prompt, 3881.Xr loader.conf 5 3882or 3883.Xr kenv 1 3884before ipfw module gets loaded. 3885.Bl -tag -width indent 3886.It Va net.inet.ip.fw.enable : No 1 3887Enables the firewall. 3888Setting this variable to 0 lets you run your machine without 3889firewall even if compiled in. 3890.It Va net.inet6.ip6.fw.enable : No 1 3891provides the same functionality as above for the IPv6 case. 3892.It Va net.link.ether.ipfw : No 0 3893Controls whether layer2 packets are passed to 3894.Nm . 3895Default is no. 3896.It Va net.inet.ip.fw.default_to_accept : No 0 3897Defines ipfw last rule behavior. 3898This value overrides 3899.Cd "options IPFW_DEFAULT_TO_(ACCEPT|DENY)" 3900from kernel configuration file. 3901.It Va net.inet.ip.fw.tables_max : No 128 3902Defines number of tables available in ipfw. 3903Number cannot exceed 65534. 3904.El 3905.Sh SYSCTL VARIABLES 3906A set of 3907.Xr sysctl 8 3908variables controls the behaviour of the firewall and 3909associated modules 3910.Pq Nm dummynet , bridge , sctp nat . 3911These are shown below together with their default value 3912(but always check with the 3913.Xr sysctl 8 3914command what value is actually in use) and meaning: 3915.Bl -tag -width indent 3916.It Va net.inet.ip.alias.sctp.accept_global_ootb_addip : No 0 3917Defines how the 3918.Nm nat 3919responds to receipt of global OOTB ASCONF-AddIP: 3920.Bl -tag -width indent 3921.It Cm 0 3922No response (unless a partially matching association exists - 3923ports and vtags match but global address does not) 3924.It Cm 1 3925.Nm nat 3926will accept and process all OOTB global AddIP messages. 3927.El 3928.Pp 3929Option 1 should never be selected as this forms a security risk. 3930An attacker can 3931establish multiple fake associations by sending AddIP messages. 3932.It Va net.inet.ip.alias.sctp.chunk_proc_limit : No 5 3933Defines the maximum number of chunks in an SCTP packet that will be 3934parsed for a 3935packet that matches an existing association. 3936This value is enforced to be greater or equal than 3937.Cm net.inet.ip.alias.sctp.initialising_chunk_proc_limit . 3938A high value is 3939a DoS risk yet setting too low a value may result in 3940important control chunks in 3941the packet not being located and parsed. 3942.It Va net.inet.ip.alias.sctp.error_on_ootb : No 1 3943Defines when the 3944.Nm nat 3945responds to any Out-of-the-Blue (OOTB) packets with ErrorM packets. 3946An OOTB packet is a packet that arrives with no existing association 3947registered in the 3948.Nm nat 3949and is not an INIT or ASCONF-AddIP packet: 3950.Bl -tag -width indent 3951.It Cm 0 3952ErrorM is never sent in response to OOTB packets. 3953.It Cm 1 3954ErrorM is only sent to OOTB packets received on the local side. 3955.It Cm 2 3956ErrorM is sent to the local side and on the global side ONLY if there is a 3957partial match (ports and vtags match but the source global IP does not). 3958This value is only useful if the 3959.Nm nat 3960is tracking global IP addresses. 3961.It Cm 3 3962ErrorM is sent in response to all OOTB packets on both 3963the local and global side 3964(DoS risk). 3965.El 3966.Pp 3967At the moment the default is 0, since the ErrorM packet is not yet 3968supported by most SCTP stacks. 3969When it is supported, and if not tracking 3970global addresses, we recommend setting this value to 1 to allow 3971multi-homed local hosts to function with the 3972.Nm nat . 3973To track global addresses, we recommend setting this value to 2 to 3974allow global hosts to be informed when they need to (re)send an 3975ASCONF-AddIP. 3976Value 3 should never be chosen (except for debugging) as the 3977.Nm nat 3978will respond to all OOTB global packets (a DoS risk). 3979.It Va net.inet.ip.alias.sctp.hashtable_size : No 2003 3980Size of hash tables used for 3981.Nm nat 3982lookups (100 < prime_number > 1000001). 3983This value sets the 3984.Nm hash table 3985size for any future created 3986.Nm nat 3987instance and therefore must be set prior to creating a 3988.Nm nat 3989instance. 3990The table sizes may be changed to suit specific needs. 3991If there will be few 3992concurrent associations, and memory is scarce, you may make these smaller. 3993If there will be many thousands (or millions) of concurrent associations, you 3994should make these larger. 3995A prime number is best for the table size. 3996The sysctl 3997update function will adjust your input value to the next highest prime number. 3998.It Va net.inet.ip.alias.sctp.holddown_time : No 0 3999Hold association in table for this many seconds after receiving a 4000SHUTDOWN-COMPLETE. 4001This allows endpoints to correct shutdown gracefully if a 4002shutdown_complete is lost and retransmissions are required. 4003.It Va net.inet.ip.alias.sctp.init_timer : No 15 4004Timeout value while waiting for (INIT-ACK|AddIP-ACK). 4005This value cannot be 0. 4006.It Va net.inet.ip.alias.sctp.initialising_chunk_proc_limit : No 2 4007Defines the maximum number of chunks in an SCTP packet that will be parsed when 4008no existing association exists that matches that packet. 4009Ideally this packet 4010will only be an INIT or ASCONF-AddIP packet. 4011A higher value may become a DoS 4012risk as malformed packets can consume processing resources. 4013.It Va net.inet.ip.alias.sctp.param_proc_limit : No 25 4014Defines the maximum number of parameters within a chunk that will be 4015parsed in a 4016packet. 4017As for other similar sysctl variables, larger values pose a DoS risk. 4018.It Va net.inet.ip.alias.sctp.log_level : No 0 4019Level of detail in the system log messages (0 \- minimal, 1 \- event, 40202 \- info, 3 \- detail, 4 \- debug, 5 \- max debug). 4021May be a good 4022option in high loss environments. 4023.It Va net.inet.ip.alias.sctp.shutdown_time : No 15 4024Timeout value while waiting for SHUTDOWN-COMPLETE. 4025This value cannot be 0. 4026.It Va net.inet.ip.alias.sctp.track_global_addresses : No 0 4027Enables/disables global IP address tracking within the 4028.Nm nat 4029and places an 4030upper limit on the number of addresses tracked for each association: 4031.Bl -tag -width indent 4032.It Cm 0 4033Global tracking is disabled 4034.It Cm >1 4035Enables tracking, the maximum number of addresses tracked for each 4036association is limited to this value 4037.El 4038.Pp 4039This variable is fully dynamic, the new value will be adopted for all newly 4040arriving associations, existing associations are treated 4041as they were previously. 4042Global tracking will decrease the number of collisions within the 4043.Nm nat 4044at a cost 4045of increased processing load, memory usage, complexity, and possible 4046.Nm nat 4047state 4048problems in complex networks with multiple 4049.Nm nats . 4050We recommend not tracking 4051global IP addresses, this will still result in a fully functional 4052.Nm nat . 4053.It Va net.inet.ip.alias.sctp.up_timer : No 300 4054Timeout value to keep an association up with no traffic. 4055This value cannot be 0. 4056.It Va net.inet.ip.dummynet.codel.interval : No 100000 4057Default 4058.Cm codel 4059AQM interval in microseconds. 4060The value must be in the range 1..5000000. 4061.It Va net.inet.ip.dummynet.codel.target : No 5000 4062Default 4063.Cm codel 4064AQM target delay time in microseconds (the minimum acceptable persistent queue 4065delay). 4066The value must be in the range 1..5000000. 4067.It Va net.inet.ip.dummynet.expire : No 1 4068Lazily delete dynamic pipes/queue once they have no pending traffic. 4069You can disable this by setting the variable to 0, in which case 4070the pipes/queues will only be deleted when the threshold is reached. 4071.It Va net.inet.ip.dummynet.fqcodel.flows : No 1024 4072Defines the default total number of flow queues (sub-queues) that 4073.Cm fq_codel 4074creates and manages. 4075The value must be in the range 1..65536. 4076.It Va net.inet.ip.dummynet.fqcodel.interval : No 100000 4077Default 4078.Cm fq_codel 4079scheduler/AQM interval in microseconds. 4080The value must be in the range 1..5000000. 4081.It Va net.inet.ip.dummynet.fqcodel.limit : No 10240 4082The default hard size limit (in unit of packet) of all queues managed by an 4083instance of the 4084.Cm fq_codel 4085scheduler. 4086The value must be in the range 1..20480. 4087.It Va net.inet.ip.dummynet.fqcodel.quantum : No 1514 4088The default quantum (credit) of the 4089.Cm fq_codel 4090in unit of byte. 4091The value must be in the range 1..9000. 4092.It Va net.inet.ip.dummynet.fqcodel.target : No 5000 4093Default 4094.Cm fq_codel 4095scheduler/AQM target delay time in microseconds (the minimum acceptable 4096persistent queue delay). 4097The value must be in the range 1..5000000. 4098.It Va net.inet.ip.dummynet.fqpie.alpha : No 125 4099The default 4100.Ar alpha 4101parameter (scaled by 1000) for 4102.Cm fq_pie 4103scheduler/AQM. 4104The value must be in the range 1..7000. 4105.It Va net.inet.ip.dummynet.fqpie.beta : No 1250 4106The default 4107.Ar beta 4108parameter (scaled by 1000) for 4109.Cm fq_pie 4110scheduler/AQM. 4111The value must be in the range 1..7000. 4112.It Va net.inet.ip.dummynet.fqpie.flows : No 1024 4113Defines the default total number of flow queues (sub-queues) that 4114.Cm fq_pie 4115creates and manages. 4116The value must be in the range 1..65536. 4117.It Va net.inet.ip.dummynet.fqpie.limit : No 10240 4118The default hard size limit (in unit of packet) of all queues managed by an 4119instance of the 4120.Cm fq_pie 4121scheduler. 4122The value must be in the range 1..20480. 4123.It Va net.inet.ip.dummynet.fqpie.max_burst : No 150000 4124The default maximum period of microseconds that 4125.Cm fq_pie 4126scheduler/AQM does not drop/mark packets. 4127The value must be in the range 1..10000000. 4128.It Va net.inet.ip.dummynet.fqpie.max_ecnth : No 99 4129The default maximum ECN probability threshold (scaled by 1000) for 4130.Cm fq_pie 4131scheduler/AQM. 4132The value must be in the range 1..7000. 4133.It Va net.inet.ip.dummynet.fqpie.quantum : No 1514 4134The default quantum (credit) of the 4135.Cm fq_pie 4136in unit of byte. 4137The value must be in the range 1..9000. 4138.It Va net.inet.ip.dummynet.fqpie.target : No 15000 4139The default 4140.Cm target 4141delay of the 4142.Cm fq_pie 4143in unit of microsecond. 4144The value must be in the range 1..5000000. 4145.It Va net.inet.ip.dummynet.fqpie.tupdate : No 15000 4146The default 4147.Cm tupdate 4148of the 4149.Cm fq_pie 4150in unit of microsecond. 4151The value must be in the range 1..5000000. 4152.It Va net.inet.ip.dummynet.hash_size : No 64 4153Default size of the hash table used for dynamic pipes/queues. 4154This value is used when no 4155.Cm buckets 4156option is specified when configuring a pipe/queue. 4157.It Va net.inet.ip.dummynet.io_fast : No 0 4158If set to a non-zero value, 4159the 4160.Dq fast 4161mode of 4162.Nm dummynet 4163operation (see above) is enabled. 4164.It Va net.inet.ip.dummynet.io_pkt 4165Number of packets passed to 4166.Nm dummynet . 4167.It Va net.inet.ip.dummynet.io_pkt_drop 4168Number of packets dropped by 4169.Nm dummynet . 4170.It Va net.inet.ip.dummynet.io_pkt_fast 4171Number of packets bypassed by the 4172.Nm dummynet 4173scheduler. 4174.It Va net.inet.ip.dummynet.max_chain_len : No 16 4175Target value for the maximum number of pipes/queues in a hash bucket. 4176The product 4177.Cm max_chain_len*hash_size 4178is used to determine the threshold over which empty pipes/queues 4179will be expired even when 4180.Cm net.inet.ip.dummynet.expire=0 . 4181.It Va net.inet.ip.dummynet.red_lookup_depth : No 256 4182.It Va net.inet.ip.dummynet.red_avg_pkt_size : No 512 4183.It Va net.inet.ip.dummynet.red_max_pkt_size : No 1500 4184Parameters used in the computations of the drop probability 4185for the RED algorithm. 4186.It Va net.inet.ip.dummynet.pie.alpha : No 125 4187The default 4188.Ar alpha 4189parameter (scaled by 1000) for 4190.Cm pie 4191AQM. 4192The value must be in the range 1..7000. 4193.It Va net.inet.ip.dummynet.pie.beta : No 1250 4194The default 4195.Ar beta 4196parameter (scaled by 1000) for 4197.Cm pie 4198AQM. 4199The value must be in the range 1..7000. 4200.It Va net.inet.ip.dummynet.pie.max_burst : No 150000 4201The default maximum period of microseconds that 4202.Cm pie 4203AQM does not drop/mark packets. 4204The value must be in the range 1..10000000. 4205.It Va net.inet.ip.dummynet.pie.max_ecnth : No 99 4206The default maximum ECN probability threshold (scaled by 1000) for 4207.Cm pie 4208AQM. 4209The value must be in the range 1..7000. 4210.It Va net.inet.ip.dummynet.pie.target : No 15000 4211The default 4212.Cm target 4213delay of 4214.Cm pie 4215AQM in unit of microsecond. 4216The value must be in the range 1..5000000. 4217.It Va net.inet.ip.dummynet.pie.tupdate : No 15000 4218The default 4219.Cm tupdate 4220of 4221.Cm pie 4222AQM in unit of microsecond. 4223The value must be in the range 1..5000000. 4224.It Va net.inet.ip.dummynet.pipe_byte_limit : No 1048576 4225.It Va net.inet.ip.dummynet.pipe_slot_limit : No 100 4226The maximum queue size that can be specified in bytes or packets. 4227These limits prevent accidental exhaustion of resources such as mbufs. 4228If you raise these limits, 4229you should make sure the system is configured so that sufficient resources 4230are available. 4231.It Va net.inet.ip.fw.autoinc_step : No 100 4232Delta between rule numbers when auto-generating them. 4233The value must be in the range 1..1000. 4234.It Va net.inet.ip.fw.curr_dyn_buckets : Va net.inet.ip.fw.dyn_buckets 4235The current number of buckets in the hash table for dynamic rules 4236(readonly). 4237.It Va net.inet.ip.fw.debug : No 1 4238Controls debugging messages produced by 4239.Nm . 4240.It Va net.inet.ip.fw.default_rule : No 65535 4241The default rule number (read-only). 4242By the design of 4243.Nm , the default rule is the last one, so its number 4244can also serve as the highest number allowed for a rule. 4245.It Va net.inet.ip.fw.dyn_buckets : No 256 4246The number of buckets in the hash table for dynamic rules. 4247Must be a power of 2, up to 65536. 4248It only takes effect when all dynamic rules have expired, so you 4249are advised to use a 4250.Cm flush 4251command to make sure that the hash table is resized. 4252.It Va net.inet.ip.fw.dyn_count : No 3 4253Current number of dynamic rules 4254(read-only). 4255.It Va net.inet.ip.fw.dyn_keepalive : No 1 4256Enables generation of keepalive packets for 4257.Cm keep-state 4258rules on TCP sessions. 4259A keepalive is generated to both 4260sides of the connection every 5 seconds for the last 20 4261seconds of the lifetime of the rule. 4262.It Va net.inet.ip.fw.dyn_max : No 8192 4263Maximum number of dynamic rules. 4264When you hit this limit, no more dynamic rules can be 4265installed until old ones expire. 4266.It Va net.inet.ip.fw.dyn_ack_lifetime : No 300 4267.It Va net.inet.ip.fw.dyn_syn_lifetime : No 20 4268.It Va net.inet.ip.fw.dyn_fin_lifetime : No 1 4269.It Va net.inet.ip.fw.dyn_rst_lifetime : No 1 4270.It Va net.inet.ip.fw.dyn_udp_lifetime : No 5 4271.It Va net.inet.ip.fw.dyn_short_lifetime : No 30 4272These variables control the lifetime, in seconds, of dynamic 4273rules. 4274Upon the initial SYN exchange the lifetime is kept short, 4275then increased after both SYN have been seen, then decreased 4276again during the final FIN exchange or when a RST is received. 4277Both 4278.Em dyn_fin_lifetime 4279and 4280.Em dyn_rst_lifetime 4281must be strictly lower than 5 seconds, the period of 4282repetition of keepalives. 4283The firewall enforces that. 4284.It Va net.inet.ip.fw.dyn_keep_states : No 0 4285Keep dynamic states on rule/set deletion. 4286States are relinked to default rule (65535). 4287This can be handly for ruleset reload. 4288Turned off by default. 4289.It Va net.inet.ip.fw.one_pass : No 1 4290When set, the packet exiting from the 4291.Nm dummynet 4292pipe or from 4293.Xr ng_ipfw 4 4294node is not passed though the firewall again. 4295Otherwise, after an action, the packet is 4296reinjected into the firewall at the next rule. 4297.It Va net.inet.ip.fw.tables_max : No 128 4298Maximum number of tables. 4299.It Va net.inet.ip.fw.verbose : No 1 4300Enables verbose messages. 4301.It Va net.inet.ip.fw.verbose_limit : No 0 4302Limits the number of messages produced by a verbose firewall. 4303.It Va net.inet6.ip6.fw.deny_unknown_exthdrs : No 1 4304If enabled packets with unknown IPv6 Extension Headers will be denied. 4305.It Va net.link.bridge.ipfw : No 0 4306Controls whether bridged packets are passed to 4307.Nm . 4308Default is no. 4309.It Va net.inet.ip.fw.nat64_debug : No 0 4310Controls debugging messages produced by 4311.Nm ipfw_nat64 4312module. 4313.It Va net.inet.ip.fw.nat64_direct_output : No 0 4314Controls the output method used by 4315.Nm ipfw_nat64 4316module: 4317.Bl -tag -width indent 4318.It Cm 0 4319A packet is handled by 4320.Nm ipfw 4321twice. 4322First time an original packet is handled by 4323.Nm ipfw 4324and consumed by 4325.Nm ipfw_nat64 4326translator. 4327Then translated packet is queued via netisr to input processing again. 4328.It Cm 1 4329A packet is handled by 4330.Nm ipfw 4331only once, and after translation it will be pushed directly to outgoing 4332interface. 4333.El 4334.El 4335.Sh INTERNAL DIAGNOSTICS 4336There are some commands that may be useful to understand current state 4337of certain subsystems inside kernel module. 4338These commands provide debugging output which may change without notice. 4339.Pp 4340Currently the following commands are available as 4341.Cm internal 4342sub-options: 4343.Bl -tag -width indent 4344.It Cm iflist 4345Lists all interface which are currently tracked by 4346.Nm 4347with their in-kernel status. 4348.It Cm monitor Op Ar filter-comment 4349Capture messages from 4350.Xr route 4 4351socket, that were logged using rules with 4352.Cm log Cm logdst Ar rtsock 4353opcode. Optional 4354.Ar filter-comment 4355can be specified to show only those messages, that were logged 4356by rules with specific rule comment. 4357.It Cm talist 4358List all table lookup algorithms currently available. 4359.El 4360.Sh EXAMPLES 4361There are far too many possible uses of 4362.Nm 4363so this Section will only give a small set of examples. 4364.Ss BASIC PACKET FILTERING 4365This command adds an entry which denies all tcp packets from 4366.Em cracker.evil.org 4367to the telnet port of 4368.Em wolf.tambov.su 4369from being forwarded by the host: 4370.Pp 4371.Dl "ipfw add deny tcp from cracker.evil.org to wolf.tambov.su telnet" 4372.Pp 4373This one disallows any connection from the entire cracker's 4374network to my host: 4375.Pp 4376.Dl "ipfw add deny ip from 123.45.67.0/24 to my.host.org" 4377.Pp 4378A first and efficient way to limit access (not using dynamic rules) 4379is the use of the following rules: 4380.Pp 4381.Dl "ipfw add allow tcp from any to any established" 4382.Dl "ipfw add allow tcp from net1 portlist1 to net2 portlist2 setup" 4383.Dl "ipfw add allow tcp from net3 portlist3 to net3 portlist3 setup" 4384.Dl "..." 4385.Dl "ipfw add deny tcp from any to any" 4386.Pp 4387The first rule will be a quick match for normal TCP packets, 4388but it will not match the initial SYN packet, which will be 4389matched by the 4390.Cm setup 4391rules only for selected source/destination pairs. 4392All other SYN packets will be rejected by the final 4393.Cm deny 4394rule. 4395.Pp 4396If you administer one or more subnets, you can take advantage 4397of the address sets and or-blocks and write extremely 4398compact rulesets which selectively enable services to blocks 4399of clients, as below: 4400.Pp 4401.Dl "goodguys=\*q{ 10.1.2.0/24{20,35,66,18} or 10.2.3.0/28{6,3,11} }\*q" 4402.Dl "badguys=\*q10.1.2.0/24{8,38,60}\*q" 4403.Dl "" 4404.Dl "ipfw add allow ip from ${goodguys} to any" 4405.Dl "ipfw add deny ip from ${badguys} to any" 4406.Dl "... normal policies ..." 4407.Pp 4408Allow any transit packets coming from single vlan 10 and 4409going out to vlans 100-1000: 4410.Pp 4411.Dl "ipfw add 10 allow out recv vlan10 \e" 4412.Dl "{ xmit vlan1000 or xmit \*qvlan[1-9]??\*q }" 4413.Pp 4414The 4415.Cm verrevpath 4416option could be used to do automated anti-spoofing by adding the 4417following to the top of a ruleset: 4418.Pp 4419.Dl "ipfw add deny ip from any to any not verrevpath in" 4420.Pp 4421This rule drops all incoming packets that appear to be coming to the 4422system on the wrong interface. 4423For example, a packet with a source 4424address belonging to a host on a protected internal network would be 4425dropped if it tried to enter the system from an external interface. 4426.Pp 4427The 4428.Cm antispoof 4429option could be used to do similar but more restricted anti-spoofing 4430by adding the following to the top of a ruleset: 4431.Pp 4432.Dl "ipfw add deny ip from any to any not antispoof in" 4433.Pp 4434This rule drops all incoming packets that appear to be coming from another 4435directly connected system but on the wrong interface. 4436For example, a packet with a source address of 4437.Li 192.168.0.0/24 , 4438configured on 4439.Li fxp0 , 4440but coming in on 4441.Li fxp1 4442would be dropped. 4443.Pp 4444The 4445.Cm setdscp 4446option could be used to (re)mark user traffic, 4447by adding the following to the appropriate place in ruleset: 4448.Pp 4449.Dl "ipfw add setdscp be ip from any to any dscp af11,af21" 4450.Ss SELECTIVE MIRRORING 4451If your network has network traffic analyzer 4452connected to your host directly via dedicated interface 4453or remotely via RSPAN vlan, you can selectively mirror 4454some Ethernet layer2 frames to the analyzer. 4455.Pp 4456First, make sure your firewall is already configured and runs. 4457Then, enable layer2 processing if not already enabled: 4458.Pp 4459.Dl "sysctl net.link.ether.ipfw=1" 4460.Pp 4461Next, load needed additional kernel modules: 4462.Pp 4463.Dl "kldload ng_ether ng_ipfw" 4464.Pp 4465Optionally, make system load these modules automatically 4466at startup: 4467.Pp 4468.Dl sysrc kld_list+="ng_ether ng_ipfw" 4469.Pp 4470Next, configure 4471.Xr ng_ipfw 4 4472kernel module to transmit mirrored copies of layer2 frames 4473out via vlan900 interface: 4474.Pp 4475.Dl "ngctl connect ipfw: vlan900: 1 lower" 4476.Pp 4477Think of "1" here as of "mirroring instance index" and vlan900 is its 4478destination. 4479You can have arbitrary number of instances. 4480Refer to 4481.Xr ng_ipfw 4 4482for details. 4483.Pp 4484At last, actually start mirroring of selected frames using "instance 1". 4485For frames incoming from em0 interface: 4486.Pp 4487.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 in recv em0" 4488.Pp 4489For frames outgoing to em0 interface: 4490.Pp 4491.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 out xmit em0" 4492.Pp 4493For both incoming and outgoing frames while flowing through em0: 4494.Pp 4495.Dl "ipfw add ngtee 1 ip from any to 192.168.0.1 layer2 via em0" 4496.Pp 4497Make sure you do not perform mirroring for already duplicated frames 4498or kernel may hang as there is no safety net. 4499.Ss DYNAMIC RULES 4500In order to protect a site from flood attacks involving fake 4501TCP packets, it is safer to use dynamic rules: 4502.Pp 4503.Dl "ipfw add check-state" 4504.Dl "ipfw add deny tcp from any to any established" 4505.Dl "ipfw add allow tcp from my-net to any setup keep-state" 4506.Pp 4507This will let the firewall install dynamic rules only for 4508those connection which start with a regular SYN packet coming 4509from the inside of our network. 4510Dynamic rules are checked when encountering the first 4511occurrence of a 4512.Cm check-state , 4513.Cm keep-state 4514or 4515.Cm limit 4516rule. 4517A 4518.Cm check-state 4519rule should usually be placed near the beginning of the 4520ruleset to minimize the amount of work scanning the ruleset. 4521Your mileage may vary. 4522.Pp 4523For more complex scenarios with dynamic rules 4524.Cm record-state 4525and 4526.Cm defer-action 4527can be used to precisely control creation and checking of dynamic rules. 4528Example of usage of these options are provided in 4529.Sx NETWORK ADDRESS TRANSLATION (NAT)\& 4530Section. 4531.Pp 4532To limit the number of connections a user can open 4533you can use the following type of rules: 4534.Pp 4535.Dl "ipfw add allow tcp from my-net/24 to any setup limit src-addr 10" 4536.Dl "ipfw add allow tcp from any to me setup limit src-addr 4" 4537.Pp 4538The former (assuming it runs on a gateway) will allow each host 4539on a /24 network to open at most 10 TCP connections. 4540The latter can be placed on a server to make sure that a single 4541client does not use more than 4 simultaneous connections. 4542.Pp 4543.Em BEWARE : 4544stateful rules can be subject to denial-of-service attacks 4545by a SYN-flood which opens a huge number of dynamic rules. 4546The effects of such attacks can be partially limited by 4547acting on a set of 4548.Xr sysctl 8 4549variables which control the operation of the firewall. 4550.Pp 4551Here is a good usage of the 4552.Cm list 4553command to see accounting records and timestamp information: 4554.Pp 4555.Dl ipfw -at list 4556.Pp 4557or in short form without timestamps: 4558.Pp 4559.Dl ipfw -a list 4560.Pp 4561which is equivalent to: 4562.Pp 4563.Dl ipfw show 4564.Pp 4565Next rule diverts all incoming packets from 192.168.2.0/24 4566to divert port 5000: 4567.Pp 4568.Dl ipfw divert 5000 ip from 192.168.2.0/24 to any in 4569.Ss TRAFFIC SHAPING 4570The following rules show some of the applications of 4571.Nm 4572and 4573.Nm dummynet 4574for simulations and the like. 4575.Pp 4576This rule drops random incoming packets with a probability 4577of 5%: 4578.Pp 4579.Dl "ipfw add prob 0.05 deny ip from any to any in" 4580.Pp 4581A similar effect can be achieved making use of 4582.Nm dummynet 4583pipes: 4584.Pp 4585.Dl "dnctl add pipe 10 ip from any to any" 4586.Dl "dnctl pipe 10 config plr 0.05" 4587.Pp 4588We can use pipes to artificially limit bandwidth, e.g.\& on a 4589machine acting as a router, if we want to limit traffic from 4590local clients on 192.168.2.0/24 we do: 4591.Pp 4592.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 4593.Dl "dnctl pipe 1 config bw 300Kbit/s queue 50KBytes" 4594.Pp 4595note that we use the 4596.Cm out 4597modifier so that the rule is not used twice. 4598Remember in fact that 4599.Nm 4600rules are checked both on incoming and outgoing packets. 4601.Pp 4602Should we want to simulate a bidirectional link with bandwidth 4603limitations, the correct way is the following: 4604.Pp 4605.Dl "ipfw add pipe 1 ip from any to any out" 4606.Dl "ipfw add pipe 2 ip from any to any in" 4607.Dl "dnctl pipe 1 config bw 64Kbit/s queue 10Kbytes" 4608.Dl "dnctl pipe 2 config bw 64Kbit/s queue 10Kbytes" 4609.Pp 4610The above can be very useful, e.g.\& if you want to see how 4611your fancy Web page will look for a residential user who 4612is connected only through a slow link. 4613You should not use only one pipe for both directions, unless 4614you want to simulate a half-duplex medium (e.g.\& AppleTalk, 4615Ethernet, IRDA). 4616It is not necessary that both pipes have the same configuration, 4617so we can also simulate asymmetric links. 4618.Pp 4619Should we want to verify network performance with the RED queue 4620management algorithm: 4621.Pp 4622.Dl "ipfw add pipe 1 ip from any to any" 4623.Dl "dnctl pipe 1 config bw 500Kbit/s queue 100 red 0.002/30/80/0.1" 4624.Pp 4625Another typical application of the traffic shaper is to 4626introduce some delay in the communication. 4627This can significantly affect applications which do a lot of Remote 4628Procedure Calls, and where the round-trip-time of the 4629connection often becomes a limiting factor much more than 4630bandwidth: 4631.Pp 4632.Dl "ipfw add pipe 1 ip from any to any out" 4633.Dl "ipfw add pipe 2 ip from any to any in" 4634.Dl "dnctl pipe 1 config delay 250ms bw 1Mbit/s" 4635.Dl "dnctl pipe 2 config delay 250ms bw 1Mbit/s" 4636.Pp 4637Per-flow queueing can be useful for a variety of purposes. 4638A very simple one is counting traffic: 4639.Pp 4640.Dl "ipfw add pipe 1 tcp from any to any" 4641.Dl "ipfw add pipe 1 udp from any to any" 4642.Dl "ipfw add pipe 1 ip from any to any" 4643.Dl "dnctl pipe 1 config mask all" 4644.Pp 4645The above set of rules will create queues (and collect 4646statistics) for all traffic. 4647Because the pipes have no limitations, the only effect is 4648collecting statistics. 4649Note that we need 3 rules, not just the last one, because 4650when 4651.Nm 4652tries to match IP packets it will not consider ports, so we 4653would not see connections on separate ports as different 4654ones. 4655.Pp 4656A more sophisticated example is limiting the outbound traffic 4657on a net with per-host limits, rather than per-network limits: 4658.Pp 4659.Dl "ipfw add pipe 1 ip from 192.168.2.0/24 to any out" 4660.Dl "ipfw add pipe 2 ip from any to 192.168.2.0/24 in" 4661.Dl "dnctl pipe 1 config mask src-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 4662.Dl "dnctl pipe 2 config mask dst-ip 0x000000ff bw 200Kbit/s queue 20Kbytes" 4663.Ss LOOKUP TABLES 4664In the following example, we need to create several traffic bandwidth 4665classes and we need different hosts/networks to fall into different classes. 4666We create one pipe for each class and configure them accordingly. 4667Then we create a single table and fill it with IP subnets and addresses. 4668For each subnet/host we set the argument equal to the number of the pipe 4669that it should use. 4670Then we classify traffic using a single rule: 4671.Pp 4672.Dl "dnctl pipe 1 config bw 1000Kbyte/s" 4673.Dl "dnctl pipe 4 config bw 4000Kbyte/s" 4674.Dl "..." 4675.Dl "ipfw table T1 create type addr" 4676.Dl "ipfw table T1 add 192.168.2.0/24 1" 4677.Dl "ipfw table T1 add 192.168.0.0/27 4" 4678.Dl "ipfw table T1 add 192.168.0.2 1" 4679.Dl "..." 4680.Dl "ipfw add pipe tablearg ip from 'table(T1)' to any" 4681.Pp 4682Using the 4683.Cm fwd 4684action, the table entries may include hostnames and IP addresses. 4685.Pp 4686.Dl "ipfw table T2 create type addr valtype ipv4" 4687.Dl "ipfw table T2 add 192.168.2.0/24 10.23.2.1" 4688.Dl "ipfw table T2 add 192.168.0.0/27 router1.dmz" 4689.Dl "..." 4690.Dl "ipfw add 100 fwd tablearg ip from any to 'table(T2)'" 4691.Pp 4692In the following example per-interface firewall is created: 4693.Pp 4694.Dl "ipfw table IN create type iface valtype skipto,fib" 4695.Dl "ipfw table IN add vlan20 12000,12" 4696.Dl "ipfw table IN add vlan30 13000,13" 4697.Dl "ipfw table OUT create type iface valtype skipto" 4698.Dl "ipfw table OUT add vlan20 22000" 4699.Dl "ipfw table OUT add vlan30 23000" 4700.Dl ".." 4701.Dl "ipfw add 100 setfib tablearg ip from any to any recv 'table(IN)' in" 4702.Dl "ipfw add 200 skipto tablearg ip from any to any recv 'table(IN)' in" 4703.Dl "ipfw add 300 skipto tablearg ip from any to any xmit 'table(OUT)' out" 4704.Pp 4705The following example illustrate usage of flow tables: 4706.Pp 4707.Dl "ipfw table fl create type flow:src-ip,proto,dst-ip,dst-port" 4708.Dl "ipfw table fl add 2a02:6b8:77::88,tcp,2a02:6b8:77::99,80 11" 4709.Dl "ipfw table fl add 10.0.0.1,udp,10.0.0.2,53 12" 4710.Dl ".." 4711.Dl "ipfw add 100 allow ip from any to any flow 'table(fl,11)' recv ix0" 4712.Ss SETS OF RULES 4713To add a set of rules atomically, e.g.\& set 18: 4714.Pp 4715.Dl "ipfw set disable 18" 4716.Dl "ipfw add NN set 18 ... # repeat as needed" 4717.Dl "ipfw set enable 18" 4718.Pp 4719To delete a set of rules atomically the command is simply: 4720.Pp 4721.Dl "ipfw delete set 18" 4722.Pp 4723To test a ruleset and disable it and regain control if something goes wrong: 4724.Pp 4725.Dl "ipfw set disable 18" 4726.Dl "ipfw add NN set 18 ... # repeat as needed" 4727.Dl "ipfw set enable 18; echo done; sleep 30 && ipfw set disable 18" 4728.Pp 4729Here if everything goes well, you press control-C before the "sleep" 4730terminates, and your ruleset will be left active. 4731Otherwise, e.g.\& if 4732you cannot access your box, the ruleset will be disabled after 4733the sleep terminates thus restoring the previous situation. 4734.Pp 4735To show rules of the specific set: 4736.Pp 4737.Dl "ipfw set 18 show" 4738.Pp 4739To show rules of the disabled set: 4740.Pp 4741.Dl "ipfw -S set 18 show" 4742.Pp 4743To clear a specific rule counters of the specific set: 4744.Pp 4745.Dl "ipfw set 18 zero NN" 4746.Pp 4747To delete a specific rule of the specific set: 4748.Pp 4749.Dl "ipfw set 18 delete NN" 4750.Ss NAT, REDIRECT AND LSNAT 4751First redirect all the traffic to nat instance 123: 4752.Pp 4753.Dl "ipfw add nat 123 all from any to any" 4754.Pp 4755Then to configure nat instance 123 to alias all the outgoing traffic with ip 4756192.168.0.123, blocking all incoming connections, trying to keep 4757same ports on both sides, clearing aliasing table on address change 4758and keeping a log of traffic/link statistics: 4759.Pp 4760.Dl "ipfw nat 123 config ip 192.168.0.123 log deny_in reset same_ports" 4761.Pp 4762Or to change address of instance 123, aliasing table will be cleared (see 4763reset option): 4764.Pp 4765.Dl "ipfw nat 123 config ip 10.0.0.1" 4766.Pp 4767To see configuration of nat instance 123: 4768.Pp 4769.Dl "ipfw nat 123 show config" 4770.Pp 4771To show logs of all instances: 4772.Pp 4773.Dl "ipfw nat show log" 4774.Pp 4775To see configurations of all instances: 4776.Pp 4777.Dl "ipfw nat show config" 4778.Pp 4779Or a redirect rule with mixed modes could looks like: 4780.Bd -literal -offset 2n 4781ipfw nat 123 config redirect_addr 10.0.0.1 10.0.0.66 4782 redirect_port tcp 192.168.0.1:80 500 4783 redirect_proto udp 192.168.1.43 192.168.1.1 4784 redirect_addr 192.168.0.10,192.168.0.11 4785 10.0.0.100 # LSNAT 4786 redirect_port tcp 192.168.0.1:80,192.168.0.10:22 4787 500 # LSNAT 4788.Ed 4789.Pp 4790or it could be split in: 4791.Bd -literal -offset 2n 4792ipfw nat 1 config redirect_addr 10.0.0.1 10.0.0.66 4793ipfw nat 2 config redirect_port tcp 192.168.0.1:80 500 4794ipfw nat 3 config redirect_proto udp 192.168.1.43 192.168.1.1 4795ipfw nat 4 config redirect_addr 192.168.0.10,192.168.0.11,192.168.0.12 4796 10.0.0.100 4797ipfw nat 5 config redirect_port tcp 4798 192.168.0.1:80,192.168.0.10:22,192.168.0.20:25 500 4799.Ed 4800.Pp 4801Sometimes you may want to mix NAT and dynamic rules. 4802It could be achieved with 4803.Cm record-state 4804and 4805.Cm defer-action 4806options. 4807Problem is, you need to create dynamic rule before NAT and check it 4808after NAT actions (or vice versa) to have consistent addresses and ports. 4809Rule with 4810.Cm keep-state 4811option will trigger activation of existing dynamic state, and action of such 4812rule will be performed as soon as rule is matched. 4813In case of NAT and 4814.Cm allow 4815rule packet need to be passed to NAT, not allowed as soon is possible. 4816.Pp 4817There is example of set of rules to achieve this. 4818Bear in mind that this is example only and it is not very useful by itself. 4819.Pp 4820On way out, after all checks place this rules: 4821.Pp 4822.Dl "ipfw add allow record-state defer-action" 4823.Dl "ipfw add nat 1" 4824.Pp 4825And on way in there should be something like this: 4826.Pp 4827.Dl "ipfw add nat 1" 4828.Dl "ipfw add check-state" 4829.Pp 4830Please note, that first rule on way out doesn't allow packet and doesn't 4831execute existing dynamic rules. 4832All it does, create new dynamic rule with 4833.Cm allow 4834action, if it is not created yet. 4835Later, this dynamic rule is used on way in by 4836.Cm check-state 4837rule. 4838.Ss CONFIGURING CODEL, PIE, FQ-CODEL and FQ-PIE AQM 4839.Cm codel 4840and 4841.Cm pie 4842AQM can be configured for 4843.Nm dummynet 4844.Cm pipe 4845or 4846.Cm queue . 4847.Pp 4848To configure a 4849.Cm pipe 4850with 4851.Cm codel 4852AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s 4853rate limit, we do: 4854.Pp 4855.Dl "dnctl pipe 1 config bw 1mbits/s codel" 4856.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any" 4857.Pp 4858To configure a 4859.Cm queue 4860with 4861.Cm codel 4862AQM using different configurations parameters for traffic from 4863192.168.0.0/24 and 1Mbits/s rate limit, we do: 4864.Pp 4865.Dl "dnctl pipe 1 config bw 1mbits/s" 4866.Dl "dnctl queue 1 config pipe 1 codel target 8ms interval 160ms ecn" 4867.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4868.Pp 4869To configure a 4870.Cm pipe 4871with 4872.Cm pie 4873AQM using default configuration for traffic from 192.168.0.0/24 and 1Mbits/s 4874rate limit, we do: 4875.Pp 4876.Dl "dnctl pipe 1 config bw 1mbits/s pie" 4877.Dl "ipfw add 100 pipe 1 ip from 192.168.0.0/24 to any" 4878.Pp 4879To configure a 4880.Cm queue 4881with 4882.Cm pie 4883AQM using different configuration parameters for traffic from 4884192.168.0.0/24 and 1Mbits/s rate limit, we do: 4885.Pp 4886.Dl "dnctl pipe 1 config bw 1mbits/s" 4887.Dl "dnctl queue 1 config pipe 1 pie target 20ms tupdate 30ms ecn" 4888.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4889.Pp 4890.Cm fq_codel 4891and 4892.Cm fq_pie 4893AQM can be configured for 4894.Nm dummynet 4895schedulers. 4896.Pp 4897To configure 4898.Cm fq_codel 4899scheduler using different configurations parameters for traffic from 4900192.168.0.0/24 and 1Mbits/s rate limit, we do: 4901.Pp 4902.Dl "dnctl pipe 1 config bw 1mbits/s" 4903.Dl "dnctl sched 1 config pipe 1 type fq_codel" 4904.Dl "dnctl queue 1 config sched 1" 4905.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4906.Pp 4907To change 4908.Cm fq_codel 4909default configuration for a 4910.Cm sched 4911such as disable ECN and change the 4912.Ar target 4913to 10ms, we do: 4914.Pp 4915.Dl "dnctl sched 1 config pipe 1 type fq_codel target 10ms noecn" 4916.Pp 4917Similar to 4918.Cm fq_codel , 4919to configure 4920.Cm fq_pie 4921scheduler using different configurations parameters for traffic from 4922192.168.0.0/24 and 1Mbits/s rate limit, we do: 4923.Pp 4924.Dl "dnctl pipe 1 config bw 1mbits/s" 4925.Dl "dnctl sched 1 config pipe 1 type fq_pie" 4926.Dl "dnctl queue 1 config sched 1" 4927.Dl "ipfw add 100 queue 1 ip from 192.168.0.0/24 to any" 4928.Pp 4929The configurations of 4930.Cm fq_pie 4931.Cm sched 4932can be changed in a similar way as for 4933.Cm fq_codel 4934.Sh SEE ALSO 4935.Xr cpp 1 , 4936.Xr m4 1 , 4937.Xr fnmatch 3 , 4938.Xr altq 4 , 4939.Xr divert 4 , 4940.Xr dummynet 4 , 4941.Xr if_bridge 4 , 4942.Xr ip 4 , 4943.Xr ipfirewall 4 , 4944.Xr ng_ether 4 , 4945.Xr ng_ipfw 4 , 4946.Xr protocols 5 , 4947.Xr services 5 , 4948.Xr init 8 , 4949.Xr kldload 8 , 4950.Xr reboot 8 , 4951.Xr sysctl 8 , 4952.Xr syslogd 8 , 4953.Xr sysrc 8 4954.Sh HISTORY 4955The 4956.Nm 4957utility first appeared in 4958.Fx 2.0 . 4959.Nm dummynet 4960was introduced in 4961.Fx 2.2.8 . 4962Stateful extensions were introduced in 4963.Fx 4.0 . 4964.Nm ipfw2 4965was introduced in Summer 2002. 4966.Sh AUTHORS 4967.An Ugen J. S. Antsilevich , 4968.An Poul-Henning Kamp , 4969.An Alex Nash , 4970.An Archie Cobbs , 4971.An Luigi Rizzo , 4972.An Rasool Al-Saadi . 4973.Pp 4974.An -nosplit 4975API based upon code written by 4976.An Daniel Boulet 4977for BSDI. 4978.Pp 4979Dummynet has been introduced by Luigi Rizzo in 1997-1998. 4980.Pp 4981Some early work (1999-2000) on the 4982.Nm dummynet 4983traffic shaper supported by Akamba Corp. 4984.Pp 4985The ipfw core (ipfw2) has been completely redesigned and 4986reimplemented by Luigi Rizzo in summer 2002. 4987Further 4988actions and 4989options have been added by various developers over the years. 4990.Pp 4991.An -nosplit 4992In-kernel NAT support written by 4993.An Paolo Pisati Aq Mt piso@FreeBSD.org 4994as part of a Summer of Code 2005 project. 4995.Pp 4996SCTP 4997.Nm nat 4998support has been developed by 4999.An The Centre for Advanced Internet Architectures (CAIA) Aq http://www.caia.swin.edu.au . 5000The primary developers and maintainers are David Hayes and Jason But. 5001For further information visit: 5002.Aq http://www.caia.swin.edu.au/urp/SONATA 5003.Pp 5004Delay profiles have been developed by Alessandro Cerri and 5005Luigi Rizzo, supported by the 5006European Commission within Projects Onelab and Onelab2. 5007.Pp 5008CoDel, PIE, FQ-CoDel and FQ-PIE AQM for Dummynet have been implemented by 5009.An The Centre for Advanced Internet Architectures (CAIA) 5010in 2016, supported by The Comcast Innovation Fund. 5011The primary developer is 5012Rasool Al-Saadi. 5013.Sh BUGS 5014The syntax has grown over the years and sometimes it might be confusing. 5015Unfortunately, backward compatibility prevents cleaning up mistakes 5016made in the definition of the syntax. 5017.Pp 5018.Em !!! WARNING !!!\& 5019.Pp 5020Misconfiguring the firewall can put your computer in an unusable state, 5021possibly shutting down network services and requiring console access to 5022regain control of it. 5023.Pp 5024Incoming packet fragments diverted by 5025.Cm divert 5026are reassembled before delivery to the socket. 5027The action used on those packet is the one from the 5028rule which matches the first fragment of the packet. 5029.Pp 5030Packets diverted to userland, and then reinserted by a userland process 5031may lose various packet attributes. 5032The packet source interface name 5033will be preserved if it is shorter than 8 bytes and the userland process 5034saves and reuses the sockaddr_in 5035(as does 5036.Xr natd 8 ) ; 5037otherwise, it may be lost. 5038If a packet is reinserted in this manner, later rules may be incorrectly 5039applied, making the order of 5040.Cm divert 5041rules in the rule sequence very important. 5042.Pp 5043Dummynet drops all packets with IPv6 link-local addresses. 5044.Pp 5045Rules using 5046.Cm uid 5047or 5048.Cm gid 5049may not behave as expected. 5050In particular, incoming SYN packets may 5051have no uid or gid associated with them since they do not yet belong 5052to a TCP connection, and the uid/gid associated with a packet may not 5053be as expected if the associated process calls 5054.Xr setuid 2 5055or similar system calls. 5056.Pp 5057Rule syntax is subject to the command line environment and some patterns 5058may need to be escaped with the backslash character 5059or quoted appropriately. 5060.Pp 5061Due to the architecture of 5062.Xr libalias 3 , 5063ipfw nat is not compatible with the TCP segmentation offloading (TSO). 5064Thus, to reliably nat your network traffic, please disable TSO 5065on your NICs using 5066.Xr ifconfig 8 . 5067.Pp 5068ICMP error messages are not implicitly matched by dynamic rules 5069for the respective conversations. 5070To avoid failures of network error detection and path MTU discovery, 5071ICMP error messages may need to be allowed explicitly through static 5072rules. 5073.Pp 5074Rules using 5075.Cm call 5076and 5077.Cm return 5078actions may lead to confusing behaviour if ruleset has mistakes, 5079and/or interaction with other subsystems (netgraph, dummynet, etc.) is used. 5080One possible case for this is packet leaving 5081.Nm 5082in subroutine on the input pass, while later on output encountering unpaired 5083.Cm return 5084first. 5085As the call stack is kept intact after input pass, packet will suddenly 5086return to the rule number used on input pass, not on output one. 5087Order of processing should be checked carefully to avoid such mistakes. 5088