1/* 2 * Copyright (c) 2014 Nicira, Inc. 3 * 4 * This program is free software; you can redistribute it and/or 5 * modify it under the terms of version 2 of the GNU General Public 6 * License as published by the Free Software Foundation. 7 * 8 * This program is distributed in the hope that it will be useful, but 9 * WITHOUT ANY WARRANTY; without even the implied warranty of 10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 11 * General Public License for more details. 12 */ 13 14#ifndef _NET_MPLS_H 15#define _NET_MPLS_H 1 16 17#include <linux/if_ether.h> 18#include <linux/netdevice.h> 19#include <linux/mpls.h> 20 21#define MPLS_HLEN 4 22 23struct mpls_shim_hdr { 24 __be32 label_stack_entry; 25}; 26 27static inline bool eth_p_mpls(__be16 eth_type) 28{ 29 return eth_type == htons(ETH_P_MPLS_UC) || 30 eth_type == htons(ETH_P_MPLS_MC); 31} 32 33static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) 34{ 35 return (struct mpls_shim_hdr *)skb_network_header(skb); 36} 37 38static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, 39 unsigned int ttl, 40 unsigned int tc, 41 bool bos) 42{ 43 struct mpls_shim_hdr result; 44 45 result.label_stack_entry = 46 cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | 47 (tc << MPLS_LS_TC_SHIFT) | 48 (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | 49 (ttl << MPLS_LS_TTL_SHIFT)); 50 return result; 51} 52 53#endif 54