xref: /linux/include/net/tc_act/tc_mpls.h (revision 24bce201d79807b668bf9d9e0aca801c5c0d5f78)
1 /* SPDX-License-Identifier: (GPL-2.0-only OR BSD-2-Clause) */
2 /* Copyright (C) 2019 Netronome Systems, Inc. */
3 
4 #ifndef __NET_TC_MPLS_H
5 #define __NET_TC_MPLS_H
6 
7 #include <linux/tc_act/tc_mpls.h>
8 #include <net/act_api.h>
9 
10 struct tcf_mpls_params {
11 	int tcfm_action;
12 	u32 tcfm_label;
13 	u8 tcfm_tc;
14 	u8 tcfm_ttl;
15 	u8 tcfm_bos;
16 	__be16 tcfm_proto;
17 	struct rcu_head	rcu;
18 };
19 
20 #define ACT_MPLS_TC_NOT_SET	0xff
21 #define ACT_MPLS_BOS_NOT_SET	0xff
22 #define ACT_MPLS_LABEL_NOT_SET	0xffffffff
23 
24 struct tcf_mpls {
25 	struct tc_action common;
26 	struct tcf_mpls_params __rcu *mpls_p;
27 };
28 #define to_mpls(a) ((struct tcf_mpls *)a)
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 
105 #endif /* __NET_TC_MPLS_H */
106