Skip to contentSkip to conversation

pktgen: should not turn off vlan when we disable svlan

PATCH In review Hangbin Liu 2 participants 6 messages May 15, 2014

Subsystems (3)
lore
Share & tools
lore
#0 lore raw

PATCH 1/3 pktgen: should not turn off vlan when we disable svlan

We will turn off svlan when disable vlan, but should keep vlan on when disable svlan. Also fix the doc typo.

---
 Documentation/networking/pktgen.txt | 2 +-
 net/core/pktgen.c                   | 3 +--
 2 files changed, 2 insertions(+), 3 deletions(-)
Documentation/networking/pktgen.txt +1 -1
index 0e30c78..672fa23 100644
@@ -150,7 +150,7 @@ Examples:
  pgset "svlan_cfi 0"      set canonical format identifier 0-1 (default 0)
 
  pgset "vlan_id 9999"     > 4095 remove vlan and svlan tags
- pgset "svlan 9999"       > 4095 remove svlan tag
+ pgset "svlan_id 9999"    > 4095 remove svlan tag
 
 
  pgset "tos XX"           set former IPv4 TOS field (e.g. "tos 28" for AF11 no ECN, default 00)
net/core/pktgen.c +1 -2
index 0304f98..dcf367f 100644
@@ -1627,11 +1627,10 @@ static ssize_t pktgen_if_write(struct file *file,
 			pkt_dev->nr_labels = 0;    /* turn off MPLS */
 			sprintf(pg_result, "OK: svlan_id=%u", pkt_dev->svlan_id);
 		} else {
-			pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
 			pkt_dev->svlan_id = 0xffff;
 
 			if (debug)
-				pr_debug("VLAN/SVLAN turned off\n");
+				pr_debug("SVLAN turned off\n");
 		}
 		return count;
 	}
Signature · 1 line
1.8.1.4
#1 lore raw

PATCH 2/3 pktgen: give user result when disable vlan/svlan

---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +2 -4
index dcf367f..1809bdf 100644
@@ -1573,8 +1573,7 @@ static ssize_t pktgen_if_write(struct file *file,
 			pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
 			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("VLAN/SVLAN turned off\n");
+			sprintf(pg_result, "OK: VLAN/SVLAN turned off");
 		}
 		return count;
 	}
@@ -1629,8 +1628,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		} else {
 			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("SVLAN turned off\n");
+			sprintf(pg_result, "OK: SVLAN turned off");
 		}
 		return count;
 	}
Signature · 1 line
1.8.1.4
#5 lore raw

PATCH 3/3 pktgen: disable IPv6 when we want to use IPv4

In reply to Hangbin Liu
---
 net/core/pktgen.c | 7 +++++++
 1 file changed, 7 insertions(+)
net/core/pktgen.c +7 -0
index 1809bdf..fabd17e 100644
@@ -1264,6 +1264,8 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (len < 0)
 			return len;
 
+		pkt_dev->flags &= ~F_IPV6;
+
 		if (copy_from_user(buf, &user_buffer[i], len))
 			return -EFAULT;
 		buf[len] = 0;
@@ -1284,6 +1286,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (len < 0)
 			return len;
 
+		pkt_dev->flags &= ~F_IPV6;
 
 		if (copy_from_user(buf, &user_buffer[i], len))
 			return -EFAULT;
@@ -1395,6 +1398,8 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (len < 0)
 			return len;
 
+		pkt_dev->flags &= ~F_IPV6;
+
 		if (copy_from_user(buf, &user_buffer[i], len))
 			return -EFAULT;
 		buf[len] = 0;
@@ -1415,6 +1420,8 @@ static ssize_t pktgen_if_write(struct file *file,
 		if (len < 0)
 			return len;
 
+		pkt_dev->flags &= ~F_IPV6;
+
 		if (copy_from_user(buf, &user_buffer[i], len))
 			return -EFAULT;
 		buf[len] = 0;
Signature · 1 line
1.8.1.4
#2 lore raw

Re: [PATCH net 2/3] pktgen: give user result when disable vlan/svlan

In reply to Hangbin Liu
Quoted 10 lines · Hangbin Liu
---
  net/core/pktgen.c | 6 ++----
  1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +0 -0
index dcf367f..1809bdf 100644

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1576

Quoted 6 lines
net/core/pktgen.c +1 -2
@@ -1573,8 +1573,7 @@ static ssize_t pktgen_if_write(struct file *file,
  			pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
  			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("VLAN/SVLAN turned off\n");
+			sprintf(pg_result, "OK: VLAN/SVLAN turned off");

I think that might break user scripts as pg_result is copied to user space, and currently only expected to return 'OK: svlan_id=%u' if it was actually successful. Unfortunately, scripts that might only check for 'OK' in the string could make wrong assumptions later on.

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1631

Quoted 10 lines
net/core/pktgen.c +1 -2
  		}
  		return count;
  	}
