Skip to content

Commit 97b59c3

Browse files
ebiedermummakynes
authored andcommitted
netfilter: ebtables: Simplify the arguments to ebt_do_table
Nearly everything thing of interest to ebt_do_table is already present in nf_hook_state. Simplify ebt_do_table by just passing in the skb, nf_hook_state, and the table. This make the code easier to read and maintenance easier. To support this create an nf_hook_state on the stack in ebt_broute (the only caller without a nf_hook_state already available). This new nf_hook_state adds no new computations to ebt_broute, but does use a few more bytes of stack. Signed-off-by: "Eric W. Biederman" <ebiederm@xmission.com> Signed-off-by: Pablo Neira Ayuso <pablo@netfilter.org>
1 parent 36aea58 commit 97b59c3

5 files changed

Lines changed: 20 additions & 19 deletions

File tree

‎include/linux/netfilter_bridge/ebtables.h‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -111,9 +111,9 @@ struct ebt_table {
111111
extern struct ebt_table *ebt_register_table(struct net *net,
112112
const struct ebt_table *table);
113113
extern void ebt_unregister_table(struct net *net, struct ebt_table *table);
114-
extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb,
115-
const struct net_device *in, const struct net_device *out,
116-
struct ebt_table *table);
114+
extern unsigned int ebt_do_table(struct sk_buff *skb,
115+
const struct nf_hook_state *state,
116+
struct ebt_table *table);
117117

118118
/* Used in the kernel match() functions */
119119
#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))

‎net/bridge/netfilter/ebtable_broute.c‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -50,10 +50,14 @@ static const struct ebt_table broute_table = {
5050

5151
static int ebt_broute(struct sk_buff *skb)
5252
{
53+
struct nf_hook_state state;
5354
int ret;
5455

55-
ret = ebt_do_table(NF_BR_BROUTING, skb, skb->dev, NULL,
56-
dev_net(skb->dev)->xt.broute_table);
56+
nf_hook_state_init(&state, NULL, NF_BR_BROUTING, INT_MIN,
57+
NFPROTO_BRIDGE, skb->dev, NULL, NULL,
58+
dev_net(skb->dev), NULL);
59+
60+
ret = ebt_do_table(skb, &state, state.net->xt.broute_table);
5761
if (ret == NF_DROP)
5862
return 1; /* route it */
5963
return 0; /* bridge it */

‎net/bridge/netfilter/ebtable_filter.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ static unsigned int
6060
ebt_in_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
6161
const struct nf_hook_state *state)
6262
{
63-
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
64-
state->net->xt.frame_filter);
63+
return ebt_do_table(skb, state, state->net->xt.frame_filter);
6564
}
6665

6766
static unsigned int
6867
ebt_out_hook(const struct nf_hook_ops *ops, struct sk_buff *skb,
6968
const struct nf_hook_state *state)
7069
{
71-
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
72-
state->net->xt.frame_filter);
70+
return ebt_do_table(skb, state, state->net->xt.frame_filter);
7371
}
7472

7573
static struct nf_hook_ops ebt_ops_filter[] __read_mostly = {

‎net/bridge/netfilter/ebtable_nat.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ static unsigned int
6060
ebt_nat_in(const struct nf_hook_ops *ops, struct sk_buff *skb,
6161
const struct nf_hook_state *state)
6262
{
63-
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
64-
state->net->xt.frame_nat);
63+
return ebt_do_table(skb, state, state->net->xt.frame_nat);
6564
}
6665

6766
static unsigned int
6867
ebt_nat_out(const struct nf_hook_ops *ops, struct sk_buff *skb,
6968
const struct nf_hook_state *state)
7069
{
71-
return ebt_do_table(ops->hooknum, skb, state->in, state->out,
72-
state->net->xt.frame_nat);
70+
return ebt_do_table(skb, state, state->net->xt.frame_nat);
7371
}
7472

7573
static struct nf_hook_ops ebt_ops_nat[] __read_mostly = {

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -183,10 +183,11 @@ struct ebt_entry *ebt_next_entry(const struct ebt_entry *entry)
183183
}
184184

185185
/* Do some firewalling */
186-
unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
187-
const struct net_device *in, const struct net_device *out,
188-
struct ebt_table *table)
186+
unsigned int ebt_do_table(struct sk_buff *skb,
187+
const struct nf_hook_state *state,
188+
struct ebt_table *table)
189189
{
190+
unsigned int hook = state->hook;
190191
int i, nentries;
191192
struct ebt_entry *point;
192193
struct ebt_counter *counter_base, *cb_base;
@@ -199,8 +200,8 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
199200
struct xt_action_param acpar;
200201

201202
acpar.family = NFPROTO_BRIDGE;
202-
acpar.in = in;
203-
acpar.out = out;
203+
acpar.in = state->in;
204+
acpar.out = state->out;
204205
acpar.hotdrop = false;
205206
acpar.hooknum = hook;
206207

@@ -220,7 +221,7 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
220221
base = private->entries;
221222
i = 0;
222223
while (i < nentries) {
223-
if (ebt_basic_match(point, skb, in, out))
224+
if (ebt_basic_match(point, skb, state->in, state->out))
224225
goto letscontinue;
225226

226227
if (EBT_MATCH_ITERATE(point, ebt_do_match, skb, &acpar) != 0)

0 commit comments

Comments
 (0)