Add support for network flow classifier rules
Subsystems (3)
cover Add support for network flow classifier rules
This patch series implements the user-space portion of network flow classifier rules. The original patches were applied to the kernel a couple of years ago, but the user-space side was never applied. As such I have gone though and updated the original patch from Santwona Behera to make it applicable to the current ethtool git tree.
In addition this updates the network flow classification rules to handle displaying the same fields as ntuple filters due to the fact that ntuple display functionality had some serious issues, and provided no means for a driver to display rules if they are stored internally.
The formatting of the man page and the help text may still need some work. I was having difficulties determining the best way to layout the class-rule-add and flow-type help instructions since they are mutually exclusive but both contain a large number of possible options.
Finally there was one minor change adding ESP hashing as a separate option to Rx-hashing that was contained in the original patch that I have moved out into a separate patch.
---
Alexander Duyck (3):
Add support for displaying a ntuple contained in an rx_flow_spec Remove strings based approach for displaying ntuple Add support for ESP as a separate protocol from AH
Santwona Behera (1):
v2 Add RX packet classification interface
Makefile.am | 3 ethtool-bitops.h | 25 + ethtool-copy.h | 23 + ethtool-util.h | 42 ++ ethtool.8.in | 204 +++++---- ethtool.c | 344 ++++++--------- rxclass.c | 1241 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 7 files changed, 1573 insertions(+), 309 deletions(-) create mode 100644 ethtool-bitops.h create mode 100644 rxclass.c
PATCH 1/4 Add support for ESP as a separate protocol from AH
This change is meant to split out ESP from AH. Currently they are present as both a combined value, and two separate values. In order to try and support eventually splitting the two out into separate values this change makes it so that ESP can be called out separately in ethtool.
---
ethtool.8.in | 2 +- ethtool.c | 21 ++++++++++++++++----- 2 files changed, 17 insertions(+), 6 deletions(-)
ethtool.8.in +1 -1
@@ -50,7 +50,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 .\"
ethtool.c +16 -5
@@ -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>
@@ -232,15 +231,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",
@@ -778,6 +777,8 @@ static int rxflow_str_to_type(const char *str) flow_type =UDP_V4_FLOW ; else if (!strcmp(str, "ah4")) flow_type =AH_ESP_V4_FLOW ; + else if (!strcmp(str, "esp4")) + flow_type =ESP_V4_FLOW ; else if (!strcmp(str, "sctp4")) flow_type =SCTP_V4_FLOW ; else if (!strcmp(str, "tcp6"))
@@ -786,6 +787,8 @@ static int rxflow_str_to_type(const char *str) flow_type =UDP_V6_FLOW ; else if (!strcmp(str, "ah6")) flow_type =AH_ESP_V6_FLOW ; + else if (!strcmp(str, "esp6")) + flow_type =ESP_V6_FLOW ; else if (!strcmp(str, "sctp6")) flow_type =SCTP_V6_FLOW ; else if (!strcmp(str, "ether"))
@@ -1918,8 +1921,12 @@ static int dump_rxfhash(int fhash, u64 val)fprintf (stdout,"SCTP over IPV4 flows" );break ;case AH_ESP_V4_FLOW : +case AH_V4_FLOW :fprintf (stdout,"IPSEC AH over IPV4 flows" );break ; +case ESP_V4_FLOW : +fprintf (stdout,"IPSEC ESP over IPV4 flows" ); +break ;case TCP_V6_FLOW :fprintf (stdout,"TCP over IPV6 flows" );break ;
@@ -1930,8 +1937,12 @@ static int dump_rxfhash(int fhash, u64 val)fprintf (stdout,"SCTP over IPV6 flows" );break ;case AH_ESP_V6_FLOW : +case AH_V6_FLOW :fprintf (stdout,"IPSEC AH over IPV6 flows" );break ; +case ESP_V6_FLOW : +fprintf (stdout,"IPSEC ESP over IPV6 flows" ); +break ;default :break ; }
PATCH 2/4 Remove strings based approach for displaying ntuple
In reply to Alexander DuyckThis change is meant to remove the strings based approach for displaying ntuple 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-copy.h | 3 +-- ethtool.c | 44 -------------------------------------------- 2 files changed, 1 insertions(+), 46 deletions(-)
ethtool-copy.h +1 -2
@@ -250,7 +250,6 @@ enum ethtool_stringset {ETH_SS_TEST =0 ,ETH_SS_STATS , ETH_SS_PRIV_FLAGS, - ETH_SS_NTUPLE_FILTERS, };/* for passing string sets for data tagging */
@@ -580,7 +579,7 @@ struct ethtool_flash {#define ETHTOOL_FLASHDEV 0x00000033/* Flash firmware to device */ #define ETHTOOL_RESET 0x00000034/* Reset hardware */ #define ETHTOOL_SRXNTUPLE 0x00000035/* Add an n-tuple filter to device */ -#define ETHTOOL_GRXNTUPLE 0x00000036/* Get n-tuple filters from device */ +/* ETHTOOL_GRXNTUPLE 0x00000036 disabled due to multiple issues */ #define ETHTOOL_GSSET_INFO 0x00000037/* Get string set info */ #define ETHTOOL_GRXFHINDIR 0x00000038/* Get RX flow hash indir'n table */ #define ETHTOOL_SRXFHINDIR 0x00000039/* Set RX flow hash indir'n table */
ethtool.c +0 -44
50 lines not on this page · raw message
PATCH 3/4 v2 Add RX packet classification interface
In reply to Alexander DuyckFrom: 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/
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.
I also added an ethtool bitops interface to allow for simple bit set and test activities since the rule manager can most efficiently store the list of active rules via a bitmap.
This patch now also merges the functionality of the packet classification into the ntuple interface. This is done by using the key word flow-type to indicate the addition of an ntuple, class-rule-add to indicate the addition of a network flow classifier, and class-rule-del to indicate the deletion of a network flow classifier. Since ntuple display functionality was already removed I have made the defalt for the -u option to display the number of rings and all network flow classification filters. If a single rule is requested via class-rule %d then only that rule will be displayed.
---
Makefile.am | 3 ethtool-bitops.h | 25 + ethtool-util.h | 42 ++ ethtool.8.in | 198 +++++---- ethtool.c | 284 ++++++------- rxclass.c | 1169 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1459 insertions(+), 262 deletions(-) create mode 100644 ethtool-bitops.h create mode 100644 rxclass.c
Makefile.am +2 -1
@@ -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-bitops.h new file +25 -0
@@ -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 ])) !=0UL ; +} + +#endif
ethtool-util.h +37 -5
73 lines not on this page · raw message
ethtool.8.in +106 -92
280 lines not on this page · raw message
ethtool.c +120 -164
400 lines not on this page · raw message
rxclass.c new file +1169 -0
1,169 lines not on this page · raw message
PATCH 4/4 Add support for displaying a ntuple contained in an rx_flow_spec
In reply to Alexander DuyckThis change is meant to add support for displaying a ntuple filter by using the unused space contained within a standard rx_flow_spec.
---
ethtool-copy.h | 20 ++++++++++++++++ ethtool.8.in | 6 +++++ ethtool.c | 3 ++ rxclass.c | 72 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 101 insertions(+), 0 deletions(-)
ethtool-copy.h +20 -0
@@ -376,10 +376,25 @@ struct ethtool_usrip4_spec { };/** +* struct ethtool_ntuple_spec_ext - flow spec extension for ntuple in nfc +* @unused: space unused by extension +* @vlan_etype: EtherType for vlan tagged packet to match +* @vlan_tci: VLAN tag to match +* @data: Driver-dependent data to match +*/ +struct ethtool_ntuple_spec_ext { +__be32 unused[15 ]; +__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 +* @flow_type_ext: Type of extended match to perform, e.g. %NTUPLE_FLOW_EXT * @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
@@ -394,8 +409,10 @@ struct ethtool_rx_flow_spec {struct ethtool_ah_espip4_spec esp_ip4_spec;struct ethtool_usrip4_spec usr_ip4_spec;struct ethhdr ether_spec; +struct ethtool_ntuple_spec_ext ntuple_spec;__u8 hdata[72 ]; } h_u, m_u; +__u32 flow_type_ext;__u64 ring_cookie;__u32 location; };
@@ -706,6 +723,9 @@ struct ethtool_flash {#define IPV6_FLOW 0x11/* hash only */ #define ETHER_FLOW 0x12/* spec only (ether_spec) */ +/* Flow extension types for network flow classifier */ +#define NTUPLE_FLOW_EXT 0x01/* indicates ntuple in nfc */ +/* L3-L4 network traffic flow hash options */ #define RXH_L2DA (1 << 1)#define RXH_VLAN (1 << 2)
ethtool.8.in +6 -0
@@ -278,6 +278,9 @@ ethtool \- query or control network driver and hardware settings .BM src-port .BM dst-port .BM spi +.BM vlan-etype +.BM vlan +.BM user-def .BN action .BN loc .RB \ |\ flow-type \ \*(NC
@@ -764,6 +767,9 @@ 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-etype \ N \\fR\ [\\fPvlan-etype-mask \ N \\fR]\\fP +Includes the VLAN tag Ethertype and an optional mask. +.TP .BI vlan \ N \\fR\ [\\fPvlan-mask \ N \\fR]\\fP Includes the VLAN tag and an optional mask. .TP
ethtool.c +3 -0
@@ -254,6 +254,9 @@ static struct option {" [ 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" " flow-type ether|ip4|tcp4|udp4|sctp4|ah4|esp4\n"
rxclass.c +72 -0
126 lines not on this page · raw message