Skip to content

Commit

Permalink
[NETFILTER]: x_tables: switch xt_match->match to bool
Browse files Browse the repository at this point in the history
Switch the return type of match functions to boolean

Signed-off-by: Jan Engelhardt <jengelh@gmx.de>
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
  • Loading branch information
Jan Engelhardt authored and David S. Miller committed Jul 11, 2007
1 parent cff533a commit 1d93a9c
Show file tree
Hide file tree
Showing 45 changed files with 320 additions and 327 deletions.
16 changes: 8 additions & 8 deletions include/linux/netfilter/x_tables.h
Original file line number Diff line number Diff line change
Expand Up @@ -141,14 +141,14 @@ struct xt_match
/* Arguments changed since 2.6.9, as this must now handle
non-linear skb, using skb_header_pointer and
skb_ip_make_writable. */
int (*match)(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
const struct xt_match *match,
const void *matchinfo,
int offset,
unsigned int protoff,
bool *hotdrop);
bool (*match)(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
const struct xt_match *match,
const void *matchinfo,
int offset,
unsigned int protoff,
bool *hotdrop);

/* Called when user tries to insert an entry of this type. */
/* Should return true or false. */
Expand Down
26 changes: 13 additions & 13 deletions net/ipv4/netfilter/ip_tables.c
Original file line number Diff line number Diff line change
Expand Up @@ -183,19 +183,19 @@ ipt_error(struct sk_buff **pskb,
}

static inline
int do_match(struct ipt_entry_match *m,
const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int offset,
bool *hotdrop)
bool do_match(struct ipt_entry_match *m,
const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
int offset,
bool *hotdrop)
{
/* Stop iteration if it doesn't match */
if (!m->u.kernel.match->match(skb, in, out, m->u.kernel.match, m->data,
offset, ip_hdrlen(skb), hotdrop))
return 1;
return true;
else
return 0;
return false;
}

static inline struct ipt_entry *
Expand Down Expand Up @@ -2105,16 +2105,16 @@ void ipt_unregister_table(struct xt_table *table)
}

/* Returns 1 if the type and code is matched by the range, 0 otherwise */
static inline int
static inline bool
icmp_type_code_match(u_int8_t test_type, u_int8_t min_code, u_int8_t max_code,
u_int8_t type, u_int8_t code,
int invert)
bool invert)
{
return ((test_type == 0xFF) || (type == test_type && code >= min_code && code <= max_code))
^ invert;
}

