mpls.h 943 B

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