internal.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  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. #define LABEL_NOT_SPECIFIED (1 << 20)
  19. #define MAX_NEW_LABELS 2
  20. /* This maximum ha length copied from the definition of struct neighbour */
  21. #define VIA_ALEN_ALIGN sizeof(unsigned long)
  22. #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
  23. enum mpls_payload_type {
  24. MPT_UNSPEC, /* IPv4 or IPv6 */
  25. MPT_IPV4 = 4,
  26. MPT_IPV6 = 6,
  27. /* Other types not implemented:
  28. * - Pseudo-wire with or without control word (RFC4385)
  29. * - GAL (RFC5586)
  30. */
  31. };
  32. struct mpls_nh { /* next hop label forwarding entry */
  33. struct net_device __rcu *nh_dev;
  34. u32 nh_label[MAX_NEW_LABELS];
  35. u8 nh_labels;
  36. u8 nh_via_alen;
  37. u8 nh_via_table;
  38. };
  39. /* The route, nexthops and vias are stored together in the same memory
  40. * block:
  41. *
  42. * +----------------------+
  43. * | mpls_route |
  44. * +----------------------+
  45. * | mpls_nh 0 |
  46. * +----------------------+
  47. * | ... |
  48. * +----------------------+
  49. * | mpls_nh n-1 |
  50. * +----------------------+
  51. * | alignment padding |
  52. * +----------------------+
  53. * | via[rt_max_alen] 0 |
  54. * +----------------------+
  55. * | ... |
  56. * +----------------------+
  57. * | via[rt_max_alen] n-1 |
  58. * +----------------------+
  59. */
  60. struct mpls_route { /* next hop label forwarding entry */
  61. struct rcu_head rt_rcu;
  62. u8 rt_protocol;
  63. u8 rt_payload_type;
  64. u8 rt_max_alen;
  65. unsigned int rt_nhn;
  66. struct mpls_nh rt_nh[0];
  67. };
  68. #define for_nexthops(rt) { \
  69. int nhsel; struct mpls_nh *nh; \
  70. for (nhsel = 0, nh = (rt)->rt_nh; \
  71. nhsel < (rt)->rt_nhn; \
  72. nh++, nhsel++)
  73. #define change_nexthops(rt) { \
  74. int nhsel; struct mpls_nh *nh; \
  75. for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \
  76. nhsel < (rt)->rt_nhn; \
  77. nh++, nhsel++)
  78. #define endfor_nexthops(rt) }
  79. static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
  80. {
  81. return (struct mpls_shim_hdr *)skb_network_header(skb);
  82. }
  83. static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
  84. {
  85. struct mpls_shim_hdr result;
  86. result.label_stack_entry =
  87. cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
  88. (tc << MPLS_LS_TC_SHIFT) |
  89. (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
  90. (ttl << MPLS_LS_TTL_SHIFT));
  91. return result;
  92. }
  93. static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
  94. {
  95. struct mpls_entry_decoded result;
  96. unsigned entry = be32_to_cpu(hdr->label_stack_entry);
  97. result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
  98. result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
  99. result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
  100. result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
  101. return result;
  102. }
  103. int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
  104. const u32 label[]);
  105. int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels,
  106. u32 label[]);
  107. int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
  108. u8 via[]);
  109. bool mpls_output_possible(const struct net_device *dev);
  110. unsigned int mpls_dev_mtu(const struct net_device *dev);
  111. bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
  112. #endif /* MPLS_INTERNAL_H */