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).
14 #include <linux/types.h>
16 #include <linux/if_arp.h>
17 #include <linux/skbuff.h>
19 #include <linux/compiler.h>
20 #include <linux/netfilter_arp.h>
22 #include <linux/netfilter/x_tables.h>
24 #define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN
25 #define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN
26 #define arpt_target xt_target
27 #define arpt_table xt_table
29 #define ARPT_DEV_ADDR_LEN_MAX 16
31 struct arpt_devaddr_info
{
32 char addr
[ARPT_DEV_ADDR_LEN_MAX
];
33 char mask
[ARPT_DEV_ADDR_LEN_MAX
];
36 /* Yes, Virginia, you have to zero the padding. */
38 /* Source and target IP addr */
39 struct in_addr src
, tgt
;
40 /* Mask for src and target IP addr */
41 struct in_addr smsk
, tmsk
;
43 /* Device hw address length, src+target device addresses */
44 u_int8_t arhln
, arhln_mask
;
45 struct arpt_devaddr_info src_devaddr
;
46 struct arpt_devaddr_info tgt_devaddr
;
48 /* ARP operation code. */
49 u_int16_t arpop
, arpop_mask
;
51 /* ARP hardware address and protocol address format. */
52 u_int16_t arhrd
, arhrd_mask
;
53 u_int16_t arpro
, arpro_mask
;
55 /* The protocol address length is only accepted if it is 4
56 * so there is no use in offering a way to do filtering on it.
59 char iniface
[IFNAMSIZ
], outiface
[IFNAMSIZ
];
60 unsigned char iniface_mask
[IFNAMSIZ
], outiface_mask
[IFNAMSIZ
];
68 #define arpt_entry_target xt_entry_target
69 #define arpt_standard_target xt_standard_target
71 /* Values for "flag" field in struct arpt_ip (general arp structure).
72 * No flags defined yet.
74 #define ARPT_F_MASK 0x00 /* All possible flag bits mask. */
76 /* Values for "inv" field in struct arpt_arp. */
77 #define ARPT_INV_VIA_IN 0x0001 /* Invert the sense of IN IFACE. */
78 #define ARPT_INV_VIA_OUT 0x0002 /* Invert the sense of OUT IFACE */
79 #define ARPT_INV_SRCIP 0x0004 /* Invert the sense of SRC IP. */
80 #define ARPT_INV_TGTIP 0x0008 /* Invert the sense of TGT IP. */
81 #define ARPT_INV_SRCDEVADDR 0x0010 /* Invert the sense of SRC DEV ADDR. */
82 #define ARPT_INV_TGTDEVADDR 0x0020 /* Invert the sense of TGT DEV ADDR. */
83 #define ARPT_INV_ARPOP 0x0040 /* Invert the sense of ARP OP. */
84 #define ARPT_INV_ARPHRD 0x0080 /* Invert the sense of ARP HRD. */
85 #define ARPT_INV_ARPPRO 0x0100 /* Invert the sense of ARP PRO. */
86 #define ARPT_INV_ARPHLN 0x0200 /* Invert the sense of ARP HLN. */
87 #define ARPT_INV_MASK 0x03FF /* All possible flag bits mask. */
89 /* This structure defines each of the firewall rules. Consists of 3
90 parts which are 1) general ARP header stuff 2) match specific
91 stuff 3) the target to perform if the rule matches */
96 /* Size of arpt_entry + matches */
97 u_int16_t target_offset
;
98 /* Size of arpt_entry + matches + target */
99 u_int16_t next_offset
;
102 unsigned int comefrom
;
104 /* Packet and byte counters. */
105 struct xt_counters counters
;
107 /* The matches (if any), then the target. */
108 unsigned char elems
[0];
112 * New IP firewall options for [gs]etsockopt at the RAW IP level.
113 * Unlike BSD Linux inherits IP options so you don't have to use a raw
114 * socket for this. Instead we check rights in the calls.
116 #define ARPT_CTL_OFFSET 32
117 #define ARPT_BASE_CTL (XT_BASE_CTL+ARPT_CTL_OFFSET)
119 #define ARPT_SO_SET_REPLACE (XT_SO_SET_REPLACE+ARPT_CTL_OFFSET)
120 #define ARPT_SO_SET_ADD_COUNTERS (XT_SO_SET_ADD_COUNTERS+ARPT_CTL_OFFSET)
121 #define ARPT_SO_SET_MAX (XT_SO_SET_MAX+ARPT_CTL_OFFSET)
123 #define ARPT_SO_GET_INFO (XT_SO_GET_INFO+ARPT_CTL_OFFSET)
124 #define ARPT_SO_GET_ENTRIES (XT_SO_GET_ENTRIES+ARPT_CTL_OFFSET)
125 /* #define ARPT_SO_GET_REVISION_MATCH XT_SO_GET_REVISION_MATCH */
126 #define ARPT_SO_GET_REVISION_TARGET (XT_SO_GET_REVISION_TARGET+ARPT_CTL_OFFSET)
127 #define ARPT_SO_GET_MAX (XT_SO_GET_REVISION_TARGET+ARPT_CTL_OFFSET)
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 */
138 /* Which table: caller fills this in. */
139 char name
[ARPT_TABLE_MAXNAMELEN
];
141 /* Kernel fills these in. */
142 /* Which hook entry points are valid: bitmask */
143 unsigned int valid_hooks
;
145 /* Hook entry points: one per netfilter hook. */
146 unsigned int hook_entry
[NF_ARP_NUMHOOKS
];
148 /* Underflow points. */
149 unsigned int underflow
[NF_ARP_NUMHOOKS
];
151 /* Number of entries */
152 unsigned int num_entries
;
154 /* Size of entries. */
158 /* The argument to ARPT_SO_SET_REPLACE. */
162 char name
[ARPT_TABLE_MAXNAMELEN
];
164 /* Which hook entry points are valid: bitmask. You can't
166 unsigned int valid_hooks
;
168 /* Number of entries */
169 unsigned int num_entries
;
171 /* Total size of new entries */
174 /* Hook entry points. */
175 unsigned int hook_entry
[NF_ARP_NUMHOOKS
];
177 /* Underflow points. */
178 unsigned int underflow
[NF_ARP_NUMHOOKS
];
180 /* Information about old entries: */
181 /* Number of counters (must be equal to current number of entries). */
182 unsigned int num_counters
;
183 /* The old entries' counters. */
184 struct xt_counters __user
*counters
;
186 /* The entries (hang off end: not really an array). */
187 struct arpt_entry entries
[0];
190 /* The argument to ARPT_SO_ADD_COUNTERS. */
191 #define arpt_counters_info xt_counters_info
193 /* The argument to ARPT_SO_GET_ENTRIES. */
194 struct arpt_get_entries
196 /* Which table: user fills this in. */
197 char name
[ARPT_TABLE_MAXNAMELEN
];
199 /* User fills this in: total entry size. */
203 struct arpt_entry entrytable
[0];
206 /* Standard return verdict, or do jump. */
207 #define ARPT_STANDARD_TARGET XT_STANDARD_TARGET
209 #define ARPT_ERROR_TARGET XT_ERROR_TARGET
211 /* Helper functions */
212 static __inline__
struct arpt_entry_target
*arpt_get_target(struct arpt_entry
*e
)
214 return (void *)e
+ e
->target_offset
;
217 /* fn returns 0 to continue iteration */
218 #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \
222 struct arpt_entry *__entry; \
224 for (__i = 0; __i < (size); __i += __entry->next_offset) { \
225 __entry = (void *)(entries) + __i; \
227 __ret = fn(__entry , ## args); \
235 * Main firewall chains definitions and global var's definitions.
239 #define arpt_register_target(tgt) \
240 ({ (tgt)->family = NF_ARP; \
241 xt_register_target(tgt); })
242 #define arpt_unregister_target(tgt) xt_unregister_target(tgt)
244 extern int arpt_register_table(struct arpt_table
*table
,
245 const struct arpt_replace
*repl
);
246 extern void arpt_unregister_table(struct arpt_table
*table
);
247 extern unsigned int arpt_do_table(struct sk_buff
**pskb
,
249 const struct net_device
*in
,
250 const struct net_device
*out
,
251 struct arpt_table
*table
);
253 #define ARPT_ALIGN(s) (((s) + (__alignof__(struct arpt_entry)-1)) & ~(__alignof__(struct arpt_entry)-1))
254 #endif /*__KERNEL__*/
255 #endif /* _ARPTABLES_H */