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 Return -EINVAL for setsockopt of short lengths
20 * o Truncate getsockopt returns
21 * o Return an optlen of the truncated length if need be
24 * David L Stevens <dlstevens@us.ibm.com>:
25 * - added multicast source filtering API for MLDv2
28 #include <linux/module.h>
29 #include <linux/capability.h>
30 #include <linux/errno.h>
31 #include <linux/types.h>
32 #include <linux/socket.h>
33 #include <linux/sockios.h>
34 #include <linux/net.h>
35 #include <linux/in6.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 static struct inet6_protocol *ipv6_gso_pull_exthdrs(struct sk_buff *skb,
63 struct inet6_protocol *ops = NULL;
66 struct ipv6_opt_hdr *opth;
69 if (proto != NEXTHDR_HOP) {
70 ops = rcu_dereference(inet6_protos[proto]);
75 if (!(ops->flags & INET6_PROTO_GSO_EXTHDR))
79 if (unlikely(!pskb_may_pull(skb, 8)))
82 opth = (void *)skb->data;
83 len = opth->hdrlen * 8 + 8;
85 if (unlikely(!pskb_may_pull(skb, len)))
88 proto = opth->nexthdr;
95 static int ipv6_gso_send_check(struct sk_buff *skb)
97 struct ipv6hdr *ipv6h;
98 struct inet6_protocol *ops;
101 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
104 ipv6h = skb->nh.ipv6h;
105 __skb_pull(skb, sizeof(*ipv6h));
106 err = -EPROTONOSUPPORT;
109 ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
110 if (likely(ops && ops->gso_send_check)) {
111 skb->h.raw = skb->data;
112 err = ops->gso_send_check(skb);
120 static struct sk_buff *ipv6_gso_segment(struct sk_buff *skb, int features)
122 struct sk_buff *segs = ERR_PTR(-EINVAL);
123 struct ipv6hdr *ipv6h;
124 struct inet6_protocol *ops;
126 if (!(features & NETIF_F_HW_CSUM))
127 features &= ~NETIF_F_SG;
129 if (unlikely(skb_shinfo(skb)->gso_type &
137 if (unlikely(!pskb_may_pull(skb, sizeof(*ipv6h))))
140 ipv6h = skb->nh.ipv6h;
141 __skb_pull(skb, sizeof(*ipv6h));
142 segs = ERR_PTR(-EPROTONOSUPPORT);
145 ops = ipv6_gso_pull_exthdrs(skb, ipv6h->nexthdr);
146 if (likely(ops && ops->gso_segment)) {
147 skb->h.raw = skb->data;
148 segs = ops->gso_segment(skb, features);
152 if (unlikely(IS_ERR(segs)))
155 for (skb = segs; skb; skb = skb->next) {
156 ipv6h = skb->nh.ipv6h;
157 ipv6h->payload_len = htons(skb->len - skb->mac_len -
165 static struct packet_type ipv6_packet_type = {
166 .type = __constant_htons(ETH_P_IPV6),
168 .gso_send_check = ipv6_gso_send_check,
169 .gso_segment = ipv6_gso_segment,
172 struct ip6_ra_chain *ip6_ra_chain;
173 DEFINE_RWLOCK(ip6_ra_lock);
175 int ip6_ra_control(struct sock *sk, int sel, void (*destructor)(struct sock *))
177 struct ip6_ra_chain *ra, *new_ra, **rap;
179 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
180 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->num != IPPROTO_RAW)
183 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
185 write_lock_bh(&ip6_ra_lock);
186 for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
189 write_unlock_bh(&ip6_ra_lock);
195 write_unlock_bh(&ip6_ra_lock);
204 if (new_ra == NULL) {
205 write_unlock_bh(&ip6_ra_lock);
210 new_ra->destructor = destructor;
214 write_unlock_bh(&ip6_ra_lock);
218 static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
219 char __user *optval, int optlen)
221 struct ipv6_pinfo *np = inet6_sk(sk);
223 int retv = -ENOPROTOOPT;
227 else if (get_user(val, (int __user *) optval))
237 if (val == PF_INET) {
238 struct ipv6_txoptions *opt;
239 struct sk_buff *pktopt;
241 if (sk->sk_protocol != IPPROTO_UDP &&
242 sk->sk_protocol != IPPROTO_UDPLITE &&
243 sk->sk_protocol != IPPROTO_TCP)
246 if (sk->sk_state != TCP_ESTABLISHED) {
251 if (ipv6_only_sock(sk) ||
252 !(ipv6_addr_type(&np->daddr) & IPV6_ADDR_MAPPED)) {
253 retv = -EADDRNOTAVAIL;
257 fl6_free_socklist(sk);
258 ipv6_sock_mc_close(sk);
261 * Sock is moving from IPv6 to IPv4 (sk_prot), so
262 * remove it from the refcnt debug socks count in the
265 sk_refcnt_debug_dec(sk);
267 if (sk->sk_protocol == IPPROTO_TCP) {
268 struct inet_connection_sock *icsk = inet_csk(sk);
271 sock_prot_dec_use(sk->sk_prot);
272 sock_prot_inc_use(&tcp_prot);
274 sk->sk_prot = &tcp_prot;
275 icsk->icsk_af_ops = &ipv4_specific;
276 sk->sk_socket->ops = &inet_stream_ops;
277 sk->sk_family = PF_INET;
278 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
280 struct proto *prot = &udp_prot;
282 if (sk->sk_protocol == IPPROTO_UDPLITE)
283 prot = &udplite_prot;
285 sock_prot_dec_use(sk->sk_prot);
286 sock_prot_inc_use(prot);
289 sk->sk_socket->ops = &inet_dgram_ops;
290 sk->sk_family = PF_INET;
292 opt = xchg(&np->opt, NULL);
294 sock_kfree_s(sk, opt, opt->tot_len);
295 pktopt = xchg(&np->pktoptions, NULL);
299 sk->sk_destruct = inet_sock_destruct;
301 * ... and add it to the refcnt debug socks count
302 * in the new family. -acme
304 sk_refcnt_debug_inc(sk);
305 module_put(THIS_MODULE);
312 if (inet_sk(sk)->num)
314 np->ipv6only = valbool;
318 case IPV6_RECVPKTINFO:
319 np->rxopt.bits.rxinfo = valbool;
323 case IPV6_2292PKTINFO:
324 np->rxopt.bits.rxoinfo = valbool;
328 case IPV6_RECVHOPLIMIT:
329 np->rxopt.bits.rxhlim = valbool;
333 case IPV6_2292HOPLIMIT:
334 np->rxopt.bits.rxohlim = valbool;
339 if (val < 0 || val > 2)
341 np->rxopt.bits.srcrt = val;
346 if (val < 0 || val > 2)
348 np->rxopt.bits.osrcrt = val;
352 case IPV6_RECVHOPOPTS:
353 np->rxopt.bits.hopopts = valbool;
357 case IPV6_2292HOPOPTS:
358 np->rxopt.bits.ohopopts = valbool;
362 case IPV6_RECVDSTOPTS:
363 np->rxopt.bits.dstopts = valbool;
367 case IPV6_2292DSTOPTS:
368 np->rxopt.bits.odstopts = valbool;
373 if (val < -1 || val > 0xff)
379 case IPV6_RECVTCLASS:
380 np->rxopt.bits.rxtclass = valbool;
385 np->rxopt.bits.rxflow = valbool;
390 case IPV6_RTHDRDSTOPTS:
394 struct ipv6_txoptions *opt;
398 /* hop-by-hop / destination options are privileged option */
400 if (optname != IPV6_RTHDR && !capable(CAP_NET_RAW))
404 if (optlen & 0x7 || optlen > 8 * 255)
407 opt = ipv6_renew_options(sk, np->opt, optname,
408 (struct ipv6_opt_hdr __user *)optval,
415 /* routing header option needs extra check */
416 if (optname == IPV6_RTHDR && opt && opt->srcrt) {
417 struct ipv6_rt_hdr *rthdr = opt->srcrt;
418 switch (rthdr->type) {
419 case IPV6_SRCRT_TYPE_0:
420 #ifdef CONFIG_IPV6_MIP6
421 case IPV6_SRCRT_TYPE_2:
428 if ((rthdr->hdrlen & 1) ||
429 (rthdr->hdrlen >> 1) != rthdr->segments_left)
434 if (inet_sk(sk)->is_icsk) {
436 struct inet_connection_sock *icsk = inet_csk(sk);
437 if (!((1 << sk->sk_state) &
438 (TCPF_LISTEN | TCPF_CLOSE))
439 && inet_sk(sk)->daddr != LOOPBACK4_IPV6) {
440 icsk->icsk_ext_hdr_len =
441 opt->opt_flen + opt->opt_nflen;
442 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
445 opt = xchg(&np->opt, opt);
448 write_lock(&sk->sk_dst_lock);
449 opt = xchg(&np->opt, opt);
450 write_unlock(&sk->sk_dst_lock);
455 sock_kfree_s(sk, opt, opt->tot_len);
459 case IPV6_2292PKTOPTIONS:
461 struct ipv6_txoptions *opt = NULL;
466 fl.fl6_flowlabel = 0;
467 fl.oif = sk->sk_bound_dev_if;
472 /* 1K is probably excessive
473 * 1K is surely not enough, 2K per standard header is 16K.
476 if (optlen > 64*1024)
479 opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL);
484 memset(opt, 0, sizeof(*opt));
485 opt->tot_len = sizeof(*opt) + optlen;
487 if (copy_from_user(opt+1, optval, optlen))
490 msg.msg_controllen = optlen;
491 msg.msg_control = (void*)(opt+1);
493 retv = datagram_send_ctl(&msg, &fl, opt, &junk, &junk);
498 if (inet_sk(sk)->is_icsk) {
500 struct inet_connection_sock *icsk = inet_csk(sk);
501 if (!((1 << sk->sk_state) &
502 (TCPF_LISTEN | TCPF_CLOSE))
503 && inet_sk(sk)->daddr != LOOPBACK4_IPV6) {
504 icsk->icsk_ext_hdr_len =
505 opt->opt_flen + opt->opt_nflen;
506 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
509 opt = xchg(&np->opt, opt);
512 write_lock(&sk->sk_dst_lock);
513 opt = xchg(&np->opt, opt);
514 write_unlock(&sk->sk_dst_lock);
520 sock_kfree_s(sk, opt, opt->tot_len);
523 case IPV6_UNICAST_HOPS:
524 if (val > 255 || val < -1)
530 case IPV6_MULTICAST_HOPS:
531 if (sk->sk_type == SOCK_STREAM)
533 if (val > 255 || val < -1)
535 np->mcast_hops = val;
539 case IPV6_MULTICAST_LOOP:
540 np->mc_loop = valbool;
544 case IPV6_MULTICAST_IF:
545 if (sk->sk_type == SOCK_STREAM)
547 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
550 if (__dev_get_by_index(val) == NULL) {
557 case IPV6_ADD_MEMBERSHIP:
558 case IPV6_DROP_MEMBERSHIP:
560 struct ipv6_mreq mreq;
563 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
566 if (optname == IPV6_ADD_MEMBERSHIP)
567 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
569 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
572 case IPV6_JOIN_ANYCAST:
573 case IPV6_LEAVE_ANYCAST:
575 struct ipv6_mreq mreq;
577 if (optlen != sizeof(struct ipv6_mreq))
581 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
584 if (optname == IPV6_JOIN_ANYCAST)
585 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
587 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
590 case MCAST_JOIN_GROUP:
591 case MCAST_LEAVE_GROUP:
593 struct group_req greq;
594 struct sockaddr_in6 *psin6;
597 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
599 if (greq.gr_group.ss_family != AF_INET6) {
600 retv = -EADDRNOTAVAIL;
603 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
604 if (optname == MCAST_JOIN_GROUP)
605 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
608 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
612 case MCAST_JOIN_SOURCE_GROUP:
613 case MCAST_LEAVE_SOURCE_GROUP:
614 case MCAST_BLOCK_SOURCE:
615 case MCAST_UNBLOCK_SOURCE:
617 struct group_source_req greqs;
620 if (optlen != sizeof(struct group_source_req))
622 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
626 if (greqs.gsr_group.ss_family != AF_INET6 ||
627 greqs.gsr_source.ss_family != AF_INET6) {
628 retv = -EADDRNOTAVAIL;
631 if (optname == MCAST_BLOCK_SOURCE) {
632 omode = MCAST_EXCLUDE;
634 } else if (optname == MCAST_UNBLOCK_SOURCE) {
635 omode = MCAST_EXCLUDE;
637 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
638 struct sockaddr_in6 *psin6;
640 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
641 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
643 /* prior join w/ different source is ok */
644 if (retv && retv != -EADDRINUSE)
646 omode = MCAST_INCLUDE;
648 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
649 omode = MCAST_INCLUDE;
652 retv = ip6_mc_source(add, omode, sk, &greqs);
657 extern int sysctl_mld_max_msf;
658 struct group_filter *gsf;
660 if (optlen < GROUP_FILTER_SIZE(0))
662 if (optlen > sysctl_optmem_max) {
666 gsf = kmalloc(optlen,GFP_KERNEL);
672 if (copy_from_user(gsf, optval, optlen)) {
676 /* numsrc >= (4G-140)/128 overflow in 32 bits */
677 if (gsf->gf_numsrc >= 0x1ffffffU ||
678 gsf->gf_numsrc > sysctl_mld_max_msf) {
683 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
688 retv = ip6_mc_msfilter(sk, gsf);
693 case IPV6_ROUTER_ALERT:
694 retv = ip6_ra_control(sk, val, NULL);
696 case IPV6_MTU_DISCOVER:
703 if (val && val < IPV6_MIN_MTU)
709 np->recverr = valbool;
711 skb_queue_purge(&sk->sk_error_queue);
714 case IPV6_FLOWINFO_SEND:
715 np->sndflow = valbool;
718 case IPV6_FLOWLABEL_MGR:
719 retv = ipv6_flowlabel_opt(sk, optval, optlen);
721 case IPV6_IPSEC_POLICY:
722 case IPV6_XFRM_POLICY:
724 if (!capable(CAP_NET_ADMIN))
726 retv = xfrm_user_policy(sk, optname, optval, optlen);
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 char __user *optval, int len)
802 struct ipv6_opt_hdr *hdr;
804 if (!opt || !opt->hopopt)
808 len = min_t(unsigned int, len, ipv6_optlen(hdr));
809 if (copy_to_user(optval, hdr, ipv6_optlen(hdr)))
814 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
815 char __user *optval, int __user *optlen)
817 struct ipv6_pinfo *np = inet6_sk(sk);
821 if (get_user(len, optlen))
825 if (sk->sk_protocol != IPPROTO_UDP &&
826 sk->sk_protocol != IPPROTO_UDPLITE &&
827 sk->sk_protocol != IPPROTO_TCP)
829 if (sk->sk_state != TCP_ESTABLISHED)
835 struct group_filter gsf;
838 if (len < GROUP_FILTER_SIZE(0))
840 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
843 err = ip6_mc_msfget(sk, &gsf,
844 (struct group_filter __user *)optval, optlen);
849 case IPV6_2292PKTOPTIONS:
854 if (sk->sk_type != SOCK_STREAM)
857 msg.msg_control = optval;
858 msg.msg_controllen = len;
862 skb = np->pktoptions;
864 atomic_inc(&skb->users);
868 int err = datagram_recv_ctl(sk, &msg, skb);
873 if (np->rxopt.bits.rxinfo) {
874 struct in6_pktinfo src_info;
875 src_info.ipi6_ifindex = np->mcast_oif;
876 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
877 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
879 if (np->rxopt.bits.rxhlim) {
880 int hlim = np->mcast_hops;
881 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
883 if (np->rxopt.bits.rxoinfo) {
884 struct in6_pktinfo src_info;
885 src_info.ipi6_ifindex = np->mcast_oif;
886 ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr);
887 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
889 if (np->rxopt.bits.rxohlim) {
890 int hlim = np->mcast_hops;
891 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
894 len -= msg.msg_controllen;
895 return put_user(len, optlen);
899 struct dst_entry *dst;
902 dst = sk_dst_get(sk);
917 case IPV6_RECVPKTINFO:
918 val = np->rxopt.bits.rxinfo;
921 case IPV6_2292PKTINFO:
922 val = np->rxopt.bits.rxoinfo;
925 case IPV6_RECVHOPLIMIT:
926 val = np->rxopt.bits.rxhlim;
929 case IPV6_2292HOPLIMIT:
930 val = np->rxopt.bits.rxohlim;
934 val = np->rxopt.bits.srcrt;
938 val = np->rxopt.bits.osrcrt;
942 case IPV6_RTHDRDSTOPTS:
948 len = ipv6_getsockopt_sticky(sk, np->opt,
951 return put_user(len, optlen);
954 case IPV6_RECVHOPOPTS:
955 val = np->rxopt.bits.hopopts;
958 case IPV6_2292HOPOPTS:
959 val = np->rxopt.bits.ohopopts;
962 case IPV6_RECVDSTOPTS:
963 val = np->rxopt.bits.dstopts;
966 case IPV6_2292DSTOPTS:
967 val = np->rxopt.bits.odstopts;
976 case IPV6_RECVTCLASS:
977 val = np->rxopt.bits.rxtclass;
981 val = np->rxopt.bits.rxflow;
984 case IPV6_UNICAST_HOPS:
985 case IPV6_MULTICAST_HOPS:
987 struct dst_entry *dst;
989 if (optname == IPV6_UNICAST_HOPS)
992 val = np->mcast_hops;
994 dst = sk_dst_get(sk);
997 val = dst_metric(dst, RTAX_HOPLIMIT);
999 val = ipv6_get_hoplimit(dst->dev);
1003 val = ipv6_devconf.hop_limit;
1007 case IPV6_MULTICAST_LOOP:
1011 case IPV6_MULTICAST_IF:
1012 val = np->mcast_oif;
1015 case IPV6_MTU_DISCOVER:
1023 case IPV6_FLOWINFO_SEND:
1030 len = min_t(unsigned int, sizeof(int), len);
1031 if(put_user(len, optlen))
1033 if(copy_to_user(optval,&val,len))
1038 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1039 char __user *optval, int __user *optlen)
1043 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1044 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1046 if(level != SOL_IPV6)
1047 return -ENOPROTOOPT;
1049 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1050 #ifdef CONFIG_NETFILTER
1051 /* we need to exclude all possible EINVALs except default case */
1052 if (err == -EINVAL && optname != IPV6_ADDRFORM &&
1053 optname != MCAST_MSFILTER) {
1056 if (get_user(len, optlen))
1060 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1064 err = put_user(len, optlen);
1070 EXPORT_SYMBOL(ipv6_getsockopt);
1072 #ifdef CONFIG_COMPAT
1073 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1074 char __user *optval, int __user *optlen)
1078 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1079 if (udp_prot.compat_getsockopt != NULL)
1080 return udp_prot.compat_getsockopt(sk, level, optname,
1082 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1085 if (level != SOL_IPV6)
1086 return -ENOPROTOOPT;
1088 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1089 #ifdef CONFIG_NETFILTER
1090 /* we need to exclude all possible EINVALs except default case */
1091 if (err == -EINVAL && optname != IPV6_ADDRFORM &&
1092 optname != MCAST_MSFILTER) {
1095 if (get_user(len, optlen))
1099 err = compat_nf_getsockopt(sk, PF_INET6,
1100 optname, optval, &len);
1103 err = put_user(len, optlen);
1109 EXPORT_SYMBOL(compat_ipv6_getsockopt);
1112 void __init ipv6_packet_init(void)
1114 dev_add_pack(&ipv6_packet_type);
1117 void ipv6_packet_cleanup(void)
1119 dev_remove_pack(&ipv6_packet_type);