Skip to contentSkip to conversation

hyperv: Add handling of IP header with option field in netvsc_set_hash()

PATCH Superseded Haiyang Zhang 2 participants 3 messages Oct 14, 2014

Subsystems (3)

v2 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

PATCH v2 1/1 hyperv: Add handling of IP header with option field in netvsc_set_hash()

In case that the IP header has optional field at the end, this patch will get the port numbers after that field, and compute the hash.

---
 drivers/net/hyperv/netvsc_drv.c |   16 ++++++++++------
 1 files changed, 10 insertions(+), 6 deletions(-)
drivers/net/hyperv/netvsc_drv.c +10 -6
index 0fcb5e7..0d60c91 100644
@@ -162,7 +162,7 @@ union sub_key {
  * data: network byte order
  * return: host byte order
  */
-static u32 comp_hash(u8 *key, int klen, u8 *data, int dlen)
+static u32 comp_hash(u8 *key, int klen, void *data, int dlen)
 {
 	union sub_key subk;
 	int k_next = 4;
@@ -176,7 +176,7 @@ static u32 comp_hash(u8 *key, int klen, u8 *data, int dlen)
 	for (i = 0; i < dlen; i++) {
 		subk.kb = key[k_next];
 		k_next = (k_next + 1) % klen;
-		dt = data[i];
+		dt = ((u8 *)data)[i];
 		for (j = 0; j < 8; j++) {
 			if (dt & 0x80)
 				ret ^= subk.ka;
@@ -191,6 +191,7 @@ static u32 comp_hash(u8 *key, int klen, u8 *data, int dlen)
 static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb)
 {
 	struct iphdr *iphdr;
+	__be32 dbuf[3];
 	int data_len;
 	bool ret = false;
 
@@ -200,12 +201,15 @@ static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb)
 	iphdr = ip_hdr(skb);
 
 	if (iphdr->version == 4) {
-		if (iphdr->protocol == IPPROTO_TCP)
+		dbuf[0] = iphdr->saddr;
+		dbuf[1] = iphdr->daddr;
+		if (iphdr->protocol == IPPROTO_TCP) {
+			dbuf[2] = *(__be32 *)&tcp_hdr(skb)->source;
 			data_len = 12;
-		else
+		} else {
 			data_len = 8;
-		*hash = comp_hash(netvsc_hash_key, HASH_KEYLEN,
-				  (u8 *)&iphdr->saddr, data_len);
+		}
+		*hash = comp_hash(netvsc_hash_key, HASH_KEYLEN, dbuf, data_len);
 		ret = true;
 	}
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: Haiyang Zhang <[email protected]>
Date: Tue, 14 Oct 2014 15:16:28 -0700

Quoted 5 lines

In case that the IP header has optional field at the end, this patch will get the port numbers after that field, and compute the hash.

Instead of adding hack after hack after hack to your internal header parser, just use the generic flow dissector we already have in the kernel to fetch out the values you need.

__skb_flow_get_ports() etc.

author maintainer
#2 lore raw
Quoted 18 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Tuesday, October 14, 2014 5:37 PM
To: Haiyang Zhang
Cc: [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next,v2] hyperv: Add handling of IP header with option field in netvsc_set_hash()

From: Haiyang Zhang <[email protected]>
Date: Tue, 14 Oct 2014 15:16:28 -0700

Quoted 3 lines

In case that the IP header has optional field at the end, this patch will get the port numbers after that field, and compute the hash.

Quoted 8 lines
Quoted 2 lines

Instead of adding hack after hack after hack to your internal header parser, just use the generic flow dissector we already have in the kernel to fetch out the values you need.

__skb_flow_get_ports() etc.

Thanks. I will update the patch.

- Haiyang