nfp: flower: add GRE encap action support
authorPieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
Thu, 27 Jun 2019 23:12:43 +0000 (16:12 -0700)
committerDavid S. Miller <davem@davemloft.net>
Fri, 28 Jun 2019 02:47:36 +0000 (19:47 -0700)
Add new GRE encapsulation support, which allows offload of filters
using tunnel_key set action in combination with actions that egress
to GRE type ports.

Signed-off-by: Pieter Jansen van Vuuren <pieter.jansenvanvuuren@netronome.com>
Signed-off-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Reviewed-by: John Hurley <john.hurley@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/ethernet/netronome/nfp/flower/action.c

index 88fedb5..b6bd31f 100644 (file)
@@ -170,13 +170,36 @@ nfp_fl_output(struct nfp_app *app, struct nfp_fl_output *output,
        return 0;
 }
 
+static bool
+nfp_flower_tun_is_gre(struct tc_cls_flower_offload *flow, int start_idx)
+{
+       struct flow_action_entry *act = flow->rule->action.entries;
+       int num_act = flow->rule->action.num_entries;
+       int act_idx;
+
+       /* Preparse action list for next mirred or redirect action */
+       for (act_idx = start_idx + 1; act_idx < num_act; act_idx++)
+               if (act[act_idx].id == FLOW_ACTION_REDIRECT ||
+                   act[act_idx].id == FLOW_ACTION_MIRRED)
+                       return netif_is_gretap(act[act_idx].dev);
+
+       return false;
+}
+
 static enum nfp_flower_tun_type
 nfp_fl_get_tun_from_act(struct nfp_app *app,
-                       const struct flow_action_entry *act)
+                       struct tc_cls_flower_offload *flow,
+                       const struct flow_action_entry *act, int act_idx)
 {
        const struct ip_tunnel_info *tun = act->tunnel;
        struct nfp_flower_priv *priv = app->priv;
 
+       /* Determine the tunnel type based on the egress netdev
+        * in the mirred action for tunnels without l4.
+        */
+       if (nfp_flower_tun_is_gre(flow, act_idx))
+               return NFP_FL_TUNNEL_GRE;
+
        switch (tun->key.tp_dst) {
        case htons(IANA_VXLAN_UDP_PORT):
                return NFP_FL_TUNNEL_VXLAN;
@@ -841,7 +864,7 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
                       enum nfp_flower_tun_type *tun_type, int *tun_out_cnt,
                       int *out_cnt, u32 *csum_updated,
                       struct nfp_flower_pedit_acts *set_act,
-                      struct netlink_ext_ack *extack)
+                      struct netlink_ext_ack *extack, int act_idx)
 {
        struct nfp_fl_set_ipv4_tun *set_tun;
        struct nfp_fl_pre_tunnel *pre_tun;
@@ -896,7 +919,7 @@ nfp_flower_loop_action(struct nfp_app *app, const struct flow_action_entry *act,
        case FLOW_ACTION_TUNNEL_ENCAP: {
                const struct ip_tunnel_info *ip_tun = act->tunnel;
 
-               *tun_type = nfp_fl_get_tun_from_act(app, act);
+               *tun_type = nfp_fl_get_tun_from_act(app, flow, act, act_idx);
                if (*tun_type == NFP_FL_TUNNEL_NONE) {
                        NL_SET_ERR_MSG_MOD(extack, "unsupported offload: unsupported tunnel type in action list");
                        return -EOPNOTSUPP;
@@ -1022,8 +1045,8 @@ int nfp_flower_compile_action(struct nfp_app *app,
                        memset(&set_act, 0, sizeof(set_act));
                err = nfp_flower_loop_action(app, act, flow, nfp_flow, &act_len,
                                             netdev, &tun_type, &tun_out_cnt,
-                                            &out_cnt, &csum_updated, &set_act,
-                                            extack);
+                                            &out_cnt, &csum_updated,
+                                            &set_act, extack, i);
                if (err)
                        return err;
                act_cnt++;