Skip to contentSkip to conversation

Network flow classifier

PATCH Applied Alexander Duyck 2 participants 22 messages Apr 21, 2011 – Apr 29, 2011

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

cover Network flow classifier

The following patches are meant to add support for the network flow classifier interface built into the ethtool_rxnfc.

Once this has been accepted I plan to submit the kernel portion to Jeff Kirsher as it is almost all ixgbe code changes with the exception of the removal of support for ethtool_get_rx_ntuple from the kernel.

Thanks,

Alex

---

Alexander Duyck (5):
Update documentation for -u/-U operations
Add support for __be64 and bitops to ethtool
ethtool: remove strings based approach for displaying n-tuple Add support for NFC flow classifier extensions
Add support for ESP as a separate protocol from AH

Santwona Behera (1):
v4 Add RX packet classification interface

 Makefile.am      |    3 
 ethtool-bitops.h |   25 +
 ethtool-copy.h   |   39 +-
 ethtool-util.h   |   44 ++
 ethtool.8.in     |  193 +++++----
 ethtool.c        |  449 +++++++++++-----------
 rxclass.c        | 1106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 7 files changed, 1519 insertions(+), 340 deletions(-)
 create mode 100644 ethtool-bitops.h
 create mode 100644 rxclass.c
#1 lore raw

PATCH 1/6 Add support for ESP as a separate protocol from AH

This change is mostly cosmetic. NIU had supported AH and ESP seperately. As such it is possible that a return value of ESP or AH may be returned for a has request instead of the AH_ESP combined value. To resolve that the inputs are combined for AH and ESP into the AH_ESP value and return values for AH and ESP will display the combined string info.

---

 ethtool.8.in |    8 +++++---
 ethtool.c    |   21 ++++++++++++---------
 2 files changed, 17 insertions(+), 12 deletions(-)
ethtool.8.in +5 -3
index 714486e..12a1d1d 100644
@@ -52,7 +52,7 @@
 .\"
 .\"	\(*FL - flow type values
 .\"
-.ds FL \fBtcp4\fP|\fBudp4\fP|\fBah4\fP|\fBsctp4\fP|\fBtcp6\fP|\fBudp6\fP|\fBah6\fP|\fBsctp6\fP
+.ds FL \fBtcp4\fP|\fBudp4\fP|\fBah4\fP|\fBesp4\fP|\fBsctp4\fP|\fBtcp6\fP|\fBudp6\fP|\fBah6\fP|\fBesp6\fP|\fBsctp6\fP
 .\"
 .\"	\(*HO - hash options
 .\"
@@ -572,11 +572,13 @@ nokeep;
 lB	l.
 tcp4	TCP over IPv4
 udp4	UDP over IPv4
-ah4	IPSEC AH/ESP over IPv4
+ah4	IPSEC AH over IPv4
+esp4	IPSEC ESP over IPv4
 sctp4	SCTP over IPv4
 tcp6	TCP over IPv6
 udp6	UDP over IPv6
-ah6	IPSEC AH/ESP over IPv6
+ah6	IPSEC AH over IPv6
+esp6	IPSEC ESP over IPv6
 sctp6	SCTP over IPv6
 .TE
 .TP
ethtool.c +12 -9
index 32df0ee..cfdac65 100644
@@ -32,7 +32,6 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <net/if.h>
 #include <sys/utsname.h>
@@ -233,15 +232,15 @@ static struct option {
     { "-S", "--statistics", MODE_GSTATS, "Show adapter statistics" },
     { "-n", "--show-nfc", MODE_GNFC, "Show Rx network flow classification "
 		"options",
-		"		[ rx-flow-hash tcp4|udp4|ah4|sctp4|"
-		"tcp6|udp6|ah6|sctp6 ]\n" },
+		"		[ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
+		"tcp6|udp6|ah6|esp6|sctp6 ]\n" },
     { "-f", "--flash", MODE_FLASHDEV, "FILENAME " "Flash firmware image "
     		"from the specified file to a region on the device",
 		"               [ REGION-NUMBER-TO-FLASH ]\n" },
     { "-N", "--config-nfc", MODE_SNFC, "Configure Rx network flow "
 		"classification options",
-		"		[ rx-flow-hash tcp4|udp4|ah4|sctp4|"
-		"tcp6|udp6|ah6|sctp6 m|v|t|s|d|f|n|r... ]\n" },
+		"		[ rx-flow-hash tcp4|udp4|ah4|esp4|sctp4|"
+		"tcp6|udp6|ah6|esp6|sctp6 m|v|t|s|d|f|n|r... ]\n" },
     { "-x", "--show-rxfh-indir", MODE_GRXFHINDIR, "Show Rx flow hash "
 		"indirection" },
     { "-X", "--set-rxfh-indir", MODE_SRXFHINDIR, "Set Rx flow hash indirection",
@@ -783,7 +782,7 @@ static int rxflow_str_to_type(const char *str)
 		flow_type = TCP_V4_FLOW;
 	else if (!strcmp(str, "udp4"))
 		flow_type = UDP_V4_FLOW;
-	else if (!strcmp(str, "ah4"))
+	else if (!strcmp(str, "ah4") || !strcmp(str, "esp4"))
 		flow_type = AH_ESP_V4_FLOW;
 	else if (!strcmp(str, "sctp4"))
 		flow_type = SCTP_V4_FLOW;
@@ -791,7 +790,7 @@ static int rxflow_str_to_type(const char *str)
 		flow_type = TCP_V6_FLOW;
 	else if (!strcmp(str, "udp6"))
 		flow_type = UDP_V6_FLOW;
-	else if (!strcmp(str, "ah6"))
+	else if (!strcmp(str, "ah6") || !strcmp(str, "esp6"))
 		flow_type = AH_ESP_V6_FLOW;
 	else if (!strcmp(str, "sctp6"))
 		flow_type = SCTP_V6_FLOW;
@@ -1941,7 +1940,9 @@ static int dump_rxfhash(int fhash, u64 val)
 		fprintf(stdout, "SCTP over IPV4 flows");
 		break;
 	case AH_ESP_V4_FLOW:
-		fprintf(stdout, "IPSEC AH over IPV4 flows");
+	case AH_V4_FLOW:
+	case ESP_V4_FLOW:
+		fprintf(stdout, "IPSEC AH/ESP over IPV4 flows");
 		break;
 	case TCP_V6_FLOW:
 		fprintf(stdout, "TCP over IPV6 flows");
@@ -1953,7 +1954,9 @@ static int dump_rxfhash(int fhash, u64 val)
 		fprintf(stdout, "SCTP over IPV6 flows");
 		break;
 	case AH_ESP_V6_FLOW:
-		fprintf(stdout, "IPSEC AH over IPV6 flows");
+	case AH_V6_FLOW:
+	case ESP_V6_FLOW:
+		fprintf(stdout, "IPSEC AH/ESP over IPV6 flows");
 		break;
 	default:
 		break;
#2 lore raw

Re: [ethtool PATCH 1/6] Add support for ESP as a separate protocol from AH

Quoted 7 lines · Alexander Duyck

This change is mostly cosmetic. NIU had supported AH and ESP seperately. As such it is possible that a return value of ESP or AH may be returned for a has request instead of the AH_ESP combined value. To resolve that the inputs are combined for AH and ESP into the AH_ESP value and return values for AH and ESP will display the combined string info.

Applied, but I moved this into a separate commit:

[...]

ethtool.c line 37

Quoted 10 lines
ethtool.c +0 -1
@@ -32,7 +32,6 @@
 #include <sys/ioctl.h>
 #include <sys/stat.h>
 #include <stdio.h>
-#include <string.h>
 #include <errno.h>
 #include <net/if.h>
 #include <sys/utsname.h>

[...]

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#3 lore raw

PATCH 2/6 Add support for NFC flow classifier extensions

In reply to Alexander Duyck

This change makes it so that we can add VLAN Ethertype, TCI, and 64bits of driver defined data to a network flow classifier allowing us to handle a n-tuple flow contained within a network flow classifier.

---

 ethtool-copy.h |   39 ++++++++++++++++++++++++++++-----------
 1 files changed, 28 insertions(+), 11 deletions(-)
ethtool-copy.h +28 -11
index 75c3ae7..5b45442 100644
@@ -376,27 +376,42 @@ struct ethtool_usrip4_spec {
 	__u8    proto;
 };
 
+union ethtool_flow_union {
+	struct ethtool_tcpip4_spec		tcp_ip4_spec;
+	struct ethtool_tcpip4_spec		udp_ip4_spec;
+	struct ethtool_tcpip4_spec		sctp_ip4_spec;
+	struct ethtool_ah_espip4_spec		ah_ip4_spec;
+	struct ethtool_ah_espip4_spec		esp_ip4_spec;
+	struct ethtool_usrip4_spec		usr_ip4_spec;
+	struct ethhdr				ether_spec;
+	__u8					hdata[60];
+};
+
+struct ethtool_flow_ext {
+	__be16	vlan_etype;
+	__be16	vlan_tci;
+	__be32	data[2];
+};
+
 /**
  * struct ethtool_rx_flow_spec - specification for RX flow filter
  * @flow_type: Type of match to perform, e.g. %TCP_V4_FLOW
  * @h_u: Flow fields to match (dependent on @flow_type)
- * @m_u: Masks for flow field bits to be ignored
+ * @h_ext: Additional fields to match
+ * @m_u: Masks for flow field bits to be matched
+ * @m_ext: Masks for additional field bits to be matched
+ *	Note, all additional fields must be ignored unless @flow_type
+ *	includes the %FLOW_EXT flag.
  * @ring_cookie: RX ring/queue index to deliver to, or %RX_CLS_FLOW_DISC
  *	if packets should be discarded
  * @location: Index of filter in hardware table
  */
 struct ethtool_rx_flow_spec {
 	__u32		flow_type;
-	union {
-		struct ethtool_tcpip4_spec		tcp_ip4_spec;
-		struct ethtool_tcpip4_spec		udp_ip4_spec;
-		struct ethtool_tcpip4_spec		sctp_ip4_spec;
-		struct ethtool_ah_espip4_spec		ah_ip4_spec;
-		struct ethtool_ah_espip4_spec		esp_ip4_spec;
-		struct ethtool_usrip4_spec		usr_ip4_spec;
-		struct ethhdr				ether_spec;
-		__u8					hdata[72];
-	} h_u, m_u;
+	union ethtool_flow_union h_u;
+	struct ethtool_flow_ext h_ext;
+	union ethtool_flow_union m_u;
+	struct ethtool_flow_ext m_ext;
 	__u64		ring_cookie;
 	__u32		location;
 };
@@ -706,6 +721,8 @@ struct ethtool_flash {
 #define	IPV4_FLOW	0x10	/* hash only */
 #define	IPV6_FLOW	0x11	/* hash only */
 #define	ETHER_FLOW	0x12	/* spec only (ether_spec) */
+/* Flag to enable additional fields in struct ethtool_rx_flow_spec */
+#define	FLOW_EXT	0x80000000
 
 /* L3-L4 network traffic flow hash options */
 #define	RXH_L2DA	(1 << 1)
#4 lore raw

Re: [ethtool PATCH 2/6] Add support for NFC flow classifier extensions

Quoted 5 lines · Alexander Duyck

This change makes it so that we can add VLAN Ethertype, TCI, and 64bits of driver defined data to a network flow classifier allowing us to handle a n-tuple flow contained within a network flow classifier.

[...]

This does not correspond to any version of ethtool.h in kernel history. I sync'd from current net-next-2.6 instead.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#5 lore raw

PATCH 3/6 ethtool: remove strings based approach for displaying n-tuple

In reply to Alexander Duyck

This change is meant to remove the strings based approach for displaying n-tuple filters. A follow-on patch will replace that functionality with a network flow classification based approach that will get the number of filters, get their locations, and then request and display them individually.

---

 ethtool.c |   44 --------------------------------------------
 1 files changed, 0 insertions(+), 44 deletions(-)
ethtool.c +0 -44
index cfdac65..9ad7000 100644
@@ -3194,50 +3194,6 @@ static int do_srxntuple(int fd, struct ifreq *ifr)
 
 static int do_grxntuple(int fd, struct ifreq *ifr)
 {
-	struct ethtool_sset_info *sset_info;
-	struct ethtool_gstrings *strings;
-	int sz_str, n_strings, err, i;
-
-	sset_info = malloc(sizeof(struct ethtool_sset_info) + sizeof(u32));
-	sset_info->cmd = ETHTOOL_GSSET_INFO;
-	sset_info->sset_mask = (1ULL << ETH_SS_NTUPLE_FILTERS);
-	ifr->ifr_data = (caddr_t)sset_info;
-	err = send_ioctl(fd, ifr);
-
-	if ((err < 0) ||
-	    (!(sset_info->sset_mask & (1ULL << ETH_SS_NTUPLE_FILTERS)))) {
-		perror("Cannot get driver strings info");
-		return 100;
-	}
-
-	n_strings = sset_info->data[0];
-	free(sset_info);
-	sz_str = n_strings * ETH_GSTRING_LEN;
-
-	strings = calloc(1, sz_str + sizeof(struct ethtool_gstrings));
-	if (!strings) {
-		fprintf(stderr, "no memory available\n");
-		return 95;
-	}
-
-	strings->cmd = ETHTOOL_GRXNTUPLE;
-	strings->string_set = ETH_SS_NTUPLE_FILTERS;
-	strings->len = n_strings;
-	ifr->ifr_data = (caddr_t) strings;
-	err = send_ioctl(fd, ifr);
-	if (err < 0) {
-		perror("Cannot get Rx n-tuple information");
-		free(strings);
-		return 101;
-	}
-
-	n_strings = strings->len;
-	fprintf(stdout, "Rx n-tuple filters:\n");
-	for (i = 0; i < n_strings; i++)
-		fprintf(stdout, "%s", &strings->data[i * ETH_GSTRING_LEN]);
-
-	free(strings);
-
 	return 0;
 }
 
#6 lore raw

Re: [ethtool PATCH 3/6] ethtool: remove strings based approach for displaying n-tuple

Quoted 5 lines · Alexander Duyck

This change is meant to remove the strings based approach for displaying n-tuple filters. A follow-on patch will replace that functionality with a network flow classification based approach that will get the number of filters, get their locations, and then request and display them individually.

[...]

I'm deferring this until the other patches are updated.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#7 lore raw

PATCH 4/6 Add support for __be64 and bitops to ethtool

In reply to Alexander Duyck

This change is meant to add support for __be64 values and bitops to ethtool. These changes will be needed in order to support network flow classifier rule configuration.

---

 ethtool-bitops.h |   25 +++++++++++++++++++++++++
 ethtool-util.h   |   30 ++++++++++++++++++++++++++----
 ethtool.c        |    7 -------
 3 files changed, 51 insertions(+), 11 deletions(-)
 create mode 100644 ethtool-bitops.h
ethtool-bitops.h new file +25 -0
new file mode 100644
index 0000000..0ff14f1
@@ -0,0 +1,25 @@
+#ifndef ETHTOOL_BITOPS_H__
+#define ETHTOOL_BITOPS_H__
+
+#define BITS_PER_BYTE		8
+#define BITS_PER_LONG		(BITS_PER_BYTE * sizeof(long))
+#define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
+#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_LONG)
+
+static inline void set_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
+}
+
+static inline void clear_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
+}
+
+static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
+{
+	return !!((1UL << (nr % BITS_PER_LONG)) &
+		  (((unsigned long *)addr)[nr / BITS_PER_LONG]));
+}
+
+#endif
ethtool-util.h +26 -4
index f053028..3d46faf 100644
@@ -5,15 +5,18 @@
 
 #include <sys/types.h>
 #include <endian.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include "ethtool-config.h"
