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(&fl
, 0, sizeof(fl
));
64 fl
.fl6_flowlabel
= usin
->sin6_flowinfo
&IPV6_FLOWINFO_MASK
;
65 if (fl
.fl6_flowlabel
&IPV6_FLOWLABEL_MASK
) {
66 flowlabel
= fl6_sock_lookup(sk
, fl
.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
,
115 if (addr_type
&IPV6_ADDR_LINKLOCAL
) {
116 if (addr_len
>= sizeof(struct sockaddr_in6
) &&
117 usin
->sin6_scope_id
) {
118 if (sk
->sk_bound_dev_if
&&
119 sk
->sk_bound_dev_if
!= usin
->sin6_scope_id
) {
123 sk
->sk_bound_dev_if
= usin
->sin6_scope_id
;
126 if (!sk
->sk_bound_dev_if
&& (addr_type
& IPV6_ADDR_MULTICAST
))
127 sk
->sk_bound_dev_if
= np
->mcast_oif
;
129 /* Connect to link-local address requires an interface */
130 if (!sk
->sk_bound_dev_if
) {
136 ipv6_addr_copy(&np
->daddr
, daddr
);
137 np
->flow_label
= fl
.fl6_flowlabel
;
139 inet
->inet_dport
= usin
->sin6_port
;
142 * Check for a route to destination an obtain the
143 * destination cache for it.
146 fl
.proto
= sk
->sk_protocol
;
147 ipv6_addr_copy(&fl
.fl6_dst
, &np
->daddr
);
148 ipv6_addr_copy(&fl
.fl6_src
, &np
->saddr
);
149 fl
.oif
= sk
->sk_bound_dev_if
;
150 fl
.mark
= sk
->sk_mark
;
151 fl
.fl_ip_dport
= inet
->inet_dport
;
152 fl
.fl_ip_sport
= inet
->inet_sport
;
154 if (!fl
.oif
&& (addr_type
&IPV6_ADDR_MULTICAST
))
155 fl
.oif
= np
->mcast_oif
;
157 security_sk_classify_flow(sk
, &fl
);
159 opt
= flowlabel
? flowlabel
->opt
: np
->opt
;
160 final_p
= fl6_update_dst(&fl
, opt
, &final
);
162 err
= ip6_dst_lookup(sk
, &dst
, &fl
);
166 ipv6_addr_copy(&fl
.fl6_dst
, final_p
);
168 err
= __xfrm_lookup(sock_net(sk
), &dst
, &fl
, sk
, XFRM_LOOKUP_WAIT
);
171 err
= ip6_dst_blackhole(sk
, &dst
, &fl
);
176 /* source address lookup done in ip6_dst_lookup */
178 if (ipv6_addr_any(&np
->saddr
))
179 ipv6_addr_copy(&np
->saddr
, &fl
.fl6_src
);
181 if (ipv6_addr_any(&np
->rcv_saddr
)) {
182 ipv6_addr_copy(&np
->rcv_saddr
, &fl
.fl6_src
);
183 inet
->inet_rcv_saddr
= LOOPBACK4_IPV6
;
186 ip6_dst_store(sk
, dst
,
187 ipv6_addr_equal(&fl
.fl6_dst
, &np
->daddr
) ?
189 #ifdef CONFIG_IPV6_SUBTREES
190 ipv6_addr_equal(&fl
.fl6_src
, &np
->saddr
) ?
195 sk
->sk_state
= TCP_ESTABLISHED
;
197 fl6_sock_release(flowlabel
);
201 void ipv6_icmp_error(struct sock
*sk
, struct sk_buff
*skb
, int err
,
202 __be16 port
, u32 info
, u8
*payload
)
204 struct ipv6_pinfo
*np
= inet6_sk(sk
);
205 struct icmp6hdr
*icmph
= icmp6_hdr(skb
);
206 struct sock_exterr_skb
*serr
;
211 skb
= skb_clone(skb
, GFP_ATOMIC
);
215 skb
->protocol
= htons(ETH_P_IPV6
);
217 serr
= SKB_EXT_ERR(skb
);
218 serr
->ee
.ee_errno
= err
;
219 serr
->ee
.ee_origin
= SO_EE_ORIGIN_ICMP6
;
220 serr
->ee
.ee_type
= icmph
->icmp6_type
;
221 serr
->ee
.ee_code
= icmph
->icmp6_code
;
223 serr
->ee
.ee_info
= info
;
224 serr
->ee
.ee_data
= 0;
225 serr
->addr_offset
= (u8
*)&(((struct ipv6hdr
*)(icmph
+ 1))->daddr
) -
226 skb_network_header(skb
);
229 __skb_pull(skb
, payload
- skb
->data
);
230 skb_reset_transport_header(skb
);
232 if (sock_queue_err_skb(sk
, skb
))
236 void ipv6_local_error(struct sock
*sk
, int err
, struct flowi
*fl
, u32 info
)
238 struct ipv6_pinfo
*np
= inet6_sk(sk
);
239 struct sock_exterr_skb
*serr
;
246 skb
= alloc_skb(sizeof(struct ipv6hdr
), GFP_ATOMIC
);
250 skb
->protocol
= htons(ETH_P_IPV6
);
252 skb_put(skb
, sizeof(struct ipv6hdr
));
253 skb_reset_network_header(skb
);
255 ipv6_addr_copy(&iph
->daddr
, &fl
->fl6_dst
);
257 serr
= SKB_EXT_ERR(skb
);
258 serr
->ee
.ee_errno
= err
;
259 serr
->ee
.ee_origin
= SO_EE_ORIGIN_LOCAL
;
260 serr
->ee
.ee_type
= 0;
261 serr
->ee
.ee_code
= 0;
263 serr
->ee
.ee_info
= info
;
264 serr
->ee
.ee_data
= 0;
265 serr
->addr_offset
= (u8
*)&iph
->daddr
- skb_network_header(skb
);
266 serr
->port
= fl
->fl_ip_dport
;
268 __skb_pull(skb
, skb_tail_pointer(skb
) - skb
->data
);
269 skb_reset_transport_header(skb
);
271 if (sock_queue_err_skb(sk
, skb
))
275 void ipv6_local_rxpmtu(struct sock
*sk
, struct flowi
*fl
, u32 mtu
)
277 struct ipv6_pinfo
*np
= inet6_sk(sk
);
280 struct ip6_mtuinfo
*mtu_info
;
282 if (!np
->rxopt
.bits
.rxpmtu
)
285 skb
= alloc_skb(sizeof(struct ipv6hdr
), GFP_ATOMIC
);
289 skb_put(skb
, sizeof(struct ipv6hdr
));
290 skb_reset_network_header(skb
);
292 ipv6_addr_copy(&iph
->daddr
, &fl
->fl6_dst
);
294 mtu_info
= IP6CBMTU(skb
);
300 mtu_info
->ip6m_mtu
= mtu
;
301 mtu_info
->ip6m_addr
.sin6_family
= AF_INET6
;
302 mtu_info
->ip6m_addr
.sin6_port
= 0;
303 mtu_info
->ip6m_addr
.sin6_flowinfo
= 0;
304 mtu_info
->ip6m_addr
.sin6_scope_id
= fl
->oif
;
305 ipv6_addr_copy(&mtu_info
->ip6m_addr
.sin6_addr
, &ipv6_hdr(skb
)->daddr
);
307 __skb_pull(skb
, skb_tail_pointer(skb
) - skb
->data
);
308 skb_reset_transport_header(skb
);
310 skb
= xchg(&np
->rxpmtu
, skb
);
315 * Handle MSG_ERRQUEUE
317 int ipv6_recv_error(struct sock
*sk
, struct msghdr
*msg
, int len
)
319 struct ipv6_pinfo
*np
= inet6_sk(sk
);
320 struct sock_exterr_skb
*serr
;
321 struct sk_buff
*skb
, *skb2
;
322 struct sockaddr_in6
*sin
;
324 struct sock_extended_err ee
;
325 struct sockaddr_in6 offender
;
331 skb
= skb_dequeue(&sk
->sk_error_queue
);
337 msg
->msg_flags
|= MSG_TRUNC
;
340 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
344 sock_recv_timestamp(msg
, sk
, skb
);
346 serr
= SKB_EXT_ERR(skb
);
348 sin
= (struct sockaddr_in6
*)msg
->msg_name
;
350 const unsigned char *nh
= skb_network_header(skb
);
351 sin
->sin6_family
= AF_INET6
;
352 sin
->sin6_flowinfo
= 0;
353 sin
->sin6_port
= serr
->port
;
354 sin
->sin6_scope_id
= 0;
355 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
356 ipv6_addr_copy(&sin
->sin6_addr
,
357 (struct in6_addr
*)(nh
+ serr
->addr_offset
));
360 (*(__be32
*)(nh
+ serr
->addr_offset
- 24) &
362 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
363 sin
->sin6_scope_id
= IP6CB(skb
)->iif
;
365 ipv6_addr_set_v4mapped(*(__be32
*)(nh
+ serr
->addr_offset
),
370 memcpy(&errhdr
.ee
, &serr
->ee
, sizeof(struct sock_extended_err
));
371 sin
= &errhdr
.offender
;
372 sin
->sin6_family
= AF_UNSPEC
;
373 if (serr
->ee
.ee_origin
!= SO_EE_ORIGIN_LOCAL
) {
374 sin
->sin6_family
= AF_INET6
;
375 sin
->sin6_flowinfo
= 0;
376 sin
->sin6_scope_id
= 0;
377 if (skb
->protocol
== htons(ETH_P_IPV6
)) {
378 ipv6_addr_copy(&sin
->sin6_addr
, &ipv6_hdr(skb
)->saddr
);
380 datagram_recv_ctl(sk
, msg
, skb
);
381 if (ipv6_addr_type(&sin
->sin6_addr
) & IPV6_ADDR_LINKLOCAL
)
382 sin
->sin6_scope_id
= IP6CB(skb
)->iif
;
384 struct inet_sock
*inet
= inet_sk(sk
);
386 ipv6_addr_set_v4mapped(ip_hdr(skb
)->saddr
,
388 if (inet
->cmsg_flags
)
389 ip_cmsg_recv(msg
, skb
);
393 put_cmsg(msg
, SOL_IPV6
, IPV6_RECVERR
, sizeof(errhdr
), &errhdr
);
395 /* Now we could try to dump offended packet options */
397 msg
->msg_flags
|= MSG_ERRQUEUE
;
400 /* Reset and regenerate socket error */
401 spin_lock_bh(&sk
->sk_error_queue
.lock
);
403 if ((skb2
= skb_peek(&sk
->sk_error_queue
)) != NULL
) {
404 sk
->sk_err
= SKB_EXT_ERR(skb2
)->ee
.ee_errno
;
405 spin_unlock_bh(&sk
->sk_error_queue
.lock
);
406 sk
->sk_error_report(sk
);
408 spin_unlock_bh(&sk
->sk_error_queue
.lock
);
418 * Handle IPV6_RECVPATHMTU
420 int ipv6_recv_rxpmtu(struct sock
*sk
, struct msghdr
*msg
, int len
)
422 struct ipv6_pinfo
*np
= inet6_sk(sk
);
424 struct sockaddr_in6
*sin
;
425 struct ip6_mtuinfo mtu_info
;
430 skb
= xchg(&np
->rxpmtu
, NULL
);
436 msg
->msg_flags
|= MSG_TRUNC
;
439 err
= skb_copy_datagram_iovec(skb
, 0, msg
->msg_iov
, copied
);
443 sock_recv_timestamp(msg
, sk
, skb
);
445 memcpy(&mtu_info
, IP6CBMTU(skb
), sizeof(mtu_info
));
447 sin
= (struct sockaddr_in6
*)msg
->msg_name
;
449 sin
->sin6_family
= AF_INET6
;
450 sin
->sin6_flowinfo
= 0;
452 sin
->sin6_scope_id
= mtu_info
.ip6m_addr
.sin6_scope_id
;
453 ipv6_addr_copy(&sin
->sin6_addr
, &mtu_info
.ip6m_addr
.sin6_addr
);
456 put_cmsg(msg
, SOL_IPV6
, IPV6_PATHMTU
, sizeof(mtu_info
), &mtu_info
);
467 int datagram_recv_ctl(struct sock
*sk
, struct msghdr
*msg
, struct sk_buff
*skb
)
469 struct ipv6_pinfo
*np
= inet6_sk(sk
);
470 struct inet6_skb_parm
*opt
= IP6CB(skb
);
471 unsigned char *nh
= skb_network_header(skb
);
473 if (np
->rxopt
.bits
.rxinfo
) {
474 struct in6_pktinfo src_info
;
476 src_info
.ipi6_ifindex
= opt
->iif
;
477 ipv6_addr_copy(&src_info
.ipi6_addr
, &ipv6_hdr(skb
)->daddr
);
478 put_cmsg(msg
, SOL_IPV6
, IPV6_PKTINFO
, sizeof(src_info
), &src_info
);
481 if (np
->rxopt
.bits
.rxhlim
) {
482 int hlim
= ipv6_hdr(skb
)->hop_limit
;
483 put_cmsg(msg
, SOL_IPV6
, IPV6_HOPLIMIT
, sizeof(hlim
), &hlim
);
486 if (np
->rxopt
.bits
.rxtclass
) {
487 int tclass
= (ntohl(*(__be32
*)ipv6_hdr(skb
)) >> 20) & 0xff;
488 put_cmsg(msg
, SOL_IPV6
, IPV6_TCLASS
, sizeof(tclass
), &tclass
);
491 if (np
->rxopt
.bits
.rxflow
&& (*(__be32
*)nh
& IPV6_FLOWINFO_MASK
)) {
492 __be32 flowinfo
= *(__be32
*)nh
& IPV6_FLOWINFO_MASK
;
493 put_cmsg(msg
, SOL_IPV6
, IPV6_FLOWINFO
, sizeof(flowinfo
), &flowinfo
);
496 /* HbH is allowed only once */
497 if (np
->rxopt
.bits
.hopopts
&& opt
->hop
) {
498 u8
*ptr
= nh
+ opt
->hop
;
499 put_cmsg(msg
, SOL_IPV6
, IPV6_HOPOPTS
, (ptr
[1]+1)<<3, ptr
);
503 (np
->rxopt
.bits
.dstopts
|| np
->rxopt
.bits
.srcrt
)) {
505 * Silly enough, but we need to reparse in order to
506 * report extension headers (except for HbH)
509 * Also note that IPV6_RECVRTHDRDSTOPTS is NOT
510 * (and WILL NOT be) defined because
511 * IPV6_RECVDSTOPTS is more generic. --yoshfuji
513 unsigned int off
= sizeof(struct ipv6hdr
);
514 u8 nexthdr
= ipv6_hdr(skb
)->nexthdr
;
516 while (off
<= opt
->lastopt
) {
521 case IPPROTO_DSTOPTS
:
523 len
= (ptr
[1] + 1) << 3;
524 if (np
->rxopt
.bits
.dstopts
)
525 put_cmsg(msg
, SOL_IPV6
, IPV6_DSTOPTS
, len
, ptr
);
527 case IPPROTO_ROUTING
:
529 len
= (ptr
[1] + 1) << 3;
530 if (np
->rxopt
.bits
.srcrt
)
531 put_cmsg(msg
, SOL_IPV6
, IPV6_RTHDR
, len
, ptr
);
535 len
= (ptr
[1] + 2) << 2;
539 len
= (ptr
[1] + 1) << 3;
547 /* socket options in old style */
548 if (np
->rxopt
.bits
.rxoinfo
) {
549 struct in6_pktinfo src_info
;
551 src_info
.ipi6_ifindex
= opt
->iif
;
552 ipv6_addr_copy(&src_info
.ipi6_addr
, &ipv6_hdr(skb
)->daddr
);
553 put_cmsg(msg
, SOL_IPV6
, IPV6_2292PKTINFO
, sizeof(src_info
), &src_info
);
555 if (np
->rxopt
.bits
.rxohlim
) {
556 int hlim
= ipv6_hdr(skb
)->hop_limit
;
557 put_cmsg(msg
, SOL_IPV6
, IPV6_2292HOPLIMIT
, sizeof(hlim
), &hlim
);
559 if (np
->rxopt
.bits
.ohopopts
&& opt
->hop
) {
560 u8
*ptr
= nh
+ opt
->hop
;
561 put_cmsg(msg
, SOL_IPV6
, IPV6_2292HOPOPTS
, (ptr
[1]+1)<<3, ptr
);
563 if (np
->rxopt
.bits
.odstopts
&& opt
->dst0
) {
564 u8
*ptr
= nh
+ opt
->dst0
;
565 put_cmsg(msg
, SOL_IPV6
, IPV6_2292DSTOPTS
, (ptr
[1]+1)<<3, ptr
);
567 if (np
->rxopt
.bits
.osrcrt
&& opt
->srcrt
) {
568 struct ipv6_rt_hdr
*rthdr
= (struct ipv6_rt_hdr
*)(nh
+ opt
->srcrt
);
569 put_cmsg(msg
, SOL_IPV6
, IPV6_2292RTHDR
, (rthdr
->hdrlen
+1) << 3, rthdr
);
571 if (np
->rxopt
.bits
.odstopts
&& opt
->dst1
) {
572 u8
*ptr
= nh
+ opt
->dst1
;
573 put_cmsg(msg
, SOL_IPV6
, IPV6_2292DSTOPTS
, (ptr
[1]+1)<<3, ptr
);
578 int datagram_send_ctl(struct net
*net
,
579 struct msghdr
*msg
, struct flowi
*fl
,
580 struct ipv6_txoptions
*opt
,
581 int *hlimit
, int *tclass
, int *dontfrag
)
583 struct in6_pktinfo
*src_info
;
584 struct cmsghdr
*cmsg
;
585 struct ipv6_rt_hdr
*rthdr
;
586 struct ipv6_opt_hdr
*hdr
;
590 for (cmsg
= CMSG_FIRSTHDR(msg
); cmsg
; cmsg
= CMSG_NXTHDR(msg
, cmsg
)) {
593 if (!CMSG_OK(msg
, cmsg
)) {
598 if (cmsg
->cmsg_level
!= SOL_IPV6
)
601 switch (cmsg
->cmsg_type
) {
603 case IPV6_2292PKTINFO
:
605 struct net_device
*dev
= NULL
;
607 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct in6_pktinfo
))) {
612 src_info
= (struct in6_pktinfo
*)CMSG_DATA(cmsg
);
614 if (src_info
->ipi6_ifindex
) {
615 if (fl
->oif
&& src_info
->ipi6_ifindex
!= fl
->oif
)
617 fl
->oif
= src_info
->ipi6_ifindex
;
620 addr_type
= __ipv6_addr_type(&src_info
->ipi6_addr
);
624 dev
= dev_get_by_index_rcu(net
, fl
->oif
);
629 } else if (addr_type
& IPV6_ADDR_LINKLOCAL
) {
634 if (addr_type
!= IPV6_ADDR_ANY
) {
635 int strict
= __ipv6_addr_src_scope(addr_type
) <= IPV6_ADDR_SCOPE_LINKLOCAL
;
636 if (!ipv6_chk_addr(net
, &src_info
->ipi6_addr
,
637 strict
? dev
: NULL
, 0))
640 ipv6_addr_copy(&fl
->fl6_src
, &src_info
->ipi6_addr
);
652 if (cmsg
->cmsg_len
< CMSG_LEN(4)) {
657 if (fl
->fl6_flowlabel
&IPV6_FLOWINFO_MASK
) {
658 if ((fl
->fl6_flowlabel
^*(__be32
*)CMSG_DATA(cmsg
))&~IPV6_FLOWINFO_MASK
) {
663 fl
->fl6_flowlabel
= IPV6_FLOWINFO_MASK
& *(__be32
*)CMSG_DATA(cmsg
);
666 case IPV6_2292HOPOPTS
:
668 if (opt
->hopopt
|| cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
673 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
674 len
= ((hdr
->hdrlen
+ 1) << 3);
675 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
679 if (!capable(CAP_NET_RAW
)) {
683 opt
->opt_nflen
+= len
;
687 case IPV6_2292DSTOPTS
:
688 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
693 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
694 len
= ((hdr
->hdrlen
+ 1) << 3);
695 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
699 if (!capable(CAP_NET_RAW
)) {
707 opt
->opt_flen
+= len
;
712 case IPV6_RTHDRDSTOPTS
:
713 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_opt_hdr
))) {
718 hdr
= (struct ipv6_opt_hdr
*)CMSG_DATA(cmsg
);
719 len
= ((hdr
->hdrlen
+ 1) << 3);
720 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
724 if (!capable(CAP_NET_RAW
)) {
728 if (cmsg
->cmsg_type
== IPV6_DSTOPTS
) {
729 opt
->opt_flen
+= len
;
732 opt
->opt_nflen
+= len
;
739 if (cmsg
->cmsg_len
< CMSG_LEN(sizeof(struct ipv6_rt_hdr
))) {
744 rthdr
= (struct ipv6_rt_hdr
*)CMSG_DATA(cmsg
);
746 switch (rthdr
->type
) {
747 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
748 case IPV6_SRCRT_TYPE_2
:
749 if (rthdr
->hdrlen
!= 2 ||
750 rthdr
->segments_left
!= 1) {
761 len
= ((rthdr
->hdrlen
+ 1) << 3);
763 if (cmsg
->cmsg_len
< CMSG_LEN(len
)) {
768 /* segments left must also match */
769 if ((rthdr
->hdrlen
>> 1) != rthdr
->segments_left
) {
774 opt
->opt_nflen
+= len
;
777 if (cmsg
->cmsg_type
== IPV6_2292RTHDR
&& opt
->dst1opt
) {
778 int dsthdrlen
= ((opt
->dst1opt
->hdrlen
+1)<<3);
780 opt
->opt_nflen
+= dsthdrlen
;
781 opt
->dst0opt
= opt
->dst1opt
;
783 opt
->opt_flen
-= dsthdrlen
;
788 case IPV6_2292HOPLIMIT
:
790 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
795 *hlimit
= *(int *)CMSG_DATA(cmsg
);
796 if (*hlimit
< -1 || *hlimit
> 0xff) {
808 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
812 tc
= *(int *)CMSG_DATA(cmsg
);
813 if (tc
< -1 || tc
> 0xff)
827 if (cmsg
->cmsg_len
!= CMSG_LEN(sizeof(int))) {
831 df
= *(int *)CMSG_DATA(cmsg
);
832 if (df
< 0 || df
> 1)
841 LIMIT_NETDEBUG(KERN_DEBUG
"invalid cmsg type: %d\n",