Index: head/sys/netinet6/frag6.c =================================================================== --- head/sys/netinet6/frag6.c +++ head/sys/netinet6/frag6.c @@ -395,6 +395,8 @@ m = *mp; offset = *offp; + M_ASSERTPKTHDR(m); + ip6 = mtod(m, struct ip6_hdr *); #ifndef PULLDOWN_TEST IP6_EXTHDR_CHECK(m, offset, sizeof(struct ip6_frag), IPPROTO_DONE); @@ -437,22 +439,35 @@ IP6STAT_INC(ip6s_fragments); in6_ifstat_inc(dstifp, ifs6_reass_reqd); - /* Offset now points to data portion. */ - offset += sizeof(struct ip6_frag); - /* * Handle "atomic" fragments (offset and m bit set to 0) upfront, - * unrelated to any reassembly. Still need to remove the frag hdr. + * unrelated to any reassembly. We need to remove the frag hdr + * which is ugly. * See RFC 6946 and section 4.5 of RFC 8200. */ if ((ip6f->ip6f_offlg & ~IP6F_RESERVED_MASK) == 0) { IP6STAT_INC(ip6s_atomicfrags); - /* XXX-BZ handle correctly. */ + nxt = ip6f->ip6f_nxt; + /* + * Set nxt(-hdr field value) to the original value. + * We cannot just set ip6->ip6_nxt as there might be + * an unfragmentable part with extension headers and + * we must update the last one. + */ + m_copyback(m, ip6_get_prevhdr(m, offset), sizeof(uint8_t), + (caddr_t)&nxt); + ip6->ip6_plen = htons(ntohs(ip6->ip6_plen) - + sizeof(struct ip6_frag)); + if (ip6_deletefraghdr(m, offset, M_NOWAIT) != 0) + goto dropfrag2; + m->m_pkthdr.len -= sizeof(struct ip6_frag); in6_ifstat_inc(dstifp, ifs6_reass_ok); - *offp = offset; - m->m_flags |= M_FRAGMENTED; - return (ip6f->ip6f_nxt); + *mp = m; + return (nxt); } + + /* Offset now points to data portion. */ + offset += sizeof(struct ip6_frag); /* Get fragment length and discard 0-byte fragments. */ frgpartlen = sizeof(struct ip6_hdr) + ntohs(ip6->ip6_plen) - offset; Index: head/tests/sys/netinet6/frag6/frag6_03.py =================================================================== --- head/tests/sys/netinet6/frag6/frag6_03.py +++ head/tests/sys/netinet6/frag6/frag6_03.py @@ -101,6 +101,33 @@ if not sniffer.foundCorrectPacket: sys.exit(1) + + # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # # ## + # + # Atomic fragment with extension header. + # + # A: Nothing listening on UDP port. + # R: ICMPv6 dst unreach, unreach port. + # + # Start sniffing on recvif + sniffer = Sniffer(args, check_icmp6_error) + + ip6f01 = sp.Ether() / \ + sp.IPv6(src=args.src[0], dst=args.to[0]) / \ + sp.IPv6ExtHdrDestOpt(options = \ + sp.PadN(optdata="\x00\x00\x00\x00\x00\x00")) / \ + sp.IPv6ExtHdrFragment(offset=0, m=0, id=0x3001) / \ + sp.UDP(dport=3456, sport=6543) + if args.debug : + ip6f01.display() + sp.sendp(ip6f01, iface=args.sendif[0], verbose=False) + + sleep(0.10) + sniffer.setEnd() + sniffer.join() + if not sniffer.foundCorrectPacket: + sys.exit(1) + sys.exit(0) if __name__ == '__main__': Index: head/tests/sys/netinet6/frag6/frag6_03.sh =================================================================== --- head/tests/sys/netinet6/frag6/frag6_03.sh +++ head/tests/sys/netinet6/frag6/frag6_03.sh @@ -67,12 +67,12 @@ # Check selection of global UDP stats. # cat < ${HOME}/filter-${jname}.txt - 1 + 2 0 0 0 0 - 1 + 2 0 0 0 @@ -94,11 +94,11 @@ 0 0 0 - 1 + 2 0 0 0 - 1 + 2 0 0 0 @@ -124,12 +124,12 @@ # XXX-TODO check output histogram (just too hard to parse [no multi-line-grep]) # cat < ${HOME}/filter-${jname}.txt - 1 + 2 0 0 0 0 - 1 + 2 0 0 0 @@ -170,8 +170,8 @@ 0 0 0 - 1 - 1 + 2 + 2 0 EOF count=`jexec ${jname} netstat -s -p ip6 -I ${ifname} --libxo xml,pretty | grep -E -x -c -f ${HOME}/filter-${jname}.txt` @@ -196,8 +196,8 @@ 0 0 0 - 1 - 1 + 2 + 2 0 0 0