+#include "ethtool-copy.h"
 
 /* ethtool.h expects these to be defined by <linux/types.h> */
 #ifndef HAVE_BE_TYPES
 typedef __uint16_t __be16;
 typedef __uint32_t __be32;
+typedef unsigned long long __be64;
 #endif
 
-#include "ethtool-copy.h"
-
 typedef unsigned long long u64;
 typedef __uint32_t u32;
 typedef __uint16_t u16;
@@ -23,11 +26,15 @@ typedef __int32_t s32;
 #if __BYTE_ORDER == __BIG_ENDIAN
 static inline u16 cpu_to_be16(u16 value)
 {
-    return value;
+	return value;
 }
 static inline u32 cpu_to_be32(u32 value)
 {
-    return value;
+	return value;
+}
+static inline u64 cpu_to_be64(u64 value)
+{
+	return value;
 }
 #else
 static inline u16 cpu_to_be16(u16 value)
@@ -38,6 +45,21 @@ static inline u32 cpu_to_be32(u32 value)
 {
 	return cpu_to_be16(value >> 16) | (cpu_to_be16(value) << 16);
 }
+static inline u64 cpu_to_be64(u64 value)
+{
+	return cpu_to_be32(value >> 32) | ((u64)cpu_to_be32(value) << 32);
+}
+#endif
+
+#define ntohll cpu_to_be64
+#define htonll cpu_to_be64
+
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#ifndef SIOCETHTOOL
+#define SIOCETHTOOL     0x8946
 #endif
 
 /* National Semiconductor DP83815, DP83816 */
ethtool.c +0 -7
index 9ad7000..15af86a 100644
@@ -45,16 +45,9 @@
 #include <linux/sockios.h>
 #include "ethtool-util.h"
 
-
-#ifndef SIOCETHTOOL
-#define SIOCETHTOOL     0x8946
-#endif
 #ifndef MAX_ADDR_LEN
 #define MAX_ADDR_LEN	32
 #endif
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
 
 #ifndef HAVE_NETIF_MSG
 enum {
#8 lore raw

Re: [ethtool PATCH 4/6] Add support for __be64 and bitops to ethtool

Quoted 32 lines · Alexander Duyck

This change is meant to add support for __be64 values and bitops to ethtool. These changes will be needed in order to support network flow classifier rule configuration.

---

 ethtool-bitops.h |   25 +++++++++++++++++++++++++
 ethtool-util.h   |   30 ++++++++++++++++++++++++++----
 ethtool.c        |    7 -------
 3 files changed, 51 insertions(+), 11 deletions(-)
 create mode 100644 ethtool-bitops.h
ethtool-bitops.h new file +13 -0
new file mode 100644
index 0000000..0ff14f1
@@ -0,0 +1,25 @@
+#ifndef ETHTOOL_BITOPS_H__
+#define ETHTOOL_BITOPS_H__
+
+#define BITS_PER_BYTE		8
+#define BITS_PER_LONG		(BITS_PER_BYTE * sizeof(long))
+#define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
+#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_LONG)
+
+static inline void set_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG] |= 1UL << (nr % BITS_PER_LONG);
+}
+

ethtool-bitops.h line 23

Quoted 10 lines
ethtool-bitops.h new file +10 -0
+static inline void clear_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG] &= ~(1UL << (nr % BITS_PER_LONG));
+}
+
+static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
+{
+	return !!((1UL << (nr % BITS_PER_LONG)) &
+		  (((unsigned long *)addr)[nr / BITS_PER_LONG]));
+}

Where is __always_inline supposed to be defined?

Quoted 13 lines
ethtool-bitops.h new file +1 -0
+#endif
ethtool-util.h +4 -0
index f053028..3d46faf 100644
@@ -5,15 +5,18 @@
 
 #include <sys/types.h>
 #include <endian.h>
+#include <sys/ioctl.h>
+#include <net/if.h>
+#include "ethtool-config.h"
+#include "ethtool-copy.h"

ethtool-util.h line 16

Quoted 10 lines
ethtool-util.h +1 -2
 
 /* ethtool.h expects these to be defined by <linux/types.h> */
 #ifndef HAVE_BE_TYPES
 typedef __uint16_t __be16;
 typedef __uint32_t __be32;
+typedef unsigned long long __be64;
 #endif
 
-#include "ethtool-copy.h"
-

You can't move the inclusion of ethtool-copy.h; that defeats the whole purpose of the HAVE_BE_TYPES feature test.

[...]

Quoted 21 lines
ethtool-util.h +6 -0
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#ifndef SIOCETHTOOL
+#define SIOCETHTOOL     0x8946
 #endif
 
 /* National Semiconductor DP83815, DP83816 */
ethtool.c +0 -3
index 9ad7000..15af86a 100644
@@ -45,16 +45,9 @@
 #include <linux/sockios.h>
 #include "ethtool-util.h"
 
-
-#ifndef SIOCETHTOOL
-#define SIOCETHTOOL     0x8946

ethtool.c line 53

Quoted 10 lines
ethtool.c +0 -4
-#endif
 #ifndef MAX_ADDR_LEN
 #define MAX_ADDR_LEN	32
 #endif
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
 
 #ifndef HAVE_NETIF_MSG
 enum {

Presumably this is needed by the next patch, but it has nothing to do with what the commit message says.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#9 lore raw

Re: [ethtool PATCH 4/6] Add support for __be64 and bitops to ethtool

Quoted 37 lines · Ben Hutchings
Quoted 36 lines · Alexander Duyck

This change is meant to add support for __be64 values and bitops to ethtool. These changes will be needed in order to support network flow classifier rule configuration.

---

  ethtool-bitops.h |   25 +++++++++++++++++++++++++
  ethtool-util.h   |   30 ++++++++++++++++++++++++++----
  ethtool.c        |    7 -------
  3 files changed, 51 insertions(+), 11 deletions(-)

create mode 100644 ethtool-bitops.h

ethtool-bitops.h new file +17 -0
new file mode 100644
index 0000000..0ff14f1
@@ -0,0 +1,25 @@
+#ifndef ETHTOOL_BITOPS_H__
+#define ETHTOOL_BITOPS_H__
+
+#define BITS_PER_BYTE		8
+#define BITS_PER_LONG		(BITS_PER_BYTE * sizeof(long))
+#define DIV_ROUND_UP(n, d)	(((n) + (d) - 1) / (d))
+#define BITS_TO_LONGS(nr)	DIV_ROUND_UP(nr, BITS_PER_LONG)
+
+static inline void set_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG] |= 1UL<<  (nr % BITS_PER_LONG);
+}
+
+static inline void clear_bit(int nr, unsigned long *addr)
+{
+	addr[nr / BITS_PER_LONG]&= ~(1UL<<  (nr % BITS_PER_LONG));
+}
Quoted 8 lines

ethtool-bitops.h line 23

Quoted 6 lines
ethtool-bitops.h new file +6 -0
+
+static __always_inline int test_bit(unsigned int nr, const unsigned long *addr)
+{
+	return !!((1UL<<  (nr % BITS_PER_LONG))&
+		  (((unsigned long *)addr)[nr / BITS_PER_LONG]));
+}

Where is __always_inline supposed to be defined?

Sorry that should have just been inline. I forgot we have to take tools other than gcc into account.

Quoted 21 lines
Quoted 21 lines
ethtool-bitops.h new file +1 -0
+#endif
ethtool-util.h +5 -0
index f053028..3d46faf 100644
@@ -5,15 +5,18 @@
 
  #include<sys/types.h>
  #include<endian.h>
+#include<sys/ioctl.h>
+#include<net/if.h>
+#include "ethtool-config.h"
+#include "ethtool-copy.h"
 
  /* ethtool.h expects these to be defined by<linux/types.h>  */
  #ifndef HAVE_BE_TYPES
  typedef __uint16_t __be16;
  typedef __uint32_t __be32;
+typedef unsigned long long __be64;
  #endif
 
Quoted 5 lines

ethtool-util.h line 16

Quoted 2 lines
ethtool-util.h +0 -2
-#include "ethtool-copy.h"
-

You can't move the inclusion of ethtool-copy.h; that defeats the whole purpose of the HAVE_BE_TYPES feature test.

You're correct. I will get that corrected so that it is located after the definitions of the types. The key bit that mattered was getting ethtool-config.h in there before the type declarations. I need it in place to address the test for HAVE_BE_TYPES.

Quoted 29 lines

[...]

Quoted 28 lines
ethtool-util.h +6 -0
+#ifndef ARRAY_SIZE
+#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
+#endif
+
+#ifndef SIOCETHTOOL
+#define SIOCETHTOOL     0x8946
  #endif
 
  /* National Semiconductor DP83815, DP83816 */
ethtool.c +0 -7
index 9ad7000..15af86a 100644
@@ -45,16 +45,9 @@
  #include<linux/sockios.h>
  #include "ethtool-util.h"
 
-
-#ifndef SIOCETHTOOL
-#define SIOCETHTOOL     0x8946
-#endif
  #ifndef MAX_ADDR_LEN
  #define MAX_ADDR_LEN	32
  #endif
-#ifndef ARRAY_SIZE
-#define ARRAY_SIZE(x) (sizeof(x) / sizeof((x)[0]))
-#endif
 
Quoted 9 lines

ethtool.c line 53

