^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 1) /* SPDX-License-Identifier: GPL-2.0-only */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 2) /*
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 3) * Copyright (c) 2014 Nicira, Inc.
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 4) */
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 5)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 6) #ifndef _NET_MPLS_H
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 7) #define _NET_MPLS_H 1
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 8)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 9) #include <linux/if_ether.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 10) #include <linux/netdevice.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 11) #include <linux/mpls.h>
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 12)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 13) #define MPLS_HLEN 4
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 14)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 15) struct mpls_shim_hdr {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 16) __be32 label_stack_entry;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 17) };
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 18)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 19) static inline bool eth_p_mpls(__be16 eth_type)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 20) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 21) return eth_type == htons(ETH_P_MPLS_UC) ||
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 22) eth_type == htons(ETH_P_MPLS_MC);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 23) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 24)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 25) static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 26) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 27) return (struct mpls_shim_hdr *)skb_network_header(skb);
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 28) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 29)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 30) static inline struct mpls_shim_hdr mpls_entry_encode(u32 label,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 31) unsigned int ttl,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 32) unsigned int tc,
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 33) bool bos)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 34) {
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 35) struct mpls_shim_hdr result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 36)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 37) result.label_stack_entry =
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 38) cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 39) (tc << MPLS_LS_TC_SHIFT) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 40) (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 41) (ttl << MPLS_LS_TTL_SHIFT));
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 42) return result;
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 43) }
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 44)
^8f3ce5b39 (kx 2023-10-28 12:00:06 +0300 45) #endif