ip6_output.c 30 KB

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