2 * Extension Header handling for IPv6
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
7 * Andi Kleen <ak@muc.de>
8 * Alexey Kuznetsov <kuznet@ms2.inr.ac.ru>
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.
17 * yoshfuji : ensure not to overrun while parsing
19 * Mitsuru KANDA @USAGI and: Remove ipv6_parse_exthdrs().
20 * YOSHIFUJI Hideaki @USAGI Register inbound extension header
21 * handlers as inet6_protocol{}.
24 #include <linux/errno.h>
25 #include <linux/types.h>
26 #include <linux/socket.h>
27 #include <linux/sockios.h>
28 #include <linux/net.h>
29 #include <linux/netdevice.h>
30 #include <linux/in6.h>
31 #include <linux/icmpv6.h>
32 #include <linux/slab.h>
33 #include <linux/export.h>
40 #include <net/protocol.h>
41 #include <net/transp_v6.h>
42 #include <net/rawv6.h>
43 #include <net/ndisc.h>
44 #include <net/ip6_route.h>
45 #include <net/addrconf.h>
46 #if IS_ENABLED(CONFIG_IPV6_MIP6)
50 #include <asm/uaccess.h>
51 #include "ip6_offload.h"
54 * Parsing tlv encoded headers.
56 * Parsing function "func" returns true, if parsing succeed
57 * and false, if it failed.
58 * It MUST NOT touch skb->h.
63 bool (*func
)(struct sk_buff
*skb
, int offset
);
66 /*********************
68 *********************/
70 /* An unknown option is detected, decide what to do */
72 static bool ip6_tlvopt_unknown(struct sk_buff
*skb
, int optoff
)
74 switch ((skb_network_header(skb
)[optoff
] & 0xC0) >> 6) {
78 case 1: /* drop packet */
81 case 3: /* Send ICMP if not a multicast address and drop packet */
82 /* Actually, it is redundant check. icmp_send
83 will recheck in any case.
85 if (ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
))
87 case 2: /* send ICMP PARM PROB regardless and drop packet */
88 icmpv6_param_prob(skb
, ICMPV6_UNK_OPTION
, optoff
);
96 /* Parse tlv encoded option header (hop-by-hop or destination) */
98 static bool ip6_parse_tlv(const struct tlvtype_proc
*procs
, struct sk_buff
*skb
)
100 const struct tlvtype_proc
*curr
;
101 const unsigned char *nh
= skb_network_header(skb
);
102 int off
= skb_network_header_len(skb
);
103 int len
= (skb_transport_header(skb
)[1] + 1) << 3;
106 if (skb_transport_offset(skb
) + len
> skb_headlen(skb
))
113 int optlen
= nh
[off
+ 1] + 2;
125 /* RFC 2460 states that the purpose of PadN is
126 * to align the containing header to multiples
127 * of 8. 7 is therefore the highest valid value.
128 * See also RFC 4942, Section 2.1.9.5.
133 /* RFC 4942 recommends receiving hosts to
134 * actively check PadN payload to contain
137 for (i
= 2; i
< optlen
; i
++) {
138 if (nh
[off
+ i
] != 0)
143 default: /* Other TLV code so scan list */
146 for (curr
=procs
; curr
->type
>= 0; curr
++) {
147 if (curr
->type
== nh
[off
]) {
148 /* type specific length/alignment
149 checks will be performed in the
151 if (curr
->func(skb
, off
) == false)
156 if (curr
->type
< 0) {
157 if (ip6_tlvopt_unknown(skb
, off
) == 0)
166 /* This case will not be caught by above check since its padding
167 * length is smaller than 7:
168 * 1 byte NH + 1 byte Length + 6 bytes Padding
170 if ((padlen
== 6) && ((off
- skb_network_header_len(skb
)) == 8))
180 /*****************************
181 Destination options header.
182 *****************************/
184 #if IS_ENABLED(CONFIG_IPV6_MIP6)
185 static bool ipv6_dest_hao(struct sk_buff
*skb
, int optoff
)
187 struct ipv6_destopt_hao
*hao
;
188 struct inet6_skb_parm
*opt
= IP6CB(skb
);
189 struct ipv6hdr
*ipv6h
= ipv6_hdr(skb
);
190 struct in6_addr tmp_addr
;
194 LIMIT_NETDEBUG(KERN_DEBUG
"hao duplicated\n");
197 opt
->dsthao
= opt
->dst1
;
200 hao
= (struct ipv6_destopt_hao
*)(skb_network_header(skb
) + optoff
);
202 if (hao
->length
!= 16) {
204 KERN_DEBUG
"hao invalid option length = %d\n", hao
->length
);
208 if (!(ipv6_addr_type(&hao
->addr
) & IPV6_ADDR_UNICAST
)) {
210 KERN_DEBUG
"hao is not an unicast addr: %pI6\n", &hao
->addr
);
214 ret
= xfrm6_input_addr(skb
, (xfrm_address_t
*)&ipv6h
->daddr
,
215 (xfrm_address_t
*)&hao
->addr
, IPPROTO_DSTOPTS
);
216 if (unlikely(ret
< 0))
219 if (skb_cloned(skb
)) {
220 if (pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
))
223 /* update all variable using below by copied skbuff */
224 hao
= (struct ipv6_destopt_hao
*)(skb_network_header(skb
) +
226 ipv6h
= ipv6_hdr(skb
);
229 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
230 skb
->ip_summed
= CHECKSUM_NONE
;
232 tmp_addr
= ipv6h
->saddr
;
233 ipv6h
->saddr
= hao
->addr
;
234 hao
->addr
= tmp_addr
;
236 if (skb
->tstamp
.tv64
== 0)
237 __net_timestamp(skb
);
247 static const struct tlvtype_proc tlvprocdestopt_lst
[] = {
248 #if IS_ENABLED(CONFIG_IPV6_MIP6)
250 .type
= IPV6_TLV_HAO
,
251 .func
= ipv6_dest_hao
,
257 static int ipv6_destopt_rcv(struct sk_buff
*skb
)
259 struct inet6_skb_parm
*opt
= IP6CB(skb
);
260 #if IS_ENABLED(CONFIG_IPV6_MIP6)
263 struct dst_entry
*dst
= skb_dst(skb
);
265 if (!pskb_may_pull(skb
, skb_transport_offset(skb
) + 8) ||
266 !pskb_may_pull(skb
, (skb_transport_offset(skb
) +
267 ((skb_transport_header(skb
)[1] + 1) << 3)))) {
268 IP6_INC_STATS_BH(dev_net(dst
->dev
), ip6_dst_idev(dst
),
269 IPSTATS_MIB_INHDRERRORS
);
274 opt
->lastopt
= opt
->dst1
= skb_network_header_len(skb
);
275 #if IS_ENABLED(CONFIG_IPV6_MIP6)
279 if (ip6_parse_tlv(tlvprocdestopt_lst
, skb
)) {
280 skb
->transport_header
+= (skb_transport_header(skb
)[1] + 1) << 3;
282 #if IS_ENABLED(CONFIG_IPV6_MIP6)
285 opt
->nhoff
= opt
->dst1
;
290 IP6_INC_STATS_BH(dev_net(dst
->dev
),
291 ip6_dst_idev(dst
), IPSTATS_MIB_INHDRERRORS
);
295 /********************************
297 ********************************/
299 /* called with rcu_read_lock() */
300 static int ipv6_rthdr_rcv(struct sk_buff
*skb
)
302 struct inet6_skb_parm
*opt
= IP6CB(skb
);
303 struct in6_addr
*addr
= NULL
;
304 struct in6_addr daddr
;
305 struct inet6_dev
*idev
;
307 struct ipv6_rt_hdr
*hdr
;
308 struct rt0_hdr
*rthdr
;
309 struct net
*net
= dev_net(skb
->dev
);
310 int accept_source_route
= net
->ipv6
.devconf_all
->accept_source_route
;
312 idev
= __in6_dev_get(skb
->dev
);
313 if (idev
&& accept_source_route
> idev
->cnf
.accept_source_route
)
314 accept_source_route
= idev
->cnf
.accept_source_route
;
316 if (!pskb_may_pull(skb
, skb_transport_offset(skb
) + 8) ||
317 !pskb_may_pull(skb
, (skb_transport_offset(skb
) +
318 ((skb_transport_header(skb
)[1] + 1) << 3)))) {
319 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
320 IPSTATS_MIB_INHDRERRORS
);
325 hdr
= (struct ipv6_rt_hdr
*)skb_transport_header(skb
);
327 if (ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
) ||
328 skb
->pkt_type
!= PACKET_HOST
) {
329 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
330 IPSTATS_MIB_INADDRERRORS
);
336 if (hdr
->segments_left
== 0) {
338 #if IS_ENABLED(CONFIG_IPV6_MIP6)
339 case IPV6_SRCRT_TYPE_2
:
340 /* Silently discard type 2 header unless it was
344 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
345 IPSTATS_MIB_INADDRERRORS
);
355 opt
->lastopt
= opt
->srcrt
= skb_network_header_len(skb
);
356 skb
->transport_header
+= (hdr
->hdrlen
+ 1) << 3;
357 opt
->dst0
= opt
->dst1
;
359 opt
->nhoff
= (&hdr
->nexthdr
) - skb_network_header(skb
);
364 #if IS_ENABLED(CONFIG_IPV6_MIP6)
365 case IPV6_SRCRT_TYPE_2
:
366 if (accept_source_route
< 0)
368 /* Silently discard invalid RTH type 2 */
369 if (hdr
->hdrlen
!= 2 || hdr
->segments_left
!= 1) {
370 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
371 IPSTATS_MIB_INHDRERRORS
);
382 * This is the routing header forwarding algorithm from
386 n
= hdr
->hdrlen
>> 1;
388 if (hdr
->segments_left
> n
) {
389 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
390 IPSTATS_MIB_INHDRERRORS
);
391 icmpv6_param_prob(skb
, ICMPV6_HDR_FIELD
,
392 ((&hdr
->segments_left
) -
393 skb_network_header(skb
)));
397 /* We are about to mangle packet header. Be careful!
398 Do not damage packets queued somewhere.
400 if (skb_cloned(skb
)) {
401 /* the copy is a forwarded packet */
402 if (pskb_expand_head(skb
, 0, 0, GFP_ATOMIC
)) {
403 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
404 IPSTATS_MIB_OUTDISCARDS
);
408 hdr
= (struct ipv6_rt_hdr
*)skb_transport_header(skb
);
411 if (skb
->ip_summed
== CHECKSUM_COMPLETE
)
412 skb
->ip_summed
= CHECKSUM_NONE
;
414 i
= n
- --hdr
->segments_left
;
416 rthdr
= (struct rt0_hdr
*) hdr
;
421 #if IS_ENABLED(CONFIG_IPV6_MIP6)
422 case IPV6_SRCRT_TYPE_2
:
423 if (xfrm6_input_addr(skb
, (xfrm_address_t
*)addr
,
424 (xfrm_address_t
*)&ipv6_hdr(skb
)->saddr
,
425 IPPROTO_ROUTING
) < 0) {
426 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
427 IPSTATS_MIB_INADDRERRORS
);
431 if (!ipv6_chk_home_addr(dev_net(skb_dst(skb
)->dev
), addr
)) {
432 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
433 IPSTATS_MIB_INADDRERRORS
);
443 if (ipv6_addr_is_multicast(addr
)) {
444 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
445 IPSTATS_MIB_INADDRERRORS
);
451 *addr
= ipv6_hdr(skb
)->daddr
;
452 ipv6_hdr(skb
)->daddr
= daddr
;
455 ip6_route_input(skb
);
456 if (skb_dst(skb
)->error
) {
457 skb_push(skb
, skb
->data
- skb_network_header(skb
));
462 if (skb_dst(skb
)->dev
->flags
&IFF_LOOPBACK
) {
463 if (ipv6_hdr(skb
)->hop_limit
<= 1) {
464 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)),
465 IPSTATS_MIB_INHDRERRORS
);
466 icmpv6_send(skb
, ICMPV6_TIME_EXCEED
, ICMPV6_EXC_HOPLIMIT
,
471 ipv6_hdr(skb
)->hop_limit
--;
475 skb_push(skb
, skb
->data
- skb_network_header(skb
));
480 IP6_INC_STATS_BH(net
, ip6_dst_idev(skb_dst(skb
)), IPSTATS_MIB_INHDRERRORS
);
481 icmpv6_param_prob(skb
, ICMPV6_HDR_FIELD
,
482 (&hdr
->type
) - skb_network_header(skb
));
486 static const struct inet6_protocol rthdr_protocol
= {
487 .handler
= ipv6_rthdr_rcv
,
488 .flags
= INET6_PROTO_NOPOLICY
,
491 static const struct inet6_protocol destopt_protocol
= {
492 .handler
= ipv6_destopt_rcv
,
493 .flags
= INET6_PROTO_NOPOLICY
,
496 static const struct inet6_protocol nodata_protocol
= {
497 .handler
= dst_discard
,
498 .flags
= INET6_PROTO_NOPOLICY
,
501 int __init
ipv6_exthdrs_init(void)
505 ret
= ipv6_exthdrs_offload_init();
509 ret
= inet6_add_protocol(&rthdr_protocol
, IPPROTO_ROUTING
);
513 ret
= inet6_add_protocol(&destopt_protocol
, IPPROTO_DSTOPTS
);
517 ret
= inet6_add_protocol(&nodata_protocol
, IPPROTO_NONE
);
524 inet6_del_protocol(&destopt_protocol
, IPPROTO_DSTOPTS
);
526 inet6_del_protocol(&rthdr_protocol
, IPPROTO_ROUTING
);
528 ipv6_exthdrs_offload_exit();
532 void ipv6_exthdrs_exit(void)
534 ipv6_exthdrs_offload_exit();
535 inet6_del_protocol(&nodata_protocol
, IPPROTO_NONE
);
536 inet6_del_protocol(&destopt_protocol
, IPPROTO_DSTOPTS
);
537 inet6_del_protocol(&rthdr_protocol
, IPPROTO_ROUTING
);
540 /**********************************
542 **********************************/
545 * Note: we cannot rely on skb_dst(skb) before we assign it in ip6_route_input().
547 static inline struct inet6_dev
*ipv6_skb_idev(struct sk_buff
*skb
)
549 return skb_dst(skb
) ? ip6_dst_idev(skb_dst(skb
)) : __in6_dev_get(skb
->dev
);
552 static inline struct net
*ipv6_skb_net(struct sk_buff
*skb
)
554 return skb_dst(skb
) ? dev_net(skb_dst(skb
)->dev
) : dev_net(skb
->dev
);
557 /* Router Alert as of RFC 2711 */
559 static bool ipv6_hop_ra(struct sk_buff
*skb
, int optoff
)
561 const unsigned char *nh
= skb_network_header(skb
);
563 if (nh
[optoff
+ 1] == 2) {
564 IP6CB(skb
)->ra
= optoff
;
567 LIMIT_NETDEBUG(KERN_DEBUG
"ipv6_hop_ra: wrong RA length %d\n",
575 static bool ipv6_hop_jumbo(struct sk_buff
*skb
, int optoff
)
577 const unsigned char *nh
= skb_network_header(skb
);
578 struct net
*net
= ipv6_skb_net(skb
);
581 if (nh
[optoff
+ 1] != 4 || (optoff
& 3) != 2) {
582 LIMIT_NETDEBUG(KERN_DEBUG
"ipv6_hop_jumbo: wrong jumbo opt length/alignment %d\n",
584 IP6_INC_STATS_BH(net
, ipv6_skb_idev(skb
),
585 IPSTATS_MIB_INHDRERRORS
);
589 pkt_len
= ntohl(*(__be32
*)(nh
+ optoff
+ 2));
590 if (pkt_len
<= IPV6_MAXPLEN
) {
591 IP6_INC_STATS_BH(net
, ipv6_skb_idev(skb
),
592 IPSTATS_MIB_INHDRERRORS
);
593 icmpv6_param_prob(skb
, ICMPV6_HDR_FIELD
, optoff
+2);
596 if (ipv6_hdr(skb
)->payload_len
) {
597 IP6_INC_STATS_BH(net
, ipv6_skb_idev(skb
),
598 IPSTATS_MIB_INHDRERRORS
);
599 icmpv6_param_prob(skb
, ICMPV6_HDR_FIELD
, optoff
);
603 if (pkt_len
> skb
->len
- sizeof(struct ipv6hdr
)) {
604 IP6_INC_STATS_BH(net
, ipv6_skb_idev(skb
),
605 IPSTATS_MIB_INTRUNCATEDPKTS
);
609 if (pskb_trim_rcsum(skb
, pkt_len
+ sizeof(struct ipv6hdr
)))
619 static const struct tlvtype_proc tlvprochopopt_lst
[] = {
621 .type
= IPV6_TLV_ROUTERALERT
,
625 .type
= IPV6_TLV_JUMBO
,
626 .func
= ipv6_hop_jumbo
,
631 int ipv6_parse_hopopts(struct sk_buff
*skb
)
633 struct inet6_skb_parm
*opt
= IP6CB(skb
);
636 * skb_network_header(skb) is equal to skb->data, and
637 * skb_network_header_len(skb) is always equal to
638 * sizeof(struct ipv6hdr) by definition of
639 * hop-by-hop options.
641 if (!pskb_may_pull(skb
, sizeof(struct ipv6hdr
) + 8) ||
642 !pskb_may_pull(skb
, (sizeof(struct ipv6hdr
) +
643 ((skb_transport_header(skb
)[1] + 1) << 3)))) {
648 opt
->hop
= sizeof(struct ipv6hdr
);
649 if (ip6_parse_tlv(tlvprochopopt_lst
, skb
)) {
650 skb
->transport_header
+= (skb_transport_header(skb
)[1] + 1) << 3;
652 opt
->nhoff
= sizeof(struct ipv6hdr
);
659 * Creating outbound headers.
661 * "build" functions work when skb is filled from head to tail (datagram)
662 * "push" functions work when headers are added from tail to head (tcp)
664 * In both cases we assume, that caller reserved enough room
668 static void ipv6_push_rthdr(struct sk_buff
*skb
, u8
*proto
,
669 struct ipv6_rt_hdr
*opt
,
670 struct in6_addr
**addr_p
)
672 struct rt0_hdr
*phdr
, *ihdr
;
675 ihdr
= (struct rt0_hdr
*) opt
;
677 phdr
= (struct rt0_hdr
*) skb_push(skb
, (ihdr
->rt_hdr
.hdrlen
+ 1) << 3);
678 memcpy(phdr
, ihdr
, sizeof(struct rt0_hdr
));
680 hops
= ihdr
->rt_hdr
.hdrlen
>> 1;
683 memcpy(phdr
->addr
, ihdr
->addr
+ 1,
684 (hops
- 1) * sizeof(struct in6_addr
));
686 phdr
->addr
[hops
- 1] = **addr_p
;
687 *addr_p
= ihdr
->addr
;
689 phdr
->rt_hdr
.nexthdr
= *proto
;
690 *proto
= NEXTHDR_ROUTING
;
693 static void ipv6_push_exthdr(struct sk_buff
*skb
, u8
*proto
, u8 type
, struct ipv6_opt_hdr
*opt
)
695 struct ipv6_opt_hdr
*h
= (struct ipv6_opt_hdr
*)skb_push(skb
, ipv6_optlen(opt
));
697 memcpy(h
, opt
, ipv6_optlen(opt
));
702 void ipv6_push_nfrag_opts(struct sk_buff
*skb
, struct ipv6_txoptions
*opt
,
704 struct in6_addr
**daddr
)
707 ipv6_push_rthdr(skb
, proto
, opt
->srcrt
, daddr
);
709 * IPV6_RTHDRDSTOPTS is ignored
710 * unless IPV6_RTHDR is set (RFC3542).
713 ipv6_push_exthdr(skb
, proto
, NEXTHDR_DEST
, opt
->dst0opt
);
716 ipv6_push_exthdr(skb
, proto
, NEXTHDR_HOP
, opt
->hopopt
);
718 EXPORT_SYMBOL(ipv6_push_nfrag_opts
);
720 void ipv6_push_frag_opts(struct sk_buff
*skb
, struct ipv6_txoptions
*opt
, u8
*proto
)
723 ipv6_push_exthdr(skb
, proto
, NEXTHDR_DEST
, opt
->dst1opt
);
726 struct ipv6_txoptions
*
727 ipv6_dup_options(struct sock
*sk
, struct ipv6_txoptions
*opt
)
729 struct ipv6_txoptions
*opt2
;
731 opt2
= sock_kmalloc(sk
, opt
->tot_len
, GFP_ATOMIC
);
733 long dif
= (char *)opt2
- (char *)opt
;
734 memcpy(opt2
, opt
, opt
->tot_len
);
736 *((char **)&opt2
->hopopt
) += dif
;
738 *((char **)&opt2
->dst0opt
) += dif
;
740 *((char **)&opt2
->dst1opt
) += dif
;
742 *((char **)&opt2
->srcrt
) += dif
;
746 EXPORT_SYMBOL_GPL(ipv6_dup_options
);
748 static int ipv6_renew_option(void *ohdr
,
749 struct ipv6_opt_hdr __user
*newopt
, int newoptlen
,
751 struct ipv6_opt_hdr
**hdr
,
756 memcpy(*p
, ohdr
, ipv6_optlen((struct ipv6_opt_hdr
*)ohdr
));
757 *hdr
= (struct ipv6_opt_hdr
*)*p
;
758 *p
+= CMSG_ALIGN(ipv6_optlen(*hdr
));
762 if (copy_from_user(*p
, newopt
, newoptlen
))
764 *hdr
= (struct ipv6_opt_hdr
*)*p
;
765 if (ipv6_optlen(*hdr
) > newoptlen
)
767 *p
+= CMSG_ALIGN(newoptlen
);
773 struct ipv6_txoptions
*
774 ipv6_renew_options(struct sock
*sk
, struct ipv6_txoptions
*opt
,
776 struct ipv6_opt_hdr __user
*newopt
, int newoptlen
)
780 struct ipv6_txoptions
*opt2
;
784 if (newtype
!= IPV6_HOPOPTS
&& opt
->hopopt
)
785 tot_len
+= CMSG_ALIGN(ipv6_optlen(opt
->hopopt
));
786 if (newtype
!= IPV6_RTHDRDSTOPTS
&& opt
->dst0opt
)
787 tot_len
+= CMSG_ALIGN(ipv6_optlen(opt
->dst0opt
));
788 if (newtype
!= IPV6_RTHDR
&& opt
->srcrt
)
789 tot_len
+= CMSG_ALIGN(ipv6_optlen(opt
->srcrt
));
790 if (newtype
!= IPV6_DSTOPTS
&& opt
->dst1opt
)
791 tot_len
+= CMSG_ALIGN(ipv6_optlen(opt
->dst1opt
));
794 if (newopt
&& newoptlen
)
795 tot_len
+= CMSG_ALIGN(newoptlen
);
800 tot_len
+= sizeof(*opt2
);
801 opt2
= sock_kmalloc(sk
, tot_len
, GFP_ATOMIC
);
803 return ERR_PTR(-ENOBUFS
);
805 memset(opt2
, 0, tot_len
);
807 opt2
->tot_len
= tot_len
;
808 p
= (char *)(opt2
+ 1);
810 err
= ipv6_renew_option(opt
? opt
->hopopt
: NULL
, newopt
, newoptlen
,
811 newtype
!= IPV6_HOPOPTS
,
816 err
= ipv6_renew_option(opt
? opt
->dst0opt
: NULL
, newopt
, newoptlen
,
817 newtype
!= IPV6_RTHDRDSTOPTS
,
822 err
= ipv6_renew_option(opt
? opt
->srcrt
: NULL
, newopt
, newoptlen
,
823 newtype
!= IPV6_RTHDR
,
824 (struct ipv6_opt_hdr
**)&opt2
->srcrt
, &p
);
828 err
= ipv6_renew_option(opt
? opt
->dst1opt
: NULL
, newopt
, newoptlen
,
829 newtype
!= IPV6_DSTOPTS
,
834 opt2
->opt_nflen
= (opt2
->hopopt
? ipv6_optlen(opt2
->hopopt
) : 0) +
835 (opt2
->dst0opt
? ipv6_optlen(opt2
->dst0opt
) : 0) +
836 (opt2
->srcrt
? ipv6_optlen(opt2
->srcrt
) : 0);
837 opt2
->opt_flen
= (opt2
->dst1opt
? ipv6_optlen(opt2
->dst1opt
) : 0);
841 sock_kfree_s(sk
, opt2
, opt2
->tot_len
);
845 struct ipv6_txoptions
*ipv6_fixup_options(struct ipv6_txoptions
*opt_space
,
846 struct ipv6_txoptions
*opt
)
849 * ignore the dest before srcrt unless srcrt is being included.
852 if (opt
&& opt
->dst0opt
&& !opt
->srcrt
) {
853 if (opt_space
!= opt
) {
854 memcpy(opt_space
, opt
, sizeof(*opt_space
));
857 opt
->opt_nflen
-= ipv6_optlen(opt
->dst0opt
);
863 EXPORT_SYMBOL_GPL(ipv6_fixup_options
);
866 * fl6_update_dst - update flowi destination address with info given
867 * by srcrt option, if any.
869 * @fl6: flowi6 for which daddr is to be updated
870 * @opt: struct ipv6_txoptions in which to look for srcrt opt
871 * @orig: copy of original daddr address if modified
873 * Returns NULL if no txoptions or no srcrt, otherwise returns orig
874 * and initial value of fl6->daddr set in orig
876 struct in6_addr
*fl6_update_dst(struct flowi6
*fl6
,
877 const struct ipv6_txoptions
*opt
,
878 struct in6_addr
*orig
)
880 if (!opt
|| !opt
->srcrt
)
884 fl6
->daddr
= *((struct rt0_hdr
*)opt
->srcrt
)->addr
;
887 EXPORT_SYMBOL_GPL(fl6_update_dst
);