1 #ifndef MPLS_INTERNAL_H
2 #define MPLS_INTERNAL_H
5 struct mpls_entry_decoded {
12 struct mpls_pcpu_stats {
13 struct mpls_link_stats stats;
14 struct u64_stats_sync syncp;
19 struct net_device *dev;
20 struct mpls_pcpu_stats __percpu *stats;
22 struct ctl_table_header *sysctl;
26 #if BITS_PER_LONG == 32
28 #define MPLS_INC_STATS_LEN(mdev, len, pkts_field, bytes_field) \
30 __typeof__(*(mdev)->stats) *ptr = \
31 raw_cpu_ptr((mdev)->stats); \
33 u64_stats_update_begin(&ptr->syncp); \
34 ptr->stats.pkts_field++; \
35 ptr->stats.bytes_field += (len); \
36 u64_stats_update_end(&ptr->syncp); \
40 #define MPLS_INC_STATS(mdev, field) \
42 __typeof__(*(mdev)->stats) *ptr = \
43 raw_cpu_ptr((mdev)->stats); \
45 u64_stats_update_begin(&ptr->syncp); \
47 u64_stats_update_end(&ptr->syncp); \
53 #define MPLS_INC_STATS_LEN(mdev, len, pkts_field, bytes_field) \
55 this_cpu_inc((mdev)->stats->stats.pkts_field); \
56 this_cpu_add((mdev)->stats->stats.bytes_field, (len)); \
59 #define MPLS_INC_STATS(mdev, field) \
60 this_cpu_inc((mdev)->stats->stats.field)
66 #define LABEL_NOT_SPECIFIED (1 << 20)
67 #define MAX_NEW_LABELS 2
69 /* This maximum ha length copied from the definition of struct neighbour */
70 #define VIA_ALEN_ALIGN sizeof(unsigned long)
71 #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
73 enum mpls_payload_type {
74 MPT_UNSPEC, /* IPv4 or IPv6 */
78 /* Other types not implemented:
79 * - Pseudo-wire with or without control word (RFC4385)
84 struct mpls_nh { /* next hop label forwarding entry */
85 struct net_device __rcu *nh_dev;
86 unsigned int nh_flags;
87 u32 nh_label[MAX_NEW_LABELS];
93 enum mpls_ttl_propagation {
94 MPLS_TTL_PROP_DEFAULT,
95 MPLS_TTL_PROP_ENABLED,
96 MPLS_TTL_PROP_DISABLED,
99 /* The route, nexthops and vias are stored together in the same memory
102 * +----------------------+
104 * +----------------------+
106 * +----------------------+
108 * +----------------------+
110 * +----------------------+
111 * | alignment padding |
112 * +----------------------+
113 * | via[rt_max_alen] 0 |
114 * +----------------------+
116 * +----------------------+
117 * | via[rt_max_alen] n-1 |
118 * +----------------------+
120 struct mpls_route { /* next hop label forwarding entry */
121 struct rcu_head rt_rcu;
127 unsigned int rt_nhn_alive;
128 struct mpls_nh rt_nh[0];
131 #define for_nexthops(rt) { \
132 int nhsel; struct mpls_nh *nh; \
133 for (nhsel = 0, nh = (rt)->rt_nh; \
134 nhsel < (rt)->rt_nhn; \
137 #define change_nexthops(rt) { \
138 int nhsel; struct mpls_nh *nh; \
139 for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \
140 nhsel < (rt)->rt_nhn; \
143 #define endfor_nexthops(rt) }
145 static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
147 struct mpls_shim_hdr result;
148 result.label_stack_entry =
149 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
150 (tc << MPLS_LS_TC_SHIFT) |
151 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
152 (ttl << MPLS_LS_TTL_SHIFT));
156 static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
158 struct mpls_entry_decoded result;
159 unsigned entry = be32_to_cpu(hdr->label_stack_entry);
161 result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
162 result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
163 result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
164 result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
169 static inline struct mpls_dev *mpls_dev_get(const struct net_device *dev)
171 return rcu_dereference_rtnl(dev->mpls_ptr);
174 int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
176 int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels,
178 int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
180 bool mpls_output_possible(const struct net_device *dev);
181 unsigned int mpls_dev_mtu(const struct net_device *dev);
182 bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
183 void mpls_stats_inc_outucastpkts(struct net_device *dev,
184 const struct sk_buff *skb);
186 #endif /* MPLS_INTERNAL_H */