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 Aug 19, 2014 – Aug 22, 2014

Subsystems (3)

v1 of 3 Superseded Latest is v3 →

lore
Share & tools
lore

Haiyang Zhang

author maintainer
#0 lore raw

PATCH 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, 12 insertions(+), 4 deletions(-)
drivers/net/hyperv/netvsc_drv.c +12 -4
index a9c5eaa..b12dcd9 100644
@@ -191,6 +191,8 @@ 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;
+	u8 dbuf[12];
+	u8 *data;
 	int data_len;
 	bool ret = false;
 
@@ -200,12 +202,18 @@ static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb)
 	iphdr = ip_hdr(skb);
 
 	if (iphdr->version == 4) {
-		if (iphdr->protocol == IPPROTO_TCP)
+		data = (u8 *)&iphdr->saddr;
+		if (iphdr->protocol == IPPROTO_TCP) {
 			data_len = 12;
-		else
+			if (iphdr->ihl > 5) {
+				memcpy(dbuf, &iphdr->saddr, 8);
+				memcpy(&dbuf[8], &tcp_hdr(skb)->source, 4);
+				data = dbuf;
+			}
+		} 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, data, data_len);
 		ret = true;
 	}
 
Signature · 1 line
1.7.1
maintainer
#1 lore raw

From: Haiyang Zhang <[email protected]>
Date: Tue, 19 Aug 2014 20:53:55 +0000

drivers/net/hyperv/netvsc_drv.c static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb) · line 210

Quoted 12 lines
drivers/net/hyperv/netvsc_drv.c +5 -2
@@ -200,12 +202,18 @@ static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb)
 	iphdr = ip_hdr(skb);
 
 	if (iphdr->version == 4) {
-		if (iphdr->protocol == IPPROTO_TCP)
+		data = (u8 *)&iphdr->saddr;
+		if (iphdr->protocol == IPPROTO_TCP) {
 			data_len = 12;
-		else
+			if (iphdr->ihl > 5) {
+				memcpy(dbuf, &iphdr->saddr, 8);
+				memcpy(&dbuf[8], &tcp_hdr(skb)->source, 4);

This is rediculous.

Make hash_comp() take a void pointer for the buffer.

Then your code is simply:

	be32 dbuf[2];

	dbuf[1] = iph->saddr;
	dbuf[2] = iph->daddr;
	dbuf[3] = *(be32 *)tcph->source;

	*hash = comp_hash(netvsc_hash_key, HASH_KEYLEN, dbuf, 12);

No special cases for IP options or any garbage like that.

author maintainer
#2 lore raw
Quoted 43 lines

-----Original Message-----
From: David Miller [mailto:[email protected]]
Sent: Friday, August 22, 2014 12:31 AM
To: Haiyang Zhang
Cc: [email protected]; KY Srinivasan; [email protected]; [email protected]; [email protected]; driverdev- [email protected]
Subject: Re: [PATCH net-next] hyperv: Add handling of IP header with option field in netvsc_set_hash()

From: Haiyang Zhang <[email protected]>
Date: Tue, 19 Aug 2014 20:53:55 +0000

Review static bool netvsc_set_hash(u32 *hash, struct

Quoted 1 line
(quoted diff) +0 -0
@@ -200,12 +202,18 @@ static bool netvsc_set_hash(u32 *hash, struct

sk_buff *skb)

drivers/net/hyperv/netvsc_drv.c static bool netvsc_set_hash(u32 *hash, struct sk_buff *skb) · line 210

Quoted 11 lines
drivers/net/hyperv/netvsc_drv.c +5 -2
 	iphdr = ip_hdr(skb);
 
 	if (iphdr->version == 4) {
-		if (iphdr->protocol == IPPROTO_TCP)
+		data = (u8 *)&iphdr->saddr;
+		if (iphdr->protocol == IPPROTO_TCP) {
 			data_len = 12;
-		else
+			if (iphdr->ihl > 5) {
+				memcpy(dbuf, &iphdr->saddr, 8);
+				memcpy(&dbuf[8], &tcp_hdr(skb)->source, 4);

This is rediculous.

Make hash_comp() take a void pointer for the buffer.

Then your code is simply:

	be32 dbuf[2];

	dbuf[1] = iph->saddr;
	dbuf[2] = iph->daddr;
	dbuf[3] = *(be32 *)tcph->source;

	*hash = comp_hash(netvsc_hash_key, HASH_KEYLEN, dbuf, 12);
Quoted 1 line

No special cases for IP options or any garbage like that.

I have submitted a revised patch with the suggested changes.

Thanks,
- Haiyang