Skip to content

Commit 912da92

Browse files
Florian Westphalummakynes
authored andcommitted
netfilter: remove NF_NAT_RANGE_PROTO_RANDOM support
Historically this was net_random() based, and was then converted to a hash based algorithm (private boot seed + hash of endpoint addresses) due to concerns of leaking net_random() bits. RANDOM_FULLY mode was added later to avoid problems with hash based mode (see commit 34ce324, "netfilter: nf_nat: add full port randomization support" for details). Just make prandom_u32() the default search starting point and get rid of ->secure_port() altogether. Signed-off-by: Florian Westphal <[email protected]> Signed-off-by: Pablo Neira Ayuso <[email protected]>
1 parent df7043b commit 912da92

File tree

4 files changed

+2
-23
lines changed

4 files changed

+2
-23
lines changed

include/net/netfilter/nf_nat_l3proto.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ struct nf_nat_l3proto {
99
bool (*in_range)(const struct nf_conntrack_tuple *t,
1010
const struct nf_nat_range2 *range);
1111

12-
u32 (*secure_port)(const struct nf_conntrack_tuple *t, __be16);
13-
1412
bool (*manip_pkt)(struct sk_buff *skb,
1513
unsigned int iphdroff,
1614
const struct nf_nat_l4proto *l4proto,

net/ipv4/netfilter/nf_nat_l3proto_ipv4.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,12 +69,6 @@ static bool nf_nat_ipv4_in_range(const struct nf_conntrack_tuple *t,
6969
ntohl(t->src.u3.ip) <= ntohl(range->max_addr.ip);
7070
}
7171

72-
static u32 nf_nat_ipv4_secure_port(const struct nf_conntrack_tuple *t,
73-
__be16 dport)
74-
{
75-
return secure_ipv4_port_ephemeral(t->src.u3.ip, t->dst.u3.ip, dport);
76-
}
77-
7872
static bool nf_nat_ipv4_manip_pkt(struct sk_buff *skb,
7973
unsigned int iphdroff,
8074
const struct nf_nat_l4proto *l4proto,
@@ -162,7 +156,6 @@ static int nf_nat_ipv4_nlattr_to_range(struct nlattr *tb[],
162156
static const struct nf_nat_l3proto nf_nat_l3proto_ipv4 = {
163157
.l3proto = NFPROTO_IPV4,
164158
.in_range = nf_nat_ipv4_in_range,
165-
.secure_port = nf_nat_ipv4_secure_port,
166159
.manip_pkt = nf_nat_ipv4_manip_pkt,
167160
.csum_update = nf_nat_ipv4_csum_update,
168161
.csum_recalc = nf_nat_ipv4_csum_recalc,

net/ipv6/netfilter/nf_nat_l3proto_ipv6.c

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -68,12 +68,6 @@ static bool nf_nat_ipv6_in_range(const struct nf_conntrack_tuple *t,
6868
ipv6_addr_cmp(&t->src.u3.in6, &range->max_addr.in6) <= 0;
6969
}
7070

71-
static u32 nf_nat_ipv6_secure_port(const struct nf_conntrack_tuple *t,
72-
__be16 dport)
73-
{
74-
return secure_ipv6_port_ephemeral(t->src.u3.ip6, t->dst.u3.ip6, dport);
75-
}
76-
7771
static bool nf_nat_ipv6_manip_pkt(struct sk_buff *skb,
7872
unsigned int iphdroff,
7973
const struct nf_nat_l4proto *l4proto,
@@ -171,7 +165,6 @@ static int nf_nat_ipv6_nlattr_to_range(struct nlattr *tb[],
171165

172166
static const struct nf_nat_l3proto nf_nat_l3proto_ipv6 = {
173167
.l3proto = NFPROTO_IPV6,
174-
.secure_port = nf_nat_ipv6_secure_port,
175168
.in_range = nf_nat_ipv6_in_range,
176169
.manip_pkt = nf_nat_ipv6_manip_pkt,
177170
.csum_update = nf_nat_ipv6_csum_update,

net/netfilter/nf_nat_proto_common.c

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -77,15 +77,10 @@ void nf_nat_l4proto_unique_tuple(const struct nf_nat_l3proto *l3proto,
7777
range_size = max - min + 1;
7878
}
7979

80-
if (range->flags & NF_NAT_RANGE_PROTO_RANDOM) {
81-
off = l3proto->secure_port(tuple, maniptype == NF_NAT_MANIP_SRC
82-
? tuple->dst.u.all
83-
: tuple->src.u.all);
84-
} else if (range->flags & NF_NAT_RANGE_PROTO_OFFSET) {
80+
if (range->flags & NF_NAT_RANGE_PROTO_OFFSET)
8581
off = (ntohs(*portptr) - ntohs(range->base_proto.all));
86-
} else {
82+
else
8783
off = prandom_u32();
88-
}
8984

9085
attempts = range_size;
9186
if (attempts > max_attempts)

0 commit comments

Comments
 (0)