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>
56 #include <asm/uaccess.h>
58 DEFINE_SNMP_STAT(struct ipstats_mib
, ipv6_statistics
) __read_mostly
;
60 struct ip6_ra_chain
*ip6_ra_chain
;
61 DEFINE_RWLOCK(ip6_ra_lock
);
63 int ip6_ra_control(struct sock
*sk
, int sel
, void (*destructor
)(struct sock
*))
65 struct ip6_ra_chain
*ra
, *new_ra
, **rap
;
67 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
68 if (sk
->sk_type
!= SOCK_RAW
|| inet_sk(sk
)->num
!= IPPROTO_RAW
)
71 new_ra
= (sel
>=0) ? kmalloc(sizeof(*new_ra
), GFP_KERNEL
) : NULL
;
73 write_lock_bh(&ip6_ra_lock
);
74 for (rap
= &ip6_ra_chain
; (ra
=*rap
) != NULL
; rap
= &ra
->next
) {
77 write_unlock_bh(&ip6_ra_lock
);
83 write_unlock_bh(&ip6_ra_lock
);
93 write_unlock_bh(&ip6_ra_lock
);
98 new_ra
->destructor
= destructor
;
102 write_unlock_bh(&ip6_ra_lock
);
106 static int do_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
107 char __user
*optval
, int optlen
)
109 struct ipv6_pinfo
*np
= inet6_sk(sk
);
110 struct net
*net
= sock_net(sk
);
112 int retv
= -ENOPROTOOPT
;
117 if (optlen
>= sizeof(int)) {
118 if (get_user(val
, (int __user
*) optval
))
126 if (ip6_mroute_opt(optname
))
127 return ip6_mroute_setsockopt(sk
, optname
, optval
, optlen
);
134 if (optlen
< sizeof(int))
136 if (val
== PF_INET
) {
137 struct ipv6_txoptions
*opt
;
138 struct sk_buff
*pktopt
;
140 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
141 sk
->sk_protocol
!= IPPROTO_UDPLITE
&&
142 sk
->sk_protocol
!= IPPROTO_TCP
)
145 if (sk
->sk_state
!= TCP_ESTABLISHED
) {
150 if (ipv6_only_sock(sk
) ||
151 !ipv6_addr_v4mapped(&np
->daddr
)) {
152 retv
= -EADDRNOTAVAIL
;
156 fl6_free_socklist(sk
);
157 ipv6_sock_mc_close(sk
);
160 * Sock is moving from IPv6 to IPv4 (sk_prot), so
161 * remove it from the refcnt debug socks count in the
164 sk_refcnt_debug_dec(sk
);
166 if (sk
->sk_protocol
== IPPROTO_TCP
) {
167 struct inet_connection_sock
*icsk
= inet_csk(sk
);
169 sock_prot_inuse_add(net
, sk
->sk_prot
, -1);
170 sock_prot_inuse_add(net
, &tcp_prot
, 1);
172 sk
->sk_prot
= &tcp_prot
;
173 icsk
->icsk_af_ops
= &ipv4_specific
;
174 sk
->sk_socket
->ops
= &inet_stream_ops
;
175 sk
->sk_family
= PF_INET
;
176 tcp_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
178 struct proto
*prot
= &udp_prot
;
180 if (sk
->sk_protocol
== IPPROTO_UDPLITE
)
181 prot
= &udplite_prot
;
183 sock_prot_inuse_add(net
, sk
->sk_prot
, -1);
184 sock_prot_inuse_add(net
, prot
, 1);
187 sk
->sk_socket
->ops
= &inet_dgram_ops
;
188 sk
->sk_family
= PF_INET
;
190 opt
= xchg(&np
->opt
, NULL
);
192 sock_kfree_s(sk
, opt
, opt
->tot_len
);
193 pktopt
= xchg(&np
->pktoptions
, NULL
);
197 sk
->sk_destruct
= inet_sock_destruct
;
199 * ... and add it to the refcnt debug socks count
200 * in the new family. -acme
202 sk_refcnt_debug_inc(sk
);
203 module_put(THIS_MODULE
);
210 if (optlen
< sizeof(int) ||
213 np
->ipv6only
= valbool
;
217 case IPV6_RECVPKTINFO
:
218 if (optlen
< sizeof(int))
220 np
->rxopt
.bits
.rxinfo
= valbool
;
224 case IPV6_2292PKTINFO
:
225 if (optlen
< sizeof(int))
227 np
->rxopt
.bits
.rxoinfo
= valbool
;
231 case IPV6_RECVHOPLIMIT
:
232 if (optlen
< sizeof(int))
234 np
->rxopt
.bits
.rxhlim
= valbool
;
238 case IPV6_2292HOPLIMIT
:
239 if (optlen
< sizeof(int))
241 np
->rxopt
.bits
.rxohlim
= valbool
;
246 if (optlen
< sizeof(int))
248 np
->rxopt
.bits
.srcrt
= valbool
;
253 if (optlen
< sizeof(int))
255 np
->rxopt
.bits
.osrcrt
= valbool
;
259 case IPV6_RECVHOPOPTS
:
260 if (optlen
< sizeof(int))
262 np
->rxopt
.bits
.hopopts
= valbool
;
266 case IPV6_2292HOPOPTS
:
267 if (optlen
< sizeof(int))
269 np
->rxopt
.bits
.ohopopts
= valbool
;
273 case IPV6_RECVDSTOPTS
:
274 if (optlen
< sizeof(int))
276 np
->rxopt
.bits
.dstopts
= valbool
;
280 case IPV6_2292DSTOPTS
:
281 if (optlen
< sizeof(int))
283 np
->rxopt
.bits
.odstopts
= valbool
;
288 if (optlen
< sizeof(int))
290 if (val
< -1 || val
> 0xff)
296 case IPV6_RECVTCLASS
:
297 if (optlen
< sizeof(int))
299 np
->rxopt
.bits
.rxtclass
= valbool
;
304 if (optlen
< sizeof(int))
306 np
->rxopt
.bits
.rxflow
= valbool
;
311 case IPV6_RTHDRDSTOPTS
:
315 struct ipv6_txoptions
*opt
;
319 /* hop-by-hop / destination options are privileged option */
321 if (optname
!= IPV6_RTHDR
&& !capable(CAP_NET_RAW
))
324 if (optlen
< sizeof(struct ipv6_opt_hdr
) ||
325 optlen
& 0x7 || optlen
> 8 * 255)
328 opt
= ipv6_renew_options(sk
, np
->opt
, optname
,
329 (struct ipv6_opt_hdr __user
*)optval
,
336 /* routing header option needs extra check */
337 if (optname
== IPV6_RTHDR
&& opt
&& opt
->srcrt
) {
338 struct ipv6_rt_hdr
*rthdr
= opt
->srcrt
;
339 switch (rthdr
->type
) {
340 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
341 case IPV6_SRCRT_TYPE_2
:
348 if ((rthdr
->hdrlen
& 1) ||
349 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
354 if (inet_sk(sk
)->is_icsk
) {
356 struct inet_connection_sock
*icsk
= inet_csk(sk
);
357 if (!((1 << sk
->sk_state
) &
358 (TCPF_LISTEN
| TCPF_CLOSE
))
359 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
360 icsk
->icsk_ext_hdr_len
=
361 opt
->opt_flen
+ opt
->opt_nflen
;
362 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
365 opt
= xchg(&np
->opt
, opt
);
368 write_lock(&sk
->sk_dst_lock
);
369 opt
= xchg(&np
->opt
, opt
);
370 write_unlock(&sk
->sk_dst_lock
);
375 sock_kfree_s(sk
, opt
, opt
->tot_len
);
379 case IPV6_2292PKTOPTIONS
:
381 struct ipv6_txoptions
*opt
= NULL
;
386 fl
.fl6_flowlabel
= 0;
387 fl
.oif
= sk
->sk_bound_dev_if
;
392 /* 1K is probably excessive
393 * 1K is surely not enough, 2K per standard header is 16K.
396 if (optlen
> 64*1024)
399 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
404 memset(opt
, 0, sizeof(*opt
));
405 opt
->tot_len
= sizeof(*opt
) + optlen
;
407 if (copy_from_user(opt
+1, optval
, optlen
))
410 msg
.msg_controllen
= optlen
;
411 msg
.msg_control
= (void*)(opt
+1);
413 retv
= datagram_send_ctl(&msg
, &fl
, opt
, &junk
, &junk
);
418 if (inet_sk(sk
)->is_icsk
) {
420 struct inet_connection_sock
*icsk
= inet_csk(sk
);
421 if (!((1 << sk
->sk_state
) &
422 (TCPF_LISTEN
| TCPF_CLOSE
))
423 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
424 icsk
->icsk_ext_hdr_len
=
425 opt
->opt_flen
+ opt
->opt_nflen
;
426 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
429 opt
= xchg(&np
->opt
, opt
);
432 write_lock(&sk
->sk_dst_lock
);
433 opt
= xchg(&np
->opt
, opt
);
434 write_unlock(&sk
->sk_dst_lock
);
440 sock_kfree_s(sk
, opt
, opt
->tot_len
);
443 case IPV6_UNICAST_HOPS
:
444 if (optlen
< sizeof(int))
446 if (val
> 255 || val
< -1)
452 case IPV6_MULTICAST_HOPS
:
453 if (sk
->sk_type
== SOCK_STREAM
)
455 if (optlen
< sizeof(int))
457 if (val
> 255 || val
< -1)
459 np
->mcast_hops
= val
;
463 case IPV6_MULTICAST_LOOP
:
464 if (optlen
< sizeof(int))
466 np
->mc_loop
= valbool
;
470 case IPV6_MULTICAST_IF
:
471 if (sk
->sk_type
== SOCK_STREAM
)
473 if (optlen
< sizeof(int))
477 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
480 if (__dev_get_by_index(net
, val
) == NULL
) {
488 case IPV6_ADD_MEMBERSHIP
:
489 case IPV6_DROP_MEMBERSHIP
:
491 struct ipv6_mreq mreq
;
493 if (optlen
< sizeof(struct ipv6_mreq
))
497 if (inet_sk(sk
)->is_icsk
)
501 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
504 if (optname
== IPV6_ADD_MEMBERSHIP
)
505 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
507 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
510 case IPV6_JOIN_ANYCAST
:
511 case IPV6_LEAVE_ANYCAST
:
513 struct ipv6_mreq mreq
;
515 if (optlen
< sizeof(struct ipv6_mreq
))
519 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
522 if (optname
== IPV6_JOIN_ANYCAST
)
523 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
525 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
528 case MCAST_JOIN_GROUP
:
529 case MCAST_LEAVE_GROUP
:
531 struct group_req greq
;
532 struct sockaddr_in6
*psin6
;
534 if (optlen
< sizeof(struct group_req
))
538 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
540 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
541 retv
= -EADDRNOTAVAIL
;
544 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
545 if (optname
== MCAST_JOIN_GROUP
)
546 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
549 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
553 case MCAST_JOIN_SOURCE_GROUP
:
554 case MCAST_LEAVE_SOURCE_GROUP
:
555 case MCAST_BLOCK_SOURCE
:
556 case MCAST_UNBLOCK_SOURCE
:
558 struct group_source_req greqs
;
561 if (optlen
< sizeof(struct group_source_req
))
563 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
567 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
568 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
569 retv
= -EADDRNOTAVAIL
;
572 if (optname
== MCAST_BLOCK_SOURCE
) {
573 omode
= MCAST_EXCLUDE
;
575 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
576 omode
= MCAST_EXCLUDE
;
578 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
579 struct sockaddr_in6
*psin6
;
581 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
582 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
584 /* prior join w/ different source is ok */
585 if (retv
&& retv
!= -EADDRINUSE
)
587 omode
= MCAST_INCLUDE
;
589 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
590 omode
= MCAST_INCLUDE
;
593 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
598 extern int sysctl_mld_max_msf
;
599 struct group_filter
*gsf
;
601 if (optlen
< GROUP_FILTER_SIZE(0))
603 if (optlen
> sysctl_optmem_max
) {
607 gsf
= kmalloc(optlen
,GFP_KERNEL
);
613 if (copy_from_user(gsf
, optval
, optlen
)) {
617 /* numsrc >= (4G-140)/128 overflow in 32 bits */
618 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
619 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
624 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
629 retv
= ip6_mc_msfilter(sk
, gsf
);
634 case IPV6_ROUTER_ALERT
:
635 if (optlen
< sizeof(int))
637 retv
= ip6_ra_control(sk
, val
, NULL
);
639 case IPV6_MTU_DISCOVER
:
640 if (optlen
< sizeof(int))
648 if (optlen
< sizeof(int))
650 if (val
&& val
< IPV6_MIN_MTU
)
656 if (optlen
< sizeof(int))
658 np
->recverr
= valbool
;
660 skb_queue_purge(&sk
->sk_error_queue
);
663 case IPV6_FLOWINFO_SEND
:
664 if (optlen
< sizeof(int))
666 np
->sndflow
= valbool
;
669 case IPV6_FLOWLABEL_MGR
:
670 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
672 case IPV6_IPSEC_POLICY
:
673 case IPV6_XFRM_POLICY
:
675 if (!capable(CAP_NET_ADMIN
))
677 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
680 case IPV6_ADDR_PREFERENCES
:
682 unsigned int pref
= 0;
683 unsigned int prefmask
= ~0;
685 if (optlen
< sizeof(int))
690 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
691 switch (val
& (IPV6_PREFER_SRC_PUBLIC
|
693 IPV6_PREFER_SRC_PUBTMP_DEFAULT
)) {
694 case IPV6_PREFER_SRC_PUBLIC
:
695 pref
|= IPV6_PREFER_SRC_PUBLIC
;
697 case IPV6_PREFER_SRC_TMP
:
698 pref
|= IPV6_PREFER_SRC_TMP
;
700 case IPV6_PREFER_SRC_PUBTMP_DEFAULT
:
703 goto pref_skip_pubtmp
;
708 prefmask
&= ~(IPV6_PREFER_SRC_PUBLIC
|
709 IPV6_PREFER_SRC_TMP
);
712 /* check HOME/COA conflicts */
713 switch (val
& (IPV6_PREFER_SRC_HOME
|IPV6_PREFER_SRC_COA
)) {
714 case IPV6_PREFER_SRC_HOME
:
716 case IPV6_PREFER_SRC_COA
:
717 pref
|= IPV6_PREFER_SRC_COA
;
724 prefmask
&= ~IPV6_PREFER_SRC_COA
;
727 /* check CGA/NONCGA conflicts */
728 switch (val
& (IPV6_PREFER_SRC_CGA
|IPV6_PREFER_SRC_NONCGA
)) {
729 case IPV6_PREFER_SRC_CGA
:
730 case IPV6_PREFER_SRC_NONCGA
:
737 np
->srcprefs
= (np
->srcprefs
& prefmask
) | pref
;
753 int ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
754 char __user
*optval
, int optlen
)
758 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
759 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
761 if (level
!= SOL_IPV6
)
764 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
765 #ifdef CONFIG_NETFILTER
766 /* we need to exclude all possible ENOPROTOOPTs except default case */
767 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
768 optname
!= IPV6_XFRM_POLICY
) {
770 err
= nf_setsockopt(sk
, PF_INET6
, optname
, optval
,
778 EXPORT_SYMBOL(ipv6_setsockopt
);
781 int compat_ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
782 char __user
*optval
, int optlen
)
786 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
787 if (udp_prot
.compat_setsockopt
!= NULL
)
788 return udp_prot
.compat_setsockopt(sk
, level
, optname
,
790 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
793 if (level
!= SOL_IPV6
)
796 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
797 #ifdef CONFIG_NETFILTER
798 /* we need to exclude all possible ENOPROTOOPTs except default case */
799 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
800 optname
!= IPV6_XFRM_POLICY
) {
802 err
= compat_nf_setsockopt(sk
, PF_INET6
, optname
,
810 EXPORT_SYMBOL(compat_ipv6_setsockopt
);
813 static int ipv6_getsockopt_sticky(struct sock
*sk
, struct ipv6_txoptions
*opt
,
814 int optname
, char __user
*optval
, int len
)
816 struct ipv6_opt_hdr
*hdr
;
825 case IPV6_RTHDRDSTOPTS
:
829 hdr
= (struct ipv6_opt_hdr
*)opt
->srcrt
;
835 return -EINVAL
; /* should not happen */
841 len
= min_t(unsigned int, len
, ipv6_optlen(hdr
));
842 if (copy_to_user(optval
, hdr
, len
))
844 return ipv6_optlen(hdr
);
847 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
848 char __user
*optval
, int __user
*optlen
)
850 struct ipv6_pinfo
*np
= inet6_sk(sk
);
854 if (ip6_mroute_opt(optname
))
855 return ip6_mroute_getsockopt(sk
, optname
, optval
, optlen
);
857 if (get_user(len
, optlen
))
861 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
862 sk
->sk_protocol
!= IPPROTO_UDPLITE
&&
863 sk
->sk_protocol
!= IPPROTO_TCP
)
865 if (sk
->sk_state
!= TCP_ESTABLISHED
)
871 struct group_filter gsf
;
874 if (len
< GROUP_FILTER_SIZE(0))
876 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
879 err
= ip6_mc_msfget(sk
, &gsf
,
880 (struct group_filter __user
*)optval
, optlen
);
885 case IPV6_2292PKTOPTIONS
:
890 if (sk
->sk_type
!= SOCK_STREAM
)
893 msg
.msg_control
= optval
;
894 msg
.msg_controllen
= len
;
898 skb
= np
->pktoptions
;
900 atomic_inc(&skb
->users
);
904 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
909 if (np
->rxopt
.bits
.rxinfo
) {
910 struct in6_pktinfo src_info
;
911 src_info
.ipi6_ifindex
= np
->mcast_oif
;
912 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
913 put_cmsg(&msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
915 if (np
->rxopt
.bits
.rxhlim
) {
916 int hlim
= np
->mcast_hops
;
917 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
919 if (np
->rxopt
.bits
.rxoinfo
) {
920 struct in6_pktinfo src_info
;
921 src_info
.ipi6_ifindex
= np
->mcast_oif
;
922 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
923 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
925 if (np
->rxopt
.bits
.rxohlim
) {
926 int hlim
= np
->mcast_hops
;
927 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
930 len
-= msg
.msg_controllen
;
931 return put_user(len
, optlen
);
935 struct dst_entry
*dst
;
938 dst
= sk_dst_get(sk
);
953 case IPV6_RECVPKTINFO
:
954 val
= np
->rxopt
.bits
.rxinfo
;
957 case IPV6_2292PKTINFO
:
958 val
= np
->rxopt
.bits
.rxoinfo
;
961 case IPV6_RECVHOPLIMIT
:
962 val
= np
->rxopt
.bits
.rxhlim
;
965 case IPV6_2292HOPLIMIT
:
966 val
= np
->rxopt
.bits
.rxohlim
;
970 val
= np
->rxopt
.bits
.srcrt
;
974 val
= np
->rxopt
.bits
.osrcrt
;
978 case IPV6_RTHDRDSTOPTS
:
984 len
= ipv6_getsockopt_sticky(sk
, np
->opt
,
985 optname
, optval
, len
);
987 return put_user(len
, optlen
);
990 case IPV6_RECVHOPOPTS
:
991 val
= np
->rxopt
.bits
.hopopts
;
994 case IPV6_2292HOPOPTS
:
995 val
= np
->rxopt
.bits
.ohopopts
;
998 case IPV6_RECVDSTOPTS
:
999 val
= np
->rxopt
.bits
.dstopts
;
1002 case IPV6_2292DSTOPTS
:
1003 val
= np
->rxopt
.bits
.odstopts
;
1012 case IPV6_RECVTCLASS
:
1013 val
= np
->rxopt
.bits
.rxtclass
;
1017 val
= np
->rxopt
.bits
.rxflow
;
1020 case IPV6_UNICAST_HOPS
:
1021 case IPV6_MULTICAST_HOPS
:
1023 struct dst_entry
*dst
;
1025 if (optname
== IPV6_UNICAST_HOPS
)
1026 val
= np
->hop_limit
;
1028 val
= np
->mcast_hops
;
1030 dst
= sk_dst_get(sk
);
1033 val
= ip6_dst_hoplimit(dst
);
1037 val
= ipv6_devconf
.hop_limit
;
1041 case IPV6_MULTICAST_LOOP
:
1045 case IPV6_MULTICAST_IF
:
1046 val
= np
->mcast_oif
;
1049 case IPV6_MTU_DISCOVER
:
1057 case IPV6_FLOWINFO_SEND
:
1061 case IPV6_ADDR_PREFERENCES
:
1064 if (np
->srcprefs
& IPV6_PREFER_SRC_TMP
)
1065 val
|= IPV6_PREFER_SRC_TMP
;
1066 else if (np
->srcprefs
& IPV6_PREFER_SRC_PUBLIC
)
1067 val
|= IPV6_PREFER_SRC_PUBLIC
;
1069 /* XXX: should we return system default? */
1070 val
|= IPV6_PREFER_SRC_PUBTMP_DEFAULT
;
1073 if (np
->srcprefs
& IPV6_PREFER_SRC_COA
)
1074 val
|= IPV6_PREFER_SRC_COA
;
1076 val
|= IPV6_PREFER_SRC_HOME
;
1080 return -ENOPROTOOPT
;
1082 len
= min_t(unsigned int, sizeof(int), len
);
1083 if(put_user(len
, optlen
))
1085 if(copy_to_user(optval
,&val
,len
))
1090 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1091 char __user
*optval
, int __user
*optlen
)
1095 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1096 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1098 if(level
!= SOL_IPV6
)
1099 return -ENOPROTOOPT
;
1101 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1102 #ifdef CONFIG_NETFILTER
1103 /* we need to exclude all possible ENOPROTOOPTs except default case */
1104 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_2292PKTOPTIONS
) {
1107 if (get_user(len
, optlen
))
1111 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1115 err
= put_user(len
, optlen
);
1121 EXPORT_SYMBOL(ipv6_getsockopt
);
1123 #ifdef CONFIG_COMPAT
1124 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1125 char __user
*optval
, int __user
*optlen
)
1129 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1130 if (udp_prot
.compat_getsockopt
!= NULL
)
1131 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1133 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1136 if (level
!= SOL_IPV6
)
1137 return -ENOPROTOOPT
;
1139 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1140 #ifdef CONFIG_NETFILTER
1141 /* we need to exclude all possible ENOPROTOOPTs except default case */
1142 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_2292PKTOPTIONS
) {
1145 if (get_user(len
, optlen
))
1149 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1150 optname
, optval
, &len
);
1153 err
= put_user(len
, optlen
);
1159 EXPORT_SYMBOL(compat_ipv6_getsockopt
);