Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

net: sched: include mpls actions in hardware intermediate representation

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>

authored by

John Hurley and committed by
David S. Miller
6749d590 658688ce

+119
+19
include/net/flow_offload.h
··· 131 131 FLOW_ACTION_SAMPLE, 132 132 FLOW_ACTION_POLICE, 133 133 FLOW_ACTION_CT, 134 + FLOW_ACTION_MPLS_PUSH, 135 + FLOW_ACTION_MPLS_POP, 136 + FLOW_ACTION_MPLS_MANGLE, 134 137 }; 135 138 136 139 /* This is mirroring enum pedit_header_type definition for easy mapping between ··· 187 184 int action; 188 185 u16 zone; 189 186 } ct; 187 + struct { /* FLOW_ACTION_MPLS_PUSH */ 188 + u32 label; 189 + __be16 proto; 190 + u8 tc; 191 + u8 bos; 192 + u8 ttl; 193 + } mpls_push; 194 + struct { /* FLOW_ACTION_MPLS_POP */ 195 + __be16 proto; 196 + } mpls_pop; 197 + struct { /* FLOW_ACTION_MPLS_MANGLE */ 198 + u32 label; 199 + u8 tc; 200 + u8 bos; 201 + u8 ttl; 202 + } mpls_mangle; 190 203 }; 191 204 }; 192 205
+75
include/net/tc_act/tc_mpls.h
··· 27 27 }; 28 28 #define to_mpls(a) ((struct tcf_mpls *)a) 29 29 30 + static inline bool is_tcf_mpls(const struct tc_action *a) 31 + { 32 + #ifdef CONFIG_NET_CLS_ACT 33 + if (a->ops && a->ops->id == TCA_ID_MPLS) 34 + return true; 35 + #endif 36 + return false; 37 + } 38 + 39 + static inline u32 tcf_mpls_action(const struct tc_action *a) 40 + { 41 + u32 tcfm_action; 42 + 43 + rcu_read_lock(); 44 + tcfm_action = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_action; 45 + rcu_read_unlock(); 46 + 47 + return tcfm_action; 48 + } 49 + 50 + static inline __be16 tcf_mpls_proto(const struct tc_action *a) 51 + { 52 + __be16 tcfm_proto; 53 + 54 + rcu_read_lock(); 55 + tcfm_proto = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_proto; 56 + rcu_read_unlock(); 57 + 58 + return tcfm_proto; 59 + } 60 + 61 + static inline u32 tcf_mpls_label(const struct tc_action *a) 62 + { 63 + u32 tcfm_label; 64 + 65 + rcu_read_lock(); 66 + tcfm_label = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_label; 67 + rcu_read_unlock(); 68 + 69 + return tcfm_label; 70 + } 71 + 72 + static inline u8 tcf_mpls_tc(const struct tc_action *a) 73 + { 74 + u8 tcfm_tc; 75 + 76 + rcu_read_lock(); 77 + tcfm_tc = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_tc; 78 + rcu_read_unlock(); 79 + 80 + return tcfm_tc; 81 + } 82 + 83 + static inline u8 tcf_mpls_bos(const struct tc_action *a) 84 + { 85 + u8 tcfm_bos; 86 + 87 + rcu_read_lock(); 88 + tcfm_bos = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_bos; 89 + rcu_read_unlock(); 90 + 91 + return tcfm_bos; 92 + } 93 + 94 + static inline u8 tcf_mpls_ttl(const struct tc_action *a) 95 + { 96 + u8 tcfm_ttl; 97 + 98 + rcu_read_lock(); 99 + tcfm_ttl = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_ttl; 100 + rcu_read_unlock(); 101 + 102 + return tcfm_ttl; 103 + } 104 + 30 105 #endif /* __NET_TC_MPLS_H */
+25
net/sched/cls_api.c
··· 36 36 #include <net/tc_act/tc_sample.h> 37 37 #include <net/tc_act/tc_skbedit.h> 38 38 #include <net/tc_act/tc_ct.h> 39 + #include <net/tc_act/tc_mpls.h> 39 40 40 41 extern const struct nla_policy rtm_tca_policy[TCA_MAX + 1]; 41 42 ··· 3270 3269 entry->id = FLOW_ACTION_CT; 3271 3270 entry->ct.action = tcf_ct_action(act); 3272 3271 entry->ct.zone = tcf_ct_zone(act); 3272 + } else if (is_tcf_mpls(act)) { 3273 + switch (tcf_mpls_action(act)) { 3274 + case TCA_MPLS_ACT_PUSH: 3275 + entry->id = FLOW_ACTION_MPLS_PUSH; 3276 + entry->mpls_push.proto = tcf_mpls_proto(act); 3277 + entry->mpls_push.label = tcf_mpls_label(act); 3278 + entry->mpls_push.tc = tcf_mpls_tc(act); 3279 + entry->mpls_push.bos = tcf_mpls_bos(act); 3280 + entry->mpls_push.ttl = tcf_mpls_ttl(act); 3281 + break; 3282 + case TCA_MPLS_ACT_POP: 3283 + entry->id = FLOW_ACTION_MPLS_POP; 3284 + entry->mpls_pop.proto = tcf_mpls_proto(act); 3285 + break; 3286 + case TCA_MPLS_ACT_MODIFY: 3287 + entry->id = FLOW_ACTION_MPLS_MANGLE; 3288 + entry->mpls_mangle.label = tcf_mpls_label(act); 3289 + entry->mpls_mangle.tc = tcf_mpls_tc(act); 3290 + entry->mpls_mangle.bos = tcf_mpls_bos(act); 3291 + entry->mpls_mangle.ttl = tcf_mpls_ttl(act); 3292 + break; 3293 + default: 3294 + goto err_out; 3295 + } 3273 3296 } else { 3274 3297 goto err_out; 3275 3298 }