2 * Format of an ARP firewall descriptor
4 * src, tgt, src_mask, tgt_mask, arpop, arpop_mask are always stored in
6 * flags are stored in host byte order (of course).
15 #include <linux/if_arp.h>
16 #include <linux/skbuff.h>
18 #include <linux/types.h>
19 #include <linux/compiler.h>
20 #include <linux/netfilter_arp.h>
22 #include <linux/netfilter/x_tables.h>
25 #define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
26 #define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
27 #define arpt_entry_target xt_entry_target
28 #define arpt_standard_target xt_standard_target
31 #define ARPT_DEV_ADDR_LEN_MAX 16
33 struct arpt_devaddr_info {
34 char addr[ARPT_DEV_ADDR_LEN_MAX];
35 char mask[ARPT_DEV_ADDR_LEN_MAX];
38 /* Yes, Virginia, you have to zero the padding. */
40 /* Source and target IP addr */
41 struct in_addr src, tgt;
42 /* Mask for src and target IP addr */
43 struct in_addr smsk, tmsk;
45 /* Device hw address length, src+target device addresses */
46 u_int8_t arhln, arhln_mask;
47 struct arpt_devaddr_info src_devaddr;
48 struct arpt_devaddr_info tgt_devaddr;
50 /* ARP operation code. */
51 __be16 arpop, arpop_mask;
53 /* ARP hardware address and protocol address format. */
54 __be16 arhrd, arhrd_mask;
55 __be16 arpro, arpro_mask;
57 /* The protocol address length is only accepted if it is 4
58 * so there is no use in offering a way to do filtering on it.
61 char iniface[IFNAMSIZ], outiface[IFNAMSIZ];
62 unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ];
70 /* Values for "flag" field in struct arpt_ip (general arp structure).
71 * No flags defined yet.
73 #define ARPT_F_MASK 0x00 /* All possible flag bits mask. */
75 /* Values for "inv" field in struct arpt_arp. */
76 #define ARPT_INV_VIA_IN 0x0001 /* Invert the sense of IN IFACE. */
77 #define ARPT_INV_VIA_OUT 0x0002 /* Invert the sense of OUT IFACE */
78 #define ARPT_INV_SRCIP 0x0004 /* Invert the sense of SRC IP. */
79 #define ARPT_INV_TGTIP 0x0008 /* Invert the sense of TGT IP. */
80 #define ARPT_INV_SRCDEVADDR 0x0010 /* Invert the sense of SRC DEV ADDR. */
81 #define ARPT_INV_TGTDEVADDR 0x0020 /* Invert the sense of TGT DEV ADDR. */
82 #define ARPT_INV_ARPOP 0x0040 /* Invert the sense of ARP OP. */
83 #define ARPT_INV_ARPHRD 0x0080 /* Invert the sense of ARP HRD. */
84 #define ARPT_INV_ARPPRO 0x0100 /* Invert the sense of ARP PRO. */
85 #define ARPT_INV_ARPHLN 0x0200 /* Invert the sense of ARP HLN. */
86 #define ARPT_INV_MASK 0x03FF /* All possible flag bits mask. */
88 /* This structure defines each of the firewall rules. Consists of 3
89 parts which are 1) general ARP header stuff 2) match specific
90 stuff 3) the target to perform if the rule matches */
95 /* Size of arpt_entry + matches */
96 u_int16_t target_offset;
97 /* Size of arpt_entry + matches + target */
98 u_int16_t next_offset;
101 unsigned int comefrom;
103 /* Packet and byte counters. */
104 struct xt_counters counters;
106 /* The matches (if any), then the target. */
107 unsigned char elems[0];
111 * New IP firewall options for [gs]etsockopt at the RAW IP level.
112 * Unlike BSD Linux inherits IP options so you don't have to use a raw
113 * socket for this. Instead we check rights in the calls.
115 * ATTENTION: check linux/in.h before adding new number here.
117 #define ARPT_BASE_CTL 96
119 #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL)
120 #define ARPT_SO_SET_ADD_COUNTERS (ARPT_BASE_CTL + 1)
121 #define ARPT_SO_SET_MAX ARPT_SO_SET_ADD_COUNTERS
123 #define ARPT_SO_GET_INFO (ARPT_BASE_CTL)
124 #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1)
125 /* #define ARPT_SO_GET_REVISION_MATCH (APRT_BASE_CTL + 2) */
126 #define ARPT_SO_GET_REVISION_TARGET (ARPT_BASE_CTL + 3)
127 #define ARPT_SO_GET_MAX (ARPT_SO_GET_REVISION_TARGET)
129 /* CONTINUE verdict for targets */
130 #define ARPT_CONTINUE XT_CONTINUE
132 /* For standard target */
133 #define ARPT_RETURN XT_RETURN
135 /* The argument to ARPT_SO_GET_INFO */
136 struct arpt_getinfo {
137 /* Which table: caller fills this in. */
138 char name[XT_TABLE_MAXNAMELEN];
140 /* Kernel fills these in. */
141 /* Which hook entry points are valid: bitmask */
142 unsigned int valid_hooks;
144 /* Hook entry points: one per netfilter hook. */
145 unsigned int hook_entry[NF_ARP_NUMHOOKS];
147 /* Underflow points. */
148 unsigned int underflow[NF_ARP_NUMHOOKS];
150 /* Number of entries */
151 unsigned int num_entries;
153 /* Size of entries. */
157 /* The argument to ARPT_SO_SET_REPLACE. */
158 struct arpt_replace {
160 char name[XT_TABLE_MAXNAMELEN];
162 /* Which hook entry points are valid: bitmask. You can't
164 unsigned int valid_hooks;
166 /* Number of entries */
167 unsigned int num_entries;
169 /* Total size of new entries */
172 /* Hook entry points. */
173 unsigned int hook_entry[NF_ARP_NUMHOOKS];
175 /* Underflow points. */
176 unsigned int underflow[NF_ARP_NUMHOOKS];
178 /* Information about old entries: */
179 /* Number of counters (must be equal to current number of entries). */
180 unsigned int num_counters;
181 /* The old entries' counters. */
182 struct xt_counters __user *counters;
184 /* The entries (hang off end: not really an array). */
185 struct arpt_entry entries[0];
188 /* The argument to ARPT_SO_ADD_COUNTERS. */
189 #define arpt_counters_info xt_counters_info
190 #define arpt_counters xt_counters
192 /* The argument to ARPT_SO_GET_ENTRIES. */
193 struct arpt_get_entries {
194 /* Which table: user fills this in. */
195 char name[XT_TABLE_MAXNAMELEN];
197 /* User fills this in: total entry size. */
201 struct arpt_entry entrytable[0];
204 /* Standard return verdict, or do jump. */
205 #define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
207 #define ARPT_ERROR_TARGET XT_ERROR_TARGET
209 /* Helper functions */
210 static __inline__ struct xt_entry_target *arpt_get_target(struct arpt_entry *e)
212 return (void *)e + e->target_offset;
216 /* fn returns 0 to continue iteration */
217 #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
218 XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args)
222 * Main firewall chains definitions and global var's definitions.
226 /* Standard entry. */
227 struct arpt_standard {
228 struct arpt_entry entry;
229 struct xt_standard_target target;
232 struct arpt_error_target {
233 struct xt_entry_target target;
234 char errorname[XT_FUNCTION_MAXNAMELEN];
238 struct arpt_entry entry;
239 struct arpt_error_target target;
242 #define ARPT_ENTRY_INIT(__size) \
244 .target_offset = sizeof(struct arpt_entry), \
245 .next_offset = (__size), \
248 #define ARPT_STANDARD_INIT(__verdict) \
250 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \
251 .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \
252 sizeof(struct xt_standard_target)), \
253 .target.verdict = -(__verdict) - 1, \
256 #define ARPT_ERROR_INIT \
258 .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \
259 .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \
260 sizeof(struct arpt_error_target)), \
261 .target.errorname = "ERROR", \
264 extern void *arpt_alloc_initial_table(const struct xt_table *);
265 extern struct xt_table *arpt_register_table(struct net *net,
266 const struct xt_table *table,
267 const struct arpt_replace *repl);
268 extern void arpt_unregister_table(struct xt_table *table);
269 extern unsigned int arpt_do_table(struct sk_buff *skb,
271 const struct net_device *in,
272 const struct net_device *out,
273 struct xt_table *table);
275 #define ARPT_ALIGN(s) XT_ALIGN(s)
278 #include <net/compat.h>
280 struct compat_arpt_entry {
282 u_int16_t target_offset;
283 u_int16_t next_offset;
284 compat_uint_t comefrom;
285 struct compat_xt_counters counters;
286 unsigned char elems[0];
289 static inline struct xt_entry_target *
290 compat_arpt_get_target(struct compat_arpt_entry *e)
292 return (void *)e + e->target_offset;
295 #define COMPAT_ARPT_ALIGN(s) COMPAT_XT_ALIGN(s)
297 #endif /* CONFIG_COMPAT */
298 #endif /*__KERNEL__*/
299 #endif /* _ARPTABLES_H */