Commit ca6a5074 authored by Patrick McHardy's avatar Patrick McHardy

[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: default avatarPatrick McHardy <kaber@trash.net>
parent 535b57c7
...@@ -105,24 +105,16 @@ EXPORT_SYMBOL_GPL(nf_nat_proto_nlattr_to_range); ...@@ -105,24 +105,16 @@ EXPORT_SYMBOL_GPL(nf_nat_proto_nlattr_to_range);
int nf_nat_proto_nlattr_to_range(struct nlattr *tb[], int nf_nat_proto_nlattr_to_range(struct nlattr *tb[],
struct nf_nat_range *range) struct nf_nat_range *range)
{ {
int ret = 0;
/* we have to return whether we actually parsed something or not */
if (tb[CTA_PROTONAT_PORT_MIN]) { if (tb[CTA_PROTONAT_PORT_MIN]) {
ret = 1;
range->min.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]); range->min.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MIN]);
range->max.all = range->min.tcp.port;
range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
} }
if (tb[CTA_PROTONAT_PORT_MAX]) {
if (!tb[CTA_PROTONAT_PORT_MAX]) {
if (ret)
range->max.all = range->min.all;
} else {
ret = 1;
range->max.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]); range->max.all = nla_get_be16(tb[CTA_PROTONAT_PORT_MAX]);
range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
} }
return 0;
return ret;
} }
EXPORT_SYMBOL_GPL(nf_nat_proto_range_to_nlattr); EXPORT_SYMBOL_GPL(nf_nat_proto_range_to_nlattr);
#endif #endif
...@@ -705,19 +705,10 @@ static int nfnetlink_parse_nat_proto(struct nlattr *attr, ...@@ -705,19 +705,10 @@ static int nfnetlink_parse_nat_proto(struct nlattr *attr,
return err; return err;
npt = nf_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum); npt = nf_nat_proto_find_get(ct->tuplehash[IP_CT_DIR_ORIGINAL].tuple.dst.protonum);
if (npt->nlattr_to_range)
if (!npt->nlattr_to_range) { err = npt->nlattr_to_range(tb, range);
nf_nat_proto_put(npt); nf_nat_proto_put(npt);
return 0; return err;
}
/* nlattr_to_range returns 1 if it parsed, 0 if not, neg. on error */
if (npt->nlattr_to_range(tb, range) > 0)
range->flags |= IP_NAT_RANGE_PROTO_SPECIFIED;
nf_nat_proto_put(npt);
return 0;
} }
static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = { static const struct nla_policy nat_nla_policy[CTA_NAT_MAX+1] = {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment