25 #include <linux/module.h>
26 #include <linux/capability.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
31 #include <linux/net.h>
32 #include <linux/in6.h>
33 #include <linux/mroute6.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_arp.h>
37 #include <linux/sysctl.h>
38 #include <linux/netfilter.h>
39 #include <linux/slab.h>
56 #include <asm/uaccess.h>
63 struct ip6_ra_chain *
ra, *new_ra, **rap;
72 for (rap = &ip6_ra_chain; (ra=*rap) !=
NULL; rap = &ra->
next) {
105 if (inet_sk(sk)->is_icsk) {
113 opt =
xchg(&inet6_sk(sk)->opt, opt);
116 opt =
xchg(&inet6_sk(sk)->opt, opt);
124 static int do_ipv6_setsockopt(
struct sock *sk,
int level,
int optname,
125 char __user *optval,
unsigned int optlen)
128 struct net *
net = sock_net(sk);
135 if (optlen >=
sizeof(
int)) {
136 if (
get_user(val, (
int __user *) optval))
144 if (ip6_mroute_opt(optname))
152 if (optlen <
sizeof(
int))
177 !ipv6_addr_v4mapped(&np->
daddr)) {
195 sock_prot_inuse_add(net, sk->sk_prot, -1);
196 sock_prot_inuse_add(net, &
tcp_prot, 1);
209 sock_prot_inuse_add(net, sk->sk_prot, -1);
210 sock_prot_inuse_add(net, prot, 1);
235 if (optlen <
sizeof(
int) ||
236 inet_sk(sk)->inet_num)
243 if (optlen <
sizeof(
int))
250 if (optlen <
sizeof(
int))
257 if (optlen <
sizeof(
int))
264 if (optlen <
sizeof(
int))
271 if (optlen <
sizeof(
int))
278 if (optlen <
sizeof(
int))
285 if (optlen <
sizeof(
int))
292 if (optlen <
sizeof(
int))
299 if (optlen <
sizeof(
int))
306 if (optlen <
sizeof(
int))
313 if (optlen <
sizeof(
int))
315 if (val < -1 || val > 0xff)
325 if (optlen <
sizeof(
int))
332 if (optlen <
sizeof(
int))
339 if (optlen <
sizeof(
int))
350 if (optlen <
sizeof(
int))
353 inet_sk(sk)->transparent = valbool;
358 if (optlen <
sizeof(
int))
376 else if (optval ==
NULL)
379 optlen & 0x7 || optlen > 8 * 255)
399 switch (rthdr->
type) {
400 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
414 opt = ipv6_update_options(sk, opt);
434 if (sk->sk_bound_dev_if && pkt.ipi6_ifindex != sk->sk_bound_dev_if)
450 memset(&fl6, 0,
sizeof(fl6));
451 fl6.flowi6_oif = sk->sk_bound_dev_if;
461 if (optlen > 64*1024)
469 memset(opt, 0,
sizeof(*opt));
470 opt->
tot_len =
sizeof(*opt) + optlen;
475 msg.msg_controllen = optlen;
476 msg.msg_control = (
void*)(opt+1);
484 opt = ipv6_update_options(sk, opt);
491 if (optlen <
sizeof(
int))
493 if (val > 255 || val < -1)
502 if (optlen <
sizeof(
int))
504 if (val > 255 || val < -1)
511 if (optlen <
sizeof(
int))
524 if (optlen !=
sizeof(
int))
541 if (sk->sk_bound_dev_if)
552 if (optlen <
sizeof(
int))
558 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
580 if (inet_sk(sk)->is_icsk)
623 if (greq.gr_group.ss_family !=
AF_INET6) {
650 if (greqs.gsr_group.ss_family !=
AF_INET6 ||
651 greqs.gsr_source.ss_family !=
AF_INET6) {
685 if (optlen > sysctl_optmem_max) {
717 if (optlen <
sizeof(
int))
722 if (optlen <
sizeof(
int))
730 if (optlen <
sizeof(
int))
738 if (optlen <
sizeof(
int))
746 if (optlen <
sizeof(
int))
764 unsigned int pref = 0;
765 unsigned int prefmask = ~0;
767 if (optlen <
sizeof(
int))
785 goto pref_skip_pubtmp;
825 if (optlen <
sizeof(
int))
827 if (val < 0 || val > 255)
848 char __user *optval,
unsigned int optlen)
853 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
858 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
859 #ifdef CONFIG_NETFILTER
876 char __user *optval,
unsigned int optlen)
882 return udp_prot.compat_setsockopt(sk, level, optname,
884 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
894 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
895 #ifdef CONFIG_NETFILTER
900 err = compat_nf_setsockopt(sk,
PF_INET6, optname,
912 int optname,
char __user *optval,
int len)
945 static int do_ipv6_getsockopt(
struct sock *sk,
int level,
int optname,
946 char __user *optval,
int __user *optlen,
unsigned int flags)
952 if (ip6_mroute_opt(optname))
993 msg.msg_control = optval;
1036 len -=
msg.msg_controllen;
1045 dst = __sk_dst_get(sk);
1089 len = ipv6_getsockopt_sticky(sk, np->
opt,
1090 optname, optval, len);
1135 if (len <
sizeof(mtuinfo))
1138 len =
sizeof(mtuinfo);
1139 memset(&mtuinfo, 0,
sizeof(mtuinfo));
1142 dst = __sk_dst_get(sk);
1144 mtuinfo.ip6m_mtu = dst_mtu(dst);
1146 if (!mtuinfo.ip6m_mtu)
1159 val = inet_sk(sk)->transparent;
1178 dst = __sk_dst_get(sk);
1185 val = sock_net(sk)->ipv6.devconf_all->hop_limit;
1242 len =
min_t(
unsigned int,
sizeof(
int), len);
1251 char __user *optval,
int __user *optlen)
1256 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1261 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen, 0);
1262 #ifdef CONFIG_NETFILTER
1283 #ifdef CONFIG_COMPAT
1285 char __user *optval,
int __user *optlen)
1291 return udp_prot.compat_getsockopt(sk, level, optname,
1293 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1303 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen,
1305 #ifdef CONFIG_NETFILTER
1314 err = compat_nf_getsockopt(sk,
PF_INET6,
1315 optname, optval, &len);