diff options
author | Kjell Wooding <kjell@cvs.openbsd.org> | 2000-04-13 19:59:41 +0000 |
---|---|---|
committer | Kjell Wooding <kjell@cvs.openbsd.org> | 2000-04-13 19:59:41 +0000 |
commit | 29ca409d8a88fde26ae9c2471dee0805149167e7 (patch) | |
tree | 57d39e9fc73135e0068eac34c4b350b947d85f63 /sbin | |
parent | fc4b41339fbe48c8df1836dc44888b911ade3d98 (diff) |
Long overdue documentation update for IPFilter. These
are taken directly from the ipf distribution, and are
not mandoc'ed. ipf(8), ipfstat(8), and ipnat(8) are yet
to go and must be done manually. (sigh)
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/ipf/ipf.4 | 244 | ||||
-rw-r--r-- | sbin/ipf/ipf.5 | 790 | ||||
-rw-r--r-- | sbin/ipnat/ipnat.4 | 214 | ||||
-rw-r--r-- | sbin/ipnat/ipnat.5 | 297 |
4 files changed, 674 insertions, 871 deletions
diff --git a/sbin/ipf/ipf.4 b/sbin/ipf/ipf.4 index 0d461cd9af8..26cb5b495ba 100644 --- a/sbin/ipf/ipf.4 +++ b/sbin/ipf/ipf.4 @@ -1,28 +1,28 @@ -.\" $OpenBSD: ipf.4,v 1.20 2000/03/16 00:36:38 aaron Exp $ -.Dd March 15, 2000 -.Dt IPF 4 -.Os -.Sh NAME -.Nm ipf -.Nd "packet filtering kernel interface" -.Sh SYNOPSIS -.Fd #include <netinet/ip_fil_compat.h> -.Fd #include <netinet/ip_fil.h> -.Sh DESCRIPTION -.Pp +.\" $OpenBSD: ipf.4,v 1.21 2000/04/13 19:59:39 kjell Exp $ +.\" +.TH IPF 4 +.SH NAME +ipf \- packet filtering kernel interface +.SH SYNOPSIS +#include <netinet/ip_compat.h> +.br +#include <netinet/ip_fil.h> +.SH IOCTLS +.PP To add and delete rules to the filter list, three 'basic' ioctls are provided -for use. -The ioctls are called as: -.Bd -literal -offset indent +for use. The ioctl's are called as: +.LP +.nf ioctl(fd, SIOCADDFR, struct frentry *) ioctl(fd, SIOCDELFR, struct frentry *) ioctl(fd, SIOCIPFFL, int *) -.Ed -.Pp +.fi +.PP However, the full complement is as follows: -.Bd -literal -offset indent - ioctl(fd, SIOCADAFR, struct frentry *) (same as SIOCADDFR) - ioctl(fd, SIOCRMAFR, struct frentry *) (same as SIOCDELFR) +.LP +.nf + ioctl(fd, SIOCADAFR, struct frentry *) (same as SUICADDFR) + ioctl(fd, SIOCRMAFR, struct frentry *) (same as SUICDELFR) ioctl(fd, SIOCADIFR, struct frentry *) ioctl(fd, SIOCRMIFR, struct frentry *) ioctl(fd, SIOCINAFR, struct frentry *) @@ -40,44 +40,37 @@ However, the full complement is as follows: ioctl(fd, SIOCAUTHW, struct fr_info *) ioctl(fd, SIOCAUTHR, struct fr_info *) ioctl(fd, SIOCATHST, struct fr_authstat *) -.Ed -.Pp -The variations, -.Dv SIOCADAFR -versus -.Dv SIOCADIFR , -allow operation on the two lists, -active and inactive, respectively. -All of these ioctls are implemented +.fi +.PP +The variations, SIOCADAFR vs. SIOCADIFR, allow operation on the two lists, +active and inactive, respectively. All of these ioctl's are implemented as being routing ioctls and thus the same rules for the various routing ioctls and the file descriptor are employed, mainly being that the fd must -be that of the device associated with the module (i.e., -.Pa /dev/ipl ) . -.Pp +be that of the device associated with the module (i.e., /dev/ipl). +.LP +.PP The three groups of ioctls above perform adding rules to the end of the list (SIOCAD*), deletion of rules from any place in the list (SIOCRM*) -and insertion of a rule into the list (SIOCIN*). -The rule place into -which it is inserted is stored in the -.Fa fr_hits -field, below. -.Bd -literal +and insertion of a rule into the list (SIOCIN*). The rule place into +which it is inserted is stored in the "fr_hits" field, below. +.LP +.nf typedef struct frentry { struct frentry *fr_next; u_short fr_group; /* group to which this rule belongs */ u_short fr_grhead; /* group # which this rule starts */ struct frentry *fr_grp; int fr_ref; /* reference count - for grouping */ - void *fr_ifa; + void *fr_ifa; #if BSD >= 199306 - void *fr_oifa; + void *fr_oifa; #endif /* - * These are only incremented when a packet matches this rule and + * These are only incremented when a packet matches this rule and * it is the last match */ - U_QUAD_T fr_hits; - U_QUAD_T fr_bytes; + U_QUAD_T fr_hits; + U_QUAD_T fr_bytes; /* * Fields after this may not change whilst in the kernel. */ @@ -91,10 +84,10 @@ typedef struct frentry { u_short fr_icmp; u_char fr_scmp; /* data for port comparisons */ - u_char fr_dcmp; + u_char fr_dcmp; u_short fr_dport; u_short fr_sport; - u_short fr_stop; /* top port for <> and >< */ + u_short fr_stop; /* top port for <> and >< */ u_short fr_dtop; /* top port for <> and >< */ u_32_t fr_flags; /* per-rule flags && options (see below) */ u_short fr_skip; /* # of rules to skip */ @@ -103,23 +96,22 @@ typedef struct frentry { char fr_icode; /* return ICMP code */ char fr_ifname[IFNAMSIZ]; #if BSD > 199306 - char fr_oifname[IFNAMSIZ]; -#endif + char fr_oifname[IFNAMSIZ]; +#endif struct frdest fr_tif; /* "to" interface */ struct frdest fr_dif; /* duplicate packet interfaces */ } frentry_t; -.Ed -.Pp +.fi +.PP When adding a new rule, all unused fields (in the filter rule) should be -initialized to be zero. -To insert a rule, at a particular position in the +initialised to be zero. To insert a rule, at a particular position in the filter list, the number of the rule which it is to be inserted before must -be put in the -.Fa fr_hits -field (the first rule is number 0). -.Pp -Flags which are recognized in fr_pass: -.Bd -literal +be put in the "fr_hits" field (the first rule is number 0). +.LP +.PP +Flags which are recognised in fr_pass: +.nf + FR_BLOCK 0x000001 /* do not allow packet to pass */ FR_PASS 0x000002 /* allow packet to pass */ FR_OUTQUE 0x000004 /* outgoing packets */ @@ -132,7 +124,7 @@ Flags which are recognized in fr_pass: FR_RETRST 0x000080 /* return a TCP RST packet if blocked */ FR_RETICMP 0x000100 /* return an ICMP packet if blocked */ FR_FAKEICMP 0x00180 /* Return ICMP unreachable with fake source */ - FR_NOMATCH 0x000200 /* no match occurred */ + FR_NOMATCH 0x000200 /* no match occured */ FR_ACCOUNT 0x000400 /* count packet bytes */ FR_KEEPFRAG 0x000800 /* keep fragment information */ FR_KEEPSTATE 0x001000 /* keep `connection' state information */ @@ -146,14 +138,13 @@ Flags which are recognized in fr_pass: FR_NOTDSTIP 0x100000 /* not the dst IP# */ FR_AUTH 0x200000 /* use authentication */ FR_PREAUTH 0x400000 /* require preauthentication */ -.Ed -.Pp -Values for -.Fa fr_scomp -and -.Fa fr_dcomp -(source and destination port value comparisons): -.Bd -literal + +.fi +.PP +Values for fr_scomp and fr_dcomp (source and destination port value +comparisons) : +.LP +.nf FR_NONE 0 FR_EQUAL 1 FR_NEQUAL 2 @@ -163,51 +154,39 @@ and FR_GREATERTE 6 FR_OUTRANGE 7 FR_INRANGE 8 -.Ed -.Pp -The third ioctl, -.Dv SIOCIPFFL , -flushes either the input filter list, the +.fi +.PP +The third ioctl, SIOCIPFFL, flushes either the input filter list, the output filter list or both and it returns the number of filters removed -from the list(s). -The values which it will take and recognize are -.Dv FR_INQUE -and -.Dv FR_OUTQUE -(see above). -This ioctl is also implemented for -.Pa /dev/ipstate -and will flush all state tables entries if passed 0 or just all those -which are not established if passed 1. -.Ss General logging flags -There are two flags which can be set to log packets independently of the -rules used. -These allow for packets which are either passed or blocked -to be logged. -To set (and clear) or get these flags, two ioctls are +from the list(s). The values which it will take and recognise are FR_INQUE +and FR_OUTQUE (see above). This ioctl is also implemented for +\fB/dev/ipstate\fP and will flush all state tables entries if passed 0 +or just all those which are not established if passed 1. + +.IP "\fBGeneral Logging Flags\fP" 0 +There are two flags which can be set to log packets independantly of the +rules used. These allow for packets which are either passed or blocked +to be logged. To set (and clear)/get these flags, two ioctls are provided: -.Bl -tag -width Ds -.It SIOCSETFF -Takes an unsigned integer as the parameter. -The flags are then set to +.IP SIOCSETFF 16 +Takes an unsigned integer as the parameter. The flags are then set to those provided (clearing/setting all in one). -.Bd -literal +.nf + FF_LOGPASS 0x10000000 FF_LOGBLOCK 0x20000000 FF_LOGNOMATCH 0x40000000 FF_BLOCKNONIP 0x80000000 /* Solaris 2.x only */ -.Ed -.Pp -.It SIOCGETFF -Takes a pointer to an unsigned integer as the parameter. -A copy of the flags currently in used is copied to user space. -.El -.Ss Filter statistics +.fi +.IP SIOCGETFF 16 +Takes a pointer to an unsigned integer as the parameter. A copy of the +flags currently in used is copied to user space. +.IP "\fBFilter statistics\fP" 0 Statistics on the various operations performed by this package on packets -is kept inside the kernel. -These statistics apply to packets traversing through the kernel. -To retrieve this structure, use this ioctl: -.Bd -literal +is kept inside the kernel. These statistics apply to packets traversing +through the kernel. To retrieve this structure, use this ioctl: +.nf + ioctl(fd, SIOCGETFS, struct friostat *) struct friostat { @@ -246,50 +225,33 @@ struct filterstats { #if SOLARIS u_long fr_notdata; /* PROTO/PCPROTO that have no data */ u_long fr_nodata; /* mblks that have no data */ - u_long fr_bad; /* bad IP packets to the filter */ + u_long fr_bad; /* bad IP packets to the filter */ u_long fr_notip; /* packets passed through no on ip queue */ u_long fr_drop; /* packets dropped - no info for them! */ #endif }; -.Ed -.Pp +.fi If we wanted to retrieve all the statistics and reset the counters back to -0, then the ioctl() call would be made to -.Dv SIOCFRZST -rather than -.Dv SIOCGETFS . +0, then the ioctl() call would be made to SIOCFRZST rather than SIOCGETFS. In addition to the statistics above, each rule keeps a hit count, counting -both number of packets and bytes. -To reset these counters for a rule, -load the various rule information into a -.Fa frentry -structure and call -.Dv SIOCZRLST . -.Ss Swapping active lists +both number of packets and bytes. To reset these counters for a rule, +load the various rule information into a frentry structure and call +SIOCZRLST. +.IP "Swapping Active lists" 0 IP Filter supports two lists of rules for filtering and accounting: an -active list and an inactive list. -This allows for large scale rule base +active list and an inactive list. This allows for large scale rule base changes to be put in place atomically with otherwise minimal interruption. -Which of the two is active can be changed using the -.Dv SIOCSWAPA -ioctl. -It is important to note that no passed argument is recognized and that the +Which of the two is active can be changed using the SIOCSWAPA ioctl. It +is important to note that no passed argument is recognised and that the value returned is that of the list which is now inactive. -.Sh FILES -.Bl -tag -width /dev/ipstate -compact -.It Pa /dev/ipauth -.It Pa /dev/ipl -.It Pa /dev/ipstate -.El -.Sh SEE ALSO -.Xr ipftest 1 , -.Xr ipl 4 , -.Xr ipnat 4 , -.Xr ipf 5 , -.Xr ipnat 5 , -.Xr ipf 8 , -.Xr ipfstat 8 , -.Xr ipmon 8 , -.Xr ipnat 8 -.Pp -http://coombs.anu.edu.au/~avalon +.br +.SH FILES +/dev/ipauth +.br +/dev/ipl +.br +/dev/ipnat +.br +/dev/ipstate +.SH SEE ALSO +ipl(4), ipnat(4), ipf(5), ipf(8), ipfstat(8) diff --git a/sbin/ipf/ipf.5 b/sbin/ipf/ipf.5 index 45f81398d1c..8692ea3794e 100644 --- a/sbin/ipf/ipf.5 +++ b/sbin/ipf/ipf.5 @@ -1,33 +1,25 @@ -.\" $OpenBSD: ipf.5,v 1.23 2000/04/12 21:47:58 aaron Exp $ -.Dd July 9, 1999 -.Dt IPF 5 -.Os -.Sh NAME -.Nm ipf -.Nd "IP packet filter rule syntax" -.Sh DESCRIPTION -A rule file for -.Nm -may have any name or even be stdin. -As -.Xr ipfstat 8 -produces parseable rules as output when displaying the internal +.\" $OpenBSD: ipf.5,v 1.24 2000/04/13 19:59:39 kjell Exp $ +.\" +.TH IPF 5 +.SH NAME +ipf, ipf.conf \- IP packet filter rule syntax +.SH DESCRIPTION +.PP +A rule file for \fBipf\fP may have any name or even be stdin. As +\fBipfstat\fP produces parseable rules as output when displaying the internal kernel filter lists, it is quite plausible to use its output to feed back -into -.Nm ipf . -Thus, to remove all filters on input packets, the following +into \fBipf\fP. Thus, to remove all filters on input packets, the following could be done: .nf -.Dl # ipfstat -i | ipf -rf - -.Pp -.Sh GRAMMAR -.Pp -The format used by -.Nm -for construction of filtering rules can be +\fC# ipfstat \-i | ipf \-rf \-\fP +.fi +.SH GRAMMAR +.PP +The format used by \fBipf\fP for construction of filtering rules can be described using the following grammar in BNF: -.Bd -literal +\fC +.nf filter-rule = [ insert ] action in-out [ options ] [ tos ] [ ttl ] [ proto ] [ ip ] [ group ]. @@ -82,7 +74,8 @@ icmp-type = "unreach" | "echo" | "echorep" | "squench" | "redir" | "inforep" | "maskreq" | "maskrep" | decnumber . icmp-code = decumber | "net-unr" | "host-unr" | "proto-unr" | "port-unr" | "needfrag" | "srcfail" | "net-unk" | "host-unk" | "isolate" | - "net-prohib" | "host-prohib" | "net-tos" | "host-tos" . + "net-prohib" | "host-prohib" | "net-tos" | "host-tos" | + "filter-prohib" | "host-preced" | "cutoff-preced" . optlist = "nop" | "rr" | "zsu" | "mtup" | "mtur" | "encode" | "ts" | "tr" | "sec" | "lsrr" | "e-sec" | "cipso" | "satid" | "ssrr" | "addext" | "visa" | "imitd" | "eip" | "finn" . @@ -91,7 +84,7 @@ facility = "kern" | "user" | "mail" | "daemon" | "auth" | "syslog" | "audit" | "logalert" | "local0" | "local1" | "local2" | "local3" | "local4" | "local5" | "local6" | "local7" . priority = "emerg" | "alert" | "crit" | "err" | "warn" | "notice" | - "info" | "debug" . + "info" | "debug" . hexnumber = "0" "x" hexstring . hexstring = hexdigit [ hexstring ] . @@ -103,578 +96,447 @@ range = "<>" | "><" . hexdigit = digit | "a" | "b" | "c" | "d" | "e" | "f" . digit = "0" | "1" | "2" | "3" | "4" | "5" | "6" | "7" | "8" | "9" . flag = "F" | "S" | "R" | "P" | "A" | "U" . -.Ed -.Pp +.fi +.PP This syntax is somewhat simplified for readability, some combinations that match this grammar are disallowed by the software because they do -not make sense (such as tcp -.Cm flags -for non-TCP packets). -.Sh FILTER RULES +not make sense (such as tcp \fBflags\fP for non-TCP packets). +.SH FILTER RULES +.PP The "briefest" valid rules are (currently) no-ops and are of the form: -.Bd -literal -offset indent -block in all -pass in all -log out all -count in all -.Ed -.Pp +.nf + block in all + pass in all + log out all + count in all +.fi +.PP Filter rules are checked in order, with the last matching rule -determining the fate of the packet (but see the -.Cm quick -option, below). -.Pp +determining the fate of the packet (but see the \fBquick\fP option, +below). +.PP Filters are installed by default at the end of the kernel's filter -lists, prepending the rule with -.Cm @n -will cause it to be inserted -as the n'th entry in the current list. -This is especially useful when -modifying and testing active filter rulesets. -.Sh ACTIONS +lists, prepending the rule with \fB@n\fP will cause it to be inserted +as the n'th entry in the current list. This is especially useful when +modifying and testing active filter rulesets. See ipf(1) for more +information. +.SH ACTIONS +.PP The action indicates what to do with the packet if it matches the rest -of the filter rule. -Each rule -.Em must -have an action. -The following actions are recognized: -.Pp -.Bl -tag -width XXXXXXXX -offset indent -.It block -indicates that the packet should be flagged to be dropped. -In response +of the filter rule. Each rule MUST have an action. The following +actions are recognised: +.TP +.B block +indicates that the packet should be flagged to be dropped. In response to blocking a packet, the filter may be instructed to send a reply -packet, either an ICMP packet -.Pq Cm return-icmp , -an ICMP packet masquerading as being from the original packet's destination ( -.Pq Cm return-icmp-as-dest , -or a TCP reset -.Pq Cm return-rst . -An ICMP packet may be generated in response to -any IP packet, and its type may optionally be specified, but a TCP -reset may only be used with a rule which is being applied to TCP -packets. -When using -.Cm return-icmp -or -.Cm return-icmp-as-dest , -it is possible to specify the actual unreachable `type'. -That is, whether -it is a network unreachable, port unreachable or even administratively -prohibited. -This is done by enclosing the ICMP code associated with it -in parenthesis directly following -.Cm return-icmp -or -.Cm return-icmp-as-dest -as follows: -.Bd -literal -offset indent -block return-icmp(11) ... -.Ed -.Pp -would return a Type-Of-Service (TOS) ICMP unreachable error. -.It pass -will flag the packet to be let through the filter. -.It log +packet, either an ICMP packet (\fBreturn-icmp\fP), an ICMP packet +masquerading as being from the original packet's destination +(\fBreturn-icmp-as-dest\fP), or a TCP "reset" (\fBreturn-rst\fP). An +ICMP packet may be generated in response to any IP packet, and its +type may optionally be specified, but a TCP reset may only be used +with a rule which is being applied to TCP packets. When using +\fBreturn-icmp\fP or \fBreturn-icmp-as-dest\fP, it is possible to specify +the actual unreachable `type'. That is, whether it is a network +unreachable, port unreachable or even administratively +prohibitied. This is done by enclosing the ICMP code associated with +it in parenthesis directly following \fBreturn-icmp\fP or +\fBreturn-icmp-as-dest\fP as follows: +.nf + block return-icmp(11) ... +.fi +.PP +Would return a Type-Of-Service (TOS) ICMP unreachable error. +.TP +.B pass +will flag the packet to be let through the filter. +.TP +.B log causes the packet to be logged (as described in the LOGGING section below) and has no effect on whether the packet will be allowed through the filter. -.It count +.TP +.B count causes the packet to be included in the accounting statistics kept by the filter, and has no effect on whether the packet will be allowed through -the filter. -These statistics are viewable with -.Xr ipfstat 8 . -.It call +the filter. These statistics are viewable with ipfstat(8). +.TP +.B call this action is used to invoke the named function in the kernel, which -must conform to a specific calling interface. -Customized actions and -semantics can thus be implemented to supplement those available. -This feature is for use by knowledgeable hackers, and is not currently +must conform to a specific calling interface. Customised actions and +semantics can thus be implemented to supplement those available. This +feature is for use by knowledgeable hackers, and is not currently documented. -.It "skip <n>" -causes the filter to skip over the next -.Cm n -filter rules. -If a rule is inserted or deleted inside the region being -skipped over, then the value of -.Cm n -is adjusted appropriately. -.It auth +.TP +.B "skip <n>" +causes the filter to skip over the next \fIn\fP filter rules. If a rule is +inserted or deleted inside the region being skipped over, then the value of +\fIn\fP is adjusted appropriately. +.TP +.B auth this allows authentication to be performed by a user-space program running -and waiting for packet information to validate. -The packet is held for a +and waiting for packet information to validate. The packet is held for a period of time in an internal buffer whilst it waits for the program to return -to the kernel the -.Em real -flags for whether it should be allowed through -or not. -Such a program might look at the source address and request some sort +to the kernel the \fIreal\fP flags for whether it should be allowed through +or not. Such a program might look at the source address and request some sort of authentication from the user (such as a password) before allowing the packet through or telling the kernel to drop it if from an unrecognised source. -.It preauth +.TP +.B preauth tells the filter that for packets of this class, it should look in the -pre-authenticated list for further clarification. -If no further matching +pre-authenticated list for further clarification. If no further matching rule is found, the packet will be dropped (the FR_PREAUTH is not the same -as FR_PASS). -If a further matching rule is found, the result from that is -used in its instead. -This might be used in a situation where a person -.Em logs in -to the firewall and it sets up some temporary rules defining +as FR_PASS). If a further matching rule is found, the result from that is +used in its instead. This might be used in a situation where a person +\fIlogs in\fP to the firewall and it sets up some temporary rules defining the access for that person. -.El -.Pp -The next word must be either -.Cm in -or -.Cm out . -Each packet moving through the kernel is either inbound (just been received -on an interface, and moving towards the kernel's protocol processing) or +.PP +The next word must be either \fBin\fP or \fBout\fP. Each packet +moving through the kernel is either inbound (just been received on an +interface, and moving towards the kernel's protocol processing) or outbound (transmitted or forwarded by the stack, and on its way to an -interface). -There is a requirement that each filter rule explicitly +interface). There is a requirement that each filter rule explicitly state which side of the I/O it is to be used on. -.Sh OPTIONS -The list of options is brief, and all are indeed optional. -Where options are used, they must be present in the order shown here. -These are the currently supported options: -.Pp -.Bl -tag -width dup-to -offset indent -.It log +.SH OPTIONS +.PP +The list of options is brief, and all are indeed optional. Where +options are used, they must be present in the order shown here. These +are the currently supported options: +.TP +.B log indicates that, should this be the last matching rule, the packet -header will be written to the -.Pa ipl -log (as described in the LOGGING section below). -.It quick +header will be written to the \fBipl\fP log (as described in the +LOGGING section below). +.TP +.B quick allows "short-cut" rules in order to speed up the filter or override -later rules. -If a packet matches a filter rule which is marked as -.Cm quick , -this rule will be the last rule checked, allowing a +later rules. If a packet matches a filter rule which is marked as +\fBquick\fP, this rule will be the last rule checked, allowing a "short-circuit" path to avoid processing later rules for this -packet. -The current status of the packet (after any effects of the +packet. The current status of the packet (after any effects of the current rule) will determine whether it is passed or blocked. -.Pp +.IP If this option is missing, the rule is taken to be a "fall-through" rule, meaning that the result of the match (block/pass) is saved and that processing will continue to see if there are any more matches. -.It on +.TP +.B on allows an interface name to be incorporated into the matching -procedure. -Interface names are as printed by -.Ic "netstat -i" . -If this option is used, the rule will only match if the packet is going -through that interface in the specified direction (in/out). -If this option is absent, the rule is taken to be applied to a packet -regardless of the interface it is present on (i.e., on all interfaces). +procedure. Interface names are as printed by "netstat \-i". If this +option is used, the rule will only match if the packet is going +through that interface in the specified direction (in/out). If this +option is absent, the rule is taken to be applied to a packet +regardless of the interface it is present on (i.e. on all interfaces). Filter rulesets are common to all interfaces, rather than having a filter list for each interface. -.Pp +.IP This option is especially useful for simple IP-spoofing protection: packets should only be allowed to pass inbound on the interface from which the specified source address would be expected, others may be logged and/or dropped. -.It dup-to +.TP +.B dup-to causes the packet to be copied, and the duplicate packet to be sent outbound on the specified interface, optionally with the destination -IP address changed to that specified. -This is useful for off-host logging, using a network sniffer. -.It to +IP address changed to that specified. This is useful for off-host +logging, using a network sniffer. +.TP +.B to causes the packet to be moved to the outbound queue on the -specified interface. -This can be used to circumvent kernel routing +specified interface. This can be used to circumvent kernel routing decisions, and even to bypass the rest of the kernel processing of the -packet (if applied to an inbound rule). -It is thus possible to +packet (if applied to an inbound rule). It is thus possible to construct a firewall that behaves transparently, like a filtering hub -or switch, rather than a router. -The -.Cm fastroute -keyword is a synonym for this option. -.Sh MATCHING PARAMETERS +or switch, rather than a router. The \fBfastroute\fP keyword is a +synonym for this option. +.SH MATCHING PARAMETERS +.PP The keywords described in this section are used to describe attributes of the packet to be used when determining whether rules match or don't -match. -The following general-purpose attributes are provided for +match. The following general-purpose attributes are provided for matching, and must be used in this order: -.Pp -.Bl -tag -width XXXXXXX -offset indent -.It tos +.TP +.B tos packets with different Type-Of-Service values can be filtered. -Individual service levels or combinations can be filtered upon. -The value for the TOS mask can either be represented as a hex number or a +Individual service levels or combinations can be filtered upon. The +value for the TOS mask can either be represented as a hex number or a decimal integer value. -.It ttl -packets may also be selected by their Time-To-Live value. -The value given in +.TP +.B ttl +packets may also be selected by their Time-To-Live value. The value given in the filter rule must exactly match that in the packet for a match to occur. This value can only be given as a decimal integer value. -.It proto -allows a specific protocol to be matched against. -All protocol names found in -.Pn /etc/protocols -are recognized and may be used. +.TP +.B proto +allows a specific protocol to be matched against. All protocol names +found in \fB/etc/protocols\fP are recognised and may be used. However, the protocol may also be given as a DECIMAL number, allowing for rules to match your own protocols, or new ones which would out-date any attempted listing. -.Pp -The special protocol keyword -.Cm tcp/udp -may be used to match either +.IP +The special protocol keyword \fBtcp/udp\fP may be used to match either a TCP or a UDP packet, and has been added as a convenience to save duplication of otherwise-identical rules. .\" XXX grammar should reflect this (/etc/protocols) -.El -.Pp -The -.Cm from -and -.Cm to -keywords are used to match against IP -addresses (and optionally port numbers). -Rules must specify -.Em both +.PP +The \fBfrom\fP and \fBto\fP keywords are used to match against IP +addresses (and optionally port numbers). Rules must specify BOTH source and destination parameters. -.Pp +.PP IP addresses may be specified in one of two ways: as a numerical -address/mask, or as a hostname -.Cm mask -netmask. -The hostname +address\fB/\fPmask, or as a hostname \fBmask\fP netmask. The hostname may either be a valid hostname, from either the hosts file or DNS -(depending on your configuration and library), an interface name -(in the case of IP address aliases, only the first IP address is used) -or of the dotted numeric -form. -There is no special designation for networks but network names -are recognized. -Note that having your filter rules depend on DNS -results can introduce an avenue of attack, and is -.Em highly -discouraged. -.Pp -There is a special case for the hostname -.Cm any -which is taken to +(depending on your configuration and library) or of the dotted numeric +form. There is no special designation for networks but network names +are recognised. Note that having your filter rules depend on DNS +results can introduce an avenue of attack, and is discouraged. +.PP +There is a special case for the hostname \fBany\fP which is taken to be 0.0.0.0/0 (see below for mask syntax) and matches all IP addresses. Only the presence of "any" has an implied mask, in all other -situations, a hostname MUST be accompanied by a mask. -It is possible +situations, a hostname MUST be accompanied by a mask. It is possible to give "any" a hostmask, but in the context of this language, it is non-sensical. -.Pp -The numerical format "x/y" indicates that a mask of y +.PP +The numerical format "x\fB/\fPy" indicates that a mask of y consecutive 1 bits set is generated, starting with the MSB, so a y value -of 16 would give 0xffff0000. -The symbolic "x mask y" indicates +of 16 would give 0xffff0000. The symbolic "x \fBmask\fP y" indicates that the mask y is in dotted IP notation or a hexadecimal number of -the form 0x12345678. -Note that all the bits of the IP address +the form 0x12345678. Note that all the bits of the IP address indicated by the bitmask must match the address on the packet exactly; there isn't currently a way to invert the sense of the match, or to match ranges of IP addresses which do not express themselves easily as bitmasks (anthropomorphization; it's not just for breakfast anymore). -.Pp -If a -.Cm port -match is included, for either or both of source and +.PP +If a \fBport\fP match is included, for either or both of source and destination, then it is only applied to .\" XXX - "may only be" ? how does this apply to other protocols? will it not match, or will it be ignored? -TCP and UDP packets. -If there is no -.Cm proto -match parameter, -packets from both protocols are compared. -This is equivalent to "proto tcp/udp". -When composing -.Cm port -comparisons, either the service -name or an integer port number may be used. -Port comparisons may be +TCP and UDP packets. If there is no \fBproto\fP match parameter, +packets from both protocols are compared. This is equivalent to "proto +tcp/udp". When composing \fBport\fP comparisons, either the service +name or an integer port number may be used. Port comparisons may be done in a number of forms, with a number of comparison operators, or -port ranges may be specified. -When the port appears as part of the -.Cm from -object, it matches the source port number, when it appears -as part of the -.Cm to -object, it matches the destination port number. +port ranges may be specified. When the port appears as part of the +\fBfrom\fP object, it matches the source port number, when it appears +as part of the \fBto\fP object, it matches the destination port number. See the examples for more information. -.Pp -The -.Cm all -keyword is essentially a synonym for "from any to any" +.PP +The \fBall\fP keyword is essentially a synonym for "from any to any" with no other match parameters. -.Pp +.PP Following the source and destination matching parameters, the following additional parameters may be used: -.Bl -tag -width XXXXXXX -offset indent -.It with +.TP +.B with is used to match irregular attributes that some packets may have -associated with them. -To match the presence of IP options in general, use -.Cm "with ipopts" . -To match packets that are too short to contain -a complete header, use -.Cm "with short" . -To match fragmented packets, -.Cm "with frag" . -For more specific filtering on IP options, +associated with them. To match the presence of IP options in general, +use \fBwith ipopts\fP. To match packets that are too short to contain +a complete header, use \fBwith short\fP. To match fragmented packets, +use \fBwith frag\fP. For more specific filtering on IP options, individual options can be listed. -.Pp -Before any parameter used after the -.Cm with -keyword, the word -.Cm not -or -.Cm no -may be inserted to cause the filter rule to only +.IP +Before any parameter used after the \fBwith\fP keyword, the word +\fBnot\fP or \fBno\fP may be inserted to cause the filter rule to only match if the option(s) is not present. -.Pp -Multiple consecutive -.Cm with -clauses are allowed. -Alternatively, the keyword -.Cm and -may be used in place of -.Cm with , -this is +.IP +Multiple consecutive \fBwith\fP clauses are allowed. Alternatively, +the keyword \fBand\fP may be used in place of \fBwith\fP, this is provided purely to make the rules more readable ("with ... and ..."). When multiple clauses are listed, all those must match to cause a match of the rule. .\" XXX describe the options more specifically in a separate section -.It flags -is only effective for TCP filtering. -Each of the letters possible +.TP +.B flags +is only effective for TCP filtering. Each of the letters possible represents one of the possible flags that can be set in the TCP -header. -The association is as follows: -.Bd -literal +header. The association is as follows: +.LP +.nf F - FIN S - SYN R - RST P - PUSH A - ACK U - URG -.Ed -.Pp +.fi +.IP The various flag symbols may be used in combination, so that "SA" -would represent a SYN-ACK combination present in a packet. -There is +would represent a SYN-ACK combination present in a packet. There is nothing preventing the specification of combinations, such as "SFR", that would not normally be generated by law-abiding TCP -implementations. -However, to guard against weird aberrations, it is -necessary to state which flags you are filtering against. -To allow +implementations. However, to guard against weird aberrations, it is +necessary to state which flags you are filtering against. To allow this, it is possible to set a mask indicating which TCP flags you wish -to compare (i.e., those you deem significant). -This is done by +to compare (i.e., those you deem significant). This is done by appending "/<flags>" to the set of TCP flags you wish to match against, e.g.: -.Bd -literal - ... flags S - # becomes "flags S/AUPRFS" and - # will match packets with ONLY - # the SYN flag set. +.LP +.nf + ... flags S + # becomes "flags S/AUPRFS" and will match + # packets with ONLY the SYN flag set. - ... flags SA - # becomes "flags SA/AUPRFS" and will match - # any packet with only the SYN and ACK - # flags set. + ... flags SA + # becomes "flags SA/AUPRFS" and will match any + # packet with only the SYN and ACK flags set. - ... flags S/SA - # will match any packet with just the SYN - # flag set out of the SYN-ACK pair; the - # common "establish" keyword action. - # "S/SA" will NOT match a packet with BOTH - # SYN and ACK set, but WILL match "SFP". -.Ed -.It icmp-type + ... flags S/SA + # will match any packet with just the SYN flag set + # out of the SYN-ACK pair; the common "establish" + # keyword action. "S/SA" will NOT match a packet + # with BOTH SYN and ACK set, but WILL match "SFP". +.fi +.TP +.B icmp-type is only effective when used with \fBproto icmp\fP and must NOT be used -in conjunction with \fBflags\fP. -There are a number of types, which can be -referred to by an abbreviation recognized by this language, or the numbers -with which they are associated can be used. -The most important from a security point of view is the ICMP redirect. -.El -.Sh KEEP HISTORY -The second last parameter that can be set for a filter rule is whether or not -to record historical information for that packet, and what sort to keep. -The following information can be kept: -.Pp -.Bl -tag -width XXXXXXX -offset indent -.It state -keeps information about the flow of a communication session. -State can be kept for TCP, UDP, and ICMP packets. -.It frags +in conjuction with \fBflags\fP. There are a number of types, which can be +referred to by an abbreviation recognised by this language, or the numbers +with which they are associated can be used. The most important from +a security point of view is the ICMP redirect. +.SH KEEP HISTORY +.PP +The second last parameter which can be set for a filter rule is whether or not +to record historical information for that packet, and what sort to keep. The +following information can be kept: +.TP +.B state +keeps information about the flow of a communication session. State can +be kept for TCP, UDP, and ICMP packets. +.TP +.B frags keeps information on fragmented packets, to be applied to later fragments. -.El -.Pp +.PP allowing packets which match these to flow straight through, rather than going through the access control list. -.Sh GROUPS -The last pair of parameters control filter rule "grouping". -By default, all -filter rules are placed in group 0 if no other group is specified. -To add a +.SH GROUPS +The last pair of parameters control filter rule "grouping". By default, all +filter rules are placed in group 0 if no other group is specified. To add a rule to a non-default group, the group must first be started by creating a -group -.Cm head . -If a packet matches a rule which is the -.Cm head -of a group, the filter processing then switches to the group, using -that rule as the default for the group. -If -.Cm quick -is used with a -.Cm head -rule, rule processing isn't stopped until it has returned from processing -the group. -.Pp +group \fIhead\fP. If a packet matches a rule which is the \fIhead\fP of a +group, the filter processing then switches to the group, using that rule as +the default for the group. If \fBquick\fP is used with a \fBhead\fP rule, rule +processing isn't stopped until it has returned from processing the group. +.PP A rule may be both the head for a new group and a member of a non-default -group -.Pf ( Cm head -and -.Cm group -may be used together in a rule). -.Pp -There may be only one -.Cm head -rule per -.Cm group. -.Bl -tag -width XXXXXXXXX -offset indent -.It "head <n>" +group (\fBhead\fP and \fBgroup\fP may be used together in a rule). +.TP +.B "head <n>" indicates that a new group (number n) should be created. -.It "group <n>" +.TP +.B "group <n>" indicates that the rule should be put in group (number n) rather than group 0. -.El -.Sh LOGGING +.SH LOGGING +.PP When a packet is logged, with either the \fBlog\fP action or option, the headers of the packet are written to the \fBipl\fP packet logging -pseudo-device. -Immediately following the \fBlog\fP keyword, the +psuedo-device. Immediately following the \fBlog\fP keyword, the following qualifiers may be used (in order): -.Bl -tag -width XXXXXXXX -offset indent -.It body +.TP +.B body indicates that the first 128 bytes of the packet contents will be -logged after the headers. -.It first -If log is being used in conjunction with a -.Cm keep -option, it is recommended that this option is also applied so that only -the triggering packet is logged and not every packet which thereafter -matches state information. -.It or-block +logged after the headers. +.TP +.B first +If log is being used in conjunction with a "keep" option, it is recommended +that this option is also applied so that only the triggering packet is logged +and not every packet which thereafter matches state information. +.TP +.B or-block indicates that, if for some reason the filter is unable to log the packet (such as the log reader being too slow) then the rule should be -interpreted as if the action was -.Cm block -for this packet. -.It "level <loglevel>" -indicates the logging facility and priority that will be used to log -information about this packet using -.Xr ipmon 8 's -.Fl s -option. -If no facility is specified, the default facility is assumed. -.El -.Pp -See -.Xr ipl 4 -for the format of records written -to this device. -The -.Xr ipmon 8 -program can be used to read and format this log. -.Sh EXAMPLES +interpreted as if the action was \fBblock\fP for this packet. +.TP +.B "level <loglevel>" +indicates what logging facility and priority, or just priority with +the default facility being used, will be used to log information about +this packet using ipmon's -s option. +.PP +See ipl(4) for the format of records written +to this device. The ipmon(8) program can be used to read and format +this log. +.SH EXAMPLES +.PP The \fBquick\fP option is good for rules such as: -.Pp -.Dl block in quick from any to any with ipopts -.Pp +\fC +.nf +block in quick from any to any with ipopts +.fi +.PP which will match any packet with a non-standard header length (IP options present) and abort further processing of later rules, recording a match and also that the packet should be blocked. -.Pp +.PP The "fall-through" rule parsing allows for effects such as this: -.Bd -literal +.LP +.nf block in from any to any port < 6000 pass in from any to any port >= 6000 block in from any to any port > 6003 -.Ed -.Pp +.fi +.PP which sets up the range 6000-6003 as being permitted and all others being -denied. -Note that the effect of the first rule is overridden by subsequent rules. -Another (easier) way to do the same is: -.Bd -literal +denied. Note that the effect of the first rule is overridden by subsequent +rules. Another (easier) way to do the same is: +.LP +.nf block in from any to any port 6000 <> 6003 pass in from any to any port 5999 >< 6004 -.Ed -.Pp +.fi +.PP Note that both the "block" and "pass" are needed here to effect a result as a failed match on the "block" action does not imply a pass, -only that the rule hasn't taken effect. -To then allow ports < 1024, a rule such as: -.Pp -.Dl pass in quick from any to any port < 1024 -.Pp -would be needed before the first block. -To create a new group for +only that the rule hasn't taken effect. To then allow ports < 1024, a +rule such as: +.LP +.nf + pass in quick from any to any port < 1024 +.fi +.PP +would be needed before the first block. To create a new group for processing all inbound packets on le0/le1/lo0, with the default being to block all inbound packets, we would do something like: -.Bd -literal +.LP +.nf block in all block in quick on le0 all head 100 block in quick on le1 all head 200 block in quick on lo0 all head 300 -.Ed -.Pp +.fi +.PP + and to then allow ICMP packets in on le0, only, we would do: -.Pp -.Dl pass in proto icmp all group 100 -.Pp +.LP +.nf + pass in proto icmp all group 100 +.fi +.PP Note that because only inbound packets on le0 are used processed by group 100, -there is no need to respecify the interface name. -Likewise, we could further breakup processing of TCP, etc, as follows: -.Bd -literal +there is no need to respecify the interface name. Likewise, we could further +breakup processing of TCP, etc, as follows: +.LP +.nf block in proto tcp all head 110 group 100 pass in from any to any port = 23 group 110 -.Ed -.Pp -and so on. -The last line, if written without the groups would be: -.Pp -.Dl pass in on le0 proto tcp from any to any port = telnet -.Pp +.fi +.PP +and so on. The last line, if written without the groups would be: +.LP +.nf + pass in on le0 proto tcp from any to any port = telnet +.fi +.PP Note, that if we wanted to say "port = telnet", "proto tcp" would need to be specified as the parser interprets each rule on its own and qualifies all service/port names with the protocol specified. -.Sh FILES -.Bl -tag -width /usr/share/ipf -compact -.It /etc/services -port names -.It /etc/hosts -host names -.It /usr/share/ipf -sample configuration files -.It /dev/ipauth -.It /dev/ipl -.It /dev/ipstate -.El -.Sh SEE ALSO -.Xr ipftest 1 , -.Xr ipf 4 , -.Xr ipl 4 , -.Xr ipnat 4 , -.Xr hosts 5 , -.Xr ipnat 5 , -.Xr services 5 , -.Xr ipf 8 , -.Xr ipfstat 8 , -.Xr ipmon 8 , -.Xr ipnat 8 +.SH FILES +/dev/ipauth +.br +/dev/ipl +.br +/dev/ipstate +.br +/etc/hosts +.br +/etc/services +.SH SEE ALSO +ipftest(1), iptest(1), mkfilters(1), ipf(4), ipnat(5), ipf(8), ipfstat(8) diff --git a/sbin/ipnat/ipnat.4 b/sbin/ipnat/ipnat.4 index 07bf5989957..92471c57788 100644 --- a/sbin/ipnat/ipnat.4 +++ b/sbin/ipnat/ipnat.4 @@ -1,126 +1,98 @@ -.\" $OpenBSD: ipnat.4,v 1.18 2000/03/18 22:55:58 aaron Exp $ -.Dd June 5, 1999 -.Dt IPNAT 4 -.Os -.Sh NAME -.Nm ipnat -.Nd Network Address Translation kernel interface -.Sh SYNOPSIS -.Fd #include <netinet/ip_fil_compat.h> -.Fd #include <netinet/ip_fil.h> -.Fd #include <netinets/ip_proxy.h> -.Fd #include <netinet/ip_nat.h> -.Sh DESCRIPTION -Unlike -.Xr ipf 4 , -only a single list is supported by the kernel NAT -interface. -An inactive list which can be swapped to is not currently supported. -.Pp -.Pp -To add/delete rules to/from the NAT list, two -.Dq basic -ioctl's are provided: -.Bd -literal -offset indent -.Fn ioctl fd SIOCADNAT "struct ipnat *" -.Fn ioctl fd SIOCRMNAT "struct ipnat *" -.Ed -.Pp -To retrieve NAT statistics -.Bd -literal -offset indent -.Fn ioctl fd SIOCGNATS "struct natstat *" -.Ed -.Pp -is provided. -.Pp -These ioctl's are implemented as routing ioctl's, so the rules -for routing ioctl's and the file descriptor -.Ar fd -must be followed. -The most important rule is that the file descriptor -.Fa fd -must be for the device associated with the module (i.e., -.Pa /dev/ipl ) . -.Pp -The structure -.Fa ipnat -and associated macros are defined as: -.Bd -literal -offset indent -typedef struct ipnat { - struct ipnat *in_next; - void *in_ifp; - void *in_apr; - u_int in_space; - u_int in_use; - struct in_addr in_nextip; - u_short in_pnext; - u_short in_flags; - u_short in_port[2]; - struct in_addr in_in[2]; - struct in_addr in_out[2]; - int in_redir; - char in_ifname[IFNAMSIZ]; - char in_plabel[APR_LABELLEN]; - char in_p; - u_short in_dport; +.\" $OpenBSD: ipnat.4,v 1.19 2000/04/13 19:59:39 kjell Exp $ +.\" +.TH IPNAT 4 +.SH NAME +ipnat \- Network Address Translation kernel interface +.SH SYNOPSIS +#include <netinet/ip_compat.h> +.br +#include <netinet/ip_fil.h> +.br +#include <netinet/ip_proxy.h> +.br +#include <netinet/ip_nat.h> +.SH IOCTLS +.PP +To add and delete rules to the NAT list, two 'basic' ioctls are provided +for use. The ioctl's are called as: +.LP +.nf + ioctl(fd, SIOCADNAT, struct ipnat *) + ioctl(fd, SIOCRMNAT, struct ipnat *) +.fi +.PP +Unlike \fBipf(4)\fP, there is only a single list supported by the kernel NAT +interface. An inactive list which can be swapped to is not currently +supported. + +These ioctl's are implemented as being routing ioctls and thus the same rules +for the various routing ioctls and the file descriptor are employed, mainly +being that the fd must be that of the device associated with the module +(i.e., /dev/ipl). +.LP +.PP +The strcture used with the NAT interface is described below: +.LP +.nf +typedef struct ipnat { + struct ipnat *in_next; + void *in_ifp; + u_short in_flags; + u_short in_pnext; + u_short in_port[2]; + struct in_addr in_in[2]; + struct in_addr in_out[2]; + struct in_addr in_nextip; + int in_space; + int in_redir; /* 0 if it's a mapping, 1 if it's a hard redir */ + char in_ifname[IFNAMSIZ]; } ipnat_t; -#define in_pmin in_port[0] -#define in_pmax in_port[1] -#define in_nip in_nextip.s_addr -#define in_inip in_in[0].s_addr -#define in_inmsk in_in[1].s_addr -#define in_outip in_out[0].s_addr -#define in_outmsk in_out[1].s_addr -.Ed -.Pp -Where recognised values for -.Fa in_redir -are: -.Bd -literal -offset indent -#define NAT_MAP 0x01 -#define NAT_REDIRECT 0x02 -#define NAT_BIMAP (NAT_MAP|NAT_REDIRECT) -.Ed -.Pp -The structure -.Fa natstat -is defined as: -.Bd -literal -offset indent -typedef struct natstat { - u_long ns_mapped[2]; - u_long ns_rules; - u_long ns_added; - u_long ns_expire; - u_long ns_inuse; - u_long ns_logged; - u_long ns_logfail; - nat_t **ns_table[2]; - ipnat_t *ns_list; - void *ns_apslist; +#define in_pmin in_port[0] /* Also holds static redir port */ +#define in_pmax in_port[1] +#define in_nip in_nextip.s_addr +#define in_inip in_in[0].s_addr +#define in_inmsk in_in[1].s_addr +#define in_outip in_out[0].s_addr +#define in_outmsk in_out[1].s_addr + +.fi +.PP +Recognised values for in_redir: +.LP +.nf +#define NAT_MAP 0 +#define NAT_REDIRECT 1 +.fi +.PP +.LP +\fBNAT statistics\fP +Statistics on the number of packets mapped, going in and out are kept, +the number of times a new entry is added and deleted (through expiration) to +the NAT table and the current usage level of the NAT table. +.PP +Pointers to the NAT table inside the kernel, as well as to the top of the +internal NAT lists constructed with the \fBSIOCADNAT\fP ioctls. The table +itself is a hash table of size NAT_SIZE (default size is 367). +.PP +To retrieve the statistics, the \fBSIOCGNATS\fP ioctl must be used, with +the appropriate structure passed by reference, as follows: +.nf + ioctl(fd, SIOCGNATS, struct natstat *) + +typedef struct natstat { + u_long ns_mapped[2]; + u_long ns_added; + u_long ns_expire; + u_long ns_inuse; + nat_t ***ns_table; + ipnat_t *ns_list; } natstat_t; -.Ed -.Pp -The NAT kernel tables are hash tables of size -.Dv NAT_SIZE -(default is 367). -.Sh FILES -.Bl -tag -width /dev/ipnat -compact -.It Pa /dev/ipnat -.El -.Sh SEE ALSO -.Xr ipf 8 , -.Xr ipftest 1 , -.Xr ipf 4 , -.Xr ipl 4 , -.Xr ipf 5 , -.Xr ipnat 5 , -.Xr ipnat 8 , -.Xr ipfstat 8 , -.Xr ipmon 8 -.Pp -http://coombs.anu.edu.au/~avalon -.Sh BUGS +.fi +.SH BUGS It would be nice if there were more flexibility when adding and deleting filter rules. - +.SH FILES +/dev/ipnat +.SH SEE ALSO +ipf(4), ipnat(5), ipf(8), ipnat(8), ipfstat(8) diff --git a/sbin/ipnat/ipnat.5 b/sbin/ipnat/ipnat.5 index 61e2878d280..48cd0da1993 100644 --- a/sbin/ipnat/ipnat.5 +++ b/sbin/ipnat/ipnat.5 @@ -1,153 +1,160 @@ -.\" $OpenBSD: ipnat.5,v 1.13 2000/03/18 22:55:59 aaron Exp $ -.Dd June 5, 1999 -.Dt IPNAT 5 -.Os -.Sh NAME -.Nm ipnat -.Nd IP NAT file format -.Sh DESCRIPTION -Files processed by -.Xr ipnat 8 -are normal text files containing either a valid NAT rule or a comment on each -non-blank line. -Comment lines begin with a -.Ql # -and are ignored, as are blank lines. -Valid NAT rules are described by the following grammar: -.Bd -literal -offset indent -natrule ::= maprule | rdrrule | bimaprule +.\" $OpenBSD: ipnat.5,v 1.14 2000/04/13 19:59:39 kjell Exp $ +.\" +.TH IPNAT 5 +.SH NAME +ipnat, ipnat.conf \- IP NAT file format +.SH DESCRIPTION +The format for files accepted by ipnat is described by the following grammar: +.LP +.nf +ipmap :: = mapblock | redir | map . -maprule ::= "map" ifname source "->" destination [mapoption] -rdrrule ::= "rdr" ifname destination port "->" target -bimaprule ::= "bimap" ifname source "->" destination +map ::= mapit ifname ipmask "->" ipmask [ mapport ] . +mapblock ::= "map-block" ifname ipmask "->" ipmask [ ports ] . +redir ::= "rdr" ifname [ fromspec ] ipmask "->" ip [ ports ] [ tcpudp ] . +ports ::= "ports" numports | "auto" . +mapit ::= "map" | "bimap" . +ipmask ::= ip "/" bits | ip "/" mask | ip "netmask" mask . +mapport ::= "portmap" tcpudp portnumber ":" portnumber . -source ::= destination -destination ::= host "/" mask -target ::= host "port" port porttype +fromspec ::= "from" ip "/" ipmask . +tcpudp ::= "tcp" | "udp" | "tcp/udp" . +portnumber ::= number { numbers } | "auto" . +ifname ::= 'A' - 'Z' { 'A' - 'Z' } numbers . -portrange ::= port ":" port -portmap ::= "portmap" porttype portrange -proxy ::= "proxy port" port [ "/" protocol ] -mapoption ::= proxy | portmap - -porttype ::= "tcp" | "udp" | "tcpudp" | "tcp/udp" - -protocol ::= <name from /etc/protocols> | <# from /etc/protocols> -port ::= <unsigned 16 bit value> | <name from /etc/services> -host ::= 'any' | <IP addr> | <interface name> | <host name> -mask ::= <non-numeric> | <IP addr> | <hex value> | <bit count> -ifname ::= <interface name> -.Ed -.Pp -Elements in a rule are usually separated by whitespace (blanks or tabs). -In the case of the -.Ql \&/ -in -.Fa host -rule or the -.Ql \&: -in the -.Fa portrange -rule, there must be no whitespace before or after it. -In the case of the -.Ql \&/ -in the -.Fa proxy -rule there must be whitespace before but no whitespace after. -.Pp -In the -.Fa host -and -.Fa mask -rules, the alternatives are evaluated in the order given. -.Pp -For the -.Fa mask -rule, if the element begins with a non-digit the mask is taken to be all zeros. -A -.Ql \&. -in the element causes the element to be interpreted as a numeric IP -address of the form 1.2.3.4. -An -.Ql x -in the element causes the element to be interpreted as a 32 bit hex value. -If all -else fails the element is interpreted as the number of sequential 1's to place -as the most significant bits in the 32 bit network mask. -Whatever the interpretation method, a result network mask of all 1's, indicating a -hostname, is valid. -A network mask of 31 1's (255.255.255.254) -is considered invalid as there is no space for allocating host -.Tn IP Ns #\&'s -after consideration for broadcast and network addresses. -.Sh EXAMPLES -To change -.Tn IP -numbers used internally from network 10 into an ISP provided 8-bit -subnet at 209.1.2.0 through the ppp0 interface, -the following would be used: -.Bd -literal -offset indent +numbers ::= '0' | '1' | '2' | '3' | '4' | '5' | '6' | '7' | '8' | '9' . +.fi +.PP +For standard NAT functionality, a rule should start with \fBmap\fP and then +proceeds to specify the interface for which outgoing packets will have their +source address rewritten. +.PP +Packets which will be rewritten can only be selected by matching the original +source address. A netmask must be specified with the IP address. +.PP +The address selected for replacing the original is chosen from an IP#/netmask +pair. A netmask of all 1's indicating a hostname is valid. A netmask of +31 1's (255.255.255.254) is considered invalid as there is no space for +allocating host IP#'s after consideration for broadcast and network +addresses. +.PP +When remapping TCP and UDP packets, it is also possible to change the source +port number. Either TCP or UDP or both can be selected by each rule, with a +range of port numbers to remap into given as \fBport-number:port-number\fP. +.SH COMMANDS +There are four commands recognised by IP Filter's NAT code: +.TP +.B map +that is used for mapping one address or network to another in an unregulated +round robin fashion; +.TP +.B rdr +that is used for redirecting packets to one IP address and port pair to +another; +.TP +.B bimap +for setting up bidirectional NAT between an external IP address and an internal +IP address and +.TP +.B map-block +which sets up static IP address based translation, based on a algorithm to +squeeze the addresses to be translated into the destination range. +.SH MATCHING +.PP +For basic NAT and redirection of packets, the address subject to change is used +along with its protocol to check if a packet should be altered. In the case +of redirects, it is also possible to select packets on a source address basis +using the \fBfrom\fP keyword, as well as the manditory destination port. The +packet \fImatching\fP part of the rule is to the left of the "->" in each rule. +.SH TRANSLATION +.PP +To the right of the "->" is the address and port specificaton which will be +written into the packet providing it has already successful matched the +prior constraints. The case of redirections (\fBrdr\fP) is the simpliest: +the new destination address is that specified in the rule. For \fBmap\fP +rules, the destination address will be one for which the tuple combining +the new source and destination is known to be unique. If the packet is +either a TCP or UDP packet, the destination and source ports come into the +equation too. If the tuple already exists, IP Filter will increment the +port number first, within the available range specified with \fBportmap\fP +and if there exists no unique tuple, the source address will be incremented +within the specified netmask. If a unique tuple cannot be determined, then +the packet will not be translated. The \fBmap-block\fP is more limited in +how it searches for a new, free and unique tuple, in that it will used an +algorithm to determine what the new source address should be, along with the +range of available ports - the IP address is never changed and nor does the +port number ever exceed its alloted range. +.SH KERNEL PROXIES +.PP +IP Filter comes with a few, simple, proxies built into the code that is loaded +into the kernel to allow secondary channels to be opened without forcing the +packets through a user program. +.SH TRNSPARENT PROXIES +.PP +True transparent proxying should be performed using the redirect (\fBrdr\fP) +rules directing ports to localhost (127.0.0.1) with the proxy program doing +a lookup through \fB/dev/ipnat\fP to determine the real source and address +of the connection. +.SH EXAMPLES +.PP +This section deals with the \fBmap\fP command and it's variations. +.PP +To change IP#'s used internally from network 10 into an ISP provided 8 bit +subnet at 209.1.2.0 through the ppp0 interface, the following would be used: +.LP +.nf map ppp0 10.0.0.0/8 -> 209.1.2.0/24 -.Ed -.Pp -The obvious problem here is we're trying to squeeze over 16,000,000 -.Tn IP -addresses into a 254 address space. -To increase the scope, remapping for -.Tn TCP -and/or -.Tn UDP , -port remapping can be used: -.Bd -literal -offset indent +.fi +.PP +The obvious problem here is we're trying to squeeze over 16,000,000 IP +addresses into a 254 address space. To increase the scope, remapping for TCP +and/or UDP, port remapping can be used; +.LP +.nf map ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000 -.Ed -.Pp -which falls only 527,566 -.Sq addresses -short of the space available in network 10. -If we were to combine these rules, they would need to be specified as +.fi +.PP +which falls only 527,566 `addresses' short of the space available in network +10. If we were to combine these rules, they would need to be specified as follows: -.Bd -literal -offset indent +.LP +.nf map ppp0 10.0.0.0/8 -> 209.1.2.0/24 portmap tcp/udp 1025:65000 map ppp0 10.0.0.0/8 -> 209.1.2.0/24 -.Ed -.Pp -so that all -.Tn TCP Ns / Tn UDP -packets were port mapped and other protocols, such as -.Tn ICMP , -have only their -.Tn IP Ns # -changed. -.Pp -Further examples can be found in the file -.Pa \&/use\&/share\&/ipf\&/nat\&.1 -.Sh FILES -.Bl -tag -width "/usr/share/ipf/nat.1" -compact -.It Pa /dev/ipnat -.It Pa /etc/services -.It Pa /etc/protocols -.It Pa /etc/hosts -.It Pa /usr/share/ipf/nat.1 -example rules -.It Pa /usr/share/ipf/nat.2 -system requirements for use of NAT -.It Pa /etc/ipnat.rules -actual rule list -.El -.Sh SEE ALSO -.Xr ipf 8 , -.Xr ipftest 1 , -.Xr ipf 4 , -.Xr ipl 4 , -.Xr ipnat 4 , -.Xr hosts 5 , -.Xr ipf 5 , -.Xr services 5 -.Xr protocols 5 -.Xr ipfstat 8 , -.Xr ipmon 8 , -.Xr ipnat 8 -.Pp -http://coombs.anu.edu.au/~avalon - +.fi +.PP +so that all TCP/UDP packets were port mapped and only other protocols, such as +ICMP, only have their IP# changed. In some instaces, it is more appropriate +to use the keyword \fBauto\fP in place of an actual range of port numbers if +you want to guarantee simultaneous access to all within the given range. +However, in the above case, it would default to 1 port per IP address, since +we need to squeeze 24 bits of address space into 8. A good example of how +this is used might be: +.LP +.nf +map ppp0 172.192.0.0/16 -> 209.1.2.0/24 portmap tcp/udp auto +.fi +.PP +which would result in each IP address being given a small range of ports to +use (252). The problem here is that the \fBmap\fP directive tells the NAT +code to use the next address/port pair available for an outgoing connection, +resulting in no easily discernable relation between external addresses/ports +and internal ones. This is overcome by using \fBmap-block\fP as follows: +.LP +.nf +map-block ppp0 172.192.0.0/16 -> 209.1.2.0/24 ports auto +.fi +.PP +For example, this would result in 172.192.0.0/24 being mapped to 209.1.2.0/32 +with each address, from 172.192.0.0 to 172.192.0.255 having 252 ports of its +own. As opposed to the above use of \fBmap\fP, if for some reason the user +of (say) 172.192.0.2 wanted 260 simultaneous connections going out, they would +be limited to 252 with \fBmap-block\fP but would just \fImove on\fP to the next +IP address with the \fBmap\fP command. +/dev/ipnat +.br +/etc/services +.br +/etc/hosts +.SH SEE ALSO +ipnat(4), hosts(5), ipf(5), services(5), ipf(8), ipnat(8) |