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
;
412 if ((rthdr
->hdrlen
& 1) ||
413 (rthdr
->hdrlen
>> 1) != rthdr
->segments_left
)
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
);
439 sock_kfree_s(sk
, opt
, opt
->tot_len
);
443 case IPV6_2292PKTOPTIONS
:
445 struct ipv6_txoptions
*opt
= NULL
;
450 fl
.fl6_flowlabel
= 0;
451 fl
.oif
= sk
->sk_bound_dev_if
;
456 /* 1K is probably excessive
457 * 1K is surely not enough, 2K per standard header is 16K.
460 if (optlen
> 64*1024)
463 opt
= sock_kmalloc(sk
, sizeof(*opt
) + optlen
, GFP_KERNEL
);
468 memset(opt
, 0, sizeof(*opt
));
469 opt
->tot_len
= sizeof(*opt
) + optlen
;
471 if (copy_from_user(opt
+1, optval
, optlen
))
474 msg
.msg_controllen
= optlen
;
475 msg
.msg_control
= (void*)(opt
+1);
477 retv
= datagram_send_ctl(&msg
, &fl
, opt
, &junk
, &junk
);
482 if (inet_sk(sk
)->is_icsk
) {
484 struct inet_connection_sock
*icsk
= inet_csk(sk
);
485 if (!((1 << sk
->sk_state
) &
486 (TCPF_LISTEN
| TCPF_CLOSE
))
487 && inet_sk(sk
)->daddr
!= LOOPBACK4_IPV6
) {
488 icsk
->icsk_ext_hdr_len
=
489 opt
->opt_flen
+ opt
->opt_nflen
;
490 icsk
->icsk_sync_mss(sk
, icsk
->icsk_pmtu_cookie
);
493 opt
= xchg(&np
->opt
, opt
);
496 write_lock(&sk
->sk_dst_lock
);
497 opt
= xchg(&np
->opt
, opt
);
498 write_unlock(&sk
->sk_dst_lock
);
504 sock_kfree_s(sk
, opt
, opt
->tot_len
);
507 case IPV6_UNICAST_HOPS
:
508 if (val
> 255 || val
< -1)
514 case IPV6_MULTICAST_HOPS
:
515 if (sk
->sk_type
== SOCK_STREAM
)
517 if (val
> 255 || val
< -1)
519 np
->mcast_hops
= val
;
523 case IPV6_MULTICAST_LOOP
:
524 np
->mc_loop
= valbool
;
528 case IPV6_MULTICAST_IF
:
529 if (sk
->sk_type
== SOCK_STREAM
)
531 if (sk
->sk_bound_dev_if
&& sk
->sk_bound_dev_if
!= val
)
534 if (__dev_get_by_index(val
) == NULL
) {
541 case IPV6_ADD_MEMBERSHIP
:
542 case IPV6_DROP_MEMBERSHIP
:
544 struct ipv6_mreq mreq
;
547 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
550 if (optname
== IPV6_ADD_MEMBERSHIP
)
551 retv
= ipv6_sock_mc_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
553 retv
= ipv6_sock_mc_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_multiaddr
);
556 case IPV6_JOIN_ANYCAST
:
557 case IPV6_LEAVE_ANYCAST
:
559 struct ipv6_mreq mreq
;
561 if (optlen
!= sizeof(struct ipv6_mreq
))
565 if (copy_from_user(&mreq
, optval
, sizeof(struct ipv6_mreq
)))
568 if (optname
== IPV6_JOIN_ANYCAST
)
569 retv
= ipv6_sock_ac_join(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
571 retv
= ipv6_sock_ac_drop(sk
, mreq
.ipv6mr_ifindex
, &mreq
.ipv6mr_acaddr
);
574 case MCAST_JOIN_GROUP
:
575 case MCAST_LEAVE_GROUP
:
577 struct group_req greq
;
578 struct sockaddr_in6
*psin6
;
581 if (copy_from_user(&greq
, optval
, sizeof(struct group_req
)))
583 if (greq
.gr_group
.ss_family
!= AF_INET6
) {
584 retv
= -EADDRNOTAVAIL
;
587 psin6
= (struct sockaddr_in6
*)&greq
.gr_group
;
588 if (optname
== MCAST_JOIN_GROUP
)
589 retv
= ipv6_sock_mc_join(sk
, greq
.gr_interface
,
592 retv
= ipv6_sock_mc_drop(sk
, greq
.gr_interface
,
596 case MCAST_JOIN_SOURCE_GROUP
:
597 case MCAST_LEAVE_SOURCE_GROUP
:
598 case MCAST_BLOCK_SOURCE
:
599 case MCAST_UNBLOCK_SOURCE
:
601 struct group_source_req greqs
;
604 if (optlen
!= sizeof(struct group_source_req
))
606 if (copy_from_user(&greqs
, optval
, sizeof(greqs
))) {
610 if (greqs
.gsr_group
.ss_family
!= AF_INET6
||
611 greqs
.gsr_source
.ss_family
!= AF_INET6
) {
612 retv
= -EADDRNOTAVAIL
;
615 if (optname
== MCAST_BLOCK_SOURCE
) {
616 omode
= MCAST_EXCLUDE
;
618 } else if (optname
== MCAST_UNBLOCK_SOURCE
) {
619 omode
= MCAST_EXCLUDE
;
621 } else if (optname
== MCAST_JOIN_SOURCE_GROUP
) {
622 struct sockaddr_in6
*psin6
;
624 psin6
= (struct sockaddr_in6
*)&greqs
.gsr_group
;
625 retv
= ipv6_sock_mc_join(sk
, greqs
.gsr_interface
,
627 /* prior join w/ different source is ok */
628 if (retv
&& retv
!= -EADDRINUSE
)
630 omode
= MCAST_INCLUDE
;
632 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
633 omode
= MCAST_INCLUDE
;
636 retv
= ip6_mc_source(add
, omode
, sk
, &greqs
);
641 extern int sysctl_mld_max_msf
;
642 struct group_filter
*gsf
;
644 if (optlen
< GROUP_FILTER_SIZE(0))
646 if (optlen
> sysctl_optmem_max
) {
650 gsf
= kmalloc(optlen
,GFP_KERNEL
);
656 if (copy_from_user(gsf
, optval
, optlen
)) {
660 /* numsrc >= (4G-140)/128 overflow in 32 bits */
661 if (gsf
->gf_numsrc
>= 0x1ffffffU
||
662 gsf
->gf_numsrc
> sysctl_mld_max_msf
) {
667 if (GROUP_FILTER_SIZE(gsf
->gf_numsrc
) > optlen
) {
672 retv
= ip6_mc_msfilter(sk
, gsf
);
677 case IPV6_ROUTER_ALERT
:
678 retv
= ip6_ra_control(sk
, val
, NULL
);
680 case IPV6_MTU_DISCOVER
:
687 if (val
&& val
< IPV6_MIN_MTU
)
693 np
->recverr
= valbool
;
695 skb_queue_purge(&sk
->sk_error_queue
);
698 case IPV6_FLOWINFO_SEND
:
699 np
->sndflow
= valbool
;
702 case IPV6_FLOWLABEL_MGR
:
703 retv
= ipv6_flowlabel_opt(sk
, optval
, optlen
);
705 case IPV6_IPSEC_POLICY
:
706 case IPV6_XFRM_POLICY
:
708 if (!capable(CAP_NET_ADMIN
))
710 retv
= xfrm_user_policy(sk
, optname
, optval
, optlen
);
723 int ipv6_setsockopt(struct sock
*sk
, int level
, int optname
,
724 char __user
*optval
, int optlen
)
728 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
729 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
731 if (level
!= SOL_IPV6
)
734 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
735 #ifdef CONFIG_NETFILTER
736 /* we need to exclude all possible ENOPROTOOPTs except default case */
737 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
738 optname
!= IPV6_XFRM_POLICY
) {
740 err
= nf_setsockopt(sk
, PF_INET6
, optname
, optval
,
750 int compat_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 if (udp_prot
.compat_setsockopt
!= NULL
)
757 return udp_prot
.compat_setsockopt(sk
, level
, optname
,
759 return udp_prot
.setsockopt(sk
, level
, optname
, optval
, optlen
);
762 if (level
!= SOL_IPV6
)
765 err
= do_ipv6_setsockopt(sk
, level
, optname
, optval
, optlen
);
766 #ifdef CONFIG_NETFILTER
767 /* we need to exclude all possible ENOPROTOOPTs except default case */
768 if (err
== -ENOPROTOOPT
&& optname
!= IPV6_IPSEC_POLICY
&&
769 optname
!= IPV6_XFRM_POLICY
) {
771 err
= compat_nf_setsockopt(sk
, PF_INET6
, optname
,
779 EXPORT_SYMBOL(compat_ipv6_setsockopt
);
782 static int ipv6_getsockopt_sticky(struct sock
*sk
, struct ipv6_opt_hdr
*hdr
,
783 char __user
*optval
, int len
)
787 len
= min_t(int, len
, ipv6_optlen(hdr
));
788 if (copy_to_user(optval
, hdr
, ipv6_optlen(hdr
)))
793 static int do_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
794 char __user
*optval
, int __user
*optlen
)
796 struct ipv6_pinfo
*np
= inet6_sk(sk
);
800 if (get_user(len
, optlen
))
804 if (sk
->sk_protocol
!= IPPROTO_UDP
&&
805 sk
->sk_protocol
!= IPPROTO_TCP
)
807 if (sk
->sk_state
!= TCP_ESTABLISHED
)
813 struct group_filter gsf
;
816 if (len
< GROUP_FILTER_SIZE(0))
818 if (copy_from_user(&gsf
, optval
, GROUP_FILTER_SIZE(0)))
821 err
= ip6_mc_msfget(sk
, &gsf
,
822 (struct group_filter __user
*)optval
, optlen
);
827 case IPV6_2292PKTOPTIONS
:
832 if (sk
->sk_type
!= SOCK_STREAM
)
835 msg
.msg_control
= optval
;
836 msg
.msg_controllen
= len
;
840 skb
= np
->pktoptions
;
842 atomic_inc(&skb
->users
);
846 int err
= datagram_recv_ctl(sk
, &msg
, skb
);
851 if (np
->rxopt
.bits
.rxinfo
) {
852 struct in6_pktinfo src_info
;
853 src_info
.ipi6_ifindex
= np
->mcast_oif
;
854 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
855 put_cmsg(&msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
857 if (np
->rxopt
.bits
.rxhlim
) {
858 int hlim
= np
->mcast_hops
;
859 put_cmsg(&msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
861 if (np
->rxopt
.bits
.rxoinfo
) {
862 struct in6_pktinfo src_info
;
863 src_info
.ipi6_ifindex
= np
->mcast_oif
;
864 ipv6_addr_copy(&src_info
.ipi6_addr
, &np
->daddr
);
865 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
867 if (np
->rxopt
.bits
.rxohlim
) {
868 int hlim
= np
->mcast_hops
;
869 put_cmsg(&msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
872 len
-= msg
.msg_controllen
;
873 return put_user(len
, optlen
);
877 struct dst_entry
*dst
;
880 dst
= sk_dst_get(sk
);
895 case IPV6_RECVPKTINFO
:
896 val
= np
->rxopt
.bits
.rxinfo
;
899 case IPV6_2292PKTINFO
:
900 val
= np
->rxopt
.bits
.rxoinfo
;
903 case IPV6_RECVHOPLIMIT
:
904 val
= np
->rxopt
.bits
.rxhlim
;
907 case IPV6_2292HOPLIMIT
:
908 val
= np
->rxopt
.bits
.rxohlim
;
912 val
= np
->rxopt
.bits
.srcrt
;
916 val
= np
->rxopt
.bits
.osrcrt
;
920 case IPV6_RTHDRDSTOPTS
:
926 len
= ipv6_getsockopt_sticky(sk
, np
->opt
->hopopt
,
929 return put_user(len
, optlen
);
932 case IPV6_RECVHOPOPTS
:
933 val
= np
->rxopt
.bits
.hopopts
;
936 case IPV6_2292HOPOPTS
:
937 val
= np
->rxopt
.bits
.ohopopts
;
940 case IPV6_RECVDSTOPTS
:
941 val
= np
->rxopt
.bits
.dstopts
;
944 case IPV6_2292DSTOPTS
:
945 val
= np
->rxopt
.bits
.odstopts
;
954 case IPV6_RECVTCLASS
:
955 val
= np
->rxopt
.bits
.rxtclass
;
959 val
= np
->rxopt
.bits
.rxflow
;
962 case IPV6_UNICAST_HOPS
:
966 case IPV6_MULTICAST_HOPS
:
967 val
= np
->mcast_hops
;
970 case IPV6_MULTICAST_LOOP
:
974 case IPV6_MULTICAST_IF
:
978 case IPV6_MTU_DISCOVER
:
986 case IPV6_FLOWINFO_SEND
:
993 len
= min_t(unsigned int, sizeof(int), len
);
994 if(put_user(len
, optlen
))
996 if(copy_to_user(optval
,&val
,len
))
1001 int ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1002 char __user
*optval
, int __user
*optlen
)
1006 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
)
1007 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1009 if(level
!= SOL_IPV6
)
1010 return -ENOPROTOOPT
;
1012 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1013 #ifdef CONFIG_NETFILTER
1014 /* we need to exclude all possible EINVALs except default case */
1015 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1016 optname
!= MCAST_MSFILTER
) {
1019 if (get_user(len
, optlen
))
1023 err
= nf_getsockopt(sk
, PF_INET6
, optname
, optval
,
1027 err
= put_user(len
, optlen
);
1033 #ifdef CONFIG_COMPAT
1034 int compat_ipv6_getsockopt(struct sock
*sk
, int level
, int optname
,
1035 char __user
*optval
, int __user
*optlen
)
1039 if (level
== SOL_IP
&& sk
->sk_type
!= SOCK_RAW
) {
1040 if (udp_prot
.compat_getsockopt
!= NULL
)
1041 return udp_prot
.compat_getsockopt(sk
, level
, optname
,
1043 return udp_prot
.getsockopt(sk
, level
, optname
, optval
, optlen
);
1046 if (level
!= SOL_IPV6
)
1047 return -ENOPROTOOPT
;
1049 err
= do_ipv6_getsockopt(sk
, level
, optname
, optval
, optlen
);
1050 #ifdef CONFIG_NETFILTER
1051 /* we need to exclude all possible EINVALs except default case */
1052 if (err
== -EINVAL
&& optname
!= IPV6_ADDRFORM
&&
1053 optname
!= MCAST_MSFILTER
) {
1056 if (get_user(len
, optlen
))
1060 err
= compat_nf_getsockopt(sk
, PF_INET6
,
1061 optname
, optval
, &len
);
1064 err
= put_user(len
, optlen
);
1070 EXPORT_SYMBOL(compat_ipv6_getsockopt
);
1073 void __init
ipv6_packet_init(void)
1075 dev_add_pack(&ipv6_packet_type
);
1078 void ipv6_packet_cleanup(void)
1080 dev_remove_pack(&ipv6_packet_type
);