blob: bdfef6c3271a5a0e39fbbd03b9464a9fe1bdb3f0 [file] [log] [blame]
Eric W. Biederman01891972015-03-03 19:10:47 -06001#ifndef MPLS_INTERNAL_H
2#define MPLS_INTERNAL_H
Jiri Benc9095e102016-09-30 19:08:06 +02003#include <net/mpls.h>
Eric W. Biederman01891972015-03-03 19:10:47 -06004
5struct mpls_entry_decoded {
6 u32 label;
7 u8 ttl;
8 u8 tc;
9 u8 bos;
10};
11
Robert Shearman03c57742015-04-22 11:14:37 +010012struct mpls_dev {
Robert Shearman37bde792015-04-22 11:14:38 +010013 int input_enabled;
14
15 struct ctl_table_header *sysctl;
Robert Shearman25cc8f02015-06-05 18:54:45 +010016 struct rcu_head rcu;
Robert Shearman03c57742015-04-22 11:14:37 +010017};
18
Eric W. Biederman01891972015-03-03 19:10:47 -060019struct sk_buff;
20
Roopa Prabhuf8efb732015-10-23 06:03:27 -070021#define LABEL_NOT_SPECIFIED (1 << 20)
22#define MAX_NEW_LABELS 2
23
24/* This maximum ha length copied from the definition of struct neighbour */
Robert Shearmancf4b24f2015-10-27 00:37:36 +000025#define VIA_ALEN_ALIGN sizeof(unsigned long)
26#define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
Roopa Prabhuf8efb732015-10-23 06:03:27 -070027
28enum mpls_payload_type {
29 MPT_UNSPEC, /* IPv4 or IPv6 */
30 MPT_IPV4 = 4,
31 MPT_IPV6 = 6,
32
33 /* Other types not implemented:
34 * - Pseudo-wire with or without control word (RFC4385)
35 * - GAL (RFC5586)
36 */
37};
38
39struct mpls_nh { /* next hop label forwarding entry */
40 struct net_device __rcu *nh_dev;
Roopa Prabhuc89359a2015-12-01 22:18:11 -080041 unsigned int nh_flags;
Roopa Prabhuf8efb732015-10-23 06:03:27 -070042 u32 nh_label[MAX_NEW_LABELS];
43 u8 nh_labels;
44 u8 nh_via_alen;
45 u8 nh_via_table;
Roopa Prabhuf8efb732015-10-23 06:03:27 -070046};
47
Robert Shearmancf4b24f2015-10-27 00:37:36 +000048/* The route, nexthops and vias are stored together in the same memory
49 * block:
50 *
51 * +----------------------+
52 * | mpls_route |
53 * +----------------------+
54 * | mpls_nh 0 |
55 * +----------------------+
56 * | ... |
57 * +----------------------+
58 * | mpls_nh n-1 |
59 * +----------------------+
60 * | alignment padding |
61 * +----------------------+
62 * | via[rt_max_alen] 0 |
63 * +----------------------+
64 * | ... |
65 * +----------------------+
66 * | via[rt_max_alen] n-1 |
67 * +----------------------+
68 */
Roopa Prabhuf8efb732015-10-23 06:03:27 -070069struct mpls_route { /* next hop label forwarding entry */
70 struct rcu_head rt_rcu;
71 u8 rt_protocol;
72 u8 rt_payload_type;
Robert Shearmancf4b24f2015-10-27 00:37:36 +000073 u8 rt_max_alen;
74 unsigned int rt_nhn;
Roopa Prabhuc89359a2015-12-01 22:18:11 -080075 unsigned int rt_nhn_alive;
Roopa Prabhuf8efb732015-10-23 06:03:27 -070076 struct mpls_nh rt_nh[0];
77};
78
79#define for_nexthops(rt) { \
80 int nhsel; struct mpls_nh *nh; \
81 for (nhsel = 0, nh = (rt)->rt_nh; \
82 nhsel < (rt)->rt_nhn; \
83 nh++, nhsel++)
84
85#define change_nexthops(rt) { \
86 int nhsel; struct mpls_nh *nh; \
87 for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \
88 nhsel < (rt)->rt_nhn; \
89 nh++, nhsel++)
90
91#define endfor_nexthops(rt) }
92
Eric W. Biederman01891972015-03-03 19:10:47 -060093static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
94{
95 struct mpls_shim_hdr result;
96 result.label_stack_entry =
97 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
98 (tc << MPLS_LS_TC_SHIFT) |
99 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
100 (ttl << MPLS_LS_TTL_SHIFT));
101 return result;
102}
103
104static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
105{
106 struct mpls_entry_decoded result;
107 unsigned entry = be32_to_cpu(hdr->label_stack_entry);
108
109 result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
110 result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
111 result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
112 result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
113
114 return result;
115}
116
Roopa Prabhuface0182015-07-21 10:43:52 +0200117int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
118 const u32 label[]);
Roopa Prabhuf8efb732015-10-23 06:03:27 -0700119int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels,
Roopa Prabhuface0182015-07-21 10:43:52 +0200120 u32 label[]);
Roopa Prabhuf8efb732015-10-23 06:03:27 -0700121int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
122 u8 via[]);
Roopa Prabhuface0182015-07-21 10:43:52 +0200123bool mpls_output_possible(const struct net_device *dev);
124unsigned int mpls_dev_mtu(const struct net_device *dev);
125bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
Eric W. Biederman966bae32015-03-03 19:13:19 -0600126
Eric W. Biederman01891972015-03-03 19:10:47 -0600127#endif /* MPLS_INTERNAL_H */