diff options
author | WANG Cong <xiyou.wangcong@gmail.com> | 2014-05-12 19:04:53 -0400 |
---|---|---|
committer | David S. Miller <davem@davemloft.net> | 2014-05-14 15:31:45 -0400 |
commit | 122ff243f5f104194750ecbc76d5946dd1eec934 (patch) | |
tree | 189020a4d2404ef567785458fee38992e14ca97d /net | |
parent | 9cc5e36d1c4794939deafd9f43bce2eab9c1142d (diff) |
ipv4: make ip_local_reserved_ports per netns
ip_local_port_range is already per netns, so should ip_local_reserved_ports
be. And since it is none by default we don't actually need it when we don't
enable CONFIG_SYSCTL.
By the way, rename inet_is_reserved_local_port() to inet_is_local_reserved_port()
Cc: "David S. Miller" <davem@davemloft.net>
Signed-off-by: Cong Wang <xiyou.wangcong@gmail.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
Diffstat (limited to 'net')
-rw-r--r-- | net/ipv4/af_inet.c | 8 | ||||
-rw-r--r-- | net/ipv4/inet_connection_sock.c | 5 | ||||
-rw-r--r-- | net/ipv4/inet_hashtables.c | 2 | ||||
-rw-r--r-- | net/ipv4/sysctl_net_ipv4.c | 31 | ||||
-rw-r--r-- | net/ipv4/udp.c | 2 | ||||
-rw-r--r-- | net/sctp/socket.c | 5 |
6 files changed, 21 insertions, 32 deletions
diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c index 211c0cc6c3d3..279132bcadd9 100644 --- a/net/ipv4/af_inet.c +++ b/net/ipv4/af_inet.c | |||
@@ -1705,13 +1705,9 @@ static int __init inet_init(void) | |||
1705 | 1705 | ||
1706 | BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); | 1706 | BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb)); |
1707 | 1707 | ||
1708 | sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL); | ||
1709 | if (!sysctl_local_reserved_ports) | ||
1710 | goto out; | ||
1711 | |||
1712 | rc = proto_register(&tcp_prot, 1); | 1708 | rc = proto_register(&tcp_prot, 1); |
1713 | if (rc) | 1709 | if (rc) |
1714 | goto out_free_reserved_ports; | 1710 | goto out; |
1715 | 1711 | ||
1716 | rc = proto_register(&udp_prot, 1); | 1712 | rc = proto_register(&udp_prot, 1); |
1717 | if (rc) | 1713 | if (rc) |
@@ -1821,8 +1817,6 @@ out_unregister_udp_proto: | |||
1821 | proto_unregister(&udp_prot); | 1817 | proto_unregister(&udp_prot); |
1822 | out_unregister_tcp_proto: | 1818 | out_unregister_tcp_proto: |
1823 | proto_unregister(&tcp_prot); | 1819 | proto_unregister(&tcp_prot); |
1824 | out_free_reserved_ports: | ||
1825 | kfree(sysctl_local_reserved_ports); | ||
1826 | goto out; | 1820 | goto out; |
1827 | } | 1821 | } |
1828 | 1822 | ||
diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c index 12e502cbfdc7..14d02ea905b6 100644 --- a/net/ipv4/inet_connection_sock.c +++ b/net/ipv4/inet_connection_sock.c | |||
@@ -29,9 +29,6 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n"; | |||
29 | EXPORT_SYMBOL(inet_csk_timer_bug_msg); | 29 | EXPORT_SYMBOL(inet_csk_timer_bug_msg); |
30 | #endif | 30 | #endif |
31 | 31 | ||
32 | unsigned long *sysctl_local_reserved_ports; | ||
33 | EXPORT_SYMBOL(sysctl_local_reserved_ports); | ||
34 | |||
35 | void inet_get_local_port_range(struct net *net, int *low, int *high) | 32 | void inet_get_local_port_range(struct net *net, int *low, int *high) |
36 | { | 33 | { |
37 | unsigned int seq; | 34 | unsigned int seq; |
@@ -113,7 +110,7 @@ again: | |||
113 | 110 | ||
114 | smallest_size = -1; | 111 | smallest_size = -1; |
115 | do { | 112 | do { |
116 | if (inet_is_reserved_local_port(rover)) | 113 | if (inet_is_local_reserved_port(net, rover)) |
117 | goto next_nolock; | 114 | goto next_nolock; |
118 | head = &hashinfo->bhash[inet_bhashfn(net, rover, | 115 | head = &hashinfo->bhash[inet_bhashfn(net, rover, |
119 | hashinfo->bhash_size)]; | 116 | hashinfo->bhash_size)]; |
diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c index 8b9cf279450d..83331f1b86ac 100644 --- a/net/ipv4/inet_hashtables.c +++ b/net/ipv4/inet_hashtables.c | |||
@@ -500,7 +500,7 @@ int __inet_hash_connect(struct inet_timewait_death_row *death_row, | |||
500 | local_bh_disable(); | 500 | local_bh_disable(); |
501 | for (i = 1; i <= remaining; i++) { | 501 | for (i = 1; i <= remaining; i++) { |
502 | port = low + (i + offset) % remaining; | 502 | port = low + (i + offset) % remaining; |
503 | if (inet_is_reserved_local_port(port)) | 503 | if (inet_is_local_reserved_port(net, port)) |
504 | continue; | 504 | continue; |
505 | head = &hinfo->bhash[inet_bhashfn(net, port, | 505 | head = &hinfo->bhash[inet_bhashfn(net, port, |
506 | hinfo->bhash_size)]; | 506 | hinfo->bhash_size)]; |
diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c index a33b9fbc1d80..79a007c52558 100644 --- a/net/ipv4/sysctl_net_ipv4.c +++ b/net/ipv4/sysctl_net_ipv4.c | |||
@@ -437,13 +437,6 @@ static struct ctl_table ipv4_table[] = { | |||
437 | .proc_handler = proc_dointvec | 437 | .proc_handler = proc_dointvec |
438 | }, | 438 | }, |
439 | { | 439 | { |
440 | .procname = "ip_local_reserved_ports", | ||
441 | .data = NULL, /* initialized in sysctl_ipv4_init */ | ||
442 | .maxlen = 65536, | ||
443 | .mode = 0644, | ||
444 | .proc_handler = proc_do_large_bitmap, | ||
445 | }, | ||
446 | { | ||
447 | .procname = "igmp_max_memberships", | 440 | .procname = "igmp_max_memberships", |
448 | .data = &sysctl_igmp_max_memberships, | 441 | .data = &sysctl_igmp_max_memberships, |
449 | .maxlen = sizeof(int), | 442 | .maxlen = sizeof(int), |
@@ -825,6 +818,13 @@ static struct ctl_table ipv4_net_table[] = { | |||
825 | .proc_handler = ipv4_local_port_range, | 818 | .proc_handler = ipv4_local_port_range, |
826 | }, | 819 | }, |
827 | { | 820 | { |
821 | .procname = "ip_local_reserved_ports", | ||
822 | .data = &init_net.ipv4.sysctl_local_reserved_ports, | ||
823 | .maxlen = 65536, | ||
824 | .mode = 0644, | ||
825 | .proc_handler = proc_do_large_bitmap, | ||
826 | }, | ||
827 | { | ||
828 | .procname = "ip_no_pmtu_disc", | 828 | .procname = "ip_no_pmtu_disc", |
829 | .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc, | 829 | .data = &init_net.ipv4.sysctl_ip_no_pmtu_disc, |
830 | .maxlen = sizeof(int), | 830 | .maxlen = sizeof(int), |
@@ -876,8 +876,14 @@ static __net_init int ipv4_sysctl_init_net(struct net *net) | |||
876 | if (net->ipv4.ipv4_hdr == NULL) | 876 | if (net->ipv4.ipv4_hdr == NULL) |
877 | goto err_reg; | 877 | goto err_reg; |
878 | 878 | ||
879 | net->ipv4.sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL); | ||
880 | if (!net->ipv4.sysctl_local_reserved_ports) | ||
881 | goto err_ports; | ||
882 | |||
879 | return 0; | 883 | return 0; |
880 | 884 | ||
885 | err_ports: | ||
886 | unregister_net_sysctl_table(net->ipv4.ipv4_hdr); | ||
881 | err_reg: | 887 | err_reg: |
882 | if (!net_eq(net, &init_net)) | 888 | if (!net_eq(net, &init_net)) |
883 | kfree(table); | 889 | kfree(table); |
@@ -889,6 +895,7 @@ static __net_exit void ipv4_sysctl_exit_net(struct net *net) | |||
889 | { | 895 | { |
890 | struct ctl_table *table; | 896 | struct ctl_table *table; |
891 | 897 | ||
898 | kfree(net->ipv4.sysctl_local_reserved_ports); | ||
892 | table = net->ipv4.ipv4_hdr->ctl_table_arg; | 899 | table = net->ipv4.ipv4_hdr->ctl_table_arg; |
893 | unregister_net_sysctl_table(net->ipv4.ipv4_hdr); | 900 | unregister_net_sysctl_table(net->ipv4.ipv4_hdr); |
894 | kfree(table); | 901 | kfree(table); |
@@ -902,16 +909,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = { | |||
902 | static __init int sysctl_ipv4_init(void) | 909 | static __init int sysctl_ipv4_init(void) |
903 | { | 910 | { |
904 | struct ctl_table_header *hdr; | 911 | struct ctl_table_header *hdr; |
905 | struct ctl_table *i; | ||
906 | |||
907 | for (i = ipv4_table; i->procname; i++) { | ||
908 | if (strcmp(i->procname, "ip_local_reserved_ports") == 0) { | ||
909 | i->data = sysctl_local_reserved_ports; | ||
910 | break; | ||
911 | } | ||
912 | } | ||
913 | if (!i->procname) | ||
914 | return -EINVAL; | ||
915 | 912 | ||
916 | hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table); | 913 | hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table); |
917 | if (hdr == NULL) | 914 | if (hdr == NULL) |
diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c index 54ea0a3a48f1..6729ea97a59d 100644 --- a/net/ipv4/udp.c +++ b/net/ipv4/udp.c | |||
@@ -246,7 +246,7 @@ int udp_lib_get_port(struct sock *sk, unsigned short snum, | |||
246 | do { | 246 | do { |
247 | if (low <= snum && snum <= high && | 247 | if (low <= snum && snum <= high && |
248 | !test_bit(snum >> udptable->log, bitmap) && | 248 | !test_bit(snum >> udptable->log, bitmap) && |
249 | !inet_is_reserved_local_port(snum)) | 249 | !inet_is_local_reserved_port(net, snum)) |
250 | goto found; | 250 | goto found; |
251 | snum += rand; | 251 | snum += rand; |
252 | } while (snum != first); | 252 | } while (snum != first); |
diff --git a/net/sctp/socket.c b/net/sctp/socket.c index e37b2cbbf177..2af76eaba8f7 100644 --- a/net/sctp/socket.c +++ b/net/sctp/socket.c | |||
@@ -5946,8 +5946,9 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5946 | /* Search for an available port. */ | 5946 | /* Search for an available port. */ |
5947 | int low, high, remaining, index; | 5947 | int low, high, remaining, index; |
5948 | unsigned int rover; | 5948 | unsigned int rover; |
5949 | struct net *net = sock_net(sk); | ||
5949 | 5950 | ||
5950 | inet_get_local_port_range(sock_net(sk), &low, &high); | 5951 | inet_get_local_port_range(net, &low, &high); |
5951 | remaining = (high - low) + 1; | 5952 | remaining = (high - low) + 1; |
5952 | rover = prandom_u32() % remaining + low; | 5953 | rover = prandom_u32() % remaining + low; |
5953 | 5954 | ||
@@ -5955,7 +5956,7 @@ static long sctp_get_port_local(struct sock *sk, union sctp_addr *addr) | |||
5955 | rover++; | 5956 | rover++; |
5956 | if ((rover < low) || (rover > high)) | 5957 | if ((rover < low) || (rover > high)) |
5957 | rover = low; | 5958 | rover = low; |
5958 | if (inet_is_reserved_local_port(rover)) | 5959 | if (inet_is_local_reserved_port(net, rover)) |
5959 | continue; | 5960 | continue; |
5960 | index = sctp_phashfn(sock_net(sk), rover); | 5961 | index = sctp_phashfn(sock_net(sk), rover); |
5961 | head = &sctp_port_hashtable[index]; | 5962 | head = &sctp_port_hashtable[index]; |