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>
56 #include <asm/uaccess.h>
58 DEFINE_SNMP_STAT(struct ipstats_mib, ipv6_statistics) __read_mostly;
60 struct ip6_ra_chain *ip6_ra_chain;
61 DEFINE_RWLOCK(ip6_ra_lock);
63 int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
65 struct ip6_ra_chain *ra, *new_ra, **rap;
67 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
68 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num != IPPROTO_RAW)
71 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
73 write_lock_bh(&ip6_ra_lock);
74 for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
77 write_unlock_bh(&ip6_ra_lock);
83 write_unlock_bh(&ip6_ra_lock);
93 write_unlock_bh(&ip6_ra_lock);
98 new_ra->destructor = destructor;
102 write_unlock_bh(&ip6_ra_lock);
107 struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
108 struct ipv6_txoptions *opt)
110 if (inet_sk(sk)->is_icsk) {
112 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
113 inet_sk(sk)->daddr != LOOPBACK4_IPV6) {
114 struct inet_connection_sock *icsk = inet_csk(sk);
115 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
116 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
118 opt = xchg(&inet6_sk(sk)->opt, opt);
120 write_lock(&sk->sk_dst_lock);
121 opt = xchg(&inet6_sk(sk)->opt, opt);
122 write_unlock(&sk->sk_dst_lock);
129 static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
130 char __user *optval, int optlen)
132 struct ipv6_pinfo *np = inet6_sk(sk);
133 struct net *net = sock_net(sk);
135 int retv = -ENOPROTOOPT;
140 if (optlen >= sizeof(int)) {
141 if (get_user(val, (int __user *) optval))
149 if (ip6_mroute_opt(optname))
150 return ip6_mroute_setsockopt(sk, optname, optval, optlen);
157 if (optlen < sizeof(int))
159 if (val == PF_INET) {
160 struct ipv6_txoptions *opt;
161 struct sk_buff *pktopt;
163 if (sk->sk_protocol != IPPROTO_UDP &&
164 sk->sk_protocol != IPPROTO_UDPLITE &&
165 sk->sk_protocol != IPPROTO_TCP)
168 if (sk->sk_state != TCP_ESTABLISHED) {
173 if (ipv6_only_sock(sk) ||
174 !ipv6_addr_v4mapped(&np->daddr)) {
175 retv = -EADDRNOTAVAIL;
179 fl6_free_socklist(sk);
180 ipv6_sock_mc_close(sk);
183 * Sock is moving from IPv6 to IPv4 (sk_prot), so
184 * remove it from the refcnt debug socks count in the
187 sk_refcnt_debug_dec(sk);
189 if (sk->sk_protocol == IPPROTO_TCP) {
190 struct inet_connection_sock *icsk = inet_csk(sk);
192 sock_prot_inuse_add(net, sk->sk_prot, -1);
193 sock_prot_inuse_add(net, &tcp_prot, 1);
195 sk->sk_prot = &tcp_prot;
196 icsk->icsk_af_ops = &ipv4_specific;
197 sk->sk_socket->ops = &inet_stream_ops;
198 sk->sk_family = PF_INET;
199 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
201 struct proto *prot = &udp_prot;
203 if (sk->sk_protocol == IPPROTO_UDPLITE)
204 prot = &udplite_prot;
206 sock_prot_inuse_add(net, sk->sk_prot, -1);
207 sock_prot_inuse_add(net, prot, 1);
210 sk->sk_socket->ops = &inet_dgram_ops;
211 sk->sk_family = PF_INET;
213 opt = xchg(&np->opt, NULL);
215 sock_kfree_s(sk, opt, opt->tot_len);
216 pktopt = xchg(&np->pktoptions, NULL);
220 sk->sk_destruct = inet_sock_destruct;
222 * ... and add it to the refcnt debug socks count
223 * in the new family. -acme
225 sk_refcnt_debug_inc(sk);
226 module_put(THIS_MODULE);
233 if (optlen < sizeof(int) ||
236 np->ipv6only = valbool;
240 case IPV6_RECVPKTINFO:
241 if (optlen < sizeof(int))
243 np->rxopt.bits.rxinfo = valbool;
247 case IPV6_2292PKTINFO:
248 if (optlen < sizeof(int))
250 np->rxopt.bits.rxoinfo = valbool;
254 case IPV6_RECVHOPLIMIT:
255 if (optlen < sizeof(int))
257 np->rxopt.bits.rxhlim = valbool;
261 case IPV6_2292HOPLIMIT:
262 if (optlen < sizeof(int))
264 np->rxopt.bits.rxohlim = valbool;
269 if (optlen < sizeof(int))
271 np->rxopt.bits.srcrt = valbool;
276 if (optlen < sizeof(int))
278 np->rxopt.bits.osrcrt = valbool;
282 case IPV6_RECVHOPOPTS:
283 if (optlen < sizeof(int))
285 np->rxopt.bits.hopopts = valbool;
289 case IPV6_2292HOPOPTS:
290 if (optlen < sizeof(int))
292 np->rxopt.bits.ohopopts = valbool;
296 case IPV6_RECVDSTOPTS:
297 if (optlen < sizeof(int))
299 np->rxopt.bits.dstopts = valbool;
303 case IPV6_2292DSTOPTS:
304 if (optlen < sizeof(int))
306 np->rxopt.bits.odstopts = valbool;
311 if (optlen < sizeof(int))
313 if (val < -1 || val > 0xff)
319 case IPV6_RECVTCLASS:
320 if (optlen < sizeof(int))
322 np->rxopt.bits.rxtclass = valbool;
327 if (optlen < sizeof(int))
329 np->rxopt.bits.rxflow = valbool;
334 case IPV6_RTHDRDSTOPTS:
338 struct ipv6_txoptions *opt;
342 /* hop-by-hop / destination options are privileged option */
344 if (optname != IPV6_RTHDR && !capable(CAP_NET_RAW))
347 if (optlen < sizeof(struct ipv6_opt_hdr) ||
348 optlen & 0x7 || optlen > 8 * 255)
351 opt = ipv6_renew_options(sk, np->opt, optname,
352 (struct ipv6_opt_hdr __user *)optval,
359 /* routing header option needs extra check */
360 if (optname == IPV6_RTHDR && opt && opt->srcrt) {
361 struct ipv6_rt_hdr *rthdr = opt->srcrt;
362 switch (rthdr->type) {
363 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
364 case IPV6_SRCRT_TYPE_2:
371 if ((rthdr->hdrlen & 1) ||
372 (rthdr->hdrlen >> 1) != rthdr->segments_left)
377 opt = ipv6_update_options(sk, opt);
380 sock_kfree_s(sk, opt, opt->tot_len);
384 case IPV6_2292PKTOPTIONS:
386 struct ipv6_txoptions *opt = NULL;
391 fl.fl6_flowlabel = 0;
392 fl.oif = sk->sk_bound_dev_if;
397 /* 1K is probably excessive
398 * 1K is surely not enough, 2K per standard header is 16K.
401 if (optlen > 64*1024)
404 opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL);
409 memset(opt, 0, sizeof(*opt));
410 opt->tot_len = sizeof(*opt) + optlen;
412 if (copy_from_user(opt+1, optval, optlen))
415 msg.msg_controllen = optlen;
416 msg.msg_control = (void*)(opt+1);
418 retv = datagram_send_ctl(&msg, &fl, opt, &junk, &junk);
423 opt = ipv6_update_options(sk, opt);
426 sock_kfree_s(sk, opt, opt->tot_len);
429 case IPV6_UNICAST_HOPS:
430 if (optlen < sizeof(int))
432 if (val > 255 || val < -1)
438 case IPV6_MULTICAST_HOPS:
439 if (sk->sk_type == SOCK_STREAM)
441 if (optlen < sizeof(int))
443 if (val > 255 || val < -1)
445 np->mcast_hops = val;
449 case IPV6_MULTICAST_LOOP:
450 if (optlen < sizeof(int))
452 np->mc_loop = valbool;
456 case IPV6_MULTICAST_IF:
457 if (sk->sk_type == SOCK_STREAM)
459 if (optlen < sizeof(int))
463 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
466 if (__dev_get_by_index(net, val) == NULL) {
474 case IPV6_ADD_MEMBERSHIP:
475 case IPV6_DROP_MEMBERSHIP:
477 struct ipv6_mreq mreq;
479 if (optlen < sizeof(struct ipv6_mreq))
483 if (inet_sk(sk)->is_icsk)
487 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
490 if (optname == IPV6_ADD_MEMBERSHIP)
491 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
493 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
496 case IPV6_JOIN_ANYCAST:
497 case IPV6_LEAVE_ANYCAST:
499 struct ipv6_mreq mreq;
501 if (optlen < sizeof(struct ipv6_mreq))
505 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
508 if (optname == IPV6_JOIN_ANYCAST)
509 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
511 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
514 case MCAST_JOIN_GROUP:
515 case MCAST_LEAVE_GROUP:
517 struct group_req greq;
518 struct sockaddr_in6 *psin6;
520 if (optlen < sizeof(struct group_req))
524 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
526 if (greq.gr_group.ss_family != AF_INET6) {
527 retv = -EADDRNOTAVAIL;
530 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
531 if (optname == MCAST_JOIN_GROUP)
532 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
535 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
539 case MCAST_JOIN_SOURCE_GROUP:
540 case MCAST_LEAVE_SOURCE_GROUP:
541 case MCAST_BLOCK_SOURCE:
542 case MCAST_UNBLOCK_SOURCE:
544 struct group_source_req greqs;
547 if (optlen < sizeof(struct group_source_req))
549 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
553 if (greqs.gsr_group.ss_family != AF_INET6 ||
554 greqs.gsr_source.ss_family != AF_INET6) {
555 retv = -EADDRNOTAVAIL;
558 if (optname == MCAST_BLOCK_SOURCE) {
559 omode = MCAST_EXCLUDE;
561 } else if (optname == MCAST_UNBLOCK_SOURCE) {
562 omode = MCAST_EXCLUDE;
564 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
565 struct sockaddr_in6 *psin6;
567 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
568 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
570 /* prior join w/ different source is ok */
571 if (retv && retv != -EADDRINUSE)
573 omode = MCAST_INCLUDE;
575 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
576 omode = MCAST_INCLUDE;
579 retv = ip6_mc_source(add, omode, sk, &greqs);
584 extern int sysctl_mld_max_msf;
585 struct group_filter *gsf;
587 if (optlen < GROUP_FILTER_SIZE(0))
589 if (optlen > sysctl_optmem_max) {
593 gsf = kmalloc(optlen,GFP_KERNEL);
599 if (copy_from_user(gsf, optval, optlen)) {
603 /* numsrc >= (4G-140)/128 overflow in 32 bits */
604 if (gsf->gf_numsrc >= 0x1ffffffU ||
605 gsf->gf_numsrc > sysctl_mld_max_msf) {
610 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
615 retv = ip6_mc_msfilter(sk, gsf);
620 case IPV6_ROUTER_ALERT:
621 if (optlen < sizeof(int))
623 retv = ip6_ra_control(sk, val, NULL);
625 case IPV6_MTU_DISCOVER:
626 if (optlen < sizeof(int))
634 if (optlen < sizeof(int))
636 if (val && val < IPV6_MIN_MTU)
642 if (optlen < sizeof(int))
644 np->recverr = valbool;
646 skb_queue_purge(&sk->sk_error_queue);
649 case IPV6_FLOWINFO_SEND:
650 if (optlen < sizeof(int))
652 np->sndflow = valbool;
655 case IPV6_FLOWLABEL_MGR:
656 retv = ipv6_flowlabel_opt(sk, optval, optlen);
658 case IPV6_IPSEC_POLICY:
659 case IPV6_XFRM_POLICY:
661 if (!capable(CAP_NET_ADMIN))
663 retv = xfrm_user_policy(sk, optname, optval, optlen);
666 case IPV6_ADDR_PREFERENCES:
668 unsigned int pref = 0;
669 unsigned int prefmask = ~0;
671 if (optlen < sizeof(int))
676 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
677 switch (val & (IPV6_PREFER_SRC_PUBLIC|
679 IPV6_PREFER_SRC_PUBTMP_DEFAULT)) {
680 case IPV6_PREFER_SRC_PUBLIC:
681 pref |= IPV6_PREFER_SRC_PUBLIC;
683 case IPV6_PREFER_SRC_TMP:
684 pref |= IPV6_PREFER_SRC_TMP;
686 case IPV6_PREFER_SRC_PUBTMP_DEFAULT:
689 goto pref_skip_pubtmp;
694 prefmask &= ~(IPV6_PREFER_SRC_PUBLIC|
695 IPV6_PREFER_SRC_TMP);
698 /* check HOME/COA conflicts */
699 switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) {
700 case IPV6_PREFER_SRC_HOME:
702 case IPV6_PREFER_SRC_COA:
703 pref |= IPV6_PREFER_SRC_COA;
710 prefmask &= ~IPV6_PREFER_SRC_COA;
713 /* check CGA/NONCGA conflicts */
714 switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) {
715 case IPV6_PREFER_SRC_CGA:
716 case IPV6_PREFER_SRC_NONCGA:
723 np->srcprefs = (np->srcprefs & prefmask) | pref;
739 int ipv6_setsockopt(struct sock *sk, int level, int optname,
740 char __user *optval, int optlen)
744 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
745 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
747 if (level != SOL_IPV6)
750 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
751 #ifdef CONFIG_NETFILTER
752 /* we need to exclude all possible ENOPROTOOPTs except default case */
753 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
754 optname != IPV6_XFRM_POLICY) {
756 err = nf_setsockopt(sk, PF_INET6, optname, optval,
764 EXPORT_SYMBOL(ipv6_setsockopt);
767 int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
768 char __user *optval, int optlen)
772 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
773 if (udp_prot.compat_setsockopt != NULL)
774 return udp_prot.compat_setsockopt(sk, level, optname,
776 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
779 if (level != SOL_IPV6)
782 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
783 #ifdef CONFIG_NETFILTER
784 /* we need to exclude all possible ENOPROTOOPTs except default case */
785 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
786 optname != IPV6_XFRM_POLICY) {
788 err = compat_nf_setsockopt(sk, PF_INET6, optname,
796 EXPORT_SYMBOL(compat_ipv6_setsockopt);
799 static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt,
800 int optname, char __user *optval, int len)
802 struct ipv6_opt_hdr *hdr;
811 case IPV6_RTHDRDSTOPTS:
815 hdr = (struct ipv6_opt_hdr *)opt->srcrt;
821 return -EINVAL; /* should not happen */
827 len = min_t(unsigned int, len, ipv6_optlen(hdr));
828 if (copy_to_user(optval, hdr, len))
830 return ipv6_optlen(hdr);
833 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
834 char __user *optval, int __user *optlen)
836 struct ipv6_pinfo *np = inet6_sk(sk);
840 if (ip6_mroute_opt(optname))
841 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
843 if (get_user(len, optlen))
847 if (sk->sk_protocol != IPPROTO_UDP &&
848 sk->sk_protocol != IPPROTO_UDPLITE &&
849 sk->sk_protocol != IPPROTO_TCP)
851 if (sk->sk_state != TCP_ESTABLISHED)
857 struct group_filter gsf;
860 if (len < GROUP_FILTER_SIZE(0))
862 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
865 err = ip6_mc_msfget(sk, &gsf,
866 (struct group_filter __user *)optval, optlen);
871 case IPV6_2292PKTOPTIONS:
876 if (sk->sk_type != SOCK_STREAM)
879 msg.msg_control = optval;
880 msg.msg_controllen = len;
884 skb = np->pktoptions;
886 atomic_inc(&skb->users);
890 int err = datagram_recv_ctl(sk, &msg, skb);
895 if (np->rxopt.bits.rxinfo) {
896 struct in6_pktinfo src_info;
897 src_info.ipi6_ifindex = np->mcast_oif;
898 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
899 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
901 if (np->rxopt.bits.rxhlim) {
902 int hlim = np->mcast_hops;
903 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
905 if (np->rxopt.bits.rxoinfo) {
906 struct in6_pktinfo src_info;
907 src_info.ipi6_ifindex = np->mcast_oif;
908 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
909 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
911 if (np->rxopt.bits.rxohlim) {
912 int hlim = np->mcast_hops;
913 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
916 len -= msg.msg_controllen;
917 return put_user(len, optlen);
921 struct dst_entry *dst;
924 dst = sk_dst_get(sk);
939 case IPV6_RECVPKTINFO:
940 val = np->rxopt.bits.rxinfo;
943 case IPV6_2292PKTINFO:
944 val = np->rxopt.bits.rxoinfo;
947 case IPV6_RECVHOPLIMIT:
948 val = np->rxopt.bits.rxhlim;
951 case IPV6_2292HOPLIMIT:
952 val = np->rxopt.bits.rxohlim;
956 val = np->rxopt.bits.srcrt;
960 val = np->rxopt.bits.osrcrt;
964 case IPV6_RTHDRDSTOPTS:
970 len = ipv6_getsockopt_sticky(sk, np->opt,
971 optname, optval, len);
973 return put_user(len, optlen);
976 case IPV6_RECVHOPOPTS:
977 val = np->rxopt.bits.hopopts;
980 case IPV6_2292HOPOPTS:
981 val = np->rxopt.bits.ohopopts;
984 case IPV6_RECVDSTOPTS:
985 val = np->rxopt.bits.dstopts;
988 case IPV6_2292DSTOPTS:
989 val = np->rxopt.bits.odstopts;
998 case IPV6_RECVTCLASS:
999 val = np->rxopt.bits.rxtclass;
1003 val = np->rxopt.bits.rxflow;
1006 case IPV6_UNICAST_HOPS:
1007 case IPV6_MULTICAST_HOPS:
1009 struct dst_entry *dst;
1011 if (optname == IPV6_UNICAST_HOPS)
1012 val = np->hop_limit;
1014 val = np->mcast_hops;
1016 dst = sk_dst_get(sk);
1019 val = ip6_dst_hoplimit(dst);
1023 val = ipv6_devconf.hop_limit;
1027 case IPV6_MULTICAST_LOOP:
1031 case IPV6_MULTICAST_IF:
1032 val = np->mcast_oif;
1035 case IPV6_MTU_DISCOVER:
1043 case IPV6_FLOWINFO_SEND:
1047 case IPV6_ADDR_PREFERENCES:
1050 if (np->srcprefs & IPV6_PREFER_SRC_TMP)
1051 val |= IPV6_PREFER_SRC_TMP;
1052 else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC)
1053 val |= IPV6_PREFER_SRC_PUBLIC;
1055 /* XXX: should we return system default? */
1056 val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT;
1059 if (np->srcprefs & IPV6_PREFER_SRC_COA)
1060 val |= IPV6_PREFER_SRC_COA;
1062 val |= IPV6_PREFER_SRC_HOME;
1066 return -ENOPROTOOPT;
1068 len = min_t(unsigned int, sizeof(int), len);
1069 if(put_user(len, optlen))
1071 if(copy_to_user(optval,&val,len))
1076 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1077 char __user *optval, int __user *optlen)
1081 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1082 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1084 if(level != SOL_IPV6)
1085 return -ENOPROTOOPT;
1087 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1088 #ifdef CONFIG_NETFILTER
1089 /* we need to exclude all possible ENOPROTOOPTs except default case */
1090 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1093 if (get_user(len, optlen))
1097 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1101 err = put_user(len, optlen);
1107 EXPORT_SYMBOL(ipv6_getsockopt);
1109 #ifdef CONFIG_COMPAT
1110 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1111 char __user *optval, int __user *optlen)
1115 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1116 if (udp_prot.compat_getsockopt != NULL)
1117 return udp_prot.compat_getsockopt(sk, level, optname,
1119 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1122 if (level != SOL_IPV6)
1123 return -ENOPROTOOPT;
1125 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1126 #ifdef CONFIG_NETFILTER
1127 /* we need to exclude all possible ENOPROTOOPTs except default case */
1128 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1131 if (get_user(len, optlen))
1135 err = compat_nf_getsockopt(sk, PF_INET6,
1136 optname, optval, &len);
1139 err = put_user(len, optlen);
1145 EXPORT_SYMBOL(compat_ipv6_getsockopt);