0001
0002
0003
0004
0005
0006 #ifndef _NET_MPLS_H
0007 #define _NET_MPLS_H 1
0008
0009 #include <linux/if_ether.h>
0010 #include <linux/netdevice.h>
0011 #include <linux/mpls.h>
0012
0013 #define MPLS_HLEN 4
0014
0015 struct mpls_shim_hdr {
0016 __be32 label_stack_entry;
0017 };
0018
0019 static inline bool eth_p_mpls(__be16 eth_type)
0020 {
0021 return eth_type == htons(ETH_P_MPLS_UC) ||
0022 eth_type == htons(ETH_P_MPLS_MC);
0023 }
0024
0025 static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
0026 {
0027 return (struct mpls_shim_hdr *)skb_network_header(skb);
0028 }
0029
0030 static inline struct mpls_shim_hdr mpls_entry_encode(u32 label,
0031 unsigned int ttl,
0032 unsigned int tc,
0033 bool bos)
0034 {
0035 struct mpls_shim_hdr result;
0036
0037 result.label_stack_entry =
0038 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
0039 (tc << MPLS_LS_TC_SHIFT) |
0040 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
0041 (ttl << MPLS_LS_TTL_SHIFT));
0042 return result;
0043 }
0044
0045 #endif