ipv4: Namespacify ip_dynaddr sysctl knob
authorNikolay Borisov <kernel@kyup.com>
Mon, 15 Feb 2016 10:11:29 +0000 (12:11 +0200)
committerDavid S. Miller <davem@davemloft.net>
Wed, 17 Feb 2016 01:42:54 +0000 (20:42 -0500)
Signed-off-by: Nikolay Borisov <kernel@kyup.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/ip.h
include/net/netns/ipv4.h
net/ipv4/af_inet.c
net/ipv4/sysctl_net_ipv4.c

index 1a98f1ca16383d2b9cd0867091e323ab7c81f045..e3fb25d764218ee5c8e95418b7426c91424f0da5 100644 (file)
@@ -248,9 +248,6 @@ extern int inet_peer_maxttl;
 /* From ip_input.c */
 extern int sysctl_ip_early_demux;
 
-/* From ip_output.c */
-extern int sysctl_ip_dynaddr;
-
 void ipfrag_init(void);
 
 void ip_static_sysctl_init(void);
index bc8f7f94abcb02419d1c906cef838fa3ba3b2449..b7e3fb2587da64c77fbd8caa3ec7755a1b968747 100644 (file)
@@ -84,6 +84,8 @@ struct netns_ipv4 {
        int sysctl_ip_no_pmtu_disc;
        int sysctl_ip_fwd_use_pmtu;
        int sysctl_ip_nonlocal_bind;
+       /* Shall we try to damage output packets if routing dev changes? */
+       int sysctl_ip_dynaddr;
 
        int sysctl_fwmark_reflect;
        int sysctl_tcp_fwmark_accept;
index eade66db214e99b42a732c5c8aa8c3744984a06c..209d1ed2895444bfd90d2eb12f6942d984be40d5 100644 (file)
@@ -1095,12 +1095,6 @@ void inet_unregister_protosw(struct inet_protosw *p)
 }
 EXPORT_SYMBOL(inet_unregister_protosw);
 
-/*
- *      Shall we try to damage output packets if routing dev changes?
- */
-
-int sysctl_ip_dynaddr __read_mostly;
-
 static int inet_sk_reselect_saddr(struct sock *sk)
 {
        struct inet_sock *inet = inet_sk(sk);
@@ -1131,7 +1125,7 @@ static int inet_sk_reselect_saddr(struct sock *sk)
        if (new_saddr == old_saddr)
                return 0;
 
-       if (sysctl_ip_dynaddr > 1) {
+       if (sock_net(sk)->ipv4.sysctl_ip_dynaddr > 1) {
                pr_info("%s(): shifting inet->saddr from %pI4 to %pI4\n",
                        __func__, &old_saddr, &new_saddr);
        }
@@ -1186,7 +1180,7 @@ int inet_sk_rebuild_header(struct sock *sk)
                 * Other protocols have to map its equivalent state to TCP_SYN_SENT.
                 * DCCP maps its DCCP_REQUESTING state to TCP_SYN_SENT. -acme
                 */
-               if (!sysctl_ip_dynaddr ||
+               if (!sock_net(sk)->ipv4.sysctl_ip_dynaddr ||
                    sk->sk_state != TCP_SYN_SENT ||
                    (sk->sk_userlocks & SOCK_BINDADDR_LOCK) ||
                    (err = inet_sk_reselect_saddr(sk)) != 0)
index a833a9f9e4cd35cea2d5215504dfa159cd10034b..04ac5b763385144b392ba30e868ce1e04b9e7867 100644 (file)
@@ -303,13 +303,6 @@ static struct ctl_table ipv4_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec
        },
-       {
-               .procname       = "ip_dynaddr",
-               .data           = &sysctl_ip_dynaddr,
-               .maxlen         = sizeof(int),
-               .mode           = 0644,
-               .proc_handler   = proc_dointvec
-       },
        {
                .procname       = "tcp_fastopen",
                .data           = &sysctl_tcp_fastopen,
@@ -743,6 +736,13 @@ static struct ctl_table ipv4_net_table[] = {
                .mode           = 0644,
                .proc_handler   = proc_dointvec
        },
+       {
+               .procname       = "ip_dynaddr",
+               .data           = &init_net.ipv4.sysctl_ip_dynaddr,
+               .maxlen         = sizeof(int),
+               .mode           = 0644,
+               .proc_handler   = proc_dointvec
+       },
        {
                .procname       = "ip_default_ttl",
                .data           = &init_net.ipv4.sysctl_ip_default_ttl,
@@ -989,6 +989,7 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
                goto err_ports;
 
        net->ipv4.sysctl_ip_default_ttl = IPDEFTTL;
+       net->ipv4.sysctl_ip_dynaddr = 0;
 
        return 0;