v6 Add support for network flow classifier
Subsystems (3)
cover v6 Add support for network flow classifier
This series is nearly identical to the last series with only a few changes in the RX packet classification interface patch. Specifically I have narrowed down the rule manager to the point where it is only used to identify a location for a rule if the rule location is unspecified. The display functionality for rules now just pulls the rule list in and goes through the list from top to bottom displaying the rules instead of initializing the rule manager and pulling the rules form there.
The main advantage to this approach is that the rule manager could easily be replaced by a future ioctl call and on the failure of that ioctl call with a return of EOPNOTSUPP it should be easy to fall back and just use the rule manager.
Thanks,
Alex
---
Alexander Duyck (3):
Add support for __be64 and bitops, centralize several needed macros Cleanup defines and header includes to address several issues
ethtool: remove strings based approach for displaying n-tuple
Santwona Behera (1):
v6 Add RX packet classification interface
Makefile.am | 3 ethtool-bitops.h | 25 + ethtool-util.h | 47 ++ ethtool.8.in | 194 +++++----- ethtool.c | 449 +++++++++++------------ rxclass.c | 1073 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 1467 insertions(+), 324 deletions(-) create mode 100644 ethtool-bitops.h create mode 100644 rxclass.c
PATCH 1/4 ethtool: remove strings based approach for displaying n-tuple
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
@@ -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 ; }
PATCH 2/4 Cleanup defines and header includes to address several issues
In reply to Alexander DuyckThis change is meant to address several issues. First it moves the check for ethtool-config.h into ethtool-util.h the reason for this change is so that any references to ethtool-util.h outside of ethtool.c will use the correct defines for the endian types.
In addition I have pulled several headers that will be common to both ethtool.c and rxclass.c into the ethtool-util.h header file. I am also centralizing several macros that will be needed across multiple files when I implement the network flow classifier rules.
---
ethtool-util.h | 17 +++++++++++++++-- ethtool.c | 17 +---------------- 2 files changed, 16 insertions(+), 18 deletions(-)
ethtool-util.h +15 -2
@@ -3,8 +3,13 @@#ifndef ETHTOOL_UTIL_H__ #define ETHTOOL_UTIL_H__ +#ifdef HAVE_CONFIG_H +#include "ethtool-config.h" +#endif #include <sys/types.h> #include <endian.h> +#include <sys/ioctl.h> +#include <net/if.h> /* ethtool.h expects these to be defined by <linux/types.h> */ #ifndef HAVE_BE_TYPES
@@ -12,14 +17,14 @@ typedef __uint16_t __be16;typedef __uint32_t __be32 ;#endif -#include "ethtool-copy.h" -typedef unsigned long long u64 ;typedef __uint32_t u32 ;typedef __uint16_t u16 ;typedef __uint8_t u8 ;typedef __int32_t s32 ; +#include "ethtool-copy.h" +#if __BYTE_ORDER == __BIG_ENDIANstatic inline u16 cpu_to_be16 (u16 value) {
@@ -40,6 +45,14 @@ static inline u32 cpu_to_be32(u32 value) }#endif +#ifndef ARRAY_SIZE +#define ARRAY_SIZE (x) (sizeof(x) / sizeof((x)[0])) +#endif + +#ifndef SIOCETHTOOL +#define SIOCETHTOOL 0x8946 +#endif +/* National Semiconductor DP83815, DP83816 */ int natsemi_dump_regs (struct ethtool_drvinfo *info,struct ethtool_regs *regs); int natsemi_dump_eeprom(struct ethtool_drvinfo *info,
ethtool.c +1 -16
@@ -21,19 +21,12 @@* * show settings for all devices */ -#ifdef HAVE_CONFIG_H -# include "ethtool-config.h" -#endif - -#include <sys/types.h> +#include "ethtool-util.h" #include <string.h> #include <stdlib.h> -#include <sys/types.h> -#include <sys/ioctl.h> #include <sys/stat.h> #include <stdio.h> #include <errno.h> -#include <net/if.h> #include <sys/utsname.h> #include <limits.h> #include <ctype.h>
@@ -43,18 +36,10 @@#include <arpa/inet.h> #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 {
PATCH 3/4 Add support for __be64 and bitops, centralize several needed macros
In reply to Alexander DuyckThis change is meant to add support for __be64 values and bitops to ethtool. In addition the patch pulls the SIOCETHTOOL define and the ARRAY_SIZE define into ethtool-util.h for later use by the rxclass files. These changes will be needed in order to support network flow classifier rule configuration.
---
ethtool-bitops.h | 25 +++++++++++++++++++++++++ ethtool-util.h | 16 ++++++++++++++-- 2 files changed, 39 insertions(+), 2 deletions(-) create mode 100644 ethtool-bitops.h
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 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 +14 -2
@@ -15,6 +15,7 @@#ifndef HAVE_BE_TYPES typedef __uint16_t __be16 ;typedef __uint32_t __be32 ; +typedef unsigned long long __be64 ;#endif typedef unsigned long long u64 ;
@@ -28,11 +29,15 @@ typedef __int32_t s32;#if __BYTE_ORDER == __BIG_ENDIANstatic 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)
@@ -43,8 +48,15 @@ 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
PATCH 4/4 v6 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/
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.
v5:
This change merged the documentation update into this patch. In addition the documentation changes were made such that there is only one listing of the individual options and they are all listed as optional.
In addition this patch contains several fixes to address things such as the fact that we were maintaining the table logic even though we only need it for displaying all of the rules, or when adding a rule with no location specified. As such all of the logic for deleting or finding rules in the table has been removed.
v6:
This change further reduced the use of the rule manager so that it is only initialized and used when a rule is added without a location specified. For future expansion it should be possible to add a call to a in kernel ethtool ioctl that can effectively replace the rule manager entirely. However this basic rule manager will be necessary to support legacy kernels.
---
Makefile.am | 3 ethtool-util.h | 14 + ethtool.8.in | 194 +++++----- ethtool.c | 400 ++++++++++++--------- rxclass.c | 1073 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 5 files changed, 1418 insertions(+), 266 deletions(-) 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-util.h +13 -1
@@ -65,6 +65,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,
@@ -128,4 +130,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.8.in +103 -91
267 lines not on this page · raw message
ethtool.c +227 -173
503 lines not on this page · raw message
rxclass.c new file +1073 -0
1,073 lines not on this page · raw message
Quoted 8 lines · Alexander Duyck
This series is nearly identical to the last series with only a few changes in the RX packet classification interface patch. Specifically I have narrowed down the rule manager to the point where it is only used to identify a location for a rule if the rule location is unspecified. The display functionality for rules now just pulls the rule list in and goes through the list from top to bottom displaying the rules instead of initializing the rule manager and pulling the rules form there.
Quoted 4 lines
The main advantage to this approach is that the rule manager could easily be replaced by a future ioctl call and on the failure of that ioctl call with a return of EOPNOTSUPP it should be easy to fall back and just use the rule manager.
Thanks a lot for persevering with this, Alexander.
I've applied this series with minor changes to the last patch. I abbreviated the version history in the commit message, and I deleted a blank line in the manual page additions which made the indentation wrong for the -U option. I also recorded the author as you, since you've largely rewritten it! The commit message credits Santwona Behera.
You managed to uncover a bug in the sfc driver, which is that set_rx_ntuple can return a positive value. Previously ethtool accepted any non-negative return value as successful, so I made a separate commit to restore that behaviour. Of course I'll fix the driver too.
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.
Quoted 8 lines · Ben Hutchings
Thanks a lot for persevering with this, Alexander.
I've applied this series with minor changes to the last patch. I abbreviated the version history in the commit message, and I deleted a blank line in the manual page additions which made the indentation wrong for the -U option. I also recorded the author as you, since you've largely rewritten it! The commit message credits Santwona Behera.
Quoted 7 lines
You managed to uncover a bug in the sfc driver, which is that
set_rx_ntuplecan return a positive value. Previously ethtool accepted any non-negative return value as successful, so I made a separate commit to restore that behaviour. Of course I'll fix the driver too.Ben.
Thanks for getting this all applied. Our validation team is now testing the ixgbe patches with your version of ethtool and if I hear about any other bugs I might have introduced I will let you know.
Alex