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/sched.h>
35 #include <linux/net.h>
36 #include <linux/in6.h>
37 #include <linux/netdevice.h>
38 #include <linux/if_arp.h>
39 #include <linux/init.h>
40 #include <linux/sysctl.h>
41 #include <linux/netfilter.h>
46 #include <net/ndisc.h>
47 #include <net/protocol.h>
48 #include <net/transp_v6.h>
49 #include <net/ip6_route.h>
50 #include <net/addrconf.h>
51 #include <net/inet_common.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 (unlikely(skb_shinfo(skb
)->gso_type
&
134 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
137 ipv6h
= skb
->nh
.ipv6h
;
138 __skb_pull(skb
, sizeof(*ipv6h
));
139 segs
= ERR_PTR(-EPROTONOSUPPORT
);
142 ops
= ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
);
143 if (likely(ops
&& ops
->gso_segment
)) {
144 skb
->h
.raw
= skb
->data
;
145 segs
= ops
->gso_segment(skb
, features
);
149 if (unlikely(IS_ERR(segs
)))
152 for (skb
= segs
; skb
; skb
= skb
->next
) {
153 ipv6h
= skb
->nh
.ipv6h
;
154 ipv6h
->payload_len
= htons(skb
->len
- skb
->mac_len
-
162 static struct packet_type ipv6_packet_type
= {
163 .type
= __constant_htons(ETH_P_IPV6
),
165 .gso_send_check
= ipv6_gso_send_check
,
166 .gso_segment
= ipv6_gso_segment
,
169 struct ip6_ra_chain
*ip6_ra_chain
;
170 DEFINE_RWLOCK(ip6_ra_lock
);
172 int ip6_ra_control(struct sock
*sk
, int sel
, void (*destructor
)(struct sock
*))
174 struct ip6_ra_chain
*ra
, *new_ra
, **rap
;
176 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
177 if (sk
->sk_type
!= SOCK_RAW
|| inet_sk(sk
)->num
!= IPPROTO_RAW
)
180 new_ra
= (sel
>=0) ? kmalloc(sizeof(*new_ra
), GFP_KERNEL
) : NULL
;
182 write_lock_bh(&ip6_ra_lock
);
183 for (rap
= &ip6_ra_chain
; (ra
=*rap
) != NULL
; rap
= &ra
->next
) {
186 write_unlock_bh(&ip6_ra_lock
);
192 write_unlock_bh(&ip6_ra_lock
);
201 if (new_ra
== NULL
) {
202 write_unlock_bh(&ip6_ra_lock
);
207 new_ra
->destructor
= destructor
;
211 write_unlock_bh(&ip6_ra_lock
);
215 static int do_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
216 char __user
*optval
, int optlen
)
218 struct ipv6_pinfo
*np
= inet6_sk(sk
);
220 int retv
= -ENOPROTOOPT
;
224 else if (get_user(val
, (int __user
*) optval
))
234 if (val
== PF_INET
) {
235 struct ipv6_txoptions
*opt
;
236 struct sk_buff
*pktopt
;
238 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
239 sk
->sk_protocol
!= IPPROTO_TCP
)
242 if (sk
->sk_state
!= TCP_ESTABLISHED
) {
247 if (ipv6_only_sock(sk
) ||
248 !(ipv6_addr_type(&np
->daddr
) & IPV6_ADDR_MAPPED
)) {
249 retv
= -EADDRNOTAVAIL
;
253 fl6_free_socklist(sk
);
254 ipv6_sock_mc_close(sk
);
257 * Sock is moving from IPv6 to IPv4 (sk_prot), so
258 * remove it from the refcnt debug socks count in the
261 sk_refcnt_debug_dec(sk
);
263 if (sk
->sk_protocol
== IPPROTO_TCP
) {
264 struct inet_connection_sock
*icsk
= inet_csk(sk
);
267 sock_prot_dec_use(sk
->sk_prot
);
268 sock_prot_inc_use(&tcp_prot
);
270 sk
->sk_prot
= &tcp_prot
;
271 icsk
->icsk_af_ops
= &ipv4_specific
;
272 sk
->sk_socket
->ops
= &inet_stream_ops
;
273 sk
->sk_family
= PF_INET
;
274 tcp_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
277 sock_prot_dec_use(sk
->sk_prot
);
278 sock_prot_inc_use(&udp_prot
);
280 sk
->sk_prot
= &udp_prot
;
281 sk
->sk_socket
->ops
= &inet_dgram_ops
;
282 sk
->sk_family
= PF_INET
;
284 opt
= xchg(&np
->opt
, NULL
);
286 sock_kfree_s(sk
, opt
, opt
->tot_len
);
287 pktopt
= xchg(&np
->pktoptions
, NULL
);
291 sk
->sk_destruct
= inet_sock_destruct
;
293 * ... and add it to the refcnt debug socks count
294 * in the new family. -acme
296 sk_refcnt_debug_inc(sk
);
297 module_put(THIS_MODULE
);
304 if (inet_sk(sk
)->num
)
306 np
->ipv6only
= valbool
;
310 case IPV6_RECVPKTINFO
:
311 np
->rxopt
.bits
.rxinfo
= valbool
;
315 case IPV6_2292PKTINFO
:
316 np
->rxopt
.bits
.rxoinfo
= valbool
;
320 case IPV6_RECVHOPLIMIT
:
321 np
->rxopt
.bits
.rxhlim
= valbool
;
325 case IPV6_2292HOPLIMIT
:
326 np
->rxopt
.bits
.rxohlim
= valbool
;
331 if (val
< 0 || val
> 2)
333 np
->rxopt
.bits
.srcrt
= val
;
338 if (val
< 0 || val
> 2)
340 np
->rxopt
.bits
.osrcrt
= val
;
344 case IPV6_RECVHOPOPTS
:
345 np
->rxopt
.bits
.hopopts
= valbool
;
349 case IPV6_2292HOPOPTS
:
350 np
->rxopt
.bits
.ohopopts
= valbool
;
354 case IPV6_RECVDSTOPTS
:
355 np
->rxopt
.bits
.dstopts
= valbool
;
359 case IPV6_2292DSTOPTS
:
360 np
->rxopt
.bits
.odstopts
= valbool
;
365 if (val
< -1 || val
> 0xff)
371 case IPV6_RECVTCLASS
:
372 np
->rxopt
.bits
.rxtclass
= valbool
;
377 np
->rxopt
.bits
.rxflow
= valbool
;
382 case IPV6_RTHDRDSTOPTS
:
386 struct ipv6_txoptions
*opt
;
390 /* hop-by-hop / destination options are privileged option */
392 if (optname
!= IPV6_RTHDR
&& !capable(CAP_NET_RAW
))
396 if (optlen
& 0x7 || optlen
> 8 * 255)
399 opt
= ipv6_renew_options(sk
, np
->opt
, optname
,
400 (struct ipv6_opt_hdr __user
*)optval
,
407 /* routing header option needs extra check */
408 if (optname
== IPV6_RTHDR
&& opt
->srcrt
) {
409 struct ipv6_rt_hdr
*rthdr
= opt
->srcrt
;
410 switch (rthdr
->type
) {
411 case IPV6_SRCRT_TYPE_0
:
412 #ifdef CONFIG_IPV6_MIP6
413 case IPV6_SRCRT_TYPE_2
:
420 if ((rthdr
->hdrlen
& 1) ||
421 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
426 if (inet_sk(sk
)->is_icsk
) {
428 struct inet_connection_sock
*icsk
= inet_csk(sk
);
429 if (!((1 << sk
->sk_state
) &
430 (TCPF_LISTEN
| TCPF_CLOSE
))
431 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
432 icsk
->icsk_ext_hdr_len
=
433 opt
->opt_flen
+ opt
->opt_nflen
;
434 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
437 opt
= xchg(&np
->opt
, opt
);
440 write_lock(&sk
->sk_dst_lock
);
441 opt
= xchg(&np
->opt
, opt
);
442 write_unlock(&sk
->sk_dst_lock
);
447 sock_kfree_s(sk
, opt
, opt
->tot_len
);
451 case IPV6_2292PKTOPTIONS
:
453 struct ipv6_txoptions
*opt
= NULL
;
458 fl
.fl6_flowlabel
= 0;
459 fl
.oif
= sk
->sk_bound_dev_if
;
464 /* 1K is probably excessive
465 * 1K is surely not enough, 2K per standard header is 16K.
468 if (optlen
> 64*1024)
471 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
476 memset(opt
, 0, sizeof(*opt
));
477 opt
->tot_len
= sizeof(*opt
) + optlen
;
479 if (copy_from_user(opt
+1, optval
, optlen
))
482 msg
.msg_controllen
= optlen
;
483 msg
.msg_control
= (void*)(opt
+1);
485 retv
= datagram_send_ctl(&msg
, &fl
, opt
, &junk
, &junk
);
490 if (inet_sk(sk
)->is_icsk
) {
492 struct inet_connection_sock
*icsk
= inet_csk(sk
);
493 if (!((1 << sk
->sk_state
) &
494 (TCPF_LISTEN
| TCPF_CLOSE
))
495 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
496 icsk
->icsk_ext_hdr_len
=
497 opt
->opt_flen
+ opt
->opt_nflen
;
498 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
501 opt
= xchg(&np
->opt
, opt
);
504 write_lock(&sk
->sk_dst_lock
);
505 opt
= xchg(&np
->opt
, opt
);
506 write_unlock(&sk
->sk_dst_lock
);
512 sock_kfree_s(sk
, opt
, opt
->tot_len
);
515 case IPV6_UNICAST_HOPS
:
516 if (val
> 255 || val
< -1)
522 case IPV6_MULTICAST_HOPS
:
523 if (sk
->sk_type
== SOCK_STREAM
)
525 if (val
> 255 || val
< -1)
527 np
->mcast_hops
= val
;
531 case IPV6_MULTICAST_LOOP
:
532 np
->mc_loop
= valbool
;
536 case IPV6_MULTICAST_IF
:
537 if (sk
->sk_type
== SOCK_STREAM
)
539 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
542 if (__dev_get_by_index(val
) == NULL
) {
549 case IPV6_ADD_MEMBERSHIP
:
550 case IPV6_DROP_MEMBERSHIP
:
552 struct ipv6_mreq mreq
;
555 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
558 if (optname
== IPV6_ADD_MEMBERSHIP
)
559 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
561 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
564 case IPV6_JOIN_ANYCAST
:
565 case IPV6_LEAVE_ANYCAST
:
567 struct ipv6_mreq mreq
;
569 if (optlen
!= sizeof(struct ipv6_mreq
))
573 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
576 if (optname
== IPV6_JOIN_ANYCAST
)
577 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
579 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
582 case MCAST_JOIN_GROUP
:
583 case MCAST_LEAVE_GROUP
:
585 struct group_req greq
;
586 struct sockaddr_in6
*psin6
;
589 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
591 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
592 retv
= -EADDRNOTAVAIL
;
595 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
596 if (optname
== MCAST_JOIN_GROUP
)
597 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
600 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
604 case MCAST_JOIN_SOURCE_GROUP
:
605 case MCAST_LEAVE_SOURCE_GROUP
:
606 case MCAST_BLOCK_SOURCE
:
607 case MCAST_UNBLOCK_SOURCE
:
609 struct group_source_req greqs
;
612 if (optlen
!= sizeof(struct group_source_req
))
614 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
618 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
619 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
620 retv
= -EADDRNOTAVAIL
;
623 if (optname
== MCAST_BLOCK_SOURCE
) {
624 omode
= MCAST_EXCLUDE
;
626 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
627 omode
= MCAST_EXCLUDE
;
629 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
630 struct sockaddr_in6
*psin6
;
632 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
633 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
635 /* prior join w/ different source is ok */
636 if (retv
&& retv
!= -EADDRINUSE
)
638 omode
= MCAST_INCLUDE
;
640 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
641 omode
= MCAST_INCLUDE
;
644 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
649 extern int sysctl_mld_max_msf
;
650 struct group_filter
*gsf
;
652 if (optlen
< GROUP_FILTER_SIZE(0))
654 if (optlen
> sysctl_optmem_max
) {
658 gsf
= kmalloc(optlen
,GFP_KERNEL
);
664 if (copy_from_user(gsf
, optval
, optlen
)) {
668 /* numsrc >= (4G-140)/128 overflow in 32 bits */
669 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
670 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
675 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
680 retv
= ip6_mc_msfilter(sk
, gsf
);
685 case IPV6_ROUTER_ALERT
:
686 retv
= ip6_ra_control(sk
, val
, NULL
);
688 case IPV6_MTU_DISCOVER
:
695 if (val
&& val
< IPV6_MIN_MTU
)
701 np
->recverr
= valbool
;
703 skb_queue_purge(&sk
->sk_error_queue
);
706 case IPV6_FLOWINFO_SEND
:
707 np
->sndflow
= valbool
;
710 case IPV6_FLOWLABEL_MGR
:
711 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
713 case IPV6_IPSEC_POLICY
:
714 case IPV6_XFRM_POLICY
:
716 if (!capable(CAP_NET_ADMIN
))
718 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
731 int ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
732 char __user
*optval
, int optlen
)
736 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
737 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
739 if (level
!= SOL_IPV6
)
742 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
743 #ifdef CONFIG_NETFILTER
744 /* we need to exclude all possible ENOPROTOOPTs except default case */
745 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
746 optname
!= IPV6_XFRM_POLICY
) {
748 err
= nf_setsockopt(sk
, PF_INET6
, optname
, optval
,
758 int compat_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
759 char __user
*optval
, int optlen
)
763 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
764 if (udp_prot
.compat_setsockopt
!= NULL
)
765 return udp_prot
.compat_setsockopt(sk
, level
, optname
,
767 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
770 if (level
!= SOL_IPV6
)
773 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
774 #ifdef CONFIG_NETFILTER
775 /* we need to exclude all possible ENOPROTOOPTs except default case */
776 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
777 optname
!= IPV6_XFRM_POLICY
) {
779 err
= compat_nf_setsockopt(sk
, PF_INET6
, optname
,
787 EXPORT_SYMBOL(compat_ipv6_setsockopt
);
790 static int ipv6_getsockopt_sticky(struct sock
*sk
, struct ipv6_opt_hdr
*hdr
,
791 char __user
*optval
, int len
)
795 len
= min_t(int, len
, ipv6_optlen(hdr
));
796 if (copy_to_user(optval
, hdr
, ipv6_optlen(hdr
)))
801 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
802 char __user
*optval
, int __user
*optlen
)
804 struct ipv6_pinfo
*np
= inet6_sk(sk
);
808 if (get_user(len
, optlen
))
812 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
813 sk
->sk_protocol
!= IPPROTO_TCP
)
815 if (sk
->sk_state
!= TCP_ESTABLISHED
)
821 struct group_filter gsf
;
824 if (len
< GROUP_FILTER_SIZE(0))
826 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
829 err
= ip6_mc_msfget(sk
, &gsf
,
830 (struct group_filter __user
*)optval
, optlen
);
835 case IPV6_2292PKTOPTIONS
:
840 if (sk
->sk_type
!= SOCK_STREAM
)
843 msg
.msg_control
= optval
;
844 msg
.msg_controllen
= len
;
848 skb
= np
->pktoptions
;
850 atomic_inc(&skb
->users
);
854 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
859 if (np
->rxopt
.bits
.rxinfo
) {
860 struct in6_pktinfo src_info
;
861 src_info
.ipi6_ifindex
= np
->mcast_oif
;
862 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
863 put_cmsg(&msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
865 if (np
->rxopt
.bits
.rxhlim
) {
866 int hlim
= np
->mcast_hops
;
867 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
869 if (np
->rxopt
.bits
.rxoinfo
) {
870 struct in6_pktinfo src_info
;
871 src_info
.ipi6_ifindex
= np
->mcast_oif
;
872 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
873 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
875 if (np
->rxopt
.bits
.rxohlim
) {
876 int hlim
= np
->mcast_hops
;
877 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
880 len
-= msg
.msg_controllen
;
881 return put_user(len
, optlen
);
885 struct dst_entry
*dst
;
888 dst
= sk_dst_get(sk
);
903 case IPV6_RECVPKTINFO
:
904 val
= np
->rxopt
.bits
.rxinfo
;
907 case IPV6_2292PKTINFO
:
908 val
= np
->rxopt
.bits
.rxoinfo
;
911 case IPV6_RECVHOPLIMIT
:
912 val
= np
->rxopt
.bits
.rxhlim
;
915 case IPV6_2292HOPLIMIT
:
916 val
= np
->rxopt
.bits
.rxohlim
;
920 val
= np
->rxopt
.bits
.srcrt
;
924 val
= np
->rxopt
.bits
.osrcrt
;
928 case IPV6_RTHDRDSTOPTS
:
934 len
= ipv6_getsockopt_sticky(sk
, np
->opt
->hopopt
,
937 return put_user(len
, optlen
);
940 case IPV6_RECVHOPOPTS
:
941 val
= np
->rxopt
.bits
.hopopts
;
944 case IPV6_2292HOPOPTS
:
945 val
= np
->rxopt
.bits
.ohopopts
;
948 case IPV6_RECVDSTOPTS
:
949 val
= np
->rxopt
.bits
.dstopts
;
952 case IPV6_2292DSTOPTS
:
953 val
= np
->rxopt
.bits
.odstopts
;
962 case IPV6_RECVTCLASS
:
963 val
= np
->rxopt
.bits
.rxtclass
;
967 val
= np
->rxopt
.bits
.rxflow
;
970 case IPV6_UNICAST_HOPS
:
974 case IPV6_MULTICAST_HOPS
:
975 val
= np
->mcast_hops
;
978 case IPV6_MULTICAST_LOOP
:
982 case IPV6_MULTICAST_IF
:
986 case IPV6_MTU_DISCOVER
:
994 case IPV6_FLOWINFO_SEND
:
1001 len
= min_t(unsigned int, sizeof(int), len
);
1002 if(put_user(len
, optlen
))
1004 if(copy_to_user(optval
,&val
,len
))
1009 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1010 char __user
*optval
, int __user
*optlen
)
1014 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1015 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1017 if(level
!= SOL_IPV6
)
1018 return -ENOPROTOOPT
;
1020 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1021 #ifdef CONFIG_NETFILTER
1022 /* we need to exclude all possible EINVALs except default case */
1023 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1024 optname
!= MCAST_MSFILTER
) {
1027 if (get_user(len
, optlen
))
1031 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1035 err
= put_user(len
, optlen
);
1041 #ifdef CONFIG_COMPAT
1042 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1043 char __user
*optval
, int __user
*optlen
)
1047 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1048 if (udp_prot
.compat_getsockopt
!= NULL
)
1049 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1051 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1054 if (level
!= SOL_IPV6
)
1055 return -ENOPROTOOPT
;
1057 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1058 #ifdef CONFIG_NETFILTER
1059 /* we need to exclude all possible EINVALs except default case */
1060 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1061 optname
!= MCAST_MSFILTER
) {
1064 if (get_user(len
, optlen
))
1068 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1069 optname
, optval
, &len
);
1072 err
= put_user(len
, optlen
);
1078 EXPORT_SYMBOL(compat_ipv6_getsockopt
);
1081 void __init
ipv6_packet_init(void)
1083 dev_add_pack(&ipv6_packet_type
);
1086 void ipv6_packet_cleanup(void)
1088 dev_remove_pack(&ipv6_packet_type
);