Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 1 | #ifndef MPLS_INTERNAL_H |
| 2 | #define MPLS_INTERNAL_H |
| 3 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 4 | struct mpls_shim_hdr { |
| 5 | __be32 label_stack_entry; |
| 6 | }; |
| 7 | |
| 8 | struct mpls_entry_decoded { |
| 9 | u32 label; |
| 10 | u8 ttl; |
| 11 | u8 tc; |
| 12 | u8 bos; |
| 13 | }; |
| 14 | |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 15 | struct mpls_dev { |
Robert Shearman | 37bde79 | 2015-04-22 11:14:38 +0100 | [diff] [blame] | 16 | int input_enabled; |
| 17 | |
| 18 | struct ctl_table_header *sysctl; |
Robert Shearman | 25cc8f0 | 2015-06-05 18:54:45 +0100 | [diff] [blame] | 19 | struct rcu_head rcu; |
Robert Shearman | 03c5774 | 2015-04-22 11:14:37 +0100 | [diff] [blame] | 20 | }; |
| 21 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 22 | struct sk_buff; |
| 23 | |
| 24 | static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) |
| 25 | { |
| 26 | return (struct mpls_shim_hdr *)skb_network_header(skb); |
| 27 | } |
| 28 | |
| 29 | static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos) |
| 30 | { |
| 31 | struct mpls_shim_hdr result; |
| 32 | result.label_stack_entry = |
| 33 | cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | |
| 34 | (tc << MPLS_LS_TC_SHIFT) | |
| 35 | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | |
| 36 | (ttl << MPLS_LS_TTL_SHIFT)); |
| 37 | return result; |
| 38 | } |
| 39 | |
| 40 | static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr) |
| 41 | { |
| 42 | struct mpls_entry_decoded result; |
| 43 | unsigned entry = be32_to_cpu(hdr->label_stack_entry); |
| 44 | |
| 45 | result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT; |
| 46 | result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT; |
| 47 | result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT; |
| 48 | result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT; |
| 49 | |
| 50 | return result; |
| 51 | } |
| 52 | |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame^] | 53 | int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels, |
| 54 | const u32 label[]); |
| 55 | int nla_get_labels(const struct nlattr *nla, u32 max_labels, u32 *labels, |
| 56 | u32 label[]); |
| 57 | bool mpls_output_possible(const struct net_device *dev); |
| 58 | unsigned int mpls_dev_mtu(const struct net_device *dev); |
| 59 | bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu); |
Eric W. Biederman | 966bae3 | 2015-03-03 19:13:19 -0600 | [diff] [blame] | 60 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 61 | #endif /* MPLS_INTERNAL_H */ |