Quoted 3 lines
ethtool.c +0 -0
  #ifndef HAVE_NETIF_MSG
  enum {

Presumably this is needed by the next patch, but it has nothing to do with what the commit message says.

Ben.

Yes. These two moves and the addition of certain headers to the ethtool-util.h were to address the needs of both the rxclass.c file and the ethtool.c file in one central location. I will probably break those off into a separate patch.

On a side note, is there a git tree somewhere I can re-base off of? At this point I know you have pulled in a number of patches and I figure it would be helpful for me to clean up my tree so I am not guessing what is there and what isn't.

Thanks,

Alex

#10 lore raw

Re: [ethtool PATCH 4/6] Add support for __be64 and bitops to ethtool

Quoted 5 lines · Alexander Duyck
Quoted 4 lines · Ben Hutchings
Quoted 3 lines · Alexander Duyck

This change is meant to add support for __be64 values and bitops to ethtool. These changes will be needed in order to support network flow classifier rule configuration.

[...]

Quoted 4 lines
Quoted 1 line

Where is __always_inline supposed to be defined?

Sorry that should have just been inline. I forgot we have to take tools other than gcc into account.

Oh, it's a gcc extension? I read the code before trying to compile it. I've never tested with anything other than gcc but I think it's worth making a small effort to avoid gcc extensions.

[...]

Quoted 4 lines

On a side note, is there a git tree somewhere I can re-base off of? At this point I know you have pulled in a number of patches and I figure it would be helpful for me to clean up my tree so I am not guessing what is there and what isn't.

git://git.kernel.org/pub/scm/network/ethtool/ethtool.git

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#11 lore raw

Re: [ethtool PATCH 4/6] Add support for __be64 and bitops to ethtool

Quoted 17 lines · Ben Hutchings
Quoted 5 lines · Alexander Duyck
Quoted 4 lines · Ben Hutchings
Quoted 3 lines · Alexander Duyck

This change is meant to add support for __be64 values and bitops to ethtool. These changes will be needed in order to support network flow classifier rule configuration.

[...]

Quoted 4 lines
Quoted 1 line

Where is __always_inline supposed to be defined?

Sorry that should have just been inline. I forgot we have to take tools other than gcc into account.

Oh, it's a gcc extension? I read the code before trying to compile it. I've never tested with anything other than gcc but I think it's worth making a small effort to avoid gcc extensions.

[...]

Quoted 9 lines
Quoted 4 lines

On a side note, is there a git tree somewhere I can re-base off of? At this point I know you have pulled in a number of patches and I figure it would be helpful for me to clean up my tree so I am not guessing what is there and what isn't.

git://git.kernel.org/pub/scm/network/ethtool/ethtool.git

Ben.

I just saw the updates pushed to the tree. Thanks. I'll start working on incorporating the suggestions you made and should have an updated version of the remaining patches ready in the next day or so.

Thanks,

Alex

#12 lore raw

PATCH 5/6 v4 Add RX packet classification interface

In reply to Alexander Duyck

From: Santwona Behera <[email protected]>

This patch was originally introduced as:
[PATCH 1/3] [ethtool] Add rx pkt classification interface

http://patchwork.ozlabs.org/patch/23223/

v2:
I have updated it to address a number of issues. As a result I removed the local caching of rules due to the fact that there were memory leaks in this code and the rule manager would consume over 1Mb of space for an 8K table when all that was needed was 1K in order to store which rules were active and which were not.

In addition I dropped the use of regions as there were multiple issue found including the fact that the regions were not properly expanding beyond 2 and the fact that the regions required reading all of the rules in order to correctly expand beyond 2. By dropping the regions from the rule manager it is possible to write a much cleaner interface leaving region management to be done by either the driver or by external management scripts.

v3:
The latest update to this patch now inverts the masks to match the mask types used for n-tuple. As such a network flow classifier is defined using the exact same syntax as n-tuple, and the tool will correct for the fact that NFC uses the 1's compliment of the n-tuple mask.

I also updated the ordering of new rules being added. All new rules will take the highest numbered open rule when no location is specified.

Since NFC now uses the same syntax as n-tuple I added code such that now when location is not specified the -U option will first try to add a new n-tuple rule, and if that fails with a ENOTSUPP it will then try to add the rule via the NFC interface.

Finally I split out the addition of bitops and the updates to documentation into separate patches. This makes the total patch size a bit more manageable since the addition of NFC and the merging of it with n-tuple were combined into this patch.

v4:
This change merges the ntuple and network flow classifier rules so that if we setup a rule and the device has the NTUPLE flag set we will first try to use set_rx_ntuple. If that fails with EOPNOTSUPP we then will attempt to use the network flow classifier rule insertion. This way we can support legacy configurations such as niu on kernels prior to 2.6.40 that support network flow classifier but not ntuple, but for drivers such as ixgbe we can test for ntuple first, and then network flow classifier.

This patch has also updated the output to make use of the updated network flow classifier extensions that have been accepted into the kernel.

---

 Makefile.am    |    3 
 ethtool-util.h |   14 +
 ethtool.c      |  357 ++++++++++--------
 rxclass.c      | 1106 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 1318 insertions(+), 162 deletions(-)
 create mode 100644 rxclass.c
Makefile.am +2 -1
index a0d2116..0262c31 100644
@@ -8,7 +8,8 @@ ethtool_SOURCES = ethtool.c ethtool-copy.h ethtool-util.h	\
 		  amd8111e.c de2104x.c e100.c e1000.c igb.c	\
 		  fec_8xx.c ibm_emac.c ixgb.c ixgbe.c natsemi.c	\
 		  pcnet32.c realtek.c tg3.c marvell.c vioc.c	\
-		  smsc911x.c at76c50x-usb.c sfc.c stmmac.c
+		  smsc911x.c at76c50x-usb.c sfc.c stmmac.c	\
+		  rxclass.c
 
 dist-hook:
 	cp $(top_srcdir)/ethtool.spec $(distdir)
ethtool-util.h +13 -1
index 3d46faf..adf8fcc 100644
@@ -62,6 +62,8 @@ static inline u64 cpu_to_be64(u64 value)
 #define SIOCETHTOOL     0x8946
 #endif
 
+#define	RX_CLS_LOC_UNSPEC	0xffffffffUL
+
 /* National Semiconductor DP83815, DP83816 */
 int natsemi_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
 int natsemi_dump_eeprom(struct ethtool_drvinfo *info,
@@ -125,4 +127,14 @@ int sfc_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
 int st_mac100_dump_regs(struct ethtool_drvinfo *info,
 			struct ethtool_regs *regs);
 int st_gmac_dump_regs(struct ethtool_drvinfo *info, struct ethtool_regs *regs);
-#endif
+
+/* Rx flow classification */
+int rxclass_parse_ruleopts(char **optstr, int opt_cnt,
+			   struct ethtool_rx_flow_spec *fsp);
+int rxclass_rule_getall(int fd, struct ifreq *ifr);
+int rxclass_rule_get(int fd, struct ifreq *ifr, __u32 loc);
+int rxclass_rule_ins(int fd, struct ifreq *ifr,
+		     struct ethtool_rx_flow_spec *fsp);
+int rxclass_rule_del(int fd, struct ifreq *ifr, __u32 loc);
+
+#endif /* ETHTOOL_UTIL_H__ */
ethtool.c +197 -160

471 lines not on this page · raw message

rxclass.c new file +1106 -0

1,106 lines not on this page · raw message

#13 lore raw

Re: [ethtool PATCH 5/6] v4 Add RX packet classification interface

On Thu, 2011-04-21 at 13:40 -0700, Alexander Duyck wrote:
[...]

Quoted 4 lines
ethtool.c +0 -0
index 15af86a..421fe20 100644

[...]

Quoted 14 lines
ethtool.c +1 -3
@@ -926,16 +862,45 @@ static void parse_cmdline(int argc, char **argp)
 				i = argc;
 				break;
 			}
-			if (mode == MODE_SNTUPLE) {
+			if (mode == MODE_SCLSRULE) {
 				if (!strcmp(argp[i], "flow-type")) {
 					i += 1;
 					if (i >= argc) {
 						exit_bad_args();
 						break;
 					}
-					parse_rxntupleopts(argc, argp, i);
-					i = argc;

ethtool.c static void parse_cmdline(int argc, char **argp) · line 880

Quoted 10 lines
ethtool.c +9 -1
-					break;
+					if (rxclass_parse_ruleopts(&argp[i],
+							argc - i,
+							&rx_rule_fs) < 0) {
+						exit_bad_args();
+					} else {
+						i = argc;
+						rx_class_rule_added = 1;
+					}
+				} else if (!strcmp(argp[i], "class-rule-del")) {

A shorter keyword like 'delete' would do, since the -U option is only used for flow classification.

Quoted 5 lines
ethtool.c +5 -0
+					i += 1;
+					if (i >= argc) {
+						exit_bad_args();
+						break;
+					}

ethtool.c static void parse_cmdline(int argc, char **argp) · line 895

Quoted 10 lines
ethtool.c +10 -0
+					rx_class_rule_del =
+						get_uint_range(argp[i], 0,
+							       INT_MAX);
+				} else {
+					exit_bad_args();
+				}
+				break;
+			}
+			if (mode == MODE_GCLSRULE) {
+				if (!strcmp(argp[i], "class-rule")) {

This keyword seems redundant.

[...]

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3074

Quoted 8 lines
ethtool.c +4 -0
@@ -3163,21 +3068,130 @@ static int do_permaddr(int fd, struct ifreq *ifr)
 	return err;
 }
 
+static int flow_spec_to_ntuple(struct ethtool_rx_flow_spec *fsp,
+			       struct ethtool_rx_ntuple_flow_spec *ntuple)
+{
+	int i;

Should be size_t, since it's compared with a sizeof() expression.

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3083

Quoted 8 lines
ethtool.c +8 -0
+	/* verify location is not specified */
+	if (fsp->location != RX_CLS_LOC_UNSPEC)
+		return -1;
+
+	/* verify ring cookie can transfer to action */
+	if (fsp->ring_cookie > INT_MAX &&
+	    ~fsp->ring_cookie > 1)
+		return -1;

The second part of this condition would be more clearly expressed as:

	fsp->ring_cookie < (u64)(-2)

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3092

Quoted 8 lines
ethtool.c +8 -0
+	/* verify only one field is setting data field */
+	if ((fsp->flow_type & FLOW_EXT) &&
+	    (fsp->m_ext.data[0] || fsp->m_ext.data[1]) &&
+	    fsp->m_ext.vlan_etype)
+		return -1;
+
+	/* initialize entire ntuple to all 0xFF */
+	memset(ntuple, ~0, sizeof(*ntuple));

The comment needs to explain *why* the value is ~0 rather than 0. I assume the idea is to set the masks to ~0 if they are not initialised below.

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3099

Quoted 6 lines
ethtool.c +6 -0
+	/* set non-filter values */
+	ntuple->flow_type = fsp->flow_type;
+	ntuple->action = fsp->ring_cookie;
+
+	/* copy header portion over */
+	memcpy(&ntuple->h_u, &fsp->h_u, sizeof(fsp->h_u));

This deserves a comment that the two h_u fields are different unions, but are defined identically except for padding at the end.

Quoted 17 lines
ethtool.c +17 -0
+	/* copy mask portion over and invert */
+	memcpy(&ntuple->m_u, &fsp->m_u, sizeof(fsp->m_u));
+	for (i = 0; i < sizeof(fsp->m_u); i++)
+		ntuple->m_u.hdata[i] ^= 0xFF;
+
+	/* copy extended fields */
+	if (fsp->flow_type & FLOW_EXT) {
+		ntuple->vlan_tag =
+			ntohs(fsp->h_ext.vlan_tci);
+		ntuple->vlan_tag_mask =
+			~ntohs(fsp->m_ext.vlan_tci);
+		if (fsp->m_ext.vlan_etype) {
+			ntuple->data =
+				ntohl(fsp->h_ext.vlan_etype);
+			ntuple->data_mask =
+				~(u64)ntohl(fsp->m_ext.vlan_etype);
+		} else {

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3127

Quoted 10 lines
ethtool.c +10 -0
+			ntuple->data =
+				(u64)ntohl(fsp->h_ext.data[0]);
+			ntuple->data |=
+				(u64)ntohl(fsp->h_ext.data[1]) << 32;
+			ntuple->data_mask =
+				(u64)ntohl(~fsp->m_ext.data[0]);
+			ntuple->data_mask |=
+				(u64)ntohl(~fsp->m_ext.data[1]) << 32;
+		}
+	}

I think it would be clearer to add:

	else {
		ntuple->vlan_tag_mask = ~(u16)0;
		ntuple->data_mask = ~(u64)0;
	}

rather than use memset() above.

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3138

Quoted 12 lines
ethtool.c +6 -2
+	return 0;
+}
+
 static int do_srxntuple(int fd, struct ifreq *ifr)
 {
+	struct ethtool_rx_ntuple ntuplecmd;
+	struct ethtool_value eval;
 	int err;
 
-	if (sntuple_changed) {
-		struct ethtool_rx_ntuple ntuplecmd;
+	/* verify if Ntuple is supported on the HW */

This comment is inaccurate.

Quoted 45 lines
ethtool.c +36 -7
+	err = flow_spec_to_ntuple(&rx_rule_fs, &ntuplecmd.fs);
+	if (err)
+		return -1;
+
+	/*
+	 * Check to see if the flag is set for N-tuple, this allows
+	 * us to avoid the possible EINVAL response for the N-tuple
+	 * flag not being set on the device
+	 */
+	eval.cmd = ETHTOOL_GFLAGS;
+	ifr->ifr_data = (caddr_t)&eval;
+	err = ioctl(fd, SIOCETHTOOL, ifr);
+	if (err || !(eval.data & ETH_FLAG_NTUPLE))
+		return -1;
 
-		ntuplecmd.cmd = ETHTOOL_SRXNTUPLE;
-		memcpy(&ntuplecmd.fs, &ntuple_fs,
-		       sizeof(struct ethtool_rx_ntuple_flow_spec));
+	/* send rule via N-tuple */
+	ntuplecmd.cmd = ETHTOOL_SRXNTUPLE;
+	ifr->ifr_data = (caddr_t)&ntuplecmd;
+	err = ioctl(fd, SIOCETHTOOL, ifr);
 
-		ifr->ifr_data = (caddr_t)&ntuplecmd;
-		err = ioctl(fd, SIOCETHTOOL, ifr);
-		if (err < 0)
-			perror("Cannot add new RX n-tuple filter");
+	/*
+	 * Display error only if reponse is something other than op not
+	 * supported.  It is possible that the interface uses the network
+	 * flow classifier interface instead of N-tuple. 
+	 */ 
+	if (err && errno != EOPNOTSUPP)
+		perror("Cannot add new rule via N-tuple");
+
+	return err;
+}
+
+static int do_srxclsrule(int fd, struct ifreq *ifr)
+{
+	int err;
+
+	if (rx_class_rule_added) {
+		/* attempt to add rule via N-tuple specifier */
+		err = do_srxntuple(fd, ifr);

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3186

Quoted 10 lines
ethtool.c +10 -0
+		if (!err)
+			return 0;
+
+		/* attempt to add rule via network flow classifier */
+		err = rxclass_rule_ins(fd, ifr, &rx_rule_fs);
+		if (err < 0) {
+			fprintf(stderr, "Cannot insert"
+				" classification rule\n");
+			return 1;
+		}

Is this the right order to try them? I'm not sure.

Quoted 11 lines
ethtool.c +8 -0
+	} else if (rx_class_rule_del >= 0) {
+		err = rxclass_rule_del(fd, ifr, rx_class_rule_del);
+
+		if (err < 0) {
+			fprintf(stderr, "Cannot delete"
+				" classification rule\n");
+			return 1;
+		}
 	} else {
 		exit_bad_args();
 	}

[...]

Quoted 31 lines
rxclass.c new file +25 -0
new file mode 100644
index 0000000..5ad0639
@@ -0,0 +1,1106 @@
+/*
+ * Copyright (C) 2008 Sun Microsystems, Inc. All rights reserved.
+ */
+#include <stdio.h>
+#include <stdint.h>
+#include <stddef.h>
+#include <stdlib.h>
+#include <string.h>
+#include <errno.h>
+
+#include <linux/sockios.h>
+#include <arpa/inet.h>
+#include "ethtool-util.h"
+#include "ethtool-bitops.h"
+
+/*
+ * This is a rule manager implementation for ordering rx flow
+ * classification rules in a longest prefix first match order.
+ * The assumption is that this rule manager is the only one adding rules to
+ * the device's hardware classifier.
+ */
+
+struct rmgr_ctrl {
+	/* slot contains a bitmap indicating which filters are valid */
+	unsigned long		*slot;

rxclass.c line 35

Quoted 10 lines
rxclass.c new file +10 -0
+	__u32			n_rules;
+	__u32			size;
+};
+
+static struct rmgr_ctrl rmgr;
+static int rmgr_init_done = 0;
+
+static void invert_flow_mask(struct ethtool_rx_flow_spec *fsp)
+{
+	int i;

Should be size_t, since it's compared with a sizeof() expression.

Quoted 13 lines
rxclass.c new file +13 -0
+	for (i = 0; i < sizeof(fsp->m_u); i++)
+		fsp->m_u.hdata[i] ^= 0xFF;
+}
+
+static void rmgr_print_nfc_spec_ext(struct ethtool_rx_flow_spec *fsp)
+{
+	u64 data, datam;
+	__u16 etype, etypem, tci, tcim;
+
+	if (!(fsp->flow_type & FLOW_EXT))
+		return;
+
+	etype = ntohs(fsp->h_ext.vlan_etype);

rxclass.c line 59

Quoted 10 lines
rxclass.c new file +10 -0
+	etypem = ntohs(~fsp->m_ext.vlan_etype);
+	tci = ntohs(fsp->h_ext.vlan_tci);
+	tcim = ntohs(~fsp->m_ext.vlan_tci);
+	data = (u64)ntohl(fsp->h_ext.data[0]) << 32;
+	data = (u64)ntohl(fsp->h_ext.data[1]);
+	datam = (u64)ntohl(~fsp->m_ext.data[0]) << 32;
+	datam |= (u64)ntohl(~fsp->m_ext.data[1]);
+
+	fprintf(stdout,
+		"\tVLAN EtherType: 0x%x mask: 0x%x\n"

Lower-case 'ethertype', please.

rxclass.c line 61

Quoted 2 lines
rxclass.c new file +2 -0
+		"\tVLAN: 0x%x mask: 0x%x\n"
+		"\tUser-defined: 0x%Lx mask: 0x%Lx\n",

'L' is not documented as an integer modifier for printf(). Use 'll' instead.

Quoted 19 lines
rxclass.c new file +19 -0
+		etype, etypem, tci, tcim, data, datam);
+}
+
+static void rmgr_print_nfc_rule(struct ethtool_rx_flow_spec *fsp)
+{
+	unsigned char	*smac, *smacm, *dmac, *dmacm;
+	__u32		sip, dip, sipm, dipm, flow_type;
+	__u16		proto, protom;
+
+	if (fsp->location != RX_CLS_LOC_UNSPEC)
+		fprintf(stdout,	"Filter: %d\n", fsp->location);
+	else
+		fprintf(stdout,	"Filter: Unspecified\n");
+
+	flow_type = fsp->flow_type & ~FLOW_EXT;
+
+	invert_flow_mask(fsp);
+
+	switch (flow_type) {

rxclass.c line 90

Quoted 10 lines
rxclass.c new file +10 -0
+	case TCP_V4_FLOW:
+	case UDP_V4_FLOW:
+	case SCTP_V4_FLOW:
+	case AH_V4_FLOW:
+	case ESP_V4_FLOW:
+	case IP_USER_FLOW:
+		sip = ntohl(fsp->h_u.tcp_ip4_spec.ip4src);
+		dip = ntohl(fsp->h_u.tcp_ip4_spec.ip4dst);
+		sipm = ntohl(fsp->m_u.tcp_ip4_spec.ip4src);
+		dipm = ntohl(fsp->m_u.tcp_ip4_spec.ip4dst);

I think this will work for AH_V4, ESP_V4 and IP_USER due to similar structure layout, but it's kind of dodgy. Please handle each structure type separately.

[...]

Quoted 18 lines
rxclass.c new file +18 -0
+static int rmgr_del(__u32 loc)
+{
+	/* verify rule exists before attempting to delete */
+	int err = rmgr_find(loc);
+	if (err)
+		return err;
+
+	/* clear bit for the rule */
+	clear_bit(loc, rmgr.slot);
+
+	return 0;
+}
+
+static int rmgr_add(struct ethtool_rx_flow_spec *fsp)
+{
+	__u32 loc = fsp->location;
+
+	/* location provided, insert rule and update regions to match rule */

rxclass.c line 297

Quoted 10 lines
rxclass.c new file +10 -0
+	if (loc != RX_CLS_LOC_UNSPEC)
+		return rmgr_ins(loc);
+
+	/* start at the end of the list since it is lowest priority */
+	loc = rmgr.size - 1;
+
+	/* only part of last word is set so fill in remaining bits and test */
+	if (!~(rmgr.slot[loc / BITS_PER_LONG] |
+	       (~1UL << (loc % BITS_PER_LONG))))
+		loc -= 1 + (loc % BITS_PER_LONG);

I think this is meant to avoid the need to search for bits in a partial word but it's a very non-obvious way to do that.

rxclass.c line 301

Quoted 3 lines
rxclass.c new file +3 -0
+	/* find an open slot */
+	while (loc != RX_CLS_LOC_UNSPEC && !~rmgr.slot[loc / BITS_PER_LONG])
+		loc -= BITS_PER_LONG;

Just because RX_CLS_LOC_UNSPEC happens to be equal to -1 doesn't mean it's a good idea to use the name here!

rxclass.c line 311

Quoted 9 lines
rxclass.c new file +9 -0
+	/* find and use available location in slot */
+	while (loc != RX_CLS_LOC_UNSPEC && test_bit(loc, rmgr.slot))
+		loc--;
+
+       /* location found, insert rule */
+       if (loc != RX_CLS_LOC_UNSPEC) {
+               fsp->location = loc;
+               return rmgr_ins(loc);
+       }

I think it would be clearer to use a separate word index:

	__u32 loc;
	int i;

	/* location provided, insert rule and update regions to match rule */
	if (fs->location != RX_CLS_LOC_UNSPEC)
		return rmgr_ins(fs->location);

	/* start at the end of the list since it is lowest priority */
	for (i = rmgr.size / BITS_PER_LONG - 1; i >= 0; i--) {
		if (~rmgr.slot[i]) {
			loc = i * BITS_PER_LONG - 1;
			while (test_bit(loc, rmgr.slot))
				loc--;

			/* location found, insert rule */
			fsp->location = loc;
			return rmgr_ins(loc);
		}
	}

[...]

Quoted 6 lines
rxclass.c new file +6 -0
+int rxclass_rule_getall(int fd, struct ifreq *ifr)
+{
+	struct ethtool_rxnfc nfccmd;
+	int err, i, j;
+
+	/* init table of available rules */

rxclass.c line 418

Quoted 10 lines
rxclass.c new file +10 -0
+	err = rmgr_init(fd, ifr);
+	if (err < 0)
+		return err;
+
+	fprintf(stdout, "Total %d rules\n\n", rmgr.n_rules);
+
+	/* fetch and display all available rules */
+	for (i = 0; i < rmgr.size; i += BITS_PER_LONG) {
+		if (!~rmgr.slot[i / BITS_PER_LONG])
+			continue;

The '~' is wrong. We want to skip words where all bits are clear, not where all bits are set.

[...]

Quoted 4 lines
rxclass.c new file +4 -0
+int rxclass_rule_get(int fd, struct ifreq *ifr, __u32 loc)
+{
+	struct ethtool_rxnfc nfccmd;
+	int err;

rxclass.c line 454

Quoted 10 lines
rxclass.c new file +10 -0
+
+	/* init table of available rules */
+	err = rmgr_init(fd, ifr);
+	if (err < 0)
+		return err;
+
+	/* verify rule exists before attempting to display */
+	err = rmgr_find(loc);
+	if (err < 0)
+		return err;

Is this really necessary? Shouldn't we let the driver check that for us, and save the cost of initialising the rule manager?

[...]

Quoted 16 lines
rxclass.c new file +16 -0
+int rxclass_rule_ins(int fd, struct ifreq *ifr,
+		     struct ethtool_rx_flow_spec *fsp)
+{
+	struct ethtool_rxnfc nfccmd;
+	int err;
+
+	/* init table of available rules */
+	err = rmgr_init(fd, ifr);
+	if (err < 0)
+		return err;
+
+	/* verify rule location */
+	err = rmgr_add(fsp);
+	if (err < 0)
+		return err;
+

rxclass.c line 498

Quoted 10 lines
rxclass.c new file +10 -0
+	/* notify netdev of new rule */
+	nfccmd.cmd = ETHTOOL_SRXCLSRLINS;
+	nfccmd.fs = *fsp;
+	ifr->ifr_data = (caddr_t)&nfccmd;
+	err = ioctl(fd, SIOCETHTOOL, ifr);
+	if (err < 0) {
+		perror("rmgr: Cannot insert RX class rule");
+		return -1;
+	}
+	rmgr.n_rules++;

If we're about to destroy the rule manager immediately afterwards, why bother maintaining n_rules?

Quoted 11 lines
rxclass.c new file +11 -0
+	printf("Added rule with ID %d\n", fsp->location);
+
+	rmgr_cleanup();
+
+	return 0;
+}
+
+int rxclass_rule_del(int fd, struct ifreq *ifr, __u32 loc)
+{
+	struct ethtool_rxnfc nfccmd;
+	int err;

rxclass.c line 520

Quoted 10 lines
rxclass.c new file +10 -0
+
+	/* init table of available rules */
+	err = rmgr_init(fd, ifr);
+	if (err < 0)
+		return err;
+
+	/* verify rule exists */
+	err = rmgr_del(loc);
+	if (err < 0)
+		return err;

Again, I think that can be left to the driver.

[...]

Quoted 24 lines
rxclass.c new file +24 -0
+typedef enum {
+	OPT_NONE = 0,
+	OPT_S32,
+	OPT_U8,
+	OPT_U16,
+	OPT_U32,
+	OPT_U64,
+	OPT_BE16,
+	OPT_BE32,
+	OPT_BE64,
+	OPT_IP4,
+	OPT_MAC,
+} rule_opt_type_t;
+
+#define NFC_FLAG_RING		0x001
+#define NFC_FLAG_LOC		0x002
+#define NFC_FLAG_SADDR		0x004
+#define NFC_FLAG_DADDR		0x008
+#define NFC_FLAG_SPORT		0x010
+#define NFC_FLAG_DPORT		0x020
+#define NFC_FLAG_SPI		0x030
+#define NFC_FLAG_TOS		0x040
+#define NFC_FLAG_PROTO		0x080
+#define NTUPLE_FLAG_VLAN	0x100

rxclass.c line 571

Quoted 10 lines
rxclass.c new file +10 -0
+#define NTUPLE_FLAG_UDEF	0x200
+#define NTUPLE_FLAG_VETH	0x400
+
+struct rule_opts {
+	const char	*name;
+	rule_opt_type_t	type;
+	u32		flag;
+	int		offset;
+	int		moffset;
+};

I think that this ought to be merged with the argument parsing in ethtool.c, but I won't insist that you do that immedaitely. However:

[...]

Quoted 7 lines
rxclass.c new file +7 -0
+static int rxclass_get_ipv4(char *str, __be32 *val)
+{
+	if (!strchr(str, '.')) {
+		unsigned long long v;
+		int err;
+
+		err = rxclass_get_ulong(str, &v, 32);

rxclass.c line 740

Quoted 10 lines
rxclass.c new file +10 -0
+		if (err)
+			return -1;
+
+		*val = htonl((u32)v);
+
+		return 0;
+	}
+
+	if (!inet_pton(AF_INET, str, val))
+		return -1;

There's no need to make a special case for integers. inet_aton() should handle all the historically supported IPv4 literal formats.

[...]

rxclass.c line 1000

Quoted 11 lines
rxclass.c new file +11 -0
+int rxclass_parse_ruleopts(char **argp, int argc,
+			   struct ethtool_rx_flow_spec *fsp)
+{
+	const struct rule_opts *options;
+	unsigned char *p = (unsigned char *)fsp;
+	int i = 0, n_opts, err;
+	u32 flags = 0;
+	int flow_type;
+
+	if (*argp == NULL || **argp == '\0' || argc < 1)
+		goto syntax_err;

argc < 1 is sufficient.

Quoted 29 lines
rxclass.c new file +29 -0
+	if (!strcmp(argp[0], "tcp4"))
+		flow_type = TCP_V4_FLOW;
+	else if (!strcmp(argp[0], "udp4"))
+		flow_type = UDP_V4_FLOW;
+	else if (!strcmp(argp[0], "sctp4"))
+		flow_type = SCTP_V4_FLOW;
+	else if (!strcmp(argp[0], "ah4"))
+		flow_type = AH_V4_FLOW;
+	else if (!strcmp(argp[0], "esp4"))
+		flow_type = ESP_V4_FLOW;
+	else if (!strcmp(argp[0], "ip4"))
+		flow_type = IP_USER_FLOW;
+	else if (!strcmp(argp[0], "ether"))
+		flow_type = ETHER_FLOW;
+	else
+		goto syntax_err;
+
+	switch (flow_type) {
+	case TCP_V4_FLOW:
+	case UDP_V4_FLOW:
+	case SCTP_V4_FLOW:
+		options = rule_nfc_tcp_ip4;
+		n_opts = ARRAY_SIZE(rule_nfc_tcp_ip4);
+		break;
+	case AH_V4_FLOW:
+	case ESP_V4_FLOW:
+		options = rule_nfc_esp_ip4;
+		n_opts = ARRAY_SIZE(rule_nfc_esp_ip4);
+		break;

rxclass.c line 1040

Quoted 10 lines
rxclass.c new file +10 -0
+	case IP_USER_FLOW:
+		options = rule_nfc_usr_ip4;
+		n_opts = ARRAY_SIZE(rule_nfc_usr_ip4);
+		break;
+	case ETHER_FLOW:
+		options = rule_nfc_ether;
+		n_opts = ARRAY_SIZE(rule_nfc_ether);
+		break;
+	default:
+		fprintf(stdout, "Add rule, invalid rule type[%s]\n", argp[0]);

stderr, not stdout

[...]

rxclass.c line 1092

Quoted 2 lines
rxclass.c new file +2 -0
+		if (idx == n_opts) {
+			fprintf(stdout, "Add rule, unreconized option[%s]\n",

Typo: 'unreconized' should be 'unrecognized'.

rxclass.c line 1104

Quoted 12 lines
rxclass.c new file +12 -0
+				argp[i]);
+			return -1;
+		}
+	}
+
+	if (flags & (NTUPLE_FLAG_VLAN | NTUPLE_FLAG_UDEF | NTUPLE_FLAG_VETH))
+		fsp->flow_type |= FLOW_EXT;
+
+	return 0;
+
+syntax_err:
+	fprintf(stdout, "Add rule, invalid syntax\n");

stderr

rxclass.c

Quoted 3 lines
rxclass.c new file +2 -0
+	return -1;
+}

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#14 lore raw

Re: [ethtool PATCH 5/6] v4 Add RX packet classification interface

Quoted 1 line · Ben Hutchings

On Thu, 2011-04-21 at 13:40 -0700, Alexander Duyck wrote:

[...]

Quoted 4 lines

rxclass.c line 59

Quoted 2 lines
rxclass.c new file +2 -0
+	fprintf(stdout,
+		"\tVLAN EtherType: 0x%x mask: 0x%x\n"

Lower-case 'ethertype', please.

[...]

Sorry, your capitalisation here is correct and the existing uses in lower-case are wrong.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#15 lore raw

Re: [ethtool PATCH 5/6] v4 Add RX packet classification interface

In reply to Ben Hutchings
Quoted 1 line · Ben Hutchings

On Thu, 2011-04-21 at 13:40 -0700, Alexander Duyck wrote:

[...]

Quoted 9 lines

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3092

Quoted 8 lines
ethtool.c +8 -0
+     /* verify only one field is setting data field */
+     if ((fsp->flow_type&  FLOW_EXT)&&
+         (fsp->m_ext.data[0] || fsp->m_ext.data[1])&&
+         fsp->m_ext.vlan_etype)
+             return -1;
+
+     /* initialize entire ntuple to all 0xFF */
+     memset(ntuple, ~0, sizeof(*ntuple));
Quoted 3 lines

The comment needs to explain *why* the value is ~0 rather than 0. I assume the idea is to set the masks to ~0 if they are not initialised below.

This has to do with future compatibility and general setup. By setting all of the values to ~0 the rule is essentially set to mask everything and has a default action of drop.

Quoted 9 lines

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr)

Quoted 6 lines
ethtool.c +6 -0
+     /* set non-filter values */
+     ntuple->flow_type = fsp->flow_type;
+     ntuple->action = fsp->ring_cookie;
+
+     /* copy header portion over */
+     memcpy(&ntuple->h_u,&fsp->h_u, sizeof(fsp->h_u));

This deserves a comment that the two h_u fields are different unions, but are defined identically except for padding at the end.

I've added a comment similar to that to the code.

Quoted 28 lines
Quoted 17 lines
ethtool.c +17 -0
+     /* copy mask portion over and invert */
+     memcpy(&ntuple->m_u,&fsp->m_u, sizeof(fsp->m_u));
+     for (i = 0; i<  sizeof(fsp->m_u); i++)
+             ntuple->m_u.hdata[i] ^= 0xFF;
+
+     /* copy extended fields */
+     if (fsp->flow_type&  FLOW_EXT) {
+             ntuple->vlan_tag =
+                     ntohs(fsp->h_ext.vlan_tci);
+             ntuple->vlan_tag_mask =
+                     ~ntohs(fsp->m_ext.vlan_tci);
+             if (fsp->m_ext.vlan_etype) {
+                     ntuple->data =
+                             ntohl(fsp->h_ext.vlan_etype);
+                     ntuple->data_mask =
+                             ~(u64)ntohl(fsp->m_ext.vlan_etype);
+             } else {

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3127

Quoted 10 lines
ethtool.c +10 -0
+                     ntuple->data =
+                             (u64)ntohl(fsp->h_ext.data[0]);
+                     ntuple->data |=
+                             (u64)ntohl(fsp->h_ext.data[1])<<  32;
+                     ntuple->data_mask =
+                             (u64)ntohl(~fsp->m_ext.data[0]);
+                     ntuple->data_mask |=
+                             (u64)ntohl(~fsp->m_ext.data[1])<<  32;
+             }
+     }
Quoted 8 lines

I think it would be clearer to add:

         else {
                 ntuple->vlan_tag_mask = ~(u16)0;
                 ntuple->data_mask = ~(u64)0;
         }

rather than use memset() above.

I thought about doing that, but the advantage of the memset is that it covers all of the fields. So in the unlikely event that someone were to add fields in the future to the h_u/m_u sections of the driver this way we can guarantee all of the fields that we didn't set are masked.

Quoted 9 lines
Quoted 9 lines
ethtool.c +5 -0
+     return 0;
+}
+
  static int do_srxntuple(int fd, struct ifreq *ifr)
  {
+     struct ethtool_rx_ntuple ntuplecmd;
+     struct ethtool_value eval;
       int err;
Quoted 5 lines

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3138

Quoted 3 lines
ethtool.c +1 -2
-     if (sntuple_changed) {
-             struct ethtool_rx_ntuple ntuplecmd;
+     /* verify if Ntuple is supported on the HW */

This comment is inaccurate.

Yeah, it belonged a few lines lower I think it was left over from some earlier work that was there and when I reordered things to do the conversion to ntuple first the comment didn't get moved.

Quoted 49 lines
Quoted 49 lines
ethtool.c +40 -7
+     err = flow_spec_to_ntuple(&rx_rule_fs,&ntuplecmd.fs);
+     if (err)
+             return -1;
+
+     /*
+      * Check to see if the flag is set for N-tuple, this allows
+      * us to avoid the possible EINVAL response for the N-tuple
+      * flag not being set on the device
+      */
+     eval.cmd = ETHTOOL_GFLAGS;
+     ifr->ifr_data = (caddr_t)&eval;
+     err = ioctl(fd, SIOCETHTOOL, ifr);
+     if (err || !(eval.data&  ETH_FLAG_NTUPLE))
+             return -1;
 
-             ntuplecmd.cmd = ETHTOOL_SRXNTUPLE;
-             memcpy(&ntuplecmd.fs,&ntuple_fs,
-                    sizeof(struct ethtool_rx_ntuple_flow_spec));
+     /* send rule via N-tuple */
+     ntuplecmd.cmd = ETHTOOL_SRXNTUPLE;
+     ifr->ifr_data = (caddr_t)&ntuplecmd;
+     err = ioctl(fd, SIOCETHTOOL, ifr);
 
-             ifr->ifr_data = (caddr_t)&ntuplecmd;
-             err = ioctl(fd, SIOCETHTOOL, ifr);
-             if (err<  0)
-                     perror("Cannot add new RX n-tuple filter");
+     /*
+      * Display error only if reponse is something other than op not
+      * supported.  It is possible that the interface uses the network
+      * flow classifier interface instead of N-tuple.
+      */
+     if (err&&  errno != EOPNOTSUPP)
+             perror("Cannot add new rule via N-tuple");
+
+     return err;
+}
+
+static int do_srxclsrule(int fd, struct ifreq *ifr)
+{
+     int err;
+
+     if (rx_class_rule_added) {
+             /* attempt to add rule via N-tuple specifier */
+             err = do_srxntuple(fd, ifr);
+             if (!err)
+                     return 0;
+
+             /* attempt to add rule via network flow classifier */
Quoted 8 lines

ethtool.c static int do_permaddr(int fd, struct ifreq *ifr) · line 3186

Quoted 6 lines
ethtool.c +6 -0
+             err = rxclass_rule_ins(fd, ifr,&rx_rule_fs);
+             if (err<  0) {
+                     fprintf(stderr, "Cannot insert"
+                             " classification rule\n");
+                     return 1;
+             }

Is this the right order to try them? I'm not sure.

The reason why I chose to do it this way was because it is actually fewer steps to try doing an ntuple than it is to do a network flow classifier rule. To fail ntuple I only really need to check the flag, whereas for network flow classifier I end up having to go through the path that does init for any rule add which is significantly more overhead.

All of the other changes you suggested for this patch I think I have implemented for the next version. I'm working on finishing up the updates now. But I think it will take me a day or to in order to sufficient testing so I can be confident all the bugs are worked out after the changes. I'll probably be able to email out the update patches on Friday.

Thanks,

Alex

#16 lore raw

PATCH 6/6 Update documentation for -u/-U operations

In reply to Alexander Duyck

This patch updates the documentation for the -u/-U operations to include the recent changes made to support addition/deletion/display of network flow classifier rules.

---

 ethtool.8.in |  185 +++++++++++++++++++++++++++++-----------------------------
 ethtool.c    |   32 ++++++----
 2 files changed, 111 insertions(+), 106 deletions(-)
ethtool.8.in +92 -93
index 12a1d1d..8908351 100644
@@ -42,10 +42,20 @@
 [\\fB\\$1\\fP\ \\fIN\\fP]
 ..
 .\"
+.\"	.BM - same as above but has a mask field for format "[value N [value-mask N]]"
+.\"
+.de BM
+[\\fB\\$1\\fP\ \\fIN\\fP\ [\\fB\\$1\-mask\\fP\ \\fIN\\fP]]
+..
+.\"
 .\"	\(*MA - mac address
 .\"
 .ds MA \fIxx\fP\fB:\fP\fIyy\fP\fB:\fP\fIzz\fP\fB:\fP\fIaa\fP\fB:\fP\fIbb\fP\fB:\fP\fIcc\fP
 .\"
+.\"	\(*PA - IP address
+.\"
+.ds PA \fIx\fP\fB.\fP\fIx\fP\fB.\fP\fIx\fP\fB.\fP\fIx\fP
+.\"
 .\"	\(*WO - wol flags
 .\"
 .ds WO \fBp\fP|\fBu\fP|\fBm\fP|\fBb\fP|\fBa\fP|\fBg\fP|\fBs\fP|\fBd\fP...
@@ -57,6 +67,12 @@
 .\"	\(*HO - hash options
 .\"
 .ds HO \fBm\fP|\fBv\fP|\fBt\fP|\fBs\fP|\fBd\fP|\fBf\fP|\fBn\fP|\fBr\fP...
+.\"
+.\"	\(*NC - Network Classifier type values
+.\"
+.ds NC \fBether\fP|\fBip4\fP|\fBtcp4\fP|\fBudp4\fP|\fBsctp4\fP|\fBah4\fP|\fBesp4\fP
+
+.\"
 .\" Start URL.
 .de UR
 .  ds m1 \\$1\"
@@ -236,9 +252,9 @@ ethtool \- query or control network driver and hardware settings
 .HP
 .B ethtool \-N
 .I ethX
-.RB [ rx\-flow\-hash \ \*(FL
-.RB \ \*(HO]
+.RB [ rx-flow-hash \ \*(FL \  \*(HO]
 .HP
+
 .B ethtool \-x|\-\-show\-rxfh\-indir
 .I ethX
 .HP
@@ -257,54 +273,28 @@ ethtool \- query or control network driver and hardware settings
 .HP
 .B ethtool \-u|\-\-show\-ntuple
 .I ethX
-.TP
+.BN class-rule
+.HP
+
 .BI ethtool\ \-U|\-\-config\-ntuple \ ethX
-.RB {
-.A3 flow\-type tcp4 udp4 sctp4
-.RB [ src\-ip
-.IR addr
-.RB [ src\-ip\-mask
-.IR mask ]]
-.RB [ dst\-ip
-.IR addr
-.RB [ dst\-ip\-mask
-.IR mask ]]
-.RB [ src\-port
-.IR port
-.RB [ src\-port\-mask
-.IR mask ]]
-.RB [ dst\-port
-.IR port
-.RB [ dst\-port\-mask
-.IR mask ]]
-.br
-.RB | \ flow\-type\ ether
-.RB [ src
-.IR mac\-addr
-.RB [ src\-mask
-.IR mask ]]
-.RB [ dst
-.IR mac\-addr
-.RB [ dst\-mask
-.IR mask ]]
-.RB [ proto
-.IR N
-.RB [ proto\-mask
-.IR mask ]]\ }
-.br
-.RB [ vlan
-.IR VLAN\-tag
-.RB [ vlan\-mask
-.IR mask ]]
-.RB [ user\-def
-.IR data
-.RB [ user\-def\-mask
-.IR mask ]]
-.RI action \ N
-.
-.\" Adjust lines (i.e. full justification) and hyphenate.
-.ad
-.hy
+.BN class-rule-del
+.RB [\  flow-type \ \*(NC
+.RB [ src \ \*(MA\ [ src-mask \ \*(MA]]
+.RB [ dst \ \*(MA\ [ dst-mask \ \*(MA]]
+.BM proto
+.RB [ src-ip \ \*(PA\ [ src-ip-mask \ \*(PA]]
+.RB [ dst-ip \ \*(PA\ [ dst-ip-mask \ \*(PA]]
+.BM tos
+.BM l4proto
+.BM src-port
+.BM dst-port
+.BM spi
+.BM vlan-etype
+.BM vlan
+.BM user-def
+.BN action
+.BN loc
+.RB ]
 
 .SH DESCRIPTION
 .BI ethtool
@@ -630,12 +620,18 @@ Default region is 0 which denotes all regions in the flash.
 .TP
 .B \-u \-\-show\-ntuple
 Get Rx ntuple filters and actions, then display them to the user.
+.TP
+.BI class-rule \ N
+Retrieves the RX classification rule with the given ID.
 .PD
 .RE
 .TP
 .B \-U \-\-config\-ntuple
 Configure Rx ntuple filters and actions
 .TP
+.BI class-rule-del \ N
+Deletes the RX classification rule with the given ID.
+.TP
 .B flow\-type tcp4|udp4|sctp4|ether
 .TS
 nokeep;
@@ -643,64 +639,61 @@ lB	l.
 tcp4	TCP over IPv4
 udp4	UDP over IPv4
 sctp4	SCTP over IPv4
+ah4	IPSEC AH over IPv4
+esp4	IPSEC ESP over IPv4
+ip4	Raw IPv4
 ether	Ethernet
 .TE
 .TP
-.BI src\-ip \ addr
-Includes the source IP address, specified using dotted-quad notation
-or as a single 32-bit number.
-.TP
-.BI src\-ip\-mask \ mask
-Specify a mask for the source IP address.
-.TP
-.BI dst\-ip \ addr
-Includes the destination IP address.
-.TP
-.BI dst\-ip\-mask \ mask
-Specify a mask for the destination IP address.
-.TP
-.BI src\-port \ port
-Includes the source port.
-.TP
-.BI src\-port\-mask \ mask
-Specify a mask for the source port.
+.BR src \ \*(MA\ [ src-mask \ \*(MA]
+Includes the source MAC address, specified as 6 bytes in hexadecimal
+separated by colons, along with an optional mask.
 .TP
-.BI dst\-port \ port
-Includes the destination port.
+.BR dst \ \*(MA\ [ src-mask \ \*(MA]
+Includes the destination MAC address, specified as 6 bytes in hexadecimal
+separated by colons, along with an optional mask.
 .TP
-.BI dst\-port\-mask \ mask
-Specify a mask for the destination port.
+.BI proto \ N \\fR\ [\\fPproto-mask \ N \\fR]\\fP
+Includes the Ethernet protocol number (ethertype) and an optional mask.
 .TP
-.BI src \ mac\-addr
-Includes the source MAC address, specified as 6 bytes in hexadecimal
-separated by colons.
+.BR src-ip \ \*(PA\ [ src-ip-mask \ \*(PA]
+Specify the source IP address of the incoming packet to
+match along with an optional mask.
 .TP
-.BI src\-mask \ mask
-Specify a mask for the source MAC address.
+.BR dst-ip \ \*(PA\ [ dst-ip-mask \ \*(PA]
+Specify the destination IP address of the incoming packet to
+match along with an optional mask.
 .TP
-.BI dst \ mac\-addr
-Includes the destination MAC address.
+.BI tos \ N \\fR\ [\\fPtos-mask \ N \\fR]\\fP
+Specify the value of the Type of Service field in the incoming packet to
+match along with an optional mask.
 .TP
-.BI dst\-mask \ mask
-Specify a mask for the destination MAC address.
+.BI l4proto \ N \\fR\ [\\fPl4proto-mask \ N \\fR]\\fP
+Includes the layer 4 protocol number and optional mask.
 .TP
-.BI proto \ N
-Includes the Ethernet protocol number (ethertype).
+.BI src-port \ N \\fR\ [\\fPsrc-port-mask \ N \\fR]\\fP
+Specify the value of the source port field (applicable to
+TCP/UDP packets)in the incoming packet to match along with an
+optional mask.
 .TP
-.BI proto\-mask \ mask
-Specify a mask for the Ethernet protocol number.
+.BI dst-port \ N \\fR\ [\\fPdst-port-mask \ N \\fR]\\fP
+Specify the value of the destination port field (applicable to
+TCP/UDP packets)in the incoming packet to match along with an
+optional mask.
 .TP
-.BI vlan \ VLAN\-tag
-Includes the VLAN tag.
+.BI spi \ N \\fR\ [\\fPspi-mask \ N \\fR]\\fP
+Specify the value of the security parameter index field (applicable to
+AH/ESP packets)in the incoming packet to match along with an
+optional mask.
 .TP
-.BI vlan\-mask \ mask
-Specify a mask for the VLAN tag.
+.BI vlan-etype \ N \\fR\ [\\fPvlan-etype-mask \ N \\fR]\\fP
+Includes the VLAN tag Ethertype and an optional mask.
 .TP
-.BI user\-def \ data
-Includes 64-bits of user-specific data.
+.BI vlan \ N \\fR\ [\\fPvlan-mask \ N \\fR]\\fP
+Includes the VLAN tag and an optional mask.
 .TP
-.BI user\-def\-mask \ mask
-Specify a mask for the user-specific data.
+.BI user-def \ N \\fR\ [\\fPuser-def-mask \ N \\fR]\\fP
+Includes 64-bits of user-specific data and an optional mask.
 .TP
 .BI action \ N
 Specifies the Rx queue to send packets to, or some other action.
@@ -711,6 +704,11 @@ lB	l.
 -1	Drop the matched flow
 0 or higher	Rx queue to route the flow
 .TE
+.TP
+.BI loc \ N
+Specify the location/ID to insert the rule. This will overwrite
+any rule present in that location and will not go through any
+of the rule ordering process.
 .SH BUGS
 Not supported (in part or whole) on all network drivers.
 .SH AUTHOR
@@ -724,7 +722,8 @@ Jakub Jelinek,
 Andre Majorel,
 Eli Kupermann,
 Scott Feldman,
-Andi Kleen.
+Andi Kleen,
+Alexander Duyck.
 .SH AVAILABILITY
 .B ethtool
 is available from
ethtool.c +19 -13
index 421fe20..e65979d 100644
@@ -243,20 +243,26 @@ static struct option {
 		"		equal N | weight W0 W1 ...\n" },
     { "-U", "--config-ntuple", MODE_SCLSRULE, "Configure Rx ntuple filters "
 		"and actions",
-		"		{ flow-type tcp4|udp4|sctp4\n"
-		"		  [ src-ip ADDR [src-ip-mask MASK] ]\n"
-		"		  [ dst-ip ADDR [dst-ip-mask MASK] ]\n"
-		"		  [ src-port PORT [src-port-mask MASK] ]\n"
-		"		  [ dst-port PORT [dst-port-mask MASK] ]\n"
-		"		| flow-type ether\n"
-		"		  [ src MAC-ADDR [src-mask MASK] ]\n"
-		"		  [ dst MAC-ADDR [dst-mask MASK] ]\n"
-		"		  [ proto N [proto-mask MASK] ] }\n"
-		"		[ vlan VLAN-TAG [vlan-mask MASK] ]\n"
-		"		[ user-def DATA [user-def-mask MASK] ]\n"
-		"		action N\n" },
+		"		[ class-rule-del %d ] |\n"
+		"		[ flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4\n"
+		"			[ src %x:%x:%x:%x:%x:%x [src-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ dst %x:%x:%x:%x:%x:%x [dst-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ proto %d [proto-mask MASK] ]\n"
+		"			[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ tos %d [tos-mask %x] ]\n"
+		"			[ l4proto %d [l4proto-mask MASK] ]\n"
+		"			[ src-port %d [src-port-mask %x] ]\n"
+		"			[ dst-port %d [dst-port-mask %x] ]\n"
+		"			[ spi %d [spi-mask %x] ]\n"
+		"			[ vlan-etype %x [vlan-etype-mask %x] ]\n"
+		"			[ vlan %x [vlan-mask %x] ]\n"
+		"			[ user-def %x [user-def-mask %x] ]\n"
+		"			[ action %d ]\n"
+		"			[ loc %d]]\n" },
     { "-u", "--show-ntuple", MODE_GCLSRULE,
-		"Get Rx ntuple filters and actions\n" },
+		"Get Rx ntuple filters and actions",
+		"		[ class-rule %d ]\n"},
     { "-P", "--show-permaddr", MODE_PERMADDR,
 		"Show permanent hardware address" },
     { "-h", "--help", MODE_HELP, "Show this help" },
#17 lore raw

Re: [ethtool PATCH 6/6] Update documentation for -u/-U operations

Quoted 3 lines · Alexander Duyck

This patch updates the documentation for the -u/-U operations to include the recent changes made to support addition/deletion/display of network flow classifier rules.

This should be included in the same patch.

Quoted 12 lines

---

 ethtool.8.in |  185 +++++++++++++++++++++++++++++-----------------------------
 ethtool.c    |   32 ++++++----
 2 files changed, 111 insertions(+), 106 deletions(-)
ethtool.8.in +0 -0
index 12a1d1d..8908351 100644

ethtool.8.in line 48

Quoted 7 lines
ethtool.8.in +4 -0
@@ -42,10 +42,20 @@
 [\\fB\\$1\\fP\ \\fIN\\fP]
..
 .\"
+.\"	.BM - same as above but has a mask field for format "[value N [value-mask N]]"
+.\"
+.de BM
+[\\fB\\$1\\fP\ \\fIN\\fP\ [\\fB\\$1\-mask\\fP\ \\fIN\\fP]]

You've changed the code to accept 'm' as an alternative to <field> '-mask', so this should be changed accordingly.

[...]

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 257

Quoted 9 lines
ethtool.8.in +2 -2
@@ -236,9 +252,9 @@ ethtool \- query or control network driver and hardware settings
 .HP
 .B ethtool \-N
 .I ethX
-.RB [ rx\-flow\-hash \ \*(FL
-.RB \ \*(HO]
+.RB [ rx-flow-hash \ \*(FL \  \*(HO]
 .HP
+

This looks like an unintentional reversion of part of commit db6c0cee6cd956767e1c39109fe81104cc4694cb.

Quoted 48 lines
ethtool.8.in +3 -37
 .B ethtool \-x|\-\-show\-rxfh\-indir
 .I ethX
 .HP
@@ -257,54 +273,28 @@ ethtool \- query or control network driver and hardware settings
 .HP
 .B ethtool \-u|\-\-show\-ntuple
 .I ethX
-.TP
+.BN class-rule
+.HP
+
 .BI ethtool\ \-U|\-\-config\-ntuple \ ethX
-.RB {
-.A3 flow\-type tcp4 udp4 sctp4
-.RB [ src\-ip
-.IR addr
-.RB [ src\-ip\-mask
-.IR mask ]]
-.RB [ dst\-ip
-.IR addr
-.RB [ dst\-ip\-mask
-.IR mask ]]
-.RB [ src\-port
-.IR port
-.RB [ src\-port\-mask
-.IR mask ]]
-.RB [ dst\-port
-.IR port
-.RB [ dst\-port\-mask
-.IR mask ]]
-.br
-.RB | \ flow\-type\ ether
-.RB [ src
-.IR mac\-addr
-.RB [ src\-mask
-.IR mask ]]
-.RB [ dst
-.IR mac\-addr
-.RB [ dst\-mask
-.IR mask ]]
-.RB [ proto
-.IR N
-.RB [ proto\-mask
-.IR mask ]]\ }
-.br
-.RB [ vlan
-.IR VLAN\-tag
-.RB [ vlan\-mask

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 307

Quoted 10 lines
ethtool.8.in +0 -10
-.IR mask ]]
-.RB [ user\-def
-.IR data
-.RB [ user\-def\-mask
-.IR mask ]]
-.RI action \ N
-.
-.\" Adjust lines (i.e. full justification) and hyphenate.
-.ad
-.hy

As do the last 3 deleted lines here.

Quoted 8 lines
ethtool.8.in +8 -0
+.BN class-rule-del
+.RB [\  flow-type \ \*(NC
+.RB [ src \ \*(MA\ [ src-mask \ \*(MA]]
+.RB [ dst \ \*(MA\ [ dst-mask \ \*(MA]]
+.BM proto
+.RB [ src-ip \ \*(PA\ [ src-ip-mask \ \*(PA]]
+.RB [ dst-ip \ \*(PA\ [ dst-ip-mask \ \*(PA]]
+.BM tos

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 297

Quoted 10 lines
ethtool.8.in +10 -0
+.BM l4proto
+.BM src-port
+.BM dst-port
+.BM spi
+.BM vlan-etype
+.BM vlan
+.BM user-def
+.BN action
+.BN loc
+.RB ]

But these options aren't all applicable to all flow-types.

[...]

Quoted 27 lines
ethtool.c +7 -12
index 421fe20..e65979d 100644
@@ -243,20 +243,26 @@ static struct option {
 		"		equal N | weight W0 W1 ...\n" },
     { "-U", "--config-ntuple", MODE_SCLSRULE, "Configure Rx ntuple filters "
 		"and actions",
-		"		{ flow-type tcp4|udp4|sctp4\n"
-		"		  [ src-ip ADDR [src-ip-mask MASK] ]\n"
-		"		  [ dst-ip ADDR [dst-ip-mask MASK] ]\n"
-		"		  [ src-port PORT [src-port-mask MASK] ]\n"
-		"		  [ dst-port PORT [dst-port-mask MASK] ]\n"
-		"		| flow-type ether\n"
-		"		  [ src MAC-ADDR [src-mask MASK] ]\n"
-		"		  [ dst MAC-ADDR [dst-mask MASK] ]\n"
-		"		  [ proto N [proto-mask MASK] ] }\n"
-		"		[ vlan VLAN-TAG [vlan-mask MASK] ]\n"
-		"		[ user-def DATA [user-def-mask MASK] ]\n"
-		"		action N\n" },
+		"		[ class-rule-del %d ] |\n"
+		"		[ flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4\n"
+		"			[ src %x:%x:%x:%x:%x:%x [src-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ dst %x:%x:%x:%x:%x:%x [dst-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ proto %d [proto-mask MASK] ]\n"
+		"			[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d] ]\n"

ethtool.c static struct option { · line 262

Quoted 10 lines
ethtool.c +10 -0
+		"			[ tos %d [tos-mask %x] ]\n"
+		"			[ l4proto %d [l4proto-mask MASK] ]\n"
+		"			[ src-port %d [src-port-mask %x] ]\n"
+		"			[ dst-port %d [dst-port-mask %x] ]\n"
+		"			[ spi %d [spi-mask %x] ]\n"
+		"			[ vlan-etype %x [vlan-etype-mask %x] ]\n"
+		"			[ vlan %x [vlan-mask %x] ]\n"
+		"			[ user-def %x [user-def-mask %x] ]\n"
+		"			[ action %d ]\n"
+		"			[ loc %d]]\n" },

[...]

Again, it's not clear which options apply to which flow-types, and the 'm' shortcut is not documented.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#18 lore raw

Re: [ethtool PATCH 6/6] Update documentation for -u/-U operations

Quoted 6 lines · Ben Hutchings
Quoted 3 lines · Alexander Duyck

This patch updates the documentation for the -u/-U operations to include the recent changes made to support addition/deletion/display of network flow classifier rules.

This should be included in the same patch.

I'll combine the two patches for the next release if that is what is preferred. I was just trying to keep the overall size down by splitting them since this is documentation only.

Quoted 7 lines
Quoted 7 lines

---

  ethtool.8.in |  185 +++++++++++++++++++++++++++++-----------------------------
  ethtool.c    |   32 ++++++----
  2 files changed, 111 insertions(+), 106 deletions(-)
Quoted 15 lines

ethtool.8.in line 48

Quoted 12 lines
ethtool.8.in +4 -0
index 12a1d1d..8908351 100644
@@ -42,10 +42,20 @@
  [\\fB\\$1\\fP\ \\fIN\\fP]
..
  .\"
+.\"	.BM - same as above but has a mask field for format "[value N [value-mask N]]"
+.\"
+.de BM
+[\\fB\\$1\\fP\ \\fIN\\fP\ [\\fB\\$1\-mask\\fP\ \\fIN\\fP]]

You've changed the code to accept 'm' as an alternative to <field> '-mask', so this should be changed accordingly.

What would be the preferred way of stating that? For now I just replaced the \\$1\-mask with m. However I am assuming that probably isn't the best approach either. Should I state somewhere that m can be replaced with "field name"-mask?

Quoted 13 lines

[...]

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 257

Quoted 9 lines
ethtool.8.in +2 -2
@@ -236,9 +252,9 @@ ethtool \- query or control network driver and hardware settings
  .HP
  .B ethtool \-N
  .I ethX
-.RB [ rx\-flow\-hash \ \*(FL
-.RB \ \*(HO]
+.RB [ rx-flow-hash \ \*(FL \  \*(HO]
  .HP
+

This looks like an unintentional reversion of part of commit db6c0cee6cd956767e1c39109fe81104cc4694cb.

Yeah, my bad. I will have it updated for the next patch. I only really meant to combine this into one line, I didn't intend to drop the "\-" formatting fixes you added.

Quoted 52 lines
Quoted 52 lines
ethtool.8.in +3 -41
  .B ethtool \-x|\-\-show\-rxfh\-indir
  .I ethX
  .HP
@@ -257,54 +273,28 @@ ethtool \- query or control network driver and hardware settings
  .HP
  .B ethtool \-u|\-\-show\-ntuple
  .I ethX
-.TP
+.BN class-rule
+.HP
+
  .BI ethtool\ \-U|\-\-config\-ntuple \ ethX
-.RB {
-.A3 flow\-type tcp4 udp4 sctp4
-.RB [ src\-ip
-.IR addr
-.RB [ src\-ip\-mask
-.IR mask ]]
-.RB [ dst\-ip
-.IR addr
-.RB [ dst\-ip\-mask
-.IR mask ]]
-.RB [ src\-port
-.IR port
-.RB [ src\-port\-mask
-.IR mask ]]
-.RB [ dst\-port
-.IR port
-.RB [ dst\-port\-mask
-.IR mask ]]
-.br
-.RB | \ flow\-type\ ether
-.RB [ src
-.IR mac\-addr
-.RB [ src\-mask
-.IR mask ]]
-.RB [ dst
-.IR mac\-addr
-.RB [ dst\-mask
-.IR mask ]]
-.RB [ proto
-.IR N
-.RB [ proto\-mask
-.IR mask ]]\ }
-.br
-.RB [ vlan
-.IR VLAN\-tag
-.RB [ vlan\-mask
-.IR mask ]]
-.RB [ user\-def
-.IR data
-.RB [ user\-def\-mask
Quoted 8 lines

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 307

Quoted 6 lines
ethtool.8.in +0 -6
-.IR mask ]]
-.RI action \ N
-.
-.\" Adjust lines (i.e. full justification) and hyphenate.
-.ad
-.hy

As do the last 3 deleted lines here.

I put them back so they should be left in place for the next version.

Quoted 19 lines
Quoted 8 lines
ethtool.8.in +8 -0
+.BN class-rule-del
+.RB [\  flow-type \ \*(NC
+.RB [ src \ \*(MA\ [ src-mask \ \*(MA]]
+.RB [ dst \ \*(MA\ [ dst-mask \ \*(MA]]
+.BM proto
+.RB [ src-ip \ \*(PA\ [ src-ip-mask \ \*(PA]]
+.RB [ dst-ip \ \*(PA\ [ dst-ip-mask \ \*(PA]]
+.BM tos

ethtool.8.in ethtool \- query or control network driver and hardware settings · line 297

Quoted 10 lines
ethtool.8.in +10 -0
+.BM l4proto
+.BM src-port
+.BM dst-port
+.BM spi
+.BM vlan-etype
+.BM vlan
+.BM user-def
+.BN action
+.BN loc
+.RB ]
Quoted 1 line

But these options aren't all applicable to all flow-types.

This is the part that gets messy and I am not sure what the best approach is. I have more comments on that below. For now what I am planning to implement to address this is that in the "DESCRIPTION" section below I add a statement to each specifier that has restrictions by stating "Valid for flow-types X, Y, and Z."

Quoted 40 lines

[...]

Quoted 37 lines
ethtool.c +17 -12
index 421fe20..e65979d 100644
@@ -243,20 +243,26 @@ static struct option {
  		"		equal N | weight W0 W1 ...\n" },
      { "-U", "--config-ntuple", MODE_SCLSRULE, "Configure Rx ntuple filters "
  		"and actions",
-		"		{ flow-type tcp4|udp4|sctp4\n"
-		"		  [ src-ip ADDR [src-ip-mask MASK] ]\n"
-		"		  [ dst-ip ADDR [dst-ip-mask MASK] ]\n"
-		"		  [ src-port PORT [src-port-mask MASK] ]\n"
-		"		  [ dst-port PORT [dst-port-mask MASK] ]\n"
-		"		| flow-type ether\n"
-		"		  [ src MAC-ADDR [src-mask MASK] ]\n"
-		"		  [ dst MAC-ADDR [dst-mask MASK] ]\n"
-		"		  [ proto N [proto-mask MASK] ] }\n"
-		"		[ vlan VLAN-TAG [vlan-mask MASK] ]\n"
-		"		[ user-def DATA [user-def-mask MASK] ]\n"
-		"		action N\n" },
+		"		[ class-rule-del %d ] |\n"
+		"		[ flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4\n"
+		"			[ src %x:%x:%x:%x:%x:%x [src-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ dst %x:%x:%x:%x:%x:%x [dst-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ proto %d [proto-mask MASK] ]\n"
+		"			[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ tos %d [tos-mask %x] ]\n"
+		"			[ l4proto %d [l4proto-mask MASK] ]\n"
+		"			[ src-port %d [src-port-mask %x] ]\n"
+		"			[ dst-port %d [dst-port-mask %x] ]\n"
+		"			[ spi %d [spi-mask %x] ]\n"
+		"			[ vlan-etype %x [vlan-etype-mask %x] ]\n"
+		"			[ vlan %x [vlan-mask %x] ]\n"
+		"			[ user-def %x [user-def-mask %x] ]\n"
+		"			[ action %d ]\n"
+		"			[ loc %d]]\n" },

[...]

Quoted 2 lines

Again, it's not clear which options apply to which flow-types, and the 'm' shortcut is not documented.

The 'm' part I agree with 100%, however the flow types are going to become kinda hairy using that approach. You basically end up with something like this:

	flow-type ether
		[ src %x:%x:%x:%x:%x:%x [src-mask %x:%x:%x:%x:%x:%x]]
		[ dst %x:%x:%x:%x:%x:%x [dst-mask %x:%x:%x:%x:%x:%x]]
		[ proto %d [proto-mask %x]]
		[ vlan-etype %x [vlan-etype-mask %x]]
		[ vlan %x [vlan-mask %x]]
		[ user-def %x [user-def-mask %x]]
		[ action %d ]
		[ loc %d]
	flow-type ip4
		[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d]]
		[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d]]
		[ tos %d [tos-mask %x]]
		[ l4proto %d [l4proto-mask %x]]
		[ src-port %d [src-port-mask %x]]
		[ dst-port %d [dst-port-mask %x]]
		[ spi %d [spi-mask %x]]
		[ vlan-etype %x [vlan-etype-mask %x]]
		[ vlan %x [vlan-mask %x]]
		[ user-def %x [user-def-mask %x]]
		[ action %d ]
		[ loc %d]
	flow-type tcp4|udp4|sctp4
		[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d]]
		[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d]]
		[ tos %d [tos-mask %x]]
		[ src-port %d [src-port-mask %x]]
		[ dst-port %d [dst-port-mask %x]]
		[ vlan-etype %x [vlan-etype-mask %x]]
		[ vlan %x [vlan-mask %x]]
		[ user-def %x [user-def-mask %x]]
		[ action %d ]
		[ loc %d]
	flow-type ah4|esp4
		[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d]]
		[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d]]
		[ tos %d [tos-mask %x]]
		[ spi %d [spi-mask %x]]
		[ vlan-etype %x [vlan-etype-mask %x]]
		[ vlan %x [vlan-mask %x]]
		[ user-def %x [user-def-mask %x]]
		[ action %d ]
		[ loc %d]

As you can see it will be a bit oversized to go through and specify which flow-type options support what fields. If that is what you want I can implement it that way but for now I would prefer calling out the flow-type limitations of the fields in the "DESCRIPTION" portion of the man page.

Quoted 3 lines

Ben.

Thanks,

Alex

#19 lore raw

Re: [ethtool PATCH 6/6] Update documentation for -u/-U operations

Quoted 2 lines · Alexander Duyck
Quoted 1 line · Ben Hutchings

On Thu, 2011-04-21 at 13:40 -0700, Alexander Duyck wrote:

[...]

Quoted 14 lines
Quoted 5 lines
Quoted 5 lines
ethtool.8.in +0 -0
@@ -42,10 +42,20 @@
  [\\fB\\$1\\fP\ \\fIN\\fP]
..
Quoted 8 lines
Quoted 5 lines

.\"
+.\" .BM - same as above but has a mask field for format "[value N [value-mask N]]"
+.\"
+.de BM
+[\\fB\\$1\\fP\ \\fIN\\fP\ [\\fB\\$1\-mask\\fP\ \\fIN\\fP]]

You've changed the code to accept 'm' as an alternative to <field> '-mask', so this should be changed accordingly.

Quoted 4 lines

What would be the preferred way of stating that? For now I just replaced the \\$1\-mask with m. However I am assuming that probably isn't the best approach either. Should I state somewhere that m can be replaced with "field name"-mask?

I think that's reasonable.

[...]

Quoted 19 lines
Quoted 19 lines
Quoted 18 lines

+.BN class-rule-del
+.RB [\ flow-type \ \*(NC
+.RB [ src \ \*(MA\ [ src-mask \ \*(MA]]
+.RB [ dst \ \*(MA\ [ dst-mask \ \*(MA]]
+.BM proto
+.RB [ src-ip \ \*(PA\ [ src-ip-mask \ \*(PA]]
+.RB [ dst-ip \ \*(PA\ [ dst-ip-mask \ \*(PA]]
+.BM tos
+.BM l4proto
+.BM src-port
+.BM dst-port
+.BM spi
+.BM vlan-etype
+.BM vlan
+.BM user-def
+.BN action
+.BN loc
+.RB ]

Quoted 7 lines
Quoted 1 line

But these options aren't all applicable to all flow-types.

This is the part that gets messy and I am not sure what the best approach is. I have more comments on that below. For now what I am planning to implement to address this is that in the "DESCRIPTION" section below I add a statement to each specifier that has restrictions by stating "Valid for flow-types X, Y, and Z."

OK.

Quoted 40 lines
Quoted 40 lines

[...]

Quoted 37 lines
ethtool.c +17 -12
index 421fe20..e65979d 100644
@@ -243,20 +243,26 @@ static struct option {
  		"		equal N | weight W0 W1 ...\n" },
      { "-U", "--config-ntuple", MODE_SCLSRULE, "Configure Rx ntuple filters "
  		"and actions",
-		"		{ flow-type tcp4|udp4|sctp4\n"
-		"		  [ src-ip ADDR [src-ip-mask MASK] ]\n"
-		"		  [ dst-ip ADDR [dst-ip-mask MASK] ]\n"
-		"		  [ src-port PORT [src-port-mask MASK] ]\n"
-		"		  [ dst-port PORT [dst-port-mask MASK] ]\n"
-		"		| flow-type ether\n"
-		"		  [ src MAC-ADDR [src-mask MASK] ]\n"
-		"		  [ dst MAC-ADDR [dst-mask MASK] ]\n"
-		"		  [ proto N [proto-mask MASK] ] }\n"
-		"		[ vlan VLAN-TAG [vlan-mask MASK] ]\n"
-		"		[ user-def DATA [user-def-mask MASK] ]\n"
-		"		action N\n" },
+		"		[ class-rule-del %d ] |\n"
+		"		[ flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4\n"
+		"			[ src %x:%x:%x:%x:%x:%x [src-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ dst %x:%x:%x:%x:%x:%x [dst-mask %x:%x:%x:%x:%x:%x] ]\n"
+		"			[ proto %d [proto-mask MASK] ]\n"
+		"			[ src-ip %d.%d.%d.%d [src-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ dst-ip %d.%d.%d.%d [dst-ip-mask %d.%d.%d.%d] ]\n"
+		"			[ tos %d [tos-mask %x] ]\n"
+		"			[ l4proto %d [l4proto-mask MASK] ]\n"
+		"			[ src-port %d [src-port-mask %x] ]\n"
+		"			[ dst-port %d [dst-port-mask %x] ]\n"
+		"			[ spi %d [spi-mask %x] ]\n"
+		"			[ vlan-etype %x [vlan-etype-mask %x] ]\n"
+		"			[ vlan %x [vlan-mask %x] ]\n"
+		"			[ user-def %x [user-def-mask %x] ]\n"
+		"			[ action %d ]\n"
+		"			[ loc %d]]\n" },

[...]

Quoted 6 lines
Quoted 2 lines

Again, it's not clear which options apply to which flow-types, and the 'm' shortcut is not documented.

The 'm' part I agree with 100%, however the flow types are going to become kinda hairy using that approach. You basically end up with something like this:

[...]

Yes, I see the problem.

Quoted 5 lines

As you can see it will be a bit oversized to go through and specify which flow-type options support what fields. If that is what you want I can implement it that way but for now I would prefer calling out the flow-type limitations of the fields in the "DESCRIPTION" portion of the man page.

In fact, even with this patch, the help for -U is pretty oversized. It might be better to replace the list of field names with '...' here and only list them in full in the man page.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#20 lore raw
In reply to Alexander Duyck
Quoted 6 lines · Alexander Duyck

The following patches are meant to add support for the network flow classifier interface built into the ethtool_rxnfc.

Once this has been accepted I plan to submit the kernel portion to Jeff Kirsher as it is almost all ixgbe code changes with the exception of the removal of support for ethtool_get_rx_ntuple from the kernel.

[...]

This is the start of a 4-way weekend in the UK, so don't be surprised if I take a while to review these changes.

Ben.

Signature · 3 lines
Ben Hutchings, Senior Software Engineer, Solarflare
Not speaking for my employer; that's the marketing department's job.
They asked us to note that Solarflare product names are trademarked.
#21 lore raw
Quoted 7 lines · Ben Hutchings
Quoted 6 lines · Alexander Duyck

The following patches are meant to add support for the network flow classifier interface built into the ethtool_rxnfc.

Once this has been accepted I plan to submit the kernel portion to Jeff Kirsher as it is almost all ixgbe code changes with the exception of the removal of support for ethtool_get_rx_ntuple from the kernel.

Quoted 7 lines

[...]

This is the start of a 4-way weekend in the UK, so don't be surprised if I take a while to review these changes.

Ben.

I'm fine with that. I wasn't in any big hurry. I was mostly just getting them out there for review so that I can probably see about polishing them up and submitting the final version for them next week.

Thanks,

Alex