[NETFILTER] nfnetlink: nfattr_parse() can never fail, make it void

nfattr_parse (and thus nfattr_parse_nested) always returns success. So we
can make them 'void' and remove all the checking at the caller side.

Based on original patch by Pablo Neira Ayuso <[EMAIL PROTECTED]>

Signed-off-by: Harald Welte <[EMAIL PROTECTED]>

---
commit b40f4d9f29829d5e96119b0747361d63d16e84b6
tree db6a3cd1e90a682c1ef0380b239b4d25ed37335c
parent 500cf07233d33f543562a7472158e00b6cc85c4e
author Harald Welte <[EMAIL PROTECTED]> Sat, 05 Nov 2005 11:30:08 +0100
committer Harald Welte <[EMAIL PROTECTED]> Sat, 05 Nov 2005 11:30:08 +0100

 include/linux/netfilter/nfnetlink.h         |    2 +
 net/ipv4/netfilter/ip_conntrack_netlink.c   |   45 +++++----------------------
 net/ipv4/netfilter/ip_conntrack_proto_tcp.c |    6 +---
 net/netfilter/nfnetlink.c                   |    4 +-
 4 files changed, 11 insertions(+), 46 deletions(-)

diff --git a/include/linux/netfilter/nfnetlink.h 
b/include/linux/netfilter/nfnetlink.h
--- a/include/linux/netfilter/nfnetlink.h
+++ b/include/linux/netfilter/nfnetlink.h
@@ -146,7 +146,7 @@ extern void nfnl_unlock(void);
 extern int nfnetlink_subsys_register(struct nfnetlink_subsystem *n);
 extern int nfnetlink_subsys_unregister(struct nfnetlink_subsystem *n);
 