@@ -1629,8 +1628,7 @@ static ssize_t pktgen_if_write(struct file *file,
  		} else {
  			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("SVLAN turned off\n");
+			sprintf(pg_result, "OK: SVLAN turned off");

Ditto.

Quoted 4 lines
net/core/pktgen.c +0 -0
  		}
  		return count;
  	}
#3 lore raw

Re: [PATCH net 2/3] pktgen: give user result when disable vlan/svlan

Quoted 14 lines · Daniel Borkmann
Quoted 13 lines · Hangbin Liu
---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +0 -0
index dcf367f..1809bdf 100644
@@ -1573,8 +1573,7 @@ static ssize_t pktgen_if_write(struct file *file,
 			pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
 			pkt_dev->svlan_id = 0xffff;
 
Quoted 8 lines

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1576

Quoted 3 lines
net/core/pktgen.c +1 -2
-			if (debug)
-				pr_debug("VLAN/SVLAN turned off\n");
+			sprintf(pg_result, "OK: VLAN/SVLAN turned off");

I think that might break user scripts as pg_result is copied to user space, and currently only expected to return 'OK: svlan_id=%u' if it was actually successful. Unfortunately, scripts that might only check for 'OK' in the string could make wrong assumptions later on.

But the original behavior will keep the last return value, which may make user confused. e.g.

# echo vlan_id 10 > /proc/net/pktgen/eno4
# cat /proc/net/pktgen/eno4
Params: count 1000  min_pkt_size: 0  max_pkt_size: 0
     frags: 0  delay: 0  clone_skb: 0  ifname: eno4
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max:
        src_min:   src_max:
     src_mac: 6c:ae:8b:20:7b:cc dst_mac: 00:00:00:00:00:00
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     vlan_id: 10  vlan_p: 0  vlan_cfi: 0
     Flags:
Current:
     pkts-sofar: 0  errors: 0
     started: 0us  stopped: 0us idle: 0us
     seq_num: 0  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0.0.0.0  cur_daddr: 0.0.0.0
     cur_udp_dst: 0  cur_udp_src: 0
     cur_queue_map: 0
     flows: 0
Result: OK: vlan_id=10
# echo vlan_id 9999 > /proc/net/pktgen/eno4
# cat /proc/net/pktgen/eno4
Params: count 1000  min_pkt_size: 0  max_pkt_size: 0
     frags: 0  delay: 0  clone_skb: 0  ifname: eno4
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max:
        src_min:   src_max:
     src_mac: 6c:ae:8b:20:7b:cc dst_mac: 00:00:00:00:00:00
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     Flags:
Current:
     pkts-sofar: 0  errors: 0
     started: 0us  stopped: 0us idle: 0us
     seq_num: 0  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0.0.0.0  cur_daddr: 0.0.0.0
     cur_udp_dst: 0  cur_udp_src: 0
     cur_queue_map: 0
     flows: 0
Result: OK: vlan_id=10
Quoted 18 lines

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1631

Quoted 11 lines
net/core/pktgen.c +1 -2
 		}
 		return count;
 	}
@@ -1629,8 +1628,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		} else {
 			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("SVLAN turned off\n");
+			sprintf(pg_result, "OK: SVLAN turned off");

Ditto.

Quoted 4 lines
net/core/pktgen.c +0 -0
 		}
 		return count;
 	}
Signature · 2 lines
Thanks & Best Regards
Hangbin Liu <[email protected]>
#4 lore raw

Re: [PATCH net 2/3] pktgen: give user result when disable vlan/svlan

Quoted 15 lines · Hangbin Liu
Quoted 14 lines · Daniel Borkmann
Quoted 13 lines · Hangbin Liu
---
 net/core/pktgen.c | 6 ++----
 1 file changed, 2 insertions(+), 4 deletions(-)
