ip6_output.c 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248
  1. /*
  2. * IPv6 output functions
  3. * Linux INET6 implementation
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. * $Id: ip6_output.c,v 1.34 2002/02/01 22:01:04 davem Exp $
  9. *
  10. * Based on linux/net/ipv4/ip_output.c
  11. *
  12. * This program is free software; you can redistribute it and/or
  13. * modify it under the terms of the GNU General Public License
  14. * as published by the Free Software Foundation; either version
  15. * 2 of the License, or (at your option) any later version.
  16. *
  17. * Changes:
  18. * A.N.Kuznetsov : airthmetics in fragmentation.
  19. * extension headers are implemented.
  20. * route changes now work.
  21. * ip6_forward does not confuse sniffers.
  22. * etc.
  23. *
  24. * H. von Brand : Added missing #include <linux/string.h>
  25. * Imran Patel : frag id should be in NBO
  26. * Kazunori MIYAZAWA @USAGI
  27. * : add ip6_append_data and related functions
  28. * for datagram xmit
  29. */
  30. #include <linux/config.h>
  31. #include <linux/errno.h>
  32. #include <linux/types.h>
  33. #include <linux/string.h>
  34. #include <linux/socket.h>
  35. #include <linux/net.h>
  36. #include <linux/netdevice.h>
  37. #include <linux/if_arp.h>
  38. #include <linux/in6.h>
  39. #include <linux/tcp.h>
  40. #include <linux/route.h>
  41. #include <linux/netfilter.h>
  42. #include <linux/netfilter_ipv6.h>
  43. #include <net/sock.h>
  44. #include <net/snmp.h>
  45. #include <net/ipv6.h>
  46. #include <net/ndisc.h>
  47. #include <net/protocol.h>
  48. #include <net/ip6_route.h>
  49. #include <net/addrconf.h>
  50. #include <net/rawv6.h>
  51. #include <net/icmp.h>
  52. #include <net/xfrm.h>
  53. #include <net/checksum.h>
  54. static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *));
  55. static __inline__ void ipv6_select_ident(struct sk_buff *skb, struct frag_hdr *fhdr)
  56. {
  57. static u32 ipv6_fragmentation_id = 1;
  58. static DEFINE_SPINLOCK(ip6_id_lock);
  59. spin_lock_bh(&ip6_id_lock);
  60. fhdr->identification = htonl(ipv6_fragmentation_id);
  61. if (++ipv6_fragmentation_id == 0)
  62. ipv6_fragmentation_id = 1;
  63. spin_unlock_bh(&ip6_id_lock);
  64. }
  65. static inline int ip6_output_finish(struct sk_buff *skb)
  66. {
  67. struct dst_entry *dst = skb->dst;
  68. struct hh_cache *hh = dst->hh;
  69. if (hh) {
  70. int hh_alen;
  71. read_lock_bh(&hh->hh_lock);
  72. hh_alen = HH_DATA_ALIGN(hh->hh_len);
  73. memcpy(skb->data - hh_alen, hh->hh_data, hh_alen);
  74. read_unlock_bh(&hh->hh_lock);
  75. skb_push(skb, hh->hh_len);
  76. return hh->hh_output(skb);
  77. } else if (dst->neighbour)
  78. return dst->neighbour->output(skb);
  79. IP6_INC_STATS_BH(IPSTATS_MIB_OUTNOROUTES);
  80. kfree_skb(skb);
  81. return -EINVAL;
  82. }
  83. /* dev_loopback_xmit for use with netfilter. */
  84. static int ip6_dev_loopback_xmit(struct sk_buff *newskb)
  85. {
  86. newskb->mac.raw = newskb->data;
  87. __skb_pull(newskb, newskb->nh.raw - newskb->data);
  88. newskb->pkt_type = PACKET_LOOPBACK;
  89. newskb->ip_summed = CHECKSUM_UNNECESSARY;
  90. BUG_TRAP(newskb->dst);
  91. netif_rx(newskb);
  92. return 0;
  93. }
  94. static int ip6_output2(struct sk_buff *skb)
  95. {
  96. struct dst_entry *dst = skb->dst;
  97. struct net_device *dev = dst->dev;
  98. skb->protocol = htons(ETH_P_IPV6);
  99. skb->dev = dev;
  100. if (ipv6_addr_is_multicast(&skb->nh.ipv6h->daddr)) {
  101. struct ipv6_pinfo* np = skb->sk ? inet6_sk(skb->sk) : NULL;
  102. if (!(dev->flags & IFF_LOOPBACK) && (!np || np->mc_loop) &&
  103. ipv6_chk_mcast_addr(dev, &skb->nh.ipv6h->daddr,
  104. &skb->nh.ipv6h->saddr)) {
  105. struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
  106. /* Do not check for IFF_ALLMULTI; multicast routing
  107. is not supported in any case.
  108. */
  109. if (newskb)
  110. NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, newskb, NULL,
  111. newskb->dev,
  112. ip6_dev_loopback_xmit);
  113. if (skb->nh.ipv6h->hop_limit == 0) {
  114. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  115. kfree_skb(skb);
  116. return 0;
  117. }
  118. }
  119. IP6_INC_STATS(IPSTATS_MIB_OUTMCASTPKTS);
  120. }
  121. return NF_HOOK(PF_INET6, NF_IP6_POST_ROUTING, skb,NULL, skb->dev,ip6_output_finish);
  122. }
  123. int ip6_output(struct sk_buff *skb)
  124. {
  125. if ((skb->len > dst_mtu(skb->dst) && !skb_shinfo(skb)->ufo_size) ||
  126. dst_allfrag(skb->dst))
  127. return ip6_fragment(skb, ip6_output2);
  128. else
  129. return ip6_output2(skb);
  130. }
  131. /*
  132. * xmit an sk_buff (used by TCP)
  133. */
  134. int ip6_xmit(struct sock *sk, struct sk_buff *skb, struct flowi *fl,
  135. struct ipv6_txoptions *opt, int ipfragok)
  136. {
  137. struct ipv6_pinfo *np = inet6_sk(sk);
  138. struct in6_addr *first_hop = &fl->fl6_dst;
  139. struct dst_entry *dst = skb->dst;
  140. struct ipv6hdr *hdr;
  141. u8 proto = fl->proto;
  142. int seg_len = skb->len;
  143. int hlimit, tclass;
  144. u32 mtu;
  145. if (opt) {
  146. int head_room;
  147. /* First: exthdrs may take lots of space (~8K for now)
  148. MAX_HEADER is not enough.
  149. */
  150. head_room = opt->opt_nflen + opt->opt_flen;
  151. seg_len += head_room;
  152. head_room += sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dst->dev);
  153. if (skb_headroom(skb) < head_room) {
  154. struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
  155. kfree_skb(skb);
  156. skb = skb2;
  157. if (skb == NULL) {
  158. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  159. return -ENOBUFS;
  160. }
  161. if (sk)
  162. skb_set_owner_w(skb, sk);
  163. }
  164. if (opt->opt_flen)
  165. ipv6_push_frag_opts(skb, opt, &proto);
  166. if (opt->opt_nflen)
  167. ipv6_push_nfrag_opts(skb, opt, &proto, &first_hop);
  168. }
  169. hdr = skb->nh.ipv6h = (struct ipv6hdr*)skb_push(skb, sizeof(struct ipv6hdr));
  170. /*
  171. * Fill in the IPv6 header
  172. */
  173. hlimit = -1;
  174. if (np)
  175. hlimit = np->hop_limit;
  176. if (hlimit < 0)
  177. hlimit = dst_metric(dst, RTAX_HOPLIMIT);
  178. if (hlimit < 0)
  179. hlimit = ipv6_get_hoplimit(dst->dev);
  180. tclass = -1;
  181. if (np)
  182. tclass = np->tclass;
  183. if (tclass < 0)
  184. tclass = 0;
  185. *(u32 *)hdr = htonl(0x60000000 | (tclass << 20)) | fl->fl6_flowlabel;
  186. hdr->payload_len = htons(seg_len);
  187. hdr->nexthdr = proto;
  188. hdr->hop_limit = hlimit;
  189. ipv6_addr_copy(&hdr->saddr, &fl->fl6_src);
  190. ipv6_addr_copy(&hdr->daddr, first_hop);
  191. skb->priority = sk->sk_priority;
  192. mtu = dst_mtu(dst);
  193. if ((skb->len <= mtu) || ipfragok) {
  194. IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
  195. return NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, dst->dev,
  196. dst_output);
  197. }
  198. if (net_ratelimit())
  199. printk(KERN_DEBUG "IPv6: sending pkt_too_big to self\n");
  200. skb->dev = dst->dev;
  201. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu, skb->dev);
  202. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  203. kfree_skb(skb);
  204. return -EMSGSIZE;
  205. }
  206. /*
  207. * To avoid extra problems ND packets are send through this
  208. * routine. It's code duplication but I really want to avoid
  209. * extra checks since ipv6_build_header is used by TCP (which
  210. * is for us performance critical)
  211. */
  212. int ip6_nd_hdr(struct sock *sk, struct sk_buff *skb, struct net_device *dev,
  213. struct in6_addr *saddr, struct in6_addr *daddr,
  214. int proto, int len)
  215. {
  216. struct ipv6_pinfo *np = inet6_sk(sk);
  217. struct ipv6hdr *hdr;
  218. int totlen;
  219. skb->protocol = htons(ETH_P_IPV6);
  220. skb->dev = dev;
  221. totlen = len + sizeof(struct ipv6hdr);
  222. hdr = (struct ipv6hdr *) skb_put(skb, sizeof(struct ipv6hdr));
  223. skb->nh.ipv6h = hdr;
  224. *(u32*)hdr = htonl(0x60000000);
  225. hdr->payload_len = htons(len);
  226. hdr->nexthdr = proto;
  227. hdr->hop_limit = np->hop_limit;
  228. ipv6_addr_copy(&hdr->saddr, saddr);
  229. ipv6_addr_copy(&hdr->daddr, daddr);
  230. return 0;
  231. }
  232. static int ip6_call_ra_chain(struct sk_buff *skb, int sel)
  233. {
  234. struct ip6_ra_chain *ra;
  235. struct sock *last = NULL;
  236. read_lock(&ip6_ra_lock);
  237. for (ra = ip6_ra_chain; ra; ra = ra->next) {
  238. struct sock *sk = ra->sk;
  239. if (sk && ra->sel == sel &&
  240. (!sk->sk_bound_dev_if ||
  241. sk->sk_bound_dev_if == skb->dev->ifindex)) {
  242. if (last) {
  243. struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
  244. if (skb2)
  245. rawv6_rcv(last, skb2);
  246. }
  247. last = sk;
  248. }
  249. }
  250. if (last) {
  251. rawv6_rcv(last, skb);
  252. read_unlock(&ip6_ra_lock);
  253. return 1;
  254. }
  255. read_unlock(&ip6_ra_lock);
  256. return 0;
  257. }
  258. static inline int ip6_forward_finish(struct sk_buff *skb)
  259. {
  260. return dst_output(skb);
  261. }
  262. int ip6_forward(struct sk_buff *skb)
  263. {
  264. struct dst_entry *dst = skb->dst;
  265. struct ipv6hdr *hdr = skb->nh.ipv6h;
  266. struct inet6_skb_parm *opt = IP6CB(skb);
  267. if (ipv6_devconf.forwarding == 0)
  268. goto error;
  269. if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
  270. IP6_INC_STATS(IPSTATS_MIB_INDISCARDS);
  271. goto drop;
  272. }
  273. skb->ip_summed = CHECKSUM_NONE;
  274. /*
  275. * We DO NOT make any processing on
  276. * RA packets, pushing them to user level AS IS
  277. * without ane WARRANTY that application will be able
  278. * to interpret them. The reason is that we
  279. * cannot make anything clever here.
  280. *
  281. * We are not end-node, so that if packet contains
  282. * AH/ESP, we cannot make anything.
  283. * Defragmentation also would be mistake, RA packets
  284. * cannot be fragmented, because there is no warranty
  285. * that different fragments will go along one path. --ANK
  286. */
  287. if (opt->ra) {
  288. u8 *ptr = skb->nh.raw + opt->ra;
  289. if (ip6_call_ra_chain(skb, (ptr[2]<<8) + ptr[3]))
  290. return 0;
  291. }
  292. /*
  293. * check and decrement ttl
  294. */
  295. if (hdr->hop_limit <= 1) {
  296. /* Force OUTPUT device used as source address */
  297. skb->dev = dst->dev;
  298. icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT,
  299. 0, skb->dev);
  300. kfree_skb(skb);
  301. return -ETIMEDOUT;
  302. }
  303. if (!xfrm6_route_forward(skb)) {
  304. IP6_INC_STATS(IPSTATS_MIB_INDISCARDS);
  305. goto drop;
  306. }
  307. dst = skb->dst;
  308. /* IPv6 specs say nothing about it, but it is clear that we cannot
  309. send redirects to source routed frames.
  310. */
  311. if (skb->dev == dst->dev && dst->neighbour && opt->srcrt == 0) {
  312. struct in6_addr *target = NULL;
  313. struct rt6_info *rt;
  314. struct neighbour *n = dst->neighbour;
  315. /*
  316. * incoming and outgoing devices are the same
  317. * send a redirect.
  318. */
  319. rt = (struct rt6_info *) dst;
  320. if ((rt->rt6i_flags & RTF_GATEWAY))
  321. target = (struct in6_addr*)&n->primary_key;
  322. else
  323. target = &hdr->daddr;
  324. /* Limit redirects both by destination (here)
  325. and by source (inside ndisc_send_redirect)
  326. */
  327. if (xrlim_allow(dst, 1*HZ))
  328. ndisc_send_redirect(skb, n, target);
  329. } else if (ipv6_addr_type(&hdr->saddr)&(IPV6_ADDR_MULTICAST|IPV6_ADDR_LOOPBACK
  330. |IPV6_ADDR_LINKLOCAL)) {
  331. /* This check is security critical. */
  332. goto error;
  333. }
  334. if (skb->len > dst_mtu(dst)) {
  335. /* Again, force OUTPUT device used as source address */
  336. skb->dev = dst->dev;
  337. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, dst_mtu(dst), skb->dev);
  338. IP6_INC_STATS_BH(IPSTATS_MIB_INTOOBIGERRORS);
  339. IP6_INC_STATS_BH(IPSTATS_MIB_FRAGFAILS);
  340. kfree_skb(skb);
  341. return -EMSGSIZE;
  342. }
  343. if (skb_cow(skb, dst->dev->hard_header_len)) {
  344. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  345. goto drop;
  346. }
  347. hdr = skb->nh.ipv6h;
  348. /* Mangling hops number delayed to point after skb COW */
  349. hdr->hop_limit--;
  350. IP6_INC_STATS_BH(IPSTATS_MIB_OUTFORWDATAGRAMS);
  351. return NF_HOOK(PF_INET6,NF_IP6_FORWARD, skb, skb->dev, dst->dev, ip6_forward_finish);
  352. error:
  353. IP6_INC_STATS_BH(IPSTATS_MIB_INADDRERRORS);
  354. drop:
  355. kfree_skb(skb);
  356. return -EINVAL;
  357. }
  358. static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from)
  359. {
  360. to->pkt_type = from->pkt_type;
  361. to->priority = from->priority;
  362. to->protocol = from->protocol;
  363. dst_release(to->dst);
  364. to->dst = dst_clone(from->dst);
  365. to->dev = from->dev;
  366. #ifdef CONFIG_NET_SCHED
  367. to->tc_index = from->tc_index;
  368. #endif
  369. #ifdef CONFIG_NETFILTER
  370. to->nfmark = from->nfmark;
  371. /* Connection association is same as pre-frag packet */
  372. nf_conntrack_put(to->nfct);
  373. to->nfct = from->nfct;
  374. nf_conntrack_get(to->nfct);
  375. to->nfctinfo = from->nfctinfo;
  376. #if defined(CONFIG_NF_CONNTRACK) || defined(CONFIG_NF_CONNTRACK_MODULE)
  377. nf_conntrack_put_reasm(to->nfct_reasm);
  378. to->nfct_reasm = from->nfct_reasm;
  379. nf_conntrack_get_reasm(to->nfct_reasm);
  380. #endif
  381. #ifdef CONFIG_BRIDGE_NETFILTER
  382. nf_bridge_put(to->nf_bridge);
  383. to->nf_bridge = from->nf_bridge;
  384. nf_bridge_get(to->nf_bridge);
  385. #endif
  386. #endif
  387. }
  388. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  389. {
  390. u16 offset = sizeof(struct ipv6hdr);
  391. struct ipv6_opt_hdr *exthdr = (struct ipv6_opt_hdr*)(skb->nh.ipv6h + 1);
  392. unsigned int packet_len = skb->tail - skb->nh.raw;
  393. int found_rhdr = 0;
  394. *nexthdr = &skb->nh.ipv6h->nexthdr;
  395. while (offset + 1 <= packet_len) {
  396. switch (**nexthdr) {
  397. case NEXTHDR_HOP:
  398. case NEXTHDR_ROUTING:
  399. case NEXTHDR_DEST:
  400. if (**nexthdr == NEXTHDR_ROUTING) found_rhdr = 1;
  401. if (**nexthdr == NEXTHDR_DEST && found_rhdr) return offset;
  402. offset += ipv6_optlen(exthdr);
  403. *nexthdr = &exthdr->nexthdr;
  404. exthdr = (struct ipv6_opt_hdr*)(skb->nh.raw + offset);
  405. break;
  406. default :
  407. return offset;
  408. }
  409. }
  410. return offset;
  411. }
  412. static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
  413. {
  414. struct net_device *dev;
  415. struct sk_buff *frag;
  416. struct rt6_info *rt = (struct rt6_info*)skb->dst;
  417. struct ipv6_pinfo *np = skb->sk ? inet6_sk(skb->sk) : NULL;
  418. struct ipv6hdr *tmp_hdr;
  419. struct frag_hdr *fh;
  420. unsigned int mtu, hlen, left, len;
  421. u32 frag_id = 0;
  422. int ptr, offset = 0, err=0;
  423. u8 *prevhdr, nexthdr = 0;
  424. dev = rt->u.dst.dev;
  425. hlen = ip6_find_1stfragopt(skb, &prevhdr);
  426. nexthdr = *prevhdr;
  427. mtu = dst_mtu(&rt->u.dst);
  428. if (np && np->frag_size < mtu) {
  429. if (np->frag_size)
  430. mtu = np->frag_size;
  431. }
  432. mtu -= hlen + sizeof(struct frag_hdr);
  433. if (skb_shinfo(skb)->frag_list) {
  434. int first_len = skb_pagelen(skb);
  435. if (first_len - hlen > mtu ||
  436. ((first_len - hlen) & 7) ||
  437. skb_cloned(skb))
  438. goto slow_path;
  439. for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
  440. /* Correct geometry. */
  441. if (frag->len > mtu ||
  442. ((frag->len & 7) && frag->next) ||
  443. skb_headroom(frag) < hlen)
  444. goto slow_path;
  445. /* Partially cloned skb? */
  446. if (skb_shared(frag))
  447. goto slow_path;
  448. BUG_ON(frag->sk);
  449. if (skb->sk) {
  450. sock_hold(skb->sk);
  451. frag->sk = skb->sk;
  452. frag->destructor = sock_wfree;
  453. skb->truesize -= frag->truesize;
  454. }
  455. }
  456. err = 0;
  457. offset = 0;
  458. frag = skb_shinfo(skb)->frag_list;
  459. skb_shinfo(skb)->frag_list = NULL;
  460. /* BUILD HEADER */
  461. tmp_hdr = kmalloc(hlen, GFP_ATOMIC);
  462. if (!tmp_hdr) {
  463. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  464. return -ENOMEM;
  465. }
  466. *prevhdr = NEXTHDR_FRAGMENT;
  467. memcpy(tmp_hdr, skb->nh.raw, hlen);
  468. __skb_pull(skb, hlen);
  469. fh = (struct frag_hdr*)__skb_push(skb, sizeof(struct frag_hdr));
  470. skb->nh.raw = __skb_push(skb, hlen);
  471. memcpy(skb->nh.raw, tmp_hdr, hlen);
  472. ipv6_select_ident(skb, fh);
  473. fh->nexthdr = nexthdr;
  474. fh->reserved = 0;
  475. fh->frag_off = htons(IP6_MF);
  476. frag_id = fh->identification;
  477. first_len = skb_pagelen(skb);
  478. skb->data_len = first_len - skb_headlen(skb);
  479. skb->len = first_len;
  480. skb->nh.ipv6h->payload_len = htons(first_len - sizeof(struct ipv6hdr));
  481. for (;;) {
  482. /* Prepare header of the next frame,
  483. * before previous one went down. */
  484. if (frag) {
  485. frag->ip_summed = CHECKSUM_NONE;
  486. frag->h.raw = frag->data;
  487. fh = (struct frag_hdr*)__skb_push(frag, sizeof(struct frag_hdr));
  488. frag->nh.raw = __skb_push(frag, hlen);
  489. memcpy(frag->nh.raw, tmp_hdr, hlen);
  490. offset += skb->len - hlen - sizeof(struct frag_hdr);
  491. fh->nexthdr = nexthdr;
  492. fh->reserved = 0;
  493. fh->frag_off = htons(offset);
  494. if (frag->next != NULL)
  495. fh->frag_off |= htons(IP6_MF);
  496. fh->identification = frag_id;
  497. frag->nh.ipv6h->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
  498. ip6_copy_metadata(frag, skb);
  499. }
  500. err = output(skb);
  501. if (err || !frag)
  502. break;
  503. skb = frag;
  504. frag = skb->next;
  505. skb->next = NULL;
  506. }
  507. kfree(tmp_hdr);
  508. if (err == 0) {
  509. IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
  510. return 0;
  511. }
  512. while (frag) {
  513. skb = frag->next;
  514. kfree_skb(frag);
  515. frag = skb;
  516. }
  517. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  518. return err;
  519. }
  520. slow_path:
  521. left = skb->len - hlen; /* Space per frame */
  522. ptr = hlen; /* Where to start from */
  523. /*
  524. * Fragment the datagram.
  525. */
  526. *prevhdr = NEXTHDR_FRAGMENT;
  527. /*
  528. * Keep copying data until we run out.
  529. */
  530. while(left > 0) {
  531. len = left;
  532. /* IF: it doesn't fit, use 'mtu' - the data space left */
  533. if (len > mtu)
  534. len = mtu;
  535. /* IF: we are not sending upto and including the packet end
  536. then align the next start on an eight byte boundary */
  537. if (len < left) {
  538. len &= ~7;
  539. }
  540. /*
  541. * Allocate buffer.
  542. */
  543. if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_RESERVED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) {
  544. NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n");
  545. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  546. err = -ENOMEM;
  547. goto fail;
  548. }
  549. /*
  550. * Set up data on packet
  551. */
  552. ip6_copy_metadata(frag, skb);
  553. skb_reserve(frag, LL_RESERVED_SPACE(rt->u.dst.dev));
  554. skb_put(frag, len + hlen + sizeof(struct frag_hdr));
  555. frag->nh.raw = frag->data;
  556. fh = (struct frag_hdr*)(frag->data + hlen);
  557. frag->h.raw = frag->data + hlen + sizeof(struct frag_hdr);
  558. /*
  559. * Charge the memory for the fragment to any owner
  560. * it might possess
  561. */
  562. if (skb->sk)
  563. skb_set_owner_w(frag, skb->sk);
  564. /*
  565. * Copy the packet header into the new buffer.
  566. */
  567. memcpy(frag->nh.raw, skb->data, hlen);
  568. /*
  569. * Build fragment header.
  570. */
  571. fh->nexthdr = nexthdr;
  572. fh->reserved = 0;
  573. if (!frag_id) {
  574. ipv6_select_ident(skb, fh);
  575. frag_id = fh->identification;
  576. } else
  577. fh->identification = frag_id;
  578. /*
  579. * Copy a block of the IP datagram.
  580. */
  581. if (skb_copy_bits(skb, ptr, frag->h.raw, len))
  582. BUG();
  583. left -= len;
  584. fh->frag_off = htons(offset);
  585. if (left > 0)
  586. fh->frag_off |= htons(IP6_MF);
  587. frag->nh.ipv6h->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
  588. ptr += len;
  589. offset += len;
  590. /*
  591. * Put this fragment into the sending queue.
  592. */
  593. IP6_INC_STATS(IPSTATS_MIB_FRAGCREATES);
  594. err = output(frag);
  595. if (err)
  596. goto fail;
  597. }
  598. kfree_skb(skb);
  599. IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
  600. return err;
  601. fail:
  602. kfree_skb(skb);
  603. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  604. return err;
  605. }
  606. int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi *fl)
  607. {
  608. int err = 0;
  609. *dst = NULL;
  610. if (sk) {
  611. struct ipv6_pinfo *np = inet6_sk(sk);
  612. *dst = sk_dst_check(sk, np->dst_cookie);
  613. if (*dst) {
  614. struct rt6_info *rt = (struct rt6_info*)*dst;
  615. /* Yes, checking route validity in not connected
  616. * case is not very simple. Take into account,
  617. * that we do not support routing by source, TOS,
  618. * and MSG_DONTROUTE --ANK (980726)
  619. *
  620. * 1. If route was host route, check that
  621. * cached destination is current.
  622. * If it is network route, we still may
  623. * check its validity using saved pointer
  624. * to the last used address: daddr_cache.
  625. * We do not want to save whole address now,
  626. * (because main consumer of this service
  627. * is tcp, which has not this problem),
  628. * so that the last trick works only on connected
  629. * sockets.
  630. * 2. oif also should be the same.
  631. */
  632. if (((rt->rt6i_dst.plen != 128 ||
  633. !ipv6_addr_equal(&fl->fl6_dst,
  634. &rt->rt6i_dst.addr))
  635. && (np->daddr_cache == NULL ||
  636. !ipv6_addr_equal(&fl->fl6_dst,
  637. np->daddr_cache)))
  638. || (fl->oif && fl->oif != (*dst)->dev->ifindex)) {
  639. dst_release(*dst);
  640. *dst = NULL;
  641. }
  642. }
  643. }
  644. if (*dst == NULL)
  645. *dst = ip6_route_output(sk, fl);
  646. if ((err = (*dst)->error))
  647. goto out_err_release;
  648. if (ipv6_addr_any(&fl->fl6_src)) {
  649. err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
  650. if (err)
  651. goto out_err_release;
  652. }
  653. return 0;
  654. out_err_release:
  655. dst_release(*dst);
  656. *dst = NULL;
  657. return err;
  658. }
  659. EXPORT_SYMBOL_GPL(ip6_dst_lookup);
  660. static inline int ip6_ufo_append_data(struct sock *sk,
  661. int getfrag(void *from, char *to, int offset, int len,
  662. int odd, struct sk_buff *skb),
  663. void *from, int length, int hh_len, int fragheaderlen,
  664. int transhdrlen, int mtu,unsigned int flags)
  665. {
  666. struct sk_buff *skb;
  667. int err;
  668. /* There is support for UDP large send offload by network
  669. * device, so create one single skb packet containing complete
  670. * udp datagram
  671. */
  672. if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) {
  673. skb = sock_alloc_send_skb(sk,
  674. hh_len + fragheaderlen + transhdrlen + 20,
  675. (flags & MSG_DONTWAIT), &err);
  676. if (skb == NULL)
  677. return -ENOMEM;
  678. /* reserve space for Hardware header */
  679. skb_reserve(skb, hh_len);
  680. /* create space for UDP/IP header */
  681. skb_put(skb,fragheaderlen + transhdrlen);
  682. /* initialize network header pointer */
  683. skb->nh.raw = skb->data;
  684. /* initialize protocol header pointer */
  685. skb->h.raw = skb->data + fragheaderlen;
  686. skb->ip_summed = CHECKSUM_HW;
  687. skb->csum = 0;
  688. sk->sk_sndmsg_off = 0;
  689. }
  690. err = skb_append_datato_frags(sk,skb, getfrag, from,
  691. (length - transhdrlen));
  692. if (!err) {
  693. struct frag_hdr fhdr;
  694. /* specify the length of each IP datagram fragment*/
  695. skb_shinfo(skb)->ufo_size = (mtu - fragheaderlen) -
  696. sizeof(struct frag_hdr);
  697. ipv6_select_ident(skb, &fhdr);
  698. skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
  699. __skb_queue_tail(&sk->sk_write_queue, skb);
  700. return 0;
  701. }
  702. /* There is not enough support do UPD LSO,
  703. * so follow normal path
  704. */
  705. kfree_skb(skb);
  706. return err;
  707. }
  708. int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
  709. int offset, int len, int odd, struct sk_buff *skb),
  710. void *from, int length, int transhdrlen,
  711. int hlimit, int tclass, struct ipv6_txoptions *opt, struct flowi *fl,
  712. struct rt6_info *rt, unsigned int flags)
  713. {
  714. struct inet_sock *inet = inet_sk(sk);
  715. struct ipv6_pinfo *np = inet6_sk(sk);
  716. struct sk_buff *skb;
  717. unsigned int maxfraglen, fragheaderlen;
  718. int exthdrlen;
  719. int hh_len;
  720. int mtu;
  721. int copy;
  722. int err;
  723. int offset = 0;
  724. int csummode = CHECKSUM_NONE;
  725. if (flags&MSG_PROBE)
  726. return 0;
  727. if (skb_queue_empty(&sk->sk_write_queue)) {
  728. /*
  729. * setup for corking
  730. */
  731. if (opt) {
  732. if (np->cork.opt == NULL) {
  733. np->cork.opt = kmalloc(opt->tot_len,
  734. sk->sk_allocation);
  735. if (unlikely(np->cork.opt == NULL))
  736. return -ENOBUFS;
  737. } else if (np->cork.opt->tot_len < opt->tot_len) {
  738. printk(KERN_DEBUG "ip6_append_data: invalid option length\n");
  739. return -EINVAL;
  740. }
  741. memcpy(np->cork.opt, opt, opt->tot_len);
  742. inet->cork.flags |= IPCORK_OPT;
  743. /* need source address above miyazawa*/
  744. }
  745. dst_hold(&rt->u.dst);
  746. np->cork.rt = rt;
  747. inet->cork.fl = *fl;
  748. np->cork.hop_limit = hlimit;
  749. np->cork.tclass = tclass;
  750. mtu = dst_mtu(rt->u.dst.path);
  751. if (np->frag_size < mtu) {
  752. if (np->frag_size)
  753. mtu = np->frag_size;
  754. }
  755. inet->cork.fragsize = mtu;
  756. if (dst_allfrag(rt->u.dst.path))
  757. inet->cork.flags |= IPCORK_ALLFRAG;
  758. inet->cork.length = 0;
  759. sk->sk_sndmsg_page = NULL;
  760. sk->sk_sndmsg_off = 0;
  761. exthdrlen = rt->u.dst.header_len + (opt ? opt->opt_flen : 0);
  762. length += exthdrlen;
  763. transhdrlen += exthdrlen;
  764. } else {
  765. rt = np->cork.rt;
  766. fl = &inet->cork.fl;
  767. if (inet->cork.flags & IPCORK_OPT)
  768. opt = np->cork.opt;
  769. transhdrlen = 0;
  770. exthdrlen = 0;
  771. mtu = inet->cork.fragsize;
  772. }
  773. hh_len = LL_RESERVED_SPACE(rt->u.dst.dev);
  774. fragheaderlen = sizeof(struct ipv6hdr) + (opt ? opt->opt_nflen : 0);
  775. maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen - sizeof(struct frag_hdr);
  776. if (mtu <= sizeof(struct ipv6hdr) + IPV6_MAXPLEN) {
  777. if (inet->cork.length + length > sizeof(struct ipv6hdr) + IPV6_MAXPLEN - fragheaderlen) {
  778. ipv6_local_error(sk, EMSGSIZE, fl, mtu-exthdrlen);
  779. return -EMSGSIZE;
  780. }
  781. }
  782. /*
  783. * Let's try using as much space as possible.
  784. * Use MTU if total length of the message fits into the MTU.
  785. * Otherwise, we need to reserve fragment header and
  786. * fragment alignment (= 8-15 octects, in total).
  787. *
  788. * Note that we may need to "move" the data from the tail of
  789. * of the buffer to the new fragment when we split
  790. * the message.
  791. *
  792. * FIXME: It may be fragmented into multiple chunks
  793. * at once if non-fragmentable extension headers
  794. * are too large.
  795. * --yoshfuji
  796. */
  797. inet->cork.length += length;
  798. if (((length > mtu) && (sk->sk_protocol == IPPROTO_UDP)) &&
  799. (rt->u.dst.dev->features & NETIF_F_UFO)) {
  800. err = ip6_ufo_append_data(sk, getfrag, from, length, hh_len,
  801. fragheaderlen, transhdrlen, mtu,
  802. flags);
  803. if (err)
  804. goto error;
  805. return 0;
  806. }
  807. if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL)
  808. goto alloc_new_skb;
  809. while (length > 0) {
  810. /* Check if the remaining data fits into current packet. */
  811. copy = (inet->cork.length <= mtu && !(inet->cork.flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - skb->len;
  812. if (copy < length)
  813. copy = maxfraglen - skb->len;
  814. if (copy <= 0) {
  815. char *data;
  816. unsigned int datalen;
  817. unsigned int fraglen;
  818. unsigned int fraggap;
  819. unsigned int alloclen;
  820. struct sk_buff *skb_prev;
  821. alloc_new_skb:
  822. skb_prev = skb;
  823. /* There's no room in the current skb */
  824. if (skb_prev)
  825. fraggap = skb_prev->len - maxfraglen;
  826. else
  827. fraggap = 0;
  828. /*
  829. * If remaining data exceeds the mtu,
  830. * we know we need more fragment(s).
  831. */
  832. datalen = length + fraggap;
  833. if (datalen > (inet->cork.length <= mtu && !(inet->cork.flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
  834. datalen = maxfraglen - fragheaderlen;
  835. fraglen = datalen + fragheaderlen;
  836. if ((flags & MSG_MORE) &&
  837. !(rt->u.dst.dev->features&NETIF_F_SG))
  838. alloclen = mtu;
  839. else
  840. alloclen = datalen + fragheaderlen;
  841. /*
  842. * The last fragment gets additional space at tail.
  843. * Note: we overallocate on fragments with MSG_MODE
  844. * because we have no idea if we're the last one.
  845. */
  846. if (datalen == length + fraggap)
  847. alloclen += rt->u.dst.trailer_len;
  848. /*
  849. * We just reserve space for fragment header.
  850. * Note: this may be overallocation if the message
  851. * (without MSG_MORE) fits into the MTU.
  852. */
  853. alloclen += sizeof(struct frag_hdr);
  854. if (transhdrlen) {
  855. skb = sock_alloc_send_skb(sk,
  856. alloclen + hh_len,
  857. (flags & MSG_DONTWAIT), &err);
  858. } else {
  859. skb = NULL;
  860. if (atomic_read(&sk->sk_wmem_alloc) <=
  861. 2 * sk->sk_sndbuf)
  862. skb = sock_wmalloc(sk,
  863. alloclen + hh_len, 1,
  864. sk->sk_allocation);
  865. if (unlikely(skb == NULL))
  866. err = -ENOBUFS;
  867. }
  868. if (skb == NULL)
  869. goto error;
  870. /*
  871. * Fill in the control structures
  872. */
  873. skb->ip_summed = csummode;
  874. skb->csum = 0;
  875. /* reserve for fragmentation */
  876. skb_reserve(skb, hh_len+sizeof(struct frag_hdr));
  877. /*
  878. * Find where to start putting bytes
  879. */
  880. data = skb_put(skb, fraglen);
  881. skb->nh.raw = data + exthdrlen;
  882. data += fragheaderlen;
  883. skb->h.raw = data + exthdrlen;
  884. if (fraggap) {
  885. skb->csum = skb_copy_and_csum_bits(
  886. skb_prev, maxfraglen,
  887. data + transhdrlen, fraggap, 0);
  888. skb_prev->csum = csum_sub(skb_prev->csum,
  889. skb->csum);
  890. data += fraggap;
  891. skb_trim(skb_prev, maxfraglen);
  892. }
  893. copy = datalen - transhdrlen - fraggap;
  894. if (copy < 0) {
  895. err = -EINVAL;
  896. kfree_skb(skb);
  897. goto error;
  898. } else if (copy > 0 && getfrag(from, data + transhdrlen, offset, copy, fraggap, skb) < 0) {
  899. err = -EFAULT;
  900. kfree_skb(skb);
  901. goto error;
  902. }
  903. offset += copy;
  904. length -= datalen - fraggap;
  905. transhdrlen = 0;
  906. exthdrlen = 0;
  907. csummode = CHECKSUM_NONE;
  908. /*
  909. * Put the packet on the pending queue
  910. */
  911. __skb_queue_tail(&sk->sk_write_queue, skb);
  912. continue;
  913. }
  914. if (copy > length)
  915. copy = length;
  916. if (!(rt->u.dst.dev->features&NETIF_F_SG)) {
  917. unsigned int off;
  918. off = skb->len;
  919. if (getfrag(from, skb_put(skb, copy),
  920. offset, copy, off, skb) < 0) {
  921. __skb_trim(skb, off);
  922. err = -EFAULT;
  923. goto error;
  924. }
  925. } else {
  926. int i = skb_shinfo(skb)->nr_frags;
  927. skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
  928. struct page *page = sk->sk_sndmsg_page;
  929. int off = sk->sk_sndmsg_off;
  930. unsigned int left;
  931. if (page && (left = PAGE_SIZE - off) > 0) {
  932. if (copy >= left)
  933. copy = left;
  934. if (page != frag->page) {
  935. if (i == MAX_SKB_FRAGS) {
  936. err = -EMSGSIZE;
  937. goto error;
  938. }
  939. get_page(page);
  940. skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0);
  941. frag = &skb_shinfo(skb)->frags[i];
  942. }
  943. } else if(i < MAX_SKB_FRAGS) {
  944. if (copy > PAGE_SIZE)
  945. copy = PAGE_SIZE;
  946. page = alloc_pages(sk->sk_allocation, 0);
  947. if (page == NULL) {
  948. err = -ENOMEM;
  949. goto error;
  950. }
  951. sk->sk_sndmsg_page = page;
  952. sk->sk_sndmsg_off = 0;
  953. skb_fill_page_desc(skb, i, page, 0, 0);
  954. frag = &skb_shinfo(skb)->frags[i];
  955. skb->truesize += PAGE_SIZE;
  956. atomic_add(PAGE_SIZE, &sk->sk_wmem_alloc);
  957. } else {
  958. err = -EMSGSIZE;
  959. goto error;
  960. }
  961. if (getfrag(from, page_address(frag->page)+frag->page_offset+frag->size, offset, copy, skb->len, skb) < 0) {
  962. err = -EFAULT;
  963. goto error;
  964. }
  965. sk->sk_sndmsg_off += copy;
  966. frag->size += copy;
  967. skb->len += copy;
  968. skb->data_len += copy;
  969. }
  970. offset += copy;
  971. length -= copy;
  972. }
  973. return 0;
  974. error:
  975. inet->cork.length -= length;
  976. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  977. return err;
  978. }
  979. int ip6_push_pending_frames(struct sock *sk)
  980. {
  981. struct sk_buff *skb, *tmp_skb;
  982. struct sk_buff **tail_skb;
  983. struct in6_addr final_dst_buf, *final_dst = &final_dst_buf;
  984. struct inet_sock *inet = inet_sk(sk);
  985. struct ipv6_pinfo *np = inet6_sk(sk);
  986. struct ipv6hdr *hdr;
  987. struct ipv6_txoptions *opt = np->cork.opt;
  988. struct rt6_info *rt = np->cork.rt;
  989. struct flowi *fl = &inet->cork.fl;
  990. unsigned char proto = fl->proto;
  991. int err = 0;
  992. if ((skb = __skb_dequeue(&sk->sk_write_queue)) == NULL)
  993. goto out;
  994. tail_skb = &(skb_shinfo(skb)->frag_list);
  995. /* move skb->data to ip header from ext header */
  996. if (skb->data < skb->nh.raw)
  997. __skb_pull(skb, skb->nh.raw - skb->data);
  998. while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
  999. __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
  1000. *tail_skb = tmp_skb;
  1001. tail_skb = &(tmp_skb->next);
  1002. skb->len += tmp_skb->len;
  1003. skb->data_len += tmp_skb->len;
  1004. skb->truesize += tmp_skb->truesize;
  1005. __sock_put(tmp_skb->sk);
  1006. tmp_skb->destructor = NULL;
  1007. tmp_skb->sk = NULL;
  1008. }
  1009. ipv6_addr_copy(final_dst, &fl->fl6_dst);
  1010. __skb_pull(skb, skb->h.raw - skb->nh.raw);
  1011. if (opt && opt->opt_flen)
  1012. ipv6_push_frag_opts(skb, opt, &proto);
  1013. if (opt && opt->opt_nflen)
  1014. ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst);
  1015. skb->nh.ipv6h = hdr = (struct ipv6hdr*) skb_push(skb, sizeof(struct ipv6hdr));
  1016. *(u32*)hdr = fl->fl6_flowlabel |
  1017. htonl(0x60000000 | ((int)np->cork.tclass << 20));
  1018. if (skb->len <= sizeof(struct ipv6hdr) + IPV6_MAXPLEN)
  1019. hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
  1020. else
  1021. hdr->payload_len = 0;
  1022. hdr->hop_limit = np->cork.hop_limit;
  1023. hdr->nexthdr = proto;
  1024. ipv6_addr_copy(&hdr->saddr, &fl->fl6_src);
  1025. ipv6_addr_copy(&hdr->daddr, final_dst);
  1026. skb->priority = sk->sk_priority;
  1027. skb->dst = dst_clone(&rt->u.dst);
  1028. IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
  1029. err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dst->dev, dst_output);
  1030. if (err) {
  1031. if (err > 0)
  1032. err = np->recverr ? net_xmit_errno(err) : 0;
  1033. if (err)
  1034. goto error;
  1035. }
  1036. out:
  1037. inet->cork.flags &= ~IPCORK_OPT;
  1038. kfree(np->cork.opt);
  1039. np->cork.opt = NULL;
  1040. if (np->cork.rt) {
  1041. dst_release(&np->cork.rt->u.dst);
  1042. np->cork.rt = NULL;
  1043. inet->cork.flags &= ~IPCORK_ALLFRAG;
  1044. }
  1045. memset(&inet->cork.fl, 0, sizeof(inet->cork.fl));
  1046. return err;
  1047. error:
  1048. goto out;
  1049. }
  1050. void ip6_flush_pending_frames(struct sock *sk)
  1051. {
  1052. struct inet_sock *inet = inet_sk(sk);
  1053. struct ipv6_pinfo *np = inet6_sk(sk);
  1054. struct sk_buff *skb;
  1055. while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) {
  1056. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  1057. kfree_skb(skb);
  1058. }
  1059. inet->cork.flags &= ~IPCORK_OPT;
  1060. kfree(np->cork.opt);
  1061. np->cork.opt = NULL;
  1062. if (np->cork.rt) {
  1063. dst_release(&np->cork.rt->u.dst);
  1064. np->cork.rt = NULL;
  1065. inet->cork.flags &= ~IPCORK_ALLFRAG;
  1066. }
  1067. memset(&inet->cork.fl, 0, sizeof(inet->cork.fl));
  1068. }