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 IP6 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 _IP6_TABLES_H
16 #define _IP6_TABLES_H
17
18 #include <linux/types.h>
19 #include <linux/netfilter_ipv6.h>
20
21 #include <linux/netfilter/x_tables.h>
22
23 #define IP6T_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
24 #define IP6T_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
25
26 #define ip6t_match xt_match
27 #define ip6t_target xt_target
28 #define ip6t_table xt_table
29 #define ip6t_get_revision xt_get_revision
30
31 /* Yes, Virginia, you have to zero the padding. */
32 struct ip6t_ip6 {
33 /* Source and destination IP6 addr */
34 struct in6_addr src, dst;
35 /* Mask for src and dest IP6 addr */
36 struct in6_addr smsk, dmsk;
37 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
38 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
39
40 /* Upper protocol number
41 * - The allowed value is 0 (any) or protocol number of last parsable
42 * header, which is 50 (ESP), 59 (No Next Header), 135 (MH), or
43 * the non IPv6 extension headers.
44 * - The protocol numbers of IPv6 extension headers except of ESP and
45 * MH do not match any packets.
46 * - You also need to set IP6T_FLAGS_PROTO to "flags" to check protocol.
47 */
48 u_int16_t proto;
49 /* TOS to match iff flags & IP6T_F_TOS */
50 u_int8_t tos;
51
52 /* Flags word */
53 u_int8_t flags;
54 /* Inverse flags */
55 u_int8_t invflags;
56 };
57
58 #define ip6t_entry_match xt_entry_match
59 #define ip6t_entry_target xt_entry_target
60 #define ip6t_standard_target xt_standard_target
61
62 #define ip6t_counters xt_counters
63
64 /* Values for "flag" field in struct ip6t_ip6 (general ip6 structure). */
65 #define IP6T_F_PROTO 0x01 /* Set if rule cares about upper
66 protocols */
67 #define IP6T_F_TOS 0x02 /* Match the TOS. */
68 #define IP6T_F_GOTO 0x04 /* Set if jump is a goto */
69 #define IP6T_F_MASK 0x07 /* All possible flag bits mask. */
70
71 /* Values for "inv" field in struct ip6t_ip6. */
72 #define IP6T_INV_VIA_IN 0x01 /* Invert the sense of IN IFACE. */
73 #define IP6T_INV_VIA_OUT 0x02 /* Invert the sense of OUT IFACE */
74 #define IP6T_INV_TOS 0x04 /* Invert the sense of TOS. */
75 #define IP6T_INV_SRCIP 0x08 /* Invert the sense of SRC IP. */
76 #define IP6T_INV_DSTIP 0x10 /* Invert the sense of DST OP. */
77 #define IP6T_INV_FRAG 0x20 /* Invert the sense of FRAG. */
78 #define IP6T_INV_PROTO XT_INV_PROTO
79 #define IP6T_INV_MASK 0x7F /* All possible flag bits mask. */
80
81 /* This structure defines each of the firewall rules. Consists of 3
82 parts which are 1) general IP header stuff 2) match specific
83 stuff 3) the target to perform if the rule matches */
84 struct ip6t_entry
85 {
86 struct ip6t_ip6 ipv6;
87
88 /* Mark with fields that we care about. */
89 unsigned int nfcache;
90
91 /* Size of ipt_entry + matches */
92 u_int16_t target_offset;
93 /* Size of ipt_entry + matches + target */
94 u_int16_t next_offset;
95
96 /* Back pointer */
97 unsigned int comefrom;
98
99 /* Packet and byte counters. */
100 struct xt_counters counters;
101
102 /* The matches (if any), then the target. */
103 unsigned char elems[0];
104 };
105
106 /* Standard entry */
107 struct ip6t_standard
108 {
109 struct ip6t_entry entry;
110 struct ip6t_standard_target target;
111 };
112
113 struct ip6t_error_target
114 {
115 struct ip6t_entry_target target;
116 char errorname[IP6T_FUNCTION_MAXNAMELEN];
117 };
118
119 struct ip6t_error
120 {
121 struct ip6t_entry entry;
122 struct ip6t_error_target target;
123 };
124
125 #define IP6T_ENTRY_INIT(__size) \
126 { \
127 .target_offset = sizeof(struct ip6t_entry), \
128 .next_offset = (__size), \
129 }
130
131 #define IP6T_STANDARD_INIT(__verdict) \
132 { \
133 .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_standard)), \
134 .target = XT_TARGET_INIT(IP6T_STANDARD_TARGET, \
135 sizeof(struct ip6t_standard_target)), \
136 .target.verdict = -(__verdict) - 1, \
137 }
138
139 #define IP6T_ERROR_INIT \
140 { \
141 .entry = IP6T_ENTRY_INIT(sizeof(struct ip6t_error)), \
142 .target = XT_TARGET_INIT(IP6T_ERROR_TARGET, \
143 sizeof(struct ip6t_error_target)), \
144 .target.errorname = "ERROR", \
145 }
146
147 /*
148 * New IP firewall options for [gs]etsockopt at the RAW IP level.
149 * Unlike BSD Linux inherits IP options so you don't have to use
150 * a raw socket for this. Instead we check rights in the calls.
151 *
152 * ATTENTION: check linux/in6.h before adding new number here.
153 */
154 #define IP6T_BASE_CTL 64
155
156 #define IP6T_SO_SET_REPLACE (IP6T_BASE_CTL)
157 #define IP6T_SO_SET_ADD_COUNTERS (IP6T_BASE_CTL + 1)
158 #define IP6T_SO_SET_MAX IP6T_SO_SET_ADD_COUNTERS
159
160 #define IP6T_SO_GET_INFO (IP6T_BASE_CTL)
161 #define IP6T_SO_GET_ENTRIES (IP6T_BASE_CTL + 1)
162 #define IP6T_SO_GET_REVISION_MATCH (IP6T_BASE_CTL + 4)
163 #define IP6T_SO_GET_REVISION_TARGET (IP6T_BASE_CTL + 5)
164 #define IP6T_SO_GET_MAX IP6T_SO_GET_REVISION_TARGET
165
166 /* CONTINUE verdict for targets */
167 #define IP6T_CONTINUE XT_CONTINUE
168
169 /* For standard target */
170 #define IP6T_RETURN XT_RETURN
171
172 /* TCP/UDP matching stuff */
173 #include <linux/netfilter/xt_tcpudp.h>
174
175 #define ip6t_tcp xt_tcp
176 #define ip6t_udp xt_udp
177
178 /* Values for "inv" field in struct ipt_tcp. */
179 #define IP6T_TCP_INV_SRCPT XT_TCP_INV_SRCPT
180 #define IP6T_TCP_INV_DSTPT XT_TCP_INV_DSTPT
181 #define IP6T_TCP_INV_FLAGS XT_TCP_INV_FLAGS
182 #define IP6T_TCP_INV_OPTION XT_TCP_INV_OPTION
183 #define IP6T_TCP_INV_MASK XT_TCP_INV_MASK
184
185 /* Values for "invflags" field in struct ipt_udp. */
186 #define IP6T_UDP_INV_SRCPT XT_UDP_INV_SRCPT
187 #define IP6T_UDP_INV_DSTPT XT_UDP_INV_DSTPT
188 #define IP6T_UDP_INV_MASK XT_UDP_INV_MASK
189
190 /* ICMP matching stuff */
191 struct ip6t_icmp
192 {
193 u_int8_t type; /* type to match */
194 u_int8_t code[2]; /* range of code */
195 u_int8_t invflags; /* Inverse flags */
196 };
197
198 /* Values for "inv" field for struct ipt_icmp. */
199 #define IP6T_ICMP_INV 0x01 /* Invert the sense of type/code test */
200
201 /* The argument to IP6T_SO_GET_INFO */
202 struct ip6t_getinfo
203 {
204 /* Which table: caller fills this in. */
205 char name[IP6T_TABLE_MAXNAMELEN];
206
207 /* Kernel fills these in. */
208 /* Which hook entry points are valid: bitmask */
209 unsigned int valid_hooks;
210
211 /* Hook entry points: one per netfilter hook. */
212 unsigned int hook_entry[NF_INET_NUMHOOKS];
213
214 /* Underflow points. */
215 unsigned int underflow[NF_INET_NUMHOOKS];
216
217 /* Number of entries */
218 unsigned int num_entries;
219
220 /* Size of entries. */
221 unsigned int size;
222 };
223
224 /* The argument to IP6T_SO_SET_REPLACE. */
225 struct ip6t_replace
226 {
227 /* Which table. */
228 char name[IP6T_TABLE_MAXNAMELEN];
229
230 /* Which hook entry points are valid: bitmask. You can't
231 change this. */
232 unsigned int valid_hooks;
233
234 /* Number of entries */
235 unsigned int num_entries;
236
237 /* Total size of new entries */
238 unsigned int size;
239
240 /* Hook entry points. */
241 unsigned int hook_entry[NF_INET_NUMHOOKS];
242
243 /* Underflow points. */
244 unsigned int underflow[NF_INET_NUMHOOKS];
245
246 /* Information about old entries: */
247 /* Number of counters (must be equal to current number of entries). */
248 unsigned int num_counters;
249 /* The old entries' counters. */
250 struct xt_counters *counters;
251
252 /* The entries (hang off end: not really an array). */
253 struct ip6t_entry entries[0];
254 };
255
256 /* The argument to IP6T_SO_ADD_COUNTERS. */
257 #define ip6t_counters_info xt_counters_info
258
259 /* The argument to IP6T_SO_GET_ENTRIES. */
260 struct ip6t_get_entries
261 {
262 /* Which table: user fills this in. */
263 char name[IP6T_TABLE_MAXNAMELEN];
264
265 /* User fills this in: total entry size. */
266 unsigned int size;
267
268 /* The entries. */
269 struct ip6t_entry entrytable[0];
270 };
271
272 /* Standard return verdict, or do jump. */
273 #define IP6T_STANDARD_TARGET XT_STANDARD_TARGET
274 /* Error verdict. */
275 #define IP6T_ERROR_TARGET XT_ERROR_TARGET
276
277 /* Helper functions */
278 static __inline__ struct ip6t_entry_target *
ip6t_get_target(struct ip6t_entry * e)279 ip6t_get_target(struct ip6t_entry *e)
280 {
281 return (void *)e + e->target_offset;
282 }
283
284 /* fn returns 0 to continue iteration */
285 #define IP6T_MATCH_ITERATE(e, fn, args...) \
286 XT_MATCH_ITERATE(struct ip6t_entry, e, fn, ## args)
287
288 /* fn returns 0 to continue iteration */
289 #define IP6T_ENTRY_ITERATE(entries, size, fn, args...) \
290 XT_ENTRY_ITERATE(struct ip6t_entry, entries, size, fn, ## args)
291
292 /*
293 * Main firewall chains definitions and global var's definitions.
294 */
295
296 #endif /* _IP6_TABLES_H */
297