net/core/pktgen.c +0 -0
index dcf367f..1809bdf 100644
@@ -1573,8 +1573,7 @@ static ssize_t pktgen_if_write(struct file *file,
 			pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
 			pkt_dev->svlan_id = 0xffff;
 
Quoted 8 lines
Quoted 8 lines

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1576

Quoted 3 lines
net/core/pktgen.c +1 -2
-			if (debug)
-				pr_debug("VLAN/SVLAN turned off\n");
+			sprintf(pg_result, "OK: VLAN/SVLAN turned off");

I think that might break user scripts as pg_result is copied to user space, and currently only expected to return 'OK: svlan_id=%u' if it was actually successful. Unfortunately, scripts that might only check for 'OK' in the string could make wrong assumptions later on.

or maybe we can return 0xffff when disabled vlan? like

net/core/pktgen.c +4 -1
index fabd17e..64afb91 100644
@@ -1580,7 +1580,10 @@ static ssize_t pktgen_if_write(struct file *file,
                        pkt_dev->vlan_id = 0xffff; /* turn off VLAN/SVLAN */
                        pkt_dev->svlan_id = 0xffff;
 
-                       sprintf(pg_result, "OK: VLAN/SVLAN turned off");
+                       sprintf(pg_result, "OK: vlan_id=0x%x", pkt_dev->vlan_id);
+
+                       if (debug)
+                               pr_debug("VLAN/SVLAN turned off\n");
                }
                return count;
        }

But I saw dst_mac, src_mac and clear_counters also didn't use the OK: param=value format.
sprintf(pg_result, "OK: dstmac %pM", pkt_dev->dst_mac); sprintf(pg_result, "OK: srcmac %pM", pkt_dev->src_mac); sprintf(pg_result, "OK: Clearing counters.\n");

We can change src_mac and dst_mac to "srcmac=%pM" easily, but I don't know how to edit counters. return OK: counters=0 ?

Quoted 72 lines

But the original behavior will keep the last return value, which may make user confused. e.g.

# echo vlan_id 10 > /proc/net/pktgen/eno4
# cat /proc/net/pktgen/eno4
Params: count 1000  min_pkt_size: 0  max_pkt_size: 0
     frags: 0  delay: 0  clone_skb: 0  ifname: eno4
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max:
        src_min:   src_max:
     src_mac: 6c:ae:8b:20:7b:cc dst_mac: 00:00:00:00:00:00
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     vlan_id: 10  vlan_p: 0  vlan_cfi: 0
     Flags:
Current:
     pkts-sofar: 0  errors: 0
     started: 0us  stopped: 0us idle: 0us
     seq_num: 0  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0.0.0.0  cur_daddr: 0.0.0.0
     cur_udp_dst: 0  cur_udp_src: 0
     cur_queue_map: 0
     flows: 0
Result: OK: vlan_id=10
# echo vlan_id 9999 > /proc/net/pktgen/eno4
# cat /proc/net/pktgen/eno4
Params: count 1000  min_pkt_size: 0  max_pkt_size: 0
     frags: 0  delay: 0  clone_skb: 0  ifname: eno4
     flows: 0 flowlen: 0
     queue_map_min: 0  queue_map_max: 0
     dst_min:   dst_max:
        src_min:   src_max:
     src_mac: 6c:ae:8b:20:7b:cc dst_mac: 00:00:00:00:00:00
     udp_src_min: 9  udp_src_max: 9  udp_dst_min: 9  udp_dst_max: 9
     src_mac_count: 0  dst_mac_count: 0
     Flags:
Current:
     pkts-sofar: 0  errors: 0
     started: 0us  stopped: 0us idle: 0us
     seq_num: 0  cur_dst_mac_offset: 0  cur_src_mac_offset: 0
     cur_saddr: 0.0.0.0  cur_daddr: 0.0.0.0
     cur_udp_dst: 0  cur_udp_src: 0
     cur_queue_map: 0
     flows: 0
Result: OK: vlan_id=10
Quoted 18 lines

net/core/pktgen.c static ssize_t pktgen_if_write(struct file *file, · line 1631

Quoted 11 lines
net/core/pktgen.c +1 -2
 		}
 		return count;
 	}
@@ -1629,8 +1628,7 @@ static ssize_t pktgen_if_write(struct file *file,
 		} else {
 			pkt_dev->svlan_id = 0xffff;
 
-			if (debug)
-				pr_debug("SVLAN turned off\n");
+			sprintf(pg_result, "OK: SVLAN turned off");

Ditto.

Quoted 4 lines
net/core/pktgen.c +0 -0
 		}
 		return count;
 	}
Signature · 2 lines
Thanks & Best Regards
Hangbin Liu <[email protected]>
Signature · 2 lines
Thanks & Best Regards
Hangbin Liu <[email protected]>