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 (!(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_TCP
)
245 if (sk
->sk_state
!= TCP_ESTABLISHED
) {
250 if (ipv6_only_sock(sk
) ||
251 !(ipv6_addr_type(&np
->daddr
) & IPV6_ADDR_MAPPED
)) {
252 retv
= -EADDRNOTAVAIL
;
256 fl6_free_socklist(sk
);
257 ipv6_sock_mc_close(sk
);
260 * Sock is moving from IPv6 to IPv4 (sk_prot), so
261 * remove it from the refcnt debug socks count in the
264 sk_refcnt_debug_dec(sk
);
266 if (sk
->sk_protocol
== IPPROTO_TCP
) {
267 struct inet_connection_sock
*icsk
= inet_csk(sk
);
270 sock_prot_dec_use(sk
->sk_prot
);
271 sock_prot_inc_use(&tcp_prot
);
273 sk
->sk_prot
= &tcp_prot
;
274 icsk
->icsk_af_ops
= &ipv4_specific
;
275 sk
->sk_socket
->ops
= &inet_stream_ops
;
276 sk
->sk_family
= PF_INET
;
277 tcp_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
280 sock_prot_dec_use(sk
->sk_prot
);
281 sock_prot_inc_use(&udp_prot
);
283 sk
->sk_prot
= &udp_prot
;
284 sk
->sk_socket
->ops
= &inet_dgram_ops
;
285 sk
->sk_family
= PF_INET
;
287 opt
= xchg(&np
->opt
, NULL
);
289 sock_kfree_s(sk
, opt
, opt
->tot_len
);
290 pktopt
= xchg(&np
->pktoptions
, NULL
);
294 sk
->sk_destruct
= inet_sock_destruct
;
296 * ... and add it to the refcnt debug socks count
297 * in the new family. -acme
299 sk_refcnt_debug_inc(sk
);
300 module_put(THIS_MODULE
);
307 if (inet_sk(sk
)->num
)
309 np
->ipv6only
= valbool
;
313 case IPV6_RECVPKTINFO
:
314 np
->rxopt
.bits
.rxinfo
= valbool
;
318 case IPV6_2292PKTINFO
:
319 np
->rxopt
.bits
.rxoinfo
= valbool
;
323 case IPV6_RECVHOPLIMIT
:
324 np
->rxopt
.bits
.rxhlim
= valbool
;
328 case IPV6_2292HOPLIMIT
:
329 np
->rxopt
.bits
.rxohlim
= valbool
;
334 if (val
< 0 || val
> 2)
336 np
->rxopt
.bits
.srcrt
= val
;
341 if (val
< 0 || val
> 2)
343 np
->rxopt
.bits
.osrcrt
= val
;
347 case IPV6_RECVHOPOPTS
:
348 np
->rxopt
.bits
.hopopts
= valbool
;
352 case IPV6_2292HOPOPTS
:
353 np
->rxopt
.bits
.ohopopts
= valbool
;
357 case IPV6_RECVDSTOPTS
:
358 np
->rxopt
.bits
.dstopts
= valbool
;
362 case IPV6_2292DSTOPTS
:
363 np
->rxopt
.bits
.odstopts
= valbool
;
368 if (val
< -1 || val
> 0xff)
374 case IPV6_RECVTCLASS
:
375 np
->rxopt
.bits
.rxtclass
= valbool
;
380 np
->rxopt
.bits
.rxflow
= valbool
;
385 case IPV6_RTHDRDSTOPTS
:
389 struct ipv6_txoptions
*opt
;
393 /* hop-by-hop / destination options are privileged option */
395 if (optname
!= IPV6_RTHDR
&& !capable(CAP_NET_RAW
))
399 if (optlen
& 0x7 || optlen
> 8 * 255)
402 opt
= ipv6_renew_options(sk
, np
->opt
, optname
,
403 (struct ipv6_opt_hdr __user
*)optval
,
410 /* routing header option needs extra check */
411 if (optname
== IPV6_RTHDR
&& opt
->srcrt
) {
412 struct ipv6_rt_hdr
*rthdr
= opt
->srcrt
;
413 switch (rthdr
->type
) {
414 case IPV6_SRCRT_TYPE_0
:
415 #ifdef CONFIG_IPV6_MIP6
416 case IPV6_SRCRT_TYPE_2
:
423 if ((rthdr
->hdrlen
& 1) ||
424 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
429 if (inet_sk(sk
)->is_icsk
) {
431 struct inet_connection_sock
*icsk
= inet_csk(sk
);
432 if (!((1 << sk
->sk_state
) &
433 (TCPF_LISTEN
| TCPF_CLOSE
))
434 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
435 icsk
->icsk_ext_hdr_len
=
436 opt
->opt_flen
+ opt
->opt_nflen
;
437 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
440 opt
= xchg(&np
->opt
, opt
);
443 write_lock(&sk
->sk_dst_lock
);
444 opt
= xchg(&np
->opt
, opt
);
445 write_unlock(&sk
->sk_dst_lock
);
450 sock_kfree_s(sk
, opt
, opt
->tot_len
);
454 case IPV6_2292PKTOPTIONS
:
456 struct ipv6_txoptions
*opt
= NULL
;
461 fl
.fl6_flowlabel
= 0;
462 fl
.oif
= sk
->sk_bound_dev_if
;
467 /* 1K is probably excessive
468 * 1K is surely not enough, 2K per standard header is 16K.
471 if (optlen
> 64*1024)
474 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
479 memset(opt
, 0, sizeof(*opt
));
480 opt
->tot_len
= sizeof(*opt
) + optlen
;
482 if (copy_from_user(opt
+1, optval
, optlen
))
485 msg
.msg_controllen
= optlen
;
486 msg
.msg_control
= (void*)(opt
+1);
488 retv
= datagram_send_ctl(&msg
, &fl
, opt
, &junk
, &junk
);
493 if (inet_sk(sk
)->is_icsk
) {
495 struct inet_connection_sock
*icsk
= inet_csk(sk
);
496 if (!((1 << sk
->sk_state
) &
497 (TCPF_LISTEN
| TCPF_CLOSE
))
498 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
499 icsk
->icsk_ext_hdr_len
=
500 opt
->opt_flen
+ opt
->opt_nflen
;
501 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
504 opt
= xchg(&np
->opt
, opt
);
507 write_lock(&sk
->sk_dst_lock
);
508 opt
= xchg(&np
->opt
, opt
);
509 write_unlock(&sk
->sk_dst_lock
);
515 sock_kfree_s(sk
, opt
, opt
->tot_len
);
518 case IPV6_UNICAST_HOPS
:
519 if (val
> 255 || val
< -1)
525 case IPV6_MULTICAST_HOPS
:
526 if (sk
->sk_type
== SOCK_STREAM
)
528 if (val
> 255 || val
< -1)
530 np
->mcast_hops
= val
;
534 case IPV6_MULTICAST_LOOP
:
535 np
->mc_loop
= valbool
;
539 case IPV6_MULTICAST_IF
:
540 if (sk
->sk_type
== SOCK_STREAM
)
542 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
545 if (__dev_get_by_index(val
) == NULL
) {
552 case IPV6_ADD_MEMBERSHIP
:
553 case IPV6_DROP_MEMBERSHIP
:
555 struct ipv6_mreq mreq
;
558 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
561 if (optname
== IPV6_ADD_MEMBERSHIP
)
562 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
564 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
567 case IPV6_JOIN_ANYCAST
:
568 case IPV6_LEAVE_ANYCAST
:
570 struct ipv6_mreq mreq
;
572 if (optlen
!= sizeof(struct ipv6_mreq
))
576 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
579 if (optname
== IPV6_JOIN_ANYCAST
)
580 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
582 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
585 case MCAST_JOIN_GROUP
:
586 case MCAST_LEAVE_GROUP
:
588 struct group_req greq
;
589 struct sockaddr_in6
*psin6
;
592 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
594 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
595 retv
= -EADDRNOTAVAIL
;
598 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
599 if (optname
== MCAST_JOIN_GROUP
)
600 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
603 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
607 case MCAST_JOIN_SOURCE_GROUP
:
608 case MCAST_LEAVE_SOURCE_GROUP
:
609 case MCAST_BLOCK_SOURCE
:
610 case MCAST_UNBLOCK_SOURCE
:
612 struct group_source_req greqs
;
615 if (optlen
!= sizeof(struct group_source_req
))
617 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
621 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
622 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
623 retv
= -EADDRNOTAVAIL
;
626 if (optname
== MCAST_BLOCK_SOURCE
) {
627 omode
= MCAST_EXCLUDE
;
629 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
630 omode
= MCAST_EXCLUDE
;
632 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
633 struct sockaddr_in6
*psin6
;
635 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
636 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
638 /* prior join w/ different source is ok */
639 if (retv
&& retv
!= -EADDRINUSE
)
641 omode
= MCAST_INCLUDE
;
643 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
644 omode
= MCAST_INCLUDE
;
647 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
652 extern int sysctl_mld_max_msf
;
653 struct group_filter
*gsf
;
655 if (optlen
< GROUP_FILTER_SIZE(0))
657 if (optlen
> sysctl_optmem_max
) {
661 gsf
= kmalloc(optlen
,GFP_KERNEL
);
667 if (copy_from_user(gsf
, optval
, optlen
)) {
671 /* numsrc >= (4G-140)/128 overflow in 32 bits */
672 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
673 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
678 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
683 retv
= ip6_mc_msfilter(sk
, gsf
);
688 case IPV6_ROUTER_ALERT
:
689 retv
= ip6_ra_control(sk
, val
, NULL
);
691 case IPV6_MTU_DISCOVER
:
698 if (val
&& val
< IPV6_MIN_MTU
)
704 np
->recverr
= valbool
;
706 skb_queue_purge(&sk
->sk_error_queue
);
709 case IPV6_FLOWINFO_SEND
:
710 np
->sndflow
= valbool
;
713 case IPV6_FLOWLABEL_MGR
:
714 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
716 case IPV6_IPSEC_POLICY
:
717 case IPV6_XFRM_POLICY
:
719 if (!capable(CAP_NET_ADMIN
))
721 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
734 int ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
735 char __user
*optval
, int optlen
)
739 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
740 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
742 if (level
!= SOL_IPV6
)
745 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
746 #ifdef CONFIG_NETFILTER
747 /* we need to exclude all possible ENOPROTOOPTs except default case */
748 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
749 optname
!= IPV6_XFRM_POLICY
) {
751 err
= nf_setsockopt(sk
, PF_INET6
, optname
, optval
,
761 int compat_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
762 char __user
*optval
, int optlen
)
766 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
767 if (udp_prot
.compat_setsockopt
!= NULL
)
768 return udp_prot
.compat_setsockopt(sk
, level
, optname
,
770 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
773 if (level
!= SOL_IPV6
)
776 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
777 #ifdef CONFIG_NETFILTER
778 /* we need to exclude all possible ENOPROTOOPTs except default case */
779 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
780 optname
!= IPV6_XFRM_POLICY
) {
782 err
= compat_nf_setsockopt(sk
, PF_INET6
, optname
,
790 EXPORT_SYMBOL(compat_ipv6_setsockopt
);
793 static int ipv6_getsockopt_sticky(struct sock
*sk
, struct ipv6_opt_hdr
*hdr
,
794 char __user
*optval
, int len
)
798 len
= min_t(int, len
, ipv6_optlen(hdr
));
799 if (copy_to_user(optval
, hdr
, ipv6_optlen(hdr
)))
804 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
805 char __user
*optval
, int __user
*optlen
)
807 struct ipv6_pinfo
*np
= inet6_sk(sk
);
811 if (get_user(len
, optlen
))
815 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
816 sk
->sk_protocol
!= IPPROTO_TCP
)
818 if (sk
->sk_state
!= TCP_ESTABLISHED
)
824 struct group_filter gsf
;
827 if (len
< GROUP_FILTER_SIZE(0))
829 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
832 err
= ip6_mc_msfget(sk
, &gsf
,
833 (struct group_filter __user
*)optval
, optlen
);
838 case IPV6_2292PKTOPTIONS
:
843 if (sk
->sk_type
!= SOCK_STREAM
)
846 msg
.msg_control
= optval
;
847 msg
.msg_controllen
= len
;
851 skb
= np
->pktoptions
;
853 atomic_inc(&skb
->users
);
857 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
862 if (np
->rxopt
.bits
.rxinfo
) {
863 struct in6_pktinfo src_info
;
864 src_info
.ipi6_ifindex
= np
->mcast_oif
;
865 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
866 put_cmsg(&msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
868 if (np
->rxopt
.bits
.rxhlim
) {
869 int hlim
= np
->mcast_hops
;
870 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
872 if (np
->rxopt
.bits
.rxoinfo
) {
873 struct in6_pktinfo src_info
;
874 src_info
.ipi6_ifindex
= np
->mcast_oif
;
875 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
876 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
878 if (np
->rxopt
.bits
.rxohlim
) {
879 int hlim
= np
->mcast_hops
;
880 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
883 len
-= msg
.msg_controllen
;
884 return put_user(len
, optlen
);
888 struct dst_entry
*dst
;
891 dst
= sk_dst_get(sk
);
906 case IPV6_RECVPKTINFO
:
907 val
= np
->rxopt
.bits
.rxinfo
;
910 case IPV6_2292PKTINFO
:
911 val
= np
->rxopt
.bits
.rxoinfo
;
914 case IPV6_RECVHOPLIMIT
:
915 val
= np
->rxopt
.bits
.rxhlim
;
918 case IPV6_2292HOPLIMIT
:
919 val
= np
->rxopt
.bits
.rxohlim
;
923 val
= np
->rxopt
.bits
.srcrt
;
927 val
= np
->rxopt
.bits
.osrcrt
;
931 case IPV6_RTHDRDSTOPTS
:
937 len
= ipv6_getsockopt_sticky(sk
, np
->opt
->hopopt
,
940 return put_user(len
, optlen
);
943 case IPV6_RECVHOPOPTS
:
944 val
= np
->rxopt
.bits
.hopopts
;
947 case IPV6_2292HOPOPTS
:
948 val
= np
->rxopt
.bits
.ohopopts
;
951 case IPV6_RECVDSTOPTS
:
952 val
= np
->rxopt
.bits
.dstopts
;
955 case IPV6_2292DSTOPTS
:
956 val
= np
->rxopt
.bits
.odstopts
;
965 case IPV6_RECVTCLASS
:
966 val
= np
->rxopt
.bits
.rxtclass
;
970 val
= np
->rxopt
.bits
.rxflow
;
973 case IPV6_UNICAST_HOPS
:
977 case IPV6_MULTICAST_HOPS
:
978 val
= np
->mcast_hops
;
981 case IPV6_MULTICAST_LOOP
:
985 case IPV6_MULTICAST_IF
:
989 case IPV6_MTU_DISCOVER
:
997 case IPV6_FLOWINFO_SEND
:
1004 len
= min_t(unsigned int, sizeof(int), len
);
1005 if(put_user(len
, optlen
))
1007 if(copy_to_user(optval
,&val
,len
))
1012 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1013 char __user
*optval
, int __user
*optlen
)
1017 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1018 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1020 if(level
!= SOL_IPV6
)
1021 return -ENOPROTOOPT
;
1023 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1024 #ifdef CONFIG_NETFILTER
1025 /* we need to exclude all possible EINVALs except default case */
1026 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1027 optname
!= MCAST_MSFILTER
) {
1030 if (get_user(len
, optlen
))
1034 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1038 err
= put_user(len
, optlen
);
1044 #ifdef CONFIG_COMPAT
1045 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1046 char __user
*optval
, int __user
*optlen
)
1050 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1051 if (udp_prot
.compat_getsockopt
!= NULL
)
1052 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1054 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1057 if (level
!= SOL_IPV6
)
1058 return -ENOPROTOOPT
;
1060 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1061 #ifdef CONFIG_NETFILTER
1062 /* we need to exclude all possible EINVALs except default case */
1063 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1064 optname
!= MCAST_MSFILTER
) {
1067 if (get_user(len
, optlen
))
1071 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1072 optname
, optval
, &len
);
1075 err
= put_user(len
, optlen
);
1081 EXPORT_SYMBOL(compat_ipv6_getsockopt
);
1084 void __init
ipv6_packet_init(void)
1086 dev_add_pack(&ipv6_packet_type
);
1089 void ipv6_packet_cleanup(void)
1091 dev_remove_pack(&ipv6_packet_type
);