aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPatrick McHardy <kaber@trash.net>2008-04-14 05:15:47 -0400
committerPatrick McHardy <kaber@trash.net>2008-04-14 05:15:47 -0400
commitca6a50749012fc17feeec91ee2f9eeacacf06f0b (patch)
treeb5dd90319ac557fedda67287576a4bb4be38347b
parent535b57c7c1524125444aa1b874332f6ff1608ef5 (diff)
[NETFILTER]: nf_conntrack_netlink: clean up NAT protocol parsing
Move responsibility for setting the IP_NAT_RANGE_PROTO_SPECIFIED flag to the NAT protocol, properly propagate errors and get rid of ugly return value convention. Signed-off-by: Patrick McHardy <kaber@trash.net>
-rw-r--r--net/ipv4/netfilter/nf_nat_proto_common.c18
-rw-r--r--net/netfilter/nf_conntrack_netlink.c15
2 files changed, 8 insertions, 25 deletions
diff --git a/net/ipv4/netfilter/nf_nat_proto_common.c b/net/ipv4/netfilter/nf_nat_proto_common.c
index ef4dc3988925..4904b86265e1 100644
--- a/net/ipv4/netfilter/nf_nat_proto_common.c
+++ b/net/ipv4/netfilter/nf_nat_proto_common.c
@@ -105,24 +105,16 @@ EXPORT_SYMBOL_GPL(nf_nat_proto_nlattr_to_range);
105int nf_nat_proto_nlattr_to_range(struct nlattr *tb[], 105int nf_nat_proto_nlattr_to_range(struct nlattr *tb[],
106 struct nf_nat_range *range) 106 struct nf_nat_range *range)
107{ 107{
108 int ret = 0;
109
110 /* we have to return whether we actually parsed something or not */
111
112 if (tb[CTA_PROTONAT_PORT_MIN]) { 108 if (tb[CTA_PROTONAT_PORT_MIN]) {
113 ret = 1;
114 range->min.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]); 109 range->min.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
110 range->max.all = range->min.tcp.port;
111 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
115 } 112 }
116 113 if (tb[CTA_PROTONAT_PORT_MAX]) {
117 if (!tb[CTA_PROTONAT_PORT_MAX]) {
118 if (ret)
119 range->max.all = range->min.all;
120 } else {
121 ret = 1;
122 range->max.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]); 114 range->max.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
115 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
123 } 116 }
124 117 return 0;
125 return ret;
126} 118}
127EXPORT_SYMBOL_GPL(nf_nat_proto_range_to_nlattr); 119EXPORT_SYMBOL_GPL(nf_nat_proto_range_to_nlattr);
128#endif 120#endif
diff --git a/net/netfilter/nf_conntrack_netlink.c b/net/netfilter/nf_conntrack_netlink.c
index 4a1b42b2b7a5..79d5ecde0ddc 100644
--- a/net/netfilter/nf_conntrack_netlink.c
+++ b/net/netfilter/nf_conntrack_netlink.c
@@ -705,19 +705,10 @@ static int nfnetlink_parse_nat_proto(struct nlattr *attr,
705 return err; 705 return err;
706 706
707 npt = nf_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum); 707 npt = nf_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
708 708 if (npt->nlattr_to_range)
709 if (!npt->nlattr_to_range) { 709 err = npt->nlattr_to_range(tb, range);
710 nf_nat_proto_put(npt);
711 return 0;
712 }
713
714 /* nlattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
715 if (npt->nlattr_to_range(tb, range) > 0)
716 range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
717
718 nf_nat_proto_put(npt); 710 nf_nat_proto_put(npt);
719 711 return err;
720 return 0;
721} 712}
722 713
723static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = { 714static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = {