Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 1 | #ifndef _X_TABLES_H |
| 2 | #define _X_TABLES_H |
| 3 | |
| 4 | #define XT_FUNCTION_MAXNAMELEN 30 |
| 5 | #define XT_TABLE_MAXNAMELEN 32 |
| 6 | |
Dmitry Mishin | 1e30a01 | 2006-03-22 13:56:56 -0800 | [diff] [blame] | 7 | struct xt_entry_match |
| 8 | { |
| 9 | union { |
| 10 | struct { |
| 11 | u_int16_t match_size; |
| 12 | |
| 13 | /* Used by userspace */ |
| 14 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 15 | |
| 16 | u_int8_t revision; |
| 17 | } user; |
| 18 | struct { |
| 19 | u_int16_t match_size; |
| 20 | |
| 21 | /* Used inside the kernel */ |
| 22 | struct xt_match *match; |
| 23 | } kernel; |
| 24 | |
| 25 | /* Total length */ |
| 26 | u_int16_t match_size; |
| 27 | } u; |
| 28 | |
| 29 | unsigned char data[0]; |
| 30 | }; |
| 31 | |
| 32 | struct xt_entry_target |
| 33 | { |
| 34 | union { |
| 35 | struct { |
| 36 | u_int16_t target_size; |
| 37 | |
| 38 | /* Used by userspace */ |
| 39 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 40 | |
| 41 | u_int8_t revision; |
| 42 | } user; |
| 43 | struct { |
| 44 | u_int16_t target_size; |
| 45 | |
| 46 | /* Used inside the kernel */ |
| 47 | struct xt_target *target; |
| 48 | } kernel; |
| 49 | |
| 50 | /* Total length */ |
| 51 | u_int16_t target_size; |
| 52 | } u; |
| 53 | |
| 54 | unsigned char data[0]; |
| 55 | }; |
| 56 | |
| 57 | struct xt_standard_target |
| 58 | { |
| 59 | struct xt_entry_target target; |
| 60 | int verdict; |
| 61 | }; |
| 62 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 63 | /* The argument to IPT_SO_GET_REVISION_*. Returns highest revision |
| 64 | * kernel supports, if >= revision. */ |
| 65 | struct xt_get_revision |
| 66 | { |
| 67 | char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 68 | |
| 69 | u_int8_t revision; |
| 70 | }; |
| 71 | |
| 72 | /* CONTINUE verdict for targets */ |
| 73 | #define XT_CONTINUE 0xFFFFFFFF |
| 74 | |
| 75 | /* For standard target */ |
| 76 | #define XT_RETURN (-NF_REPEAT - 1) |
| 77 | |
David S. Miller | 6fbfc96 | 2006-01-20 11:57:07 -0800 | [diff] [blame] | 78 | /* this is a dummy structure to find out the alignment requirement for a struct |
| 79 | * containing all the fundamental data types that are used in ipt_entry, |
| 80 | * ip6t_entry and arpt_entry. This sucks, and it is a hack. It will be my |
| 81 | * personal pleasure to remove it -HW |
| 82 | */ |
| 83 | struct _xt_align |
| 84 | { |
| 85 | u_int8_t u8; |
| 86 | u_int16_t u16; |
| 87 | u_int32_t u32; |
| 88 | u_int64_t u64; |
| 89 | }; |
| 90 | |
| 91 | #define XT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) \ |
| 92 | & ~(__alignof__(struct _xt_align)-1)) |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 93 | |
| 94 | /* Standard return verdict, or do jump. */ |
| 95 | #define XT_STANDARD_TARGET "" |
| 96 | /* Error verdict. */ |
| 97 | #define XT_ERROR_TARGET "ERROR" |
| 98 | |
| 99 | /* |
| 100 | * New IP firewall options for [gs]etsockopt at the RAW IP level. |
| 101 | * Unlike BSD Linux inherits IP options so you don't have to use a raw |
| 102 | * socket for this. Instead we check rights in the calls. */ |
| 103 | #define XT_BASE_CTL 64 /* base for firewall socket options */ |
| 104 | |
| 105 | #define XT_SO_SET_REPLACE (XT_BASE_CTL) |
| 106 | #define XT_SO_SET_ADD_COUNTERS (XT_BASE_CTL + 1) |
| 107 | #define XT_SO_SET_MAX XT_SO_SET_ADD_COUNTERS |
| 108 | |
| 109 | #define XT_SO_GET_INFO (XT_BASE_CTL) |
| 110 | #define XT_SO_GET_ENTRIES (XT_BASE_CTL + 1) |
| 111 | #define XT_SO_GET_REVISION_MATCH (XT_BASE_CTL + 2) |
| 112 | #define XT_SO_GET_REVISION_TARGET (XT_BASE_CTL + 3) |
| 113 | #define XT_SO_GET_MAX XT_SO_GET_REVISION_TARGET |
| 114 | |
| 115 | #define SET_COUNTER(c,b,p) do { (c).bcnt = (b); (c).pcnt = (p); } while(0) |
| 116 | #define ADD_COUNTER(c,b,p) do { (c).bcnt += (b); (c).pcnt += (p); } while(0) |
| 117 | |
| 118 | struct xt_counters |
| 119 | { |
| 120 | u_int64_t pcnt, bcnt; /* Packet and byte counters */ |
| 121 | }; |
| 122 | |
| 123 | /* The argument to IPT_SO_ADD_COUNTERS. */ |
| 124 | struct xt_counters_info |
| 125 | { |
| 126 | /* Which table. */ |
| 127 | char name[XT_TABLE_MAXNAMELEN]; |
| 128 | |
| 129 | unsigned int num_counters; |
| 130 | |
| 131 | /* The counters (actually `number' of these). */ |
| 132 | struct xt_counters counters[0]; |
| 133 | }; |
| 134 | |
| 135 | #define XT_INV_PROTO 0x40 /* Invert the sense of PROTO. */ |
| 136 | |
| 137 | #ifdef __KERNEL__ |
| 138 | |
| 139 | #include <linux/netdevice.h> |
| 140 | |
| 141 | #define ASSERT_READ_LOCK(x) |
| 142 | #define ASSERT_WRITE_LOCK(x) |
| 143 | #include <linux/netfilter_ipv4/listhelp.h> |
| 144 | |
| 145 | struct xt_match |
| 146 | { |
| 147 | struct list_head list; |
| 148 | |
| 149 | const char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 150 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 151 | /* Return true or false: return FALSE and set *hotdrop = 1 to |
| 152 | force immediate packet drop. */ |
| 153 | /* Arguments changed since 2.6.9, as this must now handle |
| 154 | non-linear skb, using skb_header_pointer and |
| 155 | skb_ip_make_writable. */ |
| 156 | int (*match)(const struct sk_buff *skb, |
| 157 | const struct net_device *in, |
| 158 | const struct net_device *out, |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 159 | const struct xt_match *match, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 160 | const void *matchinfo, |
| 161 | int offset, |
| 162 | unsigned int protoff, |
| 163 | int *hotdrop); |
| 164 | |
| 165 | /* Called when user tries to insert an entry of this type. */ |
| 166 | /* Should return true or false. */ |
| 167 | int (*checkentry)(const char *tablename, |
| 168 | const void *ip, |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 169 | const struct xt_match *match, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 170 | void *matchinfo, |
| 171 | unsigned int matchinfosize, |
| 172 | unsigned int hook_mask); |
| 173 | |
| 174 | /* Called when entry of this type deleted. */ |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 175 | void (*destroy)(const struct xt_match *match, void *matchinfo, |
| 176 | unsigned int matchinfosize); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 177 | |
| 178 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 179 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 180 | |
| 181 | char *table; |
| 182 | unsigned int matchsize; |
| 183 | unsigned int hooks; |
| 184 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 185 | |
| 186 | unsigned short family; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 187 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 188 | }; |
| 189 | |
| 190 | /* Registration hooks for targets. */ |
| 191 | struct xt_target |
| 192 | { |
| 193 | struct list_head list; |
| 194 | |
| 195 | const char name[XT_FUNCTION_MAXNAMELEN-1]; |
| 196 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 197 | /* Returns verdict. Argument order changed since 2.6.9, as this |
| 198 | must now handle non-linear skbs, using skb_copy_bits and |
| 199 | skb_ip_make_writable. */ |
| 200 | unsigned int (*target)(struct sk_buff **pskb, |
| 201 | const struct net_device *in, |
| 202 | const struct net_device *out, |
| 203 | unsigned int hooknum, |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 204 | const struct xt_target *target, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 205 | const void *targinfo, |
| 206 | void *userdata); |
| 207 | |
| 208 | /* Called when user tries to insert an entry of this type: |
| 209 | hook_mask is a bitmask of hooks from which it can be |
| 210 | called. */ |
| 211 | /* Should return true or false. */ |
| 212 | int (*checkentry)(const char *tablename, |
| 213 | const void *entry, |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 214 | const struct xt_target *target, |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 215 | void *targinfo, |
| 216 | unsigned int targinfosize, |
| 217 | unsigned int hook_mask); |
| 218 | |
| 219 | /* Called when entry of this type deleted. */ |
Patrick McHardy | 1c52483 | 2006-03-20 18:02:15 -0800 | [diff] [blame] | 220 | void (*destroy)(const struct xt_target *target, void *targinfo, |
| 221 | unsigned int targinfosize); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 222 | |
| 223 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 224 | struct module *me; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 225 | |
| 226 | char *table; |
| 227 | unsigned int targetsize; |
| 228 | unsigned int hooks; |
| 229 | unsigned short proto; |
Patrick McHardy | c4b8851 | 2006-03-20 18:03:40 -0800 | [diff] [blame] | 230 | |
| 231 | unsigned short family; |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 232 | u_int8_t revision; |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 233 | }; |
| 234 | |
| 235 | /* Furniture shopping... */ |
| 236 | struct xt_table |
| 237 | { |
| 238 | struct list_head list; |
| 239 | |
| 240 | /* A unique name... */ |
| 241 | char name[XT_TABLE_MAXNAMELEN]; |
| 242 | |
| 243 | /* What hooks you will enter on */ |
| 244 | unsigned int valid_hooks; |
| 245 | |
| 246 | /* Lock for the curtain */ |
| 247 | rwlock_t lock; |
| 248 | |
| 249 | /* Man behind the curtain... */ |
| 250 | //struct ip6t_table_info *private; |
| 251 | void *private; |
| 252 | |
| 253 | /* Set this to THIS_MODULE if you are a module, otherwise NULL */ |
| 254 | struct module *me; |
| 255 | |
| 256 | int af; /* address/protocol family */ |
| 257 | }; |
| 258 | |
| 259 | #include <linux/netfilter_ipv4.h> |
| 260 | |
| 261 | /* The table itself */ |
| 262 | struct xt_table_info |
| 263 | { |
| 264 | /* Size per table */ |
| 265 | unsigned int size; |
| 266 | /* Number of entries: FIXME. --RR */ |
| 267 | unsigned int number; |
| 268 | /* Initial number of entries. Needed for module usage count */ |
| 269 | unsigned int initial_entries; |
| 270 | |
| 271 | /* Entry points and underflows */ |
| 272 | unsigned int hook_entry[NF_IP_NUMHOOKS]; |
| 273 | unsigned int underflow[NF_IP_NUMHOOKS]; |
| 274 | |
| 275 | /* ipt_entry tables: one per CPU */ |
| 276 | char *entries[NR_CPUS]; |
| 277 | }; |
| 278 | |
Pablo Neira Ayuso | a45049c | 2006-03-22 13:55:40 -0800 | [diff] [blame] | 279 | extern int xt_register_target(struct xt_target *target); |
| 280 | extern void xt_unregister_target(struct xt_target *target); |
| 281 | extern int xt_register_match(struct xt_match *target); |
| 282 | extern void xt_unregister_match(struct xt_match *target); |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 283 | |
Patrick McHardy | 37f9f73 | 2006-03-20 17:59:06 -0800 | [diff] [blame] | 284 | extern int xt_check_match(const struct xt_match *match, unsigned short family, |
| 285 | unsigned int size, const char *table, unsigned int hook, |
| 286 | unsigned short proto, int inv_proto); |
| 287 | extern int xt_check_target(const struct xt_target *target, unsigned short family, |
| 288 | unsigned int size, const char *table, unsigned int hook, |
| 289 | unsigned short proto, int inv_proto); |
| 290 | |
Harald Welte | 2e4e6a1 | 2006-01-12 13:30:04 -0800 | [diff] [blame] | 291 | extern int xt_register_table(struct xt_table *table, |
| 292 | struct xt_table_info *bootstrap, |
| 293 | struct xt_table_info *newinfo); |
| 294 | extern void *xt_unregister_table(struct xt_table *table); |
| 295 | |
| 296 | extern struct xt_table_info *xt_replace_table(struct xt_table *table, |
| 297 | unsigned int num_counters, |
| 298 | struct xt_table_info *newinfo, |
| 299 | int *error); |
| 300 | |
| 301 | extern struct xt_match *xt_find_match(int af, const char *name, u8 revision); |
| 302 | extern struct xt_target *xt_find_target(int af, const char *name, u8 revision); |
| 303 | extern struct xt_target *xt_request_find_target(int af, const char *name, |
| 304 | u8 revision); |
| 305 | extern int xt_find_revision(int af, const char *name, u8 revision, int target, |
| 306 | int *err); |
| 307 | |
| 308 | extern struct xt_table *xt_find_table_lock(int af, const char *name); |
| 309 | extern void xt_table_unlock(struct xt_table *t); |
| 310 | |
| 311 | extern int xt_proto_init(int af); |
| 312 | extern void xt_proto_fini(int af); |
| 313 | |
| 314 | extern struct xt_table_info *xt_alloc_table_info(unsigned int size); |
| 315 | extern void xt_free_table_info(struct xt_table_info *info); |
| 316 | |
| 317 | #endif /* __KERNEL__ */ |
| 318 | |
| 319 | #endif /* _X_TABLES_H */ |