2 * IPv6 BSD socket options interface
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on linux/net/ipv4/ip_sockglue.c
10 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * FIXME: Make the setsockopt code POSIX compliant: That is
17 * o Truncate getsockopt returns
18 * o Return an optlen of the truncated length if need be
21 * David L Stevens <dlstevens@us.ibm.com>:
22 * - added multicast source filtering API for MLDv2
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>
30 #include <linux/sockios.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>
36 #include <linux/init.h>
37 #include <linux/sysctl.h>
38 #include <linux/netfilter.h>
43 #include <net/ndisc.h>
44 #include <net/protocol.h>
45 #include <net/transp_v6.h>
46 #include <net/ip6_route.h>
47 #include <net/addrconf.h>
48 #include <net/inet_common.h>
51 #include <net/udplite.h>
53 #include <net/compat.h>
55 #include <asm/uaccess.h>
57 DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly;
59 struct ip6_ra_chain *ip6_ra_chain;
60 DEFINE_RWLOCK(ip6_ra_lock);
62 int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
64 struct ip6_ra_chain *ra, *new_ra, **rap;
66 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
67 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num != IPPROTO_RAW)
70 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
72 write_lock_bh(&ip6_ra_lock);
73 for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
76 write_unlock_bh(&ip6_ra_lock);
82 write_unlock_bh(&ip6_ra_lock);
92 write_unlock_bh(&ip6_ra_lock);
97 new_ra->destructor = destructor;
101 write_unlock_bh(&ip6_ra_lock);
106 struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
107 struct ipv6_txoptions *opt)
109 if (inet_sk(sk)->is_icsk) {
111 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
112 inet_sk(sk)->daddr != LOOPBACK4_IPV6) {
113 struct inet_connection_sock *icsk = inet_csk(sk);
114 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
115 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
117 opt = xchg(&inet6_sk(sk)->opt, opt);
119 write_lock(&sk->sk_dst_lock);
120 opt = xchg(&inet6_sk(sk)->opt, opt);
121 write_unlock(&sk->sk_dst_lock);
128 static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
129 char __user *optval, int optlen)
131 struct ipv6_pinfo *np = inet6_sk(sk);
132 struct net *net = sock_net(sk);
134 int retv = -ENOPROTOOPT;
139 if (optlen >= sizeof(int)) {
140 if (get_user(val, (int __user *) optval))
148 if (ip6_mroute_opt(optname))
149 return ip6_mroute_setsockopt(sk, optname, optval, optlen);
156 if (optlen < sizeof(int))
158 if (val == PF_INET) {
159 struct ipv6_txoptions *opt;
160 struct sk_buff *pktopt;
162 if (sk->sk_type == SOCK_RAW)
165 if (sk->sk_protocol == IPPROTO_UDP ||
166 sk->sk_protocol == IPPROTO_UDPLITE) {
167 struct udp_sock *up = udp_sk(sk);
168 if (up->pending == AF_INET6) {
172 } else if (sk->sk_protocol != IPPROTO_TCP)
175 if (sk->sk_state != TCP_ESTABLISHED) {
180 if (ipv6_only_sock(sk) ||
181 !ipv6_addr_v4mapped(&np->daddr)) {
182 retv = -EADDRNOTAVAIL;
186 fl6_free_socklist(sk);
187 ipv6_sock_mc_close(sk);
190 * Sock is moving from IPv6 to IPv4 (sk_prot), so
191 * remove it from the refcnt debug socks count in the
194 sk_refcnt_debug_dec(sk);
196 if (sk->sk_protocol == IPPROTO_TCP) {
197 struct inet_connection_sock *icsk = inet_csk(sk);
199 sock_prot_inuse_add(net, sk->sk_prot, -1);
200 sock_prot_inuse_add(net, &tcp_prot, 1);
202 sk->sk_prot = &tcp_prot;
203 icsk->icsk_af_ops = &ipv4_specific;
204 sk->sk_socket->ops = &inet_stream_ops;
205 sk->sk_family = PF_INET;
206 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
208 struct proto *prot = &udp_prot;
210 if (sk->sk_protocol == IPPROTO_UDPLITE)
211 prot = &udplite_prot;
213 sock_prot_inuse_add(net, sk->sk_prot, -1);
214 sock_prot_inuse_add(net, prot, 1);
217 sk->sk_socket->ops = &inet_dgram_ops;
218 sk->sk_family = PF_INET;
220 opt = xchg(&np->opt, NULL);
222 sock_kfree_s(sk, opt, opt->tot_len);
223 pktopt = xchg(&np->pktoptions, NULL);
227 sk->sk_destruct = inet_sock_destruct;
229 * ... and add it to the refcnt debug socks count
230 * in the new family. -acme
232 sk_refcnt_debug_inc(sk);
233 module_put(THIS_MODULE);
240 if (optlen < sizeof(int) ||
243 np->ipv6only = valbool;
247 case IPV6_RECVPKTINFO:
248 if (optlen < sizeof(int))
250 np->rxopt.bits.rxinfo = valbool;
254 case IPV6_2292PKTINFO:
255 if (optlen < sizeof(int))
257 np->rxopt.bits.rxoinfo = valbool;
261 case IPV6_RECVHOPLIMIT:
262 if (optlen < sizeof(int))
264 np->rxopt.bits.rxhlim = valbool;
268 case IPV6_2292HOPLIMIT:
269 if (optlen < sizeof(int))
271 np->rxopt.bits.rxohlim = valbool;
276 if (optlen < sizeof(int))
278 np->rxopt.bits.srcrt = valbool;
283 if (optlen < sizeof(int))
285 np->rxopt.bits.osrcrt = valbool;
289 case IPV6_RECVHOPOPTS:
290 if (optlen < sizeof(int))
292 np->rxopt.bits.hopopts = valbool;
296 case IPV6_2292HOPOPTS:
297 if (optlen < sizeof(int))
299 np->rxopt.bits.ohopopts = valbool;
303 case IPV6_RECVDSTOPTS:
304 if (optlen < sizeof(int))
306 np->rxopt.bits.dstopts = valbool;
310 case IPV6_2292DSTOPTS:
311 if (optlen < sizeof(int))
313 np->rxopt.bits.odstopts = valbool;
318 if (optlen < sizeof(int))
320 if (val < -1 || val > 0xff)
326 case IPV6_RECVTCLASS:
327 if (optlen < sizeof(int))
329 np->rxopt.bits.rxtclass = valbool;
334 if (optlen < sizeof(int))
336 np->rxopt.bits.rxflow = valbool;
341 case IPV6_RTHDRDSTOPTS:
345 struct ipv6_txoptions *opt;
349 /* hop-by-hop / destination options are privileged option */
351 if (optname != IPV6_RTHDR && !capable(CAP_NET_RAW))
354 if (optlen < sizeof(struct ipv6_opt_hdr) ||
355 optlen & 0x7 || optlen > 8 * 255)
358 opt = ipv6_renew_options(sk, np->opt, optname,
359 (struct ipv6_opt_hdr __user *)optval,
366 /* routing header option needs extra check */
367 if (optname == IPV6_RTHDR && opt && opt->srcrt) {
368 struct ipv6_rt_hdr *rthdr = opt->srcrt;
369 switch (rthdr->type) {
370 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
371 case IPV6_SRCRT_TYPE_2:
378 if ((rthdr->hdrlen & 1) ||
379 (rthdr->hdrlen >> 1) != rthdr->segments_left)
384 opt = ipv6_update_options(sk, opt);
387 sock_kfree_s(sk, opt, opt->tot_len);
391 case IPV6_2292PKTOPTIONS:
393 struct ipv6_txoptions *opt = NULL;
398 fl.fl6_flowlabel = 0;
399 fl.oif = sk->sk_bound_dev_if;
404 /* 1K is probably excessive
405 * 1K is surely not enough, 2K per standard header is 16K.
408 if (optlen > 64*1024)
411 opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL);
416 memset(opt, 0, sizeof(*opt));
417 opt->tot_len = sizeof(*opt) + optlen;
419 if (copy_from_user(opt+1, optval, optlen))
422 msg.msg_controllen = optlen;
423 msg.msg_control = (void*)(opt+1);
425 retv = datagram_send_ctl(net, &msg, &fl, opt, &junk, &junk);
430 opt = ipv6_update_options(sk, opt);
433 sock_kfree_s(sk, opt, opt->tot_len);
436 case IPV6_UNICAST_HOPS:
437 if (optlen < sizeof(int))
439 if (val > 255 || val < -1)
445 case IPV6_MULTICAST_HOPS:
446 if (sk->sk_type == SOCK_STREAM)
448 if (optlen < sizeof(int))
450 if (val > 255 || val < -1)
452 np->mcast_hops = val;
456 case IPV6_MULTICAST_LOOP:
457 if (optlen < sizeof(int))
459 np->mc_loop = valbool;
463 case IPV6_MULTICAST_IF:
464 if (sk->sk_type == SOCK_STREAM)
466 if (optlen < sizeof(int))
470 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
473 if (__dev_get_by_index(net, val) == NULL) {
481 case IPV6_ADD_MEMBERSHIP:
482 case IPV6_DROP_MEMBERSHIP:
484 struct ipv6_mreq mreq;
486 if (optlen < sizeof(struct ipv6_mreq))
490 if (inet_sk(sk)->is_icsk)
494 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
497 if (optname == IPV6_ADD_MEMBERSHIP)
498 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
500 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
503 case IPV6_JOIN_ANYCAST:
504 case IPV6_LEAVE_ANYCAST:
506 struct ipv6_mreq mreq;
508 if (optlen < sizeof(struct ipv6_mreq))
512 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
515 if (optname == IPV6_JOIN_ANYCAST)
516 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
518 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
521 case MCAST_JOIN_GROUP:
522 case MCAST_LEAVE_GROUP:
524 struct group_req greq;
525 struct sockaddr_in6 *psin6;
527 if (optlen < sizeof(struct group_req))
531 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
533 if (greq.gr_group.ss_family != AF_INET6) {
534 retv = -EADDRNOTAVAIL;
537 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
538 if (optname == MCAST_JOIN_GROUP)
539 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
542 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
546 case MCAST_JOIN_SOURCE_GROUP:
547 case MCAST_LEAVE_SOURCE_GROUP:
548 case MCAST_BLOCK_SOURCE:
549 case MCAST_UNBLOCK_SOURCE:
551 struct group_source_req greqs;
554 if (optlen < sizeof(struct group_source_req))
556 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
560 if (greqs.gsr_group.ss_family != AF_INET6 ||
561 greqs.gsr_source.ss_family != AF_INET6) {
562 retv = -EADDRNOTAVAIL;
565 if (optname == MCAST_BLOCK_SOURCE) {
566 omode = MCAST_EXCLUDE;
568 } else if (optname == MCAST_UNBLOCK_SOURCE) {
569 omode = MCAST_EXCLUDE;
571 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
572 struct sockaddr_in6 *psin6;
574 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
575 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
577 /* prior join w/ different source is ok */
578 if (retv && retv != -EADDRINUSE)
580 omode = MCAST_INCLUDE;
582 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
583 omode = MCAST_INCLUDE;
586 retv = ip6_mc_source(add, omode, sk, &greqs);
591 extern int sysctl_mld_max_msf;
592 struct group_filter *gsf;
594 if (optlen < GROUP_FILTER_SIZE(0))
596 if (optlen > sysctl_optmem_max) {
600 gsf = kmalloc(optlen,GFP_KERNEL);
606 if (copy_from_user(gsf, optval, optlen)) {
610 /* numsrc >= (4G-140)/128 overflow in 32 bits */
611 if (gsf->gf_numsrc >= 0x1ffffffU ||
612 gsf->gf_numsrc > sysctl_mld_max_msf) {
617 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
622 retv = ip6_mc_msfilter(sk, gsf);
627 case IPV6_ROUTER_ALERT:
628 if (optlen < sizeof(int))
630 retv = ip6_ra_control(sk, val, NULL);
632 case IPV6_MTU_DISCOVER:
633 if (optlen < sizeof(int))
641 if (optlen < sizeof(int))
643 if (val && val < IPV6_MIN_MTU)
649 if (optlen < sizeof(int))
651 np->recverr = valbool;
653 skb_queue_purge(&sk->sk_error_queue);
656 case IPV6_FLOWINFO_SEND:
657 if (optlen < sizeof(int))
659 np->sndflow = valbool;
662 case IPV6_FLOWLABEL_MGR:
663 retv = ipv6_flowlabel_opt(sk, optval, optlen);
665 case IPV6_IPSEC_POLICY:
666 case IPV6_XFRM_POLICY:
668 if (!capable(CAP_NET_ADMIN))
670 retv = xfrm_user_policy(sk, optname, optval, optlen);
673 case IPV6_ADDR_PREFERENCES:
675 unsigned int pref = 0;
676 unsigned int prefmask = ~0;
678 if (optlen < sizeof(int))
683 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
684 switch (val & (IPV6_PREFER_SRC_PUBLIC|
686 IPV6_PREFER_SRC_PUBTMP_DEFAULT)) {
687 case IPV6_PREFER_SRC_PUBLIC:
688 pref |= IPV6_PREFER_SRC_PUBLIC;
690 case IPV6_PREFER_SRC_TMP:
691 pref |= IPV6_PREFER_SRC_TMP;
693 case IPV6_PREFER_SRC_PUBTMP_DEFAULT:
696 goto pref_skip_pubtmp;
701 prefmask &= ~(IPV6_PREFER_SRC_PUBLIC|
702 IPV6_PREFER_SRC_TMP);
705 /* check HOME/COA conflicts */
706 switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) {
707 case IPV6_PREFER_SRC_HOME:
709 case IPV6_PREFER_SRC_COA:
710 pref |= IPV6_PREFER_SRC_COA;
717 prefmask &= ~IPV6_PREFER_SRC_COA;
720 /* check CGA/NONCGA conflicts */
721 switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) {
722 case IPV6_PREFER_SRC_CGA:
723 case IPV6_PREFER_SRC_NONCGA:
730 np->srcprefs = (np->srcprefs & prefmask) | pref;
746 int ipv6_setsockopt(struct sock *sk, int level, int optname,
747 char __user *optval, int optlen)
751 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
752 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
754 if (level != SOL_IPV6)
757 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
758 #ifdef CONFIG_NETFILTER
759 /* we need to exclude all possible ENOPROTOOPTs except default case */
760 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
761 optname != IPV6_XFRM_POLICY) {
763 err = nf_setsockopt(sk, PF_INET6, optname, optval,
771 EXPORT_SYMBOL(ipv6_setsockopt);
774 int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
775 char __user *optval, int optlen)
779 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
780 if (udp_prot.compat_setsockopt != NULL)
781 return udp_prot.compat_setsockopt(sk, level, optname,
783 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
786 if (level != SOL_IPV6)
789 if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
790 return compat_mc_setsockopt(sk, level, optname, optval, optlen,
793 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
794 #ifdef CONFIG_NETFILTER
795 /* we need to exclude all possible ENOPROTOOPTs except default case */
796 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
797 optname != IPV6_XFRM_POLICY) {
799 err = compat_nf_setsockopt(sk, PF_INET6, optname,
807 EXPORT_SYMBOL(compat_ipv6_setsockopt);
810 static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt,
811 int optname, char __user *optval, int len)
813 struct ipv6_opt_hdr *hdr;
822 case IPV6_RTHDRDSTOPTS:
826 hdr = (struct ipv6_opt_hdr *)opt->srcrt;
832 return -EINVAL; /* should not happen */
838 len = min_t(unsigned int, len, ipv6_optlen(hdr));
839 if (copy_to_user(optval, hdr, len))
844 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
845 char __user *optval, int __user *optlen)
847 struct ipv6_pinfo *np = inet6_sk(sk);
851 if (ip6_mroute_opt(optname))
852 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
854 if (get_user(len, optlen))
858 if (sk->sk_protocol != IPPROTO_UDP &&
859 sk->sk_protocol != IPPROTO_UDPLITE &&
860 sk->sk_protocol != IPPROTO_TCP)
862 if (sk->sk_state != TCP_ESTABLISHED)
868 struct group_filter gsf;
871 if (len < GROUP_FILTER_SIZE(0))
873 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
876 err = ip6_mc_msfget(sk, &gsf,
877 (struct group_filter __user *)optval, optlen);
882 case IPV6_2292PKTOPTIONS:
887 if (sk->sk_type != SOCK_STREAM)
890 msg.msg_control = optval;
891 msg.msg_controllen = len;
895 skb = np->pktoptions;
897 atomic_inc(&skb->users);
901 int err = datagram_recv_ctl(sk, &msg, skb);
906 if (np->rxopt.bits.rxinfo) {
907 struct in6_pktinfo src_info;
908 src_info.ipi6_ifindex = np->mcast_oif;
909 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
910 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
912 if (np->rxopt.bits.rxhlim) {
913 int hlim = np->mcast_hops;
914 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
916 if (np->rxopt.bits.rxoinfo) {
917 struct in6_pktinfo src_info;
918 src_info.ipi6_ifindex = np->mcast_oif;
919 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
920 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
922 if (np->rxopt.bits.rxohlim) {
923 int hlim = np->mcast_hops;
924 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
927 len -= msg.msg_controllen;
928 return put_user(len, optlen);
932 struct dst_entry *dst;
935 dst = sk_dst_get(sk);
950 case IPV6_RECVPKTINFO:
951 val = np->rxopt.bits.rxinfo;
954 case IPV6_2292PKTINFO:
955 val = np->rxopt.bits.rxoinfo;
958 case IPV6_RECVHOPLIMIT:
959 val = np->rxopt.bits.rxhlim;
962 case IPV6_2292HOPLIMIT:
963 val = np->rxopt.bits.rxohlim;
967 val = np->rxopt.bits.srcrt;
971 val = np->rxopt.bits.osrcrt;
975 case IPV6_RTHDRDSTOPTS:
981 len = ipv6_getsockopt_sticky(sk, np->opt,
982 optname, optval, len);
984 /* check if ipv6_getsockopt_sticky() returns err code */
987 return put_user(len, optlen);
990 case IPV6_RECVHOPOPTS:
991 val = np->rxopt.bits.hopopts;
994 case IPV6_2292HOPOPTS:
995 val = np->rxopt.bits.ohopopts;
998 case IPV6_RECVDSTOPTS:
999 val = np->rxopt.bits.dstopts;
1002 case IPV6_2292DSTOPTS:
1003 val = np->rxopt.bits.odstopts;
1012 case IPV6_RECVTCLASS:
1013 val = np->rxopt.bits.rxtclass;
1017 val = np->rxopt.bits.rxflow;
1020 case IPV6_UNICAST_HOPS:
1021 case IPV6_MULTICAST_HOPS:
1023 struct dst_entry *dst;
1025 if (optname == IPV6_UNICAST_HOPS)
1026 val = np->hop_limit;
1028 val = np->mcast_hops;
1030 dst = sk_dst_get(sk);
1033 val = ip6_dst_hoplimit(dst);
1037 val = ipv6_devconf.hop_limit;
1041 case IPV6_MULTICAST_LOOP:
1045 case IPV6_MULTICAST_IF:
1046 val = np->mcast_oif;
1049 case IPV6_MTU_DISCOVER:
1057 case IPV6_FLOWINFO_SEND:
1061 case IPV6_ADDR_PREFERENCES:
1064 if (np->srcprefs & IPV6_PREFER_SRC_TMP)
1065 val |= IPV6_PREFER_SRC_TMP;
1066 else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC)
1067 val |= IPV6_PREFER_SRC_PUBLIC;
1069 /* XXX: should we return system default? */
1070 val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT;
1073 if (np->srcprefs & IPV6_PREFER_SRC_COA)
1074 val |= IPV6_PREFER_SRC_COA;
1076 val |= IPV6_PREFER_SRC_HOME;
1080 return -ENOPROTOOPT;
1082 len = min_t(unsigned int, sizeof(int), len);
1083 if(put_user(len, optlen))
1085 if(copy_to_user(optval,&val,len))
1090 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1091 char __user *optval, int __user *optlen)
1095 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1096 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1098 if(level != SOL_IPV6)
1099 return -ENOPROTOOPT;
1101 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1102 #ifdef CONFIG_NETFILTER
1103 /* we need to exclude all possible ENOPROTOOPTs except default case */
1104 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1107 if (get_user(len, optlen))
1111 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1115 err = put_user(len, optlen);
1121 EXPORT_SYMBOL(ipv6_getsockopt);
1123 #ifdef CONFIG_COMPAT
1124 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1125 char __user *optval, int __user *optlen)
1129 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1130 if (udp_prot.compat_getsockopt != NULL)
1131 return udp_prot.compat_getsockopt(sk, level, optname,
1133 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1136 if (level != SOL_IPV6)
1137 return -ENOPROTOOPT;
1139 if (optname == MCAST_MSFILTER)
1140 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1143 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1144 #ifdef CONFIG_NETFILTER
1145 /* we need to exclude all possible ENOPROTOOPTs except default case */
1146 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1149 if (get_user(len, optlen))
1153 err = compat_nf_getsockopt(sk, PF_INET6,
1154 optname, optval, &len);
1157 err = put_user(len, optlen);
1163 EXPORT_SYMBOL(compat_ipv6_getsockopt);