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 | |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 24 | #define LABEL_NOT_SPECIFIED (1 << 20) |
| 25 | #define MAX_NEW_LABELS 2 |
| 26 | |
| 27 | /* This maximum ha length copied from the definition of struct neighbour */ |
Robert Shearman | cf4b24f | 2015-10-27 00:37:36 +0000 | [diff] [blame] | 28 | #define VIA_ALEN_ALIGN sizeof(unsigned long) |
| 29 | #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN)) |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 30 | |
| 31 | enum mpls_payload_type { |
| 32 | MPT_UNSPEC, /* IPv4 or IPv6 */ |
| 33 | MPT_IPV4 = 4, |
| 34 | MPT_IPV6 = 6, |
| 35 | |
| 36 | /* Other types not implemented: |
| 37 | * - Pseudo-wire with or without control word (RFC4385) |
| 38 | * - GAL (RFC5586) |
| 39 | */ |
| 40 | }; |
| 41 | |
| 42 | struct mpls_nh { /* next hop label forwarding entry */ |
| 43 | struct net_device __rcu *nh_dev; |
| 44 | u32 nh_label[MAX_NEW_LABELS]; |
| 45 | u8 nh_labels; |
| 46 | u8 nh_via_alen; |
| 47 | u8 nh_via_table; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 48 | }; |
| 49 | |
Robert Shearman | cf4b24f | 2015-10-27 00:37:36 +0000 | [diff] [blame] | 50 | /* The route, nexthops and vias are stored together in the same memory |
| 51 | * block: |
| 52 | * |
| 53 | * +----------------------+ |
| 54 | * | mpls_route | |
| 55 | * +----------------------+ |
| 56 | * | mpls_nh 0 | |
| 57 | * +----------------------+ |
| 58 | * | ... | |
| 59 | * +----------------------+ |
| 60 | * | mpls_nh n-1 | |
| 61 | * +----------------------+ |
| 62 | * | alignment padding | |
| 63 | * +----------------------+ |
| 64 | * | via[rt_max_alen] 0 | |
| 65 | * +----------------------+ |
| 66 | * | ... | |
| 67 | * +----------------------+ |
| 68 | * | via[rt_max_alen] n-1 | |
| 69 | * +----------------------+ |
| 70 | */ |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 71 | struct mpls_route { /* next hop label forwarding entry */ |
| 72 | struct rcu_head rt_rcu; |
| 73 | u8 rt_protocol; |
| 74 | u8 rt_payload_type; |
Robert Shearman | cf4b24f | 2015-10-27 00:37:36 +0000 | [diff] [blame] | 75 | u8 rt_max_alen; |
| 76 | unsigned int rt_nhn; |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 77 | struct mpls_nh rt_nh[0]; |
| 78 | }; |
| 79 | |
| 80 | #define for_nexthops(rt) { \ |
| 81 | int nhsel; struct mpls_nh *nh; \ |
| 82 | for (nhsel = 0, nh = (rt)->rt_nh; \ |
| 83 | nhsel < (rt)->rt_nhn; \ |
| 84 | nh++, nhsel++) |
| 85 | |
| 86 | #define change_nexthops(rt) { \ |
| 87 | int nhsel; struct mpls_nh *nh; \ |
| 88 | for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \ |
| 89 | nhsel < (rt)->rt_nhn; \ |
| 90 | nh++, nhsel++) |
| 91 | |
| 92 | #define endfor_nexthops(rt) } |
| 93 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 94 | static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) |
| 95 | { |
| 96 | return (struct mpls_shim_hdr *)skb_network_header(skb); |
| 97 | } |
| 98 | |
| 99 | static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos) |
| 100 | { |
| 101 | struct mpls_shim_hdr result; |
| 102 | result.label_stack_entry = |
| 103 | cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | |
| 104 | (tc << MPLS_LS_TC_SHIFT) | |
| 105 | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | |
| 106 | (ttl << MPLS_LS_TTL_SHIFT)); |
| 107 | return result; |
| 108 | } |
| 109 | |
| 110 | static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr) |
| 111 | { |
| 112 | struct mpls_entry_decoded result; |
| 113 | unsigned entry = be32_to_cpu(hdr->label_stack_entry); |
| 114 | |
| 115 | result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT; |
| 116 | result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT; |
| 117 | result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT; |
| 118 | result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT; |
| 119 | |
| 120 | return result; |
| 121 | } |
| 122 | |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 123 | int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels, |
| 124 | const u32 label[]); |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 125 | int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels, |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 126 | u32 label[]); |
Roopa Prabhu | f8efb73 | 2015-10-23 06:03:27 -0700 | [diff] [blame] | 127 | int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table, |
| 128 | u8 via[]); |
Roopa Prabhu | face018 | 2015-07-21 10:43:52 +0200 | [diff] [blame] | 129 | bool mpls_output_possible(const struct net_device *dev); |
| 130 | unsigned int mpls_dev_mtu(const struct net_device *dev); |
| 131 | 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] | 132 | |
Eric W. Biederman | 0189197 | 2015-03-03 19:10:47 -0600 | [diff] [blame] | 133 | #endif /* MPLS_INTERNAL_H */ |