1 #ifndef MPLS_INTERNAL_H
2 #define MPLS_INTERNAL_H
5 __be32 label_stack_entry
;
8 struct mpls_entry_decoded
{
18 struct ctl_table_header
*sysctl
;
24 #define LABEL_NOT_SPECIFIED (1 << 20)
25 #define MAX_NEW_LABELS 2
27 /* This maximum ha length copied from the definition of struct neighbour */
28 #define VIA_ALEN_ALIGN sizeof(unsigned long)
29 #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
31 enum mpls_payload_type
{
32 MPT_UNSPEC
, /* IPv4 or IPv6 */
36 /* Other types not implemented:
37 * - Pseudo-wire with or without control word (RFC4385)
42 struct mpls_nh
{ /* next hop label forwarding entry */
43 struct net_device __rcu
*nh_dev
;
44 unsigned int nh_flags
;
45 u32 nh_label
[MAX_NEW_LABELS
];
51 /* The route, nexthops and vias are stored together in the same memory
54 * +----------------------+
56 * +----------------------+
58 * +----------------------+
60 * +----------------------+
62 * +----------------------+
63 * | alignment padding |
64 * +----------------------+
65 * | via[rt_max_alen] 0 |
66 * +----------------------+
68 * +----------------------+
69 * | via[rt_max_alen] n-1 |
70 * +----------------------+
72 struct mpls_route
{ /* next hop label forwarding entry */
73 struct rcu_head rt_rcu
;
78 unsigned int rt_nhn_alive
;
79 struct mpls_nh rt_nh
[0];
82 #define for_nexthops(rt) { \
83 int nhsel; struct mpls_nh *nh; \
84 for (nhsel = 0, nh = (rt)->rt_nh; \
85 nhsel < (rt)->rt_nhn; \
88 #define change_nexthops(rt) { \
89 int nhsel; struct mpls_nh *nh; \
90 for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \
91 nhsel < (rt)->rt_nhn; \
94 #define endfor_nexthops(rt) }
96 static inline struct mpls_shim_hdr
*mpls_hdr(const struct sk_buff
*skb
)
98 return (struct mpls_shim_hdr
*)skb_network_header(skb
);
101 static inline struct mpls_shim_hdr
mpls_entry_encode(u32 label
, unsigned ttl
, unsigned tc
, bool bos
)
103 struct mpls_shim_hdr result
;
104 result
.label_stack_entry
=
105 cpu_to_be32((label
<< MPLS_LS_LABEL_SHIFT
) |
106 (tc
<< MPLS_LS_TC_SHIFT
) |
107 (bos
? (1 << MPLS_LS_S_SHIFT
) : 0) |
108 (ttl
<< MPLS_LS_TTL_SHIFT
));
112 static inline struct mpls_entry_decoded
mpls_entry_decode(struct mpls_shim_hdr
*hdr
)
114 struct mpls_entry_decoded result
;
115 unsigned entry
= be32_to_cpu(hdr
->label_stack_entry
);
117 result
.label
= (entry
& MPLS_LS_LABEL_MASK
) >> MPLS_LS_LABEL_SHIFT
;
118 result
.ttl
= (entry
& MPLS_LS_TTL_MASK
) >> MPLS_LS_TTL_SHIFT
;
119 result
.tc
= (entry
& MPLS_LS_TC_MASK
) >> MPLS_LS_TC_SHIFT
;
120 result
.bos
= (entry
& MPLS_LS_S_MASK
) >> MPLS_LS_S_SHIFT
;
125 int nla_put_labels(struct sk_buff
*skb
, int attrtype
, u8 labels
,
127 int nla_get_labels(const struct nlattr
*nla
, u32 max_labels
, u8
*labels
,
129 int nla_get_via(const struct nlattr
*nla
, u8
*via_alen
, u8
*via_table
,
131 bool mpls_output_possible(const struct net_device
*dev
);
132 unsigned int mpls_dev_mtu(const struct net_device
*dev
);
133 bool mpls_pkt_too_big(const struct sk_buff
*skb
, unsigned int mtu
);
135 #endif /* MPLS_INTERNAL_H */