From abcfdaaaf0d4f8d1446e057bc5b55c4a75dab803 Mon Sep 17 00:00:00 2001
From: adrian <adrian@FreeBSD.org>
Date: Tue, 25 Aug 2015 06:12:59 +0000
Subject: [PATCH] Call the new RSS hash calculation function to correctly
 calculate a hash based on the configured requirements for the protocol.

Tested:

* UDP IPv6 TX/RX testing, w/ RSS enabled, 82599 ixgbe(4) hardware
---
 sys/netinet6/udp6_usrreq.c | 37 +++++++++++++++++++++++++++----------
 1 file changed, 27 insertions(+), 10 deletions(-)

diff --git a/sys/netinet6/udp6_usrreq.c b/sys/netinet6/udp6_usrreq.c
index eb97c1ee552a..96ad212f5320 100644
--- a/sys/netinet6/udp6_usrreq.c
+++ b/sys/netinet6/udp6_usrreq.c
@@ -840,19 +840,36 @@ udp6_output(struct inpcb *inp, struct mbuf *m, struct sockaddr *addr6,
 			m->m_pkthdr.csum_data = offsetof(struct udphdr, uh_sum);
 		}
 
-		/*
-		 * XXX for now assume UDP is 2-tuple.
-		 * Later on this may become configurable as 4-tuple;
-		 * we should support that.
-		 *
-		 * XXX .. and we should likely cache this in the inpcb.
-		 */
 #ifdef	RSS
-		m->m_pkthdr.flowid = rss_hash_ip6_2tuple(faddr, laddr);
-		M_HASHTYPE_SET(m, M_HASHTYPE_RSS_IPV6);
+		{
+			uint32_t hash_val, hash_type;
+			uint8_t pr;
+
+			pr = inp->inp_socket->so_proto->pr_protocol;
+			/*
+			 * 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_v6(faddr, laddr, fport,
+			    inp->inp_lport, pr, &hash_val, &hash_type) == 0) {
+				m->m_pkthdr.flowid = hash_val;
+				M_HASHTYPE_SET(m, hash_type);
+			}
+		}
 #endif
 		flags = 0;
-
 #ifdef	RSS
 		/*
 		 * Don't override with the inp cached flowid.