xref: /utopia/UTPA2-700.0.x/projects/tools/lint/mips-linux-gnu_include/linux/netfilter_ipv4/ip_tables.h (revision 53ee8cc121a030b8d368113ac3e966b4705770ef)
1 /*
2  * 25-Jul-1998 Major changes to allow for ip chain table
3  *
4  * 3-Jan-2000 Named tables to allow packet selection for different uses.
5  */
6 
7 /*
8  * 	Format of an IP firewall descriptor
9  *
10  * 	src, dst, src_mask, dst_mask are always stored in network byte order.
11  * 	flags are stored in host byte order (of course).
12  * 	Port numbers are stored in HOST byte order.
13  */
14 
15 #ifndef _IPTABLES_H
16 #define _IPTABLES_H
17 
18 #include <linux/types.h>
19 #include <linux/netfilter_ipv4.h>
20 
21 #include <linux/netfilter/x_tables.h>
22 
23 #define IPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
24 #define IPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
25 #define ipt_match xt_match
26 #define ipt_target xt_target
27 #define ipt_table xt_table
28 #define ipt_get_revision xt_get_revision
29 
30 /* Yes, Virginia, you have to zero the padding. */
31 struct ipt_ip {
32 	/* Source and destination IP addr */
33 	struct in_addr src, dst;
34 	/* Mask for src and dest IP addr */
35 	struct in_addr smsk, dmsk;
36 	char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
37 	unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
38 
39 	/* Protocol, 0 = ANY */
40 	u_int16_t proto;
41 
42 	/* Flags word */
43 	u_int8_t flags;
44 	/* Inverse flags */
45 	u_int8_t invflags;
46 };
47 
48 #define ipt_entry_match xt_entry_match
49 #define ipt_entry_target xt_entry_target
50 #define ipt_standard_target xt_standard_target
51 
52 #define ipt_counters xt_counters
53 
54 /* Values for "flag" field in struct ipt_ip (general ip structure). */
55 #define IPT_F_FRAG		0x01	/* Set if rule is a fragment rule */
56 #define IPT_F_GOTO		0x02	/* Set if jump is a goto */
57 #define IPT_F_MASK		0x03	/* All possible flag bits mask. */
58 
59 /* Values for "inv" field in struct ipt_ip. */
60 #define IPT_INV_VIA_IN		0x01	/* Invert the sense of IN IFACE. */
61 #define IPT_INV_VIA_OUT		0x02	/* Invert the sense of OUT IFACE */
62 #define IPT_INV_TOS		0x04	/* Invert the sense of TOS. */
63 #define IPT_INV_SRCIP		0x08	/* Invert the sense of SRC IP. */
64 #define IPT_INV_DSTIP		0x10	/* Invert the sense of DST OP. */
65 #define IPT_INV_FRAG		0x20	/* Invert the sense of FRAG. */
66 #define IPT_INV_PROTO		XT_INV_PROTO
67 #define IPT_INV_MASK		0x7F	/* All possible flag bits mask. */
68 
69 /* This structure defines each of the firewall rules.  Consists of 3
70    parts which are 1) general IP header stuff 2) match specific
71    stuff 3) the target to perform if the rule matches */
72 struct ipt_entry
73 {
74 	struct ipt_ip ip;
75 
76 	/* Mark with fields that we care about. */
77 	unsigned int nfcache;
78 
79 	/* Size of ipt_entry + matches */
80 	u_int16_t target_offset;
81 	/* Size of ipt_entry + matches + target */
82 	u_int16_t next_offset;
83 
84 	/* Back pointer */
85 	unsigned int comefrom;
86 
87 	/* Packet and byte counters. */
88 	struct xt_counters counters;
89 
90 	/* The matches (if any), then the target. */
91 	unsigned char elems[0];
92 };
93 
94 /*
95  * New IP firewall options for [gs]etsockopt at the RAW IP level.
96  * Unlike BSD Linux inherits IP options so you don't have to use a raw
97  * socket for this. Instead we check rights in the calls.
98  *
99  * ATTENTION: check linux/in.h before adding new number here.
100  */
101 #define IPT_BASE_CTL		64
102 
103 #define IPT_SO_SET_REPLACE	(IPT_BASE_CTL)
104 #define IPT_SO_SET_ADD_COUNTERS	(IPT_BASE_CTL + 1)
105 #define IPT_SO_SET_MAX		IPT_SO_SET_ADD_COUNTERS
106 
107 #define IPT_SO_GET_INFO			(IPT_BASE_CTL)
108 #define IPT_SO_GET_ENTRIES		(IPT_BASE_CTL + 1)
109 #define IPT_SO_GET_REVISION_MATCH	(IPT_BASE_CTL + 2)
110 #define IPT_SO_GET_REVISION_TARGET	(IPT_BASE_CTL + 3)
111 #define IPT_SO_GET_MAX			IPT_SO_GET_REVISION_TARGET
112 
113 #define IPT_CONTINUE XT_CONTINUE
114 #define IPT_RETURN XT_RETURN
115 
116 #include <linux/netfilter/xt_tcpudp.h>
117 #define ipt_udp xt_udp
118 #define ipt_tcp xt_tcp
119 
120 #define IPT_TCP_INV_SRCPT	XT_TCP_INV_SRCPT
121 #define IPT_TCP_INV_DSTPT	XT_TCP_INV_DSTPT
122 #define IPT_TCP_INV_FLAGS	XT_TCP_INV_FLAGS
123 #define IPT_TCP_INV_OPTION	XT_TCP_INV_OPTION
124 #define IPT_TCP_INV_MASK	XT_TCP_INV_MASK
125 
126 #define IPT_UDP_INV_SRCPT	XT_UDP_INV_SRCPT
127 #define IPT_UDP_INV_DSTPT	XT_UDP_INV_DSTPT
128 #define IPT_UDP_INV_MASK	XT_UDP_INV_MASK
129 
130 /* ICMP matching stuff */
131 struct ipt_icmp
132 {
133 	u_int8_t type;				/* type to match */
134 	u_int8_t code[2];			/* range of code */
135 	u_int8_t invflags;			/* Inverse flags */
136 };
137 
138 /* Values for "inv" field for struct ipt_icmp. */
139 #define IPT_ICMP_INV	0x01	/* Invert the sense of type/code test */
140 
141 /* The argument to IPT_SO_GET_INFO */
142 struct ipt_getinfo
143 {
144 	/* Which table: caller fills this in. */
145 	char name[IPT_TABLE_MAXNAMELEN];
146 
147 	/* Kernel fills these in. */
148 	/* Which hook entry points are valid: bitmask */
149 	unsigned int valid_hooks;
150 
151 	/* Hook entry points: one per netfilter hook. */
152 	unsigned int hook_entry[NF_INET_NUMHOOKS];
153 
154 	/* Underflow points. */
155 	unsigned int underflow[NF_INET_NUMHOOKS];
156 
157 	/* Number of entries */
158 	unsigned int num_entries;
159 
160 	/* Size of entries. */
161 	unsigned int size;
162 };
163 
164 /* The argument to IPT_SO_SET_REPLACE. */
165 struct ipt_replace
166 {
167 	/* Which table. */
168 	char name[IPT_TABLE_MAXNAMELEN];
169 
170 	/* Which hook entry points are valid: bitmask.  You can't
171            change this. */
172 	unsigned int valid_hooks;
173 
174 	/* Number of entries */
175 	unsigned int num_entries;
176 
177 	/* Total size of new entries */
178 	unsigned int size;
179 
180 	/* Hook entry points. */
181 	unsigned int hook_entry[NF_INET_NUMHOOKS];
182 
183 	/* Underflow points. */
184 	unsigned int underflow[NF_INET_NUMHOOKS];
185 
186 	/* Information about old entries: */
187 	/* Number of counters (must be equal to current number of entries). */
188 	unsigned int num_counters;
189 	/* The old entries' counters. */
190 	struct xt_counters *counters;
191 
192 	/* The entries (hang off end: not really an array). */
193 	struct ipt_entry entries[0];
194 };
195 
196 /* The argument to IPT_SO_ADD_COUNTERS. */
197 #define ipt_counters_info xt_counters_info
198 
199 /* The argument to IPT_SO_GET_ENTRIES. */
200 struct ipt_get_entries
201 {
202 	/* Which table: user fills this in. */
203 	char name[IPT_TABLE_MAXNAMELEN];
204 
205 	/* User fills this in: total entry size. */
206 	unsigned int size;
207 
208 	/* The entries. */
209 	struct ipt_entry entrytable[0];
210 };
211 
212 /* Standard return verdict, or do jump. */
213 #define IPT_STANDARD_TARGET XT_STANDARD_TARGET
214 /* Error verdict. */
215 #define IPT_ERROR_TARGET XT_ERROR_TARGET
216 
217 /* Helper functions */
218 static __inline__ struct ipt_entry_target *
ipt_get_target(struct ipt_entry * e)219 ipt_get_target(struct ipt_entry *e)
220 {
221 	return (void *)e + e->target_offset;
222 }
223 
224 /* fn returns 0 to continue iteration */
225 #define IPT_MATCH_ITERATE(e, fn, args...) \
226 	XT_MATCH_ITERATE(struct ipt_entry, e, fn, ## args)
227 
228 /* fn returns 0 to continue iteration */
229 #define IPT_ENTRY_ITERATE(entries, size, fn, args...) \
230 	XT_ENTRY_ITERATE(struct ipt_entry, entries, size, fn, ## args)
231 
232 /*
233  *	Main firewall chains definitions and global var's definitions.
234  */
235 #endif /* _IPTABLES_H */
236