18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0-only */ 28c2ecf20Sopenharmony_ci/* 38c2ecf20Sopenharmony_ci * Copyright (c) 2014 Nicira, Inc. 48c2ecf20Sopenharmony_ci */ 58c2ecf20Sopenharmony_ci 68c2ecf20Sopenharmony_ci#ifndef _NET_MPLS_H 78c2ecf20Sopenharmony_ci#define _NET_MPLS_H 1 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#include <linux/if_ether.h> 108c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 118c2ecf20Sopenharmony_ci#include <linux/mpls.h> 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ci#define MPLS_HLEN 4 148c2ecf20Sopenharmony_ci 158c2ecf20Sopenharmony_cistruct mpls_shim_hdr { 168c2ecf20Sopenharmony_ci __be32 label_stack_entry; 178c2ecf20Sopenharmony_ci}; 188c2ecf20Sopenharmony_ci 198c2ecf20Sopenharmony_cistatic inline bool eth_p_mpls(__be16 eth_type) 208c2ecf20Sopenharmony_ci{ 218c2ecf20Sopenharmony_ci return eth_type == htons(ETH_P_MPLS_UC) || 228c2ecf20Sopenharmony_ci eth_type == htons(ETH_P_MPLS_MC); 238c2ecf20Sopenharmony_ci} 248c2ecf20Sopenharmony_ci 258c2ecf20Sopenharmony_cistatic inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) 268c2ecf20Sopenharmony_ci{ 278c2ecf20Sopenharmony_ci return (struct mpls_shim_hdr *)skb_network_header(skb); 288c2ecf20Sopenharmony_ci} 298c2ecf20Sopenharmony_ci 308c2ecf20Sopenharmony_cistatic inline struct mpls_shim_hdr mpls_entry_encode(u32 label, 318c2ecf20Sopenharmony_ci unsigned int ttl, 328c2ecf20Sopenharmony_ci unsigned int tc, 338c2ecf20Sopenharmony_ci bool bos) 348c2ecf20Sopenharmony_ci{ 358c2ecf20Sopenharmony_ci struct mpls_shim_hdr result; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci result.label_stack_entry = 388c2ecf20Sopenharmony_ci cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | 398c2ecf20Sopenharmony_ci (tc << MPLS_LS_TC_SHIFT) | 408c2ecf20Sopenharmony_ci (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | 418c2ecf20Sopenharmony_ci (ttl << MPLS_LS_TTL_SHIFT)); 428c2ecf20Sopenharmony_ci return result; 438c2ecf20Sopenharmony_ci} 448c2ecf20Sopenharmony_ci 458c2ecf20Sopenharmony_ci#endif 46