Skip to content

Commit 8cc784e

Browse files
Jan Engelhardtkaber
authored andcommitted
netfilter: change return types of match functions for ebtables extensions
Signed-off-by: Jan Engelhardt <jengelh@medozas.de> Signed-off-by: Patrick McHardy <kaber@trash.net>
1 parent 19eda87 commit 8cc784e

11 files changed

Lines changed: 104 additions & 105 deletions

File tree

‎include/linux/netfilter_bridge/ebtables.h‎

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -207,8 +207,7 @@ struct ebt_match
207207
{
208208
struct list_head list;
209209
const char name[EBT_FUNCTION_MAXNAMELEN];
210-
/* 0 == it matches */
211-
int (*match)(const struct sk_buff *skb, const struct net_device *in,
210+
bool (*match)(const struct sk_buff *skb, const struct net_device *in,
212211
const struct net_device *out, const void *matchdata,
213212
unsigned int datalen);
214213
bool (*check)(const char *tablename, unsigned int hookmask,

‎net/bridge/netfilter/ebt_802_3.c‎

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,8 @@
1212
#include <linux/netfilter_bridge/ebtables.h>
1313
#include <linux/netfilter_bridge/ebt_802_3.h>
1414

15-
static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *in,
15+
static bool ebt_filter_802_3(const struct sk_buff *skb,
16+
const struct net_device *in,
1617
const struct net_device *out, const void *data, unsigned int datalen)
1718
{
1819
const struct ebt_802_3_info *info = data;
@@ -21,19 +22,19 @@ static int ebt_filter_802_3(const struct sk_buff *skb, const struct net_device *
2122

2223
if (info->bitmask & EBT_802_3_SAP) {
2324
if (FWINV(info->sap != hdr->llc.ui.ssap, EBT_802_3_SAP))
24-
return EBT_NOMATCH;
25+
return false;
2526
if (FWINV(info->sap != hdr->llc.ui.dsap, EBT_802_3_SAP))
26-
return EBT_NOMATCH;
27+
return false;
2728
}
2829

2930
if (info->bitmask & EBT_802_3_TYPE) {
3031
if (!(hdr->llc.ui.dsap == CHECK_TYPE && hdr->llc.ui.ssap == CHECK_TYPE))
31-
return EBT_NOMATCH;
32+
return false;
3233
if (FWINV(info->type != type, EBT_802_3_TYPE))
33-
return EBT_NOMATCH;
34+
return false;
3435
}
3536

36-
return EBT_MATCH;
37+
return true;
3738
}
3839

3940
static struct ebt_match filter_802_3;

‎net/bridge/netfilter/ebt_among.c‎

Lines changed: 20 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,8 @@
1414
#include <linux/if_arp.h>
1515
#include <linux/module.h>
1616

17-
static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
18-
const char *mac, __be32 ip)
17+
static bool ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
18+
const char *mac, __be32 ip)
1919
{
2020
/* You may be puzzled as to how this code works.
2121
* Some tricks were used, refer to
@@ -33,23 +33,19 @@ static int ebt_mac_wormhash_contains(const struct ebt_mac_wormhash *wh,
3333
if (ip) {
3434
for (i = start; i < limit; i++) {
3535
p = &wh->pool[i];
36-
if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
37-
if (p->ip == 0 || p->ip == ip) {
38-
return 1;
39-
}
40-
}
36+
if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0])
37+
if (p->ip == 0 || p->ip == ip)
38+
return true;
4139
}
4240
} else {
4341
for (i = start; i < limit; i++) {
4442
p = &wh->pool[i];
45-
if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0]) {
46-
if (p->ip == 0) {
47-
return 1;
48-
}
49-
}
43+
if (cmp[1] == p->cmp[1] && cmp[0] == p->cmp[0])
44+
if (p->ip == 0)
45+
return true;
5046
}
5147
}
52-
return 0;
48+
return false;
5349
}
5450

5551
static int ebt_mac_wormhash_check_integrity(const struct ebt_mac_wormhash
@@ -131,10 +127,10 @@ static int get_ip_src(const struct sk_buff *skb, __be32 *addr)
131127
return 0;
132128
}
133129

134-
static int ebt_filter_among(const struct sk_buff *skb,
135-
const struct net_device *in,
136-
const struct net_device *out, const void *data,
137-
unsigned int datalen)
130+
static bool ebt_filter_among(const struct sk_buff *skb,
131+
const struct net_device *in,
132+
const struct net_device *out, const void *data,
133+
unsigned int datalen)
138134
{
139135
const struct ebt_among_info *info = data;
140136
const char *dmac, *smac;
@@ -147,34 +143,34 @@ static int ebt_filter_among(const struct sk_buff *skb,
147143
if (wh_src) {
148144
smac = eth_hdr(skb)->h_source;
149145
if (get_ip_src(skb, &sip))
150-
return EBT_NOMATCH;
146+
return false;
151147
if (!(info->bitmask & EBT_AMONG_SRC_NEG)) {
152148
/* we match only if it contains */
153149
if (!ebt_mac_wormhash_contains(wh_src, smac, sip))
154-
return EBT_NOMATCH;
150+
return false;
155151
} else {
156152
/* we match only if it DOES NOT contain */
157153
if (ebt_mac_wormhash_contains(wh_src, smac, sip))
158-
return EBT_NOMATCH;
154+
return false;
159155
}
160156
}
161157

162158
if (wh_dst) {
163159
dmac = eth_hdr(skb)->h_dest;
164160
if (get_ip_dst(skb, &dip))
165-
return EBT_NOMATCH;
161+
return false;
166162
if (!(info->bitmask & EBT_AMONG_DST_NEG)) {
167163
/* we match only if it contains */
168164
if (!ebt_mac_wormhash_contains(wh_dst, dmac, dip))
169-
return EBT_NOMATCH;
165+
return false;
170166
} else {
171167
/* we match only if it DOES NOT contain */
172168
if (ebt_mac_wormhash_contains(wh_dst, dmac, dip))
173-
return EBT_NOMATCH;
169+
return false;
174170
}
175171
}
176172

177-
return EBT_MATCH;
173+
return true;
178174
}
179175