-extern int nfattr_parse(struct nfattr *tb[], int maxattr, 
+extern void nfattr_parse(struct nfattr *tb[], int maxattr, 
                        struct nfattr *nfa, int len);
 
 #define nfattr_parse_nested(tb, max, nfa) \
diff --git a/net/ipv4/netfilter/ip_conntrack_netlink.c 
b/net/ipv4/netfilter/ip_conntrack_netlink.c
--- a/net/ipv4/netfilter/ip_conntrack_netlink.c
+++ b/net/ipv4/netfilter/ip_conntrack_netlink.c
@@ -482,9 +482,7 @@ ctnetlink_parse_tuple_ip(struct nfattr *
 
        DEBUGP("entered %s\n", __FUNCTION__);
 
-       
-       if (nfattr_parse_nested(tb, CTA_IP_MAX, attr) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_IP_MAX, attr);
 
        if (nfattr_bad_size(tb, CTA_IP_MAX, cta_min_ip))
                return -EINVAL;
@@ -500,9 +498,6 @@ ctnetlink_parse_tuple_ip(struct nfattr *
        DEBUGP("leaving\n");
 
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 
 static const int cta_min_proto[CTA_PROTO_MAX] = {
@@ -524,8 +519,7 @@ ctnetlink_parse_tuple_proto(struct nfatt
 
        DEBUGP("entered %s\n", __FUNCTION__);
 
-       if (nfattr_parse_nested(tb, CTA_PROTO_MAX, attr) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_PROTO_MAX, attr);
 
        if (nfattr_bad_size(tb, CTA_PROTO_MAX, cta_min_proto))
                return -EINVAL;
@@ -542,9 +536,6 @@ ctnetlink_parse_tuple_proto(struct nfatt
        }
        
        return ret;
-
-nfattr_failure:
-       return -1;
 }
 
 static inline int
@@ -558,8 +549,7 @@ ctnetlink_parse_tuple(struct nfattr *cda
 
        memset(tuple, 0, sizeof(*tuple));
 
-       if (nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_TUPLE_MAX, cda[type-1]);
 
        if (!tb[CTA_TUPLE_IP-1])
                return -EINVAL;
@@ -586,9 +576,6 @@ ctnetlink_parse_tuple(struct nfattr *cda
        DEBUGP("leaving\n");
 
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 
 #ifdef CONFIG_IP_NF_NAT_NEEDED
@@ -606,11 +593,10 @@ static int ctnetlink_parse_nat_proto(str
 
        DEBUGP("entered %s\n", __FUNCTION__);
 
-       if (nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_PROTONAT_MAX, attr);
 
        if (nfattr_bad_size(tb, CTA_PROTONAT_MAX, cta_min_protonat))
-               goto nfattr_failure;
+               return -1;
 
        npt = 
ip_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
        if (!npt)
@@ -629,9 +615,6 @@ static int ctnetlink_parse_nat_proto(str
 
        DEBUGP("leaving\n");
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 
 static inline int
@@ -645,8 +628,7 @@ ctnetlink_parse_nat(struct nfattr *cda[]
 
        memset(range, 0, sizeof(*range));
        
-       if (nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_NAT_MAX, cda[CTA_NAT-1]);
 
        if (tb[CTA_NAT_MINIP-1])
                range->min_ip = *(u_int32_t *)NFA_DATA(tb[CTA_NAT_MINIP-1]);
@@ -668,9 +650,6 @@ ctnetlink_parse_nat(struct nfattr *cda[]
 
        DEBUGP("leaving\n");
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 #endif
 
@@ -681,8 +660,7 @@ ctnetlink_parse_help(struct nfattr *attr
 
        DEBUGP("entered %s\n", __FUNCTION__);
 
-       if (nfattr_parse_nested(tb, CTA_HELP_MAX, attr) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_HELP_MAX, attr);
 
        if (!tb[CTA_HELP_NAME-1])
                return -EINVAL;
@@ -690,9 +668,6 @@ ctnetlink_parse_help(struct nfattr *attr
        *helper_name = NFA_DATA(tb[CTA_HELP_NAME-1]);
 
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 
 static int
@@ -960,8 +935,7 @@ ctnetlink_change_protoinfo(struct ip_con
        u_int16_t npt = ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum;
        int err = 0;
 
-       if (nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr) < 0)
-               goto nfattr_failure;
+       nfattr_parse_nested(tb, CTA_PROTOINFO_MAX, attr);
 
        proto = ip_conntrack_proto_find_get(npt);
        if (!proto)
@@ -972,9 +946,6 @@ ctnetlink_change_protoinfo(struct ip_con
        ip_conntrack_proto_put(proto); 
 
        return err;
-
-nfattr_failure:
-       return -ENOMEM;
 }
 
 static int
diff --git a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c 
b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
--- a/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
+++ b/net/ipv4/netfilter/ip_conntrack_proto_tcp.c
@@ -362,8 +362,7 @@ static int nfattr_to_tcp(struct nfattr *
        struct nfattr *attr = cda[CTA_PROTOINFO_TCP-1];
        struct nfattr *tb[CTA_PROTOINFO_TCP_MAX];
 
-        if (nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr) < 0)
-                goto nfattr_failure;
+        nfattr_parse_nested(tb, CTA_PROTOINFO_TCP_MAX, attr);
 
        if (!tb[CTA_PROTOINFO_TCP_STATE-1])
                return -EINVAL;
@@ -374,9 +373,6 @@ static int nfattr_to_tcp(struct nfattr *
        write_unlock_bh(&tcp_lock);
 
        return 0;
-
-nfattr_failure:
-       return -1;
 }
 #endif
 
diff --git a/net/netfilter/nfnetlink.c b/net/netfilter/nfnetlink.c
--- a/net/netfilter/nfnetlink.c
+++ b/net/netfilter/nfnetlink.c
@@ -128,7 +128,7 @@ void __nfa_fill(struct sk_buff *skb, int
        memset(NFA_DATA(nfa) + attrlen, 0, NFA_ALIGN(size) - size);
 }
 
-int nfattr_parse(struct nfattr *tb[], int maxattr, struct nfattr *nfa, int len)
+void nfattr_parse(struct nfattr *tb[], int maxattr, struct nfattr *nfa, int 
len)
 {
        memset(tb, 0, sizeof(struct nfattr *) * maxattr);
 
@@ -138,8 +138,6 @@ int nfattr_parse(struct nfattr *tb[], in
                        tb[flavor-1] = nfa;
                nfa = NFA_NEXT(nfa, len);
        }
-
-       return 0;
 }
 
 /**
-- 
- Harald Welte <[EMAIL PROTECTED]>                 http://netfilter.org/
============================================================================
  "Fragmentation is like classful addressing -- an interesting early
   architectural error that shows how much experimentation was going
   on while IP was being designed."                    -- Paul Vixie

Attachment: pgpJwJ09OyKwY.pgp
Description: PGP signature

Reply via email to