diff options
author | Anton Arapov <aarapov@redhat.com> | 2007-10-19 01:00:17 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2007-10-19 01:00:17 -0400 |
commit | a25de534f89c515c82d3553c42d3bb02c2d1a7da (patch) | |
tree | d09a5ed1f8a9fa5254c9ebf5cb49bf95e636a3e8 | |
parent | be702d5e38e2e7e554604b223794f87c12fa6811 (diff) |
[INET]: Justification for local port range robustness.
There is a justifying patch for Stephen's patches. Stephen's patches
disallows using a port range of one single port and brakes the meaning
of the 'remaining' variable, in some places it has different meaning.
My patch gives back the sense of 'remaining' variable. It should mean
how many ports are remaining and nothing else. Also my patch allows
using a single port.
I sure we must be able to use mentioned port range, this does not
restricted by documentation and does not brake current behavior.
usefull links:
Patches posted by Stephen Hemminger
http://marc.info/?l=linux-netdev&m=119206106218187&w=2
http://marc.info/?l=linux-netdev&m=119206109918235&w=2
Andrew Morton's comment
http://marc.info/?l=linux-kernel&m=119248225007737&w=2
1. Allows using a port range of one single port.
2. Gives back sense of 'remaining' variable.
Signed-off-by: Anton Arapov <aarapov@redhat.com>
Acked-by: Stephen Hemminger <shemminger@linux-foundation.org>
Signed-off-by: David S. Miller <davem@davemloft.net>
-rw-r--r-- | drivers/infiniband/core/cma.c | 5 | ||||
-rw-r--r-- | net/ipv4/inet_connection_sock.c | 2 | ||||
-rw-r--r-- | net/ipv4/inet_hashtables.c | 2 | ||||
-rw-r--r-- | net/ipv4/sysctl_net_ipv4.c | 4 | ||||
-rw-r--r-- | net/ipv4/udp.c | 5 | ||||
-rw-r--r-- | net/ipv6/inet6_hashtables.c | 2 |
6 files changed, 11 insertions, 9 deletions
diff --git a/drivers/infiniband/core/cma.c b/drivers/infiniband/core/cma.c index 93644f8259..d08fb30768 100644 --- a/drivers/infiniband/core/cma.c +++ b/drivers/infiniband/core/cma.c | |||
@@ -2797,11 +2797,12 @@ static void cma_remove_one(struct ib_device *device) | |||
2797 | 2797 | ||
2798 | static int cma_init(void) | 2798 | static int cma_init(void) |
2799 | { | 2799 | { |
2800 | int ret, low, high; | 2800 | int ret, low, high, remaining; |
2801 | 2801 | ||
2802 | get_random_bytes(&next_port, sizeof next_port); | 2802 | get_random_bytes(&next_port, sizeof next_port); |
2803 | inet_get_local_port_range(&low, &high); | 2803 | inet_get_local_port_range(&low, &high); |
2804 | next_port = ((unsigned int) next_port % (high - low)) + low; | 2804 | remaining = (high - low) + 1; |
2805 | next_port = ((unsigned int) next_port % remaining) + low; | ||
2805 | 2806 | ||
2806 | cma_wq = create_singlethread_workqueue("rdma_cm"); | 2807 | cma_wq = create_singlethread_workqueue("rdma_cm"); |
2807 | if (!cma_wq) | 2808 | if (!cma_wq) |
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 3cef12835c..8fb6ca2370 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c | |||
@@ -93,7 +93,7 @@ int inet_csk_get_port(struct inet_hashinfo *hashinfo, | |||
93 | int remaining, rover, low, high; | 93 | int remaining, rover, low, high; |
94 | 94 | ||
95 | inet_get_local_port_range(&low, &high); | 95 | inet_get_local_port_range(&low, &high); |
96 | remaining = high - low; | 96 | remaining = (high - low) + 1; |
97 | rover = net_random() % remaining + low; | 97 | rover = net_random() % remaining + low; |
98 | 98 | ||
99 | do { | 99 | do { |
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index fac6398e43..16eecc7046 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c | |||
@@ -286,7 +286,7 @@ int inet_hash_connect(struct inet_timewait_death_row *death_row, | |||
286 | struct inet_timewait_sock *tw = NULL; | 286 | struct inet_timewait_sock *tw = NULL; |
287 | 287 | ||
288 | inet_get_local_port_range(&low, &high); | 288 | inet_get_local_port_range(&low, &high); |
289 | remaining = high - low; | 289 | remaining = (high - low) + 1; |
290 | 290 | ||
291 | local_bh_disable(); | 291 | local_bh_disable(); |
292 | for (i = 1; i <= remaining; i++) { | 292 | for (i = 1; i <= remaining; i++) { |
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index c78acc1a7f..ffddd2b453 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c | |||
@@ -122,7 +122,7 @@ static int ipv4_local_port_range(ctl_table *table, int write, struct file *filp, | |||
122 | ret = proc_dointvec_minmax(&tmp, write, filp, buffer, lenp, ppos); | 122 | ret = proc_dointvec_minmax(&tmp, write, filp, buffer, lenp, ppos); |
123 | 123 | ||
124 | if (write && ret == 0) { | 124 | if (write && ret == 0) { |
125 | if (range[1] <= range[0]) | 125 | if (range[1] < range[0]) |
126 | ret = -EINVAL; | 126 | ret = -EINVAL; |
127 | else | 127 | else |
128 | set_local_port_range(range); | 128 | set_local_port_range(range); |
@@ -150,7 +150,7 @@ static int ipv4_sysctl_local_port_range(ctl_table *table, int __user *name, | |||
150 | 150 | ||
151 | ret = sysctl_intvec(&tmp, name, nlen, oldval, oldlenp, newval, newlen); | 151 | ret = sysctl_intvec(&tmp, name, nlen, oldval, oldlenp, newval, newlen); |
152 | if (ret == 0 && newval && newlen) { | 152 | if (ret == 0 && newval && newlen) { |
153 | if (range[1] <= range[0]) | 153 | if (range[1] < range[0]) |
154 | ret = -EINVAL; | 154 | ret = -EINVAL; |
155 | else | 155 | else |
156 | set_local_port_range(range); | 156 | set_local_port_range(range); |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index cb9fc58efb..35d2b0e9e1 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -147,13 +147,14 @@ int __udp_lib_get_port(struct sock *sk, unsigned short snum, | |||
147 | write_lock_bh(&udp_hash_lock); | 147 | write_lock_bh(&udp_hash_lock); |
148 | 148 | ||
149 | if (!snum) { | 149 | if (!snum) { |
150 | int i, low, high; | 150 | int i, low, high, remaining; |
151 | unsigned rover, best, best_size_so_far; | 151 | unsigned rover, best, best_size_so_far; |
152 | 152 | ||
153 | inet_get_local_port_range(&low, &high); | 153 | inet_get_local_port_range(&low, &high); |
154 | remaining = (high - low) + 1; | ||
154 | 155 | ||
155 | best_size_so_far = UINT_MAX; | 156 | best_size_so_far = UINT_MAX; |
156 | best = rover = net_random() % (high - low) + low; | 157 | best = rover = net_random() % remaining + low; |
157 | 158 | ||
158 | /* 1st pass: look for empty (or shortest) hash chain */ | 159 | /* 1st pass: look for empty (or shortest) hash chain */ |
159 | for (i = 0; i < UDP_HTABLE_SIZE; i++) { | 160 | for (i = 0; i < UDP_HTABLE_SIZE; i++) { |
diff --git a/net/ipv6/inet6_hashtables.c b/net/ipv6/inet6_hashtables.c index 1c2c276554..d6f1026f19 100644 --- a/net/ipv6/inet6_hashtables.c +++ b/net/ipv6/inet6_hashtables.c | |||
@@ -261,7 +261,7 @@ int inet6_hash_connect(struct inet_timewait_death_row *death_row, | |||
261 | struct inet_timewait_sock *tw = NULL; | 261 | struct inet_timewait_sock *tw = NULL; |
262 | 262 | ||
263 | inet_get_local_port_range(&low, &high); | 263 | inet_get_local_port_range(&low, &high); |
264 | remaining = high - low; | 264 | remaining = (high - low) + 1; |
265 | 265 | ||
266 | local_bh_disable(); | 266 | local_bh_disable(); |
267 | for (i = 1; i <= remaining; i++) { | 267 | for (i = 1; i <= remaining; i++) { |