1995-02-17 19:48:36 +01:00
|
|
|
.Dd November 16, 1994
|
1996-07-11 04:37:59 +02:00
|
|
|
.Dt IPFIREWALL 4
|
1995-02-17 19:48:36 +01:00
|
|
|
.Os
|
|
|
|
.Sh NAME
|
1996-12-16 21:31:40 +01:00
|
|
|
.Nm ipfirewall ,
|
1996-07-11 04:37:59 +02:00
|
|
|
.Nm ipfw ,
|
|
|
|
.Nm ipaccounting ,
|
|
|
|
.Nm ipacct
|
|
|
|
.Nd IP packet filter and traffic accounting.
|
1995-02-17 19:48:36 +01:00
|
|
|
.Sh SYNOPSIS
|
1996-07-11 04:37:59 +02:00
|
|
|
.Fd #include <netinet/ip_fw.h>
|
|
|
|
.Ft int
|
|
|
|
.Fn setsockopt raw_socket IPPROTO_IP "ipfw/ipacct option" "struct ip | struct ipfw" size
|
1995-02-17 19:48:36 +01:00
|
|
|
|
|
|
|
Ipfw options:
|
|
|
|
IP_FW_ADD_BLK - add entry to blocking chain.
|
|
|
|
IP_FW_ADD_FWD - add entry to forwarding chain.
|
|
|
|
IP_FW_CHK_BLK - check ip packet against blocking chain.
|
|
|
|
IP_FW_CHK_FWD - check ip packet against forwarding chain.
|
|
|
|
IP_FW_DEL_BLK - delete entry from blocking chain.
|
|
|
|
IP_FW_DEL_FWD - delete entry from forwarding chain.
|
|
|
|
IP_FW_FLUSH - flush all blocking & forwarding chain entries.
|
|
|
|
IP_FW_POLICY - define default ipfw policy.
|
|
|
|
|
|
|
|
Ipacct options:
|
|
|
|
IP_ACCT_ADD - add entry to accounting chain.
|
|
|
|
IP_ACCT_DEL - delete entry from accounting chain.
|
|
|
|
IP_ACCT_FLUSH - flush all accounting chain entries.
|
|
|
|
IP_ACCT_ZERO - zero all accounting chain entries.
|
|
|
|
|
|
|
|
Ipfw/ipacct entry structure:
|
|
|
|
#define IP_FW_MAX_PORTS 10
|
|
|
|
|
|
|
|
struct ip_fw {
|
|
|
|
struct ip_fw *next;
|
|
|
|
struct in_addr src, dst;
|
|
|
|
struct in_addr src_mask, dst_mask;
|
|
|
|
u_short flags;
|
|
|
|
u_short n_src_p, n_dst_p;
|
|
|
|
u_short ports[IP_FW_MAX_PORTS];
|
|
|
|
u_long p_cnt,b_cnt;
|
|
|
|
}
|
|
|
|
|
|
|
|
Flags values for "flags" field:
|
|
|
|
IP_FW_F_ALL - The entry should match all IP packets.
|
|
|
|
IP_FW_F_TCP - The entry should match TCP packets.
|
|
|
|
IP_FW_F_UDP - The entry should match UDP packets.
|
|
|
|
IP_FW_F_ICMP - The entry should match ICMP packets.
|
|
|
|
IP_FW_F_KIND - Mask value to separate protocol kind.
|
|
|
|
IP_FW_F_ACCEPT - This entry is accepting ( see below )
|
|
|
|
IP_FW_F_SRNG - Source ports are range ( see below )
|
|
|
|
IP_FW_F_DRNG - Destination ports are range ( see below )
|
|
|
|
IP_FW_F_PRN - Print this entry ( see below )
|
|
|
|
IP_FW_F_BIDIR - This acct entry is bidirectional ( see below )
|
|
|
|
IP_FW_F_MASK - Mask to match all valid flag bits.
|
|
|
|
|
|
|
|
Kernel symbols to kvm_nlist():
|
|
|
|
struct ip_fw *ip_fw_blk_chain - chain of forwarding entries.
|
|
|
|
struct ip_fw *ip_fw_fwd_chain - chain of blocking entries.
|
|
|
|
int ip_fw_policy - default policy.
|
|
|
|
struct ip_fw *ip_acct_chain - chain of accounting entries.
|
|
|
|
|
|
|
|
Options in the kernel configuration file:
|
|
|
|
IPFIREWALL - enable ipfirewall.
|
|
|
|
IPFIREWALL_VERBOSE - enable firewall output ( see below )
|
|
|
|
DEBUG_IPFIREWALL - enable extensive debugging output.
|
|
|
|
IPACCT - enable ipaccounting.
|
|
|
|
|
|
|
|
.Sh DESCRIPTION
|
|
|
|
Ipfirewall (later ipfw) is a system facility,which allows filtering
|
|
|
|
of incoming and/or forwarding packets on the protocol+source/destination
|
1996-01-30 14:52:50 +01:00
|
|
|
address/ports base.
|
1995-02-17 19:48:36 +01:00
|
|
|
Ipaccounting (later ipacct) is a system facility,which allows counting
|
|
|
|
of incoming,outgoing and forwarding traffic by packet/byte count.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
Basic idea is that every packet checked against number of entries
|
1996-07-11 04:37:59 +02:00
|
|
|
in several chains. There are 3 chains:
|
1995-02-17 19:48:36 +01:00
|
|
|
Blocking - this chain defines whenever packet should be accepted
|
|
|
|
ever for local delivery or for forwarding.
|
|
|
|
Forwarding - this chain defines whenever packet should be accepted
|
|
|
|
for forwarding only.
|
|
|
|
Accounting - this chain defines types of packets , which should be
|
|
|
|
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
Options to add/remove specific entries or to flush all entries described
|
1996-07-11 04:37:59 +02:00
|
|
|
above. Value passed to
|
|
|
|
.Fn setsockopt
|
|
|
|
is a value of struct ip_fw for
|
|
|
|
entry. If an entry is added, it checked by such rules that when we start
|
1995-02-17 19:48:36 +01:00
|
|
|
searching chain for matching entry the first matching is the best match,
|
|
|
|
[ or at least one of them :^) ].
|
|
|
|
That means:
|
|
|
|
* First in chain entries with specific protocol and small ranges
|
1996-01-30 14:52:50 +01:00
|
|
|
of src/dst addresses and ports.
|
|
|
|
* Later go entries with wider ranges of ports and addresses.
|
|
|
|
* Later entries matching every port for some address range.
|
1995-02-17 19:48:36 +01:00
|
|
|
* Later universal entries matching any protocol.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
|
|
|
While deleting entry, every entry which is equal to that passed to
|
|
|
|
.Fn setsockopt
|
|
|
|
will be removed. Flush removes all entries.
|
|
|
|
Each entry has several fields by which packets are matched:
|
1995-02-17 19:48:36 +01:00
|
|
|
|
|
|
|
|
|
|
|
struct ip_fw *next - next entry in chain.(Set internally)
|
|
|
|
|
1996-01-30 14:52:50 +01:00
|
|
|
struct in_addr src - source address to be matched.
|
|
|
|
struct in_addr src_mask - source address mask.
|
|
|
|
To match whole networks/subnets or address groups
|
1995-02-17 19:48:36 +01:00
|
|
|
mask bits should be zeroed here and also
|
|
|
|
in src_mask field. Valuable bits should be set
|
|
|
|
in src_mask field.
|
1996-01-30 14:52:50 +01:00
|
|
|
struct in_addr dst - destination address to be matched.
|
|
|
|
struct in_addr dst_mask - destination address mask.
|
1995-02-17 19:48:36 +01:00
|
|
|
|
|
|
|
u_short flags - flags field.See exact description of flags meaning
|
|
|
|
in description later.
|
|
|
|
|
|
|
|
u_short n_src_p - number of source ports in "ports" array.
|
|
|
|
u_short n_dst_p - number of destination ports in "ports" array.
|
|
|
|
u_short ports[] - ports array.Overall length currently defined
|
|
|
|
to reasonable maximum - 10,and could be changed.
|
|
|
|
The packet's src port can ever match one of
|
|
|
|
ports[0] ... ports[--n_src_p] numbers,or if
|
|
|
|
flag IP_FW_F_SRNG set take port[0] as bottom
|
|
|
|
range value and ports[1] as top one.n_src_p should
|
|
|
|
be set to 2 then.If n_src_p equal to 0 , every port
|
|
|
|
match. The same rules apply to packet's dst port,
|
|
|
|
except that it matched against ports[n_src_p] ...
|
|
|
|
... ports[n_src_p+n_dst_p--],or if IP_FW_F_DRNG set,
|
|
|
|
range is ports[n_src_p] to ports[n_srcp++].
|
|
|
|
|
|
|
|
u_long p_cnt - packets count for ipacct entries.
|
|
|
|
u_long b_cnt - bytes count for ipacct entries.
|
|
|
|
|
1996-07-11 04:37:59 +02:00
|
|
|
Packet matching proceeds in the following manner:
|
1995-02-17 19:48:36 +01:00
|
|
|
|
|
|
|
a) If packet entry protocol set to ALL, see c).
|
|
|
|
|
|
|
|
b) If entry protocol set to TCP/UDP/ICMP and packet protocol
|
1996-07-11 04:37:59 +02:00
|
|
|
different - no match, if packet protocol and entry protocol
|
1995-02-17 19:48:36 +01:00
|
|
|
same - continue.
|
|
|
|
|
1996-01-30 14:52:50 +01:00
|
|
|
c) If source address pattern does not equal to packets sources address
|
1996-07-11 04:37:59 +02:00
|
|
|
masked with src_mask, or destination pattern not equal to packets
|
1996-01-30 14:52:50 +01:00
|
|
|
destination address masked with dst_mask - no match.
|
1995-02-17 19:48:36 +01:00
|
|
|
If they does and protocol set to ALL/ICMP - got match.
|
|
|
|
If they does and protocol set to TCP/UDP - continue.
|
|
|
|
|
|
|
|
d) If src port doesn't match or dst port doesn't match - all
|
1996-07-11 04:37:59 +02:00
|
|
|
packet don't match. If they do - got match.
|
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
In ipfw packet matched consequently against every chain entry.
|
|
|
|
Search continues untill first matching entry found.If IP_FW_F_ACCEPT
|
1996-07-11 04:37:59 +02:00
|
|
|
flag set - packet accepted. If it is not set - packet denied.
|
|
|
|
If no matching entry found, all unmatched packets ever accepted or
|
1996-01-30 14:52:50 +01:00
|
|
|
denied depending on global policy value. It can be set with
|
1996-07-11 04:37:59 +02:00
|
|
|
IP_FW_POLICY raw socket option. The value for deny is 0,
|
|
|
|
and 1 for accept.
|
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
Entries can be added with IP_FW_F_PRN flag set.If kernel compiled
|
|
|
|
with IPFIREWALL_VERBOSE option,packets matching this entries will
|
|
|
|
be printed by kernel printf's.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
If some chain is empty,every packet accepted by this chain no
|
|
|
|
matter what default policy is.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
To check whenever or not packet denied by some chain , checking
|
|
|
|
options to setsockopt() can be issued. Then the argument is
|
|
|
|
a buffer representing ip packet,thus it has to be
|
|
|
|
struct ip + struct tcphdr .
|
|
|
|
Then setsockopt() return value 0 on accept or another on deny.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
Ipaccounting entries added the same way as ipfw ones.Packet checked
|
|
|
|
against all entries in chain and values of p_cnt and b_cnt in matching
|
|
|
|
entries rised.p_cnt rises by 1 and b_cnt by ip_len value of ip packet.
|
|
|
|
Thus all traffic size counted including IP headers.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
If IP_FW_F_BIDIR flag is set in accounting entry,packets counted are
|
1996-01-30 14:52:50 +01:00
|
|
|
those which match entry in standard way along with packets which match
|
1995-02-17 19:48:36 +01:00
|
|
|
entry while their source and destination addr/port pairs swapped.
|
1996-07-11 04:37:59 +02:00
|
|
|
.Pp
|
1995-02-17 19:48:36 +01:00
|
|
|
Zero option allows all accounting to be cleared.
|
|
|
|
.Sh DIAGNOSTICS
|
|
|
|
|
|
|
|
[EINVAL] The IP option field was improperly formed; an option
|
|
|
|
field was shorter than the minimum value or longer than
|
|
|
|
the option buffer provided.An structural error in
|
1996-07-11 04:08:31 +02:00
|
|
|
ip_fw structure occurred (n_src_p+n_dst_p too big,
|
1995-02-17 19:48:36 +01:00
|
|
|
ports set for ALL/ICMP protocols etc.)
|
|
|
|
.Sh SEE ALSO
|
1996-07-11 04:37:59 +02:00
|
|
|
.Xr setsockopt 2 ,
|
|
|
|
.Xr kvm_nlist 3 ,
|
|
|
|
.Xr kvm_read 3 ,
|
|
|
|
.Xr ip 4
|
1995-02-17 19:48:36 +01:00
|
|
|
.Sh BUGS
|
1996-07-11 04:37:59 +02:00
|
|
|
The ipfw/ipacct facilities are new and, although serious bugs have
|
|
|
|
been tracked, some less important ones are expected.
|
|
|
|
.Pp
|
|
|
|
This man page is mostly out of date and should be rewritten.
|
1995-02-17 19:48:36 +01:00
|
|
|
.Sh HISTORY
|
1996-01-30 14:52:50 +01:00
|
|
|
Ipfw facility has been initially written as package to BSDI
|
1995-02-17 19:48:36 +01:00
|
|
|
by Daniel Boulet <danny@BouletFermat.ab.ca>.
|
1996-08-22 00:01:49 +02:00
|
|
|
It has been heavily modified and ported to
|
|
|
|
.Fx 2.0
|
1995-02-17 19:48:36 +01:00
|
|
|
by Ugen J.S.Antsilevich <ugen@NetVision.net.il>
|
1996-08-22 00:01:49 +02:00
|
|
|
Ipacct facility written for
|
|
|
|
.Fx 2.0
|
1995-02-17 19:48:36 +01:00
|
|
|
by Ugen J.S.Antsilevich <ugen@NetVision.net.il>
|