ip6_output.c 31 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252
  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)->gso_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)->gso_size = mtu - fragheaderlen -
  699. sizeof(struct frag_hdr);
  700. skb_shinfo(skb)->gso_type = SKB_GSO_UDPV4;
  701. ipv6_select_ident(skb, &fhdr);
  702. skb_shinfo(skb)->ip6_frag_id = fhdr.identification;
  703. __skb_queue_tail(&sk->sk_write_queue, skb);
  704. return 0;
  705. }
  706. /* There is not enough support do UPD LSO,
  707. * so follow normal path
  708. */
  709. kfree_skb(skb);
  710. return err;
  711. }
  712. int ip6_append_data(struct sock *sk, int getfrag(void *from, char *to,
  713. int offset, int len, int odd, struct sk_buff *skb),
  714. void *from, int length, int transhdrlen,
  715. int hlimit, int tclass, struct ipv6_txoptions *opt, struct flowi *fl,
  716. struct rt6_info *rt, unsigned int flags)
  717. {
  718. struct inet_sock *inet = inet_sk(sk);
  719. struct ipv6_pinfo *np = inet6_sk(sk);
  720. struct sk_buff *skb;
  721. unsigned int maxfraglen, fragheaderlen;
  722. int exthdrlen;
  723. int hh_len;
  724. int mtu;
  725. int copy;
  726. int err;
  727. int offset = 0;
  728. int csummode = CHECKSUM_NONE;
  729. if (flags&MSG_PROBE)
  730. return 0;
  731. if (skb_queue_empty(&sk->sk_write_queue)) {
  732. /*
  733. * setup for corking
  734. */
  735. if (opt) {
  736. if (np->cork.opt == NULL) {
  737. np->cork.opt = kmalloc(opt->tot_len,
  738. sk->sk_allocation);
  739. if (unlikely(np->cork.opt == NULL))
  740. return -ENOBUFS;
  741. } else if (np->cork.opt->tot_len < opt->tot_len) {
  742. printk(KERN_DEBUG "ip6_append_data: invalid option length\n");
  743. return -EINVAL;
  744. }
  745. memcpy(np->cork.opt, opt, opt->tot_len);
  746. inet->cork.flags |= IPCORK_OPT;
  747. /* need source address above miyazawa*/
  748. }
  749. dst_hold(&rt->u.dst);
  750. np->cork.rt = rt;
  751. inet->cork.fl = *fl;
  752. np->cork.hop_limit = hlimit;
  753. np->cork.tclass = tclass;
  754. mtu = dst_mtu(rt->u.dst.path);
  755. if (np->frag_size < mtu) {
  756. if (np->frag_size)
  757. mtu = np->frag_size;
  758. }
  759. inet->cork.fragsize = mtu;
  760. if (dst_allfrag(rt->u.dst.path))
  761. inet->cork.flags |= IPCORK_ALLFRAG;
  762. inet->cork.length = 0;
  763. sk->sk_sndmsg_page = NULL;
  764. sk->sk_sndmsg_off = 0;
  765. exthdrlen = rt->u.dst.header_len + (opt ? opt->opt_flen : 0);
  766. length += exthdrlen;
  767. transhdrlen += exthdrlen;
  768. } else {
  769. rt = np->cork.rt;
  770. fl = &inet->cork.fl;
  771. if (inet->cork.flags & IPCORK_OPT)
  772. opt = np->cork.opt;
  773. transhdrlen = 0;
  774. exthdrlen = 0;
  775. mtu = inet->cork.fragsize;
  776. }
  777. hh_len = LL_RESERVED_SPACE(rt->u.dst.dev);
  778. fragheaderlen = sizeof(struct ipv6hdr) + (opt ? opt->opt_nflen : 0);
  779. maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen - sizeof(struct frag_hdr);
  780. if (mtu <= sizeof(struct ipv6hdr) + IPV6_MAXPLEN) {
  781. if (inet->cork.length + length > sizeof(struct ipv6hdr) + IPV6_MAXPLEN - fragheaderlen) {
  782. ipv6_local_error(sk, EMSGSIZE, fl, mtu-exthdrlen);
  783. return -EMSGSIZE;
  784. }
  785. }
  786. /*
  787. * Let's try using as much space as possible.
  788. * Use MTU if total length of the message fits into the MTU.
  789. * Otherwise, we need to reserve fragment header and
  790. * fragment alignment (= 8-15 octects, in total).
  791. *
  792. * Note that we may need to "move" the data from the tail of
  793. * of the buffer to the new fragment when we split
  794. * the message.
  795. *
  796. * FIXME: It may be fragmented into multiple chunks
  797. * at once if non-fragmentable extension headers
  798. * are too large.
  799. * --yoshfuji
  800. */
  801. inet->cork.length += length;
  802. if (((length > mtu) && (sk->sk_protocol == IPPROTO_UDP)) &&
  803. (rt->u.dst.dev->features & NETIF_F_UFO)) {
  804. err = ip6_ufo_append_data(sk, getfrag, from, length, hh_len,
  805. fragheaderlen, transhdrlen, mtu,
  806. flags);
  807. if (err)
  808. goto error;
  809. return 0;
  810. }
  811. if ((skb = skb_peek_tail(&sk->sk_write_queue)) == NULL)
  812. goto alloc_new_skb;
  813. while (length > 0) {
  814. /* Check if the remaining data fits into current packet. */
  815. copy = (inet->cork.length <= mtu && !(inet->cork.flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - skb->len;
  816. if (copy < length)
  817. copy = maxfraglen - skb->len;
  818. if (copy <= 0) {
  819. char *data;
  820. unsigned int datalen;
  821. unsigned int fraglen;
  822. unsigned int fraggap;
  823. unsigned int alloclen;
  824. struct sk_buff *skb_prev;
  825. alloc_new_skb:
  826. skb_prev = skb;
  827. /* There's no room in the current skb */
  828. if (skb_prev)
  829. fraggap = skb_prev->len - maxfraglen;
  830. else
  831. fraggap = 0;
  832. /*
  833. * If remaining data exceeds the mtu,
  834. * we know we need more fragment(s).
  835. */
  836. datalen = length + fraggap;
  837. if (datalen > (inet->cork.length <= mtu && !(inet->cork.flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
  838. datalen = maxfraglen - fragheaderlen;
  839. fraglen = datalen + fragheaderlen;
  840. if ((flags & MSG_MORE) &&
  841. !(rt->u.dst.dev->features&NETIF_F_SG))
  842. alloclen = mtu;
  843. else
  844. alloclen = datalen + fragheaderlen;
  845. /*
  846. * The last fragment gets additional space at tail.
  847. * Note: we overallocate on fragments with MSG_MODE
  848. * because we have no idea if we're the last one.
  849. */
  850. if (datalen == length + fraggap)
  851. alloclen += rt->u.dst.trailer_len;
  852. /*
  853. * We just reserve space for fragment header.
  854. * Note: this may be overallocation if the message
  855. * (without MSG_MORE) fits into the MTU.
  856. */
  857. alloclen += sizeof(struct frag_hdr);
  858. if (transhdrlen) {
  859. skb = sock_alloc_send_skb(sk,
  860. alloclen + hh_len,
  861. (flags & MSG_DONTWAIT), &err);
  862. } else {
  863. skb = NULL;
  864. if (atomic_read(&sk->sk_wmem_alloc) <=
  865. 2 * sk->sk_sndbuf)
  866. skb = sock_wmalloc(sk,
  867. alloclen + hh_len, 1,
  868. sk->sk_allocation);
  869. if (unlikely(skb == NULL))
  870. err = -ENOBUFS;
  871. }
  872. if (skb == NULL)
  873. goto error;
  874. /*
  875. * Fill in the control structures
  876. */
  877. skb->ip_summed = csummode;
  878. skb->csum = 0;
  879. /* reserve for fragmentation */
  880. skb_reserve(skb, hh_len+sizeof(struct frag_hdr));
  881. /*
  882. * Find where to start putting bytes
  883. */
  884. data = skb_put(skb, fraglen);
  885. skb->nh.raw = data + exthdrlen;
  886. data += fragheaderlen;
  887. skb->h.raw = data + exthdrlen;
  888. if (fraggap) {
  889. skb->csum = skb_copy_and_csum_bits(
  890. skb_prev, maxfraglen,
  891. data + transhdrlen, fraggap, 0);
  892. skb_prev->csum = csum_sub(skb_prev->csum,
  893. skb->csum);
  894. data += fraggap;
  895. skb_trim(skb_prev, maxfraglen);
  896. }
  897. copy = datalen - transhdrlen - fraggap;
  898. if (copy < 0) {
  899. err = -EINVAL;
  900. kfree_skb(skb);
  901. goto error;
  902. } else if (copy > 0 && getfrag(from, data + transhdrlen, offset, copy, fraggap, skb) < 0) {
  903. err = -EFAULT;
  904. kfree_skb(skb);
  905. goto error;
  906. }
  907. offset += copy;
  908. length -= datalen - fraggap;
  909. transhdrlen = 0;
  910. exthdrlen = 0;
  911. csummode = CHECKSUM_NONE;
  912. /*
  913. * Put the packet on the pending queue
  914. */
  915. __skb_queue_tail(&sk->sk_write_queue, skb);
  916. continue;
  917. }
  918. if (copy > length)
  919. copy = length;
  920. if (!(rt->u.dst.dev->features&NETIF_F_SG)) {
  921. unsigned int off;
  922. off = skb->len;
  923. if (getfrag(from, skb_put(skb, copy),
  924. offset, copy, off, skb) < 0) {
  925. __skb_trim(skb, off);
  926. err = -EFAULT;
  927. goto error;
  928. }
  929. } else {
  930. int i = skb_shinfo(skb)->nr_frags;
  931. skb_frag_t *frag = &skb_shinfo(skb)->frags[i-1];
  932. struct page *page = sk->sk_sndmsg_page;
  933. int off = sk->sk_sndmsg_off;
  934. unsigned int left;
  935. if (page && (left = PAGE_SIZE - off) > 0) {
  936. if (copy >= left)
  937. copy = left;
  938. if (page != frag->page) {
  939. if (i == MAX_SKB_FRAGS) {
  940. err = -EMSGSIZE;
  941. goto error;
  942. }
  943. get_page(page);
  944. skb_fill_page_desc(skb, i, page, sk->sk_sndmsg_off, 0);
  945. frag = &skb_shinfo(skb)->frags[i];
  946. }
  947. } else if(i < MAX_SKB_FRAGS) {
  948. if (copy > PAGE_SIZE)
  949. copy = PAGE_SIZE;
  950. page = alloc_pages(sk->sk_allocation, 0);
  951. if (page == NULL) {
  952. err = -ENOMEM;
  953. goto error;
  954. }
  955. sk->sk_sndmsg_page = page;
  956. sk->sk_sndmsg_off = 0;
  957. skb_fill_page_desc(skb, i, page, 0, 0);
  958. frag = &skb_shinfo(skb)->frags[i];
  959. skb->truesize += PAGE_SIZE;
  960. atomic_add(PAGE_SIZE, &sk->sk_wmem_alloc);
  961. } else {
  962. err = -EMSGSIZE;
  963. goto error;
  964. }
  965. if (getfrag(from, page_address(frag->page)+frag->page_offset+frag->size, offset, copy, skb->len, skb) < 0) {
  966. err = -EFAULT;
  967. goto error;
  968. }
  969. sk->sk_sndmsg_off += copy;
  970. frag->size += copy;
  971. skb->len += copy;
  972. skb->data_len += copy;
  973. }
  974. offset += copy;
  975. length -= copy;
  976. }
  977. return 0;
  978. error:
  979. inet->cork.length -= length;
  980. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  981. return err;
  982. }
  983. int ip6_push_pending_frames(struct sock *sk)
  984. {
  985. struct sk_buff *skb, *tmp_skb;
  986. struct sk_buff **tail_skb;
  987. struct in6_addr final_dst_buf, *final_dst = &final_dst_buf;
  988. struct inet_sock *inet = inet_sk(sk);
  989. struct ipv6_pinfo *np = inet6_sk(sk);
  990. struct ipv6hdr *hdr;
  991. struct ipv6_txoptions *opt = np->cork.opt;
  992. struct rt6_info *rt = np->cork.rt;
  993. struct flowi *fl = &inet->cork.fl;
  994. unsigned char proto = fl->proto;
  995. int err = 0;
  996. if ((skb = __skb_dequeue(&sk->sk_write_queue)) == NULL)
  997. goto out;
  998. tail_skb = &(skb_shinfo(skb)->frag_list);
  999. /* move skb->data to ip header from ext header */
  1000. if (skb->data < skb->nh.raw)
  1001. __skb_pull(skb, skb->nh.raw - skb->data);
  1002. while ((tmp_skb = __skb_dequeue(&sk->sk_write_queue)) != NULL) {
  1003. __skb_pull(tmp_skb, skb->h.raw - skb->nh.raw);
  1004. *tail_skb = tmp_skb;
  1005. tail_skb = &(tmp_skb->next);
  1006. skb->len += tmp_skb->len;
  1007. skb->data_len += tmp_skb->len;
  1008. skb->truesize += tmp_skb->truesize;
  1009. __sock_put(tmp_skb->sk);
  1010. tmp_skb->destructor = NULL;
  1011. tmp_skb->sk = NULL;
  1012. }
  1013. ipv6_addr_copy(final_dst, &fl->fl6_dst);
  1014. __skb_pull(skb, skb->h.raw - skb->nh.raw);
  1015. if (opt && opt->opt_flen)
  1016. ipv6_push_frag_opts(skb, opt, &proto);
  1017. if (opt && opt->opt_nflen)
  1018. ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst);
  1019. skb->nh.ipv6h = hdr = (struct ipv6hdr*) skb_push(skb, sizeof(struct ipv6hdr));
  1020. *(u32*)hdr = fl->fl6_flowlabel |
  1021. htonl(0x60000000 | ((int)np->cork.tclass << 20));
  1022. if (skb->len <= sizeof(struct ipv6hdr) + IPV6_MAXPLEN)
  1023. hdr->payload_len = htons(skb->len - sizeof(struct ipv6hdr));
  1024. else
  1025. hdr->payload_len = 0;
  1026. hdr->hop_limit = np->cork.hop_limit;
  1027. hdr->nexthdr = proto;
  1028. ipv6_addr_copy(&hdr->saddr, &fl->fl6_src);
  1029. ipv6_addr_copy(&hdr->daddr, final_dst);
  1030. skb->priority = sk->sk_priority;
  1031. skb->dst = dst_clone(&rt->u.dst);
  1032. IP6_INC_STATS(IPSTATS_MIB_OUTREQUESTS);
  1033. err = NF_HOOK(PF_INET6, NF_IP6_LOCAL_OUT, skb, NULL, skb->dst->dev, dst_output);
  1034. if (err) {
  1035. if (err > 0)
  1036. err = np->recverr ? net_xmit_errno(err) : 0;
  1037. if (err)
  1038. goto error;
  1039. }
  1040. out:
  1041. inet->cork.flags &= ~IPCORK_OPT;
  1042. kfree(np->cork.opt);
  1043. np->cork.opt = NULL;
  1044. if (np->cork.rt) {
  1045. dst_release(&np->cork.rt->u.dst);
  1046. np->cork.rt = NULL;
  1047. inet->cork.flags &= ~IPCORK_ALLFRAG;
  1048. }
  1049. memset(&inet->cork.fl, 0, sizeof(inet->cork.fl));
  1050. return err;
  1051. error:
  1052. goto out;
  1053. }
  1054. void ip6_flush_pending_frames(struct sock *sk)
  1055. {
  1056. struct inet_sock *inet = inet_sk(sk);
  1057. struct ipv6_pinfo *np = inet6_sk(sk);
  1058. struct sk_buff *skb;
  1059. while ((skb = __skb_dequeue_tail(&sk->sk_write_queue)) != NULL) {
  1060. IP6_INC_STATS(IPSTATS_MIB_OUTDISCARDS);
  1061. kfree_skb(skb);
  1062. }
  1063. inet->cork.flags &= ~IPCORK_OPT;
  1064. kfree(np->cork.opt);
  1065. np->cork.opt = NULL;
  1066. if (np->cork.rt) {
  1067. dst_release(&np->cork.rt->u.dst);
  1068. np->cork.rt = NULL;
  1069. inet->cork.flags &= ~IPCORK_ALLFRAG;
  1070. }
  1071. memset(&inet->cork.fl, 0, sizeof(inet->cork.fl));
  1072. }