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