xref: /linux/net/mpls/internal.h (revision 2decb2682f80759f631c8332f9a2a34a02150a03)
1 #ifndef MPLS_INTERNAL_H
2 #define MPLS_INTERNAL_H
3 
4 #define LABEL_IPV4_EXPLICIT_NULL	0 /* RFC3032 */
5 #define LABEL_ROUTER_ALERT_LABEL	1 /* RFC3032 */
6 #define LABEL_IPV6_EXPLICIT_NULL	2 /* RFC3032 */
7 #define LABEL_IMPLICIT_NULL		3 /* RFC3032 */
8 #define LABEL_ENTROPY_INDICATOR		7 /* RFC6790 */
9 #define LABEL_GAL			13 /* RFC5586 */
10 #define LABEL_OAM_ALERT			14 /* RFC3429 */
11 #define LABEL_EXTENSION			15 /* RFC7274 */
12 
13 
14 struct mpls_shim_hdr {
15 	__be32 label_stack_entry;
16 };
17 
18 struct mpls_entry_decoded {
19 	u32 label;
20 	u8 ttl;
21 	u8 tc;
22 	u8 bos;
23 };
24 
25 struct mpls_dev {
26 	int			input_enabled;
27 
28 	struct ctl_table_header *sysctl;
29 };
30 
31 struct sk_buff;
32 
33 static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
34 {
35 	return (struct mpls_shim_hdr *)skb_network_header(skb);
36 }
37 
38 static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
39 {
40 	struct mpls_shim_hdr result;
41 	result.label_stack_entry =
42 		cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
43 			    (tc << MPLS_LS_TC_SHIFT) |
44 			    (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
45 			    (ttl << MPLS_LS_TTL_SHIFT));
46 	return result;
47 }
48 
49 static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
50 {
51 	struct mpls_entry_decoded result;
52 	unsigned entry = be32_to_cpu(hdr->label_stack_entry);
53 
54 	result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
55 	result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
56 	result.tc =  (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
57 	result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
58 
59 	return result;
60 }
61 
62 int nla_put_labels(struct sk_buff *skb, int attrtype,  u8 labels, const u32 label[]);
63 int nla_get_labels(const struct nlattr *nla, u32 max_labels, u32 *labels, u32 label[]);
64 
65 #endif /* MPLS_INTERNAL_H */
66