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))
461 np->mc_loop = valbool;
465 case IPV6_MULTICAST_IF:
466 if (sk->sk_type == SOCK_STREAM)
468 if (optlen < sizeof(int))
472 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
475 if (__dev_get_by_index(net, val) == NULL) {
483 case IPV6_ADD_MEMBERSHIP:
484 case IPV6_DROP_MEMBERSHIP:
486 struct ipv6_mreq mreq;
488 if (optlen < sizeof(struct ipv6_mreq))
492 if (inet_sk(sk)->is_icsk)
496 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
499 if (optname == IPV6_ADD_MEMBERSHIP)
500 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
502 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
505 case IPV6_JOIN_ANYCAST:
506 case IPV6_LEAVE_ANYCAST:
508 struct ipv6_mreq mreq;
510 if (optlen < sizeof(struct ipv6_mreq))
514 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
517 if (optname == IPV6_JOIN_ANYCAST)
518 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
520 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
523 case MCAST_JOIN_GROUP:
524 case MCAST_LEAVE_GROUP:
526 struct group_req greq;
527 struct sockaddr_in6 *psin6;
529 if (optlen < sizeof(struct group_req))
533 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
535 if (greq.gr_group.ss_family != AF_INET6) {
536 retv = -EADDRNOTAVAIL;
539 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
540 if (optname == MCAST_JOIN_GROUP)
541 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
544 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
548 case MCAST_JOIN_SOURCE_GROUP:
549 case MCAST_LEAVE_SOURCE_GROUP:
550 case MCAST_BLOCK_SOURCE:
551 case MCAST_UNBLOCK_SOURCE:
553 struct group_source_req greqs;
556 if (optlen < sizeof(struct group_source_req))
558 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
562 if (greqs.gsr_group.ss_family != AF_INET6 ||
563 greqs.gsr_source.ss_family != AF_INET6) {
564 retv = -EADDRNOTAVAIL;
567 if (optname == MCAST_BLOCK_SOURCE) {
568 omode = MCAST_EXCLUDE;
570 } else if (optname == MCAST_UNBLOCK_SOURCE) {
571 omode = MCAST_EXCLUDE;
573 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
574 struct sockaddr_in6 *psin6;
576 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
577 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
579 /* prior join w/ different source is ok */
580 if (retv && retv != -EADDRINUSE)
582 omode = MCAST_INCLUDE;
584 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
585 omode = MCAST_INCLUDE;
588 retv = ip6_mc_source(add, omode, sk, &greqs);
593 extern int sysctl_mld_max_msf;
594 struct group_filter *gsf;
596 if (optlen < GROUP_FILTER_SIZE(0))
598 if (optlen > sysctl_optmem_max) {
602 gsf = kmalloc(optlen,GFP_KERNEL);
608 if (copy_from_user(gsf, optval, optlen)) {
612 /* numsrc >= (4G-140)/128 overflow in 32 bits */
613 if (gsf->gf_numsrc >= 0x1ffffffU ||
614 gsf->gf_numsrc > sysctl_mld_max_msf) {
619 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
624 retv = ip6_mc_msfilter(sk, gsf);
629 case IPV6_ROUTER_ALERT:
630 if (optlen < sizeof(int))
632 retv = ip6_ra_control(sk, val, NULL);
634 case IPV6_MTU_DISCOVER:
635 if (optlen < sizeof(int))
643 if (optlen < sizeof(int))
645 if (val && val < IPV6_MIN_MTU)
651 if (optlen < sizeof(int))
653 np->recverr = valbool;
655 skb_queue_purge(&sk->sk_error_queue);
658 case IPV6_FLOWINFO_SEND:
659 if (optlen < sizeof(int))
661 np->sndflow = valbool;
664 case IPV6_FLOWLABEL_MGR:
665 retv = ipv6_flowlabel_opt(sk, optval, optlen);
667 case IPV6_IPSEC_POLICY:
668 case IPV6_XFRM_POLICY:
670 if (!capable(CAP_NET_ADMIN))
672 retv = xfrm_user_policy(sk, optname, optval, optlen);
675 case IPV6_ADDR_PREFERENCES:
677 unsigned int pref = 0;
678 unsigned int prefmask = ~0;
680 if (optlen < sizeof(int))
685 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
686 switch (val & (IPV6_PREFER_SRC_PUBLIC|
688 IPV6_PREFER_SRC_PUBTMP_DEFAULT)) {
689 case IPV6_PREFER_SRC_PUBLIC:
690 pref |= IPV6_PREFER_SRC_PUBLIC;
692 case IPV6_PREFER_SRC_TMP:
693 pref |= IPV6_PREFER_SRC_TMP;
695 case IPV6_PREFER_SRC_PUBTMP_DEFAULT:
698 goto pref_skip_pubtmp;
703 prefmask &= ~(IPV6_PREFER_SRC_PUBLIC|
704 IPV6_PREFER_SRC_TMP);
707 /* check HOME/COA conflicts */
708 switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) {
709 case IPV6_PREFER_SRC_HOME:
711 case IPV6_PREFER_SRC_COA:
712 pref |= IPV6_PREFER_SRC_COA;
719 prefmask &= ~IPV6_PREFER_SRC_COA;
722 /* check CGA/NONCGA conflicts */
723 switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) {
724 case IPV6_PREFER_SRC_CGA:
725 case IPV6_PREFER_SRC_NONCGA:
732 np->srcprefs = (np->srcprefs & prefmask) | pref;
748 int ipv6_setsockopt(struct sock *sk, int level, int optname,
749 char __user *optval, int optlen)
753 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
754 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
756 if (level != SOL_IPV6)
759 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
760 #ifdef CONFIG_NETFILTER
761 /* we need to exclude all possible ENOPROTOOPTs except default case */
762 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
763 optname != IPV6_XFRM_POLICY) {
765 err = nf_setsockopt(sk, PF_INET6, optname, optval,
773 EXPORT_SYMBOL(ipv6_setsockopt);
776 int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
777 char __user *optval, int optlen)
781 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
782 if (udp_prot.compat_setsockopt != NULL)
783 return udp_prot.compat_setsockopt(sk, level, optname,
785 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
788 if (level != SOL_IPV6)
791 if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
792 return compat_mc_setsockopt(sk, level, optname, optval, optlen,
795 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
796 #ifdef CONFIG_NETFILTER
797 /* we need to exclude all possible ENOPROTOOPTs except default case */
798 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
799 optname != IPV6_XFRM_POLICY) {
801 err = compat_nf_setsockopt(sk, PF_INET6, optname,
809 EXPORT_SYMBOL(compat_ipv6_setsockopt);
812 static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt,
813 int optname, char __user *optval, int len)
815 struct ipv6_opt_hdr *hdr;
824 case IPV6_RTHDRDSTOPTS:
828 hdr = (struct ipv6_opt_hdr *)opt->srcrt;
834 return -EINVAL; /* should not happen */
840 len = min_t(unsigned int, len, ipv6_optlen(hdr));
841 if (copy_to_user(optval, hdr, len))
846 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
847 char __user *optval, int __user *optlen)
849 struct ipv6_pinfo *np = inet6_sk(sk);
853 if (ip6_mroute_opt(optname))
854 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
856 if (get_user(len, optlen))
860 if (sk->sk_protocol != IPPROTO_UDP &&
861 sk->sk_protocol != IPPROTO_UDPLITE &&
862 sk->sk_protocol != IPPROTO_TCP)
864 if (sk->sk_state != TCP_ESTABLISHED)
870 struct group_filter gsf;
873 if (len < GROUP_FILTER_SIZE(0))
875 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
877 if (gsf.gf_group.ss_family != AF_INET6)
878 return -EADDRNOTAVAIL;
880 err = ip6_mc_msfget(sk, &gsf,
881 (struct group_filter __user *)optval, optlen);
886 case IPV6_2292PKTOPTIONS:
891 if (sk->sk_type != SOCK_STREAM)
894 msg.msg_control = optval;
895 msg.msg_controllen = len;
899 skb = np->pktoptions;
901 atomic_inc(&skb->users);
905 int err = datagram_recv_ctl(sk, &msg, skb);
910 if (np->rxopt.bits.rxinfo) {
911 struct in6_pktinfo src_info;
912 src_info.ipi6_ifindex = np->mcast_oif;
913 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
914 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
916 if (np->rxopt.bits.rxhlim) {
917 int hlim = np->mcast_hops;
918 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
920 if (np->rxopt.bits.rxoinfo) {
921 struct in6_pktinfo src_info;
922 src_info.ipi6_ifindex = np->mcast_oif;
923 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
924 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
926 if (np->rxopt.bits.rxohlim) {
927 int hlim = np->mcast_hops;
928 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
931 len -= msg.msg_controllen;
932 return put_user(len, optlen);
936 struct dst_entry *dst;
939 dst = sk_dst_get(sk);
954 case IPV6_RECVPKTINFO:
955 val = np->rxopt.bits.rxinfo;
958 case IPV6_2292PKTINFO:
959 val = np->rxopt.bits.rxoinfo;
962 case IPV6_RECVHOPLIMIT:
963 val = np->rxopt.bits.rxhlim;
966 case IPV6_2292HOPLIMIT:
967 val = np->rxopt.bits.rxohlim;
971 val = np->rxopt.bits.srcrt;
975 val = np->rxopt.bits.osrcrt;
979 case IPV6_RTHDRDSTOPTS:
985 len = ipv6_getsockopt_sticky(sk, np->opt,
986 optname, optval, len);
988 /* check if ipv6_getsockopt_sticky() returns err code */
991 return put_user(len, optlen);
994 case IPV6_RECVHOPOPTS:
995 val = np->rxopt.bits.hopopts;
998 case IPV6_2292HOPOPTS:
999 val = np->rxopt.bits.ohopopts;
1002 case IPV6_RECVDSTOPTS:
1003 val = np->rxopt.bits.dstopts;
1006 case IPV6_2292DSTOPTS:
1007 val = np->rxopt.bits.odstopts;
1016 case IPV6_RECVTCLASS:
1017 val = np->rxopt.bits.rxtclass;
1021 val = np->rxopt.bits.rxflow;
1024 case IPV6_UNICAST_HOPS:
1025 case IPV6_MULTICAST_HOPS:
1027 struct dst_entry *dst;
1029 if (optname == IPV6_UNICAST_HOPS)
1030 val = np->hop_limit;
1032 val = np->mcast_hops;
1034 dst = sk_dst_get(sk);
1037 val = ip6_dst_hoplimit(dst);
1041 val = ipv6_devconf.hop_limit;
1045 case IPV6_MULTICAST_LOOP:
1049 case IPV6_MULTICAST_IF:
1050 val = np->mcast_oif;
1053 case IPV6_MTU_DISCOVER:
1061 case IPV6_FLOWINFO_SEND:
1065 case IPV6_ADDR_PREFERENCES:
1068 if (np->srcprefs & IPV6_PREFER_SRC_TMP)
1069 val |= IPV6_PREFER_SRC_TMP;
1070 else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC)
1071 val |= IPV6_PREFER_SRC_PUBLIC;
1073 /* XXX: should we return system default? */
1074 val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT;
1077 if (np->srcprefs & IPV6_PREFER_SRC_COA)
1078 val |= IPV6_PREFER_SRC_COA;
1080 val |= IPV6_PREFER_SRC_HOME;
1084 return -ENOPROTOOPT;
1086 len = min_t(unsigned int, sizeof(int), len);
1087 if(put_user(len, optlen))
1089 if(copy_to_user(optval,&val,len))
1094 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1095 char __user *optval, int __user *optlen)
1099 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1100 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1102 if(level != SOL_IPV6)
1103 return -ENOPROTOOPT;
1105 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1106 #ifdef CONFIG_NETFILTER
1107 /* we need to exclude all possible ENOPROTOOPTs except default case */
1108 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1111 if (get_user(len, optlen))
1115 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1119 err = put_user(len, optlen);
1125 EXPORT_SYMBOL(ipv6_getsockopt);
1127 #ifdef CONFIG_COMPAT
1128 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1129 char __user *optval, int __user *optlen)
1133 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1134 if (udp_prot.compat_getsockopt != NULL)
1135 return udp_prot.compat_getsockopt(sk, level, optname,
1137 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1140 if (level != SOL_IPV6)
1141 return -ENOPROTOOPT;
1143 if (optname == MCAST_MSFILTER)
1144 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1147 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1148 #ifdef CONFIG_NETFILTER
1149 /* we need to exclude all possible ENOPROTOOPTs except default case */
1150 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1153 if (get_user(len, optlen))
1157 err = compat_nf_getsockopt(sk, PF_INET6,
1158 optname, optval, &len);
1161 err = put_user(len, optlen);
1167 EXPORT_SYMBOL(compat_ipv6_getsockopt);