Commit 40e786bd authored by Florian Westphal's avatar Florian Westphal Committed by Pablo Neira Ayuso

netfilter: nat: fold in_range indirection into caller

No need for indirections here, we only support ipv4 and ipv6
and the called functions are very small.
Signed-off-by: default avatarFlorian Westphal <fw@strlen.de>
Signed-off-by: default avatarPablo Neira Ayuso <pablo@netfilter.org>
parent 203f2e78
...@@ -6,9 +6,6 @@ struct nf_nat_l4proto; ...@@ -6,9 +6,6 @@ struct nf_nat_l4proto;
struct nf_nat_l3proto { struct nf_nat_l3proto {
u8 l3proto; u8 l3proto;
bool (*in_range)(const struct nf_conntrack_tuple *t,
const struct nf_nat_range2 *range);
bool (*manip_pkt)(struct sk_buff *skb, bool (*manip_pkt)(struct sk_buff *skb,
unsigned int iphdroff, unsigned int iphdroff,
const struct nf_nat_l4proto *l4proto, const struct nf_nat_l4proto *l4proto,
......
...@@ -62,13 +62,6 @@ static void nf_nat_ipv4_decode_session(struct sk_buff *skb, ...@@ -62,13 +62,6 @@ static void nf_nat_ipv4_decode_session(struct sk_buff *skb,
} }
#endif /* CONFIG_XFRM */ #endif /* CONFIG_XFRM */
static bool nf_nat_ipv4_in_range(const struct nf_conntrack_tuple *t,
const struct nf_nat_range2 *range)
{
return ntohl(t->src.u3.ip) >= ntohl(range->min_addr.ip) &&
ntohl(t->src.u3.ip) <= ntohl(range->max_addr.ip);
}
static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb, static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb,
unsigned int iphdroff, unsigned int iphdroff,
const struct nf_nat_l4proto *l4proto, const struct nf_nat_l4proto *l4proto,
...@@ -155,7 +148,6 @@ static int nf_nat_ipv4_nlattr_to_range(struct nlattr *tb[], ...@@ -155,7 +148,6 @@ static int nf_nat_ipv4_nlattr_to_range(struct nlattr *tb[],
static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = { static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = {
.l3proto = NFPROTO_IPV4, .l3proto = NFPROTO_IPV4,
.in_range = nf_nat_ipv4_in_range,
.manip_pkt = nf_nat_ipv4_manip_pkt, .manip_pkt = nf_nat_ipv4_manip_pkt,
.csum_update = nf_nat_ipv4_csum_update, .csum_update = nf_nat_ipv4_csum_update,
.csum_recalc = nf_nat_ipv4_csum_recalc, .csum_recalc = nf_nat_ipv4_csum_recalc,
......
...@@ -61,13 +61,6 @@ static void nf_nat_ipv6_decode_session(struct sk_buff *skb, ...@@ -61,13 +61,6 @@ static void nf_nat_ipv6_decode_session(struct sk_buff *skb,
} }
#endif #endif
static bool nf_nat_ipv6_in_range(const struct nf_conntrack_tuple *t,
const struct nf_nat_range2 *range)
{
return ipv6_addr_cmp(&t->src.u3.in6, &range->min_addr.in6) >= 0 &&
ipv6_addr_cmp(&t->src.u3.in6, &range->max_addr.in6) <= 0;
}
static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb, static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,
unsigned int iphdroff, unsigned int iphdroff,
const struct nf_nat_l4proto *l4proto, const struct nf_nat_l4proto *l4proto,
...@@ -165,7 +158,6 @@ static int nf_nat_ipv6_nlattr_to_range(struct nlattr *tb[], ...@@ -165,7 +158,6 @@ static int nf_nat_ipv6_nlattr_to_range(struct nlattr *tb[],
static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = { static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = {
.l3proto = NFPROTO_IPV6, .l3proto = NFPROTO_IPV6,
.in_range = nf_nat_ipv6_in_range,
.manip_pkt = nf_nat_ipv6_manip_pkt, .manip_pkt = nf_nat_ipv6_manip_pkt,
.csum_update = nf_nat_ipv6_csum_update, .csum_update = nf_nat_ipv6_csum_update,
.csum_recalc = nf_nat_ipv6_csum_recalc, .csum_recalc = nf_nat_ipv6_csum_recalc,
......
...@@ -172,11 +172,21 @@ nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple, ...@@ -172,11 +172,21 @@ nf_nat_used_tuple(const struct nf_conntrack_tuple *tuple,
} }
EXPORT_SYMBOL(nf_nat_used_tuple); EXPORT_SYMBOL(nf_nat_used_tuple);
static bool nf_nat_inet_in_range(const struct nf_conntrack_tuple *t,
const struct nf_nat_range2 *range)
{
if (t->src.l3num == NFPROTO_IPV4)
return ntohl(t->src.u3.ip) >= ntohl(range->min_addr.ip) &&
ntohl(t->src.u3.ip) <= ntohl(range->max_addr.ip);
return ipv6_addr_cmp(&t->src.u3.in6, &range->min_addr.in6) >= 0 &&
ipv6_addr_cmp(&t->src.u3.in6, &range->max_addr.in6) <= 0;
}
/* If we source map this tuple so reply looks like reply_tuple, will /* If we source map this tuple so reply looks like reply_tuple, will
* that meet the constraints of range. * that meet the constraints of range.
*/ */
static int in_range(const struct nf_nat_l3proto *l3proto, static int in_range(const struct nf_nat_l4proto *l4proto,
const struct nf_nat_l4proto *l4proto,
const struct nf_conntrack_tuple *tuple, const struct nf_conntrack_tuple *tuple,
const struct nf_nat_range2 *range) const struct nf_nat_range2 *range)
{ {
...@@ -184,7 +194,7 @@ static int in_range(const struct nf_nat_l3proto *l3proto, ...@@ -184,7 +194,7 @@ static int in_range(const struct nf_nat_l3proto *l3proto,
* range specified, otherwise let this drag us onto a new src IP. * range specified, otherwise let this drag us onto a new src IP.
*/ */
if (range->flags & NF_NAT_RANGE_MAP_IPS && if (range->flags & NF_NAT_RANGE_MAP_IPS &&
!l3proto->in_range(tuple, range)) !nf_nat_inet_in_range(tuple, range))
return 0; return 0;
if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) || if (!(range->flags & NF_NAT_RANGE_PROTO_SPECIFIED) ||
...@@ -211,7 +221,6 @@ same_src(const struct nf_conn *ct, ...@@ -211,7 +221,6 @@ same_src(const struct nf_conn *ct,
static int static int
find_appropriate_src(struct net *net, find_appropriate_src(struct net *net,
const struct nf_conntrack_zone *zone, const struct nf_conntrack_zone *zone,
const struct nf_nat_l3proto *l3proto,
const struct nf_nat_l4proto *l4proto, const struct nf_nat_l4proto *l4proto,
const struct nf_conntrack_tuple *tuple, const struct nf_conntrack_tuple *tuple,
struct nf_conntrack_tuple *result, struct nf_conntrack_tuple *result,
...@@ -229,7 +238,7 @@ find_appropriate_src(struct net *net, ...@@ -229,7 +238,7 @@ find_appropriate_src(struct net *net,
&ct->tuplehash[IP_CT_DIR_REPLY].tuple); &ct->tuplehash[IP_CT_DIR_REPLY].tuple);
result->dst = tuple->dst; result->dst = tuple->dst;
if (in_range(l3proto, l4proto, result, range)) if (in_range(l4proto, result, range))
return 1; return 1;
} }
} }
...@@ -463,12 +472,12 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple, ...@@ -463,12 +472,12 @@ get_unique_tuple(struct nf_conntrack_tuple *tuple,
if (maniptype == NF_NAT_MANIP_SRC && if (maniptype == NF_NAT_MANIP_SRC &&
!(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) { !(range->flags & NF_NAT_RANGE_PROTO_RANDOM_ALL)) {
/* try the original tuple first */ /* try the original tuple first */
if (in_range(l3proto, l4proto, orig_tuple, range)) { if (in_range(l4proto, orig_tuple, range)) {
if (!nf_nat_used_tuple(orig_tuple, ct)) { if (!nf_nat_used_tuple(orig_tuple, ct)) {
*tuple = *orig_tuple; *tuple = *orig_tuple;
goto out; goto out;
} }
} else if (find_appropriate_src(net, zone, l3proto, l4proto, } else if (find_appropriate_src(net, zone, l4proto,
orig_tuple, tuple, range)) { orig_tuple, tuple, range)) {
pr_debug("get_unique_tuple: Found current src map\n"); pr_debug("get_unique_tuple: Found current src map\n");
if (!nf_nat_used_tuple(tuple, ct)) if (!nf_nat_used_tuple(tuple, ct))
......
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