1 /* 2 * sysctl_net_ipv6.c: sysctl interface to net IPV6 subsystem. 3 * 4 * Changes: 5 * YOSHIFUJI Hideaki @USAGI: added icmp sysctl table. 6 */ 7 8 #include <linux/mm.h> 9 #include <linux/sysctl.h> 10 #include <linux/in6.h> 11 #include <linux/ipv6.h> 12 #include <linux/slab.h> 13 #include <linux/export.h> 14 #include <net/ndisc.h> 15 #include <net/ipv6.h> 16 #include <net/addrconf.h> 17 #include <net/inet_frag.h> 18 19 static int one = 1; 20 21 static struct ctl_table ipv6_table_template[] = { 22 { 23 .procname = "bindv6only", 24 .data = &init_net.ipv6.sysctl.bindv6only, 25 .maxlen = sizeof(int), 26 .mode = 0644, 27 .proc_handler = proc_dointvec 28 }, 29 { 30 .procname = "anycast_src_echo_reply", 31 .data = &init_net.ipv6.sysctl.anycast_src_echo_reply, 32 .maxlen = sizeof(int), 33 .mode = 0644, 34 .proc_handler = proc_dointvec 35 }, 36 { 37 .procname = "flowlabel_consistency", 38 .data = &init_net.ipv6.sysctl.flowlabel_consistency, 39 .maxlen = sizeof(int), 40 .mode = 0644, 41 .proc_handler = proc_dointvec 42 }, 43 { 44 .procname = "auto_flowlabels", 45 .data = &init_net.ipv6.sysctl.auto_flowlabels, 46 .maxlen = sizeof(int), 47 .mode = 0644, 48 .proc_handler = proc_dointvec 49 }, 50 { 51 .procname = "fwmark_reflect", 52 .data = &init_net.ipv6.sysctl.fwmark_reflect, 53 .maxlen = sizeof(int), 54 .mode = 0644, 55 .proc_handler = proc_dointvec 56 }, 57 { 58 .procname = "idgen_retries", 59 .data = &init_net.ipv6.sysctl.idgen_retries, 60 .maxlen = sizeof(int), 61 .mode = 0644, 62 .proc_handler = proc_dointvec, 63 }, 64 { 65 .procname = "idgen_delay", 66 .data = &init_net.ipv6.sysctl.idgen_delay, 67 .maxlen = sizeof(int), 68 .mode = 0644, 69 .proc_handler = proc_dointvec_jiffies, 70 }, 71 { 72 .procname = "flowlabel_state_ranges", 73 .data = &init_net.ipv6.sysctl.flowlabel_state_ranges, 74 .maxlen = sizeof(int), 75 .mode = 0644, 76 .proc_handler = proc_dointvec 77 }, 78 { } 79 }; 80 81 static struct ctl_table ipv6_rotable[] = { 82 { 83 .procname = "mld_max_msf", 84 .data = &sysctl_mld_max_msf, 85 .maxlen = sizeof(int), 86 .mode = 0644, 87 .proc_handler = proc_dointvec 88 }, 89 { 90 .procname = "mld_qrv", 91 .data = &sysctl_mld_qrv, 92 .maxlen = sizeof(int), 93 .mode = 0644, 94 .proc_handler = proc_dointvec_minmax, 95 .extra1 = &one 96 }, 97 { } 98 }; 99 100 static int __net_init ipv6_sysctl_net_init(struct net *net) 101 { 102 struct ctl_table *ipv6_table; 103 struct ctl_table *ipv6_route_table; 104 struct ctl_table *ipv6_icmp_table; 105 int err; 106 107 err = -ENOMEM; 108 ipv6_table = kmemdup(ipv6_table_template, sizeof(ipv6_table_template), 109 GFP_KERNEL); 110 if (!ipv6_table) 111 goto out; 112 ipv6_table[0].data = &net->ipv6.sysctl.bindv6only; 113 ipv6_table[1].data = &net->ipv6.sysctl.anycast_src_echo_reply; 114 ipv6_table[2].data = &net->ipv6.sysctl.flowlabel_consistency; 115 ipv6_table[3].data = &net->ipv6.sysctl.auto_flowlabels; 116 ipv6_table[4].data = &net->ipv6.sysctl.fwmark_reflect; 117 ipv6_table[5].data = &net->ipv6.sysctl.idgen_retries; 118 ipv6_table[6].data = &net->ipv6.sysctl.idgen_delay; 119 ipv6_table[7].data = &net->ipv6.sysctl.flowlabel_state_ranges; 120 121 ipv6_route_table = ipv6_route_sysctl_init(net); 122 if (!ipv6_route_table) 123 goto out_ipv6_table; 124 125 ipv6_icmp_table = ipv6_icmp_sysctl_init(net); 126 if (!ipv6_icmp_table) 127 goto out_ipv6_route_table; 128 129 net->ipv6.sysctl.hdr = register_net_sysctl(net, "net/ipv6", ipv6_table); 130 if (!net->ipv6.sysctl.hdr) 131 goto out_ipv6_icmp_table; 132 133 net->ipv6.sysctl.route_hdr = 134 register_net_sysctl(net, "net/ipv6/route", ipv6_route_table); 135 if (!net->ipv6.sysctl.route_hdr) 136 goto out_unregister_ipv6_table; 137 138 net->ipv6.sysctl.icmp_hdr = 139 register_net_sysctl(net, "net/ipv6/icmp", ipv6_icmp_table); 140 if (!net->ipv6.sysctl.icmp_hdr) 141 goto out_unregister_route_table; 142 143 err = 0; 144 out: 145 return err; 146 out_unregister_route_table: 147 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); 148 out_unregister_ipv6_table: 149 unregister_net_sysctl_table(net->ipv6.sysctl.hdr); 150 out_ipv6_icmp_table: 151 kfree(ipv6_icmp_table); 152 out_ipv6_route_table: 153 kfree(ipv6_route_table); 154 out_ipv6_table: 155 kfree(ipv6_table); 156 goto out; 157 } 158 159 static void __net_exit ipv6_sysctl_net_exit(struct net *net) 160 { 161 struct ctl_table *ipv6_table; 162 struct ctl_table *ipv6_route_table; 163 struct ctl_table *ipv6_icmp_table; 164 165 ipv6_table = net->ipv6.sysctl.hdr->ctl_table_arg; 166 ipv6_route_table = net->ipv6.sysctl.route_hdr->ctl_table_arg; 167 ipv6_icmp_table = net->ipv6.sysctl.icmp_hdr->ctl_table_arg; 168 169 unregister_net_sysctl_table(net->ipv6.sysctl.icmp_hdr); 170 unregister_net_sysctl_table(net->ipv6.sysctl.route_hdr); 171 unregister_net_sysctl_table(net->ipv6.sysctl.hdr); 172 173 kfree(ipv6_table); 174 kfree(ipv6_route_table); 175 kfree(ipv6_icmp_table); 176 } 177 178 static struct pernet_operations ipv6_sysctl_net_ops = { 179 .init = ipv6_sysctl_net_init, 180 .exit = ipv6_sysctl_net_exit, 181 }; 182 183 static struct ctl_table_header *ip6_header; 184 185 int ipv6_sysctl_register(void) 186 { 187 int err = -ENOMEM; 188 189 ip6_header = register_net_sysctl(&init_net, "net/ipv6", ipv6_rotable); 190 if (!ip6_header) 191 goto out; 192 193 err = register_pernet_subsys(&ipv6_sysctl_net_ops); 194 if (err) 195 goto err_pernet; 196 out: 197 return err; 198 199 err_pernet: 200 unregister_net_sysctl_table(ip6_header); 201 goto out; 202 } 203 204 void ipv6_sysctl_unregister(void) 205 { 206 unregister_net_sysctl_table(ip6_header); 207 unregister_pernet_subsys(&ipv6_sysctl_net_ops); 208 } 209