internal.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135
  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. unsigned int nh_flags;
  35. u32 nh_label[MAX_NEW_LABELS];
  36. u8 nh_labels;
  37. u8 nh_via_alen;
  38. u8 nh_via_table;
  39. };
  40. /* The route, nexthops and vias are stored together in the same memory
  41. * block:
  42. *
  43. * +----------------------+
  44. * | mpls_route |
  45. * +----------------------+
  46. * | mpls_nh 0 |
  47. * +----------------------+
  48. * | ... |
  49. * +----------------------+
  50. * | mpls_nh n-1 |
  51. * +----------------------+
  52. * | alignment padding |
  53. * +----------------------+
  54. * | via[rt_max_alen] 0 |
  55. * +----------------------+
  56. * | ... |
  57. * +----------------------+
  58. * | via[rt_max_alen] n-1 |
  59. * +----------------------+
  60. */
  61. struct mpls_route { /* next hop label forwarding entry */
  62. struct rcu_head rt_rcu;
  63. u8 rt_protocol;
  64. u8 rt_payload_type;
  65. u8 rt_max_alen;
  66. unsigned int rt_nhn;
  67. unsigned int rt_nhn_alive;
  68. struct mpls_nh rt_nh[0];
  69. };
  70. #define for_nexthops(rt) { \
  71. int nhsel; struct mpls_nh *nh; \
  72. for (nhsel = 0, nh = (rt)->rt_nh; \
  73. nhsel < (rt)->rt_nhn; \
  74. nh++, nhsel++)
  75. #define change_nexthops(rt) { \
  76. int nhsel; struct mpls_nh *nh; \
  77. for (nhsel = 0, nh = (struct mpls_nh *)((rt)->rt_nh); \
  78. nhsel < (rt)->rt_nhn; \
  79. nh++, nhsel++)
  80. #define endfor_nexthops(rt) }
  81. static inline struct mpls_shim_hdr *mpls_hdr(const struct sk_buff *skb)
  82. {
  83. return (struct mpls_shim_hdr *)skb_network_header(skb);
  84. }
  85. static inline struct mpls_shim_hdr mpls_entry_encode(u32 label, unsigned ttl, unsigned tc, bool bos)
  86. {
  87. struct mpls_shim_hdr result;
  88. result.label_stack_entry =
  89. cpu_to_be32((label << MPLS_LS_LABEL_SHIFT) |
  90. (tc << MPLS_LS_TC_SHIFT) |
  91. (bos ? (1 << MPLS_LS_S_SHIFT) : 0) |
  92. (ttl << MPLS_LS_TTL_SHIFT));
  93. return result;
  94. }
  95. static inline struct mpls_entry_decoded mpls_entry_decode(struct mpls_shim_hdr *hdr)
  96. {
  97. struct mpls_entry_decoded result;
  98. unsigned entry = be32_to_cpu(hdr->label_stack_entry);
  99. result.label = (entry & MPLS_LS_LABEL_MASK) >> MPLS_LS_LABEL_SHIFT;
  100. result.ttl = (entry & MPLS_LS_TTL_MASK) >> MPLS_LS_TTL_SHIFT;
  101. result.tc = (entry & MPLS_LS_TC_MASK) >> MPLS_LS_TC_SHIFT;
  102. result.bos = (entry & MPLS_LS_S_MASK) >> MPLS_LS_S_SHIFT;
  103. return result;
  104. }
  105. int nla_put_labels(struct sk_buff *skb, int attrtype, u8 labels,
  106. const u32 label[]);
  107. int nla_get_labels(const struct nlattr *nla, u32 max_labels, u8 *labels,
  108. u32 label[]);
  109. int nla_get_via(const struct nlattr *nla, u8 *via_alen, u8 *via_table,
  110. u8 via[]);
  111. bool mpls_output_possible(const struct net_device *dev);
  112. unsigned int mpls_dev_mtu(const struct net_device *dev);
  113. bool mpls_pkt_too_big(const struct sk_buff *skb, unsigned int mtu);
  114. #endif /* MPLS_INTERNAL_H */