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/errno.h>
  31. #include <linux/types.h>
  32. #include <linux/string.h>
  33. #include <linux/socket.h>
  34. #include <linux/net.h>
  35. #include <linux/netdevice.h>
  36. #include <linux/if_arp.h>
  37. #include <linux/in6.h>
  38. #include <linux/tcp.h>
  39. #include <linux/route.h>
  40. #include <linux/module.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)->gso_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 || skb_shinfo(skb)->gso_size) {
  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. skb_copy_secmark(to, from);
  388. }
  389. int ip6_find_1stfragopt(struct sk_buff *skb, u8 **nexthdr)
  390. {
  391. u16 offset = sizeof(struct ipv6hdr);
  392. struct ipv6_opt_hdr *exthdr = (struct ipv6_opt_hdr*)(skb->nh.ipv6h + 1);
  393. unsigned int packet_len = skb->tail - skb->nh.raw;
  394. int found_rhdr = 0;
  395. *nexthdr = &skb->nh.ipv6h->nexthdr;
  396. while (offset + 1 <= packet_len) {
  397. switch (**nexthdr) {
  398. case NEXTHDR_HOP:
  399. case NEXTHDR_ROUTING:
  400. case NEXTHDR_DEST:
  401. if (**nexthdr == NEXTHDR_ROUTING) found_rhdr = 1;
  402. if (**nexthdr == NEXTHDR_DEST && found_rhdr) return offset;
  403. offset += ipv6_optlen(exthdr);
  404. *nexthdr = &exthdr->nexthdr;
  405. exthdr = (struct ipv6_opt_hdr*)(skb->nh.raw + offset);
  406. break;
  407. default :
  408. return offset;
  409. }
  410. }
  411. return offset;
  412. }
  413. EXPORT_SYMBOL_GPL(ip6_find_1stfragopt);
  414. static int ip6_fragment(struct sk_buff *skb, int (*output)(struct sk_buff *))
  415. {
  416. struct net_device *dev;
  417. struct sk_buff *frag;
  418. struct rt6_info *rt = (struct rt6_info*)skb->dst;
  419. struct ipv6_pinfo *np = skb->sk ? inet6_sk(skb->sk) : NULL;
  420. struct ipv6hdr *tmp_hdr;
  421. struct frag_hdr *fh;
  422. unsigned int mtu, hlen, left, len;
  423. u32 frag_id = 0;
  424. int ptr, offset = 0, err=0;
  425. u8 *prevhdr, nexthdr = 0;
  426. dev = rt->u.dst.dev;
  427. hlen = ip6_find_1stfragopt(skb, &prevhdr);
  428. nexthdr = *prevhdr;
  429. mtu = dst_mtu(&rt->u.dst);
  430. if (np && np->frag_size < mtu) {
  431. if (np->frag_size)
  432. mtu = np->frag_size;
  433. }
  434. mtu -= hlen + sizeof(struct frag_hdr);
  435. if (skb_shinfo(skb)->frag_list) {
  436. int first_len = skb_pagelen(skb);
  437. if (first_len - hlen > mtu ||
  438. ((first_len - hlen) & 7) ||
  439. skb_cloned(skb))
  440. goto slow_path;
  441. for (frag = skb_shinfo(skb)->frag_list; frag; frag = frag->next) {
  442. /* Correct geometry. */
  443. if (frag->len > mtu ||
  444. ((frag->len & 7) && frag->next) ||
  445. skb_headroom(frag) < hlen)
  446. goto slow_path;
  447. /* Partially cloned skb? */
  448. if (skb_shared(frag))
  449. goto slow_path;
  450. BUG_ON(frag->sk);
  451. if (skb->sk) {
  452. sock_hold(skb->sk);
  453. frag->sk = skb->sk;
  454. frag->destructor = sock_wfree;
  455. skb->truesize -= frag->truesize;
  456. }
  457. }
  458. err = 0;
  459. offset = 0;
  460. frag = skb_shinfo(skb)->frag_list;
  461. skb_shinfo(skb)->frag_list = NULL;
  462. /* BUILD HEADER */
  463. tmp_hdr = kmalloc(hlen, GFP_ATOMIC);
  464. if (!tmp_hdr) {
  465. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  466. return -ENOMEM;
  467. }
  468. *prevhdr = NEXTHDR_FRAGMENT;
  469. memcpy(tmp_hdr, skb->nh.raw, hlen);
  470. __skb_pull(skb, hlen);
  471. fh = (struct frag_hdr*)__skb_push(skb, sizeof(struct frag_hdr));
  472. skb->nh.raw = __skb_push(skb, hlen);
  473. memcpy(skb->nh.raw, tmp_hdr, hlen);
  474. ipv6_select_ident(skb, fh);
  475. fh->nexthdr = nexthdr;
  476. fh->reserved = 0;
  477. fh->frag_off = htons(IP6_MF);
  478. frag_id = fh->identification;
  479. first_len = skb_pagelen(skb);
  480. skb->data_len = first_len - skb_headlen(skb);
  481. skb->len = first_len;
  482. skb->nh.ipv6h->payload_len = htons(first_len - sizeof(struct ipv6hdr));
  483. for (;;) {
  484. /* Prepare header of the next frame,
  485. * before previous one went down. */
  486. if (frag) {
  487. frag->ip_summed = CHECKSUM_NONE;
  488. frag->h.raw = frag->data;
  489. fh = (struct frag_hdr*)__skb_push(frag, sizeof(struct frag_hdr));
  490. frag->nh.raw = __skb_push(frag, hlen);
  491. memcpy(frag->nh.raw, tmp_hdr, hlen);
  492. offset += skb->len - hlen - sizeof(struct frag_hdr);
  493. fh->nexthdr = nexthdr;
  494. fh->reserved = 0;
  495. fh->frag_off = htons(offset);
  496. if (frag->next != NULL)
  497. fh->frag_off |= htons(IP6_MF);
  498. fh->identification = frag_id;
  499. frag->nh.ipv6h->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
  500. ip6_copy_metadata(frag, skb);
  501. }
  502. err = output(skb);
  503. if (err || !frag)
  504. break;
  505. skb = frag;
  506. frag = skb->next;
  507. skb->next = NULL;
  508. }
  509. kfree(tmp_hdr);
  510. if (err == 0) {
  511. IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
  512. return 0;
  513. }
  514. while (frag) {
  515. skb = frag->next;
  516. kfree_skb(frag);
  517. frag = skb;
  518. }
  519. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  520. return err;
  521. }
  522. slow_path:
  523. left = skb->len - hlen; /* Space per frame */
  524. ptr = hlen; /* Where to start from */
  525. /*
  526. * Fragment the datagram.
  527. */
  528. *prevhdr = NEXTHDR_FRAGMENT;
  529. /*
  530. * Keep copying data until we run out.
  531. */
  532. while(left > 0) {
  533. len = left;
  534. /* IF: it doesn't fit, use 'mtu' - the data space left */
  535. if (len > mtu)
  536. len = mtu;
  537. /* IF: we are not sending upto and including the packet end
  538. then align the next start on an eight byte boundary */
  539. if (len < left) {
  540. len &= ~7;
  541. }
  542. /*
  543. * Allocate buffer.
  544. */
  545. if ((frag = alloc_skb(len+hlen+sizeof(struct frag_hdr)+LL_RESERVED_SPACE(rt->u.dst.dev), GFP_ATOMIC)) == NULL) {
  546. NETDEBUG(KERN_INFO "IPv6: frag: no memory for new fragment!\n");
  547. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  548. err = -ENOMEM;
  549. goto fail;
  550. }
  551. /*
  552. * Set up data on packet
  553. */
  554. ip6_copy_metadata(frag, skb);
  555. skb_reserve(frag, LL_RESERVED_SPACE(rt->u.dst.dev));
  556. skb_put(frag, len + hlen + sizeof(struct frag_hdr));
  557. frag->nh.raw = frag->data;
  558. fh = (struct frag_hdr*)(frag->data + hlen);
  559. frag->h.raw = frag->data + hlen + sizeof(struct frag_hdr);
  560. /*
  561. * Charge the memory for the fragment to any owner
  562. * it might possess
  563. */
  564. if (skb->sk)
  565. skb_set_owner_w(frag, skb->sk);
  566. /*
  567. * Copy the packet header into the new buffer.
  568. */
  569. memcpy(frag->nh.raw, skb->data, hlen);
  570. /*
  571. * Build fragment header.
  572. */
  573. fh->nexthdr = nexthdr;
  574. fh->reserved = 0;
  575. if (!frag_id) {
  576. ipv6_select_ident(skb, fh);
  577. frag_id = fh->identification;
  578. } else
  579. fh->identification = frag_id;
  580. /*
  581. * Copy a block of the IP datagram.
  582. */
  583. if (skb_copy_bits(skb, ptr, frag->h.raw, len))
  584. BUG();
  585. left -= len;
  586. fh->frag_off = htons(offset);
  587. if (left > 0)
  588. fh->frag_off |= htons(IP6_MF);
  589. frag->nh.ipv6h->payload_len = htons(frag->len - sizeof(struct ipv6hdr));
  590. ptr += len;
  591. offset += len;
  592. /*
  593. * Put this fragment into the sending queue.
  594. */
  595. IP6_INC_STATS(IPSTATS_MIB_FRAGCREATES);
  596. err = output(frag);
  597. if (err)
  598. goto fail;
  599. }
  600. kfree_skb(skb);
  601. IP6_INC_STATS(IPSTATS_MIB_FRAGOKS);
  602. return err;
  603. fail:
  604. kfree_skb(skb);
  605. IP6_INC_STATS(IPSTATS_MIB_FRAGFAILS);
  606. return err;
  607. }
  608. int ip6_dst_lookup(struct sock *sk, struct dst_entry **dst, struct flowi *fl)
  609. {
  610. int err = 0;
  611. *dst = NULL;
  612. if (sk) {
  613. struct ipv6_pinfo *np = inet6_sk(sk);
  614. *dst = sk_dst_check(sk, np->dst_cookie);
  615. if (*dst) {
  616. struct rt6_info *rt = (struct rt6_info*)*dst;
  617. /* Yes, checking route validity in not connected
  618. * case is not very simple. Take into account,
  619. * that we do not support routing by source, TOS,
  620. * and MSG_DONTROUTE --ANK (980726)
  621. *
  622. * 1. If route was host route, check that
  623. * cached destination is current.
  624. * If it is network route, we still may
  625. * check its validity using saved pointer
  626. * to the last used address: daddr_cache.
  627. * We do not want to save whole address now,
  628. * (because main consumer of this service
  629. * is tcp, which has not this problem),
  630. * so that the last trick works only on connected
  631. * sockets.
  632. * 2. oif also should be the same.
  633. */
  634. if (((rt->rt6i_dst.plen != 128 ||
  635. !ipv6_addr_equal(&fl->fl6_dst,
  636. &rt->rt6i_dst.addr))
  637. && (np->daddr_cache == NULL ||
  638. !ipv6_addr_equal(&fl->fl6_dst,
  639. np->daddr_cache)))
  640. || (fl->oif && fl->oif != (*dst)->dev->ifindex)) {
  641. dst_release(*dst);
  642. *dst = NULL;
  643. }
  644. }
  645. }
  646. if (*dst == NULL)
  647. *dst = ip6_route_output(sk, fl);
  648. if ((err = (*dst)->error))
  649. goto out_err_release;
  650. if (ipv6_addr_any(&fl->fl6_src)) {
  651. err = ipv6_get_saddr(*dst, &fl->fl6_dst, &fl->fl6_src);
  652. if (err)
  653. goto out_err_release;
  654. }
  655. return 0;
  656. out_err_release:
  657. dst_release(*dst);
  658. *dst = NULL;
  659. return err;
  660. }
  661. EXPORT_SYMBOL_GPL(ip6_dst_lookup);
  662. static inline int ip6_ufo_append_data(struct sock *sk,
  663. int getfrag(void *from, char *to, int offset, int len,
  664. int odd, struct sk_buff *skb),
  665. void *from, int length, int hh_len, int fragheaderlen,
  666. int transhdrlen, int mtu,unsigned int flags)
  667. {
  668. struct sk_buff *skb;
  669. int err;
  670. /* There is support for UDP large send offload by network
  671. * device, so create one single skb packet containing complete
  672. * udp datagram
  673. */
  674. if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL) {
  675. skb = sock_alloc_send_skb(sk,
  676. hh_len + fragheaderlen + transhdrlen + 20,
  677. (flags & MSG_DONTWAIT), &err);
  678. if (skb == NULL)
  679. return -ENOMEM;
  680. /* reserve space for Hardware header */
  681. skb_reserve(skb, hh_len);
  682. /* create space for UDP/IP header */
  683. skb_put(skb,fragheaderlen + transhdrlen);
  684. /* initialize network header pointer */
  685. skb->nh.raw = skb->data;
  686. /* initialize protocol header pointer */
  687. skb->h.raw = skb->data + fragheaderlen;
  688. skb->ip_summed = CHECKSUM_HW;
  689. skb->csum = 0;
  690. sk->sk_sndmsg_off = 0;
  691. }
  692. err = skb_append_datato_frags(sk,skb, getfrag, from,
  693. (length - transhdrlen));
  694. if (!err) {
  695. struct frag_hdr fhdr;
  696. /* specify the length of each IP datagram fragment*/
  697. skb_shinfo(skb)->gso_size = mtu - fragheaderlen -
  698. sizeof(struct frag_hdr);
  699. skb_shinfo(skb)->gso_type = SKB_GSO_UDP;
  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. }