ip6_output.c 31 KB

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