mbuf: add a way to mark flowid as calculated from the internal headers

(cherry picked from commit e243367b64)
This commit is contained in:
Konstantin Belousov 2021-02-12 15:38:07 +02:00
parent 2f5491784e
commit 5cbc9d80b8
4 changed files with 36 additions and 5 deletions

View file

@ -855,6 +855,29 @@ m_adj(struct mbuf *mp, int req_len)
}
}
void
m_adj_decap(struct mbuf *mp, int len)
{
uint8_t rsstype;
m_adj(mp, len);
if ((mp->m_flags & M_PKTHDR) != 0) {
/*
* If flowid was calculated by card from the inner
* headers, move flowid to the decapsulated mbuf
* chain, otherwise clear. This depends on the
* internals of m_adj, which keeps pkthdr as is, in
* particular not changing rsstype and flowid.
*/
rsstype = mp->m_pkthdr.rsstype;
if ((rsstype & M_HASHTYPE_INNER) != 0) {
M_HASHTYPE_SET(mp, rsstype & ~M_HASHTYPE_INNER);
} else {
M_HASHTYPE_CLEAR(mp);
}
}
}
/*
* Rearange an mbuf chain so that len bytes are contiguous
* and in the data area of an mbuf (so that mtod will work

View file

@ -540,7 +540,8 @@ gif_input(struct mbuf *m, struct ifnet *ifp, int proto, uint8_t ecn)
m_freem(m);
goto drop;
}
m_adj(m, sizeof(struct etherip_header));
m_adj_decap(m, sizeof(struct etherip_header));
m->m_flags &= ~(M_BCAST|M_MCAST);
m->m_pkthdr.rcvif = ifp;

View file

@ -2790,8 +2790,9 @@ vxlan_rcv_udp_packet(struct mbuf *m, int offset, struct inpcb *inpcb,
goto out;
vni = ntohl(vxh->vxlh_vni) >> VXLAN_HDR_VNI_SHIFT;
/* Adjust to the start of the inner Ethernet frame. */
m_adj(m, offset + sizeof(struct vxlan_header));
m_adj_decap(m, offset + sizeof(struct vxlan_header));
error = vxlan_input(vso, vni, &m, srcsa);
MPASS(error != 0 || m == NULL);

View file

@ -531,6 +531,7 @@ m_epg_pagelen(const struct mbuf *m, int pidx, int pgoff)
* https://docs.microsoft.com/en-us/windows-hardware/drivers/network/rss-hashing-types#ndishashipv6ex
*/
#define M_HASHTYPE_HASHPROP 0x80 /* has hash properties */
#define M_HASHTYPE_INNER 0x40 /* calculated from inner headers */
#define M_HASHTYPE_HASH(t) (M_HASHTYPE_HASHPROP | (t))
/* Microsoft RSS standard hash types */
#define M_HASHTYPE_NONE 0
@ -547,15 +548,19 @@ m_epg_pagelen(const struct mbuf *m, int pidx, int pgoff)
#define M_HASHTYPE_RSS_UDP_IPV6_EX M_HASHTYPE_HASH(10)/* IPv6 UDP 4-tuple +
* ext hdrs */
#define M_HASHTYPE_OPAQUE 63 /* ordering, not affinity */
#define M_HASHTYPE_OPAQUE 0x3f /* ordering, not affinity */
#define M_HASHTYPE_OPAQUE_HASH M_HASHTYPE_HASH(M_HASHTYPE_OPAQUE)
/* ordering+hash, not affinity*/
#define M_HASHTYPE_CLEAR(m) ((m)->m_pkthdr.rsstype = 0)
#define M_HASHTYPE_GET(m) ((m)->m_pkthdr.rsstype)
#define M_HASHTYPE_GET(m) ((m)->m_pkthdr.rsstype & ~M_HASHTYPE_INNER)
#define M_HASHTYPE_SET(m, v) ((m)->m_pkthdr.rsstype = (v))
#define M_HASHTYPE_TEST(m, v) (M_HASHTYPE_GET(m) == (v))
#define M_HASHTYPE_ISHASH(m) (M_HASHTYPE_GET(m) & M_HASHTYPE_HASHPROP)
#define M_HASHTYPE_ISHASH(m) \
(((m)->m_pkthdr.rsstype & M_HASHTYPE_HASHPROP) != 0)
#define M_HASHTYPE_SETINNER(m) do { \
(m)->m_pkthdr.rsstype |= M_HASHTYPE_INNER; \
} while (0)
/*
* External mbuf storage buffer types.
@ -791,6 +796,7 @@ int mb_unmapped_compress(struct mbuf *m);
struct mbuf *mb_unmapped_to_ext(struct mbuf *m);
void mb_free_notready(struct mbuf *m, int count);
void m_adj(struct mbuf *, int);
void m_adj_decap(struct mbuf *, int);
int m_apply(struct mbuf *, int, int,
int (*)(void *, void *, u_int), void *);
int m_append(struct mbuf *, int, c_caddr_t);