blob: b064c345042c17ccd9ec841535857fb29041a8a3 [file] [log] [blame]
Eric W. Biederman01891972015-03-03 19:10:47 -06001#ifndef MPLS_INTERNAL_H
2#define MPLS_INTERNAL_H
3
Eric W. Biederman01891972015-03-03 19:10:47 -06004struct mpls_shim_hdr {
5 __be32 label_stack_entry;
6};
7
8struct mpls_entry_decoded {
9 u32 label;
10 u8 ttl;
11 u8 tc;
12 u8 bos;
13};
14
Robert Shearman03c57742015-04-22 11:14:37 +010015struct mpls_dev {
Robert Shearman37bde792015-04-22 11:14:38 +010016 int input_enabled;
17
18 struct ctl_table_header *sysctl;
Robert Shearman03c57742015-04-22 11:14:37 +010019};
20
Eric W. Biederman01891972015-03-03 19:10:47 -060021struct sk_buff;
22
23static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
24{
25 return (struct mpls_shim_hdr *)skb_network_header(skb);
26}
27
28static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
29{
30 struct mpls_shim_hdr result;
31 result.label_stack_entry =
32 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
33 (tc << MPLS_LS_TC_SHIFT) |
34 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
35 (ttl << MPLS_LS_TTL_SHIFT));
36 return result;
37}
38
39static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
40{
41 struct mpls_entry_decoded result;
42 unsigned entry = be32_to_cpu(hdr->label_stack_entry);
43
44 result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
45 result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
46 result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
47 result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
48
49 return result;
50}
51
Eric W. Biederman966bae32015-03-03 19:13:19 -060052int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels, const u32 label[]);
53int nla_get_labels(const struct nlattr *nla, u32 max_labels, u32 *labels, u32 label[]);
54
Eric W. Biederman01891972015-03-03 19:10:47 -060055#endif /* MPLS_INTERNAL_H */