3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * This program is free software; you can redistribute it and/or
9 * modify it under the terms of the GNU General Public License
10 * as published by the Free Software Foundation; either version
11 * 2 of the License, or (at your option) any later version.
14 #include <linux/capability.h>
15 #include <linux/errno.h>
16 #include <linux/types.h>
17 #include <linux/kernel.h>
18 #include <linux/interrupt.h>
19 #include <linux/socket.h>
20 #include <linux/sockios.h>
21 #include <linux/in6.h>
22 #include <linux/ipv6.h>
23 #include <linux/route.h>
24 #include <linux/slab.h>
27 #include <net/ndisc.h>
28 #include <net/addrconf.h>
29 #include <net/transp_v6.h>
30 #include <net/ip6_route.h>
31 #include <net/tcp_states.h>
33 #include <linux/errqueue.h>
34 #include <asm/uaccess.h>
36 int ip6_datagram_connect(struct sock
*sk
, struct sockaddr
*uaddr
, int addr_len
)
38 struct sockaddr_in6
*usin
= (struct sockaddr_in6
*) uaddr
;
39 struct inet_sock
*inet
= inet_sk(sk
);
40 struct ipv6_pinfo
*np
= inet6_sk(sk
);
41 struct in6_addr
*daddr
, *final_p
, final
;
42 struct dst_entry
*dst
;
44 struct ip6_flowlabel
*flowlabel
= NULL
;
45 struct ipv6_txoptions
*opt
;
49 if (usin
->sin6_family
== AF_INET
) {
50 if (__ipv6_only_sock(sk
))
52 err
= ip4_datagram_connect(sk
, uaddr
, addr_len
);
56 if (addr_len
< SIN6_LEN_RFC2133
)
59 if (usin
->sin6_family
!= AF_INET6
)
62 memset(&fl6
, 0, sizeof(fl6
));
64 fl6
.flowlabel
= usin
->sin6_flowinfo
&IPV6_FLOWINFO_MASK
;
65 if (fl6
.flowlabel
&IPV6_FLOWLABEL_MASK
) {
66 flowlabel
= fl6_sock_lookup(sk
, fl6
.flowlabel
);
67 if (flowlabel
== NULL
)
69 ipv6_addr_copy(&usin
->sin6_addr
, &flowlabel
->dst
);
73 addr_type
= ipv6_addr_type(&usin
->sin6_addr
);
75 if (addr_type
== IPV6_ADDR_ANY
) {
79 usin
->sin6_addr
.s6_addr
[15] = 0x01;
82 daddr
= &usin
->sin6_addr
;
84 if (addr_type
== IPV6_ADDR_MAPPED
) {
85 struct sockaddr_in sin
;
87 if (__ipv6_only_sock(sk
)) {
91 sin
.sin_family
= AF_INET
;
92 sin
.sin_addr
.s_addr
= daddr
->s6_addr32
[3];
93 sin
.sin_port
= usin
->sin6_port
;
95 err
= ip4_datagram_connect(sk
,
96 (struct sockaddr
*) &sin
,
103 ipv6_addr_set_v4mapped(inet
->inet_daddr
, &np
->daddr
);
105 if (ipv6_addr_any(&np
->saddr
))
106 ipv6_addr_set_v4mapped(inet
->inet_saddr
, &np
->saddr
);
108 if (ipv6_addr_any(&np
->rcv_saddr
)) {
109 ipv6_addr_set_v4mapped(inet
->inet_rcv_saddr
,
111 if (sk
->sk_prot
->rehash
)
112 sk
->sk_prot
->rehash(sk
);
118 if (addr_type
&IPV6_ADDR_LINKLOCAL
) {
119 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
120 usin
->sin6_scope_id
) {
121 if (sk
->sk_bound_dev_if
&&
122 sk
->sk_bound_dev_if
!= usin
->sin6_scope_id
) {
126 sk
->sk_bound_dev_if
= usin
->sin6_scope_id
;
129 if (!sk
->sk_bound_dev_if
&& (addr_type
& IPV6_ADDR_MULTICAST
))
130 sk
->sk_bound_dev_if
= np
->mcast_oif
;
132 /* Connect to link-local address requires an interface */
133 if (!sk
->sk_bound_dev_if
) {
139 ipv6_addr_copy(&np
->daddr
, daddr
);
140 np
->flow_label
= fl6
.flowlabel
;
142 inet
->inet_dport
= usin
->sin6_port
;
145 * Check for a route to destination an obtain the
146 * destination cache for it.
149 fl6
.flowi6_proto
= sk
->sk_protocol
;
150 ipv6_addr_copy(&fl6
.daddr
, &np
->daddr
);
151 ipv6_addr_copy(&fl6
.saddr
, &np
->saddr
);
152 fl6
.flowi6_oif
= sk
->sk_bound_dev_if
;
153 fl6
.flowi6_mark
= sk
->sk_mark
;
154 fl6
.fl6_dport
= inet
->inet_dport
;
155 fl6
.fl6_sport
= inet
->inet_sport
;
157 if (!fl6
.flowi6_oif
&& (addr_type
&IPV6_ADDR_MULTICAST
))
158 fl6
.flowi6_oif
= np
->mcast_oif
;
160 security_sk_classify_flow(sk
, flowi6_to_flowi(&fl6
));
162 opt
= flowlabel
? flowlabel
->opt
: np
->opt
;
163 final_p
= fl6_update_dst(&fl6
, opt
, &final
);
165 dst
= ip6_dst_lookup_flow(sk
, &fl6
, final_p
, true);
172 /* source address lookup done in ip6_dst_lookup */
174 if (ipv6_addr_any(&np
->saddr
))
175 ipv6_addr_copy(&np
->saddr
, &fl6
.saddr
);
177 if (ipv6_addr_any(&np
->rcv_saddr
)) {
178 ipv6_addr_copy(&np
->rcv_saddr
, &fl6
.saddr
);
179 inet
->inet_rcv_saddr
= LOOPBACK4_IPV6
;
180 if (sk
->sk_prot
->rehash
)
181 sk
->sk_prot
->rehash(sk
);
184 ip6_dst_store(sk
, dst
,
185 ipv6_addr_equal(&fl6
.daddr
, &np
->daddr
) ?
187 #ifdef CONFIG_IPV6_SUBTREES
188 ipv6_addr_equal(&fl6
.saddr
, &np
->saddr
) ?
193 sk
->sk_state
= TCP_ESTABLISHED
;
195 fl6_sock_release(flowlabel
);
199 void ipv6_icmp_error(struct sock
*sk
, struct sk_buff
*skb
, int err
,
200 __be16 port
, u32 info
, u8
*payload
)
202 struct ipv6_pinfo
*np
= inet6_sk(sk
);
203 struct icmp6hdr
*icmph
= icmp6_hdr(skb
);
204 struct sock_exterr_skb
*serr
;
209 skb
= skb_clone(skb
, GFP_ATOMIC
);
213 skb
->protocol
= htons(ETH_P_IPV6
);
215 serr
= SKB_EXT_ERR(skb
);
216 serr
->ee
.ee_errno
= err
;
217 serr
->ee
.ee_origin
= SO_EE_ORIGIN_ICMP6
;
218 serr
->ee
.ee_type
= icmph
->icmp6_type
;
219 serr
->ee
.ee_code
= icmph
->icmp6_code
;
221 serr
->ee
.ee_info
= info
;
222 serr
->ee
.ee_data
= 0;
223 serr
->addr_offset
= (u8
*)&(((struct ipv6hdr
*)(icmph
+ 1))->daddr
) -
224 skb_network_header(skb
);
227 __skb_pull(skb
, payload
- skb
->data
);
228 skb_reset_transport_header(skb
);
230 if (sock_queue_err_skb(sk
, skb
))
234 void ipv6_local_error(struct sock
*sk
, int err
, struct flowi6
*fl6
, u32 info
)
236 struct ipv6_pinfo
*np
= inet6_sk(sk
);
237 struct sock_exterr_skb
*serr
;
244 skb
= alloc_skb(sizeof(struct ipv6hdr
), GFP_ATOMIC
);
248 skb
->protocol
= htons(ETH_P_IPV6
);
250 skb_put(skb
, sizeof(struct ipv6hdr
));
251 skb_reset_network_header(skb
);
253 ipv6_addr_copy(&iph
->daddr
, &fl6
->daddr
);
255 serr
= SKB_EXT_ERR(skb
);
256 serr
->ee
.ee_errno
= err
;
257 serr
->ee
.ee_origin
= SO_EE_ORIGIN_LOCAL
;
258 serr
->ee
.ee_type
= 0;
259 serr
->ee
.ee_code
= 0;
261 serr
->ee
.ee_info
= info
;
262 serr
->ee
.ee_data
= 0;
263 serr
->addr_offset
= (u8
*)&iph
->daddr
- skb_network_header(skb
);
264 serr
->port
= fl6
->fl6_dport
;
266 __skb_pull(skb
, skb_tail_pointer(skb
) - skb
->data
);
267 skb_reset_transport_header(skb
);
269 if (sock_queue_err_skb(sk
, skb
))
273 void ipv6_local_rxpmtu(struct sock
*sk
, struct flowi6
*fl6
, u32 mtu
)
275 struct ipv6_pinfo
*np
= inet6_sk(sk
);
278 struct ip6_mtuinfo
*mtu_info
;
280 if (!np
->rxopt
.bits
.rxpmtu
)
283 skb
= alloc_skb(sizeof(struct ipv6hdr
), GFP_ATOMIC
);
287 skb_put(skb
, sizeof(struct ipv6hdr
));
288 skb_reset_network_header(skb
);
290 ipv6_addr_copy(&iph
->daddr
, &fl6
->daddr
);
292 mtu_info
= IP6CBMTU(skb
);
298 mtu_info
->ip6m_mtu
= mtu
;
299 mtu_info
->ip6m_addr
.sin6_family
= AF_INET6
;
300 mtu_info
->ip6m_addr
.sin6_port
= 0;
301 mtu_info
->ip6m_addr
.sin6_flowinfo
= 0;
302 mtu_info
->ip6m_addr
.sin6_scope_id
= fl6
->flowi6_oif
;
303 ipv6_addr_copy(&mtu_info
->ip6m_addr
.sin6_addr
, &ipv6_hdr(skb
)->daddr
);
305 __skb_pull(skb
, skb_tail_pointer(skb
) - skb
->data
);
306 skb_reset_transport_header(skb
);
308 skb
= xchg(&np
->rxpmtu
, skb
);
313 * Handle MSG_ERRQUEUE
315 int ipv6_recv_error(struct sock
*sk
, struct msghdr
*msg
, int len
)
317 struct ipv6_pinfo
*np
= inet6_sk(sk
);
318 struct sock_exterr_skb
*serr
;
319 struct sk_buff
*skb
, *skb2
;
320 struct sockaddr_in6
*sin
;
322 struct sock_extended_err ee
;
323 struct sockaddr_in6 offender
;
329 skb
= skb_dequeue(&sk
->sk_error_queue
);
335 msg
->msg_flags
|= MSG_TRUNC
;
338 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
342 sock_recv_timestamp(msg
, sk
, skb
);
344 serr
= SKB_EXT_ERR(skb
);
346 sin
= (struct sockaddr_in6
*)msg
->msg_name
;
348 const unsigned char *nh
= skb_network_header(skb
);
349 sin
->sin6_family
= AF_INET6
;
350 sin
->sin6_flowinfo
= 0;
351 sin
->sin6_port
= serr
->port
;
352 sin
->sin6_scope_id
= 0;
353 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
354 ipv6_addr_copy(&sin
->sin6_addr
,
355 (struct in6_addr
*)(nh
+ serr
->addr_offset
));
358 (*(__be32
*)(nh
+ serr
->addr_offset
- 24) &
360 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
361 sin
->sin6_scope_id
= IP6CB(skb
)->iif
;
363 ipv6_addr_set_v4mapped(*(__be32
*)(nh
+ serr
->addr_offset
),
368 memcpy(&errhdr
.ee
, &serr
->ee
, sizeof(struct sock_extended_err
));
369 sin
= &errhdr
.offender
;
370 sin
->sin6_family
= AF_UNSPEC
;
371 if (serr
->ee
.ee_origin
!= SO_EE_ORIGIN_LOCAL
) {
372 sin
->sin6_family
= AF_INET6
;
373 sin
->sin6_flowinfo
= 0;
374 sin
->sin6_scope_id
= 0;
375 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
376 ipv6_addr_copy(&sin
->sin6_addr
, &ipv6_hdr(skb
)->saddr
);
378 datagram_recv_ctl(sk
, msg
, skb
);
379 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
380 sin
->sin6_scope_id
= IP6CB(skb
)->iif
;
382 struct inet_sock
*inet
= inet_sk(sk
);
384 ipv6_addr_set_v4mapped(ip_hdr(skb
)->saddr
,
386 if (inet
->cmsg_flags
)
387 ip_cmsg_recv(msg
, skb
);
391 put_cmsg(msg
, SOL_IPV6
, IPV6_RECVERR
, sizeof(errhdr
), &errhdr
);
393 /* Now we could try to dump offended packet options */
395 msg
->msg_flags
|= MSG_ERRQUEUE
;
398 /* Reset and regenerate socket error */
399 spin_lock_bh(&sk
->sk_error_queue
.lock
);
401 if ((skb2
= skb_peek(&sk
->sk_error_queue
)) != NULL
) {
402 sk
->sk_err
= SKB_EXT_ERR(skb2
)->ee
.ee_errno
;
403 spin_unlock_bh(&sk
->sk_error_queue
.lock
);
404 sk
->sk_error_report(sk
);
406 spin_unlock_bh(&sk
->sk_error_queue
.lock
);
416 * Handle IPV6_RECVPATHMTU
418 int ipv6_recv_rxpmtu(struct sock
*sk
, struct msghdr
*msg
, int len
)
420 struct ipv6_pinfo
*np
= inet6_sk(sk
);
422 struct sockaddr_in6
*sin
;
423 struct ip6_mtuinfo mtu_info
;
428 skb
= xchg(&np
->rxpmtu
, NULL
);
434 msg
->msg_flags
|= MSG_TRUNC
;
437 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
441 sock_recv_timestamp(msg
, sk
, skb
);
443 memcpy(&mtu_info
, IP6CBMTU(skb
), sizeof(mtu_info
));
445 sin
= (struct sockaddr_in6
*)msg
->msg_name
;
447 sin
->sin6_family
= AF_INET6
;
448 sin
->sin6_flowinfo
= 0;
450 sin
->sin6_scope_id
= mtu_info
.ip6m_addr
.sin6_scope_id
;
451 ipv6_addr_copy(&sin
->sin6_addr
, &mtu_info
.ip6m_addr
.sin6_addr
);
454 put_cmsg(msg
, SOL_IPV6
, IPV6_PATHMTU
, sizeof(mtu_info
), &mtu_info
);
465 int datagram_recv_ctl(struct sock
*sk
, struct msghdr
*msg
, struct sk_buff
*skb
)
467 struct ipv6_pinfo
*np
= inet6_sk(sk
);
468 struct inet6_skb_parm
*opt
= IP6CB(skb
);
469 unsigned char *nh
= skb_network_header(skb
);
471 if (np
->rxopt
.bits
.rxinfo
) {
472 struct in6_pktinfo src_info
;
474 src_info
.ipi6_ifindex
= opt
->iif
;
475 ipv6_addr_copy(&src_info
.ipi6_addr
, &ipv6_hdr(skb
)->daddr
);
476 put_cmsg(msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
479 if (np
->rxopt
.bits
.rxhlim
) {
480 int hlim
= ipv6_hdr(skb
)->hop_limit
;
481 put_cmsg(msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
484 if (np
->rxopt
.bits
.rxtclass
) {
485 int tclass
= (ntohl(*(__be32
*)ipv6_hdr(skb
)) >> 20) & 0xff;
486 put_cmsg(msg
, SOL_IPV6
, IPV6_TCLASS
, sizeof(tclass
), &tclass
);
489 if (np
->rxopt
.bits
.rxflow
&& (*(__be32
*)nh
& IPV6_FLOWINFO_MASK
)) {
490 __be32 flowinfo
= *(__be32
*)nh
& IPV6_FLOWINFO_MASK
;
491 put_cmsg(msg
, SOL_IPV6
, IPV6_FLOWINFO
, sizeof(flowinfo
), &flowinfo
);
494 /* HbH is allowed only once */
495 if (np
->rxopt
.bits
.hopopts
&& opt
->hop
) {
496 u8
*ptr
= nh
+ opt
->hop
;
497 put_cmsg(msg
, SOL_IPV6
, IPV6_HOPOPTS
, (ptr
[1]+1)<<3, ptr
);
501 (np
->rxopt
.bits
.dstopts
|| np
->rxopt
.bits
.srcrt
)) {
503 * Silly enough, but we need to reparse in order to
504 * report extension headers (except for HbH)
507 * Also note that IPV6_RECVRTHDRDSTOPTS is NOT
508 * (and WILL NOT be) defined because
509 * IPV6_RECVDSTOPTS is more generic. --yoshfuji
511 unsigned int off
= sizeof(struct ipv6hdr
);
512 u8 nexthdr
= ipv6_hdr(skb
)->nexthdr
;
514 while (off
<= opt
->lastopt
) {
519 case IPPROTO_DSTOPTS
:
521 len
= (ptr
[1] + 1) << 3;
522 if (np
->rxopt
.bits
.dstopts
)
523 put_cmsg(msg
, SOL_IPV6
, IPV6_DSTOPTS
, len
, ptr
);
525 case IPPROTO_ROUTING
:
527 len
= (ptr
[1] + 1) << 3;
528 if (np
->rxopt
.bits
.srcrt
)
529 put_cmsg(msg
, SOL_IPV6
, IPV6_RTHDR
, len
, ptr
);
533 len
= (ptr
[1] + 2) << 2;
537 len
= (ptr
[1] + 1) << 3;
545 /* socket options in old style */
546 if (np
->rxopt
.bits
.rxoinfo
) {
547 struct in6_pktinfo src_info
;
549 src_info
.ipi6_ifindex
= opt
->iif
;
550 ipv6_addr_copy(&src_info
.ipi6_addr
, &ipv6_hdr(skb
)->daddr
);
551 put_cmsg(msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
553 if (np
->rxopt
.bits
.rxohlim
) {
554 int hlim
= ipv6_hdr(skb
)->hop_limit
;
555 put_cmsg(msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
557 if (np
->rxopt
.bits
.ohopopts
&& opt
->hop
) {
558 u8
*ptr
= nh
+ opt
->hop
;
559 put_cmsg(msg
, SOL_IPV6
, IPV6_2292HOPOPTS
, (ptr
[1]+1)<<3, ptr
);
561 if (np
->rxopt
.bits
.odstopts
&& opt
->dst0
) {
562 u8
*ptr
= nh
+ opt
->dst0
;
563 put_cmsg(msg
, SOL_IPV6
, IPV6_2292DSTOPTS
, (ptr
[1]+1)<<3, ptr
);
565 if (np
->rxopt
.bits
.osrcrt
&& opt
->srcrt
) {
566 struct ipv6_rt_hdr
*rthdr
= (struct ipv6_rt_hdr
*)(nh
+ opt
->srcrt
);
567 put_cmsg(msg
, SOL_IPV6
, IPV6_2292RTHDR
, (rthdr
->hdrlen
+1) << 3, rthdr
);
569 if (np
->rxopt
.bits
.odstopts
&& opt
->dst1
) {
570 u8
*ptr
= nh
+ opt
->dst1
;
571 put_cmsg(msg
, SOL_IPV6
, IPV6_2292DSTOPTS
, (ptr
[1]+1)<<3, ptr
);
573 if (np
->rxopt
.bits
.rxorigdstaddr
) {
574 struct sockaddr_in6 sin6
;
575 u16
*ports
= (u16
*) skb_transport_header(skb
);
577 if (skb_transport_offset(skb
) + 4 <= skb
->len
) {
578 /* All current transport protocols have the port numbers in the
579 * first four bytes of the transport header and this function is
580 * written with this assumption in mind.
583 sin6
.sin6_family
= AF_INET6
;
584 ipv6_addr_copy(&sin6
.sin6_addr
, &ipv6_hdr(skb
)->daddr
);
585 sin6
.sin6_port
= ports
[1];
586 sin6
.sin6_flowinfo
= 0;
587 sin6
.sin6_scope_id
= 0;
589 put_cmsg(msg
, SOL_IPV6
, IPV6_ORIGDSTADDR
, sizeof(sin6
), &sin6
);
595 int datagram_send_ctl(struct net
*net
,
596 struct msghdr
*msg
, struct flowi6
*fl6
,
597 struct ipv6_txoptions
*opt
,
598 int *hlimit
, int *tclass
, int *dontfrag
)
600 struct in6_pktinfo
*src_info
;
601 struct cmsghdr
*cmsg
;
602 struct ipv6_rt_hdr
*rthdr
;
603 struct ipv6_opt_hdr
*hdr
;
607 for (cmsg
= CMSG_FIRSTHDR(msg
); cmsg
; cmsg
= CMSG_NXTHDR(msg
, cmsg
)) {
610 if (!CMSG_OK(msg
, cmsg
)) {
615 if (cmsg
->cmsg_level
!= SOL_IPV6
)
618 switch (cmsg
->cmsg_type
) {
620 case IPV6_2292PKTINFO
:
622 struct net_device
*dev
= NULL
;
624 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct in6_pktinfo
))) {
629 src_info
= (struct in6_pktinfo
*)CMSG_DATA(cmsg
);
631 if (src_info
->ipi6_ifindex
) {
632 if (fl6
->flowi6_oif
&&
633 src_info
->ipi6_ifindex
!= fl6
->flowi6_oif
)
635 fl6
->flowi6_oif
= src_info
->ipi6_ifindex
;
638 addr_type
= __ipv6_addr_type(&src_info
->ipi6_addr
);
641 if (fl6
->flowi6_oif
) {
642 dev
= dev_get_by_index_rcu(net
, fl6
->flowi6_oif
);
647 } else if (addr_type
& IPV6_ADDR_LINKLOCAL
) {
652 if (addr_type
!= IPV6_ADDR_ANY
) {
653 int strict
= __ipv6_addr_src_scope(addr_type
) <= IPV6_ADDR_SCOPE_LINKLOCAL
;
654 if (!ipv6_chk_addr(net
, &src_info
->ipi6_addr
,
655 strict
? dev
: NULL
, 0))
658 ipv6_addr_copy(&fl6
->saddr
, &src_info
->ipi6_addr
);
670 if (cmsg
->cmsg_len
< CMSG_LEN(4)) {
675 if (fl6
->flowlabel
&IPV6_FLOWINFO_MASK
) {
676 if ((fl6
->flowlabel
^*(__be32
*)CMSG_DATA(cmsg
))&~IPV6_FLOWINFO_MASK
) {
681 fl6
->flowlabel
= IPV6_FLOWINFO_MASK
& *(__be32
*)CMSG_DATA(cmsg
);
684 case IPV6_2292HOPOPTS
:
686 if (opt
->hopopt
|| cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
691 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
692 len
= ((hdr
->hdrlen
+ 1) << 3);
693 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
697 if (!capable(CAP_NET_RAW
)) {
701 opt
->opt_nflen
+= len
;
705 case IPV6_2292DSTOPTS
:
706 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
711 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
712 len
= ((hdr
->hdrlen
+ 1) << 3);
713 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
717 if (!capable(CAP_NET_RAW
)) {
725 opt
->opt_flen
+= len
;
730 case IPV6_RTHDRDSTOPTS
:
731 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
736 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
737 len
= ((hdr
->hdrlen
+ 1) << 3);
738 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
742 if (!capable(CAP_NET_RAW
)) {
746 if (cmsg
->cmsg_type
== IPV6_DSTOPTS
) {
747 opt
->opt_flen
+= len
;
750 opt
->opt_nflen
+= len
;
757 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_rt_hdr
))) {
762 rthdr
= (struct ipv6_rt_hdr
*)CMSG_DATA(cmsg
);
764 switch (rthdr
->type
) {
765 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
766 case IPV6_SRCRT_TYPE_2
:
767 if (rthdr
->hdrlen
!= 2 ||
768 rthdr
->segments_left
!= 1) {
779 len
= ((rthdr
->hdrlen
+ 1) << 3);
781 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
786 /* segments left must also match */
787 if ((rthdr
->hdrlen
>> 1) != rthdr
->segments_left
) {
792 opt
->opt_nflen
+= len
;
795 if (cmsg
->cmsg_type
== IPV6_2292RTHDR
&& opt
->dst1opt
) {
796 int dsthdrlen
= ((opt
->dst1opt
->hdrlen
+1)<<3);
798 opt
->opt_nflen
+= dsthdrlen
;
799 opt
->dst0opt
= opt
->dst1opt
;
801 opt
->opt_flen
-= dsthdrlen
;
806 case IPV6_2292HOPLIMIT
:
808 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
813 *hlimit
= *(int *)CMSG_DATA(cmsg
);
814 if (*hlimit
< -1 || *hlimit
> 0xff) {
826 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
830 tc
= *(int *)CMSG_DATA(cmsg
);
831 if (tc
< -1 || tc
> 0xff)
845 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
849 df
= *(int *)CMSG_DATA(cmsg
);
850 if (df
< 0 || df
> 1)
859 LIMIT_NETDEBUG(KERN_DEBUG
"invalid cmsg type: %d\n",