mrp.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _NET_MRP_H
  3. #define _NET_MRP_H
  4. #define MRP_END_MARK 0x0
  5. struct mrp_pdu_hdr {
  6. u8 version;
  7. };
  8. struct mrp_msg_hdr {
  9. u8 attrtype;
  10. u8 attrlen;
  11. };
  12. struct mrp_vecattr_hdr {
  13. __be16 lenflags;
  14. unsigned char firstattrvalue[];
  15. #define MRP_VECATTR_HDR_LEN_MASK cpu_to_be16(0x1FFF)
  16. #define MRP_VECATTR_HDR_FLAG_LA cpu_to_be16(0x2000)
  17. };
  18. enum mrp_vecattr_event {
  19. MRP_VECATTR_EVENT_NEW,
  20. MRP_VECATTR_EVENT_JOIN_IN,
  21. MRP_VECATTR_EVENT_IN,
  22. MRP_VECATTR_EVENT_JOIN_MT,
  23. MRP_VECATTR_EVENT_MT,
  24. MRP_VECATTR_EVENT_LV,
  25. __MRP_VECATTR_EVENT_MAX
  26. };
  27. struct mrp_skb_cb {
  28. struct mrp_msg_hdr *mh;
  29. struct mrp_vecattr_hdr *vah;
  30. unsigned char attrvalue[];
  31. };
  32. static inline struct mrp_skb_cb *mrp_cb(struct sk_buff *skb)
  33. {
  34. BUILD_BUG_ON(sizeof(struct mrp_skb_cb) >
  35. FIELD_SIZEOF(struct sk_buff, cb));
  36. return (struct mrp_skb_cb *)skb->cb;
  37. }
  38. enum mrp_applicant_state {
  39. MRP_APPLICANT_INVALID,
  40. MRP_APPLICANT_VO,
  41. MRP_APPLICANT_VP,
  42. MRP_APPLICANT_VN,
  43. MRP_APPLICANT_AN,
  44. MRP_APPLICANT_AA,
  45. MRP_APPLICANT_QA,
  46. MRP_APPLICANT_LA,
  47. MRP_APPLICANT_AO,
  48. MRP_APPLICANT_QO,
  49. MRP_APPLICANT_AP,
  50. MRP_APPLICANT_QP,
  51. __MRP_APPLICANT_MAX
  52. };
  53. #define MRP_APPLICANT_MAX (__MRP_APPLICANT_MAX - 1)
  54. enum mrp_event {
  55. MRP_EVENT_NEW,
  56. MRP_EVENT_JOIN,
  57. MRP_EVENT_LV,
  58. MRP_EVENT_TX,
  59. MRP_EVENT_R_NEW,
  60. MRP_EVENT_R_JOIN_IN,
  61. MRP_EVENT_R_IN,
  62. MRP_EVENT_R_JOIN_MT,
  63. MRP_EVENT_R_MT,
  64. MRP_EVENT_R_LV,
  65. MRP_EVENT_R_LA,
  66. MRP_EVENT_REDECLARE,
  67. MRP_EVENT_PERIODIC,
  68. __MRP_EVENT_MAX
  69. };
  70. #define MRP_EVENT_MAX (__MRP_EVENT_MAX - 1)
  71. enum mrp_tx_action {
  72. MRP_TX_ACTION_NONE,
  73. MRP_TX_ACTION_S_NEW,
  74. MRP_TX_ACTION_S_JOIN_IN,
  75. MRP_TX_ACTION_S_JOIN_IN_OPTIONAL,
  76. MRP_TX_ACTION_S_IN_OPTIONAL,
  77. MRP_TX_ACTION_S_LV,
  78. };
  79. struct mrp_attr {
  80. struct rb_node node;
  81. enum mrp_applicant_state state;
  82. u8 type;
  83. u8 len;
  84. unsigned char value[];
  85. };
  86. enum mrp_applications {
  87. MRP_APPLICATION_MVRP,
  88. __MRP_APPLICATION_MAX
  89. };
  90. #define MRP_APPLICATION_MAX (__MRP_APPLICATION_MAX - 1)
  91. struct mrp_application {
  92. enum mrp_applications type;
  93. unsigned int maxattr;
  94. struct packet_type pkttype;
  95. unsigned char group_address[ETH_ALEN];
  96. u8 version;
  97. };
  98. struct mrp_applicant {
  99. struct mrp_application *app;
  100. struct net_device *dev;
  101. struct timer_list join_timer;
  102. struct timer_list periodic_timer;
  103. spinlock_t lock;
  104. struct sk_buff_head queue;
  105. struct sk_buff *pdu;
  106. struct rb_root mad;
  107. struct rcu_head rcu;
  108. };
  109. struct mrp_port {
  110. struct mrp_applicant __rcu *applicants[MRP_APPLICATION_MAX + 1];
  111. struct rcu_head rcu;
  112. };
  113. int mrp_register_application(struct mrp_application *app);
  114. void mrp_unregister_application(struct mrp_application *app);
  115. int mrp_init_applicant(struct net_device *dev, struct mrp_application *app);
  116. void mrp_uninit_applicant(struct net_device *dev, struct mrp_application *app);
  117. int mrp_request_join(const struct net_device *dev,
  118. const struct mrp_application *app,
  119. const void *value, u8 len, u8 type);
  120. void mrp_request_leave(const struct net_device *dev,
  121. const struct mrp_application *app,
  122. const void *value, u8 len, u8 type);
  123. #endif /* _NET_MRP_H */