nfp: flower: tunnel TTL & TOS, and Geneve options set & match support
cover nfp: flower: tunnel TTL & TOS, and Geneve options set & match support
Hi Dave,
this series contains updates for the TC Flower classifier and the offload facility for it in the NFP driver.
* Patches 1 & 2: update the NFP driver to allow offload
of matching and setting tunnel ToS/TTL of flows using the TC Flower classifier and tun_key action
* Patches 3 & 4: enhance the flow dissector and TC Flower classifier to allow match on Geneve options
* Patch 5 & 6: update the NFP driver to allow offload of matching and setting Geneve options of flows using the TC Flower classifier and tun_key action
John Hurley (2):
nfp: flower: set ip tunnel ttl from encap action
nfp: flower: allow matching on ipv4 UDP tunnel tos and ttl
Pieter Jansen van Vuuren (3):
net/sched: allow flower to match tunnel options
nfp: flower: add geneve option push action offload
nfp: flower: add geneve option match offload
Simon Horman (1):
flow_dissector: allow dissection of tunnel options from metadata
drivers/net/ethernet/netronome/nfp/flower/action.c | 139 ++++++++++-- drivers/net/ethernet/netronome/nfp/flower/cmsg.h | 33 ++- drivers/net/ethernet/netronome/nfp/flower/main.h | 1 + drivers/net/ethernet/netronome/nfp/flower/match.c | 34 +++ .../net/ethernet/netronome/nfp/flower/offload.c | 42 +++- include/net/flow_dissector.h | 17 ++ include/uapi/linux/pkt_cls.h | 26 +++ net/core/flow_dissector.c | 19 +- net/sched/cls_flower.c | 244 ++++++++++++++++++++- 9 files changed, 525 insertions(+), 30 deletions(-)
Signature · 1 line
2.11.0
PATCH 1/6 nfp: flower: set ip tunnel ttl from encap action
From: John Hurley <[email protected]>
The TTL for encapsulating headers in IPv4 UDP tunnels is taken from a route lookup. Modify this to first check if a user has specified a TTL to be used in the TC action.
--- drivers/net/ethernet/netronome/nfp/flower/action.c | 39 ++++++++++++---------- 1 file changed, 21 insertions(+), 18 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/action.c +21 -18
@@ -238,18 +238,12 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun,size_t act_size =sizeof (struct nfp_fl_set_ipv4_udp_tun );struct ip_tunnel_info *ip_tun =tcf_tunnel_info (action);u32 tmp_set_ip_tun_type_index =0 ; -struct flowi4 flow = {};/* Currently support one pre-tunnel so index is always 0. */ int pretun_idx =0 ; -struct rtable *rt; -struct net *net; -int err;if (ip_tun->options_len)return -EOPNOTSUPP ; - net =dev_net (netdev); - set_tun->head.jump_id =NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL ; set_tun->head.len_lw = act_size >>NFP_FL_LW_SIZ ;
@@ -261,19 +255,28 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun, set_tun->tun_type_index =cpu_to_be32 (tmp_set_ip_tun_type_index); set_tun->tun_id = ip_tun->key.tun_id; -/* Do a route lookup to determine ttl - if fails then use default. -* Note that CONFIG_INET is a requirement of CONFIG_NET_SWITCHDEV so -* must be defined here. -*/ - flow.daddr = ip_tun->key.u.ipv4.dst; - flow.flowi4_proto =IPPROTO_UDP ; - rt =ip_route_output_key (net, &flow); - err =PTR_ERR_OR_ZERO (rt); -if (!err) { - set_tun->ttl =ip4_dst_hoplimit (&rt->dst); -ip_rt_put (rt); +if (ip_tun->key.ttl) { + set_tun->ttl = ip_tun->key.ttl; }else { - set_tun->ttl = net->ipv4.sysctl_ip_default_ttl; +struct net *net =dev_net (netdev); +struct flowi4 flow = {}; +struct rtable *rt; +int err; + +/* Do a route lookup to determine ttl - if fails then use +* default. Note that CONFIG_INET is a requirement of +* CONFIG_NET_SWITCHDEV so must be defined here. +*/ + flow.daddr = ip_tun->key.u.ipv4.dst; + flow.flowi4_proto =IPPROTO_UDP ; + rt =ip_route_output_key (net, &flow); + err =PTR_ERR_OR_ZERO (rt); +if (!err) { + set_tun->ttl =ip4_dst_hoplimit (&rt->dst); +ip_rt_put (rt); + }else { + set_tun->ttl = net->ipv4.sysctl_ip_default_ttl; + } } set_tun->tos = ip_tun->key.tos;
Signature · 1 line
2.11.0
PATCH 2/6 nfp: flower: allow matching on ipv4 UDP tunnel tos and ttl
In reply to Simon HormanFrom: John Hurley <[email protected]>
The addition of FLOW_DISSECTOR_KEY_ENC_IP to TC flower means that the ToS and TTL of the tunnel header can now be matched on.
Extend the NFP tunnel match function to include these new fields.
--- drivers/net/ethernet/netronome/nfp/flower/cmsg.h | 7 +++++-- drivers/net/ethernet/netronome/nfp/flower/match.c | 9 +++++++++ drivers/net/ethernet/netronome/nfp/flower/offload.c | 4 +++- 3 files changed, 17 insertions(+), 3 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/cmsg.h +5 -2
@@ -346,7 +346,7 @@ struct nfp_flower_ipv6 {* +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | ipv4_addr_dst | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ -* | Reserved | +* | Reserved | tos | ttl | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ * | Reserved | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
@@ -356,7 +356,10 @@ struct nfp_flower_ipv6 {struct nfp_flower_ipv4_udp_tun {__be32 ip_src;__be32 ip_dst; -__be32 reserved[2 ]; +__be16 reserved1; +u8 tos; +u8 ttl; +__be32 reserved2;__be32 tun_id; };
drivers/net/ethernet/netronome/nfp/flower/match.c +9 -0
@@ -270,6 +270,7 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *frame,struct fl_flow_key *target = mask_version ? flow->mask : flow->key;struct flow_dissector_key_ipv4_addrs *tun_ips;struct flow_dissector_key_keyid *vni; +struct flow_dissector_key_ip *ip;memset (frame,0 ,sizeof (struct nfp_flower_ipv4_udp_tun ));
@@ -293,6 +294,14 @@ nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *frame, frame->ip_src = tun_ips->src; frame->ip_dst = tun_ips->dst; } + +if (dissector_uses_key (flow->dissector,FLOW_DISSECTOR_KEY_ENC_IP )) { + ip =skb_flow_dissector_target (flow->dissector, +FLOW_DISSECTOR_KEY_ENC_IP , + target); + frame->tos = ip->tos; + frame->ttl = ip->ttl; + } } int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow,
drivers/net/ethernet/netronome/nfp/flower/offload.c +3 -1
@@ -66,6 +66,7 @@BIT (FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS ) | \BIT (FLOW_DISSECTOR_KEY_ENC_CONTROL ) | \BIT (FLOW_DISSECTOR_KEY_ENC_PORTS ) | \ +BIT (FLOW_DISSECTOR_KEY_ENC_IP ) | \BIT (FLOW_DISSECTOR_KEY_MPLS ) | \ BIT(FLOW_DISSECTOR_KEY_IP))
@@ -74,7 +75,8 @@ BIT(FLOW_DISSECTOR_KEY_ENC_KEYID) | \ BIT(FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS) | \ BIT(FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS) | \ - BIT(FLOW_DISSECTOR_KEY_ENC_PORTS)) + BIT(FLOW_DISSECTOR_KEY_ENC_PORTS) | \ + BIT(FLOW_DISSECTOR_KEY_ENC_IP))#define NFP_FLOWER_WHITELIST_TUN_DISSECTOR_R \ (BIT(FLOW_DISSECTOR_KEY_ENC_CONTROL) | \
Signature · 1 line
2.11.0
Re: [PATCH net-next 2/6] nfp: flower: allow matching on ipv4 UDP tunnel tos and ttl
Quoted 6 lines · Simon Horman
From: John Hurley <[email protected]>
The addition of
FLOW_DISSECTOR_KEY_ENC_IPto TC flower means that the ToS and TTL of the tunnel header can now be matched on.Extend the NFP tunnel match function to include these new fields.
(referring to you patch title) where is this explicitly dealing with udp tunnel? tos/ttl belong to any IP tunnel, e.g GRE as well
Or.
Re: [PATCH net-next 2/6] nfp: flower: allow matching on ipv4 UDP tunnel tos and ttl
Quoted 6 lines · Or Gerlitz
Quoted 5 lines · Simon Horman
From: John Hurley <[email protected]>
The addition of
FLOW_DISSECTOR_KEY_ENC_IPto TC flower means that the ToS and TTL of the tunnel header can now be matched on.
Quoted 6 lines
Quoted 1 line
Extend the NFP tunnel match function to include these new fields.
(referring to you patch title) where is this explicitly dealing with udp tunnel? tos/ttl belong to any IP tunnel, e.g GRE as well
Or.
Hi Or,
Yes, you are correct.
But in our case we do not currently support GRE so, for NFP, this offload match only applies to IPv4 UDP tunnels.
John
PATCH 3/6 flow_dissector: allow dissection of tunnel options from metadata
In reply to Simon HormanAllow the existing 'dissection' of tunnel metadata to 'dissect' options already present in tunnel metadata. This dissection is controlled by a new dissector key, FLOW_DISSECTOR_KEY_ENC_OPTS.
This dissection only occurs when skb_flow_dissect_tunnel_info() is called, currently only the Flower classifier makes that call. So there should be no impact on other users of the flow dissector.
This is in preparation for allowing the flower classifier to match on Geneve options.
--- include/net/flow_dissector.h | 17 +++++++++++++++++ net/core/flow_dissector.c | 19 ++++++++++++++++++- 2 files changed, 35 insertions(+), 1 deletion(-)
include/net/flow_dissector.h +17 -0
@@ -57,6 +57,21 @@ struct flow_dissector_key_mpls { mpls_label:20 ; }; +#define FLOW_DIS_TUN_OPTS_MAX 255 +/** +* struct flow_dissector_key_enc_opts: +* @data: tunnel option data +* @len: length of tunnel option data +* @dst_opt_type: tunnel option type +*/ +struct flow_dissector_key_enc_opts { +u8 data[FLOW_DIS_TUN_OPTS_MAX ];/* Using IP_TUNNEL_OPTS_MAX is desired +* here but seems difficult to #include +*/ +u8 len; +__be16 dst_opt_type; +}; +struct flow_dissector_key_keyid {__be32 keyid; };
@@ -208,6 +223,8 @@ enum flow_dissector_key_id {FLOW_DISSECTOR_KEY_IP ,/* struct flow_dissector_key_ip */ FLOW_DISSECTOR_KEY_CVLAN ,/* struct flow_dissector_key_flow_vlan */ FLOW_DISSECTOR_KEY_ENC_IP ,/* struct flow_dissector_key_ip */ +FLOW_DISSECTOR_KEY_ENC_OPTS ,/* struct flow_dissector_key_enc_opts */ + FLOW_DISSECTOR_KEY_MAX, };
net/core/flow_dissector.c +18 -1
@@ -154,7 +154,9 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, !dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_PORTS ) && !dissector_uses_key (flow_dissector, - FLOW_DISSECTOR_KEY_ENC_IP)) +FLOW_DISSECTOR_KEY_ENC_IP ) && + !dissector_uses_key (flow_dissector, + FLOW_DISSECTOR_KEY_ENC_OPTS)) return; info =skb_tunnel_info (skb);
@@ -224,6 +226,21 @@ skb_flow_dissect_tunnel_info(const struct sk_buff *skb, ip->tos = key->tos; ip->ttl = key->ttl; } + +if (dissector_uses_key (flow_dissector,FLOW_DISSECTOR_KEY_ENC_OPTS )) { +struct flow_dissector_key_enc_opts *enc_opt; + + enc_opt =skb_flow_dissector_target (flow_dissector, +FLOW_DISSECTOR_KEY_ENC_OPTS , + target_container); + +if (info->options_len) { + enc_opt->len = info->options_len; +ip_tunnel_info_opts_get (enc_opt->data, info); + enc_opt->dst_opt_type = info->key.tun_flags & +TUNNEL_OPTIONS_PRESENT ; + } + } }EXPORT_SYMBOL (skb_flow_dissect_tunnel_info);
Signature · 1 line
2.11.0
PATCH 4/6 net/sched: allow flower to match tunnel options
In reply to Simon HormanFrom: Pieter Jansen van Vuuren <[email protected]>
Allow matching on options in Geneve tunnel headers. This makes use of existing tunnel metadata support.
The options can be described in the form CLASS:TYPE:DATA/CLASS_MASK:TYPE_MASK:DATA_MASK, where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a variable length hexadecimal value.
e.g.
# ip link add name geneve0 type geneve dstport 0 external
# tc qdisc add dev geneve0 ingress
# tc filter add dev geneve0 protocol ip parent ffff: \
flower \
enc_src_ip 10.0.99.192 \
enc_dst_ip 10.0.99.193 \
enc_key_id 11 \
geneve_opts 0102:80:1122334421314151/ffff:ff:ffffffffffffffff \
ip_proto udp \
action mirred egress redirect dev eth1This patch adds support for matching Geneve options in the order supplied by the user. This leads to an efficient implementation in the software datapath (and in our opinion hardware datapaths that offload this feature). It is also compatible with Geneve options matching provided by the Open vSwitch kernel datapath which is relevant here as the Flower classifier may be used as a mechanism to program flows into hardware as a form of Open vSwitch datapath offload (sometimes referred to as OVS-TC). The netlink Kernel/Userspace API may be extended, for example by adding a flag, if other matching options are desired, for example matching given options in any order. This would require an implementation in the TC software datapath. And be done in a way that drivers that facilitate offload of the Flower classifier can reject or accept such flows based on hardware datapath capabilities.
This approach was discussed and agreed on at Netconf 2018 in Seoul.
--- include/uapi/linux/pkt_cls.h | 26 +++++ net/sched/cls_flower.c | 244 ++++++++++++++++++++++++++++++++++++++++++- 2 files changed, 269 insertions(+), 1 deletion(-)
include/uapi/linux/pkt_cls.h +26 -0
@@ -480,12 +480,38 @@ enum {TCA_FLOWER_KEY_ENC_IP_TTL ,/* u8 */ TCA_FLOWER_KEY_ENC_IP_TTL_MASK ,/* u8 */ +TCA_FLOWER_KEY_ENC_OPTS , +TCA_FLOWER_KEY_ENC_OPTS_MASK , + __TCA_FLOWER_MAX, };#define TCA_FLOWER_MAX (__TCA_FLOWER_MAX - 1)enum { +TCA_FLOWER_KEY_ENC_OPTS_UNSPEC , +TCA_FLOWER_KEY_ENC_OPTS_GENEVE ,/* Nested +* TCA_FLOWER_KEY_ENC_OPT_GENEVE_ +* attributes +*/ + __TCA_FLOWER_KEY_ENC_OPTS_MAX, +}; + +#define TCA_FLOWER_KEY_ENC_OPTS_MAX (__TCA_FLOWER_KEY_ENC_OPTS_MAX - 1) + +enum { +TCA_FLOWER_KEY_ENC_OPT_GENEVE_UNSPEC , +TCA_FLOWER_KEY_ENC_OPT_GENEVE_CLASS ,/* u16 */ +TCA_FLOWER_KEY_ENC_OPT_GENEVE_TYPE ,/* u8 */ +TCA_FLOWER_KEY_ENC_OPT_GENEVE_DATA ,/* 4 to 128 bytes */ + + __TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX, +}; + +#define TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX \ + (__TCA_FLOWER_KEY_ENC_OPT_GENEVE_MAX - 1) + +enum {TCA_FLOWER_KEY_FLAGS_IS_FRAGMENT = (1 <<0 ),TCA_FLOWER_KEY_FLAGS_FRAG_IS_FIRST = (1 <<1 ), };
net/sched/cls_flower.c +243 -1
292 lines not on this page · raw message
Signature · 1 line
2.11.0
Re: [PATCH net-next 4/6] net/sched: allow flower to match tunnel options
Quoted 37 lines · Simon Horman
From: Pieter Jansen van Vuuren <[email protected]>
Allow matching on options in Geneve tunnel headers. This makes use of existing tunnel metadata support.
The options can be described in the form CLASS:TYPE:DATA/CLASS_MASK:TYPE_MASK:DATA_MASK, where CLASS is represented as a 16bit hexadecimal value, TYPE as an 8bit hexadecimal value and DATA as a variable length hexadecimal value.
e.g.
# ip link add name geneve0 type geneve dstport 0 external # tc qdisc add dev geneve0 ingress # tc filter add dev geneve0 protocol ip parent ffff: \ flower \ enc_src_ip 10.0.99.192 \ enc_dst_ip 10.0.99.193 \ enc_key_id 11 \ geneve_opts 0102:80:1122334421314151/ffff:ff:ffffffffffffffff \ ip_proto udp \ action mirred egress redirect dev eth1This patch adds support for matching Geneve options in the order supplied by the user. This leads to an efficient implementation in the software datapath (and in our opinion hardware datapaths that offload this feature). It is also compatible with Geneve options matching provided by the Open vSwitch kernel datapath which is relevant here as the Flower classifier may be used as a mechanism to program flows into hardware as a form of Open vSwitch datapath offload (sometimes referred to as OVS-TC). The netlink Kernel/Userspace API may be extended, for example by adding a flag, if other matching options are desired, for example matching given options in any order. This would require an implementation in the TC software datapath. And be done in a way that drivers that facilitate offload of the Flower classifier can reject or accept such flows based on hardware datapath capabilities.
Quoted 1 line
This approach was discussed and agreed on at Netconf 2018 in Seoul.
2017, please fix
2018 was in Montreal
PATCH 5/6 nfp: flower: add geneve option push action offload
In reply to Simon HormanFrom: Pieter Jansen van Vuuren <[email protected]>
Introduce new push geneve option action. This allows offloading filters configured to entunnel geneve with options.
--- drivers/net/ethernet/netronome/nfp/flower/action.c | 100 +++++++++++++++++++-- drivers/net/ethernet/netronome/nfp/flower/cmsg.h | 20 ++++- drivers/net/ethernet/netronome/nfp/flower/main.h | 1 + 3 files changed, 114 insertions(+), 7 deletions(-)
drivers/net/ethernet/netronome/nfp/flower/action.c +94 -6
@@ -32,6 +32,7 @@*/ #include <linux/bitfield.h> +#include <net/geneve.h> #include <net/pkt_cls.h> #include <net/switchdev.h> #include <net/tc_act/tc_csum.h>
@@ -45,7 +46,15 @@#include "main.h" #include "../nfp_net_repr.h" -#define NFP_FL_SUPPORTED_IPV4_UDP_TUN_FLAGS (TUNNEL_CSUM | TUNNEL_KEY) +/* The kernel versions of TUNNEL_* are not ABI and therefore vulnerable +* to change. Such changes will break our FW ABI. +*/ +#define NFP_FL_TUNNEL_CSUM cpu_to_be16(0x01) +#define NFP_FL_TUNNEL_KEY cpu_to_be16(0x04) +#define NFP_FL_TUNNEL_GENEVE_OPT cpu_to_be16(0x0800) +#define NFP_FL_SUPPORTED_IPV4_UDP_TUN_FLAGS (NFP_FL_TUNNEL_CSUM | \ + NFP_FL_TUNNEL_KEY | \ + NFP_FL_TUNNEL_GENEVE_OPT)static void nfp_fl_pop_vlan (struct nfp_fl_pop_vlan *pop_vlan) {
@@ -229,7 +238,71 @@ static struct nfp_fl_pre_tunnel *nfp_fl_pre_tunnel(char *act_data, int act_len) }static int -nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun, +nfp_fl_push_geneve_options (struct nfp_fl_payload *nfp_fl,int *list_len, +const struct tc_action *action) +{ +struct ip_tunnel_info *ip_tun =tcf_tunnel_info (action); +int opt_len, opt_cnt, act_start, tot_push_len; +u8 *src =ip_tunnel_info_opts (ip_tun); + +/* We need to populate the options in reverse order for HW. +* Therefore we go through the options, calculating the +* number of options and the total size, then we populate +* them in reverse order in the action list. +*/ + opt_cnt =0 ; + tot_push_len =0 ; + opt_len = ip_tun->options_len; +while (opt_len >0 ) { +struct geneve_opt *opt = (struct geneve_opt *)src; + + opt_cnt++; +if (opt_cnt >NFP_FL_MAX_GENEVE_OPT_CNT ) +return -EOPNOTSUPP ; + + tot_push_len +=sizeof (struct nfp_fl_push_geneve ) + + opt->length *4 ; +if (tot_push_len >NFP_FL_MAX_GENEVE_OPT_ACT ) +return -EOPNOTSUPP ; + + opt_len -=sizeof (struct geneve_opt ) + opt->length *4 ; + src +=sizeof (struct geneve_opt ) + opt->length *4 ; + } + +if (*list_len + tot_push_len >NFP_FL_MAX_A_SIZ ) +return -EOPNOTSUPP ; + + act_start = *list_len; + *list_len += tot_push_len; + src =ip_tunnel_info_opts (ip_tun); +while (opt_cnt) { +struct geneve_opt *opt = (struct geneve_opt *)src; +struct nfp_fl_push_geneve *push; +size_t act_size, len; + + opt_cnt--; + act_size =sizeof (struct nfp_fl_push_geneve ) + opt->length *4 ; + tot_push_len -= act_size; + len = act_start + tot_push_len; + + push = (struct nfp_fl_push_geneve *)&nfp_fl->action_data[len]; + push->head.jump_id =NFP_FL_ACTION_OPCODE_PUSH_GENEVE ; + push->head.len_lw = act_size >>NFP_FL_LW_SIZ ; + push->reserved =0 ; + push->class = opt->opt_class; + push->type = opt->type; + push->length = opt->length; +memcpy (&push->opt_data, opt->opt_data, opt->length *4 ); + + src +=sizeof (struct geneve_opt ) + opt->length *4 ; + } + +return 0 ; +} + +static int +nfp_fl_set_ipv4_udp_tun(struct nfp_app *app, + struct nfp_fl_set_ipv4_udp_tun *set_tun, const struct tc_action *action, struct nfp_fl_pre_tunnel *pre_tun, enum nfp_flower_tun_type tun_type,
@@ -237,11 +310,17 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun, {size_t act_size =sizeof (struct nfp_fl_set_ipv4_udp_tun );struct ip_tunnel_info *ip_tun =tcf_tunnel_info (action); +struct nfp_flower_priv *priv = app->priv;u32 tmp_set_ip_tun_type_index =0 ;/* Currently support one pre-tunnel so index is always 0. */ int pretun_idx =0 ; -if (ip_tun->options_len) +BUILD_BUG_ON (NFP_FL_TUNNEL_CSUM !=TUNNEL_CSUM || +NFP_FL_TUNNEL_KEY !=TUNNEL_KEY || +NFP_FL_TUNNEL_GENEVE_OPT !=TUNNEL_GENEVE_OPT ); +if (ip_tun->options_len && + (tun_type !=NFP_FL_TUNNEL_GENEVE || + !(priv->flower_ext_feats &NFP_FL_FEATS_GENEVE_OPT )))return -EOPNOTSUPP ; set_tun->head.jump_id =NFP_FL_ACTION_OPCODE_SET_IPV4_TUNNEL ;
@@ -281,11 +360,16 @@ nfp_fl_set_ipv4_udp_tun(struct nfp_fl_set_ipv4_udp_tun *set_tun, set_tun->tos = ip_tun->key.tos; -if (!(ip_tun->key.tun_flags &TUNNEL_KEY ) || +if (!(ip_tun->key.tun_flags &NFP_FL_TUNNEL_KEY ) || ip_tun->key.tun_flags & ~NFP_FL_SUPPORTED_IPV4_UDP_TUN_FLAGS )return -EOPNOTSUPP ; set_tun->tun_flags = ip_tun->key.tun_flags; +if (tun_type ==NFP_FL_TUNNEL_GENEVE ) { + set_tun->tun_proto =htons (ETH_P_TEB ); + set_tun->tun_len = ip_tun->options_len /4 ; + } +/* Complete pre_tunnel action. */ pre_tun->ipv4_dst = ip_tun->key.u.ipv4.dst;
@@ -674,9 +758,13 @@ nfp_flower_loop_action(struct nfp_app *app, const struct tc_action *a, nfp_fl->meta.shortcut =cpu_to_be32 (NFP_FL_SC_ACT_NULL ); *a_len +=sizeof (struct nfp_fl_pre_tunnel ); + err =nfp_fl_push_geneve_options (nfp_fl, a_len, a); +if (err) +return err; + set_tun = (void *)&nfp_fl->action_data[*a_len]; - err =nfp_fl_set_ipv4_udp_tun (set_tun, a, pre_tun, *tun_type, - netdev); + err =nfp_fl_set_ipv4_udp_tun (app, set_tun, a, pre_tun, + *tun_type, netdev);if (err)return err; *a_len +=sizeof (struct nfp_fl_set_ipv4_udp_tun );
drivers/net/ethernet/netronome/nfp/flower/cmsg.h +19 -1
@@ -37,6 +37,7 @@#include <linux/bitfield.h> #include <linux/skbuff.h> #include <linux/types.h> +#include <net/geneve.h> #include "../nfp_app.h" #include "../nfpcore/nfp_cpp.h"
@@ -81,6 +82,10 @@#define NFP_FL_MAX_A_SIZ 1216#define NFP_FL_LW_SIZ 2 +/* Maximum allowed geneve options */ +#define NFP_FL_MAX_GENEVE_OPT_ACT 32 +#define NFP_FL_MAX_GENEVE_OPT_CNT 64 +/* Action opcodes */ #define NFP_FL_ACTION_OPCODE_OUTPUT 0#define NFP_FL_ACTION_OPCODE_PUSH_VLAN 1
@@ -94,6 +99,7 @@#define NFP_FL_ACTION_OPCODE_SET_TCP 15#define NFP_FL_ACTION_OPCODE_PRE_LAG 16#define NFP_FL_ACTION_OPCODE_PRE_TUNNEL 17 +#define NFP_FL_ACTION_OPCODE_PUSH_GENEVE 26#define NFP_FL_ACTION_OPCODE_NUM 32#define NFP_FL_OUT_FLAGS_LAST BIT(15)
@@ -206,7 +212,19 @@ struct nfp_fl_set_ipv4_udp_tun {__be16 tun_flags;u8 ttl;u8 tos; -__be32 extra[2 ]; +__be32 extra; +u8 tun_len; +u8 res2; +__be16 tun_proto; +}; + +struct nfp_fl_push_geneve { +struct nfp_fl_act_head head; +__be16 reserved; +__be16 class; +u8 type; +u8 length; +u8 opt_data[]; };/* Metadata with L2 (1W/4B)
drivers/net/ethernet/netronome/nfp/flower/main.h +1 -0
@@ -69,6 +69,7 @@ struct nfp_app;/* Extra features bitmap. */ #define NFP_FL_FEATS_GENEVE BIT(0)#define NFP_FL_NBI_MTU_SETTING BIT(1) +#define NFP_FL_FEATS_GENEVE_OPT BIT(2)#define NFP_FL_FEATS_LAG BIT(31)struct nfp_fl_mask_id {
Signature · 1 line
2.11.0
PATCH 6/6 nfp: flower: add geneve option match offload
In reply to Simon HormanFrom: Pieter Jansen van Vuuren <[email protected]>
Introduce a new layer for matching on geneve options. This allows offloading filters configured to match geneve with options.
--- drivers/net/ethernet/netronome/nfp/flower/cmsg.h | 6 ++++ drivers/net/ethernet/netronome/nfp/flower/match.c | 25 ++++++++++++++ .../net/ethernet/netronome/nfp/flower/offload.c | 38 ++++++++++++++++++++++ 3 files changed, 69 insertions(+)
drivers/net/ethernet/netronome/nfp/flower/cmsg.h +6 -0
@@ -52,6 +52,7 @@#define NFP_FLOWER_LAYER_VXLAN BIT(7)#define NFP_FLOWER_LAYER2_GENEVE BIT(5) +#define NFP_FLOWER_LAYER2_GENEVE_OP BIT(6)#define NFP_FLOWER_MASK_VLAN_PRIO GENMASK(15, 13)#define NFP_FLOWER_MASK_VLAN_CFI BIT(12)
@@ -85,6 +86,7 @@/* Maximum allowed geneve options */ #define NFP_FL_MAX_GENEVE_OPT_ACT 32#define NFP_FL_MAX_GENEVE_OPT_CNT 64 +#define NFP_FL_MAX_GENEVE_OPT_KEY 32/* Action opcodes */ #define NFP_FL_ACTION_OPCODE_OUTPUT 0
@@ -381,6 +383,10 @@ struct nfp_flower_ipv4_udp_tun {__be32 tun_id; }; +struct nfp_flower_geneve_options { +u8 data[NFP_FL_MAX_GENEVE_OPT_KEY ]; +}; +#define NFP_FL_TUN_VNI_OFFSET 8/* The base header for a control message packet.
drivers/net/ethernet/netronome/nfp/flower/match.c +25 -0
@@ -262,6 +262,21 @@ nfp_flower_compile_ipv6(struct nfp_flower_ipv6 *frame,nfp_flower_compile_ip_ext (&frame->ip_ext, flow, mask_version); } +static int +nfp_flower_compile_geneve_opt (void *key_buf,struct tc_cls_flower_offload *flow, +bool mask_version) +{ +struct fl_flow_key *target = mask_version ? flow->mask : flow->key; +struct flow_dissector_key_enc_opts *opts; + + opts =skb_flow_dissector_target (flow->dissector, +FLOW_DISSECTOR_KEY_ENC_OPTS , + target); +memcpy (key_buf, opts->data, opts->len); + +return 0 ; +} + static void nfp_flower_compile_ipv4_udp_tun(struct nfp_flower_ipv4_udp_tun *frame, struct tc_cls_flower_offload *flow,
@@ -424,6 +439,16 @@ int nfp_flower_compile_flow_match(struct tc_cls_flower_offload *flow, nfp_flow->nfp_tun_ipv4_addr = tun_dst;nfp_tunnel_add_ipv4_off (netdev_repr->app, tun_dst); } + +if (key_ls->key_layer_two &NFP_FLOWER_LAYER2_GENEVE_OP ) { + err =nfp_flower_compile_geneve_opt (ext, flow, false); +if (err) +return err; + + err =nfp_flower_compile_geneve_opt (msk, flow, true); +if (err) +return err; + } }return 0 ;
drivers/net/ethernet/netronome/nfp/flower/offload.c +38 -0
@@ -66,6 +66,7 @@BIT (FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS ) | \BIT (FLOW_DISSECTOR_KEY_ENC_CONTROL ) | \BIT (FLOW_DISSECTOR_KEY_ENC_PORTS ) | \ +BIT (FLOW_DISSECTOR_KEY_ENC_OPTS ) | \BIT (FLOW_DISSECTOR_KEY_ENC_IP ) | \BIT (FLOW_DISSECTOR_KEY_MPLS ) | \ BIT(FLOW_DISSECTOR_KEY_IP))
@@ -75,6 +76,7 @@BIT (FLOW_DISSECTOR_KEY_ENC_KEYID ) | \BIT (FLOW_DISSECTOR_KEY_ENC_IPV4_ADDRS ) | \BIT (FLOW_DISSECTOR_KEY_ENC_IPV6_ADDRS ) | \ +BIT (FLOW_DISSECTOR_KEY_ENC_OPTS ) | \BIT (FLOW_DISSECTOR_KEY_ENC_PORTS ) | \ BIT(FLOW_DISSECTOR_KEY_ENC_IP))
@@ -141,6 +143,21 @@ static bool nfp_flower_check_higher_than_mac(struct tc_cls_flower_offload *f) }static int +nfp_flower_calc_opt_layer (struct flow_dissector_key_enc_opts *enc_opts, +u32 *key_layer_two,int *key_size) +{ +if (enc_opts->len >NFP_FL_MAX_GENEVE_OPT_KEY ) +return -EOPNOTSUPP ; + +if (enc_opts->len >0 ) { + *key_layer_two |=NFP_FLOWER_LAYER2_GENEVE_OP ; + *key_size +=sizeof (struct nfp_flower_geneve_options ); + } + +return 0 ; +} + +static int nfp_flower_calculate_key_layers(struct nfp_app *app, struct nfp_fl_key_ls *ret_key_ls, struct tc_cls_flower_offload *flow,
@@ -153,6 +170,7 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,u32 key_layer_two;u8 key_layer;int key_size; +int err;if (flow->dissector->used_keys & ~NFP_FLOWER_WHITELIST_DISSECTOR )return -EOPNOTSUPP ;
@@ -178,6 +196,7 @@ nfp_flower_calculate_key_layers(struct nfp_app *app, FLOW_DISSECTOR_KEY_ENC_CONTROL)) {struct flow_dissector_key_ipv4_addrs *mask_ipv4 =NULL ;struct flow_dissector_key_ports *mask_enc_ports =NULL ; +struct flow_dissector_key_enc_opts *enc_op =NULL ;struct flow_dissector_key_ports *enc_ports =NULL ;struct flow_dissector_key_control *mask_enc_ctl = skb_flow_dissector_target(flow->dissector,
@@ -214,11 +233,21 @@ nfp_flower_calculate_key_layers(struct nfp_app *app,if (mask_enc_ports->dst !=cpu_to_be16 (~0 ))return -EOPNOTSUPP ; +if (dissector_uses_key (flow->dissector, +FLOW_DISSECTOR_KEY_ENC_OPTS )) { + enc_op =skb_flow_dissector_target (flow->dissector, +FLOW_DISSECTOR_KEY_ENC_OPTS , + flow->key); + } +switch (enc_ports->dst) {case htons (NFP_FL_VXLAN_PORT ): *tun_type =NFP_FL_TUNNEL_VXLAN ; key_layer |=NFP_FLOWER_LAYER_VXLAN ; key_size +=sizeof (struct nfp_flower_ipv4_udp_tun ); + +if (enc_op) +return -EOPNOTSUPP ;break ;case htons (NFP_FL_GENEVE_PORT ):if (!(priv->flower_ext_feats &NFP_FL_FEATS_GENEVE ))
@@ -228,6 +257,15 @@ nfp_flower_calculate_key_layers(struct nfp_app *app, key_size +=sizeof (struct nfp_flower_ext_meta ); key_layer_two |=NFP_FLOWER_LAYER2_GENEVE ; key_size +=sizeof (struct nfp_flower_ipv4_udp_tun ); + +if (!enc_op) +break ; +if (!(priv->flower_ext_feats &NFP_FL_FEATS_GENEVE_OPT )) +return -EOPNOTSUPP ; + err =nfp_flower_calc_opt_layer (enc_op, &key_layer_two, + &key_size); +if (err) +return err;break ;default :return -EOPNOTSUPP ;
Signature · 1 line
2.11.0
David Miller
maintainerFrom: Simon Horman <[email protected]>
Date: Tue, 7 Aug 2018 17:35:57 +0200
Quoted 7 lines
this series contains updates for the TC Flower classifier and the offload facility for it in the NFP driver.
* Patches 1 & 2: update the NFP driver to allow offload
of matching and setting tunnel ToS/TTL of flows using the TC Flower classifier andtun_keyaction
Quoted 6 lines
* Patches 3 & 4: enhance the flow dissector and TC Flower classifier to allow match on Geneve options
* Patch 5 & 6: update the NFP driver to allow offload of matching and setting Geneve options of flows using the TC Flower classifier and
tun_keyaction
Series applied with the year fixed in the commit message of patch #4.
Thanks.