Skip to content

Commit d6b00a5

Browse files
author
Jan Engelhardt
committed
netfilter: xtables: change targets to return error code
Part of the transition of done by this semantic patch: // <smpl> @ rule1 @ struct xt_target ops; identifier check; @@ ops.checkentry = check; @@ identifier rule1.check; @@ check(...) { <... -return true; +return 0; ...> } @@ identifier rule1.check; @@ check(...) { <... -return false; +return -EINVAL; ...> } // </smpl> Signed-off-by: Jan Engelhardt <jengelh@medozas.de>
1 parent bd414ee commit d6b00a5

31 files changed

Lines changed: 116 additions & 111 deletions

‎net/bridge/netfilter/ebt_arpreply.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ static int ebt_arpreply_tg_check(const struct xt_tgchk_param *par)
6363
const struct ebt_entry *e = par->entryinfo;
6464

6565
if (BASE_CHAIN && info->target == EBT_RETURN)
66-
return false;
66+
return -EINVAL;
6767
if (e->ethproto != htons(ETH_P_ARP) ||
6868
e->invflags & EBT_IPROTO)
69-
return false;
70-
return true;
69+
return -EINVAL;
70+
return 0;
7171
}
7272

7373
static struct xt_target ebt_arpreply_tg_reg __read_mostly = {

‎net/bridge/netfilter/ebt_dnat.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,18 +32,18 @@ static int ebt_dnat_tg_check(const struct xt_tgchk_param *par)
3232
unsigned int hook_mask;
3333

3434
if (BASE_CHAIN && info->target == EBT_RETURN)
35-
return false;
35+
return -EINVAL;
3636

3737
hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
3838
if ((strcmp(par->table, "nat") != 0 ||
3939
(hook_mask & ~((1 << NF_BR_PRE_ROUTING) |
4040
(1 << NF_BR_LOCAL_OUT)))) &&
4141
(strcmp(par->table, "broute") != 0 ||
4242
hook_mask & ~(1 << NF_BR_BROUTING)))
43-
return false;
43+
return -EINVAL;
4444
if (INVALID_TARGET)
45-
return false;
46-
return true;
45+
return -EINVAL;
46+
return 0;
4747
}
4848

4949
static struct xt_target ebt_dnat_tg_reg __read_mostly = {

‎net/bridge/netfilter/ebt_log.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,11 @@ static int ebt_log_tg_check(const struct xt_tgchk_param *par)
2929
struct ebt_log_info *info = par->targinfo;
3030

3131
if (info->bitmask & ~EBT_LOG_MASK)
32-
return false;
32+
return -EINVAL;
3333
if (info->loglevel >= 8)
34-
return false;
34+
return -EINVAL;
3535
info->prefix[EBT_LOG_PREFIX_SIZE - 1] = '\0';
36-
return true;
36+
return 0;
3737
}
3838

3939
struct tcpudphdr

‎net/bridge/netfilter/ebt_mark.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,14 @@ static int ebt_mark_tg_check(const struct xt_tgchk_param *par)
4343

4444
tmp = info->target | ~EBT_VERDICT_BITS;
4545
if (BASE_CHAIN && tmp == EBT_RETURN)
46-
return false;
46+
return -EINVAL;
4747
if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
48-
return false;
48+
return -EINVAL;
4949
tmp = info->target & ~EBT_VERDICT_BITS;
5050
if (tmp != MARK_SET_VALUE && tmp != MARK_OR_VALUE &&
5151
tmp != MARK_AND_VALUE && tmp != MARK_XOR_VALUE)
52-
return false;
53-
return true;
52+
return -EINVAL;
53+
return 0;
5454
}
5555
#ifdef CONFIG_COMPAT
5656
struct compat_ebt_mark_t_info {

‎net/bridge/netfilter/ebt_nflog.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ static int ebt_nflog_tg_check(const struct xt_tgchk_param *par)
4040
struct ebt_nflog_info *info = par->targinfo;
4141

4242
if (info->flags & ~EBT_NFLOG_MASK)
43-
return false;
43+
return -EINVAL;
4444
info->prefix[EBT_NFLOG_PREFIX_SIZE - 1] = '\0';
45-
return true;
45+
return 0;
4646
}
4747

4848
static struct xt_target ebt_nflog_tg_reg __read_mostly = {

‎net/bridge/netfilter/ebt_redirect.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -38,17 +38,17 @@ static int ebt_redirect_tg_check(const struct xt_tgchk_param *par)
3838
unsigned int hook_mask;
3939

4040
if (BASE_CHAIN && info->target == EBT_RETURN)
41-
return false;
41+
return -EINVAL;
4242

4343
hook_mask = par->hook_mask & ~(1 << NF_BR_NUMHOOKS);
4444
if ((strcmp(par->table, "nat") != 0 ||
4545
hook_mask & ~(1 << NF_BR_PRE_ROUTING)) &&
4646
(strcmp(par->table, "broute") != 0 ||
4747
hook_mask & ~(1 << NF_BR_BROUTING)))
48-
return false;
48+
return -EINVAL;
4949
if (INVALID_TARGET)
50-
return false;
51-
return true;
50+
return -EINVAL;
51+
return 0;
5252
}
5353

5454
static struct xt_target ebt_redirect_tg_reg __read_mostly = {

‎net/bridge/netfilter/ebt_snat.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,14 +49,14 @@ static int ebt_snat_tg_check(const struct xt_tgchk_param *par)
4949

5050
tmp = info->target | ~EBT_VERDICT_BITS;
5151
if (BASE_CHAIN && tmp == EBT_RETURN)
52-
return false;
52+
return -EINVAL;
5353

5454
if (tmp < -NUM_STANDARD_TARGETS || tmp >= 0)
55-
return false;
55+
return -EINVAL;
5656
tmp = info->target | EBT_VERDICT_BITS;
5757
if ((tmp & ~NAT_ARP_BIT) != ~NAT_ARP_BIT)
58-
return false;
59-
return true;
58+
return -EINVAL;
59+
return 0;
6060
}
6161

6262
static struct xt_target ebt_snat_tg_reg __read_mostly = {

‎net/bridge/netfilter/ebt_ulog.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,14 +254,14 @@ static int ebt_ulog_tg_check(const struct xt_tgchk_param *par)
254254
struct ebt_ulog_info *uloginfo = par->targinfo;
255255

256256
if (uloginfo->nlgroup > 31)
257-
return false;
257+
return -EINVAL;
258258

259259
uloginfo->prefix[EBT_ULOG_PREFIX_LEN - 1] = '\0';
260260

261261
if (uloginfo->qthreshold > EBT_ULOG_MAX_QLEN)
262262
uloginfo->qthreshold = EBT_ULOG_MAX_QLEN;
263263

264-
return true;
264+
return 0;
265265
}
266266

267267
static struct xt_target ebt_ulog_tg_reg __read_mostly = {

‎net/ipv4/netfilter/ipt_CLUSTERIP.c‎

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -358,13 +358,13 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
358358
cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT &&
359359
cipinfo->hash_mode != CLUSTERIP_HASHMODE_SIP_SPT_DPT) {
360360
pr_info("unknown mode %u\n", cipinfo->hash_mode);
361-
return false;
361+
return -EINVAL;
362362

363363
}
364364
if (e->ip.dmsk.s_addr != htonl(0xffffffff) ||
365365
e->ip.dst.s_addr == 0) {
366366
pr_info("Please specify destination IP\n");
367-
return false;
367+
return -EINVAL;
368368
}
369369

370370
/* FIXME: further sanity checks */
@@ -374,28 +374,28 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
374374
if (!(cipinfo->flags & CLUSTERIP_FLAG_NEW)) {
375375
pr_info("no config found for %pI4, need 'new'\n",
376376
&e->ip.dst.s_addr);
377-
return false;
377+
return -EINVAL;
378378
} else {
379379
struct net_device *dev;
380380

381381
if (e->ip.iniface[0] == '\0') {
382382
pr_info("Please specify an interface name\n");
383-
return false;
383+
return -EINVAL;
384384
}
385385

386386
dev = dev_get_by_name(&init_net, e->ip.iniface);
387387
if (!dev) {
388388
pr_info("no such interface %s\n",
389389
e->ip.iniface);
390-
return false;
390+
return -EINVAL;
391391
}
392392

393393
config = clusterip_config_init(cipinfo,
394394
e->ip.dst.s_addr, dev);
395395
if (!config) {
396396
pr_info("cannot allocate config\n");
397397
dev_put(dev);
398-
return false;
398+
return -EINVAL;
399399
}
400400
dev_mc_add(config->dev,config->clustermac, ETH_ALEN, 0);
401401
}
@@ -405,10 +405,10 @@ static int clusterip_tg_check(const struct xt_tgchk_param *par)
405405
if (nf_ct_l3proto_try_module_get(par->family) < 0) {
406406
pr_info("cannot load conntrack support for proto=%u\n",
407407
par->family);
408-
return false;
408+
return -EINVAL;
409409
}
410410

411-
return true;
411+
return 0;
412412
}
413413

414414
/* drop reference count of cluster config when rule is deleted */

‎net/ipv4/netfilter/ipt_ECN.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -100,18 +100,18 @@ static int ecn_tg_check(const struct xt_tgchk_param *par)
100100

101101
if (einfo->operation & IPT_ECN_OP_MASK) {
102102
pr_info("unsupported ECN operation %x\n", einfo->operation);
103-
return false;
103+
return -EINVAL;
104104
}
105105
if (einfo->ip_ect & ~IPT_ECN_IP_MASK) {
106106
pr_info("new ECT codepoint %x out of mask\n", einfo->ip_ect);
107-
return false;
107+
return -EINVAL;
108108
}
109109
if ((einfo->operation & (IPT_ECN_OP_SET_ECE|IPT_ECN_OP_SET_CWR)) &&
110110
(e->ip.proto != IPPROTO_TCP || (e->ip.invflags & XT_INV_PROTO))) {
111111
pr_info("cannot use TCP operations on a non-tcp rule\n");
112-
return false;
112+
return -EINVAL;
113113
}
114-
return true;
114+
return 0;
115115
}
116116

117117
static struct xt_target ecn_tg_reg __read_mostly = {

0 commit comments

Comments
 (0)