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> 1186ae579cSEli 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 Hormanstatic 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 Bencstatic 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 } 2986ae579cSEli Cohen mpls_entry_encode(u32 label,unsigned int ttl,unsigned int tc,bool bos)3086ae579cSEli Cohenstatic inline struct mpls_shim_hdr mpls_entry_encode(u32 label, 3186ae579cSEli Cohen unsigned int ttl, 3286ae579cSEli Cohen unsigned int tc, 3386ae579cSEli Cohen bool bos) 3486ae579cSEli Cohen { 3586ae579cSEli Cohen struct mpls_shim_hdr result; 3686ae579cSEli Cohen 3786ae579cSEli Cohen result.label_stack_entry = 3886ae579cSEli Cohen cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | 3986ae579cSEli Cohen (tc << MPLS_LS_TC_SHIFT) | 4086ae579cSEli Cohen (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | 4186ae579cSEli Cohen (ttl << MPLS_LS_TTL_SHIFT)); 4286ae579cSEli Cohen return result; 4386ae579cSEli Cohen } 4486ae579cSEli Cohen 4525cd9ba0SSimon Horman #endif 46