static int
static bool
icmp_match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand All @@ -2129,7 +2129,7 @@ icmp_match(const struct sk_buff *skb,

/* Must not be a fragment. */
if (offset)
return 0;
return false;

ic = skb_header_pointer(skb, protoff, sizeof(_icmph), &_icmph);
if (ic == NULL) {
Expand All @@ -2138,7 +2138,7 @@ icmp_match(const struct sk_buff *skb,
*/
duprintf("Dropping evil ICMP tinygram.\n");
*hotdrop = true;
return 0;
return false;
}

return icmp_type_code_match(icmpinfo->type,
Expand Down
12 changes: 6 additions & 6 deletions net/ipv4/netfilter/ipt_addrtype.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,19 +22,19 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("Patrick McHardy <kaber@trash.net>");
MODULE_DESCRIPTION("iptables addrtype match");

static inline int match_type(__be32 addr, u_int16_t mask)
static inline bool match_type(__be32 addr, u_int16_t mask)
{
return !!(mask & (1 << inet_addr_type(addr)));
}

static int match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
static bool match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
{
const struct ipt_addrtype_info *info = matchinfo;
const struct iphdr *iph = ip_hdr(skb);
int ret = 1;
bool ret = true;

if (info->source)
ret &= match_type(iph->saddr, info->source)^info->invert_source;
Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/netfilter/ipt_ah.c
Original file line number Diff line number Diff line change
Expand Up @@ -25,18 +25,18 @@ MODULE_DESCRIPTION("iptables AH SPI match module");
#endif

/* Returns 1 if the spi is matched by the range, 0 otherwise */
static inline int
spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, int invert)
static inline bool
spi_match(u_int32_t min, u_int32_t max, u_int32_t spi, bool invert)
{
int r=0;
bool r;
duprintf("ah spi_match:%c 0x%x <= 0x%x <= 0x%x",invert? '!':' ',
min,spi,max);
r=(spi >= min && spi <= max) ^ invert;
duprintf(" result %s\n",r? "PASS" : "FAILED");
return r;
}

static int
static bool
match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand All @@ -51,7 +51,7 @@ match(const struct sk_buff *skb,

/* Must not be a fragment. */
if (offset)
return 0;
return false;

ah = skb_header_pointer(skb, protoff,
sizeof(_ahdr), &_ahdr);
Expand Down
38 changes: 19 additions & 19 deletions net/ipv4/netfilter/ipt_ecn.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,15 +22,15 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
MODULE_DESCRIPTION("iptables ECN matching module");
MODULE_LICENSE("GPL");

static inline int match_ip(const struct sk_buff *skb,
const struct ipt_ecn_info *einfo)
static inline bool match_ip(const struct sk_buff *skb,
const struct ipt_ecn_info *einfo)
{
return (ip_hdr(skb)->tos & IPT_ECN_IP_MASK) == einfo->ip_ect;
}

static inline int match_tcp(const struct sk_buff *skb,
const struct ipt_ecn_info *einfo,
bool *hotdrop)
static inline bool match_tcp(const struct sk_buff *skb,
const struct ipt_ecn_info *einfo,
bool *hotdrop)
{
struct tcphdr _tcph, *th;

Expand All @@ -40,51 +40,51 @@ static inline int match_tcp(const struct sk_buff *skb,
th = skb_header_pointer(skb, ip_hdrlen(skb), sizeof(_tcph), &_tcph);
if (th == NULL) {
*hotdrop = false;
return 0;
return false;
}

if (einfo->operation & IPT_ECN_OP_MATCH_ECE) {
if (einfo->invert & IPT_ECN_OP_MATCH_ECE) {
if (th->ece == 1)
return 0;
return false;
} else {
if (th->ece == 0)
return 0;
return false;
}
}

if (einfo->operation & IPT_ECN_OP_MATCH_CWR) {
if (einfo->invert & IPT_ECN_OP_MATCH_CWR) {
if (th->cwr == 1)
return 0;
return false;
} else {
if (th->cwr == 0)
return 0;
return false;
}
}

return 1;
return true;
}

static int match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
static bool match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
{
const struct ipt_ecn_info *info = matchinfo;

if (info->operation & IPT_ECN_OP_MATCH_IP)
if (!match_ip(skb, info))
return 0;
return false;

if (info->operation & (IPT_ECN_OP_MATCH_ECE|IPT_ECN_OP_MATCH_CWR)) {
if (ip_hdr(skb)->protocol != IPPROTO_TCP)
return 0;
return false;
if (!match_tcp(skb, info, hotdrop))
return 0;
return false;
}

return 1;
return true;
}

static int checkentry(const char *tablename, const void *ip_void,
Expand Down
8 changes: 4 additions & 4 deletions net/ipv4/netfilter/ipt_iprange.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ MODULE_DESCRIPTION("iptables arbitrary IP range match module");
#define DEBUGP(format, args...)
#endif

static int
static bool
match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand All @@ -44,7 +44,7 @@ match(const struct sk_buff *skb,
info->flags & IPRANGE_SRC_INV ? "(INV) " : "",
NIPQUAD(info->src.min_ip),
NIPQUAD(info->src.max_ip));
return 0;
return false;
}
}
if (info->flags & IPRANGE_DST) {
Expand All @@ -57,10 +57,10 @@ match(const struct sk_buff *skb,
info->flags & IPRANGE_DST_INV ? "(INV) " : "",
NIPQUAD(info->dst.min_ip),
NIPQUAD(info->dst.max_ip));
return 0;
return false;
}
}
return 1;
return true;
}

static struct xt_match iprange_match = {
Expand Down
10 changes: 5 additions & 5 deletions net/ipv4/netfilter/ipt_owner.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ MODULE_LICENSE("GPL");
MODULE_AUTHOR("Marc Boucher <marc@mbsi.ca>");
MODULE_DESCRIPTION("iptables owner match");

static int
static bool
match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand All @@ -34,21 +34,21 @@ match(const struct sk_buff *skb,
const struct ipt_owner_info *info = matchinfo;

if (!skb->sk || !skb->sk->sk_socket || !skb->sk->sk_socket->file)
return 0;
return false;

if(info->match & IPT_OWNER_UID) {
if ((skb->sk->sk_socket->file->f_uid != info->uid) ^
!!(info->invert & IPT_OWNER_UID))
return 0;
return false;
}

if(info->match & IPT_OWNER_GID) {
if ((skb->sk->sk_socket->file->f_gid != info->gid) ^
!!(info->invert & IPT_OWNER_GID))
return 0;
return false;
}

return 1;
return true;
}

static int
Expand Down
12 changes: 6 additions & 6 deletions net/ipv4/netfilter/ipt_recent.c
Original file line number Diff line number Diff line change
Expand Up @@ -169,7 +169,7 @@ static void recent_table_flush(struct recent_table *t)
}
}

static int
static bool
ipt_recent_match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
Expand All @@ -180,7 +180,7 @@ ipt_recent_match(const struct sk_buff *skb,
struct recent_entry *e;
__be32 addr;
u_int8_t ttl;
int ret = info->invert;
bool ret = info->invert;

if (info->side == IPT_RECENT_DEST)
addr = ip_hdr(skb)->daddr;
Expand All @@ -202,15 +202,15 @@ ipt_recent_match(const struct sk_buff *skb,
e = recent_entry_init(t, addr, ttl);
if (e == NULL)
*hotdrop = true;
ret ^= 1;
ret = !ret;
goto out;
}

if (info->check_set & IPT_RECENT_SET)
ret ^= 1;
ret = !ret;
else if (info->check_set & IPT_RECENT_REMOVE) {
recent_entry_remove(t, e);
ret ^= 1;
ret = !ret;
} else if (info->check_set & (IPT_RECENT_CHECK | IPT_RECENT_UPDATE)) {
unsigned long t = jiffies - info->seconds * HZ;
unsigned int i, hits = 0;
Expand All @@ -219,7 +219,7 @@ ipt_recent_match(const struct sk_buff *skb,
if (info->seconds && time_after(t, e->stamps[i]))
continue;
if (++hits >= info->hit_count) {
ret ^= 1;
ret = !ret;
break;
}
}
Expand Down
2 changes: 1 addition & 1 deletion net/ipv4/netfilter/ipt_tos.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
MODULE_LICENSE("GPL");
MODULE_DESCRIPTION("iptables TOS match module");

static int
static bool
match(const struct sk_buff *skb,
const struct net_device *in,
const struct net_device *out,
Expand Down
12 changes: 6 additions & 6 deletions net/ipv4/netfilter/ipt_ttl.c
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,10 @@ MODULE_AUTHOR("Harald Welte <laforge@netfilter.org>");
MODULE_DESCRIPTION("IP tables TTL matching module");
MODULE_LICENSE("GPL");

static int match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
static bool match(const struct sk_buff *skb,
const struct net_device *in, const struct net_device *out,
const struct xt_match *match, const void *matchinfo,
int offset, unsigned int protoff, bool *hotdrop)
{
const struct ipt_ttl_info *info = matchinfo;
const u8 ttl = ip_hdr(skb)->ttl;
Expand All @@ -42,10 +42,10 @@ static int match(const struct sk_buff *skb,
default:
printk(KERN_WARNING "ipt_ttl: unknown mode %d\n",
info->mode);
return 0;
return false;
}

return 0;
return false;
}

static struct xt_match ttl_match = {
Expand Down
Loading

0 comments on commit 1d93a9c

Please sign in to comment.