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 | |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 24 | #ifndef __KERNEL__ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 25 | #define ARPT_FUNCTION_MAXNAMELEN XT_FUNCTION_MAXNAMELEN |
| 26 | #define ARPT_TABLE_MAXNAMELEN XT_TABLE_MAXNAMELEN |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 27 | #define arpt_entry_target xt_entry_target |
| 28 | #define arpt_standard_target xt_standard_target |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 29 | #endif |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 30 | |
| 31 | #define ARPT_DEV_ADDR_LEN_MAX 16 |
| 32 | |
| 33 | struct arpt_devaddr_info { |
| 34 | char addr[ARPT_DEV_ADDR_LEN_MAX]; |
| 35 | char mask[ARPT_DEV_ADDR_LEN_MAX]; |
| 36 | }; |
| 37 | |
| 38 | /* Yes, Virginia, you have to zero the padding. */ |
| 39 | struct arpt_arp { |
| 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; |
| 44 | |
| 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; |
| 49 | |
| 50 | /* ARP operation code. */ |
Al Viro | 59b8bfd | 2006-09-28 14:21:07 -0700 | [diff] [blame] | 51 | __be16 arpop, arpop_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 52 | |
| 53 | /* ARP hardware address and protocol address format. */ |
Al Viro | 59b8bfd | 2006-09-28 14:21:07 -0700 | [diff] [blame] | 54 | __be16 arhrd, arhrd_mask; |
| 55 | __be16 arpro, arpro_mask; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 56 | |
| 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. |
| 59 | */ |
| 60 | |
| 61 | char iniface[IFNAMSIZ], outiface[IFNAMSIZ]; |
| 62 | unsigned char iniface_mask[IFNAMSIZ], outiface_mask[IFNAMSIZ]; |
| 63 | |
| 64 | /* Flags word */ |
| 65 | u_int8_t flags; |
| 66 | /* Inverse flags */ |
| 67 | u_int16_t invflags; |
| 68 | }; |
| 69 | |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 70 | /* Values for "flag" field in struct arpt_ip (general arp structure). |
| 71 | * No flags defined yet. |
| 72 | */ |
| 73 | #define ARPT_F_MASK 0x00 /* All possible flag bits mask. */ |
| 74 | |
| 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. */ |
| 87 | |
| 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 */ |
| 91 | struct arpt_entry |
| 92 | { |
| 93 | struct arpt_arp arp; |
| 94 | |
| 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; |
| 99 | |
| 100 | /* Back pointer */ |
| 101 | unsigned int comefrom; |
| 102 | |
| 103 | /* Packet and byte counters. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 104 | struct xt_counters counters; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 105 | |
| 106 | /* The matches (if any), then the target. */ |
| 107 | unsigned char elems[0]; |
| 108 | }; |
| 109 | |
| 110 | /* |
| 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. |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 114 | * |
| 115 | * ATTENTION: check linux/in.h before adding new number here. |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 116 | */ |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 117 | #define ARPT_BASE_CTL 96 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 118 | |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 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 |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 122 | |
Yasuyuki Kozakai | b96e7ec | 2006-11-14 19:48:48 -0800 | [diff] [blame] | 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) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 128 | |
| 129 | /* CONTINUE verdict for targets */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 130 | #define ARPT_CONTINUE XT_CONTINUE |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 131 | |
| 132 | /* For standard target */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 133 | #define ARPT_RETURN XT_RETURN |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 134 | |
| 135 | /* The argument to ARPT_SO_GET_INFO */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 136 | struct arpt_getinfo { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 137 | /* Which table: caller fills this in. */ |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 138 | char name[XT_TABLE_MAXNAMELEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 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. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 158 | struct arpt_replace { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 159 | /* Which table. */ |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 160 | char name[XT_TABLE_MAXNAMELEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 161 | |
| 162 | /* Which hook entry points are valid: bitmask. You can't |
| 163 | change this. */ |
| 164 | unsigned int valid_hooks; |
| 165 | |
| 166 | /* Number of entries */ |
| 167 | unsigned int num_entries; |
| 168 | |
| 169 | /* Total size of new entries */ |
| 170 | unsigned int size; |
| 171 | |
| 172 | /* Hook entry points. */ |
| 173 | unsigned int hook_entry[NF_ARP_NUMHOOKS]; |
| 174 | |
| 175 | /* Underflow points. */ |
| 176 | unsigned int underflow[NF_ARP_NUMHOOKS]; |
| 177 | |
| 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. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 182 | struct xt_counters __user *counters; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 183 | |
| 184 | /* The entries (hang off end: not really an array). */ |
| 185 | struct arpt_entry entries[0]; |
| 186 | }; |
| 187 | |
| 188 | /* The argument to ARPT_SO_ADD_COUNTERS. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 189 | #define arpt_counters_info xt_counters_info |
Bart De Schuymer | 8c82d8d | 2007-01-09 14:33:11 -0800 | [diff] [blame] | 190 | #define arpt_counters xt_counters |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 191 | |
| 192 | /* The argument to ARPT_SO_GET_ENTRIES. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 193 | struct arpt_get_entries { |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 194 | /* Which table: user fills this in. */ |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 195 | char name[XT_TABLE_MAXNAMELEN]; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 196 | |
| 197 | /* User fills this in: total entry size. */ |
| 198 | unsigned int size; |
| 199 | |
| 200 | /* The entries. */ |
| 201 | struct arpt_entry entrytable[0]; |
| 202 | }; |
| 203 | |
| 204 | /* Standard return verdict, or do jump. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 205 | #define ARPT_STANDARD_TARGET XT_STANDARD_TARGET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 206 | /* Error verdict. */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 207 | #define ARPT_ERROR_TARGET XT_ERROR_TARGET |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 208 | |
| 209 | /* Helper functions */ |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 210 | static __inline__ struct xt_entry_target *arpt_get_target(struct arpt_entry *e) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 211 | { |
| 212 | return (void *)e + e->target_offset; |
| 213 | } |
| 214 | |
Jan Engelhardt | 72b2b1d | 2010-02-24 18:32:59 +0100 | [diff] [blame] | 215 | #ifndef __KERNEL__ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 216 | /* fn returns 0 to continue iteration */ |
Patrick McHardy | 89c002d | 2007-12-17 21:46:59 -0800 | [diff] [blame] | 217 | #define ARPT_ENTRY_ITERATE(entries, size, fn, args...) \ |
| 218 | XT_ENTRY_ITERATE(struct arpt_entry, entries, size, fn, ## args) |
Jan Engelhardt | 72b2b1d | 2010-02-24 18:32:59 +0100 | [diff] [blame] | 219 | #endif |
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. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 227 | struct arpt_standard { |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 228 | struct arpt_entry entry; |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 229 | struct xt_standard_target target; |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 230 | }; |
| 231 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 232 | struct arpt_error_target { |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 233 | struct xt_entry_target target; |
Jan Engelhardt | 12b00c2 | 2010-10-13 15:56:56 +0200 | [diff] [blame] | 234 | char errorname[XT_FUNCTION_MAXNAMELEN]; |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 235 | }; |
| 236 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 237 | struct arpt_error { |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 238 | struct arpt_entry entry; |
| 239 | struct arpt_error_target target; |
| 240 | }; |
| 241 | |
| 242 | #define ARPT_ENTRY_INIT(__size) \ |
| 243 | { \ |
| 244 | .target_offset = sizeof(struct arpt_entry), \ |
| 245 | .next_offset = (__size), \ |
| 246 | } |
| 247 | |
| 248 | #define ARPT_STANDARD_INIT(__verdict) \ |
| 249 | { \ |
| 250 | .entry = ARPT_ENTRY_INIT(sizeof(struct arpt_standard)), \ |
| 251 | .target = XT_TARGET_INIT(ARPT_STANDARD_TARGET, \ |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 252 | sizeof(struct xt_standard_target)), \ |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 253 | .target.verdict = -(__verdict) - 1, \ |
| 254 | } |
| 255 | |
| 256 | #define ARPT_ERROR_INIT \ |
| 257 | { \ |
| 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", \ |
| 262 | } |
| 263 | |
Jan Engelhardt | e3eaa99 | 2009-06-17 22:14:54 +0200 | [diff] [blame] | 264 | extern void *arpt_alloc_initial_table(const struct xt_table *); |
Jan Engelhardt | 4abff07 | 2008-04-14 11:15:43 +0200 | [diff] [blame] | 265 | extern struct xt_table *arpt_register_table(struct net *net, |
Jan Engelhardt | 35aad0f | 2009-08-24 14:56:30 +0200 | [diff] [blame] | 266 | const struct xt_table *table, |
Jan Engelhardt | 4abff07 | 2008-04-14 11:15:43 +0200 | [diff] [blame] | 267 | const struct arpt_replace *repl); |
| 268 | extern void arpt_unregister_table(struct xt_table *table); |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 269 | extern unsigned int arpt_do_table(struct sk_buff *skb, |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 270 | unsigned int hook, |
| 271 | const struct net_device *in, |
| 272 | const struct net_device *out, |
Jan Engelhardt | 4abff07 | 2008-04-14 11:15:43 +0200 | [diff] [blame] | 273 | struct xt_table *table); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 274 | |
Patrick McHardy | 0495cf9 | 2007-12-17 21:55:34 -0800 | [diff] [blame] | 275 | #define ARPT_ALIGN(s) XT_ALIGN(s) |
Patrick McHardy | d6a2ba0 | 2007-12-17 22:26:54 -0800 | [diff] [blame] | 276 | |
| 277 | #ifdef CONFIG_COMPAT |
| 278 | #include <net/compat.h> |
| 279 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 280 | struct compat_arpt_entry { |
Patrick McHardy | d6a2ba0 | 2007-12-17 22:26:54 -0800 | [diff] [blame] | 281 | struct arpt_arp arp; |
| 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]; |
| 287 | }; |
| 288 | |
Jan Engelhardt | 87a2e70d | 2010-10-13 16:11:22 +0200 | [diff] [blame^] | 289 | static inline struct xt_entry_target * |
Patrick McHardy | d6a2ba0 | 2007-12-17 22:26:54 -0800 | [diff] [blame] | 290 | compat_arpt_get_target(struct compat_arpt_entry *e) |
| 291 | { |
| 292 | return (void *)e + e->target_offset; |
| 293 | } |
| 294 | |
| 295 | #define COMPAT_ARPT_ALIGN(s) COMPAT_XT_ALIGN(s) |
| 296 | |
Patrick McHardy | d6a2ba0 | 2007-12-17 22:26:54 -0800 | [diff] [blame] | 297 | #endif /* CONFIG_COMPAT */ |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 298 | #endif /*__KERNEL__*/ |
| 299 | #endif /* _ARPTABLES_H */ |