diff options
author | Stephen Hemminger <shemminger@vyatta.com> | 2008-08-19 00:32:32 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2008-08-19 00:32:32 -0400 |
commit | 9f593653742d1dd816c4e94c6e5154a57ccba6d1 (patch) | |
tree | 1e71181cc80da8dc3d6e1da202943482b9eb5500 | |
parent | fab00c5d15091546be681426c60b2ed2c10513bf (diff) |
nf_nat: use secure_ipv4_port_ephemeral() for NAT port randomization
Use incoming network tuple as seed for NAT port randomization.
This avoids concerns of leaking net_random() bits, and also gives better
port distribution. Don't have NAT server, compile tested only.
Signed-off-by: Stephen Hemminger <shemminger@vyatta.com>
[ added missing EXPORT_SYMBOL_GPL ]
Signed-off-by: Patrick McHardy <kaber@trash.net>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/char/random.c | 1 | ||||
-rw-r--r-- | net/ipv4/netfilter/nf_nat_proto_common.c | 8 |
2 files changed, 7 insertions, 2 deletions
diff --git a/drivers/char/random.c b/drivers/char/random.c index e0d0e371909c..1838aa3d24fe 100644 --- a/drivers/char/random.c +++ b/drivers/char/random.c | |||
@@ -1571,6 +1571,7 @@ u32 secure_ipv4_port_ephemeral(__be32 saddr, __be32 daddr, __be16 dport) | |||
1571 | 1571 | ||
1572 | return half_md4_transform(hash, keyptr->secret); | 1572 | return half_md4_transform(hash, keyptr->secret); |
1573 | } | 1573 | } |
1574 | EXPORT_SYMBOL_GPL(secure_ipv4_port_ephemeral); | ||
1574 | 1575 | ||
1575 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) | 1576 | #if defined(CONFIG_IPV6) || defined(CONFIG_IPV6_MODULE) |
1576 | u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, | 1577 | u32 secure_ipv6_port_ephemeral(const __be32 *saddr, const __be32 *daddr, |
diff --git a/net/ipv4/netfilter/nf_nat_proto_common.c b/net/ipv4/netfilter/nf_nat_proto_common.c index 91537f11273f..6c4f11f51446 100644 --- a/net/ipv4/netfilter/nf_nat_proto_common.c +++ b/net/ipv4/netfilter/nf_nat_proto_common.c | |||
@@ -73,9 +73,13 @@ bool nf_nat_proto_unique_tuple(struct nf_conntrack_tuple *tuple, | |||
73 | range_size = ntohs(range->max.all) - min + 1; | 73 | range_size = ntohs(range->max.all) - min + 1; |
74 | } | 74 | } |
75 | 75 | ||
76 | off = *rover; | ||
77 | if (range->flags & IP_NAT_RANGE_PROTO_RANDOM) | 76 | if (range->flags & IP_NAT_RANGE_PROTO_RANDOM) |
78 | off = net_random(); | 77 | off = secure_ipv4_port_ephemeral(tuple->src.u3.ip, tuple->dst.u3.ip, |
78 | maniptype == IP_NAT_MANIP_SRC | ||
79 | ? tuple->dst.u.all | ||
80 | : tuple->src.u.all); | ||
81 | else | ||
82 | off = *rover; | ||
79 | 83 | ||
80 | for (i = 0; i < range_size; i++, off++) { | 84 | for (i = 0; i < range_size; i++, off++) { |
81 | *portptr = htons(min + off % range_size); | 85 | *portptr = htons(min + off % range_size); |