xref: /linux/include/net/mpls.h (revision 4b4193256c8d3bc3a5397b5cd9494c2ad386317d)
15b497af4SThomas Gleixner /* SPDX-License-Identifier: GPL-2.0-only */
225cd9ba0SSimon Horman /*
325cd9ba0SSimon Horman  * Copyright (c) 2014 Nicira, Inc.
425cd9ba0SSimon Horman  */
525cd9ba0SSimon Horman 
625cd9ba0SSimon Horman #ifndef _NET_MPLS_H
725cd9ba0SSimon Horman #define _NET_MPLS_H 1
825cd9ba0SSimon Horman 
925cd9ba0SSimon Horman #include <linux/if_ether.h>
1025cd9ba0SSimon Horman #include <linux/netdevice.h>
11*86ae579cSEli Cohen #include <linux/mpls.h>
1225cd9ba0SSimon Horman 
1325cd9ba0SSimon Horman #define MPLS_HLEN 4
1425cd9ba0SSimon Horman 
159095e10eSJiri Benc struct mpls_shim_hdr {
169095e10eSJiri Benc 	__be32 label_stack_entry;
179095e10eSJiri Benc };
189095e10eSJiri Benc 
eth_p_mpls(__be16 eth_type)1925cd9ba0SSimon Horman static inline bool eth_p_mpls(__be16 eth_type)
2025cd9ba0SSimon Horman {
2125cd9ba0SSimon Horman 	return eth_type == htons(ETH_P_MPLS_UC) ||
2225cd9ba0SSimon Horman 		eth_type == htons(ETH_P_MPLS_MC);
2325cd9ba0SSimon Horman }
2425cd9ba0SSimon Horman 
mpls_hdr(const struct sk_buff * skb)259095e10eSJiri Benc static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
269095e10eSJiri Benc {
279095e10eSJiri Benc 	return (struct mpls_shim_hdr *)skb_network_header(skb);
289095e10eSJiri Benc }
29*86ae579cSEli Cohen 
mpls_entry_encode(u32 label,unsigned int ttl,unsigned int tc,bool bos)30*86ae579cSEli Cohen static inline struct mpls_shim_hdr mpls_entry_encode(u32 label,
31*86ae579cSEli Cohen 						     unsigned int ttl,
32*86ae579cSEli Cohen 						     unsigned int tc,
33*86ae579cSEli Cohen 						     bool bos)
34*86ae579cSEli Cohen {
35*86ae579cSEli Cohen 	struct mpls_shim_hdr result;
36*86ae579cSEli Cohen 
37*86ae579cSEli Cohen 	result.label_stack_entry =
38*86ae579cSEli Cohen 		cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
39*86ae579cSEli Cohen 			    (tc << MPLS_LS_TC_SHIFT) |
40*86ae579cSEli Cohen 			    (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
41*86ae579cSEli Cohen 			    (ttl << MPLS_LS_TTL_SHIFT));
42*86ae579cSEli Cohen 	return result;
43*86ae579cSEli Cohen }
44*86ae579cSEli Cohen 
4525cd9ba0SSimon Horman #endif
46