xref: /linux/include/net/tc_act/tc_mpls.h (revision 6749d590)
12a2ea508SJohn Hurley /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
22a2ea508SJohn Hurley /* Copyright (C) 2019 Netronome Systems, Inc. */
32a2ea508SJohn Hurley 
42a2ea508SJohn Hurley #ifndef __NET_TC_MPLS_H
52a2ea508SJohn Hurley #define __NET_TC_MPLS_H
62a2ea508SJohn Hurley 
72a2ea508SJohn Hurley #include <linux/tc_act/tc_mpls.h>
82a2ea508SJohn Hurley #include <net/act_api.h>
92a2ea508SJohn Hurley 
102a2ea508SJohn Hurley struct tcf_mpls_params {
112a2ea508SJohn Hurley 	int tcfm_action;
122a2ea508SJohn Hurley 	u32 tcfm_label;
132a2ea508SJohn Hurley 	u8 tcfm_tc;
142a2ea508SJohn Hurley 	u8 tcfm_ttl;
152a2ea508SJohn Hurley 	u8 tcfm_bos;
162a2ea508SJohn Hurley 	__be16 tcfm_proto;
172a2ea508SJohn Hurley 	struct rcu_head	rcu;
182a2ea508SJohn Hurley };
192a2ea508SJohn Hurley 
202a2ea508SJohn Hurley #define ACT_MPLS_TC_NOT_SET	0xff
212a2ea508SJohn Hurley #define ACT_MPLS_BOS_NOT_SET	0xff
222a2ea508SJohn Hurley #define ACT_MPLS_LABEL_NOT_SET	0xffffffff
232a2ea508SJohn Hurley 
242a2ea508SJohn Hurley struct tcf_mpls {
252a2ea508SJohn Hurley 	struct tc_action common;
262a2ea508SJohn Hurley 	struct tcf_mpls_params __rcu *mpls_p;
272a2ea508SJohn Hurley };
282a2ea508SJohn Hurley #define to_mpls(a) ((struct tcf_mpls *)a)
292a2ea508SJohn Hurley 
is_tcf_mpls(const struct tc_action * a)30*6749d590SJohn Hurley static inline bool is_tcf_mpls(const struct tc_action *a)
31*6749d590SJohn Hurley {
32*6749d590SJohn Hurley #ifdef CONFIG_NET_CLS_ACT
33*6749d590SJohn Hurley 	if (a->ops && a->ops->id == TCA_ID_MPLS)
34*6749d590SJohn Hurley 		return true;
35*6749d590SJohn Hurley #endif
36*6749d590SJohn Hurley 	return false;
37*6749d590SJohn Hurley }
38*6749d590SJohn Hurley 
tcf_mpls_action(const struct tc_action * a)39*6749d590SJohn Hurley static inline u32 tcf_mpls_action(const struct tc_action *a)
40*6749d590SJohn Hurley {
41*6749d590SJohn Hurley 	u32 tcfm_action;
42*6749d590SJohn Hurley 
43*6749d590SJohn Hurley 	rcu_read_lock();
44*6749d590SJohn Hurley 	tcfm_action = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_action;
45*6749d590SJohn Hurley 	rcu_read_unlock();
46*6749d590SJohn Hurley 
47*6749d590SJohn Hurley 	return tcfm_action;
48*6749d590SJohn Hurley }
49*6749d590SJohn Hurley 
tcf_mpls_proto(const struct tc_action * a)50*6749d590SJohn Hurley static inline __be16 tcf_mpls_proto(const struct tc_action *a)
51*6749d590SJohn Hurley {
52*6749d590SJohn Hurley 	__be16 tcfm_proto;
53*6749d590SJohn Hurley 
54*6749d590SJohn Hurley 	rcu_read_lock();
55*6749d590SJohn Hurley 	tcfm_proto = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_proto;
56*6749d590SJohn Hurley 	rcu_read_unlock();
57*6749d590SJohn Hurley 
58*6749d590SJohn Hurley 	return tcfm_proto;
59*6749d590SJohn Hurley }
60*6749d590SJohn Hurley 
tcf_mpls_label(const struct tc_action * a)61*6749d590SJohn Hurley static inline u32 tcf_mpls_label(const struct tc_action *a)
62*6749d590SJohn Hurley {
63*6749d590SJohn Hurley 	u32 tcfm_label;
64*6749d590SJohn Hurley 
65*6749d590SJohn Hurley 	rcu_read_lock();
66*6749d590SJohn Hurley 	tcfm_label = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_label;
67*6749d590SJohn Hurley 	rcu_read_unlock();
68*6749d590SJohn Hurley 
69*6749d590SJohn Hurley 	return tcfm_label;
70*6749d590SJohn Hurley }
71*6749d590SJohn Hurley 
tcf_mpls_tc(const struct tc_action * a)72*6749d590SJohn Hurley static inline u8 tcf_mpls_tc(const struct tc_action *a)
73*6749d590SJohn Hurley {
74*6749d590SJohn Hurley 	u8 tcfm_tc;
75*6749d590SJohn Hurley 
76*6749d590SJohn Hurley 	rcu_read_lock();
77*6749d590SJohn Hurley 	tcfm_tc = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_tc;
78*6749d590SJohn Hurley 	rcu_read_unlock();
79*6749d590SJohn Hurley 
80*6749d590SJohn Hurley 	return tcfm_tc;
81*6749d590SJohn Hurley }
82*6749d590SJohn Hurley 
tcf_mpls_bos(const struct tc_action * a)83*6749d590SJohn Hurley static inline u8 tcf_mpls_bos(const struct tc_action *a)
84*6749d590SJohn Hurley {
85*6749d590SJohn Hurley 	u8 tcfm_bos;
86*6749d590SJohn Hurley 
87*6749d590SJohn Hurley 	rcu_read_lock();
88*6749d590SJohn Hurley 	tcfm_bos = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_bos;
89*6749d590SJohn Hurley 	rcu_read_unlock();
90*6749d590SJohn Hurley 
91*6749d590SJohn Hurley 	return tcfm_bos;
92*6749d590SJohn Hurley }
93*6749d590SJohn Hurley 
tcf_mpls_ttl(const struct tc_action * a)94*6749d590SJohn Hurley static inline u8 tcf_mpls_ttl(const struct tc_action *a)
95*6749d590SJohn Hurley {
96*6749d590SJohn Hurley 	u8 tcfm_ttl;
97*6749d590SJohn Hurley 
98*6749d590SJohn Hurley 	rcu_read_lock();
99*6749d590SJohn Hurley 	tcfm_ttl = rcu_dereference(to_mpls(a)->mpls_p)->tcfm_ttl;
100*6749d590SJohn Hurley 	rcu_read_unlock();
101*6749d590SJohn Hurley 
102*6749d590SJohn Hurley 	return tcfm_ttl;
103*6749d590SJohn Hurley }
104*6749d590SJohn Hurley 
1052a2ea508SJohn Hurley #endif /* __NET_TC_MPLS_H */
106