Calculate the RSS hash for outbound UDPv4 frames.

Differential Revision:	https://reviews.freebsd.org/D527
Reviewed by:	grehan
This commit is contained in:
Adrian Chadd 2014-09-09 04:19:36 +00:00
parent b8bc95cd49
commit 8ad1a83b48
Notes: svn2git 2020-12-20 02:59:44 +00:00
svn path=/head/; revision=271301

View File

@ -90,6 +90,7 @@ __FBSDID("$FreeBSD$");
#include <netinet/udp.h>
#include <netinet/udp_var.h>
#include <netinet/udplite.h>
#include <netinet/in_rss.h>
#ifdef IPSEC
#include <netipsec/ipsec.h>
@ -207,6 +208,13 @@ void
udp_init(void)
{
/*
* For now default to 2-tuple UDP hashing - until the fragment
* reassembly code can also update the flowid.
*
* Once we can calculate the flowid that way and re-establish
* a 4-tuple, flip this to 4-tuple.
*/
in_pcbinfo_init(&V_udbinfo, "udp", &V_udb, UDBHASHSIZE, UDBHASHSIZE,
"udp_inpcb", udp_inpcb_init, NULL, UMA_ZONE_NOFREE,
IPI_HASHFIELDS_2TUPLE);
@ -1435,9 +1443,46 @@ udp_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr,
m->m_flags |= M_FLOWID;
m->m_pkthdr.flowid = flowid;
M_HASHTYPE_SET(m, flowid_type);
#ifdef RSS
} else {
uint32_t hash_val, hash_type;
/*
* Calculate an appropriate RSS hash for UDP and
* UDP Lite.
*
* The called function will take care of figuring out
* whether a 2-tuple or 4-tuple hash is required based
* on the currently configured scheme.
*
* Later later on connected socket values should be
* cached in the inpcb and reused, rather than constantly
* re-calculating it.
*
* UDP Lite is a different protocol number and will
* likely end up being hashed as a 2-tuple until
* RSS / NICs grow UDP Lite protocol awareness.
*/
if (rss_proto_software_hash_v4(faddr, laddr, fport, lport,
pr, &hash_val, &hash_type) == 0) {
m->m_pkthdr.flowid = hash_val;
m->m_flags |= M_FLOWID;
M_HASHTYPE_SET(m, hash_type);
}
#endif
}
#ifdef RSS
/*
* Don't override with the inp cached flowid value.
*
* Depending upon the kind of send being done, the inp
* flowid/flowtype values may actually not be appropriate
* for this particular socket send.
*
* We should either leave the flowid at zero (which is what is
* currently done) or set it to some software generated
* hash value based on the packet contents.
*/
ipflags |= IP_NODEFAULTFLOWID;
#endif /* RSS */