xref: /freebsd/sys/netinet/ip_fw.h (revision 8e6b01171e30297084bb0b4457c4183c2746aacc)
1 /*
2  * Copyright (c) 1993 Daniel Boulet
3  * Copyright (c) 1994 Ugen J.S.Antsilevich
4  *
5  * Redistribution and use in source forms, with and without modification,
6  * are permitted provided that this entire comment appears intact.
7  *
8  * Redistribution in binary form may occur without any restrictions.
9  * Obviously, it would be nice if you gave credit where credit is due
10  * but requiring it would be too onerous.
11  *
12  * This software is provided ``AS IS'' without any warranties of any kind.
13  *
14  *	$Id: ip_fw.h,v 1.13 1995/07/23 05:36:30 davidg Exp $
15  */
16 
17 /*
18  * Format of an IP firewall descriptor
19  *
20  * fw_src, fw_dst, fw_smsk, fw_dmsk are always stored in network byte order.
21  * fw_flg and fw_n*p are stored in host byte order (of course).
22  * Port numbers are stored in HOST byte order.
23  */
24 #ifndef _IP_FW_H
25 #define _IP_FW_H
26 
27 struct ip_fw {
28     struct ip_fw *fw_next;		/* Next firewall on chain */
29     struct in_addr fw_src, fw_dst;	/* Source and destination IP addr */
30     struct in_addr fw_smsk, fw_dmsk;	/* Mask for src and dest IP addr */
31 	/*
32 	 * This union keeps all "via" information.
33 	 * If ever fu_via_ip is 0,or IP_FW_F_IFNAME set and
34 	 * fu_via_name[0] is 0 - match any packet.
35 	 */
36     union {
37 	struct in_addr fu_via_ip;
38 	struct {
39 #define FW_IFNLEN	6		/* To keep structure on 2^x boundary */
40 		char  fu_via_name[FW_IFNLEN];
41 		short fu_via_unit;
42 	} fu_via_if;
43     } fu_via_un;
44     u_short fw_flg;			/* Flags word */
45     u_short fw_nsp, fw_ndp;             /* N'of src ports and # of dst ports */
46     					/* in ports array (dst ports follow */
47     					/* src ports; max of 10 ports in all; */
48     					/* count of 0 means match all ports) */
49 #define IP_FW_MAX_PORTS	10      	/* A reasonable maximum */
50     u_short fw_pts[IP_FW_MAX_PORTS];    /* Array of port numbers to match */
51     u_long fw_pcnt,fw_bcnt;		/* Packet and byte counters */
52     u_char fw_ipopt,fw_ipnopt;		/* IP options set/unset */
53     u_char fw_tcpf,fw_tcpnf;		/* TCP flags sen/unset */
54 };
55 
56 
57 /*
58  * Definitions to make expressions
59  * for "via" stuff shorter.
60  */
61 #define fw_via_ip	fu_via_un.fu_via_ip
62 #define fw_via_name	fu_via_un.fu_via_if.fu_via_name
63 #define fw_via_unit	fu_via_un.fu_via_if.fu_via_unit
64 
65 /*
66  * Values for "flags" field .
67  */
68 
69 #define IP_FW_F_ALL	0x000	/* This is a universal packet firewall*/
70 #define IP_FW_F_TCP	0x001	/* This is a TCP packet firewall      */
71 #define IP_FW_F_UDP	0x002	/* This is a UDP packet firewall      */
72 #define IP_FW_F_ICMP	0x003	/* This is a ICMP packet firewall     */
73 #define IP_FW_F_KIND	0x003	/* Mask to isolate firewall kind      */
74 #define IP_FW_F_ACCEPT	0x004	/* This is an accept firewall (as     *
75 				 *         opposed to a deny firewall)*
76 				 *                                    */
77 #define IP_FW_F_SRNG	0x008	/* The first two src ports are a min  *
78 				 * and max range (stored in host byte *
79 				 * order).                            *
80 				 *                                    */
81 #define IP_FW_F_DRNG	0x010	/* The first two dst ports are a min  *
82 				 * and max range (stored in host byte *
83 				 * order).                            *
84 				 * (ports[0] <= port <= ports[1])     *
85 				 *                                    */
86 #define IP_FW_F_PRN	0x020	/* In verbose mode print this firewall*/
87 #define IP_FW_F_BIDIR	0x040	/* For accounting-count two way       */
88 #define IP_FW_F_ICMPRPL	0x100	/* Send back icmp unreachable packet  */
89 #define IP_FW_F_IFNAME	0x200	/* Use interface name/unit (not IP)   */
90 #define IP_FW_F_MASK	0x3FF	/* All possible flag bits mask        */
91 
92 /*
93  * Definitions for IP option names.
94  */
95 #define IP_FW_IPOPT_LSRR	0x01
96 #define IP_FW_IPOPT_SSRR	0x02
97 #define IP_FW_IPOPT_RR		0x04
98 #define IP_FW_IPOPT_TS		0x08
99 
100 /*
101  * Definitions for TCP flags.
102  */
103 #define IP_FW_TCPF_FIN		TH_FIN
104 #define IP_FW_TCPF_SYN		TH_SYN
105 #define IP_FW_TCPF_RST		TH_RST
106 #define IP_FW_TCPF_PUSH		TH_PUSH
107 #define IP_FW_TCPF_ACK		TH_ACK
108 #define IP_FW_TCPF_URG		TH_URG
109 
110 /*
111  * New IP firewall options for [gs]etsockopt at the RAW IP level.
112  */
113 #define IP_FW_BASE_CTL	53
114 
115 #define IP_FW_ADD     (IP_FW_BASE_CTL)
116 #define IP_FW_DEL     (IP_FW_BASE_CTL+4)
117 #define IP_FW_FLUSH   (IP_FW_BASE_CTL+6)
118 #define IP_FW_POLICY  (IP_FW_BASE_CTL+7)
119 
120 #define IP_ACCT_ADD   (IP_FW_BASE_CTL+10)
121 #define IP_ACCT_DEL   (IP_FW_BASE_CTL+11)
122 #define IP_ACCT_FLUSH (IP_FW_BASE_CTL+12)
123 #define IP_ACCT_ZERO  (IP_FW_BASE_CTL+13)
124 #define IP_ACCT_CLR   (IP_FW_BASE_CTL+14)
125 
126 /*
127  * Policy flags...
128  */
129 #define IP_FW_P_DENY		0x01
130 #define IP_FW_P_ICMP		0x02
131 #define IP_FW_P_MBIPO		0x04
132 #define IP_FW_P_MASK		0x07
133 
134 
135 /*
136  * Main firewall chains definitions and global var's definitions.
137  */
138 #ifdef KERNEL
139 
140 /*
141  * Variables/chain.
142  */
143 extern struct  ip_fw *ip_fw_chain;
144 extern u_short ip_fw_policy;
145 
146 extern struct  ip_fw *ip_acct_chain;
147 
148 /*
149  * Function pointers.
150  */
151 extern int (*ip_fw_chk_ptr)(struct mbuf *, struct ip *,struct ifnet *,struct ip_fw *);
152 extern int (*ip_fw_ctl_ptr)(int,struct mbuf *);
153 
154 extern void (*ip_acct_cnt_ptr)(struct ip *,struct ifnet *,struct ip_fw *,int);
155 extern int  (*ip_acct_ctl_ptr)(int,struct mbuf *);
156 
157 /*
158  * Function definitions.
159  */
160 int ip_fw_chk(struct mbuf *, struct ip *,struct ifnet *,struct ip_fw *);
161 int ip_fw_ctl(int,struct mbuf *);
162 
163 void ip_acct_cnt(struct ip *,struct ifnet *,struct ip_fw *,int);
164 int  ip_acct_ctl(int,struct mbuf *);
165 
166 #endif /* KERNEL */
167 
168 #endif /* _IP_FW_H */
169