internal.h 1.4 KB

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