11dbefcc0SGleb Smirnoff /*- 21dbefcc0SGleb Smirnoff * Copyright (c) 2015 Gleb Smirnoff <glebius@FreeBSD.org> 31dbefcc0SGleb Smirnoff * Copyright (c) 2015 Adrian Chadd <adrian@FreeBSD.org> 41dbefcc0SGleb Smirnoff * Copyright (c) 1982, 1986, 1988, 1993 51dbefcc0SGleb Smirnoff * The Regents of the University of California. All rights reserved. 61dbefcc0SGleb Smirnoff * 71dbefcc0SGleb Smirnoff * Redistribution and use in source and binary forms, with or without 81dbefcc0SGleb Smirnoff * modification, are permitted provided that the following conditions 91dbefcc0SGleb Smirnoff * are met: 101dbefcc0SGleb Smirnoff * 1. Redistributions of source code must retain the above copyright 111dbefcc0SGleb Smirnoff * notice, this list of conditions and the following disclaimer. 121dbefcc0SGleb Smirnoff * 2. Redistributions in binary form must reproduce the above copyright 131dbefcc0SGleb Smirnoff * notice, this list of conditions and the following disclaimer in the 141dbefcc0SGleb Smirnoff * documentation and/or other materials provided with the distribution. 15fbbd9655SWarner Losh * 3. Neither the name of the University nor the names of its contributors 161dbefcc0SGleb Smirnoff * may be used to endorse or promote products derived from this software 171dbefcc0SGleb Smirnoff * without specific prior written permission. 181dbefcc0SGleb Smirnoff * 191dbefcc0SGleb Smirnoff * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 201dbefcc0SGleb Smirnoff * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 211dbefcc0SGleb Smirnoff * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 221dbefcc0SGleb Smirnoff * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 231dbefcc0SGleb Smirnoff * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 241dbefcc0SGleb Smirnoff * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 251dbefcc0SGleb Smirnoff * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 261dbefcc0SGleb Smirnoff * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 271dbefcc0SGleb Smirnoff * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 281dbefcc0SGleb Smirnoff * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 291dbefcc0SGleb Smirnoff * SUCH DAMAGE. 301dbefcc0SGleb Smirnoff * 311dbefcc0SGleb Smirnoff * @(#)ip_input.c 8.2 (Berkeley) 1/4/94 321dbefcc0SGleb Smirnoff */ 331dbefcc0SGleb Smirnoff 341dbefcc0SGleb Smirnoff #include <sys/cdefs.h> 351dbefcc0SGleb Smirnoff __FBSDID("$FreeBSD$"); 361dbefcc0SGleb Smirnoff 371dbefcc0SGleb Smirnoff #include "opt_rss.h" 381dbefcc0SGleb Smirnoff 391dbefcc0SGleb Smirnoff #include <sys/param.h> 401dbefcc0SGleb Smirnoff #include <sys/systm.h> 411dbefcc0SGleb Smirnoff #include <sys/eventhandler.h> 42c047fd1bSGleb Smirnoff #include <sys/hash.h> 431dbefcc0SGleb Smirnoff #include <sys/mbuf.h> 441dbefcc0SGleb Smirnoff #include <sys/malloc.h> 451dbefcc0SGleb Smirnoff #include <sys/lock.h> 461dbefcc0SGleb Smirnoff #include <sys/mutex.h> 471dbefcc0SGleb Smirnoff #include <sys/sysctl.h> 481dbefcc0SGleb Smirnoff 491dbefcc0SGleb Smirnoff #include <net/rss_config.h> 503e217461SAdrian Chadd #include <net/netisr.h> 511dbefcc0SGleb Smirnoff #include <net/vnet.h> 521dbefcc0SGleb Smirnoff 531dbefcc0SGleb Smirnoff #include <netinet/in.h> 541dbefcc0SGleb Smirnoff #include <netinet/ip.h> 551dbefcc0SGleb Smirnoff #include <netinet/ip_var.h> 561dbefcc0SGleb Smirnoff #include <netinet/in_rss.h> 571dbefcc0SGleb Smirnoff #ifdef MAC 581dbefcc0SGleb Smirnoff #include <security/mac/mac_framework.h> 591dbefcc0SGleb Smirnoff #endif 601dbefcc0SGleb Smirnoff 611dbefcc0SGleb Smirnoff SYSCTL_DECL(_net_inet_ip); 621dbefcc0SGleb Smirnoff 631dbefcc0SGleb Smirnoff /* 641dbefcc0SGleb Smirnoff * Reassembly headers are stored in hash buckets. 651dbefcc0SGleb Smirnoff */ 661dbefcc0SGleb Smirnoff #define IPREASS_NHASH_LOG2 6 671dbefcc0SGleb Smirnoff #define IPREASS_NHASH (1 << IPREASS_NHASH_LOG2) 681dbefcc0SGleb Smirnoff #define IPREASS_HMASK (IPREASS_NHASH - 1) 691dbefcc0SGleb Smirnoff 701dbefcc0SGleb Smirnoff struct ipqbucket { 711dbefcc0SGleb Smirnoff TAILQ_HEAD(ipqhead, ipq) head; 721dbefcc0SGleb Smirnoff struct mtx lock; 731dbefcc0SGleb Smirnoff }; 741dbefcc0SGleb Smirnoff 755f901c92SAndrew Turner VNET_DEFINE_STATIC(struct ipqbucket, ipq[IPREASS_NHASH]); 761dbefcc0SGleb Smirnoff #define V_ipq VNET(ipq) 775f901c92SAndrew Turner VNET_DEFINE_STATIC(uint32_t, ipq_hashseed); 78c047fd1bSGleb Smirnoff #define V_ipq_hashseed VNET(ipq_hashseed) 791dbefcc0SGleb Smirnoff 801dbefcc0SGleb Smirnoff #define IPQ_LOCK(i) mtx_lock(&V_ipq[i].lock) 811dbefcc0SGleb Smirnoff #define IPQ_TRYLOCK(i) mtx_trylock(&V_ipq[i].lock) 821dbefcc0SGleb Smirnoff #define IPQ_UNLOCK(i) mtx_unlock(&V_ipq[i].lock) 831dbefcc0SGleb Smirnoff #define IPQ_LOCK_ASSERT(i) mtx_assert(&V_ipq[i].lock, MA_OWNED) 841dbefcc0SGleb Smirnoff 851dbefcc0SGleb Smirnoff void ipreass_init(void); 861dbefcc0SGleb Smirnoff void ipreass_drain(void); 871dbefcc0SGleb Smirnoff void ipreass_slowtimo(void); 881dbefcc0SGleb Smirnoff #ifdef VIMAGE 891dbefcc0SGleb Smirnoff void ipreass_destroy(void); 901dbefcc0SGleb Smirnoff #endif 911dbefcc0SGleb Smirnoff static int sysctl_maxfragpackets(SYSCTL_HANDLER_ARGS); 921dbefcc0SGleb Smirnoff static void ipreass_zone_change(void *); 931dbefcc0SGleb Smirnoff static void ipreass_drain_tomax(void); 941dbefcc0SGleb Smirnoff static void ipq_free(struct ipqhead *, struct ipq *); 951dbefcc0SGleb Smirnoff static struct ipq * ipq_reuse(int); 961dbefcc0SGleb Smirnoff 971dbefcc0SGleb Smirnoff static inline void 981dbefcc0SGleb Smirnoff ipq_timeout(struct ipqhead *head, struct ipq *fp) 991dbefcc0SGleb Smirnoff { 1001dbefcc0SGleb Smirnoff 1011dbefcc0SGleb Smirnoff IPSTAT_ADD(ips_fragtimeout, fp->ipq_nfrags); 1021dbefcc0SGleb Smirnoff ipq_free(head, fp); 1031dbefcc0SGleb Smirnoff } 1041dbefcc0SGleb Smirnoff 1051dbefcc0SGleb Smirnoff static inline void 1061dbefcc0SGleb Smirnoff ipq_drop(struct ipqhead *head, struct ipq *fp) 1071dbefcc0SGleb Smirnoff { 1081dbefcc0SGleb Smirnoff 1091dbefcc0SGleb Smirnoff IPSTAT_ADD(ips_fragdropped, fp->ipq_nfrags); 1101dbefcc0SGleb Smirnoff ipq_free(head, fp); 1111dbefcc0SGleb Smirnoff } 1121dbefcc0SGleb Smirnoff 1135f901c92SAndrew Turner VNET_DEFINE_STATIC(uma_zone_t, ipq_zone); 1141dbefcc0SGleb Smirnoff #define V_ipq_zone VNET(ipq_zone) 1151dbefcc0SGleb Smirnoff SYSCTL_PROC(_net_inet_ip, OID_AUTO, maxfragpackets, CTLFLAG_VNET | 1161dbefcc0SGleb Smirnoff CTLTYPE_INT | CTLFLAG_RW, NULL, 0, sysctl_maxfragpackets, "I", 1171dbefcc0SGleb Smirnoff "Maximum number of IPv4 fragment reassembly queue entries"); 1181dbefcc0SGleb Smirnoff SYSCTL_UMA_CUR(_net_inet_ip, OID_AUTO, fragpackets, CTLFLAG_VNET, 1191dbefcc0SGleb Smirnoff &VNET_NAME(ipq_zone), 1201dbefcc0SGleb Smirnoff "Current number of IPv4 fragment reassembly queue entries"); 1211dbefcc0SGleb Smirnoff 1225f901c92SAndrew Turner VNET_DEFINE_STATIC(int, noreass); 1231dbefcc0SGleb Smirnoff #define V_noreass VNET(noreass) 1241dbefcc0SGleb Smirnoff 1255f901c92SAndrew Turner VNET_DEFINE_STATIC(int, maxfragsperpacket); 1261dbefcc0SGleb Smirnoff #define V_maxfragsperpacket VNET(maxfragsperpacket) 1271dbefcc0SGleb Smirnoff SYSCTL_INT(_net_inet_ip, OID_AUTO, maxfragsperpacket, CTLFLAG_VNET | CTLFLAG_RW, 1281dbefcc0SGleb Smirnoff &VNET_NAME(maxfragsperpacket), 0, 1291dbefcc0SGleb Smirnoff "Maximum number of IPv4 fragments allowed per packet"); 1301dbefcc0SGleb Smirnoff 1311dbefcc0SGleb Smirnoff /* 1321dbefcc0SGleb Smirnoff * Take incoming datagram fragment and try to reassemble it into 1331dbefcc0SGleb Smirnoff * whole datagram. If the argument is the first fragment or one 1341dbefcc0SGleb Smirnoff * in between the function will return NULL and store the mbuf 1351dbefcc0SGleb Smirnoff * in the fragment chain. If the argument is the last fragment 1361dbefcc0SGleb Smirnoff * the packet will be reassembled and the pointer to the new 1371dbefcc0SGleb Smirnoff * mbuf returned for further processing. Only m_tags attached 1381dbefcc0SGleb Smirnoff * to the first packet/fragment are preserved. 1391dbefcc0SGleb Smirnoff * The IP header is *NOT* adjusted out of iplen. 1401dbefcc0SGleb Smirnoff */ 1411dbefcc0SGleb Smirnoff #define M_IP_FRAG M_PROTO9 1421dbefcc0SGleb Smirnoff struct mbuf * 1431dbefcc0SGleb Smirnoff ip_reass(struct mbuf *m) 1441dbefcc0SGleb Smirnoff { 1451dbefcc0SGleb Smirnoff struct ip *ip; 1461dbefcc0SGleb Smirnoff struct mbuf *p, *q, *nq, *t; 1471dbefcc0SGleb Smirnoff struct ipq *fp; 1481dbefcc0SGleb Smirnoff struct ipqhead *head; 1491dbefcc0SGleb Smirnoff int i, hlen, next; 1501dbefcc0SGleb Smirnoff u_int8_t ecn, ecn0; 1515d9bd455SJonathan T. Looney uint32_t hash, hashkey[3]; 1521dbefcc0SGleb Smirnoff #ifdef RSS 1531dbefcc0SGleb Smirnoff uint32_t rss_hash, rss_type; 1541dbefcc0SGleb Smirnoff #endif 1551dbefcc0SGleb Smirnoff 1561dbefcc0SGleb Smirnoff /* 1571dbefcc0SGleb Smirnoff * If no reassembling or maxfragsperpacket are 0, 1581dbefcc0SGleb Smirnoff * never accept fragments. 1591dbefcc0SGleb Smirnoff */ 1601dbefcc0SGleb Smirnoff if (V_noreass == 1 || V_maxfragsperpacket == 0) { 1611dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragments); 1621dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragdropped); 1631dbefcc0SGleb Smirnoff m_freem(m); 1641dbefcc0SGleb Smirnoff return (NULL); 1651dbefcc0SGleb Smirnoff } 1661dbefcc0SGleb Smirnoff 1671dbefcc0SGleb Smirnoff ip = mtod(m, struct ip *); 1681dbefcc0SGleb Smirnoff hlen = ip->ip_hl << 2; 1691dbefcc0SGleb Smirnoff 1701dbefcc0SGleb Smirnoff /* 1711dbefcc0SGleb Smirnoff * Adjust ip_len to not reflect header, 1721dbefcc0SGleb Smirnoff * convert offset of this to bytes. 1731dbefcc0SGleb Smirnoff */ 1741dbefcc0SGleb Smirnoff ip->ip_len = htons(ntohs(ip->ip_len) - hlen); 1751dbefcc0SGleb Smirnoff if (ip->ip_off & htons(IP_MF)) { 1761dbefcc0SGleb Smirnoff /* 1771dbefcc0SGleb Smirnoff * Make sure that fragments have a data length 1781dbefcc0SGleb Smirnoff * that's a non-zero multiple of 8 bytes. 1791dbefcc0SGleb Smirnoff */ 1801dbefcc0SGleb Smirnoff if (ip->ip_len == htons(0) || (ntohs(ip->ip_len) & 0x7) != 0) { 1811dbefcc0SGleb Smirnoff IPSTAT_INC(ips_toosmall); /* XXX */ 1821dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragdropped); 1831dbefcc0SGleb Smirnoff m_freem(m); 1841dbefcc0SGleb Smirnoff return (NULL); 1851dbefcc0SGleb Smirnoff } 1861dbefcc0SGleb Smirnoff m->m_flags |= M_IP_FRAG; 1871dbefcc0SGleb Smirnoff } else 1881dbefcc0SGleb Smirnoff m->m_flags &= ~M_IP_FRAG; 1891dbefcc0SGleb Smirnoff ip->ip_off = htons(ntohs(ip->ip_off) << 3); 1901dbefcc0SGleb Smirnoff 1911dbefcc0SGleb Smirnoff /* 1921dbefcc0SGleb Smirnoff * Attempt reassembly; if it succeeds, proceed. 1931dbefcc0SGleb Smirnoff * ip_reass() will return a different mbuf. 1941dbefcc0SGleb Smirnoff */ 1951dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragments); 1961dbefcc0SGleb Smirnoff m->m_pkthdr.PH_loc.ptr = ip; 1971dbefcc0SGleb Smirnoff 1981dbefcc0SGleb Smirnoff /* 1991dbefcc0SGleb Smirnoff * Presence of header sizes in mbufs 2001dbefcc0SGleb Smirnoff * would confuse code below. 2011dbefcc0SGleb Smirnoff */ 2021dbefcc0SGleb Smirnoff m->m_data += hlen; 2031dbefcc0SGleb Smirnoff m->m_len -= hlen; 2041dbefcc0SGleb Smirnoff 2055d9bd455SJonathan T. Looney hashkey[0] = ip->ip_src.s_addr; 2065d9bd455SJonathan T. Looney hashkey[1] = ip->ip_dst.s_addr; 2075d9bd455SJonathan T. Looney hashkey[2] = (uint32_t)ip->ip_p << 16; 2085d9bd455SJonathan T. Looney hashkey[2] += ip->ip_id; 2095d9bd455SJonathan T. Looney hash = jenkins_hash32(hashkey, nitems(hashkey), V_ipq_hashseed); 2105d9bd455SJonathan T. Looney hash &= IPREASS_HMASK; 2111dbefcc0SGleb Smirnoff head = &V_ipq[hash].head; 2121dbefcc0SGleb Smirnoff IPQ_LOCK(hash); 2131dbefcc0SGleb Smirnoff 2141dbefcc0SGleb Smirnoff /* 2151dbefcc0SGleb Smirnoff * Look for queue of fragments 2161dbefcc0SGleb Smirnoff * of this datagram. 2171dbefcc0SGleb Smirnoff */ 2181dbefcc0SGleb Smirnoff TAILQ_FOREACH(fp, head, ipq_list) 2191dbefcc0SGleb Smirnoff if (ip->ip_id == fp->ipq_id && 2201dbefcc0SGleb Smirnoff ip->ip_src.s_addr == fp->ipq_src.s_addr && 2211dbefcc0SGleb Smirnoff ip->ip_dst.s_addr == fp->ipq_dst.s_addr && 2221dbefcc0SGleb Smirnoff #ifdef MAC 2231dbefcc0SGleb Smirnoff mac_ipq_match(m, fp) && 2241dbefcc0SGleb Smirnoff #endif 2251dbefcc0SGleb Smirnoff ip->ip_p == fp->ipq_p) 2261dbefcc0SGleb Smirnoff break; 2271dbefcc0SGleb Smirnoff /* 2281dbefcc0SGleb Smirnoff * If first fragment to arrive, create a reassembly queue. 2291dbefcc0SGleb Smirnoff */ 2301dbefcc0SGleb Smirnoff if (fp == NULL) { 2311dbefcc0SGleb Smirnoff fp = uma_zalloc(V_ipq_zone, M_NOWAIT); 2321dbefcc0SGleb Smirnoff if (fp == NULL) 2331dbefcc0SGleb Smirnoff fp = ipq_reuse(hash); 2341dbefcc0SGleb Smirnoff #ifdef MAC 2351dbefcc0SGleb Smirnoff if (mac_ipq_init(fp, M_NOWAIT) != 0) { 2361dbefcc0SGleb Smirnoff uma_zfree(V_ipq_zone, fp); 2371dbefcc0SGleb Smirnoff fp = NULL; 2381dbefcc0SGleb Smirnoff goto dropfrag; 2391dbefcc0SGleb Smirnoff } 2401dbefcc0SGleb Smirnoff mac_ipq_create(m, fp); 2411dbefcc0SGleb Smirnoff #endif 2421dbefcc0SGleb Smirnoff TAILQ_INSERT_HEAD(head, fp, ipq_list); 2431dbefcc0SGleb Smirnoff fp->ipq_nfrags = 1; 2441dbefcc0SGleb Smirnoff fp->ipq_ttl = IPFRAGTTL; 2451dbefcc0SGleb Smirnoff fp->ipq_p = ip->ip_p; 2461dbefcc0SGleb Smirnoff fp->ipq_id = ip->ip_id; 2471dbefcc0SGleb Smirnoff fp->ipq_src = ip->ip_src; 2481dbefcc0SGleb Smirnoff fp->ipq_dst = ip->ip_dst; 2491dbefcc0SGleb Smirnoff fp->ipq_frags = m; 2501dbefcc0SGleb Smirnoff m->m_nextpkt = NULL; 2511dbefcc0SGleb Smirnoff goto done; 2521dbefcc0SGleb Smirnoff } else { 2531dbefcc0SGleb Smirnoff fp->ipq_nfrags++; 2541dbefcc0SGleb Smirnoff #ifdef MAC 2551dbefcc0SGleb Smirnoff mac_ipq_update(m, fp); 2561dbefcc0SGleb Smirnoff #endif 2571dbefcc0SGleb Smirnoff } 2581dbefcc0SGleb Smirnoff 2591dbefcc0SGleb Smirnoff #define GETIP(m) ((struct ip*)((m)->m_pkthdr.PH_loc.ptr)) 2601dbefcc0SGleb Smirnoff 2611dbefcc0SGleb Smirnoff /* 2621dbefcc0SGleb Smirnoff * Handle ECN by comparing this segment with the first one; 2631dbefcc0SGleb Smirnoff * if CE is set, do not lose CE. 2641dbefcc0SGleb Smirnoff * drop if CE and not-ECT are mixed for the same packet. 2651dbefcc0SGleb Smirnoff */ 2661dbefcc0SGleb Smirnoff ecn = ip->ip_tos & IPTOS_ECN_MASK; 2671dbefcc0SGleb Smirnoff ecn0 = GETIP(fp->ipq_frags)->ip_tos & IPTOS_ECN_MASK; 2681dbefcc0SGleb Smirnoff if (ecn == IPTOS_ECN_CE) { 2691dbefcc0SGleb Smirnoff if (ecn0 == IPTOS_ECN_NOTECT) 2701dbefcc0SGleb Smirnoff goto dropfrag; 2711dbefcc0SGleb Smirnoff if (ecn0 != IPTOS_ECN_CE) 2721dbefcc0SGleb Smirnoff GETIP(fp->ipq_frags)->ip_tos |= IPTOS_ECN_CE; 2731dbefcc0SGleb Smirnoff } 2741dbefcc0SGleb Smirnoff if (ecn == IPTOS_ECN_NOTECT && ecn0 != IPTOS_ECN_NOTECT) 2751dbefcc0SGleb Smirnoff goto dropfrag; 2761dbefcc0SGleb Smirnoff 2771dbefcc0SGleb Smirnoff /* 2781dbefcc0SGleb Smirnoff * Find a segment which begins after this one does. 2791dbefcc0SGleb Smirnoff */ 2801dbefcc0SGleb Smirnoff for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt) 2811dbefcc0SGleb Smirnoff if (ntohs(GETIP(q)->ip_off) > ntohs(ip->ip_off)) 2821dbefcc0SGleb Smirnoff break; 2831dbefcc0SGleb Smirnoff 2841dbefcc0SGleb Smirnoff /* 2851dbefcc0SGleb Smirnoff * If there is a preceding segment, it may provide some of 2861dbefcc0SGleb Smirnoff * our data already. If so, drop the data from the incoming 2871dbefcc0SGleb Smirnoff * segment. If it provides all of our data, drop us, otherwise 2881dbefcc0SGleb Smirnoff * stick new segment in the proper place. 2891dbefcc0SGleb Smirnoff * 2901dbefcc0SGleb Smirnoff * If some of the data is dropped from the preceding 2911dbefcc0SGleb Smirnoff * segment, then it's checksum is invalidated. 2921dbefcc0SGleb Smirnoff */ 2931dbefcc0SGleb Smirnoff if (p) { 2941dbefcc0SGleb Smirnoff i = ntohs(GETIP(p)->ip_off) + ntohs(GETIP(p)->ip_len) - 2951dbefcc0SGleb Smirnoff ntohs(ip->ip_off); 2961dbefcc0SGleb Smirnoff if (i > 0) { 2971dbefcc0SGleb Smirnoff if (i >= ntohs(ip->ip_len)) 2981dbefcc0SGleb Smirnoff goto dropfrag; 2991dbefcc0SGleb Smirnoff m_adj(m, i); 3001dbefcc0SGleb Smirnoff m->m_pkthdr.csum_flags = 0; 3011dbefcc0SGleb Smirnoff ip->ip_off = htons(ntohs(ip->ip_off) + i); 3021dbefcc0SGleb Smirnoff ip->ip_len = htons(ntohs(ip->ip_len) - i); 3031dbefcc0SGleb Smirnoff } 3041dbefcc0SGleb Smirnoff m->m_nextpkt = p->m_nextpkt; 3051dbefcc0SGleb Smirnoff p->m_nextpkt = m; 3061dbefcc0SGleb Smirnoff } else { 3071dbefcc0SGleb Smirnoff m->m_nextpkt = fp->ipq_frags; 3081dbefcc0SGleb Smirnoff fp->ipq_frags = m; 3091dbefcc0SGleb Smirnoff } 3101dbefcc0SGleb Smirnoff 3111dbefcc0SGleb Smirnoff /* 3121dbefcc0SGleb Smirnoff * While we overlap succeeding segments trim them or, 3131dbefcc0SGleb Smirnoff * if they are completely covered, dequeue them. 3141dbefcc0SGleb Smirnoff */ 3151dbefcc0SGleb Smirnoff for (; q != NULL && ntohs(ip->ip_off) + ntohs(ip->ip_len) > 3161dbefcc0SGleb Smirnoff ntohs(GETIP(q)->ip_off); q = nq) { 3171dbefcc0SGleb Smirnoff i = (ntohs(ip->ip_off) + ntohs(ip->ip_len)) - 3181dbefcc0SGleb Smirnoff ntohs(GETIP(q)->ip_off); 3191dbefcc0SGleb Smirnoff if (i < ntohs(GETIP(q)->ip_len)) { 3201dbefcc0SGleb Smirnoff GETIP(q)->ip_len = htons(ntohs(GETIP(q)->ip_len) - i); 3211dbefcc0SGleb Smirnoff GETIP(q)->ip_off = htons(ntohs(GETIP(q)->ip_off) + i); 3221dbefcc0SGleb Smirnoff m_adj(q, i); 3231dbefcc0SGleb Smirnoff q->m_pkthdr.csum_flags = 0; 3241dbefcc0SGleb Smirnoff break; 3251dbefcc0SGleb Smirnoff } 3261dbefcc0SGleb Smirnoff nq = q->m_nextpkt; 3271dbefcc0SGleb Smirnoff m->m_nextpkt = nq; 3281dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragdropped); 3291dbefcc0SGleb Smirnoff fp->ipq_nfrags--; 3301dbefcc0SGleb Smirnoff m_freem(q); 3311dbefcc0SGleb Smirnoff } 3321dbefcc0SGleb Smirnoff 3331dbefcc0SGleb Smirnoff /* 3341dbefcc0SGleb Smirnoff * Check for complete reassembly and perform frag per packet 3351dbefcc0SGleb Smirnoff * limiting. 3361dbefcc0SGleb Smirnoff * 3371dbefcc0SGleb Smirnoff * Frag limiting is performed here so that the nth frag has 3381dbefcc0SGleb Smirnoff * a chance to complete the packet before we drop the packet. 3391dbefcc0SGleb Smirnoff * As a result, n+1 frags are actually allowed per packet, but 3401dbefcc0SGleb Smirnoff * only n will ever be stored. (n = maxfragsperpacket.) 3411dbefcc0SGleb Smirnoff * 3421dbefcc0SGleb Smirnoff */ 3431dbefcc0SGleb Smirnoff next = 0; 3441dbefcc0SGleb Smirnoff for (p = NULL, q = fp->ipq_frags; q; p = q, q = q->m_nextpkt) { 3451dbefcc0SGleb Smirnoff if (ntohs(GETIP(q)->ip_off) != next) { 3461dbefcc0SGleb Smirnoff if (fp->ipq_nfrags > V_maxfragsperpacket) 3471dbefcc0SGleb Smirnoff ipq_drop(head, fp); 3481dbefcc0SGleb Smirnoff goto done; 3491dbefcc0SGleb Smirnoff } 3501dbefcc0SGleb Smirnoff next += ntohs(GETIP(q)->ip_len); 3511dbefcc0SGleb Smirnoff } 3521dbefcc0SGleb Smirnoff /* Make sure the last packet didn't have the IP_MF flag */ 3531dbefcc0SGleb Smirnoff if (p->m_flags & M_IP_FRAG) { 3541dbefcc0SGleb Smirnoff if (fp->ipq_nfrags > V_maxfragsperpacket) 3551dbefcc0SGleb Smirnoff ipq_drop(head, fp); 3561dbefcc0SGleb Smirnoff goto done; 3571dbefcc0SGleb Smirnoff } 3581dbefcc0SGleb Smirnoff 3591dbefcc0SGleb Smirnoff /* 3601dbefcc0SGleb Smirnoff * Reassembly is complete. Make sure the packet is a sane size. 3611dbefcc0SGleb Smirnoff */ 3621dbefcc0SGleb Smirnoff q = fp->ipq_frags; 3631dbefcc0SGleb Smirnoff ip = GETIP(q); 3641dbefcc0SGleb Smirnoff if (next + (ip->ip_hl << 2) > IP_MAXPACKET) { 3651dbefcc0SGleb Smirnoff IPSTAT_INC(ips_toolong); 3661dbefcc0SGleb Smirnoff ipq_drop(head, fp); 3671dbefcc0SGleb Smirnoff goto done; 3681dbefcc0SGleb Smirnoff } 3691dbefcc0SGleb Smirnoff 3701dbefcc0SGleb Smirnoff /* 3711dbefcc0SGleb Smirnoff * Concatenate fragments. 3721dbefcc0SGleb Smirnoff */ 3731dbefcc0SGleb Smirnoff m = q; 3741dbefcc0SGleb Smirnoff t = m->m_next; 3751dbefcc0SGleb Smirnoff m->m_next = NULL; 3761dbefcc0SGleb Smirnoff m_cat(m, t); 3771dbefcc0SGleb Smirnoff nq = q->m_nextpkt; 3781dbefcc0SGleb Smirnoff q->m_nextpkt = NULL; 3791dbefcc0SGleb Smirnoff for (q = nq; q != NULL; q = nq) { 3801dbefcc0SGleb Smirnoff nq = q->m_nextpkt; 3811dbefcc0SGleb Smirnoff q->m_nextpkt = NULL; 3821dbefcc0SGleb Smirnoff m->m_pkthdr.csum_flags &= q->m_pkthdr.csum_flags; 3831dbefcc0SGleb Smirnoff m->m_pkthdr.csum_data += q->m_pkthdr.csum_data; 38409b0b8c0SNavdeep Parhar m_demote_pkthdr(q); 3851dbefcc0SGleb Smirnoff m_cat(m, q); 3861dbefcc0SGleb Smirnoff } 3871dbefcc0SGleb Smirnoff /* 3881dbefcc0SGleb Smirnoff * In order to do checksumming faster we do 'end-around carry' here 3891dbefcc0SGleb Smirnoff * (and not in for{} loop), though it implies we are not going to 3901dbefcc0SGleb Smirnoff * reassemble more than 64k fragments. 3911dbefcc0SGleb Smirnoff */ 3921dbefcc0SGleb Smirnoff while (m->m_pkthdr.csum_data & 0xffff0000) 3931dbefcc0SGleb Smirnoff m->m_pkthdr.csum_data = (m->m_pkthdr.csum_data & 0xffff) + 3941dbefcc0SGleb Smirnoff (m->m_pkthdr.csum_data >> 16); 3951dbefcc0SGleb Smirnoff #ifdef MAC 3961dbefcc0SGleb Smirnoff mac_ipq_reassemble(fp, m); 3971dbefcc0SGleb Smirnoff mac_ipq_destroy(fp); 3981dbefcc0SGleb Smirnoff #endif 3991dbefcc0SGleb Smirnoff 4001dbefcc0SGleb Smirnoff /* 4011dbefcc0SGleb Smirnoff * Create header for new ip packet by modifying header of first 4021dbefcc0SGleb Smirnoff * packet; dequeue and discard fragment reassembly header. 4031dbefcc0SGleb Smirnoff * Make header visible. 4041dbefcc0SGleb Smirnoff */ 4051dbefcc0SGleb Smirnoff ip->ip_len = htons((ip->ip_hl << 2) + next); 4061dbefcc0SGleb Smirnoff ip->ip_src = fp->ipq_src; 4071dbefcc0SGleb Smirnoff ip->ip_dst = fp->ipq_dst; 4081dbefcc0SGleb Smirnoff TAILQ_REMOVE(head, fp, ipq_list); 4091dbefcc0SGleb Smirnoff uma_zfree(V_ipq_zone, fp); 4101dbefcc0SGleb Smirnoff m->m_len += (ip->ip_hl << 2); 4111dbefcc0SGleb Smirnoff m->m_data -= (ip->ip_hl << 2); 4121dbefcc0SGleb Smirnoff /* some debugging cruft by sklower, below, will go away soon */ 4131dbefcc0SGleb Smirnoff if (m->m_flags & M_PKTHDR) /* XXX this should be done elsewhere */ 4141dbefcc0SGleb Smirnoff m_fixhdr(m); 4151dbefcc0SGleb Smirnoff IPSTAT_INC(ips_reassembled); 4161dbefcc0SGleb Smirnoff IPQ_UNLOCK(hash); 4171dbefcc0SGleb Smirnoff 4181dbefcc0SGleb Smirnoff #ifdef RSS 4191dbefcc0SGleb Smirnoff /* 4201dbefcc0SGleb Smirnoff * Query the RSS layer for the flowid / flowtype for the 4211dbefcc0SGleb Smirnoff * mbuf payload. 4221dbefcc0SGleb Smirnoff * 4231dbefcc0SGleb Smirnoff * For now, just assume we have to calculate a new one. 4241dbefcc0SGleb Smirnoff * Later on we should check to see if the assigned flowid matches 4251dbefcc0SGleb Smirnoff * what RSS wants for the given IP protocol and if so, just keep it. 4261dbefcc0SGleb Smirnoff * 4271dbefcc0SGleb Smirnoff * We then queue into the relevant netisr so it can be dispatched 4281dbefcc0SGleb Smirnoff * to the correct CPU. 4291dbefcc0SGleb Smirnoff * 4301dbefcc0SGleb Smirnoff * Note - this may return 1, which means the flowid in the mbuf 4311dbefcc0SGleb Smirnoff * is correct for the configured RSS hash types and can be used. 4321dbefcc0SGleb Smirnoff */ 4331dbefcc0SGleb Smirnoff if (rss_mbuf_software_hash_v4(m, 0, &rss_hash, &rss_type) == 0) { 4341dbefcc0SGleb Smirnoff m->m_pkthdr.flowid = rss_hash; 4351dbefcc0SGleb Smirnoff M_HASHTYPE_SET(m, rss_type); 4361dbefcc0SGleb Smirnoff } 4371dbefcc0SGleb Smirnoff 4381dbefcc0SGleb Smirnoff /* 4391dbefcc0SGleb Smirnoff * Queue/dispatch for reprocessing. 4401dbefcc0SGleb Smirnoff * 4411dbefcc0SGleb Smirnoff * Note: this is much slower than just handling the frame in the 4421dbefcc0SGleb Smirnoff * current receive context. It's likely worth investigating 4431dbefcc0SGleb Smirnoff * why this is. 4441dbefcc0SGleb Smirnoff */ 4451dbefcc0SGleb Smirnoff netisr_dispatch(NETISR_IP_DIRECT, m); 4461dbefcc0SGleb Smirnoff return (NULL); 4471dbefcc0SGleb Smirnoff #endif 4481dbefcc0SGleb Smirnoff 4491dbefcc0SGleb Smirnoff /* Handle in-line */ 4501dbefcc0SGleb Smirnoff return (m); 4511dbefcc0SGleb Smirnoff 4521dbefcc0SGleb Smirnoff dropfrag: 4531dbefcc0SGleb Smirnoff IPSTAT_INC(ips_fragdropped); 4541dbefcc0SGleb Smirnoff if (fp != NULL) 4551dbefcc0SGleb Smirnoff fp->ipq_nfrags--; 4561dbefcc0SGleb Smirnoff m_freem(m); 4571dbefcc0SGleb Smirnoff done: 4581dbefcc0SGleb Smirnoff IPQ_UNLOCK(hash); 4591dbefcc0SGleb Smirnoff return (NULL); 4601dbefcc0SGleb Smirnoff 4611dbefcc0SGleb Smirnoff #undef GETIP 4621dbefcc0SGleb Smirnoff } 4631dbefcc0SGleb Smirnoff 4641dbefcc0SGleb Smirnoff /* 4651dbefcc0SGleb Smirnoff * Initialize IP reassembly structures. 4661dbefcc0SGleb Smirnoff */ 4671dbefcc0SGleb Smirnoff void 4681dbefcc0SGleb Smirnoff ipreass_init(void) 4691dbefcc0SGleb Smirnoff { 4701dbefcc0SGleb Smirnoff 4711dbefcc0SGleb Smirnoff for (int i = 0; i < IPREASS_NHASH; i++) { 4721dbefcc0SGleb Smirnoff TAILQ_INIT(&V_ipq[i].head); 4731dbefcc0SGleb Smirnoff mtx_init(&V_ipq[i].lock, "IP reassembly", NULL, 4741dbefcc0SGleb Smirnoff MTX_DEF | MTX_DUPOK); 4751dbefcc0SGleb Smirnoff } 476c047fd1bSGleb Smirnoff V_ipq_hashseed = arc4random(); 4771dbefcc0SGleb Smirnoff V_maxfragsperpacket = 16; 4781dbefcc0SGleb Smirnoff V_ipq_zone = uma_zcreate("ipq", sizeof(struct ipq), NULL, NULL, NULL, 4791dbefcc0SGleb Smirnoff NULL, UMA_ALIGN_PTR, 0); 4801dbefcc0SGleb Smirnoff uma_zone_set_max(V_ipq_zone, nmbclusters / 32); 4811dbefcc0SGleb Smirnoff 4821dbefcc0SGleb Smirnoff if (IS_DEFAULT_VNET(curvnet)) 4831dbefcc0SGleb Smirnoff EVENTHANDLER_REGISTER(nmbclusters_change, ipreass_zone_change, 4841dbefcc0SGleb Smirnoff NULL, EVENTHANDLER_PRI_ANY); 4851dbefcc0SGleb Smirnoff } 4861dbefcc0SGleb Smirnoff 4871dbefcc0SGleb Smirnoff /* 4881dbefcc0SGleb Smirnoff * If a timer expires on a reassembly queue, discard it. 4891dbefcc0SGleb Smirnoff */ 4901dbefcc0SGleb Smirnoff void 4911dbefcc0SGleb Smirnoff ipreass_slowtimo(void) 4921dbefcc0SGleb Smirnoff { 4931dbefcc0SGleb Smirnoff struct ipq *fp, *tmp; 4941dbefcc0SGleb Smirnoff 4951dbefcc0SGleb Smirnoff for (int i = 0; i < IPREASS_NHASH; i++) { 4961dbefcc0SGleb Smirnoff IPQ_LOCK(i); 4971dbefcc0SGleb Smirnoff TAILQ_FOREACH_SAFE(fp, &V_ipq[i].head, ipq_list, tmp) 4981dbefcc0SGleb Smirnoff if (--fp->ipq_ttl == 0) 4991dbefcc0SGleb Smirnoff ipq_timeout(&V_ipq[i].head, fp); 5001dbefcc0SGleb Smirnoff IPQ_UNLOCK(i); 5011dbefcc0SGleb Smirnoff } 5021dbefcc0SGleb Smirnoff } 5031dbefcc0SGleb Smirnoff 5041dbefcc0SGleb Smirnoff /* 5051dbefcc0SGleb Smirnoff * Drain off all datagram fragments. 5061dbefcc0SGleb Smirnoff */ 5071dbefcc0SGleb Smirnoff void 5081dbefcc0SGleb Smirnoff ipreass_drain(void) 5091dbefcc0SGleb Smirnoff { 5101dbefcc0SGleb Smirnoff 5111dbefcc0SGleb Smirnoff for (int i = 0; i < IPREASS_NHASH; i++) { 5121dbefcc0SGleb Smirnoff IPQ_LOCK(i); 5131dbefcc0SGleb Smirnoff while(!TAILQ_EMPTY(&V_ipq[i].head)) 5141dbefcc0SGleb Smirnoff ipq_drop(&V_ipq[i].head, TAILQ_FIRST(&V_ipq[i].head)); 5151dbefcc0SGleb Smirnoff IPQ_UNLOCK(i); 5161dbefcc0SGleb Smirnoff } 5171dbefcc0SGleb Smirnoff } 5181dbefcc0SGleb Smirnoff 5191dbefcc0SGleb Smirnoff #ifdef VIMAGE 5201dbefcc0SGleb Smirnoff /* 5211dbefcc0SGleb Smirnoff * Destroy IP reassembly structures. 5221dbefcc0SGleb Smirnoff */ 5231dbefcc0SGleb Smirnoff void 5241dbefcc0SGleb Smirnoff ipreass_destroy(void) 5251dbefcc0SGleb Smirnoff { 5261dbefcc0SGleb Smirnoff 5271dbefcc0SGleb Smirnoff ipreass_drain(); 5281dbefcc0SGleb Smirnoff uma_zdestroy(V_ipq_zone); 5291dbefcc0SGleb Smirnoff for (int i = 0; i < IPREASS_NHASH; i++) 5301dbefcc0SGleb Smirnoff mtx_destroy(&V_ipq[i].lock); 5311dbefcc0SGleb Smirnoff } 5321dbefcc0SGleb Smirnoff #endif 5331dbefcc0SGleb Smirnoff 5341dbefcc0SGleb Smirnoff /* 5351dbefcc0SGleb Smirnoff * After maxnipq has been updated, propagate the change to UMA. The UMA zone 5361dbefcc0SGleb Smirnoff * max has slightly different semantics than the sysctl, for historical 5371dbefcc0SGleb Smirnoff * reasons. 5381dbefcc0SGleb Smirnoff */ 5391dbefcc0SGleb Smirnoff static void 5401dbefcc0SGleb Smirnoff ipreass_drain_tomax(void) 5411dbefcc0SGleb Smirnoff { 5421dbefcc0SGleb Smirnoff int target; 5431dbefcc0SGleb Smirnoff 5441dbefcc0SGleb Smirnoff /* 5451dbefcc0SGleb Smirnoff * If we are over the maximum number of fragments, 5461dbefcc0SGleb Smirnoff * drain off enough to get down to the new limit, 5471dbefcc0SGleb Smirnoff * stripping off last elements on queues. Every 5481dbefcc0SGleb Smirnoff * run we strip the oldest element from each bucket. 5491dbefcc0SGleb Smirnoff */ 5501dbefcc0SGleb Smirnoff target = uma_zone_get_max(V_ipq_zone); 5511dbefcc0SGleb Smirnoff while (uma_zone_get_cur(V_ipq_zone) > target) { 5521dbefcc0SGleb Smirnoff struct ipq *fp; 5531dbefcc0SGleb Smirnoff 5541dbefcc0SGleb Smirnoff for (int i = 0; i < IPREASS_NHASH; i++) { 5551dbefcc0SGleb Smirnoff IPQ_LOCK(i); 5561dbefcc0SGleb Smirnoff fp = TAILQ_LAST(&V_ipq[i].head, ipqhead); 5571dbefcc0SGleb Smirnoff if (fp != NULL) 5581dbefcc0SGleb Smirnoff ipq_timeout(&V_ipq[i].head, fp); 5591dbefcc0SGleb Smirnoff IPQ_UNLOCK(i); 5601dbefcc0SGleb Smirnoff } 5611dbefcc0SGleb Smirnoff } 5621dbefcc0SGleb Smirnoff } 5631dbefcc0SGleb Smirnoff 5641dbefcc0SGleb Smirnoff static void 5651dbefcc0SGleb Smirnoff ipreass_zone_change(void *tag) 5661dbefcc0SGleb Smirnoff { 5671dbefcc0SGleb Smirnoff 5681dbefcc0SGleb Smirnoff uma_zone_set_max(V_ipq_zone, nmbclusters / 32); 5691dbefcc0SGleb Smirnoff ipreass_drain_tomax(); 5701dbefcc0SGleb Smirnoff } 5711dbefcc0SGleb Smirnoff 5721dbefcc0SGleb Smirnoff /* 5731dbefcc0SGleb Smirnoff * Change the limit on the UMA zone, or disable the fragment allocation 5741dbefcc0SGleb Smirnoff * at all. Since 0 and -1 is a special values here, we need our own handler, 5751dbefcc0SGleb Smirnoff * instead of sysctl_handle_uma_zone_max(). 5761dbefcc0SGleb Smirnoff */ 5771dbefcc0SGleb Smirnoff static int 5781dbefcc0SGleb Smirnoff sysctl_maxfragpackets(SYSCTL_HANDLER_ARGS) 5791dbefcc0SGleb Smirnoff { 5801dbefcc0SGleb Smirnoff int error, max; 5811dbefcc0SGleb Smirnoff 5821dbefcc0SGleb Smirnoff if (V_noreass == 0) { 5831dbefcc0SGleb Smirnoff max = uma_zone_get_max(V_ipq_zone); 5841dbefcc0SGleb Smirnoff if (max == 0) 5851dbefcc0SGleb Smirnoff max = -1; 5861dbefcc0SGleb Smirnoff } else 5871dbefcc0SGleb Smirnoff max = 0; 5881dbefcc0SGleb Smirnoff error = sysctl_handle_int(oidp, &max, 0, req); 5891dbefcc0SGleb Smirnoff if (error || !req->newptr) 5901dbefcc0SGleb Smirnoff return (error); 5911dbefcc0SGleb Smirnoff if (max > 0) { 5921dbefcc0SGleb Smirnoff /* 5931dbefcc0SGleb Smirnoff * XXXRW: Might be a good idea to sanity check the argument 5941dbefcc0SGleb Smirnoff * and place an extreme upper bound. 5951dbefcc0SGleb Smirnoff */ 5961dbefcc0SGleb Smirnoff max = uma_zone_set_max(V_ipq_zone, max); 5971dbefcc0SGleb Smirnoff ipreass_drain_tomax(); 5981dbefcc0SGleb Smirnoff V_noreass = 0; 5991dbefcc0SGleb Smirnoff } else if (max == 0) { 6001dbefcc0SGleb Smirnoff V_noreass = 1; 6011dbefcc0SGleb Smirnoff ipreass_drain(); 6021dbefcc0SGleb Smirnoff } else if (max == -1) { 6031dbefcc0SGleb Smirnoff V_noreass = 0; 6041dbefcc0SGleb Smirnoff uma_zone_set_max(V_ipq_zone, 0); 6051dbefcc0SGleb Smirnoff } else 6061dbefcc0SGleb Smirnoff return (EINVAL); 6071dbefcc0SGleb Smirnoff return (0); 6081dbefcc0SGleb Smirnoff } 6091dbefcc0SGleb Smirnoff 6101dbefcc0SGleb Smirnoff /* 6111dbefcc0SGleb Smirnoff * Seek for old fragment queue header that can be reused. Try to 6121dbefcc0SGleb Smirnoff * reuse a header from currently locked hash bucket. 6131dbefcc0SGleb Smirnoff */ 6141dbefcc0SGleb Smirnoff static struct ipq * 6151dbefcc0SGleb Smirnoff ipq_reuse(int start) 6161dbefcc0SGleb Smirnoff { 6171dbefcc0SGleb Smirnoff struct ipq *fp; 6181dbefcc0SGleb Smirnoff int i; 6191dbefcc0SGleb Smirnoff 6201dbefcc0SGleb Smirnoff IPQ_LOCK_ASSERT(start); 6211dbefcc0SGleb Smirnoff 6221dbefcc0SGleb Smirnoff for (i = start;; i++) { 6231dbefcc0SGleb Smirnoff if (i == IPREASS_NHASH) 6241dbefcc0SGleb Smirnoff i = 0; 6251dbefcc0SGleb Smirnoff if (i != start && IPQ_TRYLOCK(i) == 0) 6261dbefcc0SGleb Smirnoff continue; 6271dbefcc0SGleb Smirnoff fp = TAILQ_LAST(&V_ipq[i].head, ipqhead); 6281dbefcc0SGleb Smirnoff if (fp) { 6291dbefcc0SGleb Smirnoff struct mbuf *m; 6301dbefcc0SGleb Smirnoff 6311dbefcc0SGleb Smirnoff IPSTAT_ADD(ips_fragtimeout, fp->ipq_nfrags); 6321dbefcc0SGleb Smirnoff while (fp->ipq_frags) { 6331dbefcc0SGleb Smirnoff m = fp->ipq_frags; 6341dbefcc0SGleb Smirnoff fp->ipq_frags = m->m_nextpkt; 6351dbefcc0SGleb Smirnoff m_freem(m); 6361dbefcc0SGleb Smirnoff } 6371dbefcc0SGleb Smirnoff TAILQ_REMOVE(&V_ipq[i].head, fp, ipq_list); 6381dbefcc0SGleb Smirnoff if (i != start) 6391dbefcc0SGleb Smirnoff IPQ_UNLOCK(i); 6401dbefcc0SGleb Smirnoff IPQ_LOCK_ASSERT(start); 6411dbefcc0SGleb Smirnoff return (fp); 6421dbefcc0SGleb Smirnoff } 6431dbefcc0SGleb Smirnoff if (i != start) 6441dbefcc0SGleb Smirnoff IPQ_UNLOCK(i); 6451dbefcc0SGleb Smirnoff } 6461dbefcc0SGleb Smirnoff } 6471dbefcc0SGleb Smirnoff 6481dbefcc0SGleb Smirnoff /* 6491dbefcc0SGleb Smirnoff * Free a fragment reassembly header and all associated datagrams. 6501dbefcc0SGleb Smirnoff */ 6511dbefcc0SGleb Smirnoff static void 6521dbefcc0SGleb Smirnoff ipq_free(struct ipqhead *fhp, struct ipq *fp) 6531dbefcc0SGleb Smirnoff { 6541dbefcc0SGleb Smirnoff struct mbuf *q; 6551dbefcc0SGleb Smirnoff 6561dbefcc0SGleb Smirnoff while (fp->ipq_frags) { 6571dbefcc0SGleb Smirnoff q = fp->ipq_frags; 6581dbefcc0SGleb Smirnoff fp->ipq_frags = q->m_nextpkt; 6591dbefcc0SGleb Smirnoff m_freem(q); 6601dbefcc0SGleb Smirnoff } 6611dbefcc0SGleb Smirnoff TAILQ_REMOVE(fhp, fp, ipq_list); 6621dbefcc0SGleb Smirnoff uma_zfree(V_ipq_zone, fp); 6631dbefcc0SGleb Smirnoff } 664