Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * Format of an ARP firewall descriptor |
| 3 | * |
| 4 | * src, tgt, src_mask, tgt_mask, arpop, arpop_mask are always stored in |
| 5 | * network byte order. |
| 6 | * flags are stored in host byte order (of course). |
| 7 | */ |
| 8 | |
| 9 | #ifndef _ARPTABLES_H |
| 10 | #define _ARPTABLES_H |
| 11 | |
| 12 | #ifdef __KERNEL__ |
| 13 | #include <linux/if.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 14 | #include <linux/in.h> |
| 15 | #include <linux/if_arp.h> |
| 16 | #include <linux/skbuff.h> |
| 17 | #endif |
Patrick McHardy | c8942f1 | 2008-05-21 14:08:38 -0700 | [diff] [blame] | 18 | #include <linux/types.h> |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 19 | #include <linux/compiler.h> |
| 20 | #include <linux/netfilter_arp.h> |
| 21 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 22 | #include <linux/netfilter/x_tables.h> |
| 23 | |
| 24 | #define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN |
| 25 | #define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | #define ARPT_DEV_ADDR_LEN_MAX 16 |
| 28 | |
| 29 | struct arpt_devaddr_info { |
| 30 | char addr[ARPT_DEV_ADDR_LEN_MAX]; |
| 31 | char mask[ARPT_DEV_ADDR_LEN_MAX]; |
| 32 | }; |
| 33 | |
| 34 | /* Yes, Virginia, you have to zero the padding. */ |
| 35 | struct arpt_arp { |
| 36 | /* Source and target IP addr */ |
| 37 | struct in_addr src, tgt; |
| 38 | /* Mask for src and target IP addr */ |
| 39 | struct in_addr smsk, tmsk; |
| 40 | |
| 41 | /* Device hw address length, src+target device addresses */ |
| 42 | u_int8_t arhln, arhln_mask; |
| 43 | struct arpt_devaddr_info src_devaddr; |
| 44 | struct arpt_devaddr_info tgt_devaddr; |
| 45 | |
| 46 | /* ARP operation code. */ |
Al Viro | 59b8bfd | 2006-09-28 14:21:07 -0700 | [diff] [blame] | 47 | __be16 arpop, arpop_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 48 | |
| 49 | /* ARP hardware address and protocol address format. */ |
Al Viro | 59b8bfd | 2006-09-28 14:21:07 -0700 | [diff] [blame] | 50 | __be16 arhrd, arhrd_mask; |
| 51 | __be16 arpro, arpro_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* The protocol address length is only accepted if it is 4 |
| 54 | * so there is no use in offering a way to do filtering on it. |
| 55 | */ |
| 56 | |
| 57 | char iniface[IFNAMSIZ], outiface[IFNAMSIZ]; |
| 58 | unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ]; |
| 59 | |
| 60 | /* Flags word */ |
| 61 | u_int8_t flags; |
| 62 | /* Inverse flags */ |
| 63 | u_int16_t invflags; |
| 64 | }; |
| 65 | |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 66 | #define arpt_entry_target xt_entry_target |
| 67 | #define arpt_standard_target xt_standard_target |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 68 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 69 | /* Values for "flag" field in struct arpt_ip (general arp structure). |
| 70 | * No flags defined yet. |
| 71 | */ |
| 72 | #define ARPT_F_MASK 0x00 /* All possible flag bits mask. */ |
| 73 | |
| 74 | /* Values for "inv" field in struct arpt_arp. */ |
| 75 | #define ARPT_INV_VIA_IN 0x0001 /* Invert the sense of IN IFACE. */ |
| 76 | #define ARPT_INV_VIA_OUT 0x0002 /* Invert the sense of OUT IFACE */ |
| 77 | #define ARPT_INV_SRCIP 0x0004 /* Invert the sense of SRC IP. */ |
| 78 | #define ARPT_INV_TGTIP 0x0008 /* Invert the sense of TGT IP. */ |
| 79 | #define ARPT_INV_SRCDEVADDR 0x0010 /* Invert the sense of SRC DEV ADDR. */ |
| 80 | #define ARPT_INV_TGTDEVADDR 0x0020 /* Invert the sense of TGT DEV ADDR. */ |
| 81 | #define ARPT_INV_ARPOP 0x0040 /* Invert the sense of ARP OP. */ |
| 82 | #define ARPT_INV_ARPHRD 0x0080 /* Invert the sense of ARP HRD. */ |
| 83 | #define ARPT_INV_ARPPRO 0x0100 /* Invert the sense of ARP PRO. */ |
| 84 | #define ARPT_INV_ARPHLN 0x0200 /* Invert the sense of ARP HLN. */ |
| 85 | #define ARPT_INV_MASK 0x03FF /* All possible flag bits mask. */ |
| 86 | |
| 87 | /* This structure defines each of the firewall rules. Consists of 3 |
| 88 | parts which are 1) general ARP header stuff 2) match specific |
| 89 | stuff 3) the target to perform if the rule matches */ |
| 90 | struct arpt_entry |
| 91 | { |
| 92 | struct arpt_arp arp; |
| 93 | |
| 94 | /* Size of arpt_entry + matches */ |
| 95 | u_int16_t target_offset; |
| 96 | /* Size of arpt_entry + matches + target */ |
| 97 | u_int16_t next_offset; |
| 98 | |
| 99 | /* Back pointer */ |
| 100 | unsigned int comefrom; |
| 101 | |
| 102 | /* Packet and byte counters. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 103 | struct xt_counters counters; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 104 | |
| 105 | /* The matches (if any), then the target. */ |
| 106 | unsigned char elems[0]; |
| 107 | }; |
| 108 | |
| 109 | /* |
| 110 | * New IP firewall options for [gs]etsockopt at the RAW IP level. |
| 111 | * Unlike BSD Linux inherits IP options so you don't have to use a raw |
| 112 | * socket for this. Instead we check rights in the calls. |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 113 | * |
| 114 | * ATTENTION: check linux/in.h before adding new number here. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 115 | */ |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 116 | #define ARPT_BASE_CTL 96 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 117 | |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 118 | #define ARPT_SO_SET_REPLACE (ARPT_BASE_CTL) |
| 119 | #define ARPT_SO_SET_ADD_COUNTERS (ARPT_BASE_CTL + 1) |
| 120 | #define ARPT_SO_SET_MAX ARPT_SO_SET_ADD_COUNTERS |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 121 | |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 122 | #define ARPT_SO_GET_INFO (ARPT_BASE_CTL) |
| 123 | #define ARPT_SO_GET_ENTRIES (ARPT_BASE_CTL + 1) |
| 124 | /* #define ARPT_SO_GET_REVISION_MATCH (APRT_BASE_CTL + 2) */ |
| 125 | #define ARPT_SO_GET_REVISION_TARGET (ARPT_BASE_CTL + 3) |
| 126 | #define ARPT_SO_GET_MAX (ARPT_SO_GET_REVISION_TARGET) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 127 | |
| 128 | /* CONTINUE verdict for targets */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 129 | #define ARPT_CONTINUE XT_CONTINUE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 130 | |
| 131 | /* For standard target */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 132 | #define ARPT_RETURN XT_RETURN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 133 | |
| 134 | /* The argument to ARPT_SO_GET_INFO */ |
| 135 | struct arpt_getinfo |
| 136 | { |
| 137 | /* Which table: caller fills this in. */ |
| 138 | char name[ARPT_TABLE_MAXNAMELEN]; |
| 139 | |
| 140 | /* Kernel fills these in. */ |
| 141 | /* Which hook entry points are valid: bitmask */ |
| 142 | unsigned int valid_hooks; |
| 143 | |
| 144 | /* Hook entry points: one per netfilter hook. */ |
| 145 | unsigned int hook_entry[NF_ARP_NUMHOOKS]; |
| 146 | |
| 147 | /* Underflow points. */ |
| 148 | unsigned int underflow[NF_ARP_NUMHOOKS]; |
| 149 | |
| 150 | /* Number of entries */ |
| 151 | unsigned int num_entries; |
| 152 | |
| 153 | /* Size of entries. */ |
| 154 | unsigned int size; |
| 155 | }; |
| 156 | |
| 157 | /* The argument to ARPT_SO_SET_REPLACE. */ |
| 158 | struct arpt_replace |
| 159 | { |
| 160 | /* Which table. */ |
| 161 | char name[ARPT_TABLE_MAXNAMELEN]; |
| 162 | |
| 163 | /* Which hook entry points are valid: bitmask. You can't |
| 164 | change this. */ |
| 165 | unsigned int valid_hooks; |
| 166 | |
| 167 | /* Number of entries */ |
| 168 | unsigned int num_entries; |
| 169 | |
| 170 | /* Total size of new entries */ |
| 171 | unsigned int size; |
| 172 | |
| 173 | /* Hook entry points. */ |
| 174 | unsigned int hook_entry[NF_ARP_NUMHOOKS]; |
| 175 | |
| 176 | /* Underflow points. */ |
| 177 | unsigned int underflow[NF_ARP_NUMHOOKS]; |
| 178 | |
| 179 | /* Information about old entries: */ |
| 180 | /* Number of counters (must be equal to current number of entries). */ |
| 181 | unsigned int num_counters; |
| 182 | /* The old entries' counters. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 183 | struct xt_counters __user *counters; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 184 | |
| 185 | /* The entries (hang off end: not really an array). */ |
| 186 | struct arpt_entry entries[0]; |
| 187 | }; |
| 188 | |
| 189 | /* The argument to ARPT_SO_ADD_COUNTERS. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 190 | #define arpt_counters_info xt_counters_info |
Bart De Schuymer | 8c82d8d | 2007-01-09 14:33:11 -0800 | [diff] [blame] | 191 | #define arpt_counters xt_counters |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 192 | |
| 193 | /* The argument to ARPT_SO_GET_ENTRIES. */ |
| 194 | struct arpt_get_entries |
| 195 | { |
| 196 | /* Which table: user fills this in. */ |
| 197 | char name[ARPT_TABLE_MAXNAMELEN]; |
| 198 | |
| 199 | /* User fills this in: total entry size. */ |
| 200 | unsigned int size; |
| 201 | |
| 202 | /* The entries. */ |
| 203 | struct arpt_entry entrytable[0]; |
| 204 | }; |
| 205 | |
| 206 | /* Standard return verdict, or do jump. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 207 | #define ARPT_STANDARD_TARGET XT_STANDARD_TARGET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | /* Error verdict. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 209 | #define ARPT_ERROR_TARGET XT_ERROR_TARGET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 210 | |
| 211 | /* Helper functions */ |
| 212 | static __inline__ struct arpt_entry_target *arpt_get_target(struct arpt_entry *e) |
| 213 | { |
| 214 | return (void *)e + e->target_offset; |
| 215 | } |
| 216 | |
| 217 | /* fn returns 0 to continue iteration */ |
Patrick McHardy | 89c002d | 2007-12-17 21:46:59 -0800 | [diff] [blame] | 218 | #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ |
| 219 | XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 220 | |
| 221 | /* |
| 222 | * Main firewall chains definitions and global var's definitions. |
| 223 | */ |
| 224 | #ifdef __KERNEL__ |
| 225 | |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 226 | /* Standard entry. */ |
| 227 | struct arpt_standard |
| 228 | { |
| 229 | struct arpt_entry entry; |
| 230 | struct arpt_standard_target target; |
| 231 | }; |
| 232 | |
| 233 | struct arpt_error_target |
| 234 | { |
| 235 | struct arpt_entry_target target; |
| 236 | char errorname[ARPT_FUNCTION_MAXNAMELEN]; |
| 237 | }; |
| 238 | |
| 239 | struct arpt_error |
| 240 | { |
| 241 | struct arpt_entry entry; |
| 242 | struct arpt_error_target target; |
| 243 | }; |
| 244 | |
| 245 | #define ARPT_ENTRY_INIT(__size) \ |
| 246 | { \ |
| 247 | .target_offset = sizeof(struct arpt_entry), \ |
| 248 | .next_offset = (__size), \ |
| 249 | } |
| 250 | |
| 251 | #define ARPT_STANDARD_INIT(__verdict) \ |
| 252 | { \ |
| 253 | .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \ |
| 254 | .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \ |
| 255 | sizeof(struct arpt_standard_target)), \ |
| 256 | .target.verdict = -(__verdict) - 1, \ |
| 257 | } |
| 258 | |
| 259 | #define ARPT_ERROR_INIT \ |
| 260 | { \ |
| 261 | .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_error)), \ |
| 262 | .target = XT_TARGET_INIT(ARPT_ERROR_TARGET, \ |
| 263 | sizeof(struct arpt_error_target)), \ |
| 264 | .target.errorname = "ERROR", \ |
| 265 | } |
| 266 | |
Jan Engelhardt | 4abff07 | 2008-04-14 11:15:43 +0200 | [diff] [blame] | 267 | extern struct xt_table *arpt_register_table(struct net *net, |
| 268 | struct xt_table *table, |
| 269 | const struct arpt_replace *repl); |
| 270 | extern void arpt_unregister_table(struct xt_table *table); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 271 | extern unsigned int arpt_do_table(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 272 | unsigned int hook, |
| 273 | const struct net_device *in, |
| 274 | const struct net_device *out, |
Jan Engelhardt | 4abff07 | 2008-04-14 11:15:43 +0200 | [diff] [blame] | 275 | struct xt_table *table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 276 | |
Patrick McHardy | 0495cf9 | 2007-12-17 21:55:34 -0800 | [diff] [blame] | 277 | #define ARPT_ALIGN(s) XT_ALIGN(s) |
Patrick McHardy | d6a2ba0 | 2007-12-17 22:26:54 -0800 | [diff] [blame] | 278 | |
| 279 | #ifdef CONFIG_COMPAT |
| 280 | #include <net/compat.h> |
| 281 | |
| 282 | struct compat_arpt_entry |
| 283 | { |
| 284 | struct arpt_arp arp; |
| 285 | u_int16_t target_offset; |
| 286 | u_int16_t next_offset; |
| 287 | compat_uint_t comefrom; |
| 288 | struct compat_xt_counters counters; |
| 289 | unsigned char elems[0]; |
| 290 | }; |
| 291 | |
| 292 | static inline struct arpt_entry_target * |
| 293 | compat_arpt_get_target(struct compat_arpt_entry *e) |
| 294 | { |
| 295 | return (void *)e + e->target_offset; |
| 296 | } |
| 297 | |
| 298 | #define COMPAT_ARPT_ALIGN(s) COMPAT_XT_ALIGN(s) |
| 299 | |
| 300 | /* fn returns 0 to continue iteration */ |
| 301 | #define COMPAT_ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ |
| 302 | XT_ENTRY_ITERATE(struct compat_arpt_entry, entries, size, fn, ## args) |
| 303 | |
| 304 | #define COMPAT_ARPT_ENTRY_ITERATE_CONTINUE(entries, size, n, fn, args...) \ |
| 305 | XT_ENTRY_ITERATE_CONTINUE(struct compat_arpt_entry, entries, size, n, \ |
| 306 | fn, ## args) |
| 307 | |
| 308 | #endif /* CONFIG_COMPAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 309 | #endif /*__KERNEL__*/ |
| 310 | #endif /* _ARPTABLES_H */ |