Skip to content

Commit 7eb3558

Browse files
Jan Engelhardtkaber
authored andcommitted
netfilter: xtables: move extension arguments into compound structure (4/6)
This patch does this for target extensions' target functions. Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent 6be3d85 commit 7eb3558

42 files changed

Lines changed: 209 additions & 297 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

‎include/linux/netfilter/x_tables.h‎

Lines changed: 17 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -218,6 +218,22 @@ struct xt_mtdtor_param {
218218
void *matchinfo;
219219
};
220220

221+
/**
222+
* struct xt_target_param - parameters for target extensions' target functions
223+
*
224+
* @hooknum: hook through which this target was invoked
225+
* @target: struct xt_target through which this function was invoked
226+
* @targinfo: per-target data
227+
*
228+
* Other fields see above.
229+
*/
230+
struct xt_target_param {
231+
const struct net_device *in, *out;
232+
unsigned int hooknum;
233+
const struct xt_target *target;
234+
const void *targinfo;
235+
};
236+
221237
struct xt_match
222238
{
223239
struct list_head list;
@@ -269,11 +285,7 @@ struct xt_target
269285
must now handle non-linear skbs, using skb_copy_bits and
270286
skb_ip_make_writable. */
271287
unsigned int (*target)(struct sk_buff *skb,
272-
const struct net_device *in,
273-
const struct net_device *out,
274-
unsigned int hooknum,
275-
const struct xt_target *target,
276-
const void *targinfo);
288+
const struct xt_target_param *);
277289

278290
/* Called when user tries to insert an entry of this type:
279291
hook_mask is a bitmask of hooks from which it can be

‎net/bridge/netfilter/ebt_arpreply.c‎

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,11 +16,9 @@
1616
#include <linux/netfilter_bridge/ebt_arpreply.h>
1717

1818
static unsigned int
19-
ebt_arpreply_tg(struct sk_buff *skb, const struct net_device *in,
20-
const struct net_device *out, unsigned int hook_nr,
21-
const struct xt_target *target, const void *data)
19+
ebt_arpreply_tg(struct sk_buff *skb, const struct xt_target_param *par)
2220
{
23-
const struct ebt_arpreply_info *info = data;
21+
const struct ebt_arpreply_info *info = par->targinfo;
2422
const __be32 *siptr, *diptr;
2523
__be32 _sip, _dip;
2624
const struct arphdr *ap;
@@ -53,7 +51,7 @@ ebt_arpreply_tg(struct sk_buff *skb, const struct net_device *in,
5351
if (diptr == NULL)
5452
return EBT_DROP;
5553

56-
arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)in,
54+
arp_send(ARPOP_REPLY, ETH_P_ARP, *siptr, (struct net_device *)par->in,
5755
*diptr, shp, info->mac, shp);
5856

5957
return info->target;

‎net/bridge/netfilter/ebt_dnat.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -15,11 +15,9 @@
1515
#include <linux/netfilter_bridge/ebt_nat.h>
1616

1717
static unsigned int
18-
ebt_dnat_tg(struct sk_buff *skb, const struct net_device *in,
19-
const struct net_device *out, unsigned int hook_nr,
20-
const struct xt_target *target, const void *data)
18+
ebt_dnat_tg(struct sk_buff *skb, const struct xt_target_param *par)
2119
{
22-
const struct ebt_nat_info *info = data;
20+
const struct ebt_nat_info *info = par->targinfo;
2321

2422
if (!skb_make_writable(skb, 0))
2523
return EBT_DROP;

‎net/bridge/netfilter/ebt_log.c‎

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -195,23 +195,21 @@ ebt_log_packet(u_int8_t pf, unsigned int hooknum,
195195
}
196196

197197
static unsigned int
198-
ebt_log_tg(struct sk_buff *skb, const struct net_device *in,
199-
const struct net_device *out, unsigned int hooknr,
200-
const struct xt_target *target, const void *data)
198+
ebt_log_tg(struct sk_buff *skb, const struct xt_target_param *par)
201199
{
202-
const struct ebt_log_info *info = data;
200+
const struct ebt_log_info *info = par->targinfo;
203201
struct nf_loginfo li;
204202

205203
li.type = NF_LOG_TYPE_LOG;
206204
li.u.log.level = info->loglevel;
207205
li.u.log.logflags = info->bitmask;
208206

209207
if (info->bitmask & EBT_LOG_NFLOG)
210-
nf_log_packet(NFPROTO_BRIDGE, hooknr, skb, in, out, &li,
211-
"%s", info->prefix);
208+
nf_log_packet(NFPROTO_BRIDGE, par->hooknum, skb, par->in,
209+
par->out, &li, "%s", info->prefix);
212210
else
213-
ebt_log_packet(NFPROTO_BRIDGE, hooknr, skb, in, out, &li,
214-
info->prefix);
211+
ebt_log_packet(NFPROTO_BRIDGE, par->hooknum, skb, par->in,
212+
par->out, &li, info->prefix);
215213
return EBT_CONTINUE;
216214
}
217215

‎net/bridge/netfilter/ebt_mark.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,9 @@
1919
#include <linux/netfilter_bridge/ebt_mark_t.h>
2020

2121
static unsigned int
22-
ebt_mark_tg(struct sk_buff *skb, const struct net_device *in,
23-
const struct net_device *out, unsigned int hook_nr,
24-
const struct xt_target *target, const void *data)
22+
ebt_mark_tg(struct sk_buff *skb, const struct xt_target_param *par)
2523
{
26-
const struct ebt_mark_t_info *info = data;
24+
const struct ebt_mark_t_info *info = par->targinfo;
2725
int action = info->target & -16;
2826

2927
if (action == MARK_SET_VALUE)

‎net/bridge/netfilter/ebt_nflog.c‎

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -20,19 +20,18 @@
2020
#include <net/netfilter/nf_log.h>
2121

2222
static unsigned int
23-
ebt_nflog_tg(struct sk_buff *skb, const struct net_device *in,
24-
const struct net_device *out, unsigned int hooknr,
25-
const struct xt_target *target, const void *data)
23+
ebt_nflog_tg(struct sk_buff *skb, const struct xt_target_param *par)
2624
{
27-
const struct ebt_nflog_info *info = data;
25+
const struct ebt_nflog_info *info = par->targinfo;
2826
struct nf_loginfo li;
2927

3028
li.type = NF_LOG_TYPE_ULOG;
3129
li.u.ulog.copy_len = info->len;
3230
li.u.ulog.group = info->group;
3331
li.u.ulog.qthreshold = info->threshold;
3432

35-
nf_log_packet(PF_BRIDGE, hooknr, skb, in, out, &li, "%s", info->prefix);
33+
nf_log_packet(PF_BRIDGE, par->hooknum, skb, par->in, par->out,
34+
&li, "%s", info->prefix);
3635
return EBT_CONTINUE;
3736
}
3837

‎net/bridge/netfilter/ebt_redirect.c‎

Lines changed: 5 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -16,20 +16,18 @@
1616
#include <linux/netfilter_bridge/ebt_redirect.h>
1717

1818
static unsigned int
19-
ebt_redirect_tg(struct sk_buff *skb, const struct net_device *in,
20-
const struct net_device *out, unsigned int hooknr,
21-
const struct xt_target *target, const void *data)
19+
ebt_redirect_tg(struct sk_buff *skb, const struct xt_target_param *par)
2220
{
23-
const struct ebt_redirect_info *info = data;
21+
const struct ebt_redirect_info *info = par->targinfo;
2422

2523
if (!skb_make_writable(skb, 0))
2624
return EBT_DROP;
2725

28-
if (hooknr != NF_BR_BROUTING)
26+
if (par->hooknum != NF_BR_BROUTING)
2927
memcpy(eth_hdr(skb)->h_dest,
30-
in->br_port->br->dev->dev_addr, ETH_ALEN);
28+
par->in->br_port->br->dev->dev_addr, ETH_ALEN);
3129
else
32-
memcpy(eth_hdr(skb)->h_dest, in->dev_addr, ETH_ALEN);
30+
memcpy(eth_hdr(skb)->h_dest, par->in->dev_addr, ETH_ALEN);
3331
skb->pkt_type = PACKET_HOST;
3432
return info->target;
3533
}

‎net/bridge/netfilter/ebt_snat.c‎

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,9 @@
1717
#include <linux/netfilter_bridge/ebt_nat.h>
1818

1919
static unsigned int
20-
ebt_snat_tg(struct sk_buff *skb, const struct net_device *in,
21-
const struct net_device *out, unsigned int hook_nr,
22-
const struct xt_target *target, const void *data)
20+
ebt_snat_tg(struct sk_buff *skb, const struct xt_target_param *par)
2321
{
24-
const struct ebt_nat_info *info = data;
22+
const struct ebt_nat_info *info = par->targinfo;
2523

2624
if (!skb_make_writable(skb, 0))
2725
return EBT_DROP;

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -247,13 +247,10 @@ static void ebt_log_packet(u_int8_t pf, unsigned int hooknum,
247247
}
248248

249249
static unsigned int
250-
ebt_ulog_tg(struct sk_buff *skb, const struct net_device *in,
251-
const struct net_device *out, unsigned int hooknr,
252-
const struct xt_target *target, const void *data)
250+
ebt_ulog_tg(struct sk_buff *skb, const struct xt_target_param *par)
253251
{
254-
const struct ebt_ulog_info *uloginfo = data;
255-
256-
ebt_ulog_packet(hooknr, skb, in, out, uloginfo, NULL);
252+
ebt_ulog_packet(par->hooknum, skb, par->in, par->out,
253+
par->targinfo, NULL);
257254
return EBT_CONTINUE;
258255
}
259256

‎net/bridge/netfilter/ebtables.c‎

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -64,11 +64,13 @@ static struct xt_target ebt_standard_target = {
6464
.targetsize = sizeof(int),
6565
};
6666

67-
static inline int ebt_do_watcher (struct ebt_entry_watcher *w,
68-
struct sk_buff *skb, unsigned int hooknr, const struct net_device *in,
69-
const struct net_device *out)
67+
static inline int
68+
ebt_do_watcher(const struct ebt_entry_watcher *w, struct sk_buff *skb,
69+
struct xt_target_param *par)
7070
{
71-
w->u.watcher->target(skb, in, out, hooknr, w->u.watcher, w->data);
71+
par->target = w->u.watcher;
72+
par->targinfo = w->data;
73+
w->u.watcher->target(skb, par);
7274
/* watchers don't give a verdict */
7375
return 0;
7476
}
@@ -156,10 +158,12 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
156158
struct ebt_table_info *private;
157159
bool hotdrop = false;
158160
struct xt_match_param mtpar;
161+
struct xt_target_param tgpar;
159162

160-
mtpar.in = in;
161-
mtpar.out = out;
163+
mtpar.in = tgpar.in = in;
164+
mtpar.out = tgpar.out = out;
162165
mtpar.hotdrop = &hotdrop;
166+
tgpar.hooknum = hook;
163167

164168
read_lock_bh(&table->lock);
165169
private = table->private;
@@ -193,17 +197,18 @@ unsigned int ebt_do_table (unsigned int hook, struct sk_buff *skb,
193197

194198
/* these should only watch: not modify, nor tell us
195199
what to do with the packet */
196-
EBT_WATCHER_ITERATE(point, ebt_do_watcher, skb, hook, in,
197-
out);
200+
EBT_WATCHER_ITERATE(point, ebt_do_watcher, skb, &tgpar);
198201

199202
t = (struct ebt_entry_target *)
200203
(((char *)point) + point->target_offset);
201204
/* standard target */
202205
if (!t->u.target->target)
203206
verdict = ((struct ebt_standard_target *)t)->verdict;
204-
else
205-
verdict = t->u.target->target(skb, in, out, hook,
206-
t->u.target, t->data);
207+
else {
208+
tgpar.target = t->u.target;
209+
tgpar.targinfo = t->data;
210+
verdict = t->u.target->target(skb, &tgpar);
211+
}
207212
if (verdict == EBT_ACCEPT) {
208213
read_unlock_bh(&table->lock);
209214
return NF_ACCEPT;

0 commit comments

Comments
 (0)