Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 1 | #ifndef _X_TABLES_H |
| 2 | #define _X_TABLES_H |
Alexey Dobriyan | a79ff73 | 2010-04-13 11:21:46 +0200 | [diff] [blame] | 3 | #include <linux/kernel.h> |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 4 | #include <linux/types.h> |
| 5 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 6 | #define XT_FUNCTION_MAXNAMELEN 30 |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 7 | #define XT_EXTENSION_MAXNAMELEN 29 |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 8 | #define XT_TABLE_MAXNAMELEN 32 |
| 9 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 10 | struct xt_entry_match { |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 11 | union { |
| 12 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 13 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 14 | |
| 15 | /* Used by userspace */ |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 16 | char name[XT_EXTENSION_MAXNAMELEN]; |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 17 | __u8 revision; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 18 | } user; |
| 19 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 20 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 21 | |
| 22 | /* Used inside the kernel */ |
| 23 | struct xt_match *match; |
| 24 | } kernel; |
| 25 | |
| 26 | /* Total length */ |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 27 | __u16 match_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 28 | } u; |
| 29 | |
| 30 | unsigned char data[0]; |
| 31 | }; |
| 32 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 33 | struct xt_entry_target { |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 34 | union { |
| 35 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 36 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 37 | |
| 38 | /* Used by userspace */ |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 39 | char name[XT_EXTENSION_MAXNAMELEN]; |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 40 | __u8 revision; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 41 | } user; |
| 42 | struct { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 43 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 44 | |
| 45 | /* Used inside the kernel */ |
| 46 | struct xt_target *target; |
| 47 | } kernel; |
| 48 | |
| 49 | /* Total length */ |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 50 | __u16 target_size; |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 51 | } u; |
| 52 | |
| 53 | unsigned char data[0]; |
| 54 | }; |
| 55 | |
Patrick McHardy | 3c2ad46 | 2007-05-10 14:14:16 -0700 | [diff] [blame] | 56 | #define XT_TARGET_INIT(__name, __size) \ |
| 57 | { \ |
| 58 | .target.u.user = { \ |
| 59 | .target_size = XT_ALIGN(__size), \ |
| 60 | .name = __name, \ |
| 61 | }, \ |
| 62 | } |
| 63 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 64 | struct xt_standard_target { |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 65 | struct xt_entry_target target; |
| 66 | int verdict; |
| 67 | }; |
| 68 | |
Jan Engelhardt | 75f0a0f | 2010-10-13 16:37:45 +0200 | [diff] [blame] | 69 | struct xt_error_target { |
| 70 | struct xt_entry_target target; |
| 71 | char errorname[XT_FUNCTION_MAXNAMELEN]; |
| 72 | }; |
| 73 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 74 | /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision |
| 75 | * kernel supports, if >= revision. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 76 | struct xt_get_revision { |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 77 | char name[XT_EXTENSION_MAXNAMELEN]; |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 78 | __u8 revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 79 | }; |
| 80 | |
| 81 | /* CONTINUE verdict for targets */ |
| 82 | #define XT_CONTINUE 0xFFFFFFFF |
| 83 | |
| 84 | /* For standard target */ |
| 85 | #define XT_RETURN (-NF_REPEAT - 1) |
| 86 | |
David S. Miller | 6fbfc96 | 2006-01-20 11:57:07 -0800 | [diff] [blame] | 87 | /* this is a dummy structure to find out the alignment requirement for a struct |
| 88 | * containing all the fundamental data types that are used in ipt_entry, |
| 89 | * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my |
| 90 | * personal pleasure to remove it -HW |
| 91 | */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 92 | struct _xt_align { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 93 | __u8 u8; |
| 94 | __u16 u16; |
| 95 | __u32 u32; |
| 96 | __u64 u64; |
David S. Miller | 6fbfc96 | 2006-01-20 11:57:07 -0800 | [diff] [blame] | 97 | }; |
| 98 | |
Alexey Dobriyan | a79ff73 | 2010-04-13 11:21:46 +0200 | [diff] [blame] | 99 | #define XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _xt_align)) |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 100 | |
| 101 | /* Standard return verdict, or do jump. */ |
| 102 | #define XT_STANDARD_TARGET "" |
| 103 | /* Error verdict. */ |
| 104 | #define XT_ERROR_TARGET "ERROR" |
| 105 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 106 | #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0) |
| 107 | #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0) |
| 108 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 109 | struct xt_counters { |
Arnd Bergmann | 60c195c | 2009-02-26 00:51:43 +0100 | [diff] [blame] | 110 | __u64 pcnt, bcnt; /* Packet and byte counters */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 111 | }; |
| 112 | |
| 113 | /* The argument to IPT_SO_ADD_COUNTERS. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 114 | struct xt_counters_info { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 115 | /* Which table. */ |
| 116 | char name[XT_TABLE_MAXNAMELEN]; |
| 117 | |
| 118 | unsigned int num_counters; |
| 119 | |
| 120 | /* The counters (actually `number' of these). */ |
| 121 | struct xt_counters counters[0]; |
| 122 | }; |
| 123 | |
| 124 | #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */ |
| 125 | |
Jan Engelhardt | dcea992 | 2010-02-24 18:34:48 +0100 | [diff] [blame] | 126 | #ifndef __KERNEL__ |
Patrick McHardy | 89c002d | 2007-12-17 21:46:59 -0800 | [diff] [blame] | 127 | /* fn returns 0 to continue iteration */ |
| 128 | #define XT_MATCH_ITERATE(type, e, fn, args...) \ |
| 129 | ({ \ |
| 130 | unsigned int __i; \ |
| 131 | int __ret = 0; \ |
| 132 | struct xt_entry_match *__m; \ |
| 133 | \ |
| 134 | for (__i = sizeof(type); \ |
| 135 | __i < (e)->target_offset; \ |
| 136 | __i += __m->u.match_size) { \ |
| 137 | __m = (void *)e + __i; \ |
| 138 | \ |
| 139 | __ret = fn(__m , ## args); \ |
| 140 | if (__ret != 0) \ |
| 141 | break; \ |
| 142 | } \ |
| 143 | __ret; \ |
| 144 | }) |
| 145 | |
| 146 | /* fn returns 0 to continue iteration */ |
| 147 | #define XT_ENTRY_ITERATE_CONTINUE(type, entries, size, n, fn, args...) \ |
| 148 | ({ \ |
| 149 | unsigned int __i, __n; \ |
| 150 | int __ret = 0; \ |
| 151 | type *__entry; \ |
| 152 | \ |
| 153 | for (__i = 0, __n = 0; __i < (size); \ |
| 154 | __i += __entry->next_offset, __n++) { \ |
| 155 | __entry = (void *)(entries) + __i; \ |
| 156 | if (__n < n) \ |
| 157 | continue; \ |
| 158 | \ |
| 159 | __ret = fn(__entry , ## args); \ |
| 160 | if (__ret != 0) \ |
| 161 | break; \ |
| 162 | } \ |
| 163 | __ret; \ |
| 164 | }) |
| 165 | |
| 166 | /* fn returns 0 to continue iteration */ |
| 167 | #define XT_ENTRY_ITERATE(type, entries, size, fn, args...) \ |
| 168 | XT_ENTRY_ITERATE_CONTINUE(type, entries, size, 0, fn, args) |
| 169 | |
Jan Engelhardt | 72b2b1d | 2010-02-24 18:32:59 +0100 | [diff] [blame] | 170 | #endif /* !__KERNEL__ */ |
| 171 | |
| 172 | /* pos is normally a struct ipt_entry/ip6t_entry/etc. */ |
| 173 | #define xt_entry_foreach(pos, ehead, esize) \ |
| 174 | for ((pos) = (typeof(pos))(ehead); \ |
| 175 | (pos) < (typeof(pos))((char *)(ehead) + (esize)); \ |
| 176 | (pos) = (typeof(pos))((char *)(pos) + (pos)->next_offset)) |
| 177 | |
Jan Engelhardt | dcea992 | 2010-02-24 18:34:48 +0100 | [diff] [blame] | 178 | /* can only be xt_entry_match, so no use of typeof here */ |
| 179 | #define xt_ematch_foreach(pos, entry) \ |
| 180 | for ((pos) = (struct xt_entry_match *)entry->elems; \ |
| 181 | (pos) < (struct xt_entry_match *)((char *)(entry) + \ |
| 182 | (entry)->target_offset); \ |
| 183 | (pos) = (struct xt_entry_match *)((char *)(pos) + \ |
| 184 | (pos)->u.match_size)) |
| 185 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 186 | #ifdef __KERNEL__ |
| 187 | |
| 188 | #include <linux/netdevice.h> |
| 189 | |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 190 | /** |
Jan Engelhardt | de74c16 | 2009-07-05 18:26:37 +0200 | [diff] [blame] | 191 | * struct xt_action_param - parameters for matches/targets |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 192 | * |
Jan Engelhardt | de74c16 | 2009-07-05 18:26:37 +0200 | [diff] [blame] | 193 | * @match: the match extension |
| 194 | * @target: the target extension |
| 195 | * @matchinfo: per-match data |
| 196 | * @targetinfo: per-target data |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 197 | * @in: input netdevice |
| 198 | * @out: output netdevice |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 199 | * @fragoff: packet is a fragment, this is the data offset |
| 200 | * @thoff: position of transport header relative to skb->data |
Evgeniy Polyakov | a5e7882 | 2009-06-04 16:54:42 +0200 | [diff] [blame] | 201 | * @hook: hook number given packet came from |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 202 | * @family: Actual NFPROTO_* through which the function is invoked |
| 203 | * (helpful when match->family == NFPROTO_UNSPEC) |
Jan Engelhardt | b4ba261 | 2009-07-07 20:54:30 +0200 | [diff] [blame] | 204 | * |
| 205 | * Fields written to by extensions: |
| 206 | * |
Evgeniy Polyakov | a5e7882 | 2009-06-04 16:54:42 +0200 | [diff] [blame] | 207 | * @hotdrop: drop packet if we had inspection problems |
Jan Engelhardt | 1659978 | 2010-03-18 10:30:44 +0100 | [diff] [blame] | 208 | * Network namespace obtainable using dev_net(in/out) |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 209 | */ |
Jan Engelhardt | de74c16 | 2009-07-05 18:26:37 +0200 | [diff] [blame] | 210 | struct xt_action_param { |
| 211 | union { |
| 212 | const struct xt_match *match; |
| 213 | const struct xt_target *target; |
| 214 | }; |
| 215 | union { |
| 216 | const void *matchinfo, *targinfo; |
| 217 | }; |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 218 | const struct net_device *in, *out; |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 219 | int fragoff; |
| 220 | unsigned int thoff; |
Evgeniy Polyakov | a5e7882 | 2009-06-04 16:54:42 +0200 | [diff] [blame] | 221 | unsigned int hooknum; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 222 | u_int8_t family; |
Jan Engelhardt | b4ba261 | 2009-07-07 20:54:30 +0200 | [diff] [blame] | 223 | bool hotdrop; |
Jan Engelhardt | f7108a2 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 224 | }; |
| 225 | |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 226 | /** |
| 227 | * struct xt_mtchk_param - parameters for match extensions' |
| 228 | * checkentry functions |
| 229 | * |
Jan Engelhardt | 1659978 | 2010-03-18 10:30:44 +0100 | [diff] [blame] | 230 | * @net: network namespace through which the check was invoked |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 231 | * @table: table the rule is tried to be inserted into |
| 232 | * @entryinfo: the family-specific rule data |
Jan Engelhardt | 1659978 | 2010-03-18 10:30:44 +0100 | [diff] [blame] | 233 | * (struct ipt_ip, ip6t_ip, arpt_arp or (note) ebt_entry) |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 234 | * @match: struct xt_match through which this function was invoked |
| 235 | * @matchinfo: per-match data |
| 236 | * @hook_mask: via which hooks the new rule is reachable |
Jan Engelhardt | 1659978 | 2010-03-18 10:30:44 +0100 | [diff] [blame] | 237 | * Other fields as above. |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 238 | */ |
| 239 | struct xt_mtchk_param { |
Alexey Dobriyan | a83d8e8 | 2010-01-18 08:21:13 +0100 | [diff] [blame] | 240 | struct net *net; |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 241 | const char *table; |
| 242 | const void *entryinfo; |
| 243 | const struct xt_match *match; |
| 244 | void *matchinfo; |
| 245 | unsigned int hook_mask; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 246 | u_int8_t family; |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 247 | }; |
| 248 | |
Jan Engelhardt | 1659978 | 2010-03-18 10:30:44 +0100 | [diff] [blame] | 249 | /** |
| 250 | * struct xt_mdtor_param - match destructor parameters |
| 251 | * Fields as above. |
| 252 | */ |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 253 | struct xt_mtdtor_param { |
Alexey Dobriyan | f54e936 | 2010-01-18 08:25:47 +0100 | [diff] [blame] | 254 | struct net *net; |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 255 | const struct xt_match *match; |
| 256 | void *matchinfo; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 257 | u_int8_t family; |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 258 | }; |
| 259 | |
Jan Engelhardt | 7eb3558 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 260 | /** |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 261 | * struct xt_tgchk_param - parameters for target extensions' |
| 262 | * checkentry functions |
| 263 | * |
| 264 | * @entryinfo: the family-specific rule data |
| 265 | * (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry) |
| 266 | * |
| 267 | * Other fields see above. |
| 268 | */ |
| 269 | struct xt_tgchk_param { |
Patrick McHardy | add6746 | 2010-02-03 13:45:12 +0100 | [diff] [blame] | 270 | struct net *net; |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 271 | const char *table; |
Jan Engelhardt | f79fca5 | 2008-11-24 16:06:17 -0800 | [diff] [blame] | 272 | const void *entryinfo; |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 273 | const struct xt_target *target; |
| 274 | void *targinfo; |
| 275 | unsigned int hook_mask; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 276 | u_int8_t family; |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 277 | }; |
| 278 | |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 279 | /* Target destructor parameters */ |
| 280 | struct xt_tgdtor_param { |
Patrick McHardy | add6746 | 2010-02-03 13:45:12 +0100 | [diff] [blame] | 281 | struct net *net; |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 282 | const struct xt_target *target; |
| 283 | void *targinfo; |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 284 | u_int8_t family; |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 285 | }; |
| 286 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 287 | struct xt_match { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 288 | struct list_head list; |
| 289 | |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 290 | const char name[XT_EXTENSION_MAXNAMELEN]; |
Richard Kennedy | daaf83d | 2009-01-12 00:06:11 +0000 | [diff] [blame] | 291 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 292 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 293 | /* Return true or false: return FALSE and set *hotdrop = 1 to |
| 294 | force immediate packet drop. */ |
| 295 | /* Arguments changed since 2.6.9, as this must now handle |
| 296 | non-linear skb, using skb_header_pointer and |
| 297 | skb_ip_make_writable. */ |
Jan Engelhardt | 1d93a9c | 2007-07-07 22:15:35 -0700 | [diff] [blame] | 298 | bool (*match)(const struct sk_buff *skb, |
Jan Engelhardt | 62fc805 | 2009-07-07 20:42:08 +0200 | [diff] [blame] | 299 | struct xt_action_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 300 | |
| 301 | /* Called when user tries to insert an entry of this type. */ |
Jan Engelhardt | b0f3845 | 2010-03-19 17:16:42 +0100 | [diff] [blame] | 302 | int (*checkentry)(const struct xt_mtchk_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 303 | |
| 304 | /* Called when entry of this type deleted. */ |
Jan Engelhardt | 6be3d85 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 305 | void (*destroy)(const struct xt_mtdtor_param *); |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 306 | #ifdef CONFIG_COMPAT |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 307 | /* Called when userspace align differs from kernel space one */ |
Jan Engelhardt | 739674f | 2009-06-26 08:23:19 +0200 | [diff] [blame] | 308 | void (*compat_from_user)(void *dst, const void *src); |
| 309 | int (*compat_to_user)(void __user *dst, const void *src); |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 310 | #endif |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 311 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 312 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 313 | |
Jan Engelhardt | ecb6f85 | 2008-01-31 03:54:47 -0800 | [diff] [blame] | 314 | const char *table; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 315 | unsigned int matchsize; |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 316 | #ifdef CONFIG_COMPAT |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 317 | unsigned int compatsize; |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 318 | #endif |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 319 | unsigned int hooks; |
| 320 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 321 | |
| 322 | unsigned short family; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 323 | }; |
| 324 | |
| 325 | /* Registration hooks for targets. */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 326 | struct xt_target { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 327 | struct list_head list; |
| 328 | |
Jan Engelhardt | 4b2cbd4 | 2010-04-27 15:34:34 +0200 | [diff] [blame] | 329 | const char name[XT_EXTENSION_MAXNAMELEN]; |
Jan Engelhardt | f5c511c | 2010-03-18 14:02:10 +0100 | [diff] [blame] | 330 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 331 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 332 | /* Returns verdict. Argument order changed since 2.6.9, as this |
| 333 | must now handle non-linear skbs, using skb_copy_bits and |
| 334 | skb_ip_make_writable. */ |
Herbert Xu | 3db05fe | 2007-10-15 00:53:15 -0700 | [diff] [blame] | 335 | unsigned int (*target)(struct sk_buff *skb, |
Jan Engelhardt | de74c16 | 2009-07-05 18:26:37 +0200 | [diff] [blame] | 336 | const struct xt_action_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 337 | |
| 338 | /* Called when user tries to insert an entry of this type: |
| 339 | hook_mask is a bitmask of hooks from which it can be |
| 340 | called. */ |
Luciano Coelho | 7ea7b85 | 2010-05-20 15:59:16 +0200 | [diff] [blame] | 341 | /* Should return 0 on success or an error code otherwise (-Exxxx). */ |
Jan Engelhardt | 135367b | 2010-03-19 17:16:42 +0100 | [diff] [blame] | 342 | int (*checkentry)(const struct xt_tgchk_param *); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 343 | |
| 344 | /* Called when entry of this type deleted. */ |
Jan Engelhardt | a2df164 | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 345 | void (*destroy)(const struct xt_tgdtor_param *); |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 346 | #ifdef CONFIG_COMPAT |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 347 | /* Called when userspace align differs from kernel space one */ |
Jan Engelhardt | 739674f | 2009-06-26 08:23:19 +0200 | [diff] [blame] | 348 | void (*compat_from_user)(void *dst, const void *src); |
| 349 | int (*compat_to_user)(void __user *dst, const void *src); |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 350 | #endif |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 351 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 352 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 353 | |
Jan Engelhardt | ecb6f85 | 2008-01-31 03:54:47 -0800 | [diff] [blame] | 354 | const char *table; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 355 | unsigned int targetsize; |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 356 | #ifdef CONFIG_COMPAT |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 357 | unsigned int compatsize; |
Alexey Dobriyan | c30f540 | 2010-02-02 15:03:24 +0100 | [diff] [blame] | 358 | #endif |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 359 | unsigned int hooks; |
| 360 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 361 | |
| 362 | unsigned short family; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 363 | }; |
| 364 | |
| 365 | /* Furniture shopping... */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 366 | struct xt_table { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 367 | struct list_head list; |
| 368 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 369 | /* What hooks you will enter on */ |
| 370 | unsigned int valid_hooks; |
| 371 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 372 | /* Man behind the curtain... */ |
Stephen Hemminger | 4a2f965 | 2009-02-18 16:29:44 +0100 | [diff] [blame] | 373 | struct xt_table_info *private; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 374 | |
| 375 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 376 | struct module *me; |
| 377 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 378 | u_int8_t af; /* address/protocol family */ |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 379 | int priority; /* hook order */ |
Stephen Hemminger | 4a2f965 | 2009-02-18 16:29:44 +0100 | [diff] [blame] | 380 | |
| 381 | /* A unique name... */ |
| 382 | const char name[XT_TABLE_MAXNAMELEN]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 383 | }; |
| 384 | |
| 385 | #include <linux/netfilter_ipv4.h> |
| 386 | |
| 387 | /* The table itself */ |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 388 | struct xt_table_info { |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 389 | /* Size per table */ |
| 390 | unsigned int size; |
| 391 | /* Number of entries: FIXME. --RR */ |
| 392 | unsigned int number; |
| 393 | /* Initial number of entries. Needed for module usage count */ |
| 394 | unsigned int initial_entries; |
| 395 | |
| 396 | /* Entry points and underflows */ |
Patrick McHardy | 6e23ae2 | 2007-11-19 18:53:30 -0800 | [diff] [blame] | 397 | unsigned int hook_entry[NF_INET_NUMHOOKS]; |
| 398 | unsigned int underflow[NF_INET_NUMHOOKS]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 399 | |
Jan Engelhardt | f3c5c1b | 2010-04-19 16:05:10 +0200 | [diff] [blame] | 400 | /* |
| 401 | * Number of user chains. Since tables cannot have loops, at most |
| 402 | * @stacksize jumps (number of user chains) can possibly be made. |
| 403 | */ |
| 404 | unsigned int stacksize; |
Eric Dumazet | 7489aec | 2010-05-31 16:41:35 +0200 | [diff] [blame] | 405 | unsigned int __percpu *stackptr; |
Jan Engelhardt | f3c5c1b | 2010-04-19 16:05:10 +0200 | [diff] [blame] | 406 | void ***jumpstack; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 407 | /* ipt_entry tables: one per CPU */ |
Eric Dumazet | 259d4e4 | 2007-12-04 23:24:56 -0800 | [diff] [blame] | 408 | /* Note : this field MUST be the last one, see XT_TABLE_INFO_SZ */ |
Stephen Hemminger | 7845447 | 2009-02-20 10:35:32 +0100 | [diff] [blame] | 409 | void *entries[1]; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 410 | }; |
| 411 | |
Eric Dumazet | 259d4e4 | 2007-12-04 23:24:56 -0800 | [diff] [blame] | 412 | #define XT_TABLE_INFO_SZ (offsetof(struct xt_table_info, entries) \ |
| 413 | + nr_cpu_ids * sizeof(char *)) |
Pablo Neira Ayuso | a45049c | 2006-03-22 13:55:40 -0800 | [diff] [blame] | 414 | extern int xt_register_target(struct xt_target *target); |
| 415 | extern void xt_unregister_target(struct xt_target *target); |
Patrick McHardy | 52d9c42 | 2006-08-22 00:33:45 -0700 | [diff] [blame] | 416 | extern int xt_register_targets(struct xt_target *target, unsigned int n); |
| 417 | extern void xt_unregister_targets(struct xt_target *target, unsigned int n); |
| 418 | |
Pablo Neira Ayuso | a45049c | 2006-03-22 13:55:40 -0800 | [diff] [blame] | 419 | extern int xt_register_match(struct xt_match *target); |
| 420 | extern void xt_unregister_match(struct xt_match *target); |
Patrick McHardy | 52d9c42 | 2006-08-22 00:33:45 -0700 | [diff] [blame] | 421 | extern int xt_register_matches(struct xt_match *match, unsigned int n); |
| 422 | extern void xt_unregister_matches(struct xt_match *match, unsigned int n); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 423 | |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 424 | extern int xt_check_match(struct xt_mtchk_param *, |
Jan Engelhardt | 9b4fce7 | 2008-10-08 11:35:18 +0200 | [diff] [blame] | 425 | unsigned int size, u_int8_t proto, bool inv_proto); |
Jan Engelhardt | 916a917 | 2008-10-08 11:35:20 +0200 | [diff] [blame] | 426 | extern int xt_check_target(struct xt_tgchk_param *, |
Jan Engelhardt | af5d6dc | 2008-10-08 11:35:19 +0200 | [diff] [blame] | 427 | unsigned int size, u_int8_t proto, bool inv_proto); |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 428 | |
Alexey Dobriyan | 8d87005 | 2008-01-31 04:02:13 -0800 | [diff] [blame] | 429 | extern struct xt_table *xt_register_table(struct net *net, |
Jan Engelhardt | 35aad0f | 2009-08-24 14:56:30 +0200 | [diff] [blame] | 430 | const struct xt_table *table, |
Alexey Dobriyan | a98da11 | 2008-01-31 04:01:49 -0800 | [diff] [blame] | 431 | struct xt_table_info *bootstrap, |
| 432 | struct xt_table_info *newinfo); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 433 | extern void *xt_unregister_table(struct xt_table *table); |
| 434 | |
| 435 | extern struct xt_table_info *xt_replace_table(struct xt_table *table, |
| 436 | unsigned int num_counters, |
| 437 | struct xt_table_info *newinfo, |
| 438 | int *error); |
| 439 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 440 | extern struct xt_match *xt_find_match(u8 af, const char *name, u8 revision); |
| 441 | extern struct xt_target *xt_find_target(u8 af, const char *name, u8 revision); |
Jan Engelhardt | fd0ec0e | 2009-07-10 19:27:47 +0200 | [diff] [blame] | 442 | extern struct xt_match *xt_request_find_match(u8 af, const char *name, |
| 443 | u8 revision); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 444 | extern struct xt_target *xt_request_find_target(u8 af, const char *name, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 445 | u8 revision); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 446 | extern int xt_find_revision(u8 af, const char *name, u8 revision, |
| 447 | int target, int *err); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 448 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 449 | extern struct xt_table *xt_find_table_lock(struct net *net, u_int8_t af, |
Alexey Dobriyan | 8d87005 | 2008-01-31 04:02:13 -0800 | [diff] [blame] | 450 | const char *name); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 451 | extern void xt_table_unlock(struct xt_table *t); |
| 452 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 453 | extern int xt_proto_init(struct net *net, u_int8_t af); |
| 454 | extern void xt_proto_fini(struct net *net, u_int8_t af); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 455 | |
| 456 | extern struct xt_table_info *xt_alloc_table_info(unsigned int size); |
| 457 | extern void xt_free_table_info(struct xt_table_info *info); |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 458 | |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 459 | /** |
| 460 | * xt_recseq - recursive seqcount for netfilter use |
| 461 | * |
| 462 | * Packet processing changes the seqcount only if no recursion happened |
| 463 | * get_counters() can use read_seqcount_begin()/read_seqcount_retry(), |
| 464 | * because we use the normal seqcount convention : |
| 465 | * Low order bit set to 1 if a writer is active. |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 466 | */ |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 467 | DECLARE_PER_CPU(seqcount_t, xt_recseq); |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 468 | |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 469 | /** |
| 470 | * xt_write_recseq_begin - start of a write section |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 471 | * |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 472 | * Begin packet processing : all readers must wait the end |
| 473 | * 1) Must be called with preemption disabled |
| 474 | * 2) softirqs must be disabled too (or we should use irqsafe_cpu_add()) |
| 475 | * Returns : |
| 476 | * 1 if no recursion on this cpu |
| 477 | * 0 if recursion detected |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 478 | */ |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 479 | static inline unsigned int xt_write_recseq_begin(void) |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 480 | { |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 481 | unsigned int addend; |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 482 | |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 483 | /* |
| 484 | * Low order bit of sequence is set if we already |
| 485 | * called xt_write_recseq_begin(). |
| 486 | */ |
| 487 | addend = (__this_cpu_read(xt_recseq.sequence) + 1) & 1; |
| 488 | |
| 489 | /* |
| 490 | * This is kind of a write_seqcount_begin(), but addend is 0 or 1 |
| 491 | * We dont check addend value to avoid a test and conditional jump, |
| 492 | * since addend is most likely 1 |
| 493 | */ |
| 494 | __this_cpu_add(xt_recseq.sequence, addend); |
| 495 | smp_wmb(); |
| 496 | |
| 497 | return addend; |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 498 | } |
| 499 | |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 500 | /** |
| 501 | * xt_write_recseq_end - end of a write section |
| 502 | * @addend: return value from previous xt_write_recseq_begin() |
| 503 | * |
| 504 | * End packet processing : all readers can proceed |
| 505 | * 1) Must be called with preemption disabled |
| 506 | * 2) softirqs must be disabled too (or we should use irqsafe_cpu_add()) |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 507 | */ |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 508 | static inline void xt_write_recseq_end(unsigned int addend) |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 509 | { |
Eric Dumazet | 7f5c6d4 | 2011-04-04 17:04:03 +0200 | [diff] [blame] | 510 | /* this is kind of a write_seqcount_end(), but addend is 0 or 1 */ |
| 511 | smp_wmb(); |
| 512 | __this_cpu_add(xt_recseq.sequence, addend); |
Stephen Hemminger | 942e4a2 | 2009-04-28 22:36:33 -0700 | [diff] [blame] | 513 | } |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 514 | |
Eric Dumazet | b8dfe49 | 2009-03-25 17:31:52 +0100 | [diff] [blame] | 515 | /* |
| 516 | * This helper is performance critical and must be inlined |
| 517 | */ |
| 518 | static inline unsigned long ifname_compare_aligned(const char *_a, |
| 519 | const char *_b, |
| 520 | const char *_mask) |
| 521 | { |
| 522 | const unsigned long *a = (const unsigned long *)_a; |
| 523 | const unsigned long *b = (const unsigned long *)_b; |
| 524 | const unsigned long *mask = (const unsigned long *)_mask; |
| 525 | unsigned long ret; |
| 526 | |
| 527 | ret = (a[0] ^ b[0]) & mask[0]; |
| 528 | if (IFNAMSIZ > sizeof(unsigned long)) |
| 529 | ret |= (a[1] ^ b[1]) & mask[1]; |
| 530 | if (IFNAMSIZ > 2 * sizeof(unsigned long)) |
| 531 | ret |= (a[2] ^ b[2]) & mask[2]; |
| 532 | if (IFNAMSIZ > 3 * sizeof(unsigned long)) |
| 533 | ret |= (a[3] ^ b[3]) & mask[3]; |
| 534 | BUILD_BUG_ON(IFNAMSIZ > 4 * sizeof(unsigned long)); |
| 535 | return ret; |
| 536 | } |
| 537 | |
Jan Engelhardt | 2b95efe | 2009-06-17 13:57:48 +0200 | [diff] [blame] | 538 | extern struct nf_hook_ops *xt_hook_link(const struct xt_table *, nf_hookfn *); |
| 539 | extern void xt_hook_unlink(const struct xt_table *, struct nf_hook_ops *); |
| 540 | |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 541 | #ifdef CONFIG_COMPAT |
| 542 | #include <net/compat.h> |
| 543 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 544 | struct compat_xt_entry_match { |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 545 | union { |
| 546 | struct { |
| 547 | u_int16_t match_size; |
| 548 | char name[XT_FUNCTION_MAXNAMELEN - 1]; |
| 549 | u_int8_t revision; |
| 550 | } user; |
Patrick McHardy | 46c5ea3c | 2006-05-02 05:12:22 +0200 | [diff] [blame] | 551 | struct { |
| 552 | u_int16_t match_size; |
| 553 | compat_uptr_t match; |
| 554 | } kernel; |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 555 | u_int16_t match_size; |
| 556 | } u; |
| 557 | unsigned char data[0]; |
| 558 | }; |
| 559 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 560 | struct compat_xt_entry_target { |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 561 | union { |
| 562 | struct { |
| 563 | u_int16_t target_size; |
| 564 | char name[XT_FUNCTION_MAXNAMELEN - 1]; |
| 565 | u_int8_t revision; |
| 566 | } user; |
Patrick McHardy | 46c5ea3c | 2006-05-02 05:12:22 +0200 | [diff] [blame] | 567 | struct { |
| 568 | u_int16_t target_size; |
| 569 | compat_uptr_t target; |
| 570 | } kernel; |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 571 | u_int16_t target_size; |
| 572 | } u; |
| 573 | unsigned char data[0]; |
| 574 | }; |
| 575 | |
| 576 | /* FIXME: this works only on 32 bit tasks |
| 577 | * need to change whole approach in order to calculate align as function of |
| 578 | * current task alignment */ |
| 579 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 580 | struct compat_xt_counters { |
Alexey Dobriyan | 0a02604 | 2010-02-10 15:00:32 +0100 | [diff] [blame] | 581 | compat_u64 pcnt, bcnt; /* Packet and byte counters */ |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 582 | }; |
| 583 | |
Eric Dumazet | d94d9fe | 2009-11-04 09:50:58 -0800 | [diff] [blame] | 584 | struct compat_xt_counters_info { |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 585 | char name[XT_TABLE_MAXNAMELEN]; |
| 586 | compat_uint_t num_counters; |
| 587 | struct compat_xt_counters counters[0]; |
| 588 | }; |
| 589 | |
Alexey Dobriyan | 42107f5 | 2010-02-10 15:03:27 +0100 | [diff] [blame] | 590 | struct _compat_xt_align { |
| 591 | __u8 u8; |
| 592 | __u16 u16; |
| 593 | __u32 u32; |
| 594 | compat_u64 u64; |
| 595 | }; |
| 596 | |
Alexey Dobriyan | a79ff73 | 2010-04-13 11:21:46 +0200 | [diff] [blame] | 597 | #define COMPAT_XT_ALIGN(s) __ALIGN_KERNEL((s), __alignof__(struct _compat_xt_align)) |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 598 | |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 599 | extern void xt_compat_lock(u_int8_t af); |
| 600 | extern void xt_compat_unlock(u_int8_t af); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 601 | |
Eric Dumazet | 255d0dc | 2010-12-18 18:35:15 +0100 | [diff] [blame] | 602 | extern int xt_compat_add_offset(u_int8_t af, unsigned int offset, int delta); |
Jan Engelhardt | 76108ce | 2008-10-08 11:35:00 +0200 | [diff] [blame] | 603 | extern void xt_compat_flush_offsets(u_int8_t af); |
Eric Dumazet | 255d0dc | 2010-12-18 18:35:15 +0100 | [diff] [blame] | 604 | extern void xt_compat_init_offsets(u_int8_t af, unsigned int number); |
Florian Westphal | 3e5e524 | 2010-02-15 18:17:10 +0100 | [diff] [blame] | 605 | extern int xt_compat_calc_jump(u_int8_t af, unsigned int offset); |
Patrick McHardy | b386d9f | 2007-12-17 21:47:48 -0800 | [diff] [blame] | 606 | |
Jan Engelhardt | 5452e42 | 2008-04-14 11:15:35 +0200 | [diff] [blame] | 607 | extern int xt_compat_match_offset(const struct xt_match *match); |
Patrick McHardy | 8956695 | 2007-12-17 21:46:40 -0800 | [diff] [blame] | 608 | extern int xt_compat_match_from_user(struct xt_entry_match *m, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 609 | void **dstptr, unsigned int *size); |
Jan Engelhardt | 739674f | 2009-06-26 08:23:19 +0200 | [diff] [blame] | 610 | extern int xt_compat_match_to_user(const struct xt_entry_match *m, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 611 | void __user **dstptr, unsigned int *size); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 612 | |
Jan Engelhardt | 5452e42 | 2008-04-14 11:15:35 +0200 | [diff] [blame] | 613 | extern int xt_compat_target_offset(const struct xt_target *target); |
Patrick McHardy | 9fa492c | 2006-09-20 12:05:37 -0700 | [diff] [blame] | 614 | extern void xt_compat_target_from_user(struct xt_entry_target *t, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 615 | void **dstptr, unsigned int *size); |
Jan Engelhardt | 739674f | 2009-06-26 08:23:19 +0200 | [diff] [blame] | 616 | extern int xt_compat_target_to_user(const struct xt_entry_target *t, |
Patrick McHardy | b0a6363 | 2008-01-31 04:10:18 -0800 | [diff] [blame] | 617 | void __user **dstptr, unsigned int *size); |
Dmitry Mishin | 2722971 | 2006-04-01 02:25:19 -0800 | [diff] [blame] | 618 | |
| 619 | #endif /* CONFIG_COMPAT */ |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 620 | #endif /* __KERNEL__ */ |
| 621 | |
| 622 | #endif /* _X_TABLES_H */ |