ip6_output.c 45 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789
  1. /*
  2. * IPv6 output functions
  3. * Linux INET6 implementation
  4. *
  5. * Authors:
  6. * Pedro Roque <roque@di.fc.ul.pt>
  7. *
  8. * Based on linux/net/ipv4/ip_output.c
  9. *
  10. * This program is free software; you can redistribute it and/or
  11. * modify it under the terms of the GNU General Public License
  12. * as published by the Free Software Foundation; either version
  13. * 2 of the License, or (at your option) any later version.
  14. *
  15. * Changes:
  16. * A.N.Kuznetsov : airthmetics in fragmentation.
  17. * extension headers are implemented.
  18. * route changes now work.
  19. * ip6_forward does not confuse sniffers.
  20. * etc.
  21. *
  22. * H. von Brand : Added missing #include <linux/string.h>
  23. * Imran Patel : frag id should be in NBO
  24. * Kazunori MIYAZAWA @USAGI
  25. * : add ip6_append_data and related functions
  26. * for datagram xmit
  27. */
  28. #include <linux/errno.h>
  29. #include <linux/kernel.h>
  30. #include <linux/string.h>
  31. #include <linux/socket.h>
  32. #include <linux/net.h>
  33. #include <linux/netdevice.h>
  34. #include <linux/if_arp.h>
  35. #include <linux/in6.h>
  36. #include <linux/tcp.h>
  37. #include <linux/route.h>
  38. #include <linux/module.h>
  39. #include <linux/slab.h>
  40. #include <linux/bpf-cgroup.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. #include <linux/mroute6.h>
  55. #include <net/l3mdev.h>
  56. #include <net/lwtunnel.h>
  57. static int ip6_finish_output2(struct net *net, struct sock *sk, struct sk_buff *skb)
  58. {
  59. struct dst_entry *dst = skb_dst(skb);
  60. struct net_device *dev = dst->dev;
  61. struct neighbour *neigh;
  62. struct in6_addr *nexthop;
  63. int ret;
  64. if (ipv6_addr_is_multicast(&ipv6_hdr(skb)->daddr)) {
  65. struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
  66. if (!(dev->flags & IFF_LOOPBACK) && sk_mc_loop(sk) &&
  67. ((mroute6_is_socket(net, skb) &&
  68. !(IP6CB(skb)->flags & IP6SKB_FORWARDED)) ||
  69. ipv6_chk_mcast_addr(dev, &ipv6_hdr(skb)->daddr,
  70. &ipv6_hdr(skb)->saddr))) {
  71. struct sk_buff *newskb = skb_clone(skb, GFP_ATOMIC);
  72. /* Do not check for IFF_ALLMULTI; multicast routing
  73. is not supported in any case.
  74. */
  75. if (newskb)
  76. NF_HOOK(NFPROTO_IPV6, NF_INET_POST_ROUTING,
  77. net, sk, newskb, NULL, newskb->dev,
  78. dev_loopback_xmit);
  79. if (ipv6_hdr(skb)->hop_limit == 0) {
  80. IP6_INC_STATS(net, idev,
  81. IPSTATS_MIB_OUTDISCARDS);
  82. kfree_skb(skb);
  83. return 0;
  84. }
  85. }
  86. IP6_UPD_PO_STATS(net, idev, IPSTATS_MIB_OUTMCAST, skb->len);
  87. if (IPV6_ADDR_MC_SCOPE(&ipv6_hdr(skb)->daddr) <=
  88. IPV6_ADDR_SCOPE_NODELOCAL &&
  89. !(dev->flags & IFF_LOOPBACK)) {
  90. kfree_skb(skb);
  91. return 0;
  92. }
  93. }
  94. if (lwtunnel_xmit_redirect(dst->lwtstate)) {
  95. int res = lwtunnel_xmit(skb);
  96. if (res < 0 || res == LWTUNNEL_XMIT_DONE)
  97. return res;
  98. }
  99. rcu_read_lock_bh();
  100. nexthop = rt6_nexthop((struct rt6_info *)dst, &ipv6_hdr(skb)->daddr);
  101. neigh = __ipv6_neigh_lookup_noref(dst->dev, nexthop);
  102. if (unlikely(!neigh))
  103. neigh = __neigh_create(&nd_tbl, nexthop, dst->dev, false);
  104. if (!IS_ERR(neigh)) {
  105. sock_confirm_neigh(skb, neigh);
  106. ret = neigh_output(neigh, skb);
  107. rcu_read_unlock_bh();
  108. return ret;
  109. }
  110. rcu_read_unlock_bh();
  111. IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTNOROUTES);
  112. kfree_skb(skb);
  113. return -EINVAL;
  114. }
  115. static int ip6_finish_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  116. {
  117. int ret;
  118. ret = BPF_CGROUP_RUN_PROG_INET_EGRESS(sk, skb);
  119. if (ret) {
  120. kfree_skb(skb);
  121. return ret;
  122. }
  123. #if defined(CONFIG_NETFILTER) && defined(CONFIG_XFRM)
  124. /* Policy lookup after SNAT yielded a new policy */
  125. if (skb_dst(skb)->xfrm) {
  126. IPCB(skb)->flags |= IPSKB_REROUTED;
  127. return dst_output(net, sk, skb);
  128. }
  129. #endif
  130. if ((skb->len > ip6_skb_dst_mtu(skb) && !skb_is_gso(skb)) ||
  131. dst_allfrag(skb_dst(skb)) ||
  132. (IP6CB(skb)->frag_max_size && skb->len > IP6CB(skb)->frag_max_size))
  133. return ip6_fragment(net, sk, skb, ip6_finish_output2);
  134. else
  135. return ip6_finish_output2(net, sk, skb);
  136. }
  137. int ip6_output(struct net *net, struct sock *sk, struct sk_buff *skb)
  138. {
  139. struct net_device *dev = skb_dst(skb)->dev;
  140. struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
  141. skb->protocol = htons(ETH_P_IPV6);
  142. skb->dev = dev;
  143. if (unlikely(idev->cnf.disable_ipv6)) {
  144. IP6_INC_STATS(net, idev, IPSTATS_MIB_OUTDISCARDS);
  145. kfree_skb(skb);
  146. return 0;
  147. }
  148. return NF_HOOK_COND(NFPROTO_IPV6, NF_INET_POST_ROUTING,
  149. net, sk, skb, NULL, dev,
  150. ip6_finish_output,
  151. !(IP6CB(skb)->flags & IP6SKB_REROUTED));
  152. }
  153. bool ip6_autoflowlabel(struct net *net, const struct ipv6_pinfo *np)
  154. {
  155. if (!np->autoflowlabel_set)
  156. return ip6_default_np_autolabel(net);
  157. else
  158. return np->autoflowlabel;
  159. }
  160. /*
  161. * xmit an sk_buff (used by TCP, SCTP and DCCP)
  162. * Note : socket lock is not held for SYNACK packets, but might be modified
  163. * by calls to skb_set_owner_w() and ipv6_local_error(),
  164. * which are using proper atomic operations or spinlocks.
  165. */
  166. int ip6_xmit(const struct sock *sk, struct sk_buff *skb, struct flowi6 *fl6,
  167. __u32 mark, struct ipv6_txoptions *opt, int tclass)
  168. {
  169. struct net *net = sock_net(sk);
  170. const struct ipv6_pinfo *np = inet6_sk(sk);
  171. struct in6_addr *first_hop = &fl6->daddr;
  172. struct dst_entry *dst = skb_dst(skb);
  173. unsigned int head_room;
  174. struct ipv6hdr *hdr;
  175. u8 proto = fl6->flowi6_proto;
  176. int seg_len = skb->len;
  177. int hlimit = -1;
  178. u32 mtu;
  179. head_room = sizeof(struct ipv6hdr) + LL_RESERVED_SPACE(dst->dev);
  180. if (opt)
  181. head_room += opt->opt_nflen + opt->opt_flen;
  182. if (unlikely(skb_headroom(skb) < head_room)) {
  183. struct sk_buff *skb2 = skb_realloc_headroom(skb, head_room);
  184. if (!skb2) {
  185. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
  186. IPSTATS_MIB_OUTDISCARDS);
  187. kfree_skb(skb);
  188. return -ENOBUFS;
  189. }
  190. if (skb->sk)
  191. skb_set_owner_w(skb2, skb->sk);
  192. consume_skb(skb);
  193. skb = skb2;
  194. }
  195. if (opt) {
  196. seg_len += opt->opt_nflen + opt->opt_flen;
  197. if (opt->opt_flen)
  198. ipv6_push_frag_opts(skb, opt, &proto);
  199. if (opt->opt_nflen)
  200. ipv6_push_nfrag_opts(skb, opt, &proto, &first_hop,
  201. &fl6->saddr);
  202. }
  203. skb_push(skb, sizeof(struct ipv6hdr));
  204. skb_reset_network_header(skb);
  205. hdr = ipv6_hdr(skb);
  206. /*
  207. * Fill in the IPv6 header
  208. */
  209. if (np)
  210. hlimit = np->hop_limit;
  211. if (hlimit < 0)
  212. hlimit = ip6_dst_hoplimit(dst);
  213. ip6_flow_hdr(hdr, tclass, ip6_make_flowlabel(net, skb, fl6->flowlabel,
  214. ip6_autoflowlabel(net, np), fl6));
  215. hdr->payload_len = htons(seg_len);
  216. hdr->nexthdr = proto;
  217. hdr->hop_limit = hlimit;
  218. hdr->saddr = fl6->saddr;
  219. hdr->daddr = *first_hop;
  220. skb->protocol = htons(ETH_P_IPV6);
  221. skb->priority = sk->sk_priority;
  222. skb->mark = mark;
  223. mtu = dst_mtu(dst);
  224. if ((skb->len <= mtu) || skb->ignore_df || skb_is_gso(skb)) {
  225. IP6_UPD_PO_STATS(net, ip6_dst_idev(skb_dst(skb)),
  226. IPSTATS_MIB_OUT, skb->len);
  227. /* if egress device is enslaved to an L3 master device pass the
  228. * skb to its handler for processing
  229. */
  230. skb = l3mdev_ip6_out((struct sock *)sk, skb);
  231. if (unlikely(!skb))
  232. return 0;
  233. /* hooks should never assume socket lock is held.
  234. * we promote our socket to non const
  235. */
  236. return NF_HOOK(NFPROTO_IPV6, NF_INET_LOCAL_OUT,
  237. net, (struct sock *)sk, skb, NULL, dst->dev,
  238. dst_output);
  239. }
  240. skb->dev = dst->dev;
  241. /* ipv6_local_error() does not require socket lock,
  242. * we promote our socket to non const
  243. */
  244. ipv6_local_error((struct sock *)sk, EMSGSIZE, fl6, mtu);
  245. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)), IPSTATS_MIB_FRAGFAILS);
  246. kfree_skb(skb);
  247. return -EMSGSIZE;
  248. }
  249. EXPORT_SYMBOL(ip6_xmit);
  250. static int ip6_call_ra_chain(struct sk_buff *skb, int sel)
  251. {
  252. struct ip6_ra_chain *ra;
  253. struct sock *last = NULL;
  254. read_lock(&ip6_ra_lock);
  255. for (ra = ip6_ra_chain; ra; ra = ra->next) {
  256. struct sock *sk = ra->sk;
  257. if (sk && ra->sel == sel &&
  258. (!sk->sk_bound_dev_if ||
  259. sk->sk_bound_dev_if == skb->dev->ifindex)) {
  260. if (last) {
  261. struct sk_buff *skb2 = skb_clone(skb, GFP_ATOMIC);
  262. if (skb2)
  263. rawv6_rcv(last, skb2);
  264. }
  265. last = sk;
  266. }
  267. }
  268. if (last) {
  269. rawv6_rcv(last, skb);
  270. read_unlock(&ip6_ra_lock);
  271. return 1;
  272. }
  273. read_unlock(&ip6_ra_lock);
  274. return 0;
  275. }
  276. static int ip6_forward_proxy_check(struct sk_buff *skb)
  277. {
  278. struct ipv6hdr *hdr = ipv6_hdr(skb);
  279. u8 nexthdr = hdr->nexthdr;
  280. __be16 frag_off;
  281. int offset;
  282. if (ipv6_ext_hdr(nexthdr)) {
  283. offset = ipv6_skip_exthdr(skb, sizeof(*hdr), &nexthdr, &frag_off);
  284. if (offset < 0)
  285. return 0;
  286. } else
  287. offset = sizeof(struct ipv6hdr);
  288. if (nexthdr == IPPROTO_ICMPV6) {
  289. struct icmp6hdr *icmp6;
  290. if (!pskb_may_pull(skb, (skb_network_header(skb) +
  291. offset + 1 - skb->data)))
  292. return 0;
  293. icmp6 = (struct icmp6hdr *)(skb_network_header(skb) + offset);
  294. switch (icmp6->icmp6_type) {
  295. case NDISC_ROUTER_SOLICITATION:
  296. case NDISC_ROUTER_ADVERTISEMENT:
  297. case NDISC_NEIGHBOUR_SOLICITATION:
  298. case NDISC_NEIGHBOUR_ADVERTISEMENT:
  299. case NDISC_REDIRECT:
  300. /* For reaction involving unicast neighbor discovery
  301. * message destined to the proxied address, pass it to
  302. * input function.
  303. */
  304. return 1;
  305. default:
  306. break;
  307. }
  308. }
  309. /*
  310. * The proxying router can't forward traffic sent to a link-local
  311. * address, so signal the sender and discard the packet. This
  312. * behavior is clarified by the MIPv6 specification.
  313. */
  314. if (ipv6_addr_type(&hdr->daddr) & IPV6_ADDR_LINKLOCAL) {
  315. dst_link_failure(skb);
  316. return -1;
  317. }
  318. return 0;
  319. }
  320. static inline int ip6_forward_finish(struct net *net, struct sock *sk,
  321. struct sk_buff *skb)
  322. {
  323. struct dst_entry *dst = skb_dst(skb);
  324. __IP6_INC_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTFORWDATAGRAMS);
  325. __IP6_ADD_STATS(net, ip6_dst_idev(dst), IPSTATS_MIB_OUTOCTETS, skb->len);
  326. skb->tstamp = 0;
  327. return dst_output(net, sk, skb);
  328. }
  329. static bool ip6_pkt_too_big(const struct sk_buff *skb, unsigned int mtu)
  330. {
  331. if (skb->len <= mtu)
  332. return false;
  333. /* ipv6 conntrack defrag sets max_frag_size + ignore_df */
  334. if (IP6CB(skb)->frag_max_size && IP6CB(skb)->frag_max_size > mtu)
  335. return true;
  336. if (skb->ignore_df)
  337. return false;
  338. if (skb_is_gso(skb) && skb_gso_validate_network_len(skb, mtu))
  339. return false;
  340. return true;
  341. }
  342. int ip6_forward(struct sk_buff *skb)
  343. {
  344. struct inet6_dev *idev = __in6_dev_get_safely(skb->dev);
  345. struct dst_entry *dst = skb_dst(skb);
  346. struct ipv6hdr *hdr = ipv6_hdr(skb);
  347. struct inet6_skb_parm *opt = IP6CB(skb);
  348. struct net *net = dev_net(dst->dev);
  349. u32 mtu;
  350. if (net->ipv6.devconf_all->forwarding == 0)
  351. goto error;
  352. if (skb->pkt_type != PACKET_HOST)
  353. goto drop;
  354. if (unlikely(skb->sk))
  355. goto drop;
  356. if (skb_warn_if_lro(skb))
  357. goto drop;
  358. if (!xfrm6_policy_check(NULL, XFRM_POLICY_FWD, skb)) {
  359. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
  360. goto drop;
  361. }
  362. skb_forward_csum(skb);
  363. /*
  364. * We DO NOT make any processing on
  365. * RA packets, pushing them to user level AS IS
  366. * without ane WARRANTY that application will be able
  367. * to interpret them. The reason is that we
  368. * cannot make anything clever here.
  369. *
  370. * We are not end-node, so that if packet contains
  371. * AH/ESP, we cannot make anything.
  372. * Defragmentation also would be mistake, RA packets
  373. * cannot be fragmented, because there is no warranty
  374. * that different fragments will go along one path. --ANK
  375. */
  376. if (unlikely(opt->flags & IP6SKB_ROUTERALERT)) {
  377. if (ip6_call_ra_chain(skb, ntohs(opt->ra)))
  378. return 0;
  379. }
  380. /*
  381. * check and decrement ttl
  382. */
  383. if (hdr->hop_limit <= 1) {
  384. /* Force OUTPUT device used as source address */
  385. skb->dev = dst->dev;
  386. icmpv6_send(skb, ICMPV6_TIME_EXCEED, ICMPV6_EXC_HOPLIMIT, 0);
  387. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INHDRERRORS);
  388. kfree_skb(skb);
  389. return -ETIMEDOUT;
  390. }
  391. /* XXX: idev->cnf.proxy_ndp? */
  392. if (net->ipv6.devconf_all->proxy_ndp &&
  393. pneigh_lookup(&nd_tbl, net, &hdr->daddr, skb->dev, 0)) {
  394. int proxied = ip6_forward_proxy_check(skb);
  395. if (proxied > 0)
  396. return ip6_input(skb);
  397. else if (proxied < 0) {
  398. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
  399. goto drop;
  400. }
  401. }
  402. if (!xfrm6_route_forward(skb)) {
  403. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INDISCARDS);
  404. goto drop;
  405. }
  406. dst = skb_dst(skb);
  407. /* IPv6 specs say nothing about it, but it is clear that we cannot
  408. send redirects to source routed frames.
  409. We don't send redirects to frames decapsulated from IPsec.
  410. */
  411. if (IP6CB(skb)->iif == dst->dev->ifindex &&
  412. opt->srcrt == 0 && !skb_sec_path(skb)) {
  413. struct in6_addr *target = NULL;
  414. struct inet_peer *peer;
  415. struct rt6_info *rt;
  416. /*
  417. * incoming and outgoing devices are the same
  418. * send a redirect.
  419. */
  420. rt = (struct rt6_info *) dst;
  421. if (rt->rt6i_flags & RTF_GATEWAY)
  422. target = &rt->rt6i_gateway;
  423. else
  424. target = &hdr->daddr;
  425. peer = inet_getpeer_v6(net->ipv6.peers, &hdr->daddr, 1);
  426. /* Limit redirects both by destination (here)
  427. and by source (inside ndisc_send_redirect)
  428. */
  429. if (inet_peer_xrlim_allow(peer, 1*HZ))
  430. ndisc_send_redirect(skb, target);
  431. if (peer)
  432. inet_putpeer(peer);
  433. } else {
  434. int addrtype = ipv6_addr_type(&hdr->saddr);
  435. /* This check is security critical. */
  436. if (addrtype == IPV6_ADDR_ANY ||
  437. addrtype & (IPV6_ADDR_MULTICAST | IPV6_ADDR_LOOPBACK))
  438. goto error;
  439. if (addrtype & IPV6_ADDR_LINKLOCAL) {
  440. icmpv6_send(skb, ICMPV6_DEST_UNREACH,
  441. ICMPV6_NOT_NEIGHBOUR, 0);
  442. goto error;
  443. }
  444. }
  445. mtu = ip6_dst_mtu_forward(dst);
  446. if (mtu < IPV6_MIN_MTU)
  447. mtu = IPV6_MIN_MTU;
  448. if (ip6_pkt_too_big(skb, mtu)) {
  449. /* Again, force OUTPUT device used as source address */
  450. skb->dev = dst->dev;
  451. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
  452. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INTOOBIGERRORS);
  453. __IP6_INC_STATS(net, ip6_dst_idev(dst),
  454. IPSTATS_MIB_FRAGFAILS);
  455. kfree_skb(skb);
  456. return -EMSGSIZE;
  457. }
  458. if (skb_cow(skb, dst->dev->hard_header_len)) {
  459. __IP6_INC_STATS(net, ip6_dst_idev(dst),
  460. IPSTATS_MIB_OUTDISCARDS);
  461. goto drop;
  462. }
  463. hdr = ipv6_hdr(skb);
  464. /* Mangling hops number delayed to point after skb COW */
  465. hdr->hop_limit--;
  466. return NF_HOOK(NFPROTO_IPV6, NF_INET_FORWARD,
  467. net, NULL, skb, skb->dev, dst->dev,
  468. ip6_forward_finish);
  469. error:
  470. __IP6_INC_STATS(net, idev, IPSTATS_MIB_INADDRERRORS);
  471. drop:
  472. kfree_skb(skb);
  473. return -EINVAL;
  474. }
  475. static void ip6_copy_metadata(struct sk_buff *to, struct sk_buff *from)
  476. {
  477. to->pkt_type = from->pkt_type;
  478. to->priority = from->priority;
  479. to->protocol = from->protocol;
  480. skb_dst_drop(to);
  481. skb_dst_set(to, dst_clone(skb_dst(from)));
  482. to->dev = from->dev;
  483. to->mark = from->mark;
  484. skb_copy_hash(to, from);
  485. #ifdef CONFIG_NET_SCHED
  486. to->tc_index = from->tc_index;
  487. #endif
  488. nf_copy(to, from);
  489. skb_copy_secmark(to, from);
  490. }
  491. int ip6_fragment(struct net *net, struct sock *sk, struct sk_buff *skb,
  492. int (*output)(struct net *, struct sock *, struct sk_buff *))
  493. {
  494. struct sk_buff *frag;
  495. struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
  496. struct ipv6_pinfo *np = skb->sk && !dev_recursion_level() ?
  497. inet6_sk(skb->sk) : NULL;
  498. struct ipv6hdr *tmp_hdr;
  499. struct frag_hdr *fh;
  500. unsigned int mtu, hlen, left, len, nexthdr_offset;
  501. int hroom, troom;
  502. __be32 frag_id;
  503. int ptr, offset = 0, err = 0;
  504. u8 *prevhdr, nexthdr = 0;
  505. err = ip6_find_1stfragopt(skb, &prevhdr);
  506. if (err < 0)
  507. goto fail;
  508. hlen = err;
  509. nexthdr = *prevhdr;
  510. nexthdr_offset = prevhdr - skb_network_header(skb);
  511. mtu = ip6_skb_dst_mtu(skb);
  512. /* We must not fragment if the socket is set to force MTU discovery
  513. * or if the skb it not generated by a local socket.
  514. */
  515. if (unlikely(!skb->ignore_df && skb->len > mtu))
  516. goto fail_toobig;
  517. if (IP6CB(skb)->frag_max_size) {
  518. if (IP6CB(skb)->frag_max_size > mtu)
  519. goto fail_toobig;
  520. /* don't send fragments larger than what we received */
  521. mtu = IP6CB(skb)->frag_max_size;
  522. if (mtu < IPV6_MIN_MTU)
  523. mtu = IPV6_MIN_MTU;
  524. }
  525. if (np && np->frag_size < mtu) {
  526. if (np->frag_size)
  527. mtu = np->frag_size;
  528. }
  529. if (mtu < hlen + sizeof(struct frag_hdr) + 8)
  530. goto fail_toobig;
  531. mtu -= hlen + sizeof(struct frag_hdr);
  532. frag_id = ipv6_select_ident(net, &ipv6_hdr(skb)->daddr,
  533. &ipv6_hdr(skb)->saddr);
  534. if (skb->ip_summed == CHECKSUM_PARTIAL &&
  535. (err = skb_checksum_help(skb)))
  536. goto fail;
  537. prevhdr = skb_network_header(skb) + nexthdr_offset;
  538. hroom = LL_RESERVED_SPACE(rt->dst.dev);
  539. if (skb_has_frag_list(skb)) {
  540. unsigned int first_len = skb_pagelen(skb);
  541. struct sk_buff *frag2;
  542. if (first_len - hlen > mtu ||
  543. ((first_len - hlen) & 7) ||
  544. skb_cloned(skb) ||
  545. skb_headroom(skb) < (hroom + sizeof(struct frag_hdr)))
  546. goto slow_path;
  547. skb_walk_frags(skb, frag) {
  548. /* Correct geometry. */
  549. if (frag->len > mtu ||
  550. ((frag->len & 7) && frag->next) ||
  551. skb_headroom(frag) < (hlen + hroom + sizeof(struct frag_hdr)))
  552. goto slow_path_clean;
  553. /* Partially cloned skb? */
  554. if (skb_shared(frag))
  555. goto slow_path_clean;
  556. BUG_ON(frag->sk);
  557. if (skb->sk) {
  558. frag->sk = skb->sk;
  559. frag->destructor = sock_wfree;
  560. }
  561. skb->truesize -= frag->truesize;
  562. }
  563. err = 0;
  564. offset = 0;
  565. /* BUILD HEADER */
  566. *prevhdr = NEXTHDR_FRAGMENT;
  567. tmp_hdr = kmemdup(skb_network_header(skb), hlen, GFP_ATOMIC);
  568. if (!tmp_hdr) {
  569. err = -ENOMEM;
  570. goto fail;
  571. }
  572. frag = skb_shinfo(skb)->frag_list;
  573. skb_frag_list_init(skb);
  574. __skb_pull(skb, hlen);
  575. fh = __skb_push(skb, sizeof(struct frag_hdr));
  576. __skb_push(skb, hlen);
  577. skb_reset_network_header(skb);
  578. memcpy(skb_network_header(skb), tmp_hdr, hlen);
  579. fh->nexthdr = nexthdr;
  580. fh->reserved = 0;
  581. fh->frag_off = htons(IP6_MF);
  582. fh->identification = frag_id;
  583. first_len = skb_pagelen(skb);
  584. skb->data_len = first_len - skb_headlen(skb);
  585. skb->len = first_len;
  586. ipv6_hdr(skb)->payload_len = htons(first_len -
  587. sizeof(struct ipv6hdr));
  588. for (;;) {
  589. /* Prepare header of the next frame,
  590. * before previous one went down. */
  591. if (frag) {
  592. frag->ip_summed = CHECKSUM_NONE;
  593. skb_reset_transport_header(frag);
  594. fh = __skb_push(frag, sizeof(struct frag_hdr));
  595. __skb_push(frag, hlen);
  596. skb_reset_network_header(frag);
  597. memcpy(skb_network_header(frag), tmp_hdr,
  598. hlen);
  599. offset += skb->len - hlen - sizeof(struct frag_hdr);
  600. fh->nexthdr = nexthdr;
  601. fh->reserved = 0;
  602. fh->frag_off = htons(offset);
  603. if (frag->next)
  604. fh->frag_off |= htons(IP6_MF);
  605. fh->identification = frag_id;
  606. ipv6_hdr(frag)->payload_len =
  607. htons(frag->len -
  608. sizeof(struct ipv6hdr));
  609. ip6_copy_metadata(frag, skb);
  610. }
  611. err = output(net, sk, skb);
  612. if (!err)
  613. IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
  614. IPSTATS_MIB_FRAGCREATES);
  615. if (err || !frag)
  616. break;
  617. skb = frag;
  618. frag = skb->next;
  619. skb->next = NULL;
  620. }
  621. kfree(tmp_hdr);
  622. if (err == 0) {
  623. IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
  624. IPSTATS_MIB_FRAGOKS);
  625. return 0;
  626. }
  627. kfree_skb_list(frag);
  628. IP6_INC_STATS(net, ip6_dst_idev(&rt->dst),
  629. IPSTATS_MIB_FRAGFAILS);
  630. return err;
  631. slow_path_clean:
  632. skb_walk_frags(skb, frag2) {
  633. if (frag2 == frag)
  634. break;
  635. frag2->sk = NULL;
  636. frag2->destructor = NULL;
  637. skb->truesize += frag2->truesize;
  638. }
  639. }
  640. slow_path:
  641. left = skb->len - hlen; /* Space per frame */
  642. ptr = hlen; /* Where to start from */
  643. /*
  644. * Fragment the datagram.
  645. */
  646. troom = rt->dst.dev->needed_tailroom;
  647. /*
  648. * Keep copying data until we run out.
  649. */
  650. while (left > 0) {
  651. u8 *fragnexthdr_offset;
  652. len = left;
  653. /* IF: it doesn't fit, use 'mtu' - the data space left */
  654. if (len > mtu)
  655. len = mtu;
  656. /* IF: we are not sending up to and including the packet end
  657. then align the next start on an eight byte boundary */
  658. if (len < left) {
  659. len &= ~7;
  660. }
  661. /* Allocate buffer */
  662. frag = alloc_skb(len + hlen + sizeof(struct frag_hdr) +
  663. hroom + troom, GFP_ATOMIC);
  664. if (!frag) {
  665. err = -ENOMEM;
  666. goto fail;
  667. }
  668. /*
  669. * Set up data on packet
  670. */
  671. ip6_copy_metadata(frag, skb);
  672. skb_reserve(frag, hroom);
  673. skb_put(frag, len + hlen + sizeof(struct frag_hdr));
  674. skb_reset_network_header(frag);
  675. fh = (struct frag_hdr *)(skb_network_header(frag) + hlen);
  676. frag->transport_header = (frag->network_header + hlen +
  677. sizeof(struct frag_hdr));
  678. /*
  679. * Charge the memory for the fragment to any owner
  680. * it might possess
  681. */
  682. if (skb->sk)
  683. skb_set_owner_w(frag, skb->sk);
  684. /*
  685. * Copy the packet header into the new buffer.
  686. */
  687. skb_copy_from_linear_data(skb, skb_network_header(frag), hlen);
  688. fragnexthdr_offset = skb_network_header(frag);
  689. fragnexthdr_offset += prevhdr - skb_network_header(skb);
  690. *fragnexthdr_offset = NEXTHDR_FRAGMENT;
  691. /*
  692. * Build fragment header.
  693. */
  694. fh->nexthdr = nexthdr;
  695. fh->reserved = 0;
  696. fh->identification = frag_id;
  697. /*
  698. * Copy a block of the IP datagram.
  699. */
  700. BUG_ON(skb_copy_bits(skb, ptr, skb_transport_header(frag),
  701. len));
  702. left -= len;
  703. fh->frag_off = htons(offset);
  704. if (left > 0)
  705. fh->frag_off |= htons(IP6_MF);
  706. ipv6_hdr(frag)->payload_len = htons(frag->len -
  707. sizeof(struct ipv6hdr));
  708. ptr += len;
  709. offset += len;
  710. /*
  711. * Put this fragment into the sending queue.
  712. */
  713. err = output(net, sk, frag);
  714. if (err)
  715. goto fail;
  716. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
  717. IPSTATS_MIB_FRAGCREATES);
  718. }
  719. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
  720. IPSTATS_MIB_FRAGOKS);
  721. consume_skb(skb);
  722. return err;
  723. fail_toobig:
  724. if (skb->sk && dst_allfrag(skb_dst(skb)))
  725. sk_nocaps_add(skb->sk, NETIF_F_GSO_MASK);
  726. icmpv6_send(skb, ICMPV6_PKT_TOOBIG, 0, mtu);
  727. err = -EMSGSIZE;
  728. fail:
  729. IP6_INC_STATS(net, ip6_dst_idev(skb_dst(skb)),
  730. IPSTATS_MIB_FRAGFAILS);
  731. kfree_skb(skb);
  732. return err;
  733. }
  734. static inline int ip6_rt_check(const struct rt6key *rt_key,
  735. const struct in6_addr *fl_addr,
  736. const struct in6_addr *addr_cache)
  737. {
  738. return (rt_key->plen != 128 || !ipv6_addr_equal(fl_addr, &rt_key->addr)) &&
  739. (!addr_cache || !ipv6_addr_equal(fl_addr, addr_cache));
  740. }
  741. static struct dst_entry *ip6_sk_dst_check(struct sock *sk,
  742. struct dst_entry *dst,
  743. const struct flowi6 *fl6)
  744. {
  745. struct ipv6_pinfo *np = inet6_sk(sk);
  746. struct rt6_info *rt;
  747. if (!dst)
  748. goto out;
  749. if (dst->ops->family != AF_INET6) {
  750. dst_release(dst);
  751. return NULL;
  752. }
  753. rt = (struct rt6_info *)dst;
  754. /* Yes, checking route validity in not connected
  755. * case is not very simple. Take into account,
  756. * that we do not support routing by source, TOS,
  757. * and MSG_DONTROUTE --ANK (980726)
  758. *
  759. * 1. ip6_rt_check(): If route was host route,
  760. * check that cached destination is current.
  761. * If it is network route, we still may
  762. * check its validity using saved pointer
  763. * to the last used address: daddr_cache.
  764. * We do not want to save whole address now,
  765. * (because main consumer of this service
  766. * is tcp, which has not this problem),
  767. * so that the last trick works only on connected
  768. * sockets.
  769. * 2. oif also should be the same.
  770. */
  771. if (ip6_rt_check(&rt->rt6i_dst, &fl6->daddr, np->daddr_cache) ||
  772. #ifdef CONFIG_IPV6_SUBTREES
  773. ip6_rt_check(&rt->rt6i_src, &fl6->saddr, np->saddr_cache) ||
  774. #endif
  775. (!(fl6->flowi6_flags & FLOWI_FLAG_SKIP_NH_OIF) &&
  776. (fl6->flowi6_oif && fl6->flowi6_oif != dst->dev->ifindex))) {
  777. dst_release(dst);
  778. dst = NULL;
  779. }
  780. out:
  781. return dst;
  782. }
  783. static int ip6_dst_lookup_tail(struct net *net, const struct sock *sk,
  784. struct dst_entry **dst, struct flowi6 *fl6)
  785. {
  786. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  787. struct neighbour *n;
  788. struct rt6_info *rt;
  789. #endif
  790. int err;
  791. int flags = 0;
  792. /* The correct way to handle this would be to do
  793. * ip6_route_get_saddr, and then ip6_route_output; however,
  794. * the route-specific preferred source forces the
  795. * ip6_route_output call _before_ ip6_route_get_saddr.
  796. *
  797. * In source specific routing (no src=any default route),
  798. * ip6_route_output will fail given src=any saddr, though, so
  799. * that's why we try it again later.
  800. */
  801. if (ipv6_addr_any(&fl6->saddr) && (!*dst || !(*dst)->error)) {
  802. struct fib6_info *from;
  803. struct rt6_info *rt;
  804. bool had_dst = *dst != NULL;
  805. if (!had_dst)
  806. *dst = ip6_route_output(net, sk, fl6);
  807. rt = (*dst)->error ? NULL : (struct rt6_info *)*dst;
  808. rcu_read_lock();
  809. from = rt ? rcu_dereference(rt->from) : NULL;
  810. err = ip6_route_get_saddr(net, from, &fl6->daddr,
  811. sk ? inet6_sk(sk)->srcprefs : 0,
  812. &fl6->saddr);
  813. rcu_read_unlock();
  814. if (err)
  815. goto out_err_release;
  816. /* If we had an erroneous initial result, pretend it
  817. * never existed and let the SA-enabled version take
  818. * over.
  819. */
  820. if (!had_dst && (*dst)->error) {
  821. dst_release(*dst);
  822. *dst = NULL;
  823. }
  824. if (fl6->flowi6_oif)
  825. flags |= RT6_LOOKUP_F_IFACE;
  826. }
  827. if (!*dst)
  828. *dst = ip6_route_output_flags(net, sk, fl6, flags);
  829. err = (*dst)->error;
  830. if (err)
  831. goto out_err_release;
  832. #ifdef CONFIG_IPV6_OPTIMISTIC_DAD
  833. /*
  834. * Here if the dst entry we've looked up
  835. * has a neighbour entry that is in the INCOMPLETE
  836. * state and the src address from the flow is
  837. * marked as OPTIMISTIC, we release the found
  838. * dst entry and replace it instead with the
  839. * dst entry of the nexthop router
  840. */
  841. rt = (struct rt6_info *) *dst;
  842. rcu_read_lock_bh();
  843. n = __ipv6_neigh_lookup_noref(rt->dst.dev,
  844. rt6_nexthop(rt, &fl6->daddr));
  845. err = n && !(n->nud_state & NUD_VALID) ? -EINVAL : 0;
  846. rcu_read_unlock_bh();
  847. if (err) {
  848. struct inet6_ifaddr *ifp;
  849. struct flowi6 fl_gw6;
  850. int redirect;
  851. ifp = ipv6_get_ifaddr(net, &fl6->saddr,
  852. (*dst)->dev, 1);
  853. redirect = (ifp && ifp->flags & IFA_F_OPTIMISTIC);
  854. if (ifp)
  855. in6_ifa_put(ifp);
  856. if (redirect) {
  857. /*
  858. * We need to get the dst entry for the
  859. * default router instead
  860. */
  861. dst_release(*dst);
  862. memcpy(&fl_gw6, fl6, sizeof(struct flowi6));
  863. memset(&fl_gw6.daddr, 0, sizeof(struct in6_addr));
  864. *dst = ip6_route_output(net, sk, &fl_gw6);
  865. err = (*dst)->error;
  866. if (err)
  867. goto out_err_release;
  868. }
  869. }
  870. #endif
  871. if (ipv6_addr_v4mapped(&fl6->saddr) &&
  872. !(ipv6_addr_v4mapped(&fl6->daddr) || ipv6_addr_any(&fl6->daddr))) {
  873. err = -EAFNOSUPPORT;
  874. goto out_err_release;
  875. }
  876. return 0;
  877. out_err_release:
  878. dst_release(*dst);
  879. *dst = NULL;
  880. if (err == -ENETUNREACH)
  881. IP6_INC_STATS(net, NULL, IPSTATS_MIB_OUTNOROUTES);
  882. return err;
  883. }
  884. /**
  885. * ip6_dst_lookup - perform route lookup on flow
  886. * @sk: socket which provides route info
  887. * @dst: pointer to dst_entry * for result
  888. * @fl6: flow to lookup
  889. *
  890. * This function performs a route lookup on the given flow.
  891. *
  892. * It returns zero on success, or a standard errno code on error.
  893. */
  894. int ip6_dst_lookup(struct net *net, struct sock *sk, struct dst_entry **dst,
  895. struct flowi6 *fl6)
  896. {
  897. *dst = NULL;
  898. return ip6_dst_lookup_tail(net, sk, dst, fl6);
  899. }
  900. EXPORT_SYMBOL_GPL(ip6_dst_lookup);
  901. /**
  902. * ip6_dst_lookup_flow - perform route lookup on flow with ipsec
  903. * @sk: socket which provides route info
  904. * @fl6: flow to lookup
  905. * @final_dst: final destination address for ipsec lookup
  906. *
  907. * This function performs a route lookup on the given flow.
  908. *
  909. * It returns a valid dst pointer on success, or a pointer encoded
  910. * error code.
  911. */
  912. struct dst_entry *ip6_dst_lookup_flow(const struct sock *sk, struct flowi6 *fl6,
  913. const struct in6_addr *final_dst)
  914. {
  915. struct dst_entry *dst = NULL;
  916. int err;
  917. err = ip6_dst_lookup_tail(sock_net(sk), sk, &dst, fl6);
  918. if (err)
  919. return ERR_PTR(err);
  920. if (final_dst)
  921. fl6->daddr = *final_dst;
  922. return xfrm_lookup_route(sock_net(sk), dst, flowi6_to_flowi(fl6), sk, 0);
  923. }
  924. EXPORT_SYMBOL_GPL(ip6_dst_lookup_flow);
  925. /**
  926. * ip6_sk_dst_lookup_flow - perform socket cached route lookup on flow
  927. * @sk: socket which provides the dst cache and route info
  928. * @fl6: flow to lookup
  929. * @final_dst: final destination address for ipsec lookup
  930. * @connected: whether @sk is connected or not
  931. *
  932. * This function performs a route lookup on the given flow with the
  933. * possibility of using the cached route in the socket if it is valid.
  934. * It will take the socket dst lock when operating on the dst cache.
  935. * As a result, this function can only be used in process context.
  936. *
  937. * In addition, for a connected socket, cache the dst in the socket
  938. * if the current cache is not valid.
  939. *
  940. * It returns a valid dst pointer on success, or a pointer encoded
  941. * error code.
  942. */
  943. struct dst_entry *ip6_sk_dst_lookup_flow(struct sock *sk, struct flowi6 *fl6,
  944. const struct in6_addr *final_dst,
  945. bool connected)
  946. {
  947. struct dst_entry *dst = sk_dst_check(sk, inet6_sk(sk)->dst_cookie);
  948. dst = ip6_sk_dst_check(sk, dst, fl6);
  949. if (dst)
  950. return dst;
  951. dst = ip6_dst_lookup_flow(sk, fl6, final_dst);
  952. if (connected && !IS_ERR(dst))
  953. ip6_sk_dst_store_flow(sk, dst_clone(dst), fl6);
  954. return dst;
  955. }
  956. EXPORT_SYMBOL_GPL(ip6_sk_dst_lookup_flow);
  957. static inline struct ipv6_opt_hdr *ip6_opt_dup(struct ipv6_opt_hdr *src,
  958. gfp_t gfp)
  959. {
  960. return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
  961. }
  962. static inline struct ipv6_rt_hdr *ip6_rthdr_dup(struct ipv6_rt_hdr *src,
  963. gfp_t gfp)
  964. {
  965. return src ? kmemdup(src, (src->hdrlen + 1) * 8, gfp) : NULL;
  966. }
  967. static void ip6_append_data_mtu(unsigned int *mtu,
  968. int *maxfraglen,
  969. unsigned int fragheaderlen,
  970. struct sk_buff *skb,
  971. struct rt6_info *rt,
  972. unsigned int orig_mtu)
  973. {
  974. if (!(rt->dst.flags & DST_XFRM_TUNNEL)) {
  975. if (!skb) {
  976. /* first fragment, reserve header_len */
  977. *mtu = orig_mtu - rt->dst.header_len;
  978. } else {
  979. /*
  980. * this fragment is not first, the headers
  981. * space is regarded as data space.
  982. */
  983. *mtu = orig_mtu;
  984. }
  985. *maxfraglen = ((*mtu - fragheaderlen) & ~7)
  986. + fragheaderlen - sizeof(struct frag_hdr);
  987. }
  988. }
  989. static int ip6_setup_cork(struct sock *sk, struct inet_cork_full *cork,
  990. struct inet6_cork *v6_cork, struct ipcm6_cookie *ipc6,
  991. struct rt6_info *rt, struct flowi6 *fl6)
  992. {
  993. struct ipv6_pinfo *np = inet6_sk(sk);
  994. unsigned int mtu;
  995. struct ipv6_txoptions *opt = ipc6->opt;
  996. /*
  997. * setup for corking
  998. */
  999. if (opt) {
  1000. if (WARN_ON(v6_cork->opt))
  1001. return -EINVAL;
  1002. v6_cork->opt = kzalloc(sizeof(*opt), sk->sk_allocation);
  1003. if (unlikely(!v6_cork->opt))
  1004. return -ENOBUFS;
  1005. v6_cork->opt->tot_len = sizeof(*opt);
  1006. v6_cork->opt->opt_flen = opt->opt_flen;
  1007. v6_cork->opt->opt_nflen = opt->opt_nflen;
  1008. v6_cork->opt->dst0opt = ip6_opt_dup(opt->dst0opt,
  1009. sk->sk_allocation);
  1010. if (opt->dst0opt && !v6_cork->opt->dst0opt)
  1011. return -ENOBUFS;
  1012. v6_cork->opt->dst1opt = ip6_opt_dup(opt->dst1opt,
  1013. sk->sk_allocation);
  1014. if (opt->dst1opt && !v6_cork->opt->dst1opt)
  1015. return -ENOBUFS;
  1016. v6_cork->opt->hopopt = ip6_opt_dup(opt->hopopt,
  1017. sk->sk_allocation);
  1018. if (opt->hopopt && !v6_cork->opt->hopopt)
  1019. return -ENOBUFS;
  1020. v6_cork->opt->srcrt = ip6_rthdr_dup(opt->srcrt,
  1021. sk->sk_allocation);
  1022. if (opt->srcrt && !v6_cork->opt->srcrt)
  1023. return -ENOBUFS;
  1024. /* need source address above miyazawa*/
  1025. }
  1026. dst_hold(&rt->dst);
  1027. cork->base.dst = &rt->dst;
  1028. cork->fl.u.ip6 = *fl6;
  1029. v6_cork->hop_limit = ipc6->hlimit;
  1030. v6_cork->tclass = ipc6->tclass;
  1031. if (rt->dst.flags & DST_XFRM_TUNNEL)
  1032. mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
  1033. READ_ONCE(rt->dst.dev->mtu) : dst_mtu(&rt->dst);
  1034. else
  1035. mtu = np->pmtudisc >= IPV6_PMTUDISC_PROBE ?
  1036. READ_ONCE(rt->dst.dev->mtu) : dst_mtu(xfrm_dst_path(&rt->dst));
  1037. if (np->frag_size < mtu) {
  1038. if (np->frag_size)
  1039. mtu = np->frag_size;
  1040. }
  1041. if (mtu < IPV6_MIN_MTU)
  1042. return -EINVAL;
  1043. cork->base.fragsize = mtu;
  1044. cork->base.gso_size = ipc6->gso_size;
  1045. cork->base.tx_flags = 0;
  1046. sock_tx_timestamp(sk, ipc6->sockc.tsflags, &cork->base.tx_flags);
  1047. if (dst_allfrag(xfrm_dst_path(&rt->dst)))
  1048. cork->base.flags |= IPCORK_ALLFRAG;
  1049. cork->base.length = 0;
  1050. cork->base.transmit_time = ipc6->sockc.transmit_time;
  1051. return 0;
  1052. }
  1053. static int __ip6_append_data(struct sock *sk,
  1054. struct flowi6 *fl6,
  1055. struct sk_buff_head *queue,
  1056. struct inet_cork *cork,
  1057. struct inet6_cork *v6_cork,
  1058. struct page_frag *pfrag,
  1059. int getfrag(void *from, char *to, int offset,
  1060. int len, int odd, struct sk_buff *skb),
  1061. void *from, int length, int transhdrlen,
  1062. unsigned int flags, struct ipcm6_cookie *ipc6)
  1063. {
  1064. struct sk_buff *skb, *skb_prev = NULL;
  1065. unsigned int maxfraglen, fragheaderlen, mtu, orig_mtu, pmtu;
  1066. int exthdrlen = 0;
  1067. int dst_exthdrlen = 0;
  1068. int hh_len;
  1069. int copy;
  1070. int err;
  1071. int offset = 0;
  1072. u32 tskey = 0;
  1073. struct rt6_info *rt = (struct rt6_info *)cork->dst;
  1074. struct ipv6_txoptions *opt = v6_cork->opt;
  1075. int csummode = CHECKSUM_NONE;
  1076. unsigned int maxnonfragsize, headersize;
  1077. unsigned int wmem_alloc_delta = 0;
  1078. bool paged;
  1079. skb = skb_peek_tail(queue);
  1080. if (!skb) {
  1081. exthdrlen = opt ? opt->opt_flen : 0;
  1082. dst_exthdrlen = rt->dst.header_len - rt->rt6i_nfheader_len;
  1083. }
  1084. paged = !!cork->gso_size;
  1085. mtu = cork->gso_size ? IP6_MAX_MTU : cork->fragsize;
  1086. orig_mtu = mtu;
  1087. if (cork->tx_flags & SKBTX_ANY_SW_TSTAMP &&
  1088. sk->sk_tsflags & SOF_TIMESTAMPING_OPT_ID)
  1089. tskey = sk->sk_tskey++;
  1090. hh_len = LL_RESERVED_SPACE(rt->dst.dev);
  1091. fragheaderlen = sizeof(struct ipv6hdr) + rt->rt6i_nfheader_len +
  1092. (opt ? opt->opt_nflen : 0);
  1093. maxfraglen = ((mtu - fragheaderlen) & ~7) + fragheaderlen -
  1094. sizeof(struct frag_hdr);
  1095. headersize = sizeof(struct ipv6hdr) +
  1096. (opt ? opt->opt_flen + opt->opt_nflen : 0) +
  1097. (dst_allfrag(&rt->dst) ?
  1098. sizeof(struct frag_hdr) : 0) +
  1099. rt->rt6i_nfheader_len;
  1100. /* as per RFC 7112 section 5, the entire IPv6 Header Chain must fit
  1101. * the first fragment
  1102. */
  1103. if (headersize + transhdrlen > mtu)
  1104. goto emsgsize;
  1105. if (cork->length + length > mtu - headersize && ipc6->dontfrag &&
  1106. (sk->sk_protocol == IPPROTO_UDP ||
  1107. sk->sk_protocol == IPPROTO_RAW)) {
  1108. ipv6_local_rxpmtu(sk, fl6, mtu - headersize +
  1109. sizeof(struct ipv6hdr));
  1110. goto emsgsize;
  1111. }
  1112. if (ip6_sk_ignore_df(sk))
  1113. maxnonfragsize = sizeof(struct ipv6hdr) + IPV6_MAXPLEN;
  1114. else
  1115. maxnonfragsize = mtu;
  1116. if (cork->length + length > maxnonfragsize - headersize) {
  1117. emsgsize:
  1118. pmtu = max_t(int, mtu - headersize + sizeof(struct ipv6hdr), 0);
  1119. ipv6_local_error(sk, EMSGSIZE, fl6, pmtu);
  1120. return -EMSGSIZE;
  1121. }
  1122. /* CHECKSUM_PARTIAL only with no extension headers and when
  1123. * we are not going to fragment
  1124. */
  1125. if (transhdrlen && sk->sk_protocol == IPPROTO_UDP &&
  1126. headersize == sizeof(struct ipv6hdr) &&
  1127. length <= mtu - headersize &&
  1128. (!(flags & MSG_MORE) || cork->gso_size) &&
  1129. rt->dst.dev->features & (NETIF_F_IPV6_CSUM | NETIF_F_HW_CSUM))
  1130. csummode = CHECKSUM_PARTIAL;
  1131. /*
  1132. * Let's try using as much space as possible.
  1133. * Use MTU if total length of the message fits into the MTU.
  1134. * Otherwise, we need to reserve fragment header and
  1135. * fragment alignment (= 8-15 octects, in total).
  1136. *
  1137. * Note that we may need to "move" the data from the tail of
  1138. * of the buffer to the new fragment when we split
  1139. * the message.
  1140. *
  1141. * FIXME: It may be fragmented into multiple chunks
  1142. * at once if non-fragmentable extension headers
  1143. * are too large.
  1144. * --yoshfuji
  1145. */
  1146. cork->length += length;
  1147. if (!skb)
  1148. goto alloc_new_skb;
  1149. while (length > 0) {
  1150. /* Check if the remaining data fits into current packet. */
  1151. copy = (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - skb->len;
  1152. if (copy < length)
  1153. copy = maxfraglen - skb->len;
  1154. if (copy <= 0) {
  1155. char *data;
  1156. unsigned int datalen;
  1157. unsigned int fraglen;
  1158. unsigned int fraggap;
  1159. unsigned int alloclen;
  1160. unsigned int pagedlen;
  1161. alloc_new_skb:
  1162. /* There's no room in the current skb */
  1163. if (skb)
  1164. fraggap = skb->len - maxfraglen;
  1165. else
  1166. fraggap = 0;
  1167. /* update mtu and maxfraglen if necessary */
  1168. if (!skb || !skb_prev)
  1169. ip6_append_data_mtu(&mtu, &maxfraglen,
  1170. fragheaderlen, skb, rt,
  1171. orig_mtu);
  1172. skb_prev = skb;
  1173. /*
  1174. * If remaining data exceeds the mtu,
  1175. * we know we need more fragment(s).
  1176. */
  1177. datalen = length + fraggap;
  1178. if (datalen > (cork->length <= mtu && !(cork->flags & IPCORK_ALLFRAG) ? mtu : maxfraglen) - fragheaderlen)
  1179. datalen = maxfraglen - fragheaderlen - rt->dst.trailer_len;
  1180. fraglen = datalen + fragheaderlen;
  1181. pagedlen = 0;
  1182. if ((flags & MSG_MORE) &&
  1183. !(rt->dst.dev->features&NETIF_F_SG))
  1184. alloclen = mtu;
  1185. else if (!paged)
  1186. alloclen = fraglen;
  1187. else {
  1188. alloclen = min_t(int, fraglen, MAX_HEADER);
  1189. pagedlen = fraglen - alloclen;
  1190. }
  1191. alloclen += dst_exthdrlen;
  1192. if (datalen != length + fraggap) {
  1193. /*
  1194. * this is not the last fragment, the trailer
  1195. * space is regarded as data space.
  1196. */
  1197. datalen += rt->dst.trailer_len;
  1198. }
  1199. alloclen += rt->dst.trailer_len;
  1200. fraglen = datalen + fragheaderlen;
  1201. /*
  1202. * We just reserve space for fragment header.
  1203. * Note: this may be overallocation if the message
  1204. * (without MSG_MORE) fits into the MTU.
  1205. */
  1206. alloclen += sizeof(struct frag_hdr);
  1207. copy = datalen - transhdrlen - fraggap - pagedlen;
  1208. if (copy < 0) {
  1209. err = -EINVAL;
  1210. goto error;
  1211. }
  1212. if (transhdrlen) {
  1213. skb = sock_alloc_send_skb(sk,
  1214. alloclen + hh_len,
  1215. (flags & MSG_DONTWAIT), &err);
  1216. } else {
  1217. skb = NULL;
  1218. if (refcount_read(&sk->sk_wmem_alloc) + wmem_alloc_delta <=
  1219. 2 * sk->sk_sndbuf)
  1220. skb = alloc_skb(alloclen + hh_len,
  1221. sk->sk_allocation);
  1222. if (unlikely(!skb))
  1223. err = -ENOBUFS;
  1224. }
  1225. if (!skb)
  1226. goto error;
  1227. /*
  1228. * Fill in the control structures
  1229. */
  1230. skb->protocol = htons(ETH_P_IPV6);
  1231. skb->ip_summed = csummode;
  1232. skb->csum = 0;
  1233. /* reserve for fragmentation and ipsec header */
  1234. skb_reserve(skb, hh_len + sizeof(struct frag_hdr) +
  1235. dst_exthdrlen);
  1236. /* Only the initial fragment is time stamped */
  1237. skb_shinfo(skb)->tx_flags = cork->tx_flags;
  1238. cork->tx_flags = 0;
  1239. skb_shinfo(skb)->tskey = tskey;
  1240. tskey = 0;
  1241. /*
  1242. * Find where to start putting bytes
  1243. */
  1244. data = skb_put(skb, fraglen - pagedlen);
  1245. skb_set_network_header(skb, exthdrlen);
  1246. data += fragheaderlen;
  1247. skb->transport_header = (skb->network_header +
  1248. fragheaderlen);
  1249. if (fraggap) {
  1250. skb->csum = skb_copy_and_csum_bits(
  1251. skb_prev, maxfraglen,
  1252. data + transhdrlen, fraggap, 0);
  1253. skb_prev->csum = csum_sub(skb_prev->csum,
  1254. skb->csum);
  1255. data += fraggap;
  1256. pskb_trim_unique(skb_prev, maxfraglen);
  1257. }
  1258. if (copy > 0 &&
  1259. getfrag(from, data + transhdrlen, offset,
  1260. copy, fraggap, skb) < 0) {
  1261. err = -EFAULT;
  1262. kfree_skb(skb);
  1263. goto error;
  1264. }
  1265. offset += copy;
  1266. length -= copy + transhdrlen;
  1267. transhdrlen = 0;
  1268. exthdrlen = 0;
  1269. dst_exthdrlen = 0;
  1270. if ((flags & MSG_CONFIRM) && !skb_prev)
  1271. skb_set_dst_pending_confirm(skb, 1);
  1272. /*
  1273. * Put the packet on the pending queue
  1274. */
  1275. if (!skb->destructor) {
  1276. skb->destructor = sock_wfree;
  1277. skb->sk = sk;
  1278. wmem_alloc_delta += skb->truesize;
  1279. }
  1280. __skb_queue_tail(queue, skb);
  1281. continue;
  1282. }
  1283. if (copy > length)
  1284. copy = length;
  1285. if (!(rt->dst.dev->features&NETIF_F_SG) &&
  1286. skb_tailroom(skb) >= copy) {
  1287. unsigned int off;
  1288. off = skb->len;
  1289. if (getfrag(from, skb_put(skb, copy),
  1290. offset, copy, off, skb) < 0) {
  1291. __skb_trim(skb, off);
  1292. err = -EFAULT;
  1293. goto error;
  1294. }
  1295. } else {
  1296. int i = skb_shinfo(skb)->nr_frags;
  1297. err = -ENOMEM;
  1298. if (!sk_page_frag_refill(sk, pfrag))
  1299. goto error;
  1300. if (!skb_can_coalesce(skb, i, pfrag->page,
  1301. pfrag->offset)) {
  1302. err = -EMSGSIZE;
  1303. if (i == MAX_SKB_FRAGS)
  1304. goto error;
  1305. __skb_fill_page_desc(skb, i, pfrag->page,
  1306. pfrag->offset, 0);
  1307. skb_shinfo(skb)->nr_frags = ++i;
  1308. get_page(pfrag->page);
  1309. }
  1310. copy = min_t(int, copy, pfrag->size - pfrag->offset);
  1311. if (getfrag(from,
  1312. page_address(pfrag->page) + pfrag->offset,
  1313. offset, copy, skb->len, skb) < 0)
  1314. goto error_efault;
  1315. pfrag->offset += copy;
  1316. skb_frag_size_add(&skb_shinfo(skb)->frags[i - 1], copy);
  1317. skb->len += copy;
  1318. skb->data_len += copy;
  1319. skb->truesize += copy;
  1320. wmem_alloc_delta += copy;
  1321. }
  1322. offset += copy;
  1323. length -= copy;
  1324. }
  1325. if (wmem_alloc_delta)
  1326. refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
  1327. return 0;
  1328. error_efault:
  1329. err = -EFAULT;
  1330. error:
  1331. cork->length -= length;
  1332. IP6_INC_STATS(sock_net(sk), rt->rt6i_idev, IPSTATS_MIB_OUTDISCARDS);
  1333. refcount_add(wmem_alloc_delta, &sk->sk_wmem_alloc);
  1334. return err;
  1335. }
  1336. int ip6_append_data(struct sock *sk,
  1337. int getfrag(void *from, char *to, int offset, int len,
  1338. int odd, struct sk_buff *skb),
  1339. void *from, int length, int transhdrlen,
  1340. struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
  1341. struct rt6_info *rt, unsigned int flags)
  1342. {
  1343. struct inet_sock *inet = inet_sk(sk);
  1344. struct ipv6_pinfo *np = inet6_sk(sk);
  1345. int exthdrlen;
  1346. int err;
  1347. if (flags&MSG_PROBE)
  1348. return 0;
  1349. if (skb_queue_empty(&sk->sk_write_queue)) {
  1350. /*
  1351. * setup for corking
  1352. */
  1353. err = ip6_setup_cork(sk, &inet->cork, &np->cork,
  1354. ipc6, rt, fl6);
  1355. if (err)
  1356. return err;
  1357. exthdrlen = (ipc6->opt ? ipc6->opt->opt_flen : 0);
  1358. length += exthdrlen;
  1359. transhdrlen += exthdrlen;
  1360. } else {
  1361. fl6 = &inet->cork.fl.u.ip6;
  1362. transhdrlen = 0;
  1363. }
  1364. return __ip6_append_data(sk, fl6, &sk->sk_write_queue, &inet->cork.base,
  1365. &np->cork, sk_page_frag(sk), getfrag,
  1366. from, length, transhdrlen, flags, ipc6);
  1367. }
  1368. EXPORT_SYMBOL_GPL(ip6_append_data);
  1369. static void ip6_cork_release(struct inet_cork_full *cork,
  1370. struct inet6_cork *v6_cork)
  1371. {
  1372. if (v6_cork->opt) {
  1373. kfree(v6_cork->opt->dst0opt);
  1374. kfree(v6_cork->opt->dst1opt);
  1375. kfree(v6_cork->opt->hopopt);
  1376. kfree(v6_cork->opt->srcrt);
  1377. kfree(v6_cork->opt);
  1378. v6_cork->opt = NULL;
  1379. }
  1380. if (cork->base.dst) {
  1381. dst_release(cork->base.dst);
  1382. cork->base.dst = NULL;
  1383. cork->base.flags &= ~IPCORK_ALLFRAG;
  1384. }
  1385. memset(&cork->fl, 0, sizeof(cork->fl));
  1386. }
  1387. struct sk_buff *__ip6_make_skb(struct sock *sk,
  1388. struct sk_buff_head *queue,
  1389. struct inet_cork_full *cork,
  1390. struct inet6_cork *v6_cork)
  1391. {
  1392. struct sk_buff *skb, *tmp_skb;
  1393. struct sk_buff **tail_skb;
  1394. struct in6_addr final_dst_buf, *final_dst = &final_dst_buf;
  1395. struct ipv6_pinfo *np = inet6_sk(sk);
  1396. struct net *net = sock_net(sk);
  1397. struct ipv6hdr *hdr;
  1398. struct ipv6_txoptions *opt = v6_cork->opt;
  1399. struct rt6_info *rt = (struct rt6_info *)cork->base.dst;
  1400. struct flowi6 *fl6 = &cork->fl.u.ip6;
  1401. unsigned char proto = fl6->flowi6_proto;
  1402. skb = __skb_dequeue(queue);
  1403. if (!skb)
  1404. goto out;
  1405. tail_skb = &(skb_shinfo(skb)->frag_list);
  1406. /* move skb->data to ip header from ext header */
  1407. if (skb->data < skb_network_header(skb))
  1408. __skb_pull(skb, skb_network_offset(skb));
  1409. while ((tmp_skb = __skb_dequeue(queue)) != NULL) {
  1410. __skb_pull(tmp_skb, skb_network_header_len(skb));
  1411. *tail_skb = tmp_skb;
  1412. tail_skb = &(tmp_skb->next);
  1413. skb->len += tmp_skb->len;
  1414. skb->data_len += tmp_skb->len;
  1415. skb->truesize += tmp_skb->truesize;
  1416. tmp_skb->destructor = NULL;
  1417. tmp_skb->sk = NULL;
  1418. }
  1419. /* Allow local fragmentation. */
  1420. skb->ignore_df = ip6_sk_ignore_df(sk);
  1421. *final_dst = fl6->daddr;
  1422. __skb_pull(skb, skb_network_header_len(skb));
  1423. if (opt && opt->opt_flen)
  1424. ipv6_push_frag_opts(skb, opt, &proto);
  1425. if (opt && opt->opt_nflen)
  1426. ipv6_push_nfrag_opts(skb, opt, &proto, &final_dst, &fl6->saddr);
  1427. skb_push(skb, sizeof(struct ipv6hdr));
  1428. skb_reset_network_header(skb);
  1429. hdr = ipv6_hdr(skb);
  1430. ip6_flow_hdr(hdr, v6_cork->tclass,
  1431. ip6_make_flowlabel(net, skb, fl6->flowlabel,
  1432. ip6_autoflowlabel(net, np), fl6));
  1433. hdr->hop_limit = v6_cork->hop_limit;
  1434. hdr->nexthdr = proto;
  1435. hdr->saddr = fl6->saddr;
  1436. hdr->daddr = *final_dst;
  1437. skb->priority = sk->sk_priority;
  1438. skb->mark = sk->sk_mark;
  1439. skb->tstamp = cork->base.transmit_time;
  1440. skb_dst_set(skb, dst_clone(&rt->dst));
  1441. IP6_UPD_PO_STATS(net, rt->rt6i_idev, IPSTATS_MIB_OUT, skb->len);
  1442. if (proto == IPPROTO_ICMPV6) {
  1443. struct inet6_dev *idev = ip6_dst_idev(skb_dst(skb));
  1444. ICMP6MSGOUT_INC_STATS(net, idev, icmp6_hdr(skb)->icmp6_type);
  1445. ICMP6_INC_STATS(net, idev, ICMP6_MIB_OUTMSGS);
  1446. }
  1447. ip6_cork_release(cork, v6_cork);
  1448. out:
  1449. return skb;
  1450. }
  1451. int ip6_send_skb(struct sk_buff *skb)
  1452. {
  1453. struct net *net = sock_net(skb->sk);
  1454. struct rt6_info *rt = (struct rt6_info *)skb_dst(skb);
  1455. int err;
  1456. err = ip6_local_out(net, skb->sk, skb);
  1457. if (err) {
  1458. if (err > 0)
  1459. err = net_xmit_errno(err);
  1460. if (err)
  1461. IP6_INC_STATS(net, rt->rt6i_idev,
  1462. IPSTATS_MIB_OUTDISCARDS);
  1463. }
  1464. return err;
  1465. }
  1466. int ip6_push_pending_frames(struct sock *sk)
  1467. {
  1468. struct sk_buff *skb;
  1469. skb = ip6_finish_skb(sk);
  1470. if (!skb)
  1471. return 0;
  1472. return ip6_send_skb(skb);
  1473. }
  1474. EXPORT_SYMBOL_GPL(ip6_push_pending_frames);
  1475. static void __ip6_flush_pending_frames(struct sock *sk,
  1476. struct sk_buff_head *queue,
  1477. struct inet_cork_full *cork,
  1478. struct inet6_cork *v6_cork)
  1479. {
  1480. struct sk_buff *skb;
  1481. while ((skb = __skb_dequeue_tail(queue)) != NULL) {
  1482. if (skb_dst(skb))
  1483. IP6_INC_STATS(sock_net(sk), ip6_dst_idev(skb_dst(skb)),
  1484. IPSTATS_MIB_OUTDISCARDS);
  1485. kfree_skb(skb);
  1486. }
  1487. ip6_cork_release(cork, v6_cork);
  1488. }
  1489. void ip6_flush_pending_frames(struct sock *sk)
  1490. {
  1491. __ip6_flush_pending_frames(sk, &sk->sk_write_queue,
  1492. &inet_sk(sk)->cork, &inet6_sk(sk)->cork);
  1493. }
  1494. EXPORT_SYMBOL_GPL(ip6_flush_pending_frames);
  1495. struct sk_buff *ip6_make_skb(struct sock *sk,
  1496. int getfrag(void *from, char *to, int offset,
  1497. int len, int odd, struct sk_buff *skb),
  1498. void *from, int length, int transhdrlen,
  1499. struct ipcm6_cookie *ipc6, struct flowi6 *fl6,
  1500. struct rt6_info *rt, unsigned int flags,
  1501. struct inet_cork_full *cork)
  1502. {
  1503. struct inet6_cork v6_cork;
  1504. struct sk_buff_head queue;
  1505. int exthdrlen = (ipc6->opt ? ipc6->opt->opt_flen : 0);
  1506. int err;
  1507. if (flags & MSG_PROBE)
  1508. return NULL;
  1509. __skb_queue_head_init(&queue);
  1510. cork->base.flags = 0;
  1511. cork->base.addr = 0;
  1512. cork->base.opt = NULL;
  1513. cork->base.dst = NULL;
  1514. v6_cork.opt = NULL;
  1515. err = ip6_setup_cork(sk, cork, &v6_cork, ipc6, rt, fl6);
  1516. if (err) {
  1517. ip6_cork_release(cork, &v6_cork);
  1518. return ERR_PTR(err);
  1519. }
  1520. if (ipc6->dontfrag < 0)
  1521. ipc6->dontfrag = inet6_sk(sk)->dontfrag;
  1522. err = __ip6_append_data(sk, fl6, &queue, &cork->base, &v6_cork,
  1523. &current->task_frag, getfrag, from,
  1524. length + exthdrlen, transhdrlen + exthdrlen,
  1525. flags, ipc6);
  1526. if (err) {
  1527. __ip6_flush_pending_frames(sk, &queue, cork, &v6_cork);
  1528. return ERR_PTR(err);
  1529. }
  1530. return __ip6_make_skb(sk, &queue, cork, &v6_cork);
  1531. }