Thomas Gleixner | 5b497af | 2019-05-29 07:18:09 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Simon Horman | 25cd9ba | 2014-10-06 05:05:13 -0700 | [diff] [blame] | 2 | /* |
| 3 | * Copyright (c) 2014 Nicira, Inc. |
Simon Horman | 25cd9ba | 2014-10-06 05:05:13 -0700 | [diff] [blame] | 4 | */ |
| 5 | |
| 6 | #ifndef _NET_MPLS_H |
| 7 | #define _NET_MPLS_H 1 |
| 8 | |
| 9 | #include <linux/if_ether.h> |
| 10 | #include <linux/netdevice.h> |
Eli Cohen | 86ae579 | 2020-05-27 08:35:03 +0300 | [diff] [blame] | 11 | #include <linux/mpls.h> |
Simon Horman | 25cd9ba | 2014-10-06 05:05:13 -0700 | [diff] [blame] | 12 | |
| 13 | #define MPLS_HLEN 4 |
| 14 | |
Jiri Benc | 9095e10 | 2016-09-30 19:08:06 +0200 | [diff] [blame] | 15 | struct mpls_shim_hdr { |
| 16 | __be32 label_stack_entry; |
| 17 | }; |
| 18 | |
Simon Horman | 25cd9ba | 2014-10-06 05:05:13 -0700 | [diff] [blame] | 19 | static inline bool eth_p_mpls(__be16 eth_type) |
| 20 | { |
| 21 | return eth_type == htons(ETH_P_MPLS_UC) || |
| 22 | eth_type == htons(ETH_P_MPLS_MC); |
| 23 | } |
| 24 | |
Jiri Benc | 9095e10 | 2016-09-30 19:08:06 +0200 | [diff] [blame] | 25 | static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb) |
| 26 | { |
| 27 | return (struct mpls_shim_hdr *)skb_network_header(skb); |
| 28 | } |
Eli Cohen | 86ae579 | 2020-05-27 08:35:03 +0300 | [diff] [blame] | 29 | |
| 30 | static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, |
| 31 | unsigned int ttl, |
| 32 | unsigned int tc, |
| 33 | bool bos) |
| 34 | { |
| 35 | struct mpls_shim_hdr result; |
| 36 | |
| 37 | result.label_stack_entry = |
| 38 | cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) | |
| 39 | (tc << MPLS_LS_TC_SHIFT) | |
| 40 | (bos ? (1 << MPLS_LS_S_SHIFT) : 0) | |
| 41 | (ttl << MPLS_LS_TTL_SHIFT)); |
| 42 | return result; |
| 43 | } |
| 44 | |
Simon Horman | 25cd9ba | 2014-10-06 05:05:13 -0700 | [diff] [blame] | 45 | #endif |