1 /*!\file netinet/ip_fw.h
2 * IP firewall definitions.
6 * Copyright (c) 1993 Daniel Boulet
7 * Copyright (c) 1994 Ugen J.S.Antsilevich
9 * Redistribution and use in source forms, with and without modification,
10 * are permitted provided that this entire comment appears intact.
12 * Redistribution in binary form may occur without any restrictions.
13 * Obviously, it would be nice if you gave credit where credit is due
14 * but requiring it would be too onerous.
16 * This software is provided ``AS IS'' without any warranties of any kind.
18 * $Id: ip_fw.h,v 1.23.2.1 1997/01/29 13:15:43 adam Exp $
22 * Format of an IP firewall descriptor
24 * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
25 * fw_flg and fw_n*p are stored in host byte order (of course).
26 * Port numbers are stored in HOST byte order.
29 #ifndef __NETINET_IP_FW_H
30 #define __NETINET_IP_FW_H
33 u_long fw_pcnt,fw_bcnt; /* Packet and byte counters */
34 struct in_addr fw_src, fw_dst; /* Source and destination IP addr */
35 struct in_addr fw_smsk, fw_dmsk; /* Mask for src and dest IP addr */
37 struct in_addr fu_via_ip; /* Specified by IP address */
38 struct { /* Specified by interface name */
39 #define FW_IFNLEN 6 /* To keep structure on 2^x boundary */
40 char fu_via_name[FW_IFNLEN];
44 #define fw_via_ip fu_via_un.fu_via_ip
45 #define fw_via_name fu_via_un.fu_via_if.fu_via_name
46 #define fw_via_unit fu_via_un.fu_via_if.fu_via_unit
48 u_short fw_flg; /* Flags word */
49 u_short fw_nsp, fw_ndp; /* N'of src ports and # of dst ports */
50 /* in ports array (dst ports follow */
51 /* src ports; max of 10 ports in all; */
52 /* count of 0 means match all ports) */
53 #define IP_FW_MAX_PORTS 10 /* A reasonable maximum */
54 u_short fw_pts[IP_FW_MAX_PORTS]; /* Array of port numbers to match */
55 u_char fw_ipopt,fw_ipnopt; /* IP options set/unset */
56 u_char fw_tcpf,fw_tcpnf; /* TCP flags set/unset */
57 #define IP_FW_ICMPTYPES_DIM (256 / (sizeof(unsigned) * 8))
58 unsigned fw_icmptypes[IP_FW_ICMPTYPES_DIM]; /* ICMP types bitmap */
59 long timestamp; /* timestamp (tv_sec) of last match */
60 u_short fw_divert_port; /* Divert port (options IPDIVERT) */
61 u_char fw_prot; /* IP protocol */
65 LIST_ENTRY(ip_fw_chain) chain;
70 * Values for "flags" field .
72 #define IP_FW_F_INVSRC 0x0001 /* Invert sense of src check */
73 #define IP_FW_F_INVDST 0x0002 /* Invert sense of dst check */
74 #define IP_FW_F_IN 0x0004 /* Inbound */
75 #define IP_FW_F_OUT 0x0008 /* Outbound */
77 #define IP_FW_F_COMMAND 0x0030 /* Mask for type of chain entry: */
78 #define IP_FW_F_ACCEPT 0x0010 /* This is an accept rule */
79 #define IP_FW_F_COUNT 0x0020 /* This is a count rule */
80 #define IP_FW_F_DIVERT 0x0030 /* This is a divert rule */
81 #define IP_FW_F_DENY 0x0000 /* This is a deny rule */
83 #define IP_FW_F_PRN 0x0040 /* Print if this rule matches */
84 #define IP_FW_F_ICMPRPL 0x0080 /* Send back icmp unreachable packet */
86 #define IP_FW_F_SRNG 0x0100 /* The first two src ports are a min *
87 * and max range (stored in host byte *
90 #define IP_FW_F_DRNG 0x0200 /* The first two dst ports are a min *
91 * and max range (stored in host byte *
94 #define IP_FW_F_IFNAME 0x0400 /* Use interface name/unit (not IP) */
96 #define IP_FW_F_FRAG 0x0800 /* Fragment */
98 #define IP_FW_F_ICMPBIT 0x1000 /* ICMP type bitmap is valid */
100 #define IP_FW_F_IFUWILD 0x2000 /* Match all interface units */
102 #define IP_FW_F_MASK 0x3FFF /* All possible flag bits mask */
105 * Definitions for IP option names.
107 #define IP_FW_IPOPT_LSRR 0x01
108 #define IP_FW_IPOPT_SSRR 0x02
109 #define IP_FW_IPOPT_RR 0x04
110 #define IP_FW_IPOPT_TS 0x08
113 * Definitions for TCP flags.
115 #define IP_FW_TCPF_FIN TH_FIN
116 #define IP_FW_TCPF_SYN TH_SYN
117 #define IP_FW_TCPF_RST TH_RST
118 #define IP_FW_TCPF_PSH TH_PUSH
119 #define IP_FW_TCPF_ACK TH_ACK
120 #define IP_FW_TCPF_URG TH_URG
121 #define IP_FW_TCPF_ESTAB 0x40