internal.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #ifndef MPLS_INTERNAL_H
  2. #define MPLS_INTERNAL_H
  3. #define LABEL_IPV4_EXPLICIT_NULL 0 /* RFC3032 */
  4. #define LABEL_ROUTER_ALERT_LABEL 1 /* RFC3032 */
  5. #define LABEL_IPV6_EXPLICIT_NULL 2 /* RFC3032 */
  6. #define LABEL_IMPLICIT_NULL 3 /* RFC3032 */
  7. #define LABEL_ENTROPY_INDICATOR 7 /* RFC6790 */
  8. #define LABEL_GAL 13 /* RFC5586 */
  9. #define LABEL_OAM_ALERT 14 /* RFC3429 */
  10. #define LABEL_EXTENSION 15 /* RFC7274 */
  11. struct mpls_shim_hdr {
  12. __be32 label_stack_entry;
  13. };
  14. struct mpls_entry_decoded {
  15. u32 label;
  16. u8 ttl;
  17. u8 tc;
  18. u8 bos;
  19. };
  20. struct sk_buff;
  21. static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
  22. {
  23. return (struct mpls_shim_hdr *)skb_network_header(skb);
  24. }
  25. static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
  26. {
  27. struct mpls_shim_hdr result;
  28. result.label_stack_entry =
  29. cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
  30. (tc << MPLS_LS_TC_SHIFT) |
  31. (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
  32. (ttl << MPLS_LS_TTL_SHIFT));
  33. return result;
  34. }
  35. static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
  36. {
  37. struct mpls_entry_decoded result;
  38. unsigned entry = be32_to_cpu(hdr->label_stack_entry);
  39. result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
  40. result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
  41. result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
  42. result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
  43. return result;
  44. }
  45. int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels, const u32 label[]);
  46. int nla_get_labels(const struct nlattr *nla, u32 max_labels, u32 *labels, u32 label[]);
  47. #endif /* MPLS_INTERNAL_H */