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 * $Id: ipv6_sockglue.c,v 1.41 2002/02/01 22:01:04 davem Exp $
12 * This program is free software; you can redistribute it and/or
13 * modify it under the terms of the GNU General Public License
14 * as published by the Free Software Foundation; either version
15 * 2 of the License, or (at your option) any later version.
17 * FIXME: Make the setsockopt code POSIX compliant: That is
19 * o Truncate getsockopt returns
20 * o Return an optlen of the truncated length if need be
23 * David L Stevens <dlstevens@us.ibm.com>:
24 * - added multicast source filtering API for MLDv2
27 #include <linux/module.h>
28 #include <linux/capability.h>
29 #include <linux/errno.h>
30 #include <linux/types.h>
31 #include <linux/socket.h>
32 #include <linux/sockios.h>
33 #include <linux/net.h>
34 #include <linux/in6.h>
35 #include <linux/mroute6.h>
36 #include <linux/netdevice.h>
37 #include <linux/if_arp.h>
38 #include <linux/init.h>
39 #include <linux/sysctl.h>
40 #include <linux/netfilter.h>
45 #include <net/ndisc.h>
46 #include <net/protocol.h>
47 #include <net/transp_v6.h>
48 #include <net/ip6_route.h>
49 #include <net/addrconf.h>
50 #include <net/inet_common.h>
53 #include <net/udplite.h>
55 #include <net/compat.h>
57 #include <asm/uaccess.h>
59 DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly;
61 struct ip6_ra_chain *ip6_ra_chain;
62 DEFINE_RWLOCK(ip6_ra_lock);
64 int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
66 struct ip6_ra_chain *ra, *new_ra, **rap;
68 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
69 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num != IPPROTO_RAW)
72 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
74 write_lock_bh(&ip6_ra_lock);
75 for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
78 write_unlock_bh(&ip6_ra_lock);
84 write_unlock_bh(&ip6_ra_lock);
94 write_unlock_bh(&ip6_ra_lock);
99 new_ra->destructor = destructor;
103 write_unlock_bh(&ip6_ra_lock);
108 struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
109 struct ipv6_txoptions *opt)
111 if (inet_sk(sk)->is_icsk) {
113 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
114 inet_sk(sk)->daddr != LOOPBACK4_IPV6) {
115 struct inet_connection_sock *icsk = inet_csk(sk);
116 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
117 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
119 opt = xchg(&inet6_sk(sk)->opt, opt);
121 write_lock(&sk->sk_dst_lock);
122 opt = xchg(&inet6_sk(sk)->opt, opt);
123 write_unlock(&sk->sk_dst_lock);
130 static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
131 char __user *optval, int optlen)
133 struct ipv6_pinfo *np = inet6_sk(sk);
134 struct net *net = sock_net(sk);
136 int retv = -ENOPROTOOPT;
141 if (optlen >= sizeof(int)) {
142 if (get_user(val, (int __user *) optval))
150 if (ip6_mroute_opt(optname))
151 return ip6_mroute_setsockopt(sk, optname, optval, optlen);
158 if (optlen < sizeof(int))
160 if (val == PF_INET) {
161 struct ipv6_txoptions *opt;
162 struct sk_buff *pktopt;
164 if (sk->sk_protocol != IPPROTO_UDP &&
165 sk->sk_protocol != IPPROTO_UDPLITE &&
166 sk->sk_protocol != IPPROTO_TCP)
169 if (sk->sk_state != TCP_ESTABLISHED) {
174 if (ipv6_only_sock(sk) ||
175 !ipv6_addr_v4mapped(&np->daddr)) {
176 retv = -EADDRNOTAVAIL;
180 fl6_free_socklist(sk);
181 ipv6_sock_mc_close(sk);
184 * Sock is moving from IPv6 to IPv4 (sk_prot), so
185 * remove it from the refcnt debug socks count in the
188 sk_refcnt_debug_dec(sk);
190 if (sk->sk_protocol == IPPROTO_TCP) {
191 struct inet_connection_sock *icsk = inet_csk(sk);
193 sock_prot_inuse_add(net, sk->sk_prot, -1);
194 sock_prot_inuse_add(net, &tcp_prot, 1);
196 sk->sk_prot = &tcp_prot;
197 icsk->icsk_af_ops = &ipv4_specific;
198 sk->sk_socket->ops = &inet_stream_ops;
199 sk->sk_family = PF_INET;
200 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
202 struct proto *prot = &udp_prot;
204 if (sk->sk_protocol == IPPROTO_UDPLITE)
205 prot = &udplite_prot;
207 sock_prot_inuse_add(net, sk->sk_prot, -1);
208 sock_prot_inuse_add(net, prot, 1);
211 sk->sk_socket->ops = &inet_dgram_ops;
212 sk->sk_family = PF_INET;
214 opt = xchg(&np->opt, NULL);
216 sock_kfree_s(sk, opt, opt->tot_len);
217 pktopt = xchg(&np->pktoptions, NULL);
221 sk->sk_destruct = inet_sock_destruct;
223 * ... and add it to the refcnt debug socks count
224 * in the new family. -acme
226 sk_refcnt_debug_inc(sk);
227 module_put(THIS_MODULE);
234 if (optlen < sizeof(int) ||
237 np->ipv6only = valbool;
241 case IPV6_RECVPKTINFO:
242 if (optlen < sizeof(int))
244 np->rxopt.bits.rxinfo = valbool;
248 case IPV6_2292PKTINFO:
249 if (optlen < sizeof(int))
251 np->rxopt.bits.rxoinfo = valbool;
255 case IPV6_RECVHOPLIMIT:
256 if (optlen < sizeof(int))
258 np->rxopt.bits.rxhlim = valbool;
262 case IPV6_2292HOPLIMIT:
263 if (optlen < sizeof(int))
265 np->rxopt.bits.rxohlim = valbool;
270 if (optlen < sizeof(int))
272 np->rxopt.bits.srcrt = valbool;
277 if (optlen < sizeof(int))
279 np->rxopt.bits.osrcrt = valbool;
283 case IPV6_RECVHOPOPTS:
284 if (optlen < sizeof(int))
286 np->rxopt.bits.hopopts = valbool;
290 case IPV6_2292HOPOPTS:
291 if (optlen < sizeof(int))
293 np->rxopt.bits.ohopopts = valbool;
297 case IPV6_RECVDSTOPTS:
298 if (optlen < sizeof(int))
300 np->rxopt.bits.dstopts = valbool;
304 case IPV6_2292DSTOPTS:
305 if (optlen < sizeof(int))
307 np->rxopt.bits.odstopts = valbool;
312 if (optlen < sizeof(int))
314 if (val < -1 || val > 0xff)
320 case IPV6_RECVTCLASS:
321 if (optlen < sizeof(int))
323 np->rxopt.bits.rxtclass = valbool;
328 if (optlen < sizeof(int))
330 np->rxopt.bits.rxflow = valbool;
335 case IPV6_RTHDRDSTOPTS:
339 struct ipv6_txoptions *opt;
343 /* hop-by-hop / destination options are privileged option */
345 if (optname != IPV6_RTHDR && !capable(CAP_NET_RAW))
348 if (optlen < sizeof(struct ipv6_opt_hdr) ||
349 optlen & 0x7 || optlen > 8 * 255)
352 opt = ipv6_renew_options(sk, np->opt, optname,
353 (struct ipv6_opt_hdr __user *)optval,
360 /* routing header option needs extra check */
361 if (optname == IPV6_RTHDR && opt && opt->srcrt) {
362 struct ipv6_rt_hdr *rthdr = opt->srcrt;
363 switch (rthdr->type) {
364 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
365 case IPV6_SRCRT_TYPE_2:
372 if ((rthdr->hdrlen & 1) ||
373 (rthdr->hdrlen >> 1) != rthdr->segments_left)
378 opt = ipv6_update_options(sk, opt);
381 sock_kfree_s(sk, opt, opt->tot_len);
385 case IPV6_2292PKTOPTIONS:
387 struct ipv6_txoptions *opt = NULL;
392 fl.fl6_flowlabel = 0;
393 fl.oif = sk->sk_bound_dev_if;
398 /* 1K is probably excessive
399 * 1K is surely not enough, 2K per standard header is 16K.
402 if (optlen > 64*1024)
405 opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL);
410 memset(opt, 0, sizeof(*opt));
411 opt->tot_len = sizeof(*opt) + optlen;
413 if (copy_from_user(opt+1, optval, optlen))
416 msg.msg_controllen = optlen;
417 msg.msg_control = (void*)(opt+1);
419 retv = datagram_send_ctl(&msg, &fl, opt, &junk, &junk);
424 opt = ipv6_update_options(sk, opt);
427 sock_kfree_s(sk, opt, opt->tot_len);
430 case IPV6_UNICAST_HOPS:
431 if (optlen < sizeof(int))
433 if (val > 255 || val < -1)
439 case IPV6_MULTICAST_HOPS:
440 if (sk->sk_type == SOCK_STREAM)
442 if (optlen < sizeof(int))
444 if (val > 255 || val < -1)
446 np->mcast_hops = val;
450 case IPV6_MULTICAST_LOOP:
451 if (optlen < sizeof(int))
453 np->mc_loop = valbool;
457 case IPV6_MULTICAST_IF:
458 if (sk->sk_type == SOCK_STREAM)
460 if (optlen < sizeof(int))
464 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
467 if (__dev_get_by_index(net, val) == NULL) {
475 case IPV6_ADD_MEMBERSHIP:
476 case IPV6_DROP_MEMBERSHIP:
478 struct ipv6_mreq mreq;
480 if (optlen < sizeof(struct ipv6_mreq))
484 if (inet_sk(sk)->is_icsk)
488 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
491 if (optname == IPV6_ADD_MEMBERSHIP)
492 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
494 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
497 case IPV6_JOIN_ANYCAST:
498 case IPV6_LEAVE_ANYCAST:
500 struct ipv6_mreq mreq;
502 if (optlen < sizeof(struct ipv6_mreq))
506 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
509 if (optname == IPV6_JOIN_ANYCAST)
510 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
512 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
515 case MCAST_JOIN_GROUP:
516 case MCAST_LEAVE_GROUP:
518 struct group_req greq;
519 struct sockaddr_in6 *psin6;
521 if (optlen < sizeof(struct group_req))
525 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
527 if (greq.gr_group.ss_family != AF_INET6) {
528 retv = -EADDRNOTAVAIL;
531 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
532 if (optname == MCAST_JOIN_GROUP)
533 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
536 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
540 case MCAST_JOIN_SOURCE_GROUP:
541 case MCAST_LEAVE_SOURCE_GROUP:
542 case MCAST_BLOCK_SOURCE:
543 case MCAST_UNBLOCK_SOURCE:
545 struct group_source_req greqs;
548 if (optlen < sizeof(struct group_source_req))
550 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
554 if (greqs.gsr_group.ss_family != AF_INET6 ||
555 greqs.gsr_source.ss_family != AF_INET6) {
556 retv = -EADDRNOTAVAIL;
559 if (optname == MCAST_BLOCK_SOURCE) {
560 omode = MCAST_EXCLUDE;
562 } else if (optname == MCAST_UNBLOCK_SOURCE) {
563 omode = MCAST_EXCLUDE;
565 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
566 struct sockaddr_in6 *psin6;
568 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
569 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
571 /* prior join w/ different source is ok */
572 if (retv && retv != -EADDRINUSE)
574 omode = MCAST_INCLUDE;
576 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
577 omode = MCAST_INCLUDE;
580 retv = ip6_mc_source(add, omode, sk, &greqs);
585 extern int sysctl_mld_max_msf;
586 struct group_filter *gsf;
588 if (optlen < GROUP_FILTER_SIZE(0))
590 if (optlen > sysctl_optmem_max) {
594 gsf = kmalloc(optlen,GFP_KERNEL);
600 if (copy_from_user(gsf, optval, optlen)) {
604 /* numsrc >= (4G-140)/128 overflow in 32 bits */
605 if (gsf->gf_numsrc >= 0x1ffffffU ||
606 gsf->gf_numsrc > sysctl_mld_max_msf) {
611 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
616 retv = ip6_mc_msfilter(sk, gsf);
621 case IPV6_ROUTER_ALERT:
622 if (optlen < sizeof(int))
624 retv = ip6_ra_control(sk, val, NULL);
626 case IPV6_MTU_DISCOVER:
627 if (optlen < sizeof(int))
635 if (optlen < sizeof(int))
637 if (val && val < IPV6_MIN_MTU)
643 if (optlen < sizeof(int))
645 np->recverr = valbool;
647 skb_queue_purge(&sk->sk_error_queue);
650 case IPV6_FLOWINFO_SEND:
651 if (optlen < sizeof(int))
653 np->sndflow = valbool;
656 case IPV6_FLOWLABEL_MGR:
657 retv = ipv6_flowlabel_opt(sk, optval, optlen);
659 case IPV6_IPSEC_POLICY:
660 case IPV6_XFRM_POLICY:
662 if (!capable(CAP_NET_ADMIN))
664 retv = xfrm_user_policy(sk, optname, optval, optlen);
667 case IPV6_ADDR_PREFERENCES:
669 unsigned int pref = 0;
670 unsigned int prefmask = ~0;
672 if (optlen < sizeof(int))
677 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
678 switch (val & (IPV6_PREFER_SRC_PUBLIC|
680 IPV6_PREFER_SRC_PUBTMP_DEFAULT)) {
681 case IPV6_PREFER_SRC_PUBLIC:
682 pref |= IPV6_PREFER_SRC_PUBLIC;
684 case IPV6_PREFER_SRC_TMP:
685 pref |= IPV6_PREFER_SRC_TMP;
687 case IPV6_PREFER_SRC_PUBTMP_DEFAULT:
690 goto pref_skip_pubtmp;
695 prefmask &= ~(IPV6_PREFER_SRC_PUBLIC|
696 IPV6_PREFER_SRC_TMP);
699 /* check HOME/COA conflicts */
700 switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) {
701 case IPV6_PREFER_SRC_HOME:
703 case IPV6_PREFER_SRC_COA:
704 pref |= IPV6_PREFER_SRC_COA;
711 prefmask &= ~IPV6_PREFER_SRC_COA;
714 /* check CGA/NONCGA conflicts */
715 switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) {
716 case IPV6_PREFER_SRC_CGA:
717 case IPV6_PREFER_SRC_NONCGA:
724 np->srcprefs = (np->srcprefs & prefmask) | pref;
740 int ipv6_setsockopt(struct sock *sk, int level, int optname,
741 char __user *optval, int optlen)
745 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
746 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
748 if (level != SOL_IPV6)
751 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
752 #ifdef CONFIG_NETFILTER
753 /* we need to exclude all possible ENOPROTOOPTs except default case */
754 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
755 optname != IPV6_XFRM_POLICY) {
757 err = nf_setsockopt(sk, PF_INET6, optname, optval,
765 EXPORT_SYMBOL(ipv6_setsockopt);
768 int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
769 char __user *optval, int optlen)
773 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
774 if (udp_prot.compat_setsockopt != NULL)
775 return udp_prot.compat_setsockopt(sk, level, optname,
777 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
780 if (level != SOL_IPV6)
783 if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
784 return compat_mc_setsockopt(sk, level, optname, optval, optlen,
787 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
788 #ifdef CONFIG_NETFILTER
789 /* we need to exclude all possible ENOPROTOOPTs except default case */
790 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
791 optname != IPV6_XFRM_POLICY) {
793 err = compat_nf_setsockopt(sk, PF_INET6, optname,
801 EXPORT_SYMBOL(compat_ipv6_setsockopt);
804 static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt,
805 int optname, char __user *optval, int len)
807 struct ipv6_opt_hdr *hdr;
816 case IPV6_RTHDRDSTOPTS:
820 hdr = (struct ipv6_opt_hdr *)opt->srcrt;
826 return -EINVAL; /* should not happen */
832 len = min_t(unsigned int, len, ipv6_optlen(hdr));
833 if (copy_to_user(optval, hdr, len))
835 return ipv6_optlen(hdr);
838 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
839 char __user *optval, int __user *optlen)
841 struct ipv6_pinfo *np = inet6_sk(sk);
845 if (ip6_mroute_opt(optname))
846 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
848 if (get_user(len, optlen))
852 if (sk->sk_protocol != IPPROTO_UDP &&
853 sk->sk_protocol != IPPROTO_UDPLITE &&
854 sk->sk_protocol != IPPROTO_TCP)
856 if (sk->sk_state != TCP_ESTABLISHED)
862 struct group_filter gsf;
865 if (len < GROUP_FILTER_SIZE(0))
867 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
870 err = ip6_mc_msfget(sk, &gsf,
871 (struct group_filter __user *)optval, optlen);
876 case IPV6_2292PKTOPTIONS:
881 if (sk->sk_type != SOCK_STREAM)
884 msg.msg_control = optval;
885 msg.msg_controllen = len;
889 skb = np->pktoptions;
891 atomic_inc(&skb->users);
895 int err = datagram_recv_ctl(sk, &msg, skb);
900 if (np->rxopt.bits.rxinfo) {
901 struct in6_pktinfo src_info;
902 src_info.ipi6_ifindex = np->mcast_oif;
903 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
904 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
906 if (np->rxopt.bits.rxhlim) {
907 int hlim = np->mcast_hops;
908 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
910 if (np->rxopt.bits.rxoinfo) {
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_2292PKTINFO, sizeof(src_info), &src_info);
916 if (np->rxopt.bits.rxohlim) {
917 int hlim = np->mcast_hops;
918 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
921 len -= msg.msg_controllen;
922 return put_user(len, optlen);
926 struct dst_entry *dst;
929 dst = sk_dst_get(sk);
944 case IPV6_RECVPKTINFO:
945 val = np->rxopt.bits.rxinfo;
948 case IPV6_2292PKTINFO:
949 val = np->rxopt.bits.rxoinfo;
952 case IPV6_RECVHOPLIMIT:
953 val = np->rxopt.bits.rxhlim;
956 case IPV6_2292HOPLIMIT:
957 val = np->rxopt.bits.rxohlim;
961 val = np->rxopt.bits.srcrt;
965 val = np->rxopt.bits.osrcrt;
969 case IPV6_RTHDRDSTOPTS:
975 len = ipv6_getsockopt_sticky(sk, np->opt,
976 optname, optval, len);
978 return put_user(len, optlen);
981 case IPV6_RECVHOPOPTS:
982 val = np->rxopt.bits.hopopts;
985 case IPV6_2292HOPOPTS:
986 val = np->rxopt.bits.ohopopts;
989 case IPV6_RECVDSTOPTS:
990 val = np->rxopt.bits.dstopts;
993 case IPV6_2292DSTOPTS:
994 val = np->rxopt.bits.odstopts;
1003 case IPV6_RECVTCLASS:
1004 val = np->rxopt.bits.rxtclass;
1008 val = np->rxopt.bits.rxflow;
1011 case IPV6_UNICAST_HOPS:
1012 case IPV6_MULTICAST_HOPS:
1014 struct dst_entry *dst;
1016 if (optname == IPV6_UNICAST_HOPS)
1017 val = np->hop_limit;
1019 val = np->mcast_hops;
1021 dst = sk_dst_get(sk);
1024 val = ip6_dst_hoplimit(dst);
1028 val = ipv6_devconf.hop_limit;
1032 case IPV6_MULTICAST_LOOP:
1036 case IPV6_MULTICAST_IF:
1037 val = np->mcast_oif;
1040 case IPV6_MTU_DISCOVER:
1048 case IPV6_FLOWINFO_SEND:
1052 case IPV6_ADDR_PREFERENCES:
1055 if (np->srcprefs & IPV6_PREFER_SRC_TMP)
1056 val |= IPV6_PREFER_SRC_TMP;
1057 else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC)
1058 val |= IPV6_PREFER_SRC_PUBLIC;
1060 /* XXX: should we return system default? */
1061 val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT;
1064 if (np->srcprefs & IPV6_PREFER_SRC_COA)
1065 val |= IPV6_PREFER_SRC_COA;
1067 val |= IPV6_PREFER_SRC_HOME;
1071 return -ENOPROTOOPT;
1073 len = min_t(unsigned int, sizeof(int), len);
1074 if(put_user(len, optlen))
1076 if(copy_to_user(optval,&val,len))
1081 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1082 char __user *optval, int __user *optlen)
1086 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1087 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1089 if(level != SOL_IPV6)
1090 return -ENOPROTOOPT;
1092 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1093 #ifdef CONFIG_NETFILTER
1094 /* we need to exclude all possible ENOPROTOOPTs except default case */
1095 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1098 if (get_user(len, optlen))
1102 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1106 err = put_user(len, optlen);
1112 EXPORT_SYMBOL(ipv6_getsockopt);
1114 #ifdef CONFIG_COMPAT
1115 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1116 char __user *optval, int __user *optlen)
1120 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1121 if (udp_prot.compat_getsockopt != NULL)
1122 return udp_prot.compat_getsockopt(sk, level, optname,
1124 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1127 if (level != SOL_IPV6)
1128 return -ENOPROTOOPT;
1130 if (optname == MCAST_MSFILTER)
1131 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1134 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1135 #ifdef CONFIG_NETFILTER
1136 /* we need to exclude all possible ENOPROTOOPTs except default case */
1137 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1140 if (get_user(len, optlen))
1144 err = compat_nf_getsockopt(sk, PF_INET6,
1145 optname, optval, &len);
1148 err = put_user(len, optlen);
1154 EXPORT_SYMBOL(compat_ipv6_getsockopt);