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>
55 #include <net/compat.h>
57 #include <asm/uaccess.h>
59 DEFINE_SNMP_STAT(struct ipstats_mib
, ipv6_statistics
) __read_mostly
;
61 struct ip6_ra_chain
*ip6_ra_chain
;
62 DEFINE_RWLOCK(ip6_ra_lock
);
64 int ip6_ra_control(struct sock
*sk
, int sel
, void (*destructor
)(struct sock
*))
66 struct ip6_ra_chain
*ra
, *new_ra
, **rap
;
68 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
69 if (sk
->sk_type
!= SOCK_RAW
|| inet_sk(sk
)->num
!= IPPROTO_RAW
)
72 new_ra
= (sel
>=0) ? kmalloc(sizeof(*new_ra
), GFP_KERNEL
) : NULL
;
74 write_lock_bh(&ip6_ra_lock
);
75 for (rap
= &ip6_ra_chain
; (ra
=*rap
) != NULL
; rap
= &ra
->next
) {
78 write_unlock_bh(&ip6_ra_lock
);
84 write_unlock_bh(&ip6_ra_lock
);
94 write_unlock_bh(&ip6_ra_lock
);
99 new_ra
->destructor
= destructor
;
103 write_unlock_bh(&ip6_ra_lock
);
108 struct ipv6_txoptions
*ipv6_update_options(struct sock
*sk
,
109 struct ipv6_txoptions
*opt
)
111 if (inet_sk(sk
)->is_icsk
) {
113 !((1 << sk
->sk_state
) & (TCPF_LISTEN
| TCPF_CLOSE
)) &&
114 inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
115 struct inet_connection_sock
*icsk
= inet_csk(sk
);
116 icsk
->icsk_ext_hdr_len
= opt
->opt_flen
+ opt
->opt_nflen
;
117 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
119 opt
= xchg(&inet6_sk(sk
)->opt
, opt
);
121 write_lock(&sk
->sk_dst_lock
);
122 opt
= xchg(&inet6_sk(sk
)->opt
, opt
);
123 write_unlock(&sk
->sk_dst_lock
);
130 static int do_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
131 char __user
*optval
, int optlen
)
133 struct ipv6_pinfo
*np
= inet6_sk(sk
);
134 struct net
*net
= sock_net(sk
);
136 int retv
= -ENOPROTOOPT
;
141 if (optlen
>= sizeof(int)) {
142 if (get_user(val
, (int __user
*) optval
))
150 if (ip6_mroute_opt(optname
))
151 return ip6_mroute_setsockopt(sk
, optname
, optval
, optlen
);
158 if (optlen
< sizeof(int))
160 if (val
== PF_INET
) {
161 struct ipv6_txoptions
*opt
;
162 struct sk_buff
*pktopt
;
164 if (sk
->sk_type
== SOCK_RAW
)
167 if (sk
->sk_protocol
== IPPROTO_UDP
||
168 sk
->sk_protocol
== IPPROTO_UDPLITE
) {
169 struct udp_sock
*up
= udp_sk(sk
);
170 if (up
->pending
== AF_INET6
) {
174 } else if (sk
->sk_protocol
!= IPPROTO_TCP
)
177 if (sk
->sk_state
!= TCP_ESTABLISHED
) {
182 if (ipv6_only_sock(sk
) ||
183 !ipv6_addr_v4mapped(&np
->daddr
)) {
184 retv
= -EADDRNOTAVAIL
;
188 fl6_free_socklist(sk
);
189 ipv6_sock_mc_close(sk
);
192 * Sock is moving from IPv6 to IPv4 (sk_prot), so
193 * remove it from the refcnt debug socks count in the
196 sk_refcnt_debug_dec(sk
);
198 if (sk
->sk_protocol
== IPPROTO_TCP
) {
199 struct inet_connection_sock
*icsk
= inet_csk(sk
);
201 sock_prot_inuse_add(net
, sk
->sk_prot
, -1);
202 sock_prot_inuse_add(net
, &tcp_prot
, 1);
204 sk
->sk_prot
= &tcp_prot
;
205 icsk
->icsk_af_ops
= &ipv4_specific
;
206 sk
->sk_socket
->ops
= &inet_stream_ops
;
207 sk
->sk_family
= PF_INET
;
208 tcp_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
210 struct proto
*prot
= &udp_prot
;
212 if (sk
->sk_protocol
== IPPROTO_UDPLITE
)
213 prot
= &udplite_prot
;
215 sock_prot_inuse_add(net
, sk
->sk_prot
, -1);
216 sock_prot_inuse_add(net
, prot
, 1);
219 sk
->sk_socket
->ops
= &inet_dgram_ops
;
220 sk
->sk_family
= PF_INET
;
222 opt
= xchg(&np
->opt
, NULL
);
224 sock_kfree_s(sk
, opt
, opt
->tot_len
);
225 pktopt
= xchg(&np
->pktoptions
, NULL
);
229 sk
->sk_destruct
= inet_sock_destruct
;
231 * ... and add it to the refcnt debug socks count
232 * in the new family. -acme
234 sk_refcnt_debug_inc(sk
);
235 module_put(THIS_MODULE
);
242 if (optlen
< sizeof(int) ||
245 np
->ipv6only
= valbool
;
249 case IPV6_RECVPKTINFO
:
250 if (optlen
< sizeof(int))
252 np
->rxopt
.bits
.rxinfo
= valbool
;
256 case IPV6_2292PKTINFO
:
257 if (optlen
< sizeof(int))
259 np
->rxopt
.bits
.rxoinfo
= valbool
;
263 case IPV6_RECVHOPLIMIT
:
264 if (optlen
< sizeof(int))
266 np
->rxopt
.bits
.rxhlim
= valbool
;
270 case IPV6_2292HOPLIMIT
:
271 if (optlen
< sizeof(int))
273 np
->rxopt
.bits
.rxohlim
= valbool
;
278 if (optlen
< sizeof(int))
280 np
->rxopt
.bits
.srcrt
= valbool
;
285 if (optlen
< sizeof(int))
287 np
->rxopt
.bits
.osrcrt
= valbool
;
291 case IPV6_RECVHOPOPTS
:
292 if (optlen
< sizeof(int))
294 np
->rxopt
.bits
.hopopts
= valbool
;
298 case IPV6_2292HOPOPTS
:
299 if (optlen
< sizeof(int))
301 np
->rxopt
.bits
.ohopopts
= valbool
;
305 case IPV6_RECVDSTOPTS
:
306 if (optlen
< sizeof(int))
308 np
->rxopt
.bits
.dstopts
= valbool
;
312 case IPV6_2292DSTOPTS
:
313 if (optlen
< sizeof(int))
315 np
->rxopt
.bits
.odstopts
= valbool
;
320 if (optlen
< sizeof(int))
322 if (val
< -1 || val
> 0xff)
328 case IPV6_RECVTCLASS
:
329 if (optlen
< sizeof(int))
331 np
->rxopt
.bits
.rxtclass
= valbool
;
336 if (optlen
< sizeof(int))
338 np
->rxopt
.bits
.rxflow
= valbool
;
343 case IPV6_RTHDRDSTOPTS
:
347 struct ipv6_txoptions
*opt
;
351 /* hop-by-hop / destination options are privileged option */
353 if (optname
!= IPV6_RTHDR
&& !capable(CAP_NET_RAW
))
356 if (optlen
< sizeof(struct ipv6_opt_hdr
) ||
357 optlen
& 0x7 || optlen
> 8 * 255)
360 opt
= ipv6_renew_options(sk
, np
->opt
, optname
,
361 (struct ipv6_opt_hdr __user
*)optval
,
368 /* routing header option needs extra check */
369 if (optname
== IPV6_RTHDR
&& opt
&& opt
->srcrt
) {
370 struct ipv6_rt_hdr
*rthdr
= opt
->srcrt
;
371 switch (rthdr
->type
) {
372 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
373 case IPV6_SRCRT_TYPE_2
:
380 if ((rthdr
->hdrlen
& 1) ||
381 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
386 opt
= ipv6_update_options(sk
, opt
);
389 sock_kfree_s(sk
, opt
, opt
->tot_len
);
393 case IPV6_2292PKTOPTIONS
:
395 struct ipv6_txoptions
*opt
= NULL
;
400 fl
.fl6_flowlabel
= 0;
401 fl
.oif
= sk
->sk_bound_dev_if
;
406 /* 1K is probably excessive
407 * 1K is surely not enough, 2K per standard header is 16K.
410 if (optlen
> 64*1024)
413 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
418 memset(opt
, 0, sizeof(*opt
));
419 opt
->tot_len
= sizeof(*opt
) + optlen
;
421 if (copy_from_user(opt
+1, optval
, optlen
))
424 msg
.msg_controllen
= optlen
;
425 msg
.msg_control
= (void*)(opt
+1);
427 retv
= datagram_send_ctl(net
, &msg
, &fl
, opt
, &junk
, &junk
);
432 opt
= ipv6_update_options(sk
, opt
);
435 sock_kfree_s(sk
, opt
, opt
->tot_len
);
438 case IPV6_UNICAST_HOPS
:
439 if (optlen
< sizeof(int))
441 if (val
> 255 || val
< -1)
447 case IPV6_MULTICAST_HOPS
:
448 if (sk
->sk_type
== SOCK_STREAM
)
450 if (optlen
< sizeof(int))
452 if (val
> 255 || val
< -1)
454 np
->mcast_hops
= val
;
458 case IPV6_MULTICAST_LOOP
:
459 if (optlen
< sizeof(int))
463 np
->mc_loop
= valbool
;
467 case IPV6_MULTICAST_IF
:
468 if (sk
->sk_type
== SOCK_STREAM
)
470 if (optlen
< sizeof(int))
474 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
477 if (__dev_get_by_index(net
, val
) == NULL
) {
485 case IPV6_ADD_MEMBERSHIP
:
486 case IPV6_DROP_MEMBERSHIP
:
488 struct ipv6_mreq mreq
;
490 if (optlen
< sizeof(struct ipv6_mreq
))
494 if (inet_sk(sk
)->is_icsk
)
498 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
501 if (optname
== IPV6_ADD_MEMBERSHIP
)
502 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
504 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
507 case IPV6_JOIN_ANYCAST
:
508 case IPV6_LEAVE_ANYCAST
:
510 struct ipv6_mreq mreq
;
512 if (optlen
< sizeof(struct ipv6_mreq
))
516 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
519 if (optname
== IPV6_JOIN_ANYCAST
)
520 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
522 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
525 case MCAST_JOIN_GROUP
:
526 case MCAST_LEAVE_GROUP
:
528 struct group_req greq
;
529 struct sockaddr_in6
*psin6
;
531 if (optlen
< sizeof(struct group_req
))
535 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
537 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
538 retv
= -EADDRNOTAVAIL
;
541 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
542 if (optname
== MCAST_JOIN_GROUP
)
543 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
546 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
550 case MCAST_JOIN_SOURCE_GROUP
:
551 case MCAST_LEAVE_SOURCE_GROUP
:
552 case MCAST_BLOCK_SOURCE
:
553 case MCAST_UNBLOCK_SOURCE
:
555 struct group_source_req greqs
;
558 if (optlen
< sizeof(struct group_source_req
))
560 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
564 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
565 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
566 retv
= -EADDRNOTAVAIL
;
569 if (optname
== MCAST_BLOCK_SOURCE
) {
570 omode
= MCAST_EXCLUDE
;
572 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
573 omode
= MCAST_EXCLUDE
;
575 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
576 struct sockaddr_in6
*psin6
;
578 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
579 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
581 /* prior join w/ different source is ok */
582 if (retv
&& retv
!= -EADDRINUSE
)
584 omode
= MCAST_INCLUDE
;
586 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
587 omode
= MCAST_INCLUDE
;
590 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
595 extern int sysctl_mld_max_msf
;
596 struct group_filter
*gsf
;
598 if (optlen
< GROUP_FILTER_SIZE(0))
600 if (optlen
> sysctl_optmem_max
) {
604 gsf
= kmalloc(optlen
,GFP_KERNEL
);
610 if (copy_from_user(gsf
, optval
, optlen
)) {
614 /* numsrc >= (4G-140)/128 overflow in 32 bits */
615 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
616 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
621 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
626 retv
= ip6_mc_msfilter(sk
, gsf
);
631 case IPV6_ROUTER_ALERT
:
632 if (optlen
< sizeof(int))
634 retv
= ip6_ra_control(sk
, val
, NULL
);
636 case IPV6_MTU_DISCOVER
:
637 if (optlen
< sizeof(int))
645 if (optlen
< sizeof(int))
647 if (val
&& val
< IPV6_MIN_MTU
)
653 if (optlen
< sizeof(int))
655 np
->recverr
= valbool
;
657 skb_queue_purge(&sk
->sk_error_queue
);
660 case IPV6_FLOWINFO_SEND
:
661 if (optlen
< sizeof(int))
663 np
->sndflow
= valbool
;
666 case IPV6_FLOWLABEL_MGR
:
667 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
669 case IPV6_IPSEC_POLICY
:
670 case IPV6_XFRM_POLICY
:
672 if (!capable(CAP_NET_ADMIN
))
674 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
677 case IPV6_ADDR_PREFERENCES
:
679 unsigned int pref
= 0;
680 unsigned int prefmask
= ~0;
682 if (optlen
< sizeof(int))
687 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
688 switch (val
& (IPV6_PREFER_SRC_PUBLIC
|
690 IPV6_PREFER_SRC_PUBTMP_DEFAULT
)) {
691 case IPV6_PREFER_SRC_PUBLIC
:
692 pref
|= IPV6_PREFER_SRC_PUBLIC
;
694 case IPV6_PREFER_SRC_TMP
:
695 pref
|= IPV6_PREFER_SRC_TMP
;
697 case IPV6_PREFER_SRC_PUBTMP_DEFAULT
:
700 goto pref_skip_pubtmp
;
705 prefmask
&= ~(IPV6_PREFER_SRC_PUBLIC
|
706 IPV6_PREFER_SRC_TMP
);
709 /* check HOME/COA conflicts */
710 switch (val
& (IPV6_PREFER_SRC_HOME
|IPV6_PREFER_SRC_COA
)) {
711 case IPV6_PREFER_SRC_HOME
:
713 case IPV6_PREFER_SRC_COA
:
714 pref
|= IPV6_PREFER_SRC_COA
;
721 prefmask
&= ~IPV6_PREFER_SRC_COA
;
724 /* check CGA/NONCGA conflicts */
725 switch (val
& (IPV6_PREFER_SRC_CGA
|IPV6_PREFER_SRC_NONCGA
)) {
726 case IPV6_PREFER_SRC_CGA
:
727 case IPV6_PREFER_SRC_NONCGA
:
734 np
->srcprefs
= (np
->srcprefs
& prefmask
) | pref
;
750 int ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
751 char __user
*optval
, int optlen
)
755 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
756 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
758 if (level
!= SOL_IPV6
)
761 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
762 #ifdef CONFIG_NETFILTER
763 /* we need to exclude all possible ENOPROTOOPTs except default case */
764 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
765 optname
!= IPV6_XFRM_POLICY
) {
767 err
= nf_setsockopt(sk
, PF_INET6
, optname
, optval
,
775 EXPORT_SYMBOL(ipv6_setsockopt
);
778 int compat_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
779 char __user
*optval
, int optlen
)
783 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
784 if (udp_prot
.compat_setsockopt
!= NULL
)
785 return udp_prot
.compat_setsockopt(sk
, level
, optname
,
787 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
790 if (level
!= SOL_IPV6
)
793 if (optname
>= MCAST_JOIN_GROUP
&& optname
<= MCAST_MSFILTER
)
794 return compat_mc_setsockopt(sk
, level
, optname
, optval
, optlen
,
797 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
798 #ifdef CONFIG_NETFILTER
799 /* we need to exclude all possible ENOPROTOOPTs except default case */
800 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
801 optname
!= IPV6_XFRM_POLICY
) {
803 err
= compat_nf_setsockopt(sk
, PF_INET6
, optname
,
811 EXPORT_SYMBOL(compat_ipv6_setsockopt
);
814 static int ipv6_getsockopt_sticky(struct sock
*sk
, struct ipv6_txoptions
*opt
,
815 int optname
, char __user
*optval
, int len
)
817 struct ipv6_opt_hdr
*hdr
;
826 case IPV6_RTHDRDSTOPTS
:
830 hdr
= (struct ipv6_opt_hdr
*)opt
->srcrt
;
836 return -EINVAL
; /* should not happen */
842 len
= min_t(unsigned int, len
, ipv6_optlen(hdr
));
843 if (copy_to_user(optval
, hdr
, len
))
848 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
849 char __user
*optval
, int __user
*optlen
)
851 struct ipv6_pinfo
*np
= inet6_sk(sk
);
855 if (ip6_mroute_opt(optname
))
856 return ip6_mroute_getsockopt(sk
, optname
, optval
, optlen
);
858 if (get_user(len
, optlen
))
862 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
863 sk
->sk_protocol
!= IPPROTO_UDPLITE
&&
864 sk
->sk_protocol
!= IPPROTO_TCP
)
866 if (sk
->sk_state
!= TCP_ESTABLISHED
)
872 struct group_filter gsf
;
875 if (len
< GROUP_FILTER_SIZE(0))
877 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
879 if (gsf
.gf_group
.ss_family
!= AF_INET6
)
880 return -EADDRNOTAVAIL
;
882 err
= ip6_mc_msfget(sk
, &gsf
,
883 (struct group_filter __user
*)optval
, optlen
);
888 case IPV6_2292PKTOPTIONS
:
893 if (sk
->sk_type
!= SOCK_STREAM
)
896 msg
.msg_control
= optval
;
897 msg
.msg_controllen
= len
;
901 skb
= np
->pktoptions
;
903 atomic_inc(&skb
->users
);
907 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
912 if (np
->rxopt
.bits
.rxinfo
) {
913 struct in6_pktinfo src_info
;
914 src_info
.ipi6_ifindex
= np
->mcast_oif
;
915 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
916 put_cmsg(&msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
918 if (np
->rxopt
.bits
.rxhlim
) {
919 int hlim
= np
->mcast_hops
;
920 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
922 if (np
->rxopt
.bits
.rxoinfo
) {
923 struct in6_pktinfo src_info
;
924 src_info
.ipi6_ifindex
= np
->mcast_oif
;
925 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
926 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
928 if (np
->rxopt
.bits
.rxohlim
) {
929 int hlim
= np
->mcast_hops
;
930 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
933 len
-= msg
.msg_controllen
;
934 return put_user(len
, optlen
);
938 struct dst_entry
*dst
;
941 dst
= sk_dst_get(sk
);
956 case IPV6_RECVPKTINFO
:
957 val
= np
->rxopt
.bits
.rxinfo
;
960 case IPV6_2292PKTINFO
:
961 val
= np
->rxopt
.bits
.rxoinfo
;
964 case IPV6_RECVHOPLIMIT
:
965 val
= np
->rxopt
.bits
.rxhlim
;
968 case IPV6_2292HOPLIMIT
:
969 val
= np
->rxopt
.bits
.rxohlim
;
973 val
= np
->rxopt
.bits
.srcrt
;
977 val
= np
->rxopt
.bits
.osrcrt
;
981 case IPV6_RTHDRDSTOPTS
:
987 len
= ipv6_getsockopt_sticky(sk
, np
->opt
,
988 optname
, optval
, len
);
990 /* check if ipv6_getsockopt_sticky() returns err code */
993 return put_user(len
, optlen
);
996 case IPV6_RECVHOPOPTS
:
997 val
= np
->rxopt
.bits
.hopopts
;
1000 case IPV6_2292HOPOPTS
:
1001 val
= np
->rxopt
.bits
.ohopopts
;
1004 case IPV6_RECVDSTOPTS
:
1005 val
= np
->rxopt
.bits
.dstopts
;
1008 case IPV6_2292DSTOPTS
:
1009 val
= np
->rxopt
.bits
.odstopts
;
1018 case IPV6_RECVTCLASS
:
1019 val
= np
->rxopt
.bits
.rxtclass
;
1023 val
= np
->rxopt
.bits
.rxflow
;
1026 case IPV6_UNICAST_HOPS
:
1027 case IPV6_MULTICAST_HOPS
:
1029 struct dst_entry
*dst
;
1031 if (optname
== IPV6_UNICAST_HOPS
)
1032 val
= np
->hop_limit
;
1034 val
= np
->mcast_hops
;
1036 dst
= sk_dst_get(sk
);
1039 val
= ip6_dst_hoplimit(dst
);
1043 val
= ipv6_devconf
.hop_limit
;
1047 case IPV6_MULTICAST_LOOP
:
1051 case IPV6_MULTICAST_IF
:
1052 val
= np
->mcast_oif
;
1055 case IPV6_MTU_DISCOVER
:
1063 case IPV6_FLOWINFO_SEND
:
1067 case IPV6_ADDR_PREFERENCES
:
1070 if (np
->srcprefs
& IPV6_PREFER_SRC_TMP
)
1071 val
|= IPV6_PREFER_SRC_TMP
;
1072 else if (np
->srcprefs
& IPV6_PREFER_SRC_PUBLIC
)
1073 val
|= IPV6_PREFER_SRC_PUBLIC
;
1075 /* XXX: should we return system default? */
1076 val
|= IPV6_PREFER_SRC_PUBTMP_DEFAULT
;
1079 if (np
->srcprefs
& IPV6_PREFER_SRC_COA
)
1080 val
|= IPV6_PREFER_SRC_COA
;
1082 val
|= IPV6_PREFER_SRC_HOME
;
1086 return -ENOPROTOOPT
;
1088 len
= min_t(unsigned int, sizeof(int), len
);
1089 if(put_user(len
, optlen
))
1091 if(copy_to_user(optval
,&val
,len
))
1096 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1097 char __user
*optval
, int __user
*optlen
)
1101 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1102 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1104 if(level
!= SOL_IPV6
)
1105 return -ENOPROTOOPT
;
1107 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1108 #ifdef CONFIG_NETFILTER
1109 /* we need to exclude all possible ENOPROTOOPTs except default case */
1110 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_2292PKTOPTIONS
) {
1113 if (get_user(len
, optlen
))
1117 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1121 err
= put_user(len
, optlen
);
1127 EXPORT_SYMBOL(ipv6_getsockopt
);
1129 #ifdef CONFIG_COMPAT
1130 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1131 char __user
*optval
, int __user
*optlen
)
1135 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1136 if (udp_prot
.compat_getsockopt
!= NULL
)
1137 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1139 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1142 if (level
!= SOL_IPV6
)
1143 return -ENOPROTOOPT
;
1145 if (optname
== MCAST_MSFILTER
)
1146 return compat_mc_getsockopt(sk
, level
, optname
, optval
, optlen
,
1149 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1150 #ifdef CONFIG_NETFILTER
1151 /* we need to exclude all possible ENOPROTOOPTs except default case */
1152 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_2292PKTOPTIONS
) {
1155 if (get_user(len
, optlen
))
1159 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1160 optname
, optval
, &len
);
1163 err
= put_user(len
, optlen
);
1169 EXPORT_SYMBOL(compat_ipv6_getsockopt
);