internal.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. #ifndef MPLS_INTERNAL_H
  2. #define MPLS_INTERNAL_H
  3. #include <net/mpls.h>
  4. struct mpls_entry_decoded {
  5. u32 label;
  6. u8 ttl;
  7. u8 tc;
  8. u8 bos;
  9. };
  10. struct mpls_dev {
  11. int input_enabled;
  12. struct ctl_table_header *sysctl;
  13. struct rcu_head rcu;
  14. };
  15. struct sk_buff;
  16. #define LABEL_NOT_SPECIFIED (1 << 20)
  17. #define MAX_NEW_LABELS 2
  18. /* This maximum ha length copied from the definition of struct neighbour */
  19. #define VIA_ALEN_ALIGN sizeof(unsigned long)
  20. #define MAX_VIA_ALEN (ALIGN(MAX_ADDR_LEN, VIA_ALEN_ALIGN))
  21. enum mpls_payload_type {
  22. MPT_UNSPEC, /* IPv4 or IPv6 */
  23. MPT_IPV4 = 4,
  24. MPT_IPV6 = 6,
  25. /* Other types not implemented:
  26. * - Pseudo-wire with or without control word (RFC4385)
  27. * - GAL (RFC5586)
  28. */
  29. };
  30. struct mpls_nh { /* next hop label forwarding entry */
  31. struct net_device __rcu *nh_dev;
  32. unsigned int nh_flags;
  33. u32 nh_label[MAX_NEW_LABELS];
  34. u8 nh_labels;
  35. u8 nh_via_alen;
  36. u8 nh_via_table;
  37. };
  38. /* The route, nexthops and vias are stored together in the same memory
  39. * block:
  40. *
  41. * +----------------------+
  42. * | mpls_route |
  43. * +----------------------+
  44. * | mpls_nh 0 |
  45. * +----------------------+
  46. * | ... |
  47. * +----------------------+
  48. * | mpls_nh n-1 |
  49. * +----------------------+
  50. * | alignment padding |
  51. * +----------------------+
  52. * | via[rt_max_alen] 0 |
  53. * +----------------------+
  54. * | ... |
  55. * +----------------------+
  56. * | via[rt_max_alen] n-1 |
  57. * +----------------------+
  58. */
  59. struct mpls_route { /* next hop label forwarding entry */
  60. struct rcu_head rt_rcu;
  61. u8 rt_protocol;
  62. u8 rt_payload_type;
  63. u8 rt_max_alen;
  64. unsigned int rt_nhn;
  65. unsigned int rt_nhn_alive;
  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_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
  80. {
  81. struct mpls_shim_hdr result;
  82. result.label_stack_entry =
  83. cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
  84. (tc << MPLS_LS_TC_SHIFT) |
  85. (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
  86. (ttl << MPLS_LS_TTL_SHIFT));
  87. return result;
  88. }
  89. static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
  90. {
  91. struct mpls_entry_decoded result;
  92. unsigned entry = be32_to_cpu(hdr->label_stack_entry);
  93. result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
  94. result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
  95. result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
  96. result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
  97. return result;
  98. }
  99. int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
  100. const u32 label[]);
  101. int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels,
  102. u32 label[]);
  103. int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
  104. u8 via[]);
  105. bool mpls_output_possible(const struct net_device *dev);
  106. unsigned int mpls_dev_mtu(const struct net_device *dev);
  107. bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
  108. #endif /* MPLS_INTERNAL_H */