Skip to content

Commit af5d6dc

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

39 files changed

Lines changed: 208 additions & 283 deletions

‎include/linux/netfilter/x_tables.h‎

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,23 @@ struct xt_target_param {
234234
const void *targinfo;
235235
};
236236

237+
/**
238+
* struct xt_tgchk_param - parameters for target extensions'
239+
* checkentry functions
240+
*
241+
* @entryinfo: the family-specific rule data
242+
* (struct ipt_entry, ip6t_entry, arpt_entry, ebt_entry)
243+
*
244+
* Other fields see above.
245+
*/
246+
struct xt_tgchk_param {
247+
const char *table;
248+
void *entryinfo;
249+
const struct xt_target *target;
250+
void *targinfo;
251+
unsigned int hook_mask;
252+
};
253+
237254
struct xt_match
238255
{
239256
struct list_head list;
@@ -291,11 +308,7 @@ struct xt_target
291308
hook_mask is a bitmask of hooks from which it can be
292309
called. */
293310
/* Should return true or false. */
294-
bool (*checkentry)(const char *tablename,
295-
const void *entry,
296-
const struct xt_target *target,
297-
void *targinfo,
298-
unsigned int hook_mask);
311+
bool (*checkentry)(const struct xt_tgchk_param *);
299312

300313
/* Called when entry of this type deleted. */
301314
void (*destroy)(const struct xt_target *target, void *targinfo);
@@ -376,10 +389,8 @@ extern void xt_unregister_matches(struct xt_match *match, unsigned int n);
376389

377390
extern int xt_check_match(struct xt_mtchk_param *, u_int8_t family,
378391
unsigned int size, u_int8_t proto, bool inv_proto);
379-
extern int xt_check_target(const struct xt_target *target, unsigned short family,
380-
unsigned int size, const char *table, unsigned int hook,
381-
unsigned short proto, int inv_proto,
382-
const void *entry, void *targinfo);
392+
extern int xt_check_target(struct xt_tgchk_param *, u_int8_t family,
393+
unsigned int size, u_int8_t proto, bool inv_proto);
383394

384395
extern struct xt_table *xt_register_table(struct net *net,
385396
struct xt_table *table,

‎include/linux/netfilter_bridge/ebtables.h‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -310,9 +310,9 @@ extern unsigned int ebt_do_table(unsigned int hook, struct sk_buff *skb,
310310
#define FWINV(bool,invflg) ((bool) ^ !!(info->invflags & invflg))
311311
/* True if the hook mask denotes that the rule is in a base chain,
312312
* used in the check() functions */
313-
#define BASE_CHAIN (hookmask & (1 << NF_BR_NUMHOOKS))
313+
#define BASE_CHAIN (par->hook_mask & (1 << NF_BR_NUMHOOKS))
314314
/* Clear the bit in the hook mask that tells if the rule is on a base chain */
315-
#define CLEAR_BASE_CHAIN_BIT (hookmask &= ~(1 << NF_BR_NUMHOOKS))
315+
#define CLEAR_BASE_CHAIN_BIT (par->hook_mask &= ~(1 << NF_BR_NUMHOOKS))
316316
/* True if the target is not a standard target */
317317
#define INVALID_TARGET (info->target < -NUM_STANDARD_TARGETS || info->target >= 0)
318318

‎net/bridge/netfilter/ebt_arpreply.c‎

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -57,20 +57,16 @@ ebt_arpreply_tg(struct sk_buff *skb, const struct xt_target_param *par)
5757
return info->target;
5858
}
5959

60-
static bool
61-
ebt_arpreply_tg_check(const char *tablename, const void *entry,
62-
const struct xt_target *target, void *data,
63-
unsigned int hookmask)
60+
static bool ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
6461
{
65-
const struct ebt_arpreply_info *info = data;
66-
const struct ebt_entry *e = entry;
62+
const struct ebt_arpreply_info *info = par->targinfo;
63+
const struct ebt_entry *e = par->entryinfo;
6764

6865
if (BASE_CHAIN && info->target == EBT_RETURN)
6966
return false;
7067
if (e->ethproto != htons(ETH_P_ARP) ||
7168
e->invflags & EBT_IPROTO)
7269
return false;
73-
CLEAR_BASE_CHAIN_BIT;
7470
return true;
7571
}
7672

‎net/bridge/netfilter/ebt_dnat.c‎

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -26,19 +26,20 @@ ebt_dnat_tg(struct sk_buff *skb, const struct xt_target_param *par)
2626
return info->target;
2727
}
2828

29-
static bool
30-
ebt_dnat_tg_check(const char *tablename, const void *entry,
31-
const struct xt_target *target, void *data,
32-
unsigned int hookmask)
29+
static bool ebt_dnat_tg_check(const struct xt_tgchk_param *par)
3330
{
34-
const struct ebt_nat_info *info = data;
31+
const struct ebt_nat_info *info = par->targinfo;
32+
unsigned int hook_mask;
3533

3634
if (BASE_CHAIN && info->target == EBT_RETURN)
3735
return false;
38-
CLEAR_BASE_CHAIN_BIT;
39-
if ( (strcmp(tablename, "nat") ||
40-
(hookmask & ~((1 << NF_BR_PRE_ROUTING) | (1 << NF_BR_LOCAL_OUT)))) &&
41-
(strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
36+
37+
hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
38+
if ((strcmp(par->table, "nat") != 0 ||
39+
(hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
40+
(1 << NF_BR_LOCAL_OUT)))) &&
41+
(strcmp(par->table, "broute") != 0 ||
42+
hook_mask & ~(1 << NF_BR_BROUTING)))
4243
return false;
4344
if (INVALID_TARGET)
4445
return false;

‎net/bridge/netfilter/ebt_log.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,9 @@
2424

2525
static DEFINE_SPINLOCK(ebt_log_lock);
2626

27-
static bool
28-
ebt_log_tg_check(const char *table, const void *entry,
29-
const struct xt_target *target, void *data,
30-
unsigned int hook_mask)
27+
static bool ebt_log_tg_check(const struct xt_tgchk_param *par)
3128
{
32-
struct ebt_log_info *info = data;
29+
struct ebt_log_info *info = par->targinfo;
3330

3431
if (info->bitmask & ~EBT_LOG_MASK)
3532
return false;

‎net/bridge/netfilter/ebt_mark.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -36,18 +36,14 @@ ebt_mark_tg(struct sk_buff *skb, const struct xt_target_param *par)
3636
return info->target | ~EBT_VERDICT_BITS;
3737
}
3838

39-
static bool
40-
ebt_mark_tg_check(const char *table, const void *e,
41-
const struct xt_target *target, void *data,
42-
unsigned int hookmask)
39+
static bool ebt_mark_tg_check(const struct xt_tgchk_param *par)
4340
{
44-
const struct ebt_mark_t_info *info = data;
41+
const struct ebt_mark_t_info *info = par->targinfo;
4542
int tmp;
4643

4744
tmp = info->target | ~EBT_VERDICT_BITS;
4845
if (BASE_CHAIN && tmp == EBT_RETURN)
4946
return false;
50-
CLEAR_BASE_CHAIN_BIT;
5147
if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
5248
return false;
5349
tmp = info->target & ~EBT_VERDICT_BITS;

‎net/bridge/netfilter/ebt_nflog.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,12 +35,9 @@ ebt_nflog_tg(struct sk_buff *skb, const struct xt_target_param *par)
3535
return EBT_CONTINUE;
3636
}
3737

38-
static bool
39-
ebt_nflog_tg_check(const char *table, const void *e,
40-
const struct xt_target *target, void *data,
41-
unsigned int hookmask)
38+
static bool ebt_nflog_tg_check(const struct xt_tgchk_param *par)
4239
{
43-
struct ebt_nflog_info *info = data;
40+
struct ebt_nflog_info *info = par->targinfo;
4441

4542
if (info->flags & ~EBT_NFLOG_MASK)
4643
return false;

‎net/bridge/netfilter/ebt_redirect.c‎

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,19 @@ ebt_redirect_tg(struct sk_buff *skb, const struct xt_target_param *par)
3232
return info->target;
3333
}
3434

35-
static bool
36-
ebt_redirect_tg_check(const char *tablename, const void *e,
37-
const struct xt_target *target, void *data,
38-
unsigned int hookmask)
35+
static bool ebt_redirect_tg_check(const struct xt_tgchk_param *par)
3936
{
40-
const struct ebt_redirect_info *info = data;
37+
const struct ebt_redirect_info *info = par->targinfo;
38+
unsigned int hook_mask;
4139

4240
if (BASE_CHAIN && info->target == EBT_RETURN)
4341
return false;
44-
CLEAR_BASE_CHAIN_BIT;
45-
if ( (strcmp(tablename, "nat") || hookmask & ~(1 << NF_BR_PRE_ROUTING)) &&
46-
(strcmp(tablename, "broute") || hookmask & ~(1 << NF_BR_BROUTING)) )
42+
43+
hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
44+
if ((strcmp(par->table, "nat") != 0 ||
45+
hook_mask & ~(1 << NF_BR_PRE_ROUTING)) &&
46+
(strcmp(par->table, "broute") != 0 ||
47+
hook_mask & ~(1 << NF_BR_BROUTING)))
4748
return false;
4849
if (INVALID_TARGET)
4950
return false;

‎net/bridge/netfilter/ebt_snat.c‎

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,14 @@ ebt_snat_tg(struct sk_buff *skb, const struct xt_target_param *par)
4242
return info->target | ~EBT_VERDICT_BITS;
4343
}
4444

45-
static bool
46-
ebt_snat_tg_check(const char *tablename, const void *e,
47-
const struct xt_target *target, void *data,
48-
unsigned int hookmask)
45+
static bool ebt_snat_tg_check(const struct xt_tgchk_param *par)
4946
{
50-
const struct ebt_nat_info *info = data;
47+
const struct ebt_nat_info *info = par->targinfo;
5148
int tmp;
5249

5350
tmp = info->target | ~EBT_VERDICT_BITS;
5451
if (BASE_CHAIN && tmp == EBT_RETURN)
5552
return false;
56-
CLEAR_BASE_CHAIN_BIT;
5753

5854
if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
5955
return false;

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -254,12 +254,9 @@ ebt_ulog_tg(struct sk_buff *skb, const struct xt_target_param *par)
254254
return EBT_CONTINUE;
255255
}
256256

257-
static bool
258-
ebt_ulog_tg_check(const char *table, const void *entry,
259-
const struct xt_target *target, void *data,
260-
unsigned int hookmask)
257+
static bool ebt_ulog_tg_check(const struct xt_tgchk_param *par)
261258
{
262-
struct ebt_ulog_info *uloginfo = data;
259+
struct ebt_ulog_info *uloginfo = par->targinfo;
263260

264261
if (uloginfo->nlgroup > 31)
265262
return false;

0 commit comments

Comments
 (0)