2 * IPv6 output functions
3 * Linux INET6 implementation
6 * Pedro Roque <roque@di.fc.ul.pt>
8 * Based on linux/net/ipv4/ip_output.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.
16 * A.N.Kuznetsov : airthmetics in fragmentation.
17 * extension headers are implemented.
18 * route changes now work.
19 * ip6_forward does not confuse sniffers.
22 * H. von Brand : Added missing #include <linux/string.h>
23 * Imran Patel : frag id should be in NBO
24 * Kazunori MIYAZAWA @USAGI
25 * : add ip6_append_data and related functions
29 #include <linux/errno.h>
30 #include <linux/kernel.h>
31 #include <linux/string.h>
32 #include <linux/socket.h>
33 #include <linux/net.h>
34 #include <linux/netdevice.h>
35 #include <linux/if_arp.h>
36 #include <linux/in6.h>
37 #include <linux/tcp.h>
38 #include <linux/route.h>
39 #include <linux/module.h>
40 #include <linux/slab.h>
42 #include <linux/netfilter.h>
43 #include <linux/netfilter_ipv6.h>
49 #include <net/ndisc.h>
50 #include <net/protocol.h>
51 #include <net/ip6_route.h>
52 #include <net/addrconf.h>
53 #include <net/rawv6.h>
56 #include <net/checksum.h>
57 #include <linux/mroute6.h>
59 int ip6_fragment(struct sk_buff
*skb
, int (*output
)(struct sk_buff
*));
61 int __ip6_local_out(struct sk_buff
*skb
)
65 len
= skb
->len
- sizeof(struct ipv6hdr
);
66 if (len
> IPV6_MAXPLEN
)
68 ipv6_hdr(skb
)->payload_len
= htons(len
);
70 return nf_hook(NFPROTO_IPV6
, NF_INET_LOCAL_OUT
, skb
, NULL
,
71 skb_dst(skb
)->dev
, dst_output
);
74 int ip6_local_out(struct sk_buff
*skb
)
78 err
= __ip6_local_out(skb
);
80 err
= dst_output(skb
);
84 EXPORT_SYMBOL_GPL(ip6_local_out
);
86 /* dev_loopback_xmit for use with netfilter. */
87 static int ip6_dev_loopback_xmit(struct sk_buff
*newskb
)
89 skb_reset_mac_header(newskb
);
90 __skb_pull(newskb
, skb_network_offset(newskb
));
91 newskb
->pkt_type
= PACKET_LOOPBACK
;
92 newskb
->ip_summed
= CHECKSUM_UNNECESSARY
;
93 WARN_ON(!skb_dst(newskb
));
99 static int ip6_finish_output2(struct sk_buff
*skb
)
101 struct dst_entry
*dst
= skb_dst(skb
);
102 struct net_device
*dev
= dst
->dev
;
103 struct neighbour
*neigh
;
106 skb
->protocol
= htons(ETH_P_IPV6
);
109 if (ipv6_addr_is_multicast(&ipv6_hdr(skb
)->daddr
)) {
110 struct inet6_dev
*idev
= ip6_dst_idev(skb_dst(skb
));
112 if (!(dev
->flags
& IFF_LOOPBACK
) && sk_mc_loop(skb
->sk
) &&
113 ((mroute6_socket(dev_net(dev
), skb
) &&
114 !(IP6CB(skb
)->flags
& IP6SKB_FORWARDED
)) ||
115 ipv6_chk_mcast_addr(dev
, &ipv6_hdr(skb
)->daddr
,
116 &ipv6_hdr(skb
)->saddr
))) {
117 struct sk_buff
*newskb
= skb_clone(skb
, GFP_ATOMIC
);
119 /* Do not check for IFF_ALLMULTI; multicast routing
120 is not supported in any case.
123 NF_HOOK(NFPROTO_IPV6
, NF_INET_POST_ROUTING
,
124 newskb
, NULL
, newskb
->dev
,
125 ip6_dev_loopback_xmit
);
127 if (ipv6_hdr(skb
)->hop_limit
== 0) {
128 IP6_INC_STATS(dev_net(dev
), idev
,
129 IPSTATS_MIB_OUTDISCARDS
);
135 IP6_UPD_PO_STATS(dev_net(dev
), idev
, IPSTATS_MIB_OUTMCAST
,
141 res
= neigh_hh_output(dst
->hh
, skb
);
146 neigh
= dst_get_neighbour(dst
);
148 res
= neigh
->output(skb
);
156 IP6_INC_STATS_BH(dev_net(dst
->dev
),
157 ip6_dst_idev(dst
), IPSTATS_MIB_OUTNOROUTES
);
162 static int ip6_finish_output(struct sk_buff
*skb
)
164 if ((skb
->len
> ip6_skb_dst_mtu(skb
) && !skb_is_gso(skb
)) ||
165 dst_allfrag(skb_dst(skb
)))
166 return ip6_fragment(skb
, ip6_finish_output2
);
168 return ip6_finish_output2(skb
);
171 int ip6_output(struct sk_buff
*skb
)
173 struct net_device
*dev
= skb_dst(skb
)->dev
;
174 struct inet6_dev
*idev
= ip6_dst_idev(skb_dst(skb
));
175 if (unlikely(idev
->cnf
.disable_ipv6
)) {
176 IP6_INC_STATS(dev_net(dev
), idev
,
177 IPSTATS_MIB_OUTDISCARDS
);
182 return NF_HOOK_COND(NFPROTO_IPV6
, NF_INET_POST_ROUTING
, skb
, NULL
, dev
,
184 !(IP6CB(skb
)->flags
& IP6SKB_REROUTED
));
188 * xmit an sk_buff (used by TCP, SCTP and DCCP)
191 int ip6_xmit(struct sock
*sk
, struct sk_buff
*skb
, struct flowi6
*fl6
,
192 struct ipv6_txoptions
*opt
)
194 struct net
*net
= sock_net(sk
);
195 struct ipv6_pinfo
*np
= inet6_sk(sk
);
196 struct in6_addr
*first_hop
= &fl6
->daddr
;
197 struct dst_entry
*dst
= skb_dst(skb
);
199 u8 proto
= fl6
->flowi6_proto
;
200 int seg_len
= skb
->len
;
206 unsigned int head_room
;
208 /* First: exthdrs may take lots of space (~8K for now)
209 MAX_HEADER is not enough.
211 head_room
= opt
->opt_nflen
+ opt
->opt_flen
;
212 seg_len
+= head_room
;
213 head_room
+= sizeof(struct ipv6hdr
) + LL_RESERVED_SPACE(dst
->dev
);
215 if (skb_headroom(skb
) < head_room
) {
216 struct sk_buff
*skb2
= skb_realloc_headroom(skb
, head_room
);
218 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
219 IPSTATS_MIB_OUTDISCARDS
);
225 skb_set_owner_w(skb
, sk
);
228 ipv6_push_frag_opts(skb
, opt
, &proto
);
230 ipv6_push_nfrag_opts(skb
, opt
, &proto
, &first_hop
);
233 skb_push(skb
, sizeof(struct ipv6hdr
));
234 skb_reset_network_header(skb
);
238 * Fill in the IPv6 header
242 hlimit
= np
->hop_limit
;
245 hlimit
= ip6_dst_hoplimit(dst
);
247 *(__be32
*)hdr
= htonl(0x60000000 | (tclass
<< 20)) | fl6
->flowlabel
;
249 hdr
->payload_len
= htons(seg_len
);
250 hdr
->nexthdr
= proto
;
251 hdr
->hop_limit
= hlimit
;
253 ipv6_addr_copy(&hdr
->saddr
, &fl6
->saddr
);
254 ipv6_addr_copy(&hdr
->daddr
, first_hop
);
256 skb
->priority
= sk
->sk_priority
;
257 skb
->mark
= sk
->sk_mark
;
260 if ((skb
->len
<= mtu
) || skb
->local_df
|| skb_is_gso(skb
)) {
261 IP6_UPD_PO_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
262 IPSTATS_MIB_OUT
, skb
->len
);
263 return NF_HOOK(NFPROTO_IPV6
, NF_INET_LOCAL_OUT
, skb
, NULL
,
264 dst
->dev
, dst_output
);
268 printk(KERN_DEBUG
"IPv6: sending pkt_too_big to self\n");
270 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
271 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)), IPSTATS_MIB_FRAGFAILS
);
276 EXPORT_SYMBOL(ip6_xmit
);
279 * To avoid extra problems ND packets are send through this
280 * routine. It's code duplication but I really want to avoid
281 * extra checks since ipv6_build_header is used by TCP (which
282 * is for us performance critical)
285 int ip6_nd_hdr(struct sock
*sk
, struct sk_buff
*skb
, struct net_device
*dev
,
286 const struct in6_addr
*saddr
, const struct in6_addr
*daddr
,
289 struct ipv6_pinfo
*np
= inet6_sk(sk
);
292 skb
->protocol
= htons(ETH_P_IPV6
);
295 skb_reset_network_header(skb
);
296 skb_put(skb
, sizeof(struct ipv6hdr
));
299 *(__be32
*)hdr
= htonl(0x60000000);
301 hdr
->payload_len
= htons(len
);
302 hdr
->nexthdr
= proto
;
303 hdr
->hop_limit
= np
->hop_limit
;
305 ipv6_addr_copy(&hdr
->saddr
, saddr
);
306 ipv6_addr_copy(&hdr
->daddr
, daddr
);
311 static int ip6_call_ra_chain(struct sk_buff
*skb
, int sel
)
313 struct ip6_ra_chain
*ra
;
314 struct sock
*last
= NULL
;
316 read_lock(&ip6_ra_lock
);
317 for (ra
= ip6_ra_chain
; ra
; ra
= ra
->next
) {
318 struct sock
*sk
= ra
->sk
;
319 if (sk
&& ra
->sel
== sel
&&
320 (!sk
->sk_bound_dev_if
||
321 sk
->sk_bound_dev_if
== skb
->dev
->ifindex
)) {
323 struct sk_buff
*skb2
= skb_clone(skb
, GFP_ATOMIC
);
325 rawv6_rcv(last
, skb2
);
332 rawv6_rcv(last
, skb
);
333 read_unlock(&ip6_ra_lock
);
336 read_unlock(&ip6_ra_lock
);
340 static int ip6_forward_proxy_check(struct sk_buff
*skb
)
342 struct ipv6hdr
*hdr
= ipv6_hdr(skb
);
343 u8 nexthdr
= hdr
->nexthdr
;
346 if (ipv6_ext_hdr(nexthdr
)) {
347 offset
= ipv6_skip_exthdr(skb
, sizeof(*hdr
), &nexthdr
);
351 offset
= sizeof(struct ipv6hdr
);
353 if (nexthdr
== IPPROTO_ICMPV6
) {
354 struct icmp6hdr
*icmp6
;
356 if (!pskb_may_pull(skb
, (skb_network_header(skb
) +
357 offset
+ 1 - skb
->data
)))
360 icmp6
= (struct icmp6hdr
*)(skb_network_header(skb
) + offset
);
362 switch (icmp6
->icmp6_type
) {
363 case NDISC_ROUTER_SOLICITATION
:
364 case NDISC_ROUTER_ADVERTISEMENT
:
365 case NDISC_NEIGHBOUR_SOLICITATION
:
366 case NDISC_NEIGHBOUR_ADVERTISEMENT
:
368 /* For reaction involving unicast neighbor discovery
369 * message destined to the proxied address, pass it to
379 * The proxying router can't forward traffic sent to a link-local
380 * address, so signal the sender and discard the packet. This
381 * behavior is clarified by the MIPv6 specification.
383 if (ipv6_addr_type(&hdr
->daddr
) & IPV6_ADDR_LINKLOCAL
) {
384 dst_link_failure(skb
);
391 static inline int ip6_forward_finish(struct sk_buff
*skb
)
393 return dst_output(skb
);
396 int ip6_forward(struct sk_buff
*skb
)
398 struct dst_entry
*dst
= skb_dst(skb
);
399 struct ipv6hdr
*hdr
= ipv6_hdr(skb
);
400 struct inet6_skb_parm
*opt
= IP6CB(skb
);
401 struct net
*net
= dev_net(dst
->dev
);
405 if (net
->ipv6
.devconf_all
->forwarding
== 0)
408 if (skb_warn_if_lro(skb
))
411 if (!xfrm6_policy_check(NULL
, XFRM_POLICY_FWD
, skb
)) {
412 IP6_INC_STATS(net
, ip6_dst_idev(dst
), IPSTATS_MIB_INDISCARDS
);
416 if (skb
->pkt_type
!= PACKET_HOST
)
419 skb_forward_csum(skb
);
422 * We DO NOT make any processing on
423 * RA packets, pushing them to user level AS IS
424 * without ane WARRANTY that application will be able
425 * to interpret them. The reason is that we
426 * cannot make anything clever here.
428 * We are not end-node, so that if packet contains
429 * AH/ESP, we cannot make anything.
430 * Defragmentation also would be mistake, RA packets
431 * cannot be fragmented, because there is no warranty
432 * that different fragments will go along one path. --ANK
435 u8
*ptr
= skb_network_header(skb
) + opt
->ra
;
436 if (ip6_call_ra_chain(skb
, (ptr
[2]<<8) + ptr
[3]))
441 * check and decrement ttl
443 if (hdr
->hop_limit
<= 1) {
444 /* Force OUTPUT device used as source address */
446 icmpv6_send(skb
, ICMPV6_TIME_EXCEED
, ICMPV6_EXC_HOPLIMIT
, 0);
447 IP6_INC_STATS_BH(net
,
448 ip6_dst_idev(dst
), IPSTATS_MIB_INHDRERRORS
);
454 /* XXX: idev->cnf.proxy_ndp? */
455 if (net
->ipv6
.devconf_all
->proxy_ndp
&&
456 pneigh_lookup(&nd_tbl
, net
, &hdr
->daddr
, skb
->dev
, 0)) {
457 int proxied
= ip6_forward_proxy_check(skb
);
459 return ip6_input(skb
);
460 else if (proxied
< 0) {
461 IP6_INC_STATS(net
, ip6_dst_idev(dst
),
462 IPSTATS_MIB_INDISCARDS
);
467 if (!xfrm6_route_forward(skb
)) {
468 IP6_INC_STATS(net
, ip6_dst_idev(dst
), IPSTATS_MIB_INDISCARDS
);
473 /* IPv6 specs say nothing about it, but it is clear that we cannot
474 send redirects to source routed frames.
475 We don't send redirects to frames decapsulated from IPsec.
477 n
= dst_get_neighbour(dst
);
478 if (skb
->dev
== dst
->dev
&& n
&& opt
->srcrt
== 0 && !skb_sec_path(skb
)) {
479 struct in6_addr
*target
= NULL
;
483 * incoming and outgoing devices are the same
487 rt
= (struct rt6_info
*) dst
;
488 if ((rt
->rt6i_flags
& RTF_GATEWAY
))
489 target
= (struct in6_addr
*)&n
->primary_key
;
491 target
= &hdr
->daddr
;
494 rt6_bind_peer(rt
, 1);
496 /* Limit redirects both by destination (here)
497 and by source (inside ndisc_send_redirect)
499 if (inet_peer_xrlim_allow(rt
->rt6i_peer
, 1*HZ
))
500 ndisc_send_redirect(skb
, n
, target
);
502 int addrtype
= ipv6_addr_type(&hdr
->saddr
);
504 /* This check is security critical. */
505 if (addrtype
== IPV6_ADDR_ANY
||
506 addrtype
& (IPV6_ADDR_MULTICAST
| IPV6_ADDR_LOOPBACK
))
508 if (addrtype
& IPV6_ADDR_LINKLOCAL
) {
509 icmpv6_send(skb
, ICMPV6_DEST_UNREACH
,
510 ICMPV6_NOT_NEIGHBOUR
, 0);
516 if (mtu
< IPV6_MIN_MTU
)
519 if (skb
->len
> mtu
&& !skb_is_gso(skb
)) {
520 /* Again, force OUTPUT device used as source address */
522 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
523 IP6_INC_STATS_BH(net
,
524 ip6_dst_idev(dst
), IPSTATS_MIB_INTOOBIGERRORS
);
525 IP6_INC_STATS_BH(net
,
526 ip6_dst_idev(dst
), IPSTATS_MIB_FRAGFAILS
);
531 if (skb_cow(skb
, dst
->dev
->hard_header_len
)) {
532 IP6_INC_STATS(net
, ip6_dst_idev(dst
), IPSTATS_MIB_OUTDISCARDS
);
538 /* Mangling hops number delayed to point after skb COW */
542 IP6_INC_STATS_BH(net
, ip6_dst_idev(dst
), IPSTATS_MIB_OUTFORWDATAGRAMS
);
543 return NF_HOOK(NFPROTO_IPV6
, NF_INET_FORWARD
, skb
, skb
->dev
, dst
->dev
,
547 IP6_INC_STATS_BH(net
, ip6_dst_idev(dst
), IPSTATS_MIB_INADDRERRORS
);
553 static void ip6_copy_metadata(struct sk_buff
*to
, struct sk_buff
*from
)
555 to
->pkt_type
= from
->pkt_type
;
556 to
->priority
= from
->priority
;
557 to
->protocol
= from
->protocol
;
559 skb_dst_set(to
, dst_clone(skb_dst(from
)));
561 to
->mark
= from
->mark
;
563 #ifdef CONFIG_NET_SCHED
564 to
->tc_index
= from
->tc_index
;
567 #if defined(CONFIG_NETFILTER_XT_TARGET_TRACE) || \
568 defined(CONFIG_NETFILTER_XT_TARGET_TRACE_MODULE)
569 to
->nf_trace
= from
->nf_trace
;
571 skb_copy_secmark(to
, from
);
574 int ip6_find_1stfragopt(struct sk_buff
*skb
, u8
**nexthdr
)
576 u16 offset
= sizeof(struct ipv6hdr
);
577 struct ipv6_opt_hdr
*exthdr
=
578 (struct ipv6_opt_hdr
*)(ipv6_hdr(skb
) + 1);
579 unsigned int packet_len
= skb
->tail
- skb
->network_header
;
581 *nexthdr
= &ipv6_hdr(skb
)->nexthdr
;
583 while (offset
+ 1 <= packet_len
) {
589 case NEXTHDR_ROUTING
:
593 #if defined(CONFIG_IPV6_MIP6) || defined(CONFIG_IPV6_MIP6_MODULE)
594 if (ipv6_find_tlv(skb
, offset
, IPV6_TLV_HAO
) >= 0)
604 offset
+= ipv6_optlen(exthdr
);
605 *nexthdr
= &exthdr
->nexthdr
;
606 exthdr
= (struct ipv6_opt_hdr
*)(skb_network_header(skb
) +
613 static u32 hashidentrnd __read_mostly
;
614 #define FID_HASH_SZ 16
615 static u32 ipv6_fragmentation_id
[FID_HASH_SZ
];
617 void __init
initialize_hashidentrnd(void)
619 get_random_bytes(&hashidentrnd
, sizeof(hashidentrnd
));
622 static u32
__ipv6_select_ident(const struct in6_addr
*addr
)
624 u32 newid
, oldid
, hash
= jhash2((u32
*)addr
, 4, hashidentrnd
);
625 u32
*pid
= &ipv6_fragmentation_id
[hash
% FID_HASH_SZ
];
632 } while (cmpxchg(pid
, oldid
, newid
) != oldid
);
637 void ipv6_select_ident(struct frag_hdr
*fhdr
, struct in6_addr
*addr
)
639 fhdr
->identification
= htonl(__ipv6_select_ident(addr
));
642 int ip6_fragment(struct sk_buff
*skb
, int (*output
)(struct sk_buff
*))
644 struct sk_buff
*frag
;
645 struct rt6_info
*rt
= (struct rt6_info
*)skb_dst(skb
);
646 struct ipv6_pinfo
*np
= skb
->sk
? inet6_sk(skb
->sk
) : NULL
;
647 struct ipv6hdr
*tmp_hdr
;
649 unsigned int mtu
, hlen
, left
, len
;
651 int ptr
, offset
= 0, err
=0;
652 u8
*prevhdr
, nexthdr
= 0;
653 struct net
*net
= dev_net(skb_dst(skb
)->dev
);
655 hlen
= ip6_find_1stfragopt(skb
, &prevhdr
);
658 mtu
= ip6_skb_dst_mtu(skb
);
660 /* We must not fragment if the socket is set to force MTU discovery
661 * or if the skb it not generated by a local socket.
663 if (!skb
->local_df
&& skb
->len
> mtu
) {
664 skb
->dev
= skb_dst(skb
)->dev
;
665 icmpv6_send(skb
, ICMPV6_PKT_TOOBIG
, 0, mtu
);
666 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
667 IPSTATS_MIB_FRAGFAILS
);
672 if (np
&& np
->frag_size
< mtu
) {
676 mtu
-= hlen
+ sizeof(struct frag_hdr
);
678 if (skb_has_frag_list(skb
)) {
679 int first_len
= skb_pagelen(skb
);
680 struct sk_buff
*frag2
;
682 if (first_len
- hlen
> mtu
||
683 ((first_len
- hlen
) & 7) ||
687 skb_walk_frags(skb
, frag
) {
688 /* Correct geometry. */
689 if (frag
->len
> mtu
||
690 ((frag
->len
& 7) && frag
->next
) ||
691 skb_headroom(frag
) < hlen
)
692 goto slow_path_clean
;
694 /* Partially cloned skb? */
695 if (skb_shared(frag
))
696 goto slow_path_clean
;
701 frag
->destructor
= sock_wfree
;
703 skb
->truesize
-= frag
->truesize
;
708 frag
= skb_shinfo(skb
)->frag_list
;
709 skb_frag_list_init(skb
);
712 *prevhdr
= NEXTHDR_FRAGMENT
;
713 tmp_hdr
= kmemdup(skb_network_header(skb
), hlen
, GFP_ATOMIC
);
715 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
716 IPSTATS_MIB_FRAGFAILS
);
720 __skb_pull(skb
, hlen
);
721 fh
= (struct frag_hdr
*)__skb_push(skb
, sizeof(struct frag_hdr
));
722 __skb_push(skb
, hlen
);
723 skb_reset_network_header(skb
);
724 memcpy(skb_network_header(skb
), tmp_hdr
, hlen
);
726 ipv6_select_ident(fh
, &rt
->rt6i_dst
.addr
);
727 fh
->nexthdr
= nexthdr
;
729 fh
->frag_off
= htons(IP6_MF
);
730 frag_id
= fh
->identification
;
732 first_len
= skb_pagelen(skb
);
733 skb
->data_len
= first_len
- skb_headlen(skb
);
734 skb
->len
= first_len
;
735 ipv6_hdr(skb
)->payload_len
= htons(first_len
-
736 sizeof(struct ipv6hdr
));
741 /* Prepare header of the next frame,
742 * before previous one went down. */
744 frag
->ip_summed
= CHECKSUM_NONE
;
745 skb_reset_transport_header(frag
);
746 fh
= (struct frag_hdr
*)__skb_push(frag
, sizeof(struct frag_hdr
));
747 __skb_push(frag
, hlen
);
748 skb_reset_network_header(frag
);
749 memcpy(skb_network_header(frag
), tmp_hdr
,
751 offset
+= skb
->len
- hlen
- sizeof(struct frag_hdr
);
752 fh
->nexthdr
= nexthdr
;
754 fh
->frag_off
= htons(offset
);
755 if (frag
->next
!= NULL
)
756 fh
->frag_off
|= htons(IP6_MF
);
757 fh
->identification
= frag_id
;
758 ipv6_hdr(frag
)->payload_len
=
760 sizeof(struct ipv6hdr
));
761 ip6_copy_metadata(frag
, skb
);
766 IP6_INC_STATS(net
, ip6_dst_idev(&rt
->dst
),
767 IPSTATS_MIB_FRAGCREATES
);
780 IP6_INC_STATS(net
, ip6_dst_idev(&rt
->dst
),
781 IPSTATS_MIB_FRAGOKS
);
782 dst_release(&rt
->dst
);
792 IP6_INC_STATS(net
, ip6_dst_idev(&rt
->dst
),
793 IPSTATS_MIB_FRAGFAILS
);
794 dst_release(&rt
->dst
);
798 skb_walk_frags(skb
, frag2
) {
802 frag2
->destructor
= NULL
;
803 skb
->truesize
+= frag2
->truesize
;
808 left
= skb
->len
- hlen
; /* Space per frame */
809 ptr
= hlen
; /* Where to start from */
812 * Fragment the datagram.
815 *prevhdr
= NEXTHDR_FRAGMENT
;
818 * Keep copying data until we run out.
822 /* IF: it doesn't fit, use 'mtu' - the data space left */
825 /* IF: we are not sending up to and including the packet end
826 then align the next start on an eight byte boundary */
834 if ((frag
= alloc_skb(len
+hlen
+sizeof(struct frag_hdr
)+LL_ALLOCATED_SPACE(rt
->dst
.dev
), GFP_ATOMIC
)) == NULL
) {
835 NETDEBUG(KERN_INFO
"IPv6: frag: no memory for new fragment!\n");
836 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
837 IPSTATS_MIB_FRAGFAILS
);
843 * Set up data on packet
846 ip6_copy_metadata(frag
, skb
);
847 skb_reserve(frag
, LL_RESERVED_SPACE(rt
->dst
.dev
));
848 skb_put(frag
, len
+ hlen
+ sizeof(struct frag_hdr
));
849 skb_reset_network_header(frag
);
850 fh
= (struct frag_hdr
*)(skb_network_header(frag
) + hlen
);
851 frag
->transport_header
= (frag
->network_header
+ hlen
+
852 sizeof(struct frag_hdr
));
855 * Charge the memory for the fragment to any owner
859 skb_set_owner_w(frag
, skb
->sk
);
862 * Copy the packet header into the new buffer.
864 skb_copy_from_linear_data(skb
, skb_network_header(frag
), hlen
);
867 * Build fragment header.
869 fh
->nexthdr
= nexthdr
;
872 ipv6_select_ident(fh
, &rt
->rt6i_dst
.addr
);
873 frag_id
= fh
->identification
;
875 fh
->identification
= frag_id
;
878 * Copy a block of the IP datagram.
880 if (skb_copy_bits(skb
, ptr
, skb_transport_header(frag
), len
))
884 fh
->frag_off
= htons(offset
);
886 fh
->frag_off
|= htons(IP6_MF
);
887 ipv6_hdr(frag
)->payload_len
= htons(frag
->len
-
888 sizeof(struct ipv6hdr
));
894 * Put this fragment into the sending queue.
900 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
901 IPSTATS_MIB_FRAGCREATES
);
903 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
904 IPSTATS_MIB_FRAGOKS
);
909 IP6_INC_STATS(net
, ip6_dst_idev(skb_dst(skb
)),
910 IPSTATS_MIB_FRAGFAILS
);
915 static inline int ip6_rt_check(const struct rt6key
*rt_key
,
916 const struct in6_addr
*fl_addr
,
917 const struct in6_addr
*addr_cache
)
919 return (rt_key
->plen
!= 128 || !ipv6_addr_equal(fl_addr
, &rt_key
->addr
)) &&
920 (addr_cache
== NULL
|| !ipv6_addr_equal(fl_addr
, addr_cache
));
923 static struct dst_entry
*ip6_sk_dst_check(struct sock
*sk
,
924 struct dst_entry
*dst
,
925 const struct flowi6
*fl6
)
927 struct ipv6_pinfo
*np
= inet6_sk(sk
);
928 struct rt6_info
*rt
= (struct rt6_info
*)dst
;
933 /* Yes, checking route validity in not connected
934 * case is not very simple. Take into account,
935 * that we do not support routing by source, TOS,
936 * and MSG_DONTROUTE --ANK (980726)
938 * 1. ip6_rt_check(): If route was host route,
939 * check that cached destination is current.
940 * If it is network route, we still may
941 * check its validity using saved pointer
942 * to the last used address: daddr_cache.
943 * We do not want to save whole address now,
944 * (because main consumer of this service
945 * is tcp, which has not this problem),
946 * so that the last trick works only on connected
948 * 2. oif also should be the same.
950 if (ip6_rt_check(&rt
->rt6i_dst
, &fl6
->daddr
, np
->daddr_cache
) ||
951 #ifdef CONFIG_IPV6_SUBTREES
952 ip6_rt_check(&rt
->rt6i_src
, &fl6
->saddr
, np
->saddr_cache
) ||
954 (fl6
->flowi6_oif
&& fl6
->flowi6_oif
!= dst
->dev
->ifindex
)) {
963 static int ip6_dst_lookup_tail(struct sock
*sk
,
964 struct dst_entry
**dst
, struct flowi6
*fl6
)
966 struct net
*net
= sock_net(sk
);
967 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
973 *dst
= ip6_route_output(net
, sk
, fl6
);
975 if ((err
= (*dst
)->error
))
976 goto out_err_release
;
978 if (ipv6_addr_any(&fl6
->saddr
)) {
979 struct rt6_info
*rt
= (struct rt6_info
*) *dst
;
980 err
= ip6_route_get_saddr(net
, rt
, &fl6
->daddr
,
981 sk
? inet6_sk(sk
)->srcprefs
: 0,
984 goto out_err_release
;
987 #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
989 * Here if the dst entry we've looked up
990 * has a neighbour entry that is in the INCOMPLETE
991 * state and the src address from the flow is
992 * marked as OPTIMISTIC, we release the found
993 * dst entry and replace it instead with the
994 * dst entry of the nexthop router
997 n
= dst_get_neighbour(*dst
);
998 if (n
&& !(n
->nud_state
& NUD_VALID
)) {
999 struct inet6_ifaddr
*ifp
;
1000 struct flowi6 fl_gw6
;
1004 ifp
= ipv6_get_ifaddr(net
, &fl6
->saddr
,
1007 redirect
= (ifp
&& ifp
->flags
& IFA_F_OPTIMISTIC
);
1013 * We need to get the dst entry for the
1014 * default router instead
1017 memcpy(&fl_gw6
, fl6
, sizeof(struct flowi6
));
1018 memset(&fl_gw6
.daddr
, 0, sizeof(struct in6_addr
));
1019 *dst
= ip6_route_output(net
, sk
, &fl_gw6
);
1020 if ((err
= (*dst
)->error
))
1021 goto out_err_release
;
1031 if (err
== -ENETUNREACH
)
1032 IP6_INC_STATS_BH(net
, NULL
, IPSTATS_MIB_OUTNOROUTES
);
1039 * ip6_dst_lookup - perform route lookup on flow
1040 * @sk: socket which provides route info
1041 * @dst: pointer to dst_entry * for result
1042 * @fl6: flow to lookup
1044 * This function performs a route lookup on the given flow.
1046 * It returns zero on success, or a standard errno code on error.
1048 int ip6_dst_lookup(struct sock
*sk
, struct dst_entry
**dst
, struct flowi6
*fl6
)
1051 return ip6_dst_lookup_tail(sk
, dst
, fl6
);
1053 EXPORT_SYMBOL_GPL(ip6_dst_lookup
);
1056 * ip6_dst_lookup_flow - perform route lookup on flow with ipsec
1057 * @sk: socket which provides route info
1058 * @fl6: flow to lookup
1059 * @final_dst: final destination address for ipsec lookup
1060 * @can_sleep: we are in a sleepable context
1062 * This function performs a route lookup on the given flow.
1064 * It returns a valid dst pointer on success, or a pointer encoded
1067 struct dst_entry
*ip6_dst_lookup_flow(struct sock
*sk
, struct flowi6
*fl6
,
1068 const struct in6_addr
*final_dst
,
1071 struct dst_entry
*dst
= NULL
;
1074 err
= ip6_dst_lookup_tail(sk
, &dst
, fl6
);
1076 return ERR_PTR(err
);
1078 ipv6_addr_copy(&fl6
->daddr
, final_dst
);
1080 fl6
->flowi6_flags
|= FLOWI_FLAG_CAN_SLEEP
;
1082 return xfrm_lookup(sock_net(sk
), dst
, flowi6_to_flowi(fl6
), sk
, 0);
1084 EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow
);
1087 * ip6_sk_dst_lookup_flow - perform socket cached route lookup on flow
1088 * @sk: socket which provides the dst cache and route info
1089 * @fl6: flow to lookup
1090 * @final_dst: final destination address for ipsec lookup
1091 * @can_sleep: we are in a sleepable context
1093 * This function performs a route lookup on the given flow with the
1094 * possibility of using the cached route in the socket if it is valid.
1095 * It will take the socket dst lock when operating on the dst cache.
1096 * As a result, this function can only be used in process context.
1098 * It returns a valid dst pointer on success, or a pointer encoded
1101 struct dst_entry
*ip6_sk_dst_lookup_flow(struct sock
*sk
, struct flowi6
*fl6
,
1102 const struct in6_addr
*final_dst
,
1105 struct dst_entry
*dst
= sk_dst_check(sk
, inet6_sk(sk
)->dst_cookie
);
1108 dst
= ip6_sk_dst_check(sk
, dst
, fl6
);
1110 err
= ip6_dst_lookup_tail(sk
, &dst
, fl6
);
1112 return ERR_PTR(err
);
1114 ipv6_addr_copy(&fl6
->daddr
, final_dst
);
1116 fl6
->flowi6_flags
|= FLOWI_FLAG_CAN_SLEEP
;
1118 return xfrm_lookup(sock_net(sk
), dst
, flowi6_to_flowi(fl6
), sk
, 0);
1120 EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow
);
1122 static inline int ip6_ufo_append_data(struct sock
*sk
,
1123 int getfrag(void *from
, char *to
, int offset
, int len
,
1124 int odd
, struct sk_buff
*skb
),
1125 void *from
, int length
, int hh_len
, int fragheaderlen
,
1126 int transhdrlen
, int mtu
,unsigned int flags
,
1127 struct rt6_info
*rt
)
1130 struct sk_buff
*skb
;
1133 /* There is support for UDP large send offload by network
1134 * device, so create one single skb packet containing complete
1137 if ((skb
= skb_peek_tail(&sk
->sk_write_queue
)) == NULL
) {
1138 skb
= sock_alloc_send_skb(sk
,
1139 hh_len
+ fragheaderlen
+ transhdrlen
+ 20,
1140 (flags
& MSG_DONTWAIT
), &err
);
1144 /* reserve space for Hardware header */
1145 skb_reserve(skb
, hh_len
);
1147 /* create space for UDP/IP header */
1148 skb_put(skb
,fragheaderlen
+ transhdrlen
);
1150 /* initialize network header pointer */
1151 skb_reset_network_header(skb
);
1153 /* initialize protocol header pointer */
1154 skb
->transport_header
= skb
->network_header
+ fragheaderlen
;
1156 skb
->ip_summed
= CHECKSUM_PARTIAL
;
1160 err
= skb_append_datato_frags(sk
,skb
, getfrag
, from
,
1161 (length
- transhdrlen
));
1163 struct frag_hdr fhdr
;
1165 /* Specify the length of each IPv6 datagram fragment.
1166 * It has to be a multiple of 8.
1168 skb_shinfo(skb
)->gso_size
= (mtu
- fragheaderlen
-
1169 sizeof(struct frag_hdr
)) & ~7;
1170 skb_shinfo(skb
)->gso_type
= SKB_GSO_UDP
;
1171 ipv6_select_ident(&fhdr
, &rt
->rt6i_dst
.addr
);
1172 skb_shinfo(skb
)->ip6_frag_id
= fhdr
.identification
;
1173 __skb_queue_tail(&sk
->sk_write_queue
, skb
);
1177 /* There is not enough support do UPD LSO,
1178 * so follow normal path
1185 static inline struct ipv6_opt_hdr
*ip6_opt_dup(struct ipv6_opt_hdr
*src
,
1188 return src
? kmemdup(src
, (src
->hdrlen
+ 1) * 8, gfp
) : NULL
;
1191 static inline struct ipv6_rt_hdr
*ip6_rthdr_dup(struct ipv6_rt_hdr
*src
,
1194 return src
? kmemdup(src
, (src
->hdrlen
+ 1) * 8, gfp
) : NULL
;
1197 int ip6_append_data(struct sock
*sk
, int getfrag(void *from
, char *to
,
1198 int offset
, int len
, int odd
, struct sk_buff
*skb
),
1199 void *from
, int length
, int transhdrlen
,
1200 int hlimit
, int tclass
, struct ipv6_txoptions
*opt
, struct flowi6
*fl6
,
1201 struct rt6_info
*rt
, unsigned int flags
, int dontfrag
)
1203 struct inet_sock
*inet
= inet_sk(sk
);
1204 struct ipv6_pinfo
*np
= inet6_sk(sk
);
1205 struct inet_cork
*cork
;
1206 struct sk_buff
*skb
;
1207 unsigned int maxfraglen
, fragheaderlen
;
1214 int csummode
= CHECKSUM_NONE
;
1217 if (flags
&MSG_PROBE
)
1219 cork
= &inet
->cork
.base
;
1220 if (skb_queue_empty(&sk
->sk_write_queue
)) {
1225 if (WARN_ON(np
->cork
.opt
))
1228 np
->cork
.opt
= kmalloc(opt
->tot_len
, sk
->sk_allocation
);
1229 if (unlikely(np
->cork
.opt
== NULL
))
1232 np
->cork
.opt
->tot_len
= opt
->tot_len
;
1233 np
->cork
.opt
->opt_flen
= opt
->opt_flen
;
1234 np
->cork
.opt
->opt_nflen
= opt
->opt_nflen
;
1236 np
->cork
.opt
->dst0opt
= ip6_opt_dup(opt
->dst0opt
,
1238 if (opt
->dst0opt
&& !np
->cork
.opt
->dst0opt
)
1241 np
->cork
.opt
->dst1opt
= ip6_opt_dup(opt
->dst1opt
,
1243 if (opt
->dst1opt
&& !np
->cork
.opt
->dst1opt
)
1246 np
->cork
.opt
->hopopt
= ip6_opt_dup(opt
->hopopt
,
1248 if (opt
->hopopt
&& !np
->cork
.opt
->hopopt
)
1251 np
->cork
.opt
->srcrt
= ip6_rthdr_dup(opt
->srcrt
,
1253 if (opt
->srcrt
&& !np
->cork
.opt
->srcrt
)
1256 /* need source address above miyazawa*/
1259 cork
->dst
= &rt
->dst
;
1260 inet
->cork
.fl
.u
.ip6
= *fl6
;
1261 np
->cork
.hop_limit
= hlimit
;
1262 np
->cork
.tclass
= tclass
;
1263 mtu
= np
->pmtudisc
== IPV6_PMTUDISC_PROBE
?
1264 rt
->dst
.dev
->mtu
: dst_mtu(rt
->dst
.path
);
1265 if (np
->frag_size
< mtu
) {
1267 mtu
= np
->frag_size
;
1269 cork
->fragsize
= mtu
;
1270 if (dst_allfrag(rt
->dst
.path
))
1271 cork
->flags
|= IPCORK_ALLFRAG
;
1273 sk
->sk_sndmsg_page
= NULL
;
1274 sk
->sk_sndmsg_off
= 0;
1275 exthdrlen
= rt
->dst
.header_len
+ (opt
? opt
->opt_flen
: 0) -
1276 rt
->rt6i_nfheader_len
;
1277 length
+= exthdrlen
;
1278 transhdrlen
+= exthdrlen
;
1280 rt
= (struct rt6_info
*)cork
->dst
;
1281 fl6
= &inet
->cork
.fl
.u
.ip6
;
1285 mtu
= cork
->fragsize
;
1288 hh_len
= LL_RESERVED_SPACE(rt
->dst
.dev
);
1290 fragheaderlen
= sizeof(struct ipv6hdr
) + rt
->rt6i_nfheader_len
+
1291 (opt
? opt
->opt_nflen
: 0);
1292 maxfraglen
= ((mtu
- fragheaderlen
) & ~7) + fragheaderlen
- sizeof(struct frag_hdr
);
1294 if (mtu
<= sizeof(struct ipv6hdr
) + IPV6_MAXPLEN
) {
1295 if (cork
->length
+ length
> sizeof(struct ipv6hdr
) + IPV6_MAXPLEN
- fragheaderlen
) {
1296 ipv6_local_error(sk
, EMSGSIZE
, fl6
, mtu
-exthdrlen
);
1301 /* For UDP, check if TX timestamp is enabled */
1302 if (sk
->sk_type
== SOCK_DGRAM
) {
1303 err
= sock_tx_timestamp(sk
, &tx_flags
);
1309 * Let's try using as much space as possible.
1310 * Use MTU if total length of the message fits into the MTU.
1311 * Otherwise, we need to reserve fragment header and
1312 * fragment alignment (= 8-15 octects, in total).
1314 * Note that we may need to "move" the data from the tail of
1315 * of the buffer to the new fragment when we split
1318 * FIXME: It may be fragmented into multiple chunks
1319 * at once if non-fragmentable extension headers
1324 cork
->length
+= length
;
1326 int proto
= sk
->sk_protocol
;
1327 if (dontfrag
&& (proto
== IPPROTO_UDP
|| proto
== IPPROTO_RAW
)){
1328 ipv6_local_rxpmtu(sk
, fl6
, mtu
-exthdrlen
);
1332 if (proto
== IPPROTO_UDP
&&
1333 (rt
->dst
.dev
->features
& NETIF_F_UFO
)) {
1335 err
= ip6_ufo_append_data(sk
, getfrag
, from
, length
,
1336 hh_len
, fragheaderlen
,
1337 transhdrlen
, mtu
, flags
, rt
);
1344 if ((skb
= skb_peek_tail(&sk
->sk_write_queue
)) == NULL
)
1347 while (length
> 0) {
1348 /* Check if the remaining data fits into current packet. */
1349 copy
= (cork
->length
<= mtu
&& !(cork
->flags
& IPCORK_ALLFRAG
) ? mtu
: maxfraglen
) - skb
->len
;
1351 copy
= maxfraglen
- skb
->len
;
1355 unsigned int datalen
;
1356 unsigned int fraglen
;
1357 unsigned int fraggap
;
1358 unsigned int alloclen
;
1359 struct sk_buff
*skb_prev
;
1363 /* There's no room in the current skb */
1365 fraggap
= skb_prev
->len
- maxfraglen
;
1370 * If remaining data exceeds the mtu,
1371 * we know we need more fragment(s).
1373 datalen
= length
+ fraggap
;
1374 if (datalen
> (cork
->length
<= mtu
&& !(cork
->flags
& IPCORK_ALLFRAG
) ? mtu
: maxfraglen
) - fragheaderlen
)
1375 datalen
= maxfraglen
- fragheaderlen
;
1377 fraglen
= datalen
+ fragheaderlen
;
1378 if ((flags
& MSG_MORE
) &&
1379 !(rt
->dst
.dev
->features
&NETIF_F_SG
))
1382 alloclen
= datalen
+ fragheaderlen
;
1385 * The last fragment gets additional space at tail.
1386 * Note: we overallocate on fragments with MSG_MODE
1387 * because we have no idea if we're the last one.
1389 if (datalen
== length
+ fraggap
)
1390 alloclen
+= rt
->dst
.trailer_len
;
1393 * We just reserve space for fragment header.
1394 * Note: this may be overallocation if the message
1395 * (without MSG_MORE) fits into the MTU.
1397 alloclen
+= sizeof(struct frag_hdr
);
1400 skb
= sock_alloc_send_skb(sk
,
1402 (flags
& MSG_DONTWAIT
), &err
);
1405 if (atomic_read(&sk
->sk_wmem_alloc
) <=
1407 skb
= sock_wmalloc(sk
,
1408 alloclen
+ hh_len
, 1,
1410 if (unlikely(skb
== NULL
))
1413 /* Only the initial fragment
1422 * Fill in the control structures
1424 skb
->ip_summed
= csummode
;
1426 /* reserve for fragmentation */
1427 skb_reserve(skb
, hh_len
+sizeof(struct frag_hdr
));
1429 if (sk
->sk_type
== SOCK_DGRAM
)
1430 skb_shinfo(skb
)->tx_flags
= tx_flags
;
1433 * Find where to start putting bytes
1435 data
= skb_put(skb
, fraglen
);
1436 skb_set_network_header(skb
, exthdrlen
);
1437 data
+= fragheaderlen
;
1438 skb
->transport_header
= (skb
->network_header
+
1441 skb
->csum
= skb_copy_and_csum_bits(
1442 skb_prev
, maxfraglen
,
1443 data
+ transhdrlen
, fraggap
, 0);
1444 skb_prev
->csum
= csum_sub(skb_prev
->csum
,
1447 pskb_trim_unique(skb_prev
, maxfraglen
);
1449 copy
= datalen
- transhdrlen
- fraggap
;
1454 } else if (copy
> 0 && getfrag(from
, data
+ transhdrlen
, offset
, copy
, fraggap
, skb
) < 0) {
1461 length
-= datalen
- fraggap
;
1464 csummode
= CHECKSUM_NONE
;
1467 * Put the packet on the pending queue
1469 __skb_queue_tail(&sk
->sk_write_queue
, skb
);
1476 if (!(rt
->dst
.dev
->features
&NETIF_F_SG
)) {
1480 if (getfrag(from
, skb_put(skb
, copy
),
1481 offset
, copy
, off
, skb
) < 0) {
1482 __skb_trim(skb
, off
);
1487 int i
= skb_shinfo(skb
)->nr_frags
;
1488 skb_frag_t
*frag
= &skb_shinfo(skb
)->frags
[i
-1];
1489 struct page
*page
= sk
->sk_sndmsg_page
;
1490 int off
= sk
->sk_sndmsg_off
;
1493 if (page
&& (left
= PAGE_SIZE
- off
) > 0) {
1496 if (page
!= frag
->page
) {
1497 if (i
== MAX_SKB_FRAGS
) {
1502 skb_fill_page_desc(skb
, i
, page
, sk
->sk_sndmsg_off
, 0);
1503 frag
= &skb_shinfo(skb
)->frags
[i
];
1505 } else if(i
< MAX_SKB_FRAGS
) {
1506 if (copy
> PAGE_SIZE
)
1508 page
= alloc_pages(sk
->sk_allocation
, 0);
1513 sk
->sk_sndmsg_page
= page
;
1514 sk
->sk_sndmsg_off
= 0;
1516 skb_fill_page_desc(skb
, i
, page
, 0, 0);
1517 frag
= &skb_shinfo(skb
)->frags
[i
];
1522 if (getfrag(from
, page_address(frag
->page
)+frag
->page_offset
+frag
->size
, offset
, copy
, skb
->len
, skb
) < 0) {
1526 sk
->sk_sndmsg_off
+= copy
;
1529 skb
->data_len
+= copy
;
1530 skb
->truesize
+= copy
;
1531 atomic_add(copy
, &sk
->sk_wmem_alloc
);
1538 cork
->length
-= length
;
1539 IP6_INC_STATS(sock_net(sk
), rt
->rt6i_idev
, IPSTATS_MIB_OUTDISCARDS
);
1543 static void ip6_cork_release(struct inet_sock
*inet
, struct ipv6_pinfo
*np
)
1546 kfree(np
->cork
.opt
->dst0opt
);
1547 kfree(np
->cork
.opt
->dst1opt
);
1548 kfree(np
->cork
.opt
->hopopt
);
1549 kfree(np
->cork
.opt
->srcrt
);
1550 kfree(np
->cork
.opt
);
1551 np
->cork
.opt
= NULL
;
1554 if (inet
->cork
.base
.dst
) {
1555 dst_release(inet
->cork
.base
.dst
);
1556 inet
->cork
.base
.dst
= NULL
;
1557 inet
->cork
.base
.flags
&= ~IPCORK_ALLFRAG
;
1559 memset(&inet
->cork
.fl
, 0, sizeof(inet
->cork
.fl
));
1562 int ip6_push_pending_frames(struct sock
*sk
)
1564 struct sk_buff
*skb
, *tmp_skb
;
1565 struct sk_buff
**tail_skb
;
1566 struct in6_addr final_dst_buf
, *final_dst
= &final_dst_buf
;
1567 struct inet_sock
*inet
= inet_sk(sk
);
1568 struct ipv6_pinfo
*np
= inet6_sk(sk
);
1569 struct net
*net
= sock_net(sk
);
1570 struct ipv6hdr
*hdr
;
1571 struct ipv6_txoptions
*opt
= np
->cork
.opt
;
1572 struct rt6_info
*rt
= (struct rt6_info
*)inet
->cork
.base
.dst
;
1573 struct flowi6
*fl6
= &inet
->cork
.fl
.u
.ip6
;
1574 unsigned char proto
= fl6
->flowi6_proto
;
1577 if ((skb
= __skb_dequeue(&sk
->sk_write_queue
)) == NULL
)
1579 tail_skb
= &(skb_shinfo(skb
)->frag_list
);
1581 /* move skb->data to ip header from ext header */
1582 if (skb
->data
< skb_network_header(skb
))
1583 __skb_pull(skb
, skb_network_offset(skb
));
1584 while ((tmp_skb
= __skb_dequeue(&sk
->sk_write_queue
)) != NULL
) {
1585 __skb_pull(tmp_skb
, skb_network_header_len(skb
));
1586 *tail_skb
= tmp_skb
;
1587 tail_skb
= &(tmp_skb
->next
);
1588 skb
->len
+= tmp_skb
->len
;
1589 skb
->data_len
+= tmp_skb
->len
;
1590 skb
->truesize
+= tmp_skb
->truesize
;
1591 tmp_skb
->destructor
= NULL
;
1595 /* Allow local fragmentation. */
1596 if (np
->pmtudisc
< IPV6_PMTUDISC_DO
)
1599 ipv6_addr_copy(final_dst
, &fl6
->daddr
);
1600 __skb_pull(skb
, skb_network_header_len(skb
));
1601 if (opt
&& opt
->opt_flen
)
1602 ipv6_push_frag_opts(skb
, opt
, &proto
);
1603 if (opt
&& opt
->opt_nflen
)
1604 ipv6_push_nfrag_opts(skb
, opt
, &proto
, &final_dst
);
1606 skb_push(skb
, sizeof(struct ipv6hdr
));
1607 skb_reset_network_header(skb
);
1608 hdr
= ipv6_hdr(skb
);
1610 *(__be32
*)hdr
= fl6
->flowlabel
|
1611 htonl(0x60000000 | ((int)np
->cork
.tclass
<< 20));
1613 hdr
->hop_limit
= np
->cork
.hop_limit
;
1614 hdr
->nexthdr
= proto
;
1615 ipv6_addr_copy(&hdr
->saddr
, &fl6
->saddr
);
1616 ipv6_addr_copy(&hdr
->daddr
, final_dst
);
1618 skb
->priority
= sk
->sk_priority
;
1619 skb
->mark
= sk
->sk_mark
;
1621 skb_dst_set(skb
, dst_clone(&rt
->dst
));
1622 IP6_UPD_PO_STATS(net
, rt
->rt6i_idev
, IPSTATS_MIB_OUT
, skb
->len
);
1623 if (proto
== IPPROTO_ICMPV6
) {
1624 struct inet6_dev
*idev
= ip6_dst_idev(skb_dst(skb
));
1626 ICMP6MSGOUT_INC_STATS_BH(net
, idev
, icmp6_hdr(skb
)->icmp6_type
);
1627 ICMP6_INC_STATS_BH(net
, idev
, ICMP6_MIB_OUTMSGS
);
1630 err
= ip6_local_out(skb
);
1633 err
= net_xmit_errno(err
);
1639 ip6_cork_release(inet
, np
);
1642 IP6_INC_STATS(net
, rt
->rt6i_idev
, IPSTATS_MIB_OUTDISCARDS
);
1646 void ip6_flush_pending_frames(struct sock
*sk
)
1648 struct sk_buff
*skb
;
1650 while ((skb
= __skb_dequeue_tail(&sk
->sk_write_queue
)) != NULL
) {
1652 IP6_INC_STATS(sock_net(sk
), ip6_dst_idev(skb_dst(skb
)),
1653 IPSTATS_MIB_OUTDISCARDS
);
1657 ip6_cork_release(inet_sk(sk
), inet6_sk(sk
));