]> git.proxmox.com Git - mirror_ubuntu-bionic-kernel.git/blame - net/mpls/internal.h
net: add extack arg to lwtunnel build state
[mirror_ubuntu-bionic-kernel.git] / net / mpls / internal.h
CommitLineData
0189197f
EB
1#ifndef MPLS_INTERNAL_H
2#define MPLS_INTERNAL_H
9095e10e 3#include <net/mpls.h>
0189197f 4
1511009c
DA
5/* put a reasonable limit on the number of labels
6 * we will accept from userspace
7 */
8#define MAX_NEW_LABELS 30
9
0189197f
EB
10struct mpls_entry_decoded {
11 u32 label;
12 u8 ttl;
13 u8 tc;
14 u8 bos;
15};
16
27d69105
RS
17struct mpls_pcpu_stats {
18 struct mpls_link_stats stats;
19 struct u64_stats_sync syncp;
20};
21
03c57747 22struct mpls_dev {
27d69105 23 int input_enabled;
24045a03 24 struct net_device *dev;
27d69105
RS
25 struct mpls_pcpu_stats __percpu *stats;
26
27 struct ctl_table_header *sysctl;
28 struct rcu_head rcu;
03c57747
RS
29};
30
27d69105
RS
31#if BITS_PER_LONG == 32
32
33#define MPLS_INC_STATS_LEN(mdev, len, pkts_field, bytes_field) \
34 do { \
35 __typeof__(*(mdev)->stats) *ptr = \
36 raw_cpu_ptr((mdev)->stats); \
37 local_bh_disable(); \
38 u64_stats_update_begin(&ptr->syncp); \
39 ptr->stats.pkts_field++; \
40 ptr->stats.bytes_field += (len); \
41 u64_stats_update_end(&ptr->syncp); \
42 local_bh_enable(); \
43 } while (0)
44
45#define MPLS_INC_STATS(mdev, field) \
46 do { \
47 __typeof__(*(mdev)->stats) *ptr = \
48 raw_cpu_ptr((mdev)->stats); \
49 local_bh_disable(); \
50 u64_stats_update_begin(&ptr->syncp); \
51 ptr->stats.field++; \
52 u64_stats_update_end(&ptr->syncp); \
53 local_bh_enable(); \
54 } while (0)
55
56#else
57
58#define MPLS_INC_STATS_LEN(mdev, len, pkts_field, bytes_field) \
59 do { \
60 this_cpu_inc((mdev)->stats->stats.pkts_field); \
61 this_cpu_add((mdev)->stats->stats.bytes_field, (len)); \
62 } while (0)
63
64#define MPLS_INC_STATS(mdev, field) \
65 this_cpu_inc((mdev)->stats->stats.field)
66
67#endif
68
0189197f
EB
69struct sk_buff;
70
f8efb73c 71#define LABEL_NOT_SPECIFIED (1 << 20)
f8efb73c
RP
72
73/* This maximum ha length copied from the definition of struct neighbour */
cf4b24f0
RS
74#define VIA_ALEN_ALIGN sizeof(unsigned long)
75#define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
f8efb73c
RP
76
77enum mpls_payload_type {
78 MPT_UNSPEC, /* IPv4 or IPv6 */
79 MPT_IPV4 = 4,
80 MPT_IPV6 = 6,
81
82 /* Other types not implemented:
83 * - Pseudo-wire with or without control word (RFC4385)
84 * - GAL (RFC5586)
85 */
86};
87
88struct mpls_nh { /* next hop label forwarding entry */
89 struct net_device __rcu *nh_dev;
39eb8cd1
DA
90
91 /* nh_flags is accessed under RCU in the packet path; it is
92 * modified handling netdev events with rtnl lock held
93 */
c89359a4 94 unsigned int nh_flags;
f8efb73c
RP
95 u8 nh_labels;
96 u8 nh_via_alen;
97 u8 nh_via_table;
59b20966
DA
98 u8 nh_reserved1;
99
100 u32 nh_label[0];
f8efb73c
RP
101};
102
59b20966
DA
103/* offset of via from beginning of mpls_nh */
104#define MPLS_NH_VIA_OFF(num_labels) \
105 ALIGN(sizeof(struct mpls_nh) + (num_labels) * sizeof(u32), \
106 VIA_ALEN_ALIGN)
107
108/* all nexthops within a route have the same size based on the
109 * max number of labels and max via length across all nexthops
110 */
111#define MPLS_NH_SIZE(num_labels, max_via_alen) \
112 (MPLS_NH_VIA_OFF((num_labels)) + \
113 ALIGN((max_via_alen), VIA_ALEN_ALIGN))
114
5b441ac8
RS
115enum mpls_ttl_propagation {
116 MPLS_TTL_PROP_DEFAULT,
117 MPLS_TTL_PROP_ENABLED,
118 MPLS_TTL_PROP_DISABLED,
119};
120
cf4b24f0
RS
121/* The route, nexthops and vias are stored together in the same memory
122 * block:
123 *
124 * +----------------------+
125 * | mpls_route |
126 * +----------------------+
127 * | mpls_nh 0 |
128 * +----------------------+
59b20966 129 * | alignment padding | 4 bytes for odd number of labels
cf4b24f0
RS
130 * +----------------------+
131 * | via[rt_max_alen] 0 |
132 * +----------------------+
59b20966
DA
133 * | alignment padding | via's aligned on sizeof(unsigned long)
134 * +----------------------+
cf4b24f0
RS
135 * | ... |
136 * +----------------------+
59b20966
DA
137 * | mpls_nh n-1 |
138 * +----------------------+
cf4b24f0
RS
139 * | via[rt_max_alen] n-1 |
140 * +----------------------+
141 */
f8efb73c
RP
142struct mpls_route { /* next hop label forwarding entry */
143 struct rcu_head rt_rcu;
144 u8 rt_protocol;
145 u8 rt_payload_type;
cf4b24f0 146 u8 rt_max_alen;
5b441ac8 147 u8 rt_ttl_propagate;
77ef013a 148 u8 rt_nhn;
39eb8cd1
DA
149 /* rt_nhn_alive is accessed under RCU in the packet path; it
150 * is modified handling netdev events with rtnl lock held
151 */
77ef013a 152 u8 rt_nhn_alive;
59b20966
DA
153 u8 rt_nh_size;
154 u8 rt_via_offset;
155 u8 rt_reserved1;
f8efb73c
RP
156 struct mpls_nh rt_nh[0];
157};
158
159#define for_nexthops(rt) { \
59b20966
DA
160 int nhsel; struct mpls_nh *nh; u8 *__nh; \
161 for (nhsel = 0, nh = (rt)->rt_nh, __nh = (u8 *)((rt)->rt_nh); \
f8efb73c 162 nhsel < (rt)->rt_nhn; \
59b20966 163 __nh += rt->rt_nh_size, nh = (struct mpls_nh *)__nh, nhsel++)
f8efb73c
RP
164
165#define change_nexthops(rt) { \
59b20966
DA
166 int nhsel; struct mpls_nh *nh; u8 *__nh; \
167 for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh), \
168 __nh = (u8 *)((rt)->rt_nh); \
f8efb73c 169 nhsel < (rt)->rt_nhn; \
59b20966 170 __nh += rt->rt_nh_size, nh = (struct mpls_nh *)__nh, nhsel++)
f8efb73c
RP
171
172#define endfor_nexthops(rt) }
173
0189197f
EB
174static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
175{
176 struct mpls_shim_hdr result;
177 result.label_stack_entry =
178 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
179 (tc << MPLS_LS_TC_SHIFT) |
180 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
181 (ttl << MPLS_LS_TTL_SHIFT));
182 return result;
183}
184
185static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
186{
187 struct mpls_entry_decoded result;
188 unsigned entry = be32_to_cpu(hdr->label_stack_entry);
189
190 result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
191 result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
192 result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
193 result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
194
195 return result;
196}
197
27d69105
RS
198static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
199{
200 return rcu_dereference_rtnl(dev->mpls_ptr);
201}
202
face0188
RP
203int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
204 const u32 label[]);
a4ac8c98 205int nla_get_labels(const struct nlattr *nla, u8 max_labels, u8 *labels,
face0188 206 u32 label[]);
f8efb73c
RP
207int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
208 u8 via[]);
face0188
RP
209bool mpls_output_possible(const struct net_device *dev);
210unsigned int mpls_dev_mtu(const struct net_device *dev);
211bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
27d69105
RS
212void mpls_stats_inc_outucastpkts(struct net_device *dev,
213 const struct sk_buff *skb);
966bae33 214
0189197f 215#endif /* MPLS_INTERNAL_H */