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>
54 #include <net/udplite.h>
57 #include <asm/uaccess.h>
59 DEFINE_SNMP_STAT(struct ipstats_mib
, ipv6_statistics
) __read_mostly
;
61 static struct inet6_protocol
*ipv6_gso_pull_exthdrs(struct sk_buff
*skb
,
64 struct inet6_protocol
*ops
= NULL
;
67 struct ipv6_opt_hdr
*opth
;
70 if (proto
!= NEXTHDR_HOP
) {
71 ops
= rcu_dereference(inet6_protos
[proto
]);
76 if (!(ops
->flags
& INET6_PROTO_GSO_EXTHDR
))
80 if (unlikely(!pskb_may_pull(skb
, 8)))
83 opth
= (void *)skb
->data
;
84 len
= opth
->hdrlen
* 8 + 8;
86 if (unlikely(!pskb_may_pull(skb
, len
)))
89 proto
= opth
->nexthdr
;
96 static int ipv6_gso_send_check(struct sk_buff
*skb
)
98 struct ipv6hdr
*ipv6h
;
99 struct inet6_protocol
*ops
;
102 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
105 ipv6h
= skb
->nh
.ipv6h
;
106 __skb_pull(skb
, sizeof(*ipv6h
));
107 err
= -EPROTONOSUPPORT
;
110 ops
= ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
);
111 if (likely(ops
&& ops
->gso_send_check
)) {
112 skb
->h
.raw
= skb
->data
;
113 err
= ops
->gso_send_check(skb
);
121 static struct sk_buff
*ipv6_gso_segment(struct sk_buff
*skb
, int features
)
123 struct sk_buff
*segs
= ERR_PTR(-EINVAL
);
124 struct ipv6hdr
*ipv6h
;
125 struct inet6_protocol
*ops
;
127 if (!(features
& NETIF_F_HW_CSUM
))
128 features
&= ~NETIF_F_SG
;
130 if (unlikely(skb_shinfo(skb
)->gso_type
&
138 if (unlikely(!pskb_may_pull(skb
, sizeof(*ipv6h
))))
141 ipv6h
= skb
->nh
.ipv6h
;
142 __skb_pull(skb
, sizeof(*ipv6h
));
143 segs
= ERR_PTR(-EPROTONOSUPPORT
);
146 ops
= ipv6_gso_pull_exthdrs(skb
, ipv6h
->nexthdr
);
147 if (likely(ops
&& ops
->gso_segment
)) {
148 skb
->h
.raw
= skb
->data
;
149 segs
= ops
->gso_segment(skb
, features
);
153 if (unlikely(IS_ERR(segs
)))
156 for (skb
= segs
; skb
; skb
= skb
->next
) {
157 ipv6h
= skb
->nh
.ipv6h
;
158 ipv6h
->payload_len
= htons(skb
->len
- skb
->mac_len
-
166 static struct packet_type ipv6_packet_type
= {
167 .type
= __constant_htons(ETH_P_IPV6
),
169 .gso_send_check
= ipv6_gso_send_check
,
170 .gso_segment
= ipv6_gso_segment
,
173 struct ip6_ra_chain
*ip6_ra_chain
;
174 DEFINE_RWLOCK(ip6_ra_lock
);
176 int ip6_ra_control(struct sock
*sk
, int sel
, void (*destructor
)(struct sock
*))
178 struct ip6_ra_chain
*ra
, *new_ra
, **rap
;
180 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
181 if (sk
->sk_type
!= SOCK_RAW
|| inet_sk(sk
)->num
!= IPPROTO_RAW
)
184 new_ra
= (sel
>=0) ? kmalloc(sizeof(*new_ra
), GFP_KERNEL
) : NULL
;
186 write_lock_bh(&ip6_ra_lock
);
187 for (rap
= &ip6_ra_chain
; (ra
=*rap
) != NULL
; rap
= &ra
->next
) {
190 write_unlock_bh(&ip6_ra_lock
);
196 write_unlock_bh(&ip6_ra_lock
);
205 if (new_ra
== NULL
) {
206 write_unlock_bh(&ip6_ra_lock
);
211 new_ra
->destructor
= destructor
;
215 write_unlock_bh(&ip6_ra_lock
);
219 static int do_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
220 char __user
*optval
, int optlen
)
222 struct ipv6_pinfo
*np
= inet6_sk(sk
);
224 int retv
= -ENOPROTOOPT
;
228 else if (get_user(val
, (int __user
*) optval
))
238 if (val
== PF_INET
) {
239 struct ipv6_txoptions
*opt
;
240 struct sk_buff
*pktopt
;
242 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
243 sk
->sk_protocol
!= IPPROTO_UDPLITE
&&
244 sk
->sk_protocol
!= IPPROTO_TCP
)
247 if (sk
->sk_state
!= TCP_ESTABLISHED
) {
252 if (ipv6_only_sock(sk
) ||
253 !(ipv6_addr_type(&np
->daddr
) & IPV6_ADDR_MAPPED
)) {
254 retv
= -EADDRNOTAVAIL
;
258 fl6_free_socklist(sk
);
259 ipv6_sock_mc_close(sk
);
262 * Sock is moving from IPv6 to IPv4 (sk_prot), so
263 * remove it from the refcnt debug socks count in the
266 sk_refcnt_debug_dec(sk
);
268 if (sk
->sk_protocol
== IPPROTO_TCP
) {
269 struct inet_connection_sock
*icsk
= inet_csk(sk
);
272 sock_prot_dec_use(sk
->sk_prot
);
273 sock_prot_inc_use(&tcp_prot
);
275 sk
->sk_prot
= &tcp_prot
;
276 icsk
->icsk_af_ops
= &ipv4_specific
;
277 sk
->sk_socket
->ops
= &inet_stream_ops
;
278 sk
->sk_family
= PF_INET
;
279 tcp_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
281 struct proto
*prot
= &udp_prot
;
283 if (sk
->sk_protocol
== IPPROTO_UDPLITE
)
284 prot
= &udplite_prot
;
286 sock_prot_dec_use(sk
->sk_prot
);
287 sock_prot_inc_use(prot
);
290 sk
->sk_socket
->ops
= &inet_dgram_ops
;
291 sk
->sk_family
= PF_INET
;
293 opt
= xchg(&np
->opt
, NULL
);
295 sock_kfree_s(sk
, opt
, opt
->tot_len
);
296 pktopt
= xchg(&np
->pktoptions
, NULL
);
300 sk
->sk_destruct
= inet_sock_destruct
;
302 * ... and add it to the refcnt debug socks count
303 * in the new family. -acme
305 sk_refcnt_debug_inc(sk
);
306 module_put(THIS_MODULE
);
313 if (inet_sk(sk
)->num
)
315 np
->ipv6only
= valbool
;
319 case IPV6_RECVPKTINFO
:
320 np
->rxopt
.bits
.rxinfo
= valbool
;
324 case IPV6_2292PKTINFO
:
325 np
->rxopt
.bits
.rxoinfo
= valbool
;
329 case IPV6_RECVHOPLIMIT
:
330 np
->rxopt
.bits
.rxhlim
= valbool
;
334 case IPV6_2292HOPLIMIT
:
335 np
->rxopt
.bits
.rxohlim
= valbool
;
340 if (val
< 0 || val
> 2)
342 np
->rxopt
.bits
.srcrt
= val
;
347 if (val
< 0 || val
> 2)
349 np
->rxopt
.bits
.osrcrt
= val
;
353 case IPV6_RECVHOPOPTS
:
354 np
->rxopt
.bits
.hopopts
= valbool
;
358 case IPV6_2292HOPOPTS
:
359 np
->rxopt
.bits
.ohopopts
= valbool
;
363 case IPV6_RECVDSTOPTS
:
364 np
->rxopt
.bits
.dstopts
= valbool
;
368 case IPV6_2292DSTOPTS
:
369 np
->rxopt
.bits
.odstopts
= valbool
;
374 if (val
< -1 || val
> 0xff)
380 case IPV6_RECVTCLASS
:
381 np
->rxopt
.bits
.rxtclass
= valbool
;
386 np
->rxopt
.bits
.rxflow
= valbool
;
391 case IPV6_RTHDRDSTOPTS
:
395 struct ipv6_txoptions
*opt
;
399 /* hop-by-hop / destination options are privileged option */
401 if (optname
!= IPV6_RTHDR
&& !capable(CAP_NET_RAW
))
405 if (optlen
& 0x7 || optlen
> 8 * 255)
408 opt
= ipv6_renew_options(sk
, np
->opt
, optname
,
409 (struct ipv6_opt_hdr __user
*)optval
,
416 /* routing header option needs extra check */
417 if (optname
== IPV6_RTHDR
&& opt
->srcrt
) {
418 struct ipv6_rt_hdr
*rthdr
= opt
->srcrt
;
419 switch (rthdr
->type
) {
420 case IPV6_SRCRT_TYPE_0
:
421 #ifdef CONFIG_IPV6_MIP6
422 case IPV6_SRCRT_TYPE_2
:
429 if ((rthdr
->hdrlen
& 1) ||
430 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
435 if (inet_sk(sk
)->is_icsk
) {
437 struct inet_connection_sock
*icsk
= inet_csk(sk
);
438 if (!((1 << sk
->sk_state
) &
439 (TCPF_LISTEN
| TCPF_CLOSE
))
440 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
441 icsk
->icsk_ext_hdr_len
=
442 opt
->opt_flen
+ opt
->opt_nflen
;
443 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
446 opt
= xchg(&np
->opt
, opt
);
449 write_lock(&sk
->sk_dst_lock
);
450 opt
= xchg(&np
->opt
, opt
);
451 write_unlock(&sk
->sk_dst_lock
);
456 sock_kfree_s(sk
, opt
, opt
->tot_len
);
460 case IPV6_2292PKTOPTIONS
:
462 struct ipv6_txoptions
*opt
= NULL
;
467 fl
.fl6_flowlabel
= 0;
468 fl
.oif
= sk
->sk_bound_dev_if
;
473 /* 1K is probably excessive
474 * 1K is surely not enough, 2K per standard header is 16K.
477 if (optlen
> 64*1024)
480 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
485 memset(opt
, 0, sizeof(*opt
));
486 opt
->tot_len
= sizeof(*opt
) + optlen
;
488 if (copy_from_user(opt
+1, optval
, optlen
))
491 msg
.msg_controllen
= optlen
;
492 msg
.msg_control
= (void*)(opt
+1);
494 retv
= datagram_send_ctl(&msg
, &fl
, opt
, &junk
, &junk
);
499 if (inet_sk(sk
)->is_icsk
) {
501 struct inet_connection_sock
*icsk
= inet_csk(sk
);
502 if (!((1 << sk
->sk_state
) &
503 (TCPF_LISTEN
| TCPF_CLOSE
))
504 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
505 icsk
->icsk_ext_hdr_len
=
506 opt
->opt_flen
+ opt
->opt_nflen
;
507 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
510 opt
= xchg(&np
->opt
, opt
);
513 write_lock(&sk
->sk_dst_lock
);
514 opt
= xchg(&np
->opt
, opt
);
515 write_unlock(&sk
->sk_dst_lock
);
521 sock_kfree_s(sk
, opt
, opt
->tot_len
);
524 case IPV6_UNICAST_HOPS
:
525 if (val
> 255 || val
< -1)
531 case IPV6_MULTICAST_HOPS
:
532 if (sk
->sk_type
== SOCK_STREAM
)
534 if (val
> 255 || val
< -1)
536 np
->mcast_hops
= val
;
540 case IPV6_MULTICAST_LOOP
:
541 np
->mc_loop
= valbool
;
545 case IPV6_MULTICAST_IF
:
546 if (sk
->sk_type
== SOCK_STREAM
)
548 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
551 if (__dev_get_by_index(val
) == NULL
) {
558 case IPV6_ADD_MEMBERSHIP
:
559 case IPV6_DROP_MEMBERSHIP
:
561 struct ipv6_mreq mreq
;
564 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
567 if (optname
== IPV6_ADD_MEMBERSHIP
)
568 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
570 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
573 case IPV6_JOIN_ANYCAST
:
574 case IPV6_LEAVE_ANYCAST
:
576 struct ipv6_mreq mreq
;
578 if (optlen
!= sizeof(struct ipv6_mreq
))
582 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
585 if (optname
== IPV6_JOIN_ANYCAST
)
586 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
588 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
591 case MCAST_JOIN_GROUP
:
592 case MCAST_LEAVE_GROUP
:
594 struct group_req greq
;
595 struct sockaddr_in6
*psin6
;
598 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
600 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
601 retv
= -EADDRNOTAVAIL
;
604 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
605 if (optname
== MCAST_JOIN_GROUP
)
606 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
609 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
613 case MCAST_JOIN_SOURCE_GROUP
:
614 case MCAST_LEAVE_SOURCE_GROUP
:
615 case MCAST_BLOCK_SOURCE
:
616 case MCAST_UNBLOCK_SOURCE
:
618 struct group_source_req greqs
;
621 if (optlen
!= sizeof(struct group_source_req
))
623 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
627 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
628 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
629 retv
= -EADDRNOTAVAIL
;
632 if (optname
== MCAST_BLOCK_SOURCE
) {
633 omode
= MCAST_EXCLUDE
;
635 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
636 omode
= MCAST_EXCLUDE
;
638 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
639 struct sockaddr_in6
*psin6
;
641 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
642 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
644 /* prior join w/ different source is ok */
645 if (retv
&& retv
!= -EADDRINUSE
)
647 omode
= MCAST_INCLUDE
;
649 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
650 omode
= MCAST_INCLUDE
;
653 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
658 extern int sysctl_mld_max_msf
;
659 struct group_filter
*gsf
;
661 if (optlen
< GROUP_FILTER_SIZE(0))
663 if (optlen
> sysctl_optmem_max
) {
667 gsf
= kmalloc(optlen
,GFP_KERNEL
);
673 if (copy_from_user(gsf
, optval
, optlen
)) {
677 /* numsrc >= (4G-140)/128 overflow in 32 bits */
678 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
679 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
684 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
689 retv
= ip6_mc_msfilter(sk
, gsf
);
694 case IPV6_ROUTER_ALERT
:
695 retv
= ip6_ra_control(sk
, val
, NULL
);
697 case IPV6_MTU_DISCOVER
:
704 if (val
&& val
< IPV6_MIN_MTU
)
710 np
->recverr
= valbool
;
712 skb_queue_purge(&sk
->sk_error_queue
);
715 case IPV6_FLOWINFO_SEND
:
716 np
->sndflow
= valbool
;
719 case IPV6_FLOWLABEL_MGR
:
720 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
722 case IPV6_IPSEC_POLICY
:
723 case IPV6_XFRM_POLICY
:
725 if (!capable(CAP_NET_ADMIN
))
727 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
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
,
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_opt_hdr
*hdr
,
800 char __user
*optval
, int len
)
804 len
= min_t(int, len
, ipv6_optlen(hdr
));
805 if (copy_to_user(optval
, hdr
, ipv6_optlen(hdr
)))
810 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
811 char __user
*optval
, int __user
*optlen
)
813 struct ipv6_pinfo
*np
= inet6_sk(sk
);
817 if (get_user(len
, optlen
))
821 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
822 sk
->sk_protocol
!= IPPROTO_UDPLITE
&&
823 sk
->sk_protocol
!= IPPROTO_TCP
)
825 if (sk
->sk_state
!= TCP_ESTABLISHED
)
831 struct group_filter gsf
;
834 if (len
< GROUP_FILTER_SIZE(0))
836 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
839 err
= ip6_mc_msfget(sk
, &gsf
,
840 (struct group_filter __user
*)optval
, optlen
);
845 case IPV6_2292PKTOPTIONS
:
850 if (sk
->sk_type
!= SOCK_STREAM
)
853 msg
.msg_control
= optval
;
854 msg
.msg_controllen
= len
;
858 skb
= np
->pktoptions
;
860 atomic_inc(&skb
->users
);
864 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
869 if (np
->rxopt
.bits
.rxinfo
) {
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_PKTINFO
, sizeof(src_info
), &src_info
);
875 if (np
->rxopt
.bits
.rxhlim
) {
876 int hlim
= np
->mcast_hops
;
877 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
879 if (np
->rxopt
.bits
.rxoinfo
) {
880 struct in6_pktinfo src_info
;
881 src_info
.ipi6_ifindex
= np
->mcast_oif
;
882 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
883 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
885 if (np
->rxopt
.bits
.rxohlim
) {
886 int hlim
= np
->mcast_hops
;
887 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
890 len
-= msg
.msg_controllen
;
891 return put_user(len
, optlen
);
895 struct dst_entry
*dst
;
898 dst
= sk_dst_get(sk
);
913 case IPV6_RECVPKTINFO
:
914 val
= np
->rxopt
.bits
.rxinfo
;
917 case IPV6_2292PKTINFO
:
918 val
= np
->rxopt
.bits
.rxoinfo
;
921 case IPV6_RECVHOPLIMIT
:
922 val
= np
->rxopt
.bits
.rxhlim
;
925 case IPV6_2292HOPLIMIT
:
926 val
= np
->rxopt
.bits
.rxohlim
;
930 val
= np
->rxopt
.bits
.srcrt
;
934 val
= np
->rxopt
.bits
.osrcrt
;
938 case IPV6_RTHDRDSTOPTS
:
944 len
= ipv6_getsockopt_sticky(sk
, np
->opt
->hopopt
,
947 return put_user(len
, optlen
);
950 case IPV6_RECVHOPOPTS
:
951 val
= np
->rxopt
.bits
.hopopts
;
954 case IPV6_2292HOPOPTS
:
955 val
= np
->rxopt
.bits
.ohopopts
;
958 case IPV6_RECVDSTOPTS
:
959 val
= np
->rxopt
.bits
.dstopts
;
962 case IPV6_2292DSTOPTS
:
963 val
= np
->rxopt
.bits
.odstopts
;
972 case IPV6_RECVTCLASS
:
973 val
= np
->rxopt
.bits
.rxtclass
;
977 val
= np
->rxopt
.bits
.rxflow
;
980 case IPV6_UNICAST_HOPS
:
984 case IPV6_MULTICAST_HOPS
:
985 val
= np
->mcast_hops
;
988 case IPV6_MULTICAST_LOOP
:
992 case IPV6_MULTICAST_IF
:
996 case IPV6_MTU_DISCOVER
:
1004 case IPV6_FLOWINFO_SEND
:
1011 len
= min_t(unsigned int, sizeof(int), len
);
1012 if(put_user(len
, optlen
))
1014 if(copy_to_user(optval
,&val
,len
))
1019 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1020 char __user
*optval
, int __user
*optlen
)
1024 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1025 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1027 if(level
!= SOL_IPV6
)
1028 return -ENOPROTOOPT
;
1030 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1031 #ifdef CONFIG_NETFILTER
1032 /* we need to exclude all possible EINVALs except default case */
1033 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1034 optname
!= MCAST_MSFILTER
) {
1037 if (get_user(len
, optlen
))
1041 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1045 err
= put_user(len
, optlen
);
1051 #ifdef CONFIG_COMPAT
1052 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1053 char __user
*optval
, int __user
*optlen
)
1057 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1058 if (udp_prot
.compat_getsockopt
!= NULL
)
1059 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1061 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1064 if (level
!= SOL_IPV6
)
1065 return -ENOPROTOOPT
;
1067 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1068 #ifdef CONFIG_NETFILTER
1069 /* we need to exclude all possible EINVALs except default case */
1070 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1071 optname
!= MCAST_MSFILTER
) {
1074 if (get_user(len
, optlen
))
1078 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1079 optname
, optval
, &len
);
1082 err
= put_user(len
, optlen
);
1088 EXPORT_SYMBOL(compat_ipv6_getsockopt
);
1091 void __init
ipv6_packet_init(void)
1093 dev_add_pack(&ipv6_packet_type
);
1096 void ipv6_packet_cleanup(void)
1098 dev_remove_pack(&ipv6_packet_type
);