ipv6.c 14 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747
  1. #include "u.h"
  2. #include "../port/lib.h"
  3. #include "mem.h"
  4. #include "dat.h"
  5. #include "fns.h"
  6. #include "../port/error.h"
  7. #include "ip.h"
  8. #include "ipv6.h"
  9. enum
  10. {
  11. IP4HDR = 20, /* sizeof(Ip4hdr) */
  12. IP6HDR = 40, /* sizeof(Ip6hdr) */
  13. IP_HLEN4 = 0x05, /* Header length in words */
  14. IP_DF = 0x4000, /* Don't fragment */
  15. IP_MF = 0x2000, /* More fragments */
  16. IP6FHDR = 8, /* sizeof(Fraghdr6) */
  17. IP_MAX = (32*1024), /* Maximum Internet packet size */
  18. };
  19. #define IPV6CLASS(hdr) ((hdr->vcf[0]&0x0F)<<2 | (hdr->vcf[1]&0xF0)>>2)
  20. #define BLKIPVER(xp) (((Ip6hdr*)((xp)->rp))->vcf[0]&0xF0)
  21. /*
  22. * This sleazy macro is stolen shamelessly from ip.c, see comment there.
  23. */
  24. #define BKFG(xp) ((Ipfrag*)((xp)->base))
  25. typedef struct IP IP;
  26. typedef struct Fragment4 Fragment4;
  27. typedef struct Fragment6 Fragment6;
  28. typedef struct Ipfrag Ipfrag;
  29. Block* ip6reassemble(IP*, int, Block*, Ip6hdr*);
  30. void ipfragfree6(IP*, Fragment6*);
  31. Fragment6* ipfragallo6(IP*);
  32. static Block* procxtns(IP *ip, Block *bp, int doreasm);
  33. int unfraglen(Block *bp, uchar *nexthdr, int setfh);
  34. Block* procopts(Block *bp);
  35. /* MIB II counters */
  36. enum
  37. {
  38. Forwarding,
  39. DefaultTTL,
  40. InReceives,
  41. InHdrErrors,
  42. InAddrErrors,
  43. ForwDatagrams,
  44. InUnknownProtos,
  45. InDiscards,
  46. InDelivers,
  47. OutRequests,
  48. OutDiscards,
  49. OutNoRoutes,
  50. ReasmTimeout,
  51. ReasmReqds,
  52. ReasmOKs,
  53. ReasmFails,
  54. FragOKs,
  55. FragFails,
  56. FragCreates,
  57. Nstats,
  58. };
  59. static char *statnames[] =
  60. {
  61. [Forwarding] "Forwarding",
  62. [DefaultTTL] "DefaultTTL",
  63. [InReceives] "InReceives",
  64. [InHdrErrors] "InHdrErrors",
  65. [InAddrErrors] "InAddrErrors",
  66. [ForwDatagrams] "ForwDatagrams",
  67. [InUnknownProtos] "InUnknownProtos",
  68. [InDiscards] "InDiscards",
  69. [InDelivers] "InDelivers",
  70. [OutRequests] "OutRequests",
  71. [OutDiscards] "OutDiscards",
  72. [OutNoRoutes] "OutNoRoutes",
  73. [ReasmTimeout] "ReasmTimeout",
  74. [ReasmReqds] "ReasmReqds",
  75. [ReasmOKs] "ReasmOKs",
  76. [ReasmFails] "ReasmFails",
  77. [FragOKs] "FragOKs",
  78. [FragFails] "FragFails",
  79. [FragCreates] "FragCreates",
  80. };
  81. struct Fragment4
  82. {
  83. Block* blist;
  84. Fragment4* next;
  85. ulong src;
  86. ulong dst;
  87. ushort id;
  88. ulong age;
  89. };
  90. struct Fragment6
  91. {
  92. Block* blist;
  93. Fragment6* next;
  94. uchar src[IPaddrlen];
  95. uchar dst[IPaddrlen];
  96. uint id;
  97. ulong age;
  98. };
  99. struct Ipfrag
  100. {
  101. ushort foff;
  102. ushort flen;
  103. };
  104. /* an instance of IP */
  105. struct IP
  106. {
  107. ulong stats[Nstats];
  108. QLock fraglock4;
  109. Fragment4* flisthead4;
  110. Fragment4* fragfree4;
  111. Ref id4;
  112. QLock fraglock6;
  113. Fragment6* flisthead6;
  114. Fragment6* fragfree6;
  115. Ref id6;
  116. int iprouting; /* true if we route like a gateway */
  117. };
  118. int
  119. ipoput6(Fs *f, Block *bp, int gating, int ttl, int tos)
  120. {
  121. int tentative;
  122. Ipifc *ifc;
  123. uchar *gate, nexthdr;
  124. Ip6hdr *eh;
  125. int medialen, len, chunk, uflen, flen, seglen, lid, offset, fragoff, morefrags, blklen;
  126. Route *r, *sr;
  127. Fraghdr6 fraghdr;
  128. Block *xp, *nb;
  129. IP *ip;
  130. int rv = 0;
  131. ip = f->ip;
  132. /* Fill out the ip header */
  133. eh = (Ip6hdr*)(bp->rp);
  134. ip->stats[OutRequests]++;
  135. /* Number of uchars in data and ip header to write */
  136. len = blocklen(bp);
  137. tentative = iptentative(f, eh->src);
  138. if(tentative){
  139. netlog(f, Logip, "reject tx of packet with tentative src address\n");
  140. goto free;
  141. }
  142. if(gating){
  143. chunk = nhgets(eh->ploadlen);
  144. if(chunk > len){
  145. ip->stats[OutDiscards]++;
  146. netlog(f, Logip, "short gated packet\n");
  147. goto free;
  148. }
  149. if(chunk + IPV6HDR_LEN < len)
  150. len = chunk + IPV6HDR_LEN;
  151. }
  152. if(len >= IP_MAX){
  153. print("len > IP_MAX, free\n");
  154. ip->stats[OutDiscards]++;
  155. netlog(f, Logip, "exceeded ip max size %I\n", eh->dst);
  156. goto free;
  157. }
  158. r = v6lookup(f, eh->dst);
  159. if(r == nil){
  160. // print("no route for %I, src %I free\n", eh->dst, eh->src);
  161. ip->stats[OutNoRoutes]++;
  162. netlog(f, Logip, "no interface %I\n", eh->dst);
  163. rv = -1;
  164. goto free;
  165. }
  166. ifc = r->ifc;
  167. if(r->type & (Rifc|Runi))
  168. gate = eh->dst;
  169. else
  170. if(r->type & (Rbcast|Rmulti)) {
  171. gate = eh->dst;
  172. sr = v6lookup(f, eh->src);
  173. if(sr != nil && (sr->type & Runi))
  174. ifc = sr->ifc;
  175. }
  176. else
  177. gate = r->v6.gate;
  178. if(!gating)
  179. eh->vcf[0] = IP_VER6;
  180. eh->ttl = ttl;
  181. if(!gating) {
  182. eh->vcf[0] |= (tos >> 4);
  183. eh->vcf[1] = (tos << 4);
  184. }
  185. if(!canrlock(ifc)) {
  186. goto free;
  187. }
  188. if(waserror()){
  189. runlock(ifc);
  190. nexterror();
  191. }
  192. if(ifc->m == nil) {
  193. goto raise;
  194. }
  195. /* If we dont need to fragment just send it */
  196. medialen = ifc->maxtu - ifc->m->hsize;
  197. if(len <= medialen) {
  198. hnputs(eh->ploadlen, len-IPV6HDR_LEN);
  199. ifc->m->bwrite(ifc, bp, V6, gate);
  200. runlock(ifc);
  201. poperror();
  202. return 0;
  203. }
  204. if(gating)
  205. if(ifc->reassemble <= 0) {
  206. /* v6 intermediate nodes are not supposed to fragment pkts;
  207. we fragment if ifc->reassemble is turned on; an exception
  208. needed for nat.
  209. */
  210. ip->stats[OutDiscards]++;
  211. icmppkttoobig6(f, ifc, bp);
  212. netlog(f, Logip, "%I: gated pkts not fragmented\n", eh->dst);
  213. goto raise;
  214. }
  215. /* start v6 fragmentation */
  216. uflen = unfraglen(bp, &nexthdr, 1);
  217. if(uflen > medialen) {
  218. ip->stats[FragFails]++;
  219. ip->stats[OutDiscards]++;
  220. netlog(f, Logip, "%I: unfragmentable part too big\n", eh->dst);
  221. goto raise;
  222. }
  223. flen = len - uflen;
  224. seglen = (medialen - (uflen + IP6FHDR)) & ~7;
  225. if(seglen < 8) {
  226. ip->stats[FragFails]++;
  227. ip->stats[OutDiscards]++;
  228. netlog(f, Logip, "%I: seglen < 8\n", eh->dst);
  229. goto raise;
  230. }
  231. lid = incref(&ip->id6);
  232. fraghdr.nexthdr = nexthdr;
  233. fraghdr.res = 0;
  234. hnputl(fraghdr.id, lid);
  235. xp = bp;
  236. offset = uflen;
  237. while (xp != nil && offset && offset >= BLEN(xp)) {
  238. offset -= BLEN(xp);
  239. xp = xp->next;
  240. }
  241. xp->rp += offset;
  242. fragoff = 0;
  243. morefrags = 1;
  244. for(; fragoff < flen; fragoff += seglen) {
  245. nb = allocb(uflen + IP6FHDR + seglen);
  246. if(fragoff + seglen >= flen) {
  247. seglen = flen - fragoff;
  248. morefrags = 0;
  249. }
  250. hnputs(eh->ploadlen, seglen+IP6FHDR);
  251. memmove(nb->wp, eh, uflen);
  252. nb->wp += uflen;
  253. hnputs(fraghdr.offsetRM, fragoff); // last 3 bits must be 0
  254. fraghdr.offsetRM[1] |= morefrags;
  255. memmove(nb->wp, &fraghdr, IP6FHDR);
  256. nb->wp += IP6FHDR;
  257. /* Copy data */
  258. chunk = seglen;
  259. while (chunk) {
  260. if(!xp) {
  261. ip->stats[OutDiscards]++;
  262. ip->stats[FragFails]++;
  263. freeblist(nb);
  264. netlog(f, Logip, "!xp: chunk in v6%d\n", chunk);
  265. goto raise;
  266. }
  267. blklen = chunk;
  268. if(BLEN(xp) < chunk)
  269. blklen = BLEN(xp);
  270. memmove(nb->wp, xp->rp, blklen);
  271. nb->wp += blklen;
  272. xp->rp += blklen;
  273. chunk -= blklen;
  274. if(xp->rp == xp->wp)
  275. xp = xp->next;
  276. }
  277. ifc->m->bwrite(ifc, nb, V6, gate);
  278. ip->stats[FragCreates]++;
  279. }
  280. ip->stats[FragOKs]++;
  281. raise:
  282. runlock(ifc);
  283. poperror();
  284. free:
  285. freeblist(bp);
  286. return rv;
  287. }
  288. void
  289. ipiput6(Fs *f, Ipifc *ifc, Block *bp)
  290. {
  291. int hl;
  292. int hop, tos;
  293. uchar proto;
  294. Ip6hdr *h;
  295. Proto *p;
  296. int notforme;
  297. int tentative;
  298. uchar v6dst[IPaddrlen];
  299. IP *ip;
  300. Route *r, *sr;
  301. ip = f->ip;
  302. ip->stats[InReceives]++;
  303. /*
  304. * Ensure we have all the header info in the first
  305. * block. Make life easier for other protocols by
  306. * collecting up to the first 64 bytes in the first block.
  307. */
  308. if(BLEN(bp) < 64) {
  309. hl = blocklen(bp);
  310. if(hl < IP6HDR)
  311. hl = IP6HDR;
  312. if(hl > 64)
  313. hl = 64;
  314. bp = pullupblock(bp, hl);
  315. if(bp == nil)
  316. return;
  317. }
  318. h = (Ip6hdr *)(bp->rp);
  319. memmove(&v6dst[0], &(h->dst)[0], IPaddrlen);
  320. notforme = ipforme(f, v6dst) == 0;
  321. tentative = iptentative(f, v6dst);
  322. if(tentative && (h->proto != ICMPv6)) {
  323. print("tentative addr, drop\n");
  324. freeblist(bp);
  325. return;
  326. }
  327. /* Check header version */
  328. if(BLKIPVER(bp) != IP_VER6) {
  329. ip->stats[InHdrErrors]++;
  330. netlog(f, Logip, "ip: bad version %ux\n", (h->vcf[0]&0xF0)>>2);
  331. freeblist(bp);
  332. return;
  333. }
  334. /* route */
  335. if(notforme) {
  336. if(!ip->iprouting){
  337. freeb(bp);
  338. return;
  339. }
  340. /* don't forward to source's network */
  341. sr = v6lookup(f, h->src);
  342. r = v6lookup(f, h->dst);
  343. if(r == nil || sr == r){
  344. ip->stats[OutDiscards]++;
  345. freeblist(bp);
  346. return;
  347. }
  348. /* don't forward if packet has timed out */
  349. hop = h->ttl;
  350. if(hop < 1) {
  351. ip->stats[InHdrErrors]++;
  352. icmpttlexceeded6(f, ifc, bp);
  353. freeblist(bp);
  354. return;
  355. }
  356. /* process headers & reassemble if the interface expects it */
  357. bp = procxtns(ip, bp, r->ifc->reassemble);
  358. if(bp == nil)
  359. return;
  360. ip->stats[ForwDatagrams]++;
  361. h = (Ip6hdr *) (bp->rp);
  362. tos = IPV6CLASS(h);
  363. hop = h->ttl;
  364. ipoput6(f, bp, 1, hop-1, tos);
  365. return;
  366. }
  367. /* reassemble & process headers if needed */
  368. bp = procxtns(ip, bp, 1);
  369. if(bp == nil)
  370. return;
  371. h = (Ip6hdr *) (bp->rp);
  372. proto = h->proto;
  373. p = Fsrcvpcol(f, proto);
  374. if(p != nil && p->rcv != nil) {
  375. ip->stats[InDelivers]++;
  376. (*p->rcv)(p, ifc, bp);
  377. return;
  378. }
  379. ip->stats[InDiscards]++;
  380. ip->stats[InUnknownProtos]++;
  381. freeblist(bp);
  382. }
  383. /*
  384. * ipfragfree6 - copied from ipfragfree4 - assume hold fraglock6
  385. */
  386. void
  387. ipfragfree6(IP *ip, Fragment6 *frag)
  388. {
  389. Fragment6 *fl, **l;
  390. if(frag->blist)
  391. freeblist(frag->blist);
  392. memset(frag->src, 0, IPaddrlen);
  393. frag->id = 0;
  394. frag->blist = nil;
  395. l = &ip->flisthead6;
  396. for(fl = *l; fl; fl = fl->next) {
  397. if(fl == frag) {
  398. *l = frag->next;
  399. break;
  400. }
  401. l = &fl->next;
  402. }
  403. frag->next = ip->fragfree6;
  404. ip->fragfree6 = frag;
  405. }
  406. /*
  407. * ipfragallo6 - copied from ipfragalloc4
  408. */
  409. Fragment6*
  410. ipfragallo6(IP *ip)
  411. {
  412. Fragment6 *f;
  413. while(ip->fragfree6 == nil) {
  414. /* free last entry on fraglist */
  415. for(f = ip->flisthead6; f->next; f = f->next)
  416. ;
  417. ipfragfree6(ip, f);
  418. }
  419. f = ip->fragfree6;
  420. ip->fragfree6 = f->next;
  421. f->next = ip->flisthead6;
  422. ip->flisthead6 = f;
  423. f->age = NOW + 30000;
  424. return f;
  425. }
  426. static Block*
  427. procxtns(IP *ip, Block *bp, int doreasm) {
  428. int offset;
  429. uchar proto;
  430. Ip6hdr *h;
  431. h = (Ip6hdr *) (bp->rp);
  432. offset = unfraglen(bp, &proto, 0);
  433. if((proto == FH) && (doreasm != 0)) {
  434. bp = ip6reassemble(ip, offset, bp, h);
  435. if(bp == nil)
  436. return nil;
  437. offset = unfraglen(bp, &proto, 0);
  438. }
  439. if(proto == DOH || offset > IP6HDR)
  440. bp = procopts(bp);
  441. return bp;
  442. }
  443. /* returns length of "Unfragmentable part", i.e., sum of lengths of ipv6 hdr,
  444. * hop-by-hop & routing headers if present; *nexthdr is set to nexthdr value
  445. * of the last header in the "Unfragmentable part"; if setfh != 0, nexthdr
  446. * field of the last header in the "Unfragmentable part" is set to FH.
  447. */
  448. int
  449. unfraglen(Block *bp, uchar *nexthdr, int setfh)
  450. {
  451. uchar *p, *q;
  452. int ufl, hs;
  453. p = bp->rp;
  454. q = p+6; /* proto, = p+sizeof(Ip6hdr.vcf)+sizeof(Ip6hdr.ploadlen) */
  455. *nexthdr = *q;
  456. ufl = IP6HDR;
  457. p += ufl;
  458. for(;;) {
  459. if(*nexthdr == HBH || *nexthdr == RH) {
  460. *nexthdr = *p;
  461. hs = ((int)*(p+1) + 1) * 8;
  462. ufl += hs;
  463. q = p;
  464. p += hs;
  465. }
  466. else
  467. break;
  468. }
  469. if(*nexthdr == FH)
  470. *q = *p;
  471. if(setfh)
  472. *q = FH;
  473. return ufl;
  474. }
  475. Block*
  476. procopts(Block *bp)
  477. {
  478. return bp;
  479. }
  480. Block*
  481. ip6reassemble(IP* ip, int uflen, Block* bp, Ip6hdr* ih)
  482. {
  483. int fend, offset;
  484. uint id;
  485. Fragment6 *f, *fnext;
  486. Fraghdr6 *fraghdr;
  487. uchar src[IPaddrlen], dst[IPaddrlen];
  488. Block *bl, **l, *last, *prev;
  489. int ovlap, len, fragsize, pktposn;
  490. fraghdr = (Fraghdr6 *) (bp->rp + uflen);
  491. memmove(src, ih->src, IPaddrlen);
  492. memmove(dst, ih->dst, IPaddrlen);
  493. id = nhgetl(fraghdr->id);
  494. offset = nhgets(fraghdr->offsetRM) & ~7;
  495. /*
  496. * block lists are too hard, pullupblock into a single block
  497. */
  498. if(bp->next){
  499. bp = pullupblock(bp, blocklen(bp));
  500. ih = (Ip6hdr *)(bp->rp);
  501. }
  502. qlock(&ip->fraglock6);
  503. /*
  504. * find a reassembly queue for this fragment
  505. */
  506. for(f = ip->flisthead6; f; f = fnext){
  507. fnext = f->next;
  508. if(ipcmp(f->src, src)==0 && ipcmp(f->dst, dst)==0 && f->id == id)
  509. break;
  510. if(f->age < NOW){
  511. ip->stats[ReasmTimeout]++;
  512. ipfragfree6(ip, f);
  513. }
  514. }
  515. /*
  516. * if this isn't a fragmented packet, accept it
  517. * and get rid of any fragments that might go
  518. * with it.
  519. */
  520. if(nhgets(fraghdr->offsetRM)==0) { // first frag is also the last
  521. if(f != nil) {
  522. ipfragfree6(ip, f);
  523. ip->stats[ReasmFails]++;
  524. }
  525. qunlock(&ip->fraglock6);
  526. return bp;
  527. }
  528. if(bp->base+sizeof(Ipfrag) >= bp->rp){
  529. bp = padblock(bp, sizeof(Ipfrag));
  530. bp->rp += sizeof(Ipfrag);
  531. }
  532. BKFG(bp)->foff = offset;
  533. BKFG(bp)->flen = nhgets(ih->ploadlen) + IP6HDR - uflen - IP6FHDR;
  534. /* First fragment allocates a reassembly queue */
  535. if(f == nil) {
  536. f = ipfragallo6(ip);
  537. f->id = id;
  538. memmove(f->src, src, IPaddrlen);
  539. memmove(f->dst, dst, IPaddrlen);
  540. f->blist = bp;
  541. qunlock(&ip->fraglock6);
  542. ip->stats[ReasmReqds]++;
  543. return nil;
  544. }
  545. /*
  546. * find the new fragment's position in the queue
  547. */
  548. prev = nil;
  549. l = &f->blist;
  550. bl = f->blist;
  551. while(bl != nil && BKFG(bp)->foff > BKFG(bl)->foff) {
  552. prev = bl;
  553. l = &bl->next;
  554. bl = bl->next;
  555. }
  556. /* Check overlap of a previous fragment - trim away as necessary */
  557. if(prev) {
  558. ovlap = BKFG(prev)->foff + BKFG(prev)->flen - BKFG(bp)->foff;
  559. if(ovlap > 0) {
  560. if(ovlap >= BKFG(bp)->flen) {
  561. freeblist(bp);
  562. qunlock(&ip->fraglock6);
  563. return nil;
  564. }
  565. BKFG(prev)->flen -= ovlap;
  566. }
  567. }
  568. /* Link onto assembly queue */
  569. bp->next = *l;
  570. *l = bp;
  571. /* Check to see if succeeding segments overlap */
  572. if(bp->next) {
  573. l = &bp->next;
  574. fend = BKFG(bp)->foff + BKFG(bp)->flen;
  575. /* Take completely covered segments out */
  576. while(*l) {
  577. ovlap = fend - BKFG(*l)->foff;
  578. if(ovlap <= 0)
  579. break;
  580. if(ovlap < BKFG(*l)->flen) {
  581. BKFG(*l)->flen -= ovlap;
  582. BKFG(*l)->foff += ovlap;
  583. /* move up ih hdrs */
  584. memmove((*l)->rp + ovlap, (*l)->rp, uflen);
  585. (*l)->rp += ovlap;
  586. break;
  587. }
  588. last = (*l)->next;
  589. (*l)->next = nil;
  590. freeblist(*l);
  591. *l = last;
  592. }
  593. }
  594. /*
  595. * look for a complete packet. if we get to a fragment
  596. * with the trailing bit of fraghdr->offsetRM[1] set, we're done.
  597. */
  598. pktposn = 0;
  599. for(bl = f->blist; bl; bl = bl->next) {
  600. if(BKFG(bl)->foff != pktposn)
  601. break;
  602. fraghdr = (Fraghdr6 *) (bl->rp + uflen);
  603. if((fraghdr->offsetRM[1] & 1) == 0) {
  604. bl = f->blist;
  605. /* get rid of frag header in first fragment */
  606. memmove(bl->rp + IP6FHDR, bl->rp, uflen);
  607. bl->rp += IP6FHDR;
  608. len = nhgets(((Ip6hdr*)(bl->rp))->ploadlen) - IP6FHDR;
  609. bl->wp = bl->rp + len + IP6HDR;
  610. /* Pullup all the fragment headers and
  611. * return a complete packet
  612. */
  613. for(bl = bl->next; bl; bl = bl->next) {
  614. fragsize = BKFG(bl)->flen;
  615. len += fragsize;
  616. bl->rp += uflen + IP6FHDR;
  617. bl->wp = bl->rp + fragsize;
  618. }
  619. bl = f->blist;
  620. f->blist = nil;
  621. ipfragfree6(ip, f);
  622. ih = (Ip6hdr*)(bl->rp);
  623. hnputs(ih->ploadlen, len);
  624. qunlock(&ip->fraglock6);
  625. ip->stats[ReasmOKs]++;
  626. return bl;
  627. }
  628. pktposn += BKFG(bl)->flen;
  629. }
  630. qunlock(&ip->fraglock6);
  631. return nil;
  632. }