]> git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/commitdiff
net: sched: include mpls actions in hardware intermediate representation
authorJohn Hurley <john.hurley@netronome.com>
Tue, 23 Jul 2019 14:33:59 +0000 (15:33 +0100)
committerDavid S. Miller <davem@davemloft.net>
Tue, 23 Jul 2019 20:52:50 +0000 (13:52 -0700)
A recent addition to TC actions is the ability to manipulate the MPLS
headers on packets.

In preparation to offload such actions to hardware, update the IR code to
accept and prepare the new actions.

Note that no driver currently impliments the MPLS dec_ttl action so this
is not included.

Signed-off-by: John Hurley <john.hurley@netronome.com>
Reviewed-by: Jakub Kicinski <jakub.kicinski@netronome.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
include/net/flow_offload.h
include/net/tc_act/tc_mpls.h
net/sched/cls_api.c

index b16d21636d6969113549f7d943037694914a50d1..00b9aab5fdc1289678d51e7e6cf3f6f218f3ca05 100644 (file)
@@ -131,6 +131,9 @@ enum flow_action_id {
        FLOW_ACTION_SAMPLE,
        FLOW_ACTION_POLICE,
        FLOW_ACTION_CT,
+       FLOW_ACTION_MPLS_PUSH,
+       FLOW_ACTION_MPLS_POP,
+       FLOW_ACTION_MPLS_MANGLE,
 };
 
 /* This is mirroring enum pedit_header_type definition for easy mapping between
@@ -184,6 +187,22 @@ struct flow_action_entry {
                        int action;
                        u16 zone;
                } ct;
+               struct {                                /* FLOW_ACTION_MPLS_PUSH */
+                       u32             label;
+                       __be16          proto;
+                       u8              tc;
+                       u8              bos;
+                       u8              ttl;
+               } mpls_push;
+               struct {                                /* FLOW_ACTION_MPLS_POP */
+                       __be16          proto;
+               } mpls_pop;
+               struct {                                /* FLOW_ACTION_MPLS_MANGLE */
+                       u32             label;
+                       u8              tc;
+                       u8              bos;
+                       u8              ttl;
+               } mpls_mangle;
        };
 };
 
index 4bc3d9250ef0b18a484ce9faa9adbd2f23dfa959..721de4f5733a9366d37457d8b7307d78ae2f4903 100644 (file)
@@ -27,4 +27,79 @@ struct tcf_mpls {
 };
 #define to_mpls(a) ((struct tcf_mpls *)a)
 
+static inline bool is_tcf_mpls(const struct tc_action *a)
+{
+#ifdef CONFIG_NET_CLS_ACT
+       if (a->ops && a->ops->id == TCA_ID_MPLS)
+               return true;
+#endif
+       return false;
+}
+
+static inline u32 tcf_mpls_action(const struct tc_action *a)
+{
+       u32 tcfm_action;
+
+       rcu_read_lock();
+       tcfm_action = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_action;
+       rcu_read_unlock();
+
+       return tcfm_action;
+}
+
+static inline __be16 tcf_mpls_proto(const struct tc_action *a)
+{
+       __be16 tcfm_proto;
+
+       rcu_read_lock();
+       tcfm_proto = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_proto;
+       rcu_read_unlock();
+
+       return tcfm_proto;
+}
+
+static inline u32 tcf_mpls_label(const struct tc_action *a)
+{
+       u32 tcfm_label;
+
+       rcu_read_lock();
+       tcfm_label = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_label;
+       rcu_read_unlock();
+
+       return tcfm_label;
+}
+
+static inline u8 tcf_mpls_tc(const struct tc_action *a)
+{
+       u8 tcfm_tc;
+
+       rcu_read_lock();
+       tcfm_tc = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_tc;
+       rcu_read_unlock();
+
+       return tcfm_tc;
+}
+
+static inline u8 tcf_mpls_bos(const struct tc_action *a)
+{
+       u8 tcfm_bos;
+
+       rcu_read_lock();
+       tcfm_bos = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_bos;
+       rcu_read_unlock();
+
+       return tcfm_bos;
+}
+
+static inline u8 tcf_mpls_ttl(const struct tc_action *a)
+{
+       u8 tcfm_ttl;
+
+       rcu_read_lock();
+       tcfm_ttl = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_ttl;
+       rcu_read_unlock();
+
+       return tcfm_ttl;
+}
+
 #endif /* __NET_TC_MPLS_H */
index efd3cfb80a2ad775dc8ab3c4900bd73d52c7aaad..3565d9aa09aace4e97683c3fd39cfb50b45d6082 100644 (file)
@@ -36,6 +36,7 @@
 #include <net/tc_act/tc_sample.h>
 #include <net/tc_act/tc_skbedit.h>
 #include <net/tc_act/tc_ct.h>
+#include <net/tc_act/tc_mpls.h>
 
 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1];
 
@@ -3269,6 +3270,30 @@ int tc_setup_flow_action(struct flow_action *flow_action,
                        entry->id = FLOW_ACTION_CT;
                        entry->ct.action = tcf_ct_action(act);
                        entry->ct.zone = tcf_ct_zone(act);
+               } else if (is_tcf_mpls(act)) {
+                       switch (tcf_mpls_action(act)) {
+                       case TCA_MPLS_ACT_PUSH:
+                               entry->id = FLOW_ACTION_MPLS_PUSH;
+                               entry->mpls_push.proto = tcf_mpls_proto(act);
+                               entry->mpls_push.label = tcf_mpls_label(act);
+                               entry->mpls_push.tc = tcf_mpls_tc(act);
+                               entry->mpls_push.bos = tcf_mpls_bos(act);
+                               entry->mpls_push.ttl = tcf_mpls_ttl(act);
+                               break;
+                       case TCA_MPLS_ACT_POP:
+                               entry->id = FLOW_ACTION_MPLS_POP;
+                               entry->mpls_pop.proto = tcf_mpls_proto(act);
+                               break;
+                       case TCA_MPLS_ACT_MODIFY:
+                               entry->id = FLOW_ACTION_MPLS_MANGLE;
+                               entry->mpls_mangle.label = tcf_mpls_label(act);
+                               entry->mpls_mangle.tc = tcf_mpls_tc(act);
+                               entry->mpls_mangle.bos = tcf_mpls_bos(act);
+                               entry->mpls_mangle.ttl = tcf_mpls_ttl(act);
+                               break;
+                       default:
+                               goto err_out;
+                       }
                } else {
                        goto err_out;
                }