Skip to content

Commit bd414ee

Browse files
author
Jan Engelhardt
committed
netfilter: xtables: change matches to return error code
The following semantic patch does part of the transformation: // <smpl> @ rule1 @ struct xt_match 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 135367b commit bd414ee

44 files changed

Lines changed: 162 additions & 156 deletions

Some content is hidden

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

‎net/bridge/netfilter/ebt_802_3.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -41,9 +41,9 @@ static int ebt_802_3_mt_check(const struct xt_mtchk_param *par)
4141
const struct ebt_802_3_info *info = par->matchinfo;
4242

4343
if (info->bitmask & ~EBT_802_3_MASK || info->invflags & ~EBT_802_3_MASK)
44-
return false;
44+
return -EINVAL;
4545

46-
return true;
46+
return 0;
4747
}
4848

4949
static struct xt_match ebt_802_3_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_among.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -190,17 +190,17 @@ static int ebt_among_mt_check(const struct xt_mtchk_param *par)
190190
pr_info("wrong size: %d against expected %d, rounded to %Zd\n",
191191
em->match_size, expected_length,
192192
EBT_ALIGN(expected_length));
193-
return false;
193+
return -EINVAL;
194194
}
195195
if (wh_dst && (err = ebt_mac_wormhash_check_integrity(wh_dst))) {
196196
pr_info("dst integrity fail: %x\n", -err);
197-
return false;
197+
return -EINVAL;
198198
}
199199
if (wh_src && (err = ebt_mac_wormhash_check_integrity(wh_src))) {
200200
pr_info("src integrity fail: %x\n", -err);
201-
return false;
201+
return -EINVAL;
202202
}
203-
return true;
203+
return 0;
204204
}
205205

206206
static struct xt_match ebt_among_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_arp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -108,10 +108,10 @@ static int ebt_arp_mt_check(const struct xt_mtchk_param *par)
108108
if ((e->ethproto != htons(ETH_P_ARP) &&
109109
e->ethproto != htons(ETH_P_RARP)) ||
110110
e->invflags & EBT_IPROTO)
111-
return false;
111+
return -EINVAL;
112112
if (info->bitmask & ~EBT_ARP_MASK || info->invflags & ~EBT_ARP_MASK)
113-
return false;
114-
return true;
113+
return -EINVAL;
114+
return 0;
115115
}
116116

117117
static struct xt_match ebt_arp_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_ip.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -84,24 +84,24 @@ static int ebt_ip_mt_check(const struct xt_mtchk_param *par)
8484

8585
if (e->ethproto != htons(ETH_P_IP) ||
8686
e->invflags & EBT_IPROTO)
87-
return false;
87+
return -EINVAL;
8888
if (info->bitmask & ~EBT_IP_MASK || info->invflags & ~EBT_IP_MASK)
89-
return false;
89+
return -EINVAL;
9090
if (info->bitmask & (EBT_IP_DPORT | EBT_IP_SPORT)) {
9191
if (info->invflags & EBT_IP_PROTO)
92-
return false;
92+
return -EINVAL;
9393
if (info->protocol != IPPROTO_TCP &&
9494
info->protocol != IPPROTO_UDP &&
9595
info->protocol != IPPROTO_UDPLITE &&
9696
info->protocol != IPPROTO_SCTP &&
9797
info->protocol != IPPROTO_DCCP)
98-
return false;
98+
return -EINVAL;
9999
}
100100
if (info->bitmask & EBT_IP_DPORT && info->dport[0] > info->dport[1])
101-
return false;
101+
return -EINVAL;
102102
if (info->bitmask & EBT_IP_SPORT && info->sport[0] > info->sport[1])
103-
return false;
104-
return true;
103+
return -EINVAL;
104+
return 0;
105105
}
106106

107107
static struct xt_match ebt_ip_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_ip6.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -86,24 +86,24 @@ static int ebt_ip6_mt_check(const struct xt_mtchk_param *par)
8686
struct ebt_ip6_info *info = par->matchinfo;
8787

8888
if (e->ethproto != htons(ETH_P_IPV6) || e->invflags & EBT_IPROTO)
89-
return false;
89+
return -EINVAL;
9090
if (info->bitmask & ~EBT_IP6_MASK || info->invflags & ~EBT_IP6_MASK)
91-
return false;
91+
return -EINVAL;
9292
if (info->bitmask & (EBT_IP6_DPORT | EBT_IP6_SPORT)) {
9393
if (info->invflags & EBT_IP6_PROTO)
94-
return false;
94+
return -EINVAL;
9595
if (info->protocol != IPPROTO_TCP &&
9696
info->protocol != IPPROTO_UDP &&
9797
info->protocol != IPPROTO_UDPLITE &&
9898
info->protocol != IPPROTO_SCTP &&
9999
info->protocol != IPPROTO_DCCP)
100-
return false;
100+
return -EINVAL;
101101
}
102102
if (info->bitmask & EBT_IP6_DPORT && info->dport[0] > info->dport[1])
103-
return false;
103+
return -EINVAL;
104104
if (info->bitmask & EBT_IP6_SPORT && info->sport[0] > info->sport[1])
105-
return false;
106-
return true;
105+
return -EINVAL;
106+
return 0;
107107
}
108108

109109
static struct xt_match ebt_ip6_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_limit.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -74,15 +74,15 @@ static int ebt_limit_mt_check(const struct xt_mtchk_param *par)
7474
user2credits(info->avg * info->burst) < user2credits(info->avg)) {
7575
pr_info("overflow, try lower: %u/%u\n",
7676
info->avg, info->burst);
77-
return false;
77+
return -EINVAL;
7878
}
7979

8080
/* User avg in seconds * EBT_LIMIT_SCALE: convert to jiffies * 128. */
8181
info->prev = jiffies;
8282
info->credit = user2credits(info->avg * info->burst);
8383
info->credit_cap = user2credits(info->avg * info->burst);
8484
info->cost = user2credits(info->avg);
85-
return true;
85+
return 0;
8686
}
8787

8888

‎net/bridge/netfilter/ebt_mark_m.c‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,12 +27,12 @@ static int ebt_mark_mt_check(const struct xt_mtchk_param *par)
2727
const struct ebt_mark_m_info *info = par->matchinfo;
2828

2929
if (info->bitmask & ~EBT_MARK_MASK)
30-
return false;
30+
return -EINVAL;
3131
if ((info->bitmask & EBT_MARK_OR) && (info->bitmask & EBT_MARK_AND))
32-
return false;
32+
return -EINVAL;
3333
if (!info->bitmask)
34-
return false;
35-
return true;
34+
return -EINVAL;
35+
return 0;
3636
}
3737

3838

‎net/bridge/netfilter/ebt_pkttype.c‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -25,9 +25,9 @@ static int ebt_pkttype_mt_check(const struct xt_mtchk_param *par)
2525
const struct ebt_pkttype_info *info = par->matchinfo;
2626

2727
if (info->invert != 0 && info->invert != 1)
28-
return false;
28+
return -EINVAL;
2929
/* Allow any pkt_type value */
30-
return true;
30+
return 0;
3131
}
3232

3333
static struct xt_match ebt_pkttype_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_stp.c‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -162,13 +162,13 @@ static int ebt_stp_mt_check(const struct xt_mtchk_param *par)
162162

163163
if (info->bitmask & ~EBT_STP_MASK || info->invflags & ~EBT_STP_MASK ||
164164
!(info->bitmask & EBT_STP_MASK))
165-
return false;
165+
return -EINVAL;
166166
/* Make sure the match only receives stp frames */
167167
if (compare_ether_addr(e->destmac, bridge_ula) ||
168168
compare_ether_addr(e->destmsk, msk) || !(e->bitmask & EBT_DESTMAC))
169-
return false;
169+
return -EINVAL;
170170

171-
return true;
171+
return 0;
172172
}
173173

174174
static struct xt_match ebt_stp_mt_reg __read_mostly = {

‎net/bridge/netfilter/ebt_vlan.c‎

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,22 +88,22 @@ static int ebt_vlan_mt_check(const struct xt_mtchk_param *par)
8888
if (e->ethproto != htons(ETH_P_8021Q)) {
8989
pr_debug("passed entry proto %2.4X is not 802.1Q (8100)\n",
9090
ntohs(e->ethproto));
91-
return false;
91+
return -EINVAL;
9292
}
9393

9494
/* Check for bitmask range
9595
* True if even one bit is out of mask */
9696
if (info->bitmask & ~EBT_VLAN_MASK) {
9797
pr_debug("bitmask %2X is out of mask (%2X)\n",
9898
info->bitmask, EBT_VLAN_MASK);
99-
return false;
99+
return -EINVAL;
100100
}
101101

102102
/* Check for inversion flags range */
103103
if (info->invflags & ~EBT_VLAN_MASK) {
104104
pr_debug("inversion flags %2X is out of mask (%2X)\n",
105105
info->invflags, EBT_VLAN_MASK);
106-
return false;
106+
return -EINVAL;
107107
}
108108

109109
/* Reserved VLAN ID (VID) values
@@ -117,7 +117,7 @@ static int ebt_vlan_mt_check(const struct xt_mtchk_param *par)
117117
if (info->id > VLAN_GROUP_ARRAY_LEN) {
118118
pr_debug("id %d is out of range (1-4096)\n",
119119
info->id);
120-
return false;
120+
return -EINVAL;
121121
}
122122
/* Note: This is valid VLAN-tagged frame point.
123123
* Any value of user_priority are acceptable,
@@ -132,7 +132,7 @@ static int ebt_vlan_mt_check(const struct xt_mtchk_param *par)
132132
if ((unsigned char) info->prio > 7) {
133133
pr_debug("prio %d is out of range (0-7)\n",
134134
info->prio);
135-
return false;
135+
return -EINVAL;
136136
}
137137
}
138138
/* Check for encapsulated proto range - it is possible to be
@@ -142,11 +142,11 @@ static int ebt_vlan_mt_check(const struct xt_mtchk_param *par)
142142
if ((unsigned short) ntohs(info->encap) < ETH_ZLEN) {
143143
pr_debug("encap frame length %d is less than "
144144
"minimal\n", ntohs(info->encap));
145-
return false;
145+
return -EINVAL;
146146
}
147147
}
148148

149-
return true;
149+
return 0;
150150
}
151151

152152
static struct xt_match ebt_vlan_mt_reg __read_mostly = {

0 commit comments

Comments
 (0)