From 6d29bbbab8fa308687fb6806b01fdc2262f37d6e Mon Sep 17 00:00:00 2001 From: bz Date: Thu, 24 Oct 2019 08:15:40 +0000 Subject: [PATCH] frag6: small improvements Rather than walking the mbuf chain manually use m_last() which doing exactly that for us. Defer initializing srcifp for longer as there are multiple exit paths out of the function which do not need it set. Initialize before taking the lock though. Rename the mtx lock to match the type better. MFC after: 3 weeks Sponsored by: Netflix --- sys/netinet6/frag6.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/sys/netinet6/frag6.c b/sys/netinet6/frag6.c index 758dbf75281b..e77404f467bc 100644 --- a/sys/netinet6/frag6.c +++ b/sys/netinet6/frag6.c @@ -399,9 +399,6 @@ frag6_input(struct mbuf **mp, int *offp, int proto) return (IPPROTO_DONE); #endif - /* Store receive network interface pointer for later. */ - srcifp = m->m_pkthdr.rcvif; - dstifp = NULL; /* Find the destination interface of the packet. */ ia6 = in6ifa_ifwithaddr(&ip6->ip6_dst, 0 /* XXX */); @@ -461,6 +458,9 @@ frag6_input(struct mbuf **mp, int *offp, int proto) return (IPPROTO_DONE); } + /* Store receive network interface pointer for later. */ + srcifp = m->m_pkthdr.rcvif; + /* Generate a hash value for fragment bucket selection. */ hashkeyp = hashkey; memcpy(hashkeyp, &ip6->ip6_src, sizeof(struct in6_addr)); @@ -739,8 +739,7 @@ frag6_input(struct mbuf **mp, int *offp, int proto) af6->ip6af_m->m_pkthdr.csum_data; TAILQ_REMOVE(&q6->ip6q_frags, af6, ip6af_tq); - while (t->m_next) - t = t->m_next; + t = m_last(t); m_adj(af6->ip6af_m, af6->ip6af_offset); m_demote_pkthdr(af6->ip6af_m); m_cat(t, af6->ip6af_m); @@ -930,7 +929,7 @@ frag6_init(void) frag6_set_bucketsize(); for (bucket = 0; bucket < IP6REASS_NHASH; bucket++) { TAILQ_INIT(IP6QB_HEAD(bucket)); - mtx_init(&V_ip6qb[bucket].lock, "ip6qlock", NULL, MTX_DEF); + mtx_init(&V_ip6qb[bucket].lock, "ip6qb", NULL, MTX_DEF); V_ip6qb[bucket].count = 0; } V_ip6qb_hashseed = arc4random();