/kernel/2.6.32_froyo_photon_nightly/include/linux/netfilter_bridge/ebtables.h

http://photon-android.googlecode.com/ · C++ Header · 393 lines · 287 code · 34 blank · 72 comment · 25 complexity · c9d78e55fd6842923c290e0fa6e10a19 MD5 · raw file

  1. /*
  2. * ebtables
  3. *
  4. * Authors:
  5. * Bart De Schuymer <bdschuym@pandora.be>
  6. *
  7. * ebtables.c,v 2.0, April, 2002
  8. *
  9. * This code is stongly inspired on the iptables code which is
  10. * Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
  11. */
  12. #ifndef __LINUX_BRIDGE_EFF_H
  13. #define __LINUX_BRIDGE_EFF_H
  14. #include <linux/if.h>
  15. #include <linux/netfilter_bridge.h>
  16. #include <linux/if_ether.h>
  17. #define EBT_TABLE_MAXNAMELEN 32
  18. #define EBT_CHAIN_MAXNAMELEN EBT_TABLE_MAXNAMELEN
  19. #define EBT_FUNCTION_MAXNAMELEN EBT_TABLE_MAXNAMELEN
  20. /* verdicts >0 are "branches" */
  21. #define EBT_ACCEPT -1
  22. #define EBT_DROP -2
  23. #define EBT_CONTINUE -3
  24. #define EBT_RETURN -4
  25. #define NUM_STANDARD_TARGETS 4
  26. /* ebtables target modules store the verdict inside an int. We can
  27. * reclaim a part of this int for backwards compatible extensions.
  28. * The 4 lsb are more than enough to store the verdict. */
  29. #define EBT_VERDICT_BITS 0x0000000F
  30. struct xt_match;
  31. struct xt_target;
  32. struct ebt_counter
  33. {
  34. uint64_t pcnt;
  35. uint64_t bcnt;
  36. };
  37. struct ebt_replace
  38. {
  39. char name[EBT_TABLE_MAXNAMELEN];
  40. unsigned int valid_hooks;
  41. /* nr of rules in the table */
  42. unsigned int nentries;
  43. /* total size of the entries */
  44. unsigned int entries_size;
  45. /* start of the chains */
  46. struct ebt_entries __user *hook_entry[NF_BR_NUMHOOKS];
  47. /* nr of counters userspace expects back */
  48. unsigned int num_counters;
  49. /* where the kernel will put the old counters */
  50. struct ebt_counter __user *counters;
  51. char __user *entries;
  52. };
  53. struct ebt_replace_kernel
  54. {
  55. char name[EBT_TABLE_MAXNAMELEN];
  56. unsigned int valid_hooks;
  57. /* nr of rules in the table */
  58. unsigned int nentries;
  59. /* total size of the entries */
  60. unsigned int entries_size;
  61. /* start of the chains */
  62. struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
  63. /* nr of counters userspace expects back */
  64. unsigned int num_counters;
  65. /* where the kernel will put the old counters */
  66. struct ebt_counter *counters;
  67. char *entries;
  68. };
  69. struct ebt_entries {
  70. /* this field is always set to zero
  71. * See EBT_ENTRY_OR_ENTRIES.
  72. * Must be same size as ebt_entry.bitmask */
  73. unsigned int distinguisher;
  74. /* the chain name */
  75. char name[EBT_CHAIN_MAXNAMELEN];
  76. /* counter offset for this chain */
  77. unsigned int counter_offset;
  78. /* one standard (accept, drop, return) per hook */
  79. int policy;
  80. /* nr. of entries */
  81. unsigned int nentries;
  82. /* entry list */
  83. char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
  84. };
  85. /* used for the bitmask of struct ebt_entry */
  86. /* This is a hack to make a difference between an ebt_entry struct and an
  87. * ebt_entries struct when traversing the entries from start to end.
  88. * Using this simplifies the code alot, while still being able to use
  89. * ebt_entries.
  90. * Contrary, iptables doesn't use something like ebt_entries and therefore uses
  91. * different techniques for naming the policy and such. So, iptables doesn't
  92. * need a hack like this.
  93. */
  94. #define EBT_ENTRY_OR_ENTRIES 0x01
  95. /* these are the normal masks */
  96. #define EBT_NOPROTO 0x02
  97. #define EBT_802_3 0x04
  98. #define EBT_SOURCEMAC 0x08
  99. #define EBT_DESTMAC 0x10
  100. #define EBT_F_MASK (EBT_NOPROTO | EBT_802_3 | EBT_SOURCEMAC | EBT_DESTMAC \
  101. | EBT_ENTRY_OR_ENTRIES)
  102. #define EBT_IPROTO 0x01
  103. #define EBT_IIN 0x02
  104. #define EBT_IOUT 0x04
  105. #define EBT_ISOURCE 0x8
  106. #define EBT_IDEST 0x10
  107. #define EBT_ILOGICALIN 0x20
  108. #define EBT_ILOGICALOUT 0x40
  109. #define EBT_INV_MASK (EBT_IPROTO | EBT_IIN | EBT_IOUT | EBT_ILOGICALIN \
  110. | EBT_ILOGICALOUT | EBT_ISOURCE | EBT_IDEST)
  111. struct ebt_entry_match
  112. {
  113. union {
  114. char name[EBT_FUNCTION_MAXNAMELEN];
  115. struct xt_match *match;
  116. } u;
  117. /* size of data */
  118. unsigned int match_size;
  119. unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
  120. };
  121. struct ebt_entry_watcher
  122. {
  123. union {
  124. char name[EBT_FUNCTION_MAXNAMELEN];
  125. struct xt_target *watcher;
  126. } u;
  127. /* size of data */
  128. unsigned int watcher_size;
  129. unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
  130. };
  131. struct ebt_entry_target
  132. {
  133. union {
  134. char name[EBT_FUNCTION_MAXNAMELEN];
  135. struct xt_target *target;
  136. } u;
  137. /* size of data */
  138. unsigned int target_size;
  139. unsigned char data[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
  140. };
  141. #define EBT_STANDARD_TARGET "standard"
  142. struct ebt_standard_target
  143. {
  144. struct ebt_entry_target target;
  145. int verdict;
  146. };
  147. /* one entry */
  148. struct ebt_entry {
  149. /* this needs to be the first field */
  150. unsigned int bitmask;
  151. unsigned int invflags;
  152. __be16 ethproto;
  153. /* the physical in-dev */
  154. char in[IFNAMSIZ];
  155. /* the logical in-dev */
  156. char logical_in[IFNAMSIZ];
  157. /* the physical out-dev */
  158. char out[IFNAMSIZ];
  159. /* the logical out-dev */
  160. char logical_out[IFNAMSIZ];
  161. unsigned char sourcemac[ETH_ALEN];
  162. unsigned char sourcemsk[ETH_ALEN];
  163. unsigned char destmac[ETH_ALEN];
  164. unsigned char destmsk[ETH_ALEN];
  165. /* sizeof ebt_entry + matches */
  166. unsigned int watchers_offset;
  167. /* sizeof ebt_entry + matches + watchers */
  168. unsigned int target_offset;
  169. /* sizeof ebt_entry + matches + watchers + target */
  170. unsigned int next_offset;
  171. unsigned char elems[0] __attribute__ ((aligned (__alignof__(struct ebt_replace))));
  172. };
  173. /* {g,s}etsockopt numbers */
  174. #define EBT_BASE_CTL 128
  175. #define EBT_SO_SET_ENTRIES (EBT_BASE_CTL)
  176. #define EBT_SO_SET_COUNTERS (EBT_SO_SET_ENTRIES+1)
  177. #define EBT_SO_SET_MAX (EBT_SO_SET_COUNTERS+1)
  178. #define EBT_SO_GET_INFO (EBT_BASE_CTL)
  179. #define EBT_SO_GET_ENTRIES (EBT_SO_GET_INFO+1)
  180. #define EBT_SO_GET_INIT_INFO (EBT_SO_GET_ENTRIES+1)
  181. #define EBT_SO_GET_INIT_ENTRIES (EBT_SO_GET_INIT_INFO+1)
  182. #define EBT_SO_GET_MAX (EBT_SO_GET_INIT_ENTRIES+1)
  183. #ifdef __KERNEL__
  184. /* return values for match() functions */
  185. #define EBT_MATCH 0
  186. #define EBT_NOMATCH 1
  187. struct ebt_match
  188. {
  189. struct list_head list;
  190. const char name[EBT_FUNCTION_MAXNAMELEN];
  191. bool (*match)(const struct sk_buff *skb, const struct net_device *in,
  192. const struct net_device *out, const struct xt_match *match,
  193. const void *matchinfo, int offset, unsigned int protoff,
  194. bool *hotdrop);
  195. bool (*checkentry)(const char *table, const void *entry,
  196. const struct xt_match *match, void *matchinfo,
  197. unsigned int hook_mask);
  198. void (*destroy)(const struct xt_match *match, void *matchinfo);
  199. unsigned int matchsize;
  200. u_int8_t revision;
  201. u_int8_t family;
  202. struct module *me;
  203. };
  204. struct ebt_watcher
  205. {
  206. struct list_head list;
  207. const char name[EBT_FUNCTION_MAXNAMELEN];
  208. unsigned int (*target)(struct sk_buff *skb,
  209. const struct net_device *in, const struct net_device *out,
  210. unsigned int hook_num, const struct xt_target *target,
  211. const void *targinfo);
  212. bool (*checkentry)(const char *table, const void *entry,
  213. const struct xt_target *target, void *targinfo,
  214. unsigned int hook_mask);
  215. void (*destroy)(const struct xt_target *target, void *targinfo);
  216. unsigned int targetsize;
  217. u_int8_t revision;
  218. u_int8_t family;
  219. struct module *me;
  220. };
  221. struct ebt_target
  222. {
  223. struct list_head list;
  224. const char name[EBT_FUNCTION_MAXNAMELEN];
  225. /* returns one of the standard EBT_* verdicts */
  226. unsigned int (*target)(struct sk_buff *skb,
  227. const struct net_device *in, const struct net_device *out,
  228. unsigned int hook_num, const struct xt_target *target,
  229. const void *targinfo);
  230. bool (*checkentry)(const char *table, const void *entry,
  231. const struct xt_target *target, void *targinfo,
  232. unsigned int hook_mask);
  233. void (*destroy)(const struct xt_target *target, void *targinfo);
  234. unsigned int targetsize;
  235. u_int8_t revision;
  236. u_int8_t family;
  237. struct module *me;
  238. };
  239. /* used for jumping from and into user defined chains (udc) */
  240. struct ebt_chainstack
  241. {
  242. struct ebt_entries *chaininfo; /* pointer to chain data */
  243. struct ebt_entry *e; /* pointer to entry data */
  244. unsigned int n; /* n'th entry */
  245. };
  246. struct ebt_table_info
  247. {
  248. /* total size of the entries */
  249. unsigned int entries_size;
  250. unsigned int nentries;
  251. /* pointers to the start of the chains */
  252. struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
  253. /* room to maintain the stack used for jumping from and into udc */
  254. struct ebt_chainstack **chainstack;
  255. char *entries;
  256. struct ebt_counter counters[0] ____cacheline_aligned;
  257. };
  258. struct ebt_table
  259. {
  260. struct list_head list;
  261. char name[EBT_TABLE_MAXNAMELEN];
  262. struct ebt_replace_kernel *table;
  263. unsigned int valid_hooks;
  264. rwlock_t lock;
  265. /* e.g. could be the table explicitly only allows certain
  266. * matches, targets, ... 0 == let it in */
  267. int (*check)(const struct ebt_table_info *info,
  268. unsigned int valid_hooks);
  269. /* the data used by the kernel */
  270. struct ebt_table_info *private;
  271. struct module *me;
  272. };
  273. #define EBT_ALIGN(s) (((s) + (__alignof__(struct ebt_replace)-1)) & \
  274. ~(__alignof__(struct ebt_replace)-1))
  275. extern struct ebt_table *ebt_register_table(struct net *net,
  276. const struct ebt_table *table);
  277. extern void ebt_unregister_table(struct ebt_table *table);
  278. extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb,
  279. const struct net_device *in, const struct net_device *out,
  280. struct ebt_table *table);
  281. /* Used in the kernel match() functions */
  282. #define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
  283. /* True if the hook mask denotes that the rule is in a base chain,
  284. * used in the check() functions */
  285. #define BASE_CHAIN (par->hook_mask & (1 << NF_BR_NUMHOOKS))
  286. /* Clear the bit in the hook mask that tells if the rule is on a base chain */
  287. #define CLEAR_BASE_CHAIN_BIT (par->hook_mask &= ~(1 << NF_BR_NUMHOOKS))
  288. /* True if the target is not a standard target */
  289. #define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
  290. #endif /* __KERNEL__ */
  291. /* blatently stolen from ip_tables.h
  292. * fn returns 0 to continue iteration */
  293. #define EBT_MATCH_ITERATE(e, fn, args...) \
  294. ({ \
  295. unsigned int __i; \
  296. int __ret = 0; \
  297. struct ebt_entry_match *__match; \
  298. \
  299. for (__i = sizeof(struct ebt_entry); \
  300. __i < (e)->watchers_offset; \
  301. __i += __match->match_size + \
  302. sizeof(struct ebt_entry_match)) { \
  303. __match = (void *)(e) + __i; \
  304. \
  305. __ret = fn(__match , ## args); \
  306. if (__ret != 0) \
  307. break; \
  308. } \
  309. if (__ret == 0) { \
  310. if (__i != (e)->watchers_offset) \
  311. __ret = -EINVAL; \
  312. } \
  313. __ret; \
  314. })
  315. #define EBT_WATCHER_ITERATE(e, fn, args...) \
  316. ({ \
  317. unsigned int __i; \
  318. int __ret = 0; \
  319. struct ebt_entry_watcher *__watcher; \
  320. \
  321. for (__i = e->watchers_offset; \
  322. __i < (e)->target_offset; \
  323. __i += __watcher->watcher_size + \
  324. sizeof(struct ebt_entry_watcher)) { \
  325. __watcher = (void *)(e) + __i; \
  326. \
  327. __ret = fn(__watcher , ## args); \
  328. if (__ret != 0) \
  329. break; \
  330. } \
  331. if (__ret == 0) { \
  332. if (__i != (e)->target_offset) \
  333. __ret = -EINVAL; \
  334. } \
  335. __ret; \
  336. })
  337. #define EBT_ENTRY_ITERATE(entries, size, fn, args...) \
  338. ({ \
  339. unsigned int __i; \
  340. int __ret = 0; \
  341. struct ebt_entry *__entry; \
  342. \
  343. for (__i = 0; __i < (size);) { \
  344. __entry = (void *)(entries) + __i; \
  345. __ret = fn(__entry , ## args); \
  346. if (__ret != 0) \
  347. break; \
  348. if (__entry->bitmask != 0) \
  349. __i += __entry->next_offset; \
  350. else \
  351. __i += sizeof(struct ebt_entries); \
  352. } \
  353. if (__ret == 0) { \
  354. if (__i != (size)) \
  355. __ret = -EINVAL; \
  356. } \
  357. __ret; \
  358. })
  359. #endif