180176
static bool

‎net/bridge/netfilter/ebt_arp.c‎

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,8 @@
1515
#include <linux/netfilter_bridge/ebtables.h>
1616
#include <linux/netfilter_bridge/ebt_arp.h>
1717

18-
static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in,
18+
static bool ebt_filter_arp(const struct sk_buff *skb,
19+
const struct net_device *in,
1920
const struct net_device *out, const void *data, unsigned int datalen)
2021
{
2122
const struct ebt_arp_info *info = data;
@@ -24,42 +25,42 @@ static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in
2425

2526
ah = skb_header_pointer(skb, 0, sizeof(_arph), &_arph);
2627
if (ah == NULL)
27-
return EBT_NOMATCH;
28+
return false;
2829
if (info->bitmask & EBT_ARP_OPCODE && FWINV(info->opcode !=
2930
ah->ar_op, EBT_ARP_OPCODE))
30-
return EBT_NOMATCH;
31+
return false;
3132
if (info->bitmask & EBT_ARP_HTYPE && FWINV(info->htype !=
3233
ah->ar_hrd, EBT_ARP_HTYPE))
33-
return EBT_NOMATCH;
34+
return false;
3435
if (info->bitmask & EBT_ARP_PTYPE && FWINV(info->ptype !=
3536
ah->ar_pro, EBT_ARP_PTYPE))
36-
return EBT_NOMATCH;
37+
return false;
3738

3839
if (info->bitmask & (EBT_ARP_SRC_IP | EBT_ARP_DST_IP | EBT_ARP_GRAT)) {
3940
const __be32 *sap, *dap;
4041
__be32 saddr, daddr;
4142

4243
if (ah->ar_pln != sizeof(__be32) || ah->ar_pro != htons(ETH_P_IP))
43-
return EBT_NOMATCH;
44+
return false;
4445
sap = skb_header_pointer(skb, sizeof(struct arphdr) +
4546
ah->ar_hln, sizeof(saddr),
4647
&saddr);
4748
if (sap == NULL)
48-
return EBT_NOMATCH;
49+
return false;
4950
dap = skb_header_pointer(skb, sizeof(struct arphdr) +
5051
2*ah->ar_hln+sizeof(saddr),
5152
sizeof(daddr), &daddr);
5253
if (dap == NULL)
53-
return EBT_NOMATCH;
54+
return false;
5455
if (info->bitmask & EBT_ARP_SRC_IP &&
5556
FWINV(info->saddr != (*sap & info->smsk), EBT_ARP_SRC_IP))
56-
return EBT_NOMATCH;
57+
return false;
5758
if (info->bitmask & EBT_ARP_DST_IP &&
5859
FWINV(info->daddr != (*dap & info->dmsk), EBT_ARP_DST_IP))
59-
return EBT_NOMATCH;
60+
return false;
6061
if (info->bitmask & EBT_ARP_GRAT &&
6162
FWINV(*dap != *sap, EBT_ARP_GRAT))
62-
return EBT_NOMATCH;
63+
return false;
6364
}
6465

6566
if (info->bitmask & (EBT_ARP_SRC_MAC | EBT_ARP_DST_MAC)) {
@@ -68,36 +69,36 @@ static int ebt_filter_arp(const struct sk_buff *skb, const struct net_device *in
6869
uint8_t verdict, i;
6970

7071
if (ah->ar_hln != ETH_ALEN || ah->ar_hrd != htons(ARPHRD_ETHER))
71-
return EBT_NOMATCH;
72+
return false;
7273
if (info->bitmask & EBT_ARP_SRC_MAC) {
7374
mp = skb_header_pointer(skb, sizeof(struct arphdr),
7475
sizeof(_mac), &_mac);
7576
if (mp == NULL)
76-
return EBT_NOMATCH;
77+
return false;
7778
verdict = 0;
7879
for (i = 0; i < 6; i++)
7980
verdict |= (mp[i] ^ info->smaddr[i]) &
8081
info->smmsk[i];
8182
if (FWINV(verdict != 0, EBT_ARP_SRC_MAC))
82-
return EBT_NOMATCH;
83+
return false;
8384
}
8485

8586
if (info->bitmask & EBT_ARP_DST_MAC) {
8687
mp = skb_header_pointer(skb, sizeof(struct arphdr) +
8788
ah->ar_hln + ah->ar_pln,
8889
sizeof(_mac), &_mac);
8990
if (mp == NULL)
90-
return EBT_NOMATCH;
91+
return false;
9192
verdict = 0;
9293
for (i = 0; i < 6; i++)
9394
verdict |= (mp[i] ^ info->dmaddr[i]) &
9495
info->dmmsk[i];
9596
if (FWINV(verdict != 0, EBT_ARP_DST_MAC))
96-
return EBT_NOMATCH;
97+
return false;
9798
}
9899
}
99100

100-
return EBT_MATCH;
101+
return true;
101102
}
102103

103104
static bool ebt_arp_check(const char *tablename, unsigned int hookmask,

‎net/bridge/netfilter/ebt_ip.c‎

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,8 @@ struct tcpudphdr {
2424
__be16 dst;
2525
};
2626

27-
static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
27+
static bool ebt_filter_ip(const struct sk_buff *skb,
28+
const struct net_device *in,
2829
const struct net_device *out, const void *data,
2930
unsigned int datalen)
3031
{
@@ -36,46 +37,46 @@ static int ebt_filter_ip(const struct sk_buff *skb, const struct net_device *in,
3637

3738
ih = skb_header_pointer(skb, 0, sizeof(_iph), &_iph);
3839
if (ih == NULL)
39-
return EBT_NOMATCH;
40+
return false;
4041
if (info->bitmask & EBT_IP_TOS &&
4142
FWINV(info->tos != ih->tos, EBT_IP_TOS))
42-
return EBT_NOMATCH;
43+
return false;
4344
if (info->bitmask & EBT_IP_SOURCE &&
4445
FWINV((ih->saddr & info->smsk) !=
4546
info->saddr, EBT_IP_SOURCE))
46-
return EBT_NOMATCH;
47+
return false;
4748
if ((info->bitmask & EBT_IP_DEST) &&
4849
FWINV((ih->daddr & info->dmsk) !=
4950
info->daddr, EBT_IP_DEST))
50-
return EBT_NOMATCH;
51+
return false;
5152
if (info->bitmask & EBT_IP_PROTO) {
5253
if (FWINV(info->protocol != ih->protocol, EBT_IP_PROTO))
53-
return EBT_NOMATCH;
54+
return false;
5455
if (!(info->bitmask & EBT_IP_DPORT) &&
5556
!(info->bitmask & EBT_IP_SPORT))
56-
return EBT_MATCH;
57+
return true;
5758
if (ntohs(ih->frag_off) & IP_OFFSET)
58-
return EBT_NOMATCH;
59+
return false;
5960
pptr = skb_header_pointer(skb, ih->ihl*4,
6061
sizeof(_ports), &_ports);
6162
if (pptr == NULL)
62-
return EBT_NOMATCH;
63+
return false;
6364
if (info->bitmask & EBT_IP_DPORT) {
6465
u32 dst = ntohs(pptr->dst);
6566
if (FWINV(dst < info->dport[0] ||
6667
dst > info->dport[1],
6768
EBT_IP_DPORT))
68-
return EBT_NOMATCH;
69+
return false;
6970
}
7071
if (info->bitmask & EBT_IP_SPORT) {
7172
u32 src = ntohs(pptr->src);
7273
if (FWINV(src < info->sport[0] ||
7374
src > info->sport[1],
7475
EBT_IP_SPORT))
75-
return EBT_NOMATCH;
76+
return false;
7677
}
7778
}
78-
return EBT_MATCH;
79+
return true;
7980
}
8081

8182
static bool ebt_ip_check(const char *tablename, unsigned int hookmask,

‎net/bridge/netfilter/ebt_ip6.c‎

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ struct tcpudphdr {
2727
__be16 dst;
2828
};
2929

30-
static int ebt_filter_ip6(const struct sk_buff *skb,
30+
static bool ebt_filter_ip6(const struct sk_buff *skb,
3131
const struct net_device *in,
3232
const struct net_device *out, const void *data,
3333
unsigned int datalen)
@@ -42,54 +42,54 @@ static int ebt_filter_ip6(const struct sk_buff *skb,
4242

4343
ih6 = skb_header_pointer(skb, 0, sizeof(_ip6h), &_ip6h);
4444
if (ih6 == NULL)
45-
return EBT_NOMATCH;
45+
return false;
4646
if (info->bitmask & EBT_IP6_TCLASS &&
4747
FWINV(info->tclass != ipv6_get_dsfield(ih6), EBT_IP6_TCLASS))
48-
return EBT_NOMATCH;
48+
return false;
4949
for (i = 0; i < 4; i++)
5050
tmp_addr.in6_u.u6_addr32[i] = ih6->saddr.in6_u.u6_addr32[i] &
5151
info->smsk.in6_u.u6_addr32[i];
5252
if (info->bitmask & EBT_IP6_SOURCE &&
5353
FWINV((ipv6_addr_cmp(&tmp_addr, &info->saddr) != 0),
5454
EBT_IP6_SOURCE))
55-
return EBT_NOMATCH;
55+
return false;
5656
for (i = 0; i < 4; i++)
5757
tmp_addr.in6_u.u6_addr32[i] = ih6->daddr.in6_u.u6_addr32[i] &
5858
info->dmsk.in6_u.u6_addr32[i];
5959
if (info->bitmask & EBT_IP6_DEST &&
6060
FWINV((ipv6_addr_cmp(&tmp_addr, &info->daddr) != 0), EBT_IP6_DEST))
61-
return EBT_NOMATCH;
61+
return false;
6262
if (info->bitmask & EBT_IP6_PROTO) {
6363
uint8_t nexthdr = ih6->nexthdr;
6464
int offset_ph;
6565

6666
offset_ph = ipv6_skip_exthdr(skb, sizeof(_ip6h), &nexthdr);
6767
if (offset_ph == -1)
68-
return EBT_NOMATCH;
68+
return false;
6969
if (FWINV(info->protocol != nexthdr, EBT_IP6_PROTO))
70-
return EBT_NOMATCH;
70+
return false;
7171
if (!(info->bitmask & EBT_IP6_DPORT) &&
7272
!(info->bitmask & EBT_IP6_SPORT))
73-
return EBT_MATCH;
73+
return true;
7474
pptr = skb_header_pointer(skb, offset_ph, sizeof(_ports),
7575
&_ports);
7676
if (pptr == NULL)
77-
return EBT_NOMATCH;
77+
return false;
7878
if (info->bitmask & EBT_IP6_DPORT) {
7979
u32 dst = ntohs(pptr->dst);
8080
if (FWINV(dst < info->dport[0] ||
8181
dst > info->dport[1], EBT_IP6_DPORT))
82-
return EBT_NOMATCH;
82+
return false;
8383
}
8484
if (info->bitmask & EBT_IP6_SPORT) {
8585
u32 src = ntohs(pptr->src);
8686
if (FWINV(src < info->sport[0] ||
8787
src > info->sport[1], EBT_IP6_SPORT))
88-
return EBT_NOMATCH;
88+
return false;
8989
}
90-
return EBT_MATCH;
90+
return true;
9191
}
92-
return EBT_MATCH;
92+
return true;
9393
}
9494

9595
static bool ebt_ip6_check(const char *tablename, unsigned int hookmask,

0 commit comments

Comments
 (0)