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 * This program is free software; you can redistribute it and/or
11 * modify it under the terms of the GNU General Public License
12 * as published by the Free Software Foundation; either version
13 * 2 of the License, or (at your option) any later version.
15 * FIXME: Make the setsockopt code POSIX compliant: That is
17 * o Truncate getsockopt returns
18 * o Return an optlen of the truncated length if need be
21 * David L Stevens <dlstevens@us.ibm.com>:
22 * - added multicast source filtering API for MLDv2
25 #include <linux/module.h>
26 #include <linux/capability.h>
27 #include <linux/errno.h>
28 #include <linux/types.h>
29 #include <linux/socket.h>
30 #include <linux/sockios.h>
31 #include <linux/net.h>
32 #include <linux/in6.h>
33 #include <linux/mroute6.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_arp.h>
36 #include <linux/init.h>
37 #include <linux/sysctl.h>
38 #include <linux/netfilter.h>
39 #include <linux/slab.h>
44 #include <net/ndisc.h>
45 #include <net/protocol.h>
46 #include <net/transp_v6.h>
47 #include <net/ip6_route.h>
48 #include <net/addrconf.h>
49 #include <net/inet_common.h>
52 #include <net/udplite.h>
54 #include <net/compat.h>
56 #include <asm/uaccess.h>
58 struct ip6_ra_chain *ip6_ra_chain;
59 DEFINE_RWLOCK(ip6_ra_lock);
61 int ip6_ra_control(struct sock *sk, int sel)
63 struct ip6_ra_chain *ra, *new_ra, **rap;
65 /* RA packet may be delivered ONLY to IPPROTO_RAW socket */
66 if (sk->sk_type != SOCK_RAW || inet_sk(sk)->inet_num != IPPROTO_RAW)
69 new_ra = (sel>=0) ? kmalloc(sizeof(*new_ra), GFP_KERNEL) : NULL;
71 write_lock_bh(&ip6_ra_lock);
72 for (rap = &ip6_ra_chain; (ra=*rap) != NULL; rap = &ra->next) {
75 write_unlock_bh(&ip6_ra_lock);
81 write_unlock_bh(&ip6_ra_lock);
89 write_unlock_bh(&ip6_ra_lock);
97 write_unlock_bh(&ip6_ra_lock);
102 struct ipv6_txoptions *ipv6_update_options(struct sock *sk,
103 struct ipv6_txoptions *opt)
105 if (inet_sk(sk)->is_icsk) {
107 !((1 << sk->sk_state) & (TCPF_LISTEN | TCPF_CLOSE)) &&
108 inet_sk(sk)->inet_daddr != LOOPBACK4_IPV6) {
109 struct inet_connection_sock *icsk = inet_csk(sk);
110 icsk->icsk_ext_hdr_len = opt->opt_flen + opt->opt_nflen;
111 icsk->icsk_sync_mss(sk, icsk->icsk_pmtu_cookie);
113 opt = xchg(&inet6_sk(sk)->opt, opt);
115 spin_lock(&sk->sk_dst_lock);
116 opt = xchg(&inet6_sk(sk)->opt, opt);
117 spin_unlock(&sk->sk_dst_lock);
124 static int do_ipv6_setsockopt(struct sock *sk, int level, int optname,
125 char __user *optval, unsigned int optlen)
127 struct ipv6_pinfo *np = inet6_sk(sk);
128 struct net *net = sock_net(sk);
130 int retv = -ENOPROTOOPT;
135 if (optlen >= sizeof(int)) {
136 if (get_user(val, (int __user *) optval))
144 if (ip6_mroute_opt(optname))
145 return ip6_mroute_setsockopt(sk, optname, optval, optlen);
152 if (optlen < sizeof(int))
154 if (val == PF_INET) {
155 struct ipv6_txoptions *opt;
156 struct sk_buff *pktopt;
158 if (sk->sk_type == SOCK_RAW)
161 if (sk->sk_protocol == IPPROTO_UDP ||
162 sk->sk_protocol == IPPROTO_UDPLITE) {
163 struct udp_sock *up = udp_sk(sk);
164 if (up->pending == AF_INET6) {
168 } else if (sk->sk_protocol != IPPROTO_TCP)
171 if (sk->sk_state != TCP_ESTABLISHED) {
176 if (ipv6_only_sock(sk) ||
177 !ipv6_addr_v4mapped(&np->daddr)) {
178 retv = -EADDRNOTAVAIL;
182 fl6_free_socklist(sk);
183 ipv6_sock_mc_close(sk);
186 * Sock is moving from IPv6 to IPv4 (sk_prot), so
187 * remove it from the refcnt debug socks count in the
190 sk_refcnt_debug_dec(sk);
192 if (sk->sk_protocol == IPPROTO_TCP) {
193 struct inet_connection_sock *icsk = inet_csk(sk);
195 sock_prot_inuse_add(net, sk->sk_prot, -1);
196 sock_prot_inuse_add(net, &tcp_prot, 1);
198 sk->sk_prot = &tcp_prot;
199 icsk->icsk_af_ops = &ipv4_specific;
200 sk->sk_socket->ops = &inet_stream_ops;
201 sk->sk_family = PF_INET;
202 tcp_sync_mss(sk, icsk->icsk_pmtu_cookie);
204 struct proto *prot = &udp_prot;
206 if (sk->sk_protocol == IPPROTO_UDPLITE)
207 prot = &udplite_prot;
209 sock_prot_inuse_add(net, sk->sk_prot, -1);
210 sock_prot_inuse_add(net, prot, 1);
213 sk->sk_socket->ops = &inet_dgram_ops;
214 sk->sk_family = PF_INET;
216 opt = xchg(&np->opt, NULL);
218 sock_kfree_s(sk, opt, opt->tot_len);
219 pktopt = xchg(&np->pktoptions, NULL);
222 sk->sk_destruct = inet_sock_destruct;
224 * ... and add it to the refcnt debug socks count
225 * in the new family. -acme
227 sk_refcnt_debug_inc(sk);
228 module_put(THIS_MODULE);
235 if (optlen < sizeof(int) ||
236 inet_sk(sk)->inet_num)
238 np->ipv6only = valbool;
242 case IPV6_RECVPKTINFO:
243 if (optlen < sizeof(int))
245 np->rxopt.bits.rxinfo = valbool;
249 case IPV6_2292PKTINFO:
250 if (optlen < sizeof(int))
252 np->rxopt.bits.rxoinfo = valbool;
256 case IPV6_RECVHOPLIMIT:
257 if (optlen < sizeof(int))
259 np->rxopt.bits.rxhlim = valbool;
263 case IPV6_2292HOPLIMIT:
264 if (optlen < sizeof(int))
266 np->rxopt.bits.rxohlim = valbool;
271 if (optlen < sizeof(int))
273 np->rxopt.bits.srcrt = valbool;
278 if (optlen < sizeof(int))
280 np->rxopt.bits.osrcrt = valbool;
284 case IPV6_RECVHOPOPTS:
285 if (optlen < sizeof(int))
287 np->rxopt.bits.hopopts = valbool;
291 case IPV6_2292HOPOPTS:
292 if (optlen < sizeof(int))
294 np->rxopt.bits.ohopopts = valbool;
298 case IPV6_RECVDSTOPTS:
299 if (optlen < sizeof(int))
301 np->rxopt.bits.dstopts = valbool;
305 case IPV6_2292DSTOPTS:
306 if (optlen < sizeof(int))
308 np->rxopt.bits.odstopts = valbool;
313 if (optlen < sizeof(int))
315 if (val < -1 || val > 0xff)
317 /* RFC 3542, 6.5: default traffic class of 0x0 */
324 case IPV6_RECVTCLASS:
325 if (optlen < sizeof(int))
327 np->rxopt.bits.rxtclass = valbool;
332 if (optlen < sizeof(int))
334 np->rxopt.bits.rxflow = valbool;
338 case IPV6_RECVPATHMTU:
339 if (optlen < sizeof(int))
341 np->rxopt.bits.rxpmtu = valbool;
345 case IPV6_TRANSPARENT:
346 if (optlen < sizeof(int))
348 /* we don't have a separate transparent bit for IPV6 we use the one in the IPv4 socket */
349 inet_sk(sk)->transparent = valbool;
353 case IPV6_RECVORIGDSTADDR:
354 if (optlen < sizeof(int))
356 np->rxopt.bits.rxorigdstaddr = valbool;
361 case IPV6_RTHDRDSTOPTS:
365 struct ipv6_txoptions *opt;
367 /* remove any sticky options header with a zero option
368 * length, per RFC3542.
372 else if (optval == NULL)
374 else if (optlen < sizeof(struct ipv6_opt_hdr) ||
375 optlen & 0x7 || optlen > 8 * 255)
378 /* hop-by-hop / destination options are privileged option */
380 if (optname != IPV6_RTHDR && !capable(CAP_NET_RAW))
383 opt = ipv6_renew_options(sk, np->opt, optname,
384 (struct ipv6_opt_hdr __user *)optval,
391 /* routing header option needs extra check */
393 if (optname == IPV6_RTHDR && opt && opt->srcrt) {
394 struct ipv6_rt_hdr *rthdr = opt->srcrt;
395 switch (rthdr->type) {
396 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
397 case IPV6_SRCRT_TYPE_2:
398 if (rthdr->hdrlen != 2 ||
399 rthdr->segments_left != 1)
410 opt = ipv6_update_options(sk, opt);
413 sock_kfree_s(sk, opt, opt->tot_len);
419 struct in6_pktinfo pkt;
423 else if (optlen < sizeof(struct in6_pktinfo) || optval == NULL)
426 if (copy_from_user(&pkt, optval, sizeof(struct in6_pktinfo))) {
430 if (sk->sk_bound_dev_if && pkt.ipi6_ifindex != sk->sk_bound_dev_if)
433 np->sticky_pktinfo.ipi6_ifindex = pkt.ipi6_ifindex;
434 ipv6_addr_copy(&np->sticky_pktinfo.ipi6_addr, &pkt.ipi6_addr);
439 case IPV6_2292PKTOPTIONS:
441 struct ipv6_txoptions *opt = NULL;
446 fl.fl6_flowlabel = 0;
447 fl.oif = sk->sk_bound_dev_if;
448 fl.mark = sk->sk_mark;
453 /* 1K is probably excessive
454 * 1K is surely not enough, 2K per standard header is 16K.
457 if (optlen > 64*1024)
460 opt = sock_kmalloc(sk, sizeof(*opt) + optlen, GFP_KERNEL);
465 memset(opt, 0, sizeof(*opt));
466 opt->tot_len = sizeof(*opt) + optlen;
468 if (copy_from_user(opt+1, optval, optlen))
471 msg.msg_controllen = optlen;
472 msg.msg_control = (void*)(opt+1);
474 retv = datagram_send_ctl(net, &msg, &fl, opt, &junk, &junk,
480 opt = ipv6_update_options(sk, opt);
483 sock_kfree_s(sk, opt, opt->tot_len);
486 case IPV6_UNICAST_HOPS:
487 if (optlen < sizeof(int))
489 if (val > 255 || val < -1)
495 case IPV6_MULTICAST_HOPS:
496 if (sk->sk_type == SOCK_STREAM)
498 if (optlen < sizeof(int))
500 if (val > 255 || val < -1)
502 np->mcast_hops = val;
506 case IPV6_MULTICAST_LOOP:
507 if (optlen < sizeof(int))
511 np->mc_loop = valbool;
515 case IPV6_MULTICAST_IF:
516 if (sk->sk_type == SOCK_STREAM)
518 if (optlen < sizeof(int))
522 struct net_device *dev;
524 if (sk->sk_bound_dev_if && sk->sk_bound_dev_if != val)
527 dev = dev_get_by_index(net, val);
537 case IPV6_ADD_MEMBERSHIP:
538 case IPV6_DROP_MEMBERSHIP:
540 struct ipv6_mreq mreq;
542 if (optlen < sizeof(struct ipv6_mreq))
546 if (inet_sk(sk)->is_icsk)
550 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
553 if (optname == IPV6_ADD_MEMBERSHIP)
554 retv = ipv6_sock_mc_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
556 retv = ipv6_sock_mc_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_multiaddr);
559 case IPV6_JOIN_ANYCAST:
560 case IPV6_LEAVE_ANYCAST:
562 struct ipv6_mreq mreq;
564 if (optlen < sizeof(struct ipv6_mreq))
568 if (copy_from_user(&mreq, optval, sizeof(struct ipv6_mreq)))
571 if (optname == IPV6_JOIN_ANYCAST)
572 retv = ipv6_sock_ac_join(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
574 retv = ipv6_sock_ac_drop(sk, mreq.ipv6mr_ifindex, &mreq.ipv6mr_acaddr);
577 case MCAST_JOIN_GROUP:
578 case MCAST_LEAVE_GROUP:
580 struct group_req greq;
581 struct sockaddr_in6 *psin6;
583 if (optlen < sizeof(struct group_req))
587 if (copy_from_user(&greq, optval, sizeof(struct group_req)))
589 if (greq.gr_group.ss_family != AF_INET6) {
590 retv = -EADDRNOTAVAIL;
593 psin6 = (struct sockaddr_in6 *)&greq.gr_group;
594 if (optname == MCAST_JOIN_GROUP)
595 retv = ipv6_sock_mc_join(sk, greq.gr_interface,
598 retv = ipv6_sock_mc_drop(sk, greq.gr_interface,
602 case MCAST_JOIN_SOURCE_GROUP:
603 case MCAST_LEAVE_SOURCE_GROUP:
604 case MCAST_BLOCK_SOURCE:
605 case MCAST_UNBLOCK_SOURCE:
607 struct group_source_req greqs;
610 if (optlen < sizeof(struct group_source_req))
612 if (copy_from_user(&greqs, optval, sizeof(greqs))) {
616 if (greqs.gsr_group.ss_family != AF_INET6 ||
617 greqs.gsr_source.ss_family != AF_INET6) {
618 retv = -EADDRNOTAVAIL;
621 if (optname == MCAST_BLOCK_SOURCE) {
622 omode = MCAST_EXCLUDE;
624 } else if (optname == MCAST_UNBLOCK_SOURCE) {
625 omode = MCAST_EXCLUDE;
627 } else if (optname == MCAST_JOIN_SOURCE_GROUP) {
628 struct sockaddr_in6 *psin6;
630 psin6 = (struct sockaddr_in6 *)&greqs.gsr_group;
631 retv = ipv6_sock_mc_join(sk, greqs.gsr_interface,
633 /* prior join w/ different source is ok */
634 if (retv && retv != -EADDRINUSE)
636 omode = MCAST_INCLUDE;
638 } else /* MCAST_LEAVE_SOURCE_GROUP */ {
639 omode = MCAST_INCLUDE;
642 retv = ip6_mc_source(add, omode, sk, &greqs);
647 extern int sysctl_mld_max_msf;
648 struct group_filter *gsf;
650 if (optlen < GROUP_FILTER_SIZE(0))
652 if (optlen > sysctl_optmem_max) {
656 gsf = kmalloc(optlen,GFP_KERNEL);
662 if (copy_from_user(gsf, optval, optlen)) {
666 /* numsrc >= (4G-140)/128 overflow in 32 bits */
667 if (gsf->gf_numsrc >= 0x1ffffffU ||
668 gsf->gf_numsrc > sysctl_mld_max_msf) {
673 if (GROUP_FILTER_SIZE(gsf->gf_numsrc) > optlen) {
678 retv = ip6_mc_msfilter(sk, gsf);
683 case IPV6_ROUTER_ALERT:
684 if (optlen < sizeof(int))
686 retv = ip6_ra_control(sk, val);
688 case IPV6_MTU_DISCOVER:
689 if (optlen < sizeof(int))
691 if (val < IP_PMTUDISC_DONT || val > IP_PMTUDISC_PROBE)
697 if (optlen < sizeof(int))
699 if (val && val < IPV6_MIN_MTU)
705 if (optlen < sizeof(int))
707 np->recverr = valbool;
709 skb_queue_purge(&sk->sk_error_queue);
712 case IPV6_FLOWINFO_SEND:
713 if (optlen < sizeof(int))
715 np->sndflow = valbool;
718 case IPV6_FLOWLABEL_MGR:
719 retv = ipv6_flowlabel_opt(sk, optval, optlen);
721 case IPV6_IPSEC_POLICY:
722 case IPV6_XFRM_POLICY:
724 if (!capable(CAP_NET_ADMIN))
726 retv = xfrm_user_policy(sk, optname, optval, optlen);
729 case IPV6_ADDR_PREFERENCES:
731 unsigned int pref = 0;
732 unsigned int prefmask = ~0;
734 if (optlen < sizeof(int))
739 /* check PUBLIC/TMP/PUBTMP_DEFAULT conflicts */
740 switch (val & (IPV6_PREFER_SRC_PUBLIC|
742 IPV6_PREFER_SRC_PUBTMP_DEFAULT)) {
743 case IPV6_PREFER_SRC_PUBLIC:
744 pref |= IPV6_PREFER_SRC_PUBLIC;
746 case IPV6_PREFER_SRC_TMP:
747 pref |= IPV6_PREFER_SRC_TMP;
749 case IPV6_PREFER_SRC_PUBTMP_DEFAULT:
752 goto pref_skip_pubtmp;
757 prefmask &= ~(IPV6_PREFER_SRC_PUBLIC|
758 IPV6_PREFER_SRC_TMP);
761 /* check HOME/COA conflicts */
762 switch (val & (IPV6_PREFER_SRC_HOME|IPV6_PREFER_SRC_COA)) {
763 case IPV6_PREFER_SRC_HOME:
765 case IPV6_PREFER_SRC_COA:
766 pref |= IPV6_PREFER_SRC_COA;
773 prefmask &= ~IPV6_PREFER_SRC_COA;
776 /* check CGA/NONCGA conflicts */
777 switch (val & (IPV6_PREFER_SRC_CGA|IPV6_PREFER_SRC_NONCGA)) {
778 case IPV6_PREFER_SRC_CGA:
779 case IPV6_PREFER_SRC_NONCGA:
786 np->srcprefs = (np->srcprefs & prefmask) | pref;
791 case IPV6_MINHOPCOUNT:
792 if (optlen < sizeof(int))
794 if (val < 0 || val > 255)
796 np->min_hopcount = val;
799 np->dontfrag = valbool;
813 int ipv6_setsockopt(struct sock *sk, int level, int optname,
814 char __user *optval, unsigned int optlen)
818 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
819 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
821 if (level != SOL_IPV6)
824 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
825 #ifdef CONFIG_NETFILTER
826 /* we need to exclude all possible ENOPROTOOPTs except default case */
827 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
828 optname != IPV6_XFRM_POLICY) {
830 err = nf_setsockopt(sk, PF_INET6, optname, optval,
838 EXPORT_SYMBOL(ipv6_setsockopt);
841 int compat_ipv6_setsockopt(struct sock *sk, int level, int optname,
842 char __user *optval, unsigned int optlen)
846 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
847 if (udp_prot.compat_setsockopt != NULL)
848 return udp_prot.compat_setsockopt(sk, level, optname,
850 return udp_prot.setsockopt(sk, level, optname, optval, optlen);
853 if (level != SOL_IPV6)
856 if (optname >= MCAST_JOIN_GROUP && optname <= MCAST_MSFILTER)
857 return compat_mc_setsockopt(sk, level, optname, optval, optlen,
860 err = do_ipv6_setsockopt(sk, level, optname, optval, optlen);
861 #ifdef CONFIG_NETFILTER
862 /* we need to exclude all possible ENOPROTOOPTs except default case */
863 if (err == -ENOPROTOOPT && optname != IPV6_IPSEC_POLICY &&
864 optname != IPV6_XFRM_POLICY) {
866 err = compat_nf_setsockopt(sk, PF_INET6, optname,
874 EXPORT_SYMBOL(compat_ipv6_setsockopt);
877 static int ipv6_getsockopt_sticky(struct sock *sk, struct ipv6_txoptions *opt,
878 int optname, char __user *optval, int len)
880 struct ipv6_opt_hdr *hdr;
889 case IPV6_RTHDRDSTOPTS:
893 hdr = (struct ipv6_opt_hdr *)opt->srcrt;
899 return -EINVAL; /* should not happen */
905 len = min_t(unsigned int, len, ipv6_optlen(hdr));
906 if (copy_to_user(optval, hdr, len))
911 static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
912 char __user *optval, int __user *optlen)
914 struct ipv6_pinfo *np = inet6_sk(sk);
918 if (ip6_mroute_opt(optname))
919 return ip6_mroute_getsockopt(sk, optname, optval, optlen);
921 if (get_user(len, optlen))
925 if (sk->sk_protocol != IPPROTO_UDP &&
926 sk->sk_protocol != IPPROTO_UDPLITE &&
927 sk->sk_protocol != IPPROTO_TCP)
929 if (sk->sk_state != TCP_ESTABLISHED)
935 struct group_filter gsf;
938 if (len < GROUP_FILTER_SIZE(0))
940 if (copy_from_user(&gsf, optval, GROUP_FILTER_SIZE(0)))
942 if (gsf.gf_group.ss_family != AF_INET6)
943 return -EADDRNOTAVAIL;
945 err = ip6_mc_msfget(sk, &gsf,
946 (struct group_filter __user *)optval, optlen);
951 case IPV6_2292PKTOPTIONS:
956 if (sk->sk_type != SOCK_STREAM)
959 msg.msg_control = optval;
960 msg.msg_controllen = len;
964 skb = np->pktoptions;
966 atomic_inc(&skb->users);
970 int err = datagram_recv_ctl(sk, &msg, skb);
975 if (np->rxopt.bits.rxinfo) {
976 struct in6_pktinfo src_info;
977 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif :
978 np->sticky_pktinfo.ipi6_ifindex;
979 np->mcast_oif? ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr) :
980 ipv6_addr_copy(&src_info.ipi6_addr, &(np->sticky_pktinfo.ipi6_addr));
981 put_cmsg(&msg, SOL_IPV6, IPV6_PKTINFO, sizeof(src_info), &src_info);
983 if (np->rxopt.bits.rxhlim) {
984 int hlim = np->mcast_hops;
985 put_cmsg(&msg, SOL_IPV6, IPV6_HOPLIMIT, sizeof(hlim), &hlim);
987 if (np->rxopt.bits.rxoinfo) {
988 struct in6_pktinfo src_info;
989 src_info.ipi6_ifindex = np->mcast_oif ? np->mcast_oif :
990 np->sticky_pktinfo.ipi6_ifindex;
991 np->mcast_oif? ipv6_addr_copy(&src_info.ipi6_addr, &np->daddr) :
992 ipv6_addr_copy(&src_info.ipi6_addr, &(np->sticky_pktinfo.ipi6_addr));
993 put_cmsg(&msg, SOL_IPV6, IPV6_2292PKTINFO, sizeof(src_info), &src_info);
995 if (np->rxopt.bits.rxohlim) {
996 int hlim = np->mcast_hops;
997 put_cmsg(&msg, SOL_IPV6, IPV6_2292HOPLIMIT, sizeof(hlim), &hlim);
1000 len -= msg.msg_controllen;
1001 return put_user(len, optlen);
1005 struct dst_entry *dst;
1009 dst = __sk_dst_get(sk);
1022 case IPV6_RECVPKTINFO:
1023 val = np->rxopt.bits.rxinfo;
1026 case IPV6_2292PKTINFO:
1027 val = np->rxopt.bits.rxoinfo;
1030 case IPV6_RECVHOPLIMIT:
1031 val = np->rxopt.bits.rxhlim;
1034 case IPV6_2292HOPLIMIT:
1035 val = np->rxopt.bits.rxohlim;
1038 case IPV6_RECVRTHDR:
1039 val = np->rxopt.bits.srcrt;
1042 case IPV6_2292RTHDR:
1043 val = np->rxopt.bits.osrcrt;
1047 case IPV6_RTHDRDSTOPTS:
1053 len = ipv6_getsockopt_sticky(sk, np->opt,
1054 optname, optval, len);
1056 /* check if ipv6_getsockopt_sticky() returns err code */
1059 return put_user(len, optlen);
1062 case IPV6_RECVHOPOPTS:
1063 val = np->rxopt.bits.hopopts;
1066 case IPV6_2292HOPOPTS:
1067 val = np->rxopt.bits.ohopopts;
1070 case IPV6_RECVDSTOPTS:
1071 val = np->rxopt.bits.dstopts;
1074 case IPV6_2292DSTOPTS:
1075 val = np->rxopt.bits.odstopts;
1082 case IPV6_RECVTCLASS:
1083 val = np->rxopt.bits.rxtclass;
1087 val = np->rxopt.bits.rxflow;
1090 case IPV6_RECVPATHMTU:
1091 val = np->rxopt.bits.rxpmtu;
1096 struct dst_entry *dst;
1097 struct ip6_mtuinfo mtuinfo;
1099 if (len < sizeof(mtuinfo))
1102 len = sizeof(mtuinfo);
1103 memset(&mtuinfo, 0, sizeof(mtuinfo));
1106 dst = __sk_dst_get(sk);
1108 mtuinfo.ip6m_mtu = dst_mtu(dst);
1110 if (!mtuinfo.ip6m_mtu)
1113 if (put_user(len, optlen))
1115 if (copy_to_user(optval, &mtuinfo, len))
1122 case IPV6_TRANSPARENT:
1123 val = inet_sk(sk)->transparent;
1126 case IPV6_RECVORIGDSTADDR:
1127 val = np->rxopt.bits.rxorigdstaddr;
1130 case IPV6_UNICAST_HOPS:
1131 case IPV6_MULTICAST_HOPS:
1133 struct dst_entry *dst;
1135 if (optname == IPV6_UNICAST_HOPS)
1136 val = np->hop_limit;
1138 val = np->mcast_hops;
1142 dst = __sk_dst_get(sk);
1144 val = ip6_dst_hoplimit(dst);
1149 val = sock_net(sk)->ipv6.devconf_all->hop_limit;
1153 case IPV6_MULTICAST_LOOP:
1157 case IPV6_MULTICAST_IF:
1158 val = np->mcast_oif;
1161 case IPV6_MTU_DISCOVER:
1169 case IPV6_FLOWINFO_SEND:
1173 case IPV6_ADDR_PREFERENCES:
1176 if (np->srcprefs & IPV6_PREFER_SRC_TMP)
1177 val |= IPV6_PREFER_SRC_TMP;
1178 else if (np->srcprefs & IPV6_PREFER_SRC_PUBLIC)
1179 val |= IPV6_PREFER_SRC_PUBLIC;
1181 /* XXX: should we return system default? */
1182 val |= IPV6_PREFER_SRC_PUBTMP_DEFAULT;
1185 if (np->srcprefs & IPV6_PREFER_SRC_COA)
1186 val |= IPV6_PREFER_SRC_COA;
1188 val |= IPV6_PREFER_SRC_HOME;
1191 case IPV6_MINHOPCOUNT:
1192 val = np->min_hopcount;
1200 return -ENOPROTOOPT;
1202 len = min_t(unsigned int, sizeof(int), len);
1203 if(put_user(len, optlen))
1205 if(copy_to_user(optval,&val,len))
1210 int ipv6_getsockopt(struct sock *sk, int level, int optname,
1211 char __user *optval, int __user *optlen)
1215 if (level == SOL_IP && sk->sk_type != SOCK_RAW)
1216 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1218 if(level != SOL_IPV6)
1219 return -ENOPROTOOPT;
1221 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1222 #ifdef CONFIG_NETFILTER
1223 /* we need to exclude all possible ENOPROTOOPTs except default case */
1224 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1227 if (get_user(len, optlen))
1231 err = nf_getsockopt(sk, PF_INET6, optname, optval,
1235 err = put_user(len, optlen);
1241 EXPORT_SYMBOL(ipv6_getsockopt);
1243 #ifdef CONFIG_COMPAT
1244 int compat_ipv6_getsockopt(struct sock *sk, int level, int optname,
1245 char __user *optval, int __user *optlen)
1249 if (level == SOL_IP && sk->sk_type != SOCK_RAW) {
1250 if (udp_prot.compat_getsockopt != NULL)
1251 return udp_prot.compat_getsockopt(sk, level, optname,
1253 return udp_prot.getsockopt(sk, level, optname, optval, optlen);
1256 if (level != SOL_IPV6)
1257 return -ENOPROTOOPT;
1259 if (optname == MCAST_MSFILTER)
1260 return compat_mc_getsockopt(sk, level, optname, optval, optlen,
1263 err = do_ipv6_getsockopt(sk, level, optname, optval, optlen);
1264 #ifdef CONFIG_NETFILTER
1265 /* we need to exclude all possible ENOPROTOOPTs except default case */
1266 if (err == -ENOPROTOOPT && optname != IPV6_2292PKTOPTIONS) {
1269 if (get_user(len, optlen))
1273 err = compat_nf_getsockopt(sk, PF_INET6,
1274 optname, optval, &len);
1277 err = put_user(len, optlen);
1283 EXPORT_SYMBOL(compat_ipv6_getsockopt);