• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /* SPDX-License-Identifier: GPL-2.0 */
2 /*
3  *  ebtables
4  *
5  *	Authors:
6  *	Bart De Schuymer		<bdschuym@pandora.be>
7  *
8  *  ebtables.c,v 2.0, April, 2002
9  *
10  *  This code is strongly inspired by the iptables code which is
11  *  Copyright (C) 1999 Paul `Rusty' Russell & Michael J. Neuling
12  */
13 #ifndef __LINUX_BRIDGE_EFF_H
14 #define __LINUX_BRIDGE_EFF_H
15 
16 #include <linux/if.h>
17 #include <linux/if_ether.h>
18 #include <uapi/linux/netfilter_bridge/ebtables.h>
19 
20 /* return values for match() functions */
21 #define EBT_MATCH 0
22 #define EBT_NOMATCH 1
23 
24 struct ebt_match {
25 	struct list_head list;
26 	const char name[EBT_FUNCTION_MAXNAMELEN];
27 	bool (*match)(const struct sk_buff *skb, const struct net_device *in,
28 		const struct net_device *out, const struct xt_match *match,
29 		const void *matchinfo, int offset, unsigned int protoff,
30 		bool *hotdrop);
31 	bool (*checkentry)(const char *table, const void *entry,
32 		const struct xt_match *match, void *matchinfo,
33 		unsigned int hook_mask);
34 	void (*destroy)(const struct xt_match *match, void *matchinfo);
35 	unsigned int matchsize;
36 	u_int8_t revision;
37 	u_int8_t family;
38 	struct module *me;
39 };
40 
41 struct ebt_watcher {
42 	struct list_head list;
43 	const char name[EBT_FUNCTION_MAXNAMELEN];
44 	unsigned int (*target)(struct sk_buff *skb,
45 		const struct net_device *in, const struct net_device *out,
46 		unsigned int hook_num, const struct xt_target *target,
47 		const void *targinfo);
48 	bool (*checkentry)(const char *table, const void *entry,
49 		const struct xt_target *target, void *targinfo,
50 		unsigned int hook_mask);
51 	void (*destroy)(const struct xt_target *target, void *targinfo);
52 	unsigned int targetsize;
53 	u_int8_t revision;
54 	u_int8_t family;
55 	struct module *me;
56 };
57 
58 struct ebt_target {
59 	struct list_head list;
60 	const char name[EBT_FUNCTION_MAXNAMELEN];
61 	/* returns one of the standard EBT_* verdicts */
62 	unsigned int (*target)(struct sk_buff *skb,
63 		const struct net_device *in, const struct net_device *out,
64 		unsigned int hook_num, const struct xt_target *target,
65 		const void *targinfo);
66 	bool (*checkentry)(const char *table, const void *entry,
67 		const struct xt_target *target, void *targinfo,
68 		unsigned int hook_mask);
69 	void (*destroy)(const struct xt_target *target, void *targinfo);
70 	unsigned int targetsize;
71 	u_int8_t revision;
72 	u_int8_t family;
73 	struct module *me;
74 };
75 
76 /* used for jumping from and into user defined chains (udc) */
77 struct ebt_chainstack {
78 	struct ebt_entries *chaininfo; /* pointer to chain data */
79 	struct ebt_entry *e; /* pointer to entry data */
80 	unsigned int n; /* n'th entry */
81 };
82 
83 struct ebt_table_info {
84 	/* total size of the entries */
85 	unsigned int entries_size;
86 	unsigned int nentries;
87 	/* pointers to the start of the chains */
88 	struct ebt_entries *hook_entry[NF_BR_NUMHOOKS];
89 	/* room to maintain the stack used for jumping from and into udc */
90 	struct ebt_chainstack **chainstack;
91 	char *entries;
92 	struct ebt_counter counters[0] ____cacheline_aligned;
93 };
94 
95 struct ebt_table {
96 	struct list_head list;
97 	char name[EBT_TABLE_MAXNAMELEN];
98 	struct ebt_replace_kernel *table;
99 	unsigned int valid_hooks;
100 	rwlock_t lock;
101 	/* e.g. could be the table explicitly only allows certain
102 	 * matches, targets, ... 0 == let it in */
103 	int (*check)(const struct ebt_table_info *info,
104 	   unsigned int valid_hooks);
105 	/* the data used by the kernel */
106 	struct ebt_table_info *private;
107 	struct module *me;
108 };
109 
110 #define EBT_ALIGN(s) (((s) + (__alignof__(struct _xt_align)-1)) & \
111 		     ~(__alignof__(struct _xt_align)-1))
112 extern int ebt_register_table(struct net *net,
113 			      const struct ebt_table *table,
114 			      const struct nf_hook_ops *ops,
115 			      struct ebt_table **res);
116 extern void ebt_unregister_table(struct net *net, struct ebt_table *table,
117 				 const struct nf_hook_ops *);
118 extern unsigned int ebt_do_table(struct sk_buff *skb,
119 				 const struct nf_hook_state *state,
120 				 struct ebt_table *table);
121 
122 /* True if the hook mask denotes that the rule is in a base chain,
123  * used in the check() functions */
124 #define BASE_CHAIN (par->hook_mask & (1 << NF_BR_NUMHOOKS))
125 /* Clear the bit in the hook mask that tells if the rule is on a base chain */
126 #define CLEAR_BASE_CHAIN_BIT (par->hook_mask &= ~(1 << NF_BR_NUMHOOKS))
127 
ebt_invalid_target(int target)128 static inline bool ebt_invalid_target(int target)
129 {
130 	return (target < -NUM_STANDARD_TARGETS || target >= 0);
131 }
132 
133 #endif
134