garp.h 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. /* SPDX-License-Identifier: GPL-2.0 */
  2. #ifndef _NET_GARP_H
  3. #define _NET_GARP_H
  4. #include <net/stp.h>
  5. #define GARP_PROTOCOL_ID 0x1
  6. #define GARP_END_MARK 0x0
  7. struct garp_pdu_hdr {
  8. __be16 protocol;
  9. };
  10. struct garp_msg_hdr {
  11. u8 attrtype;
  12. };
  13. enum garp_attr_event {
  14. GARP_LEAVE_ALL,
  15. GARP_JOIN_EMPTY,
  16. GARP_JOIN_IN,
  17. GARP_LEAVE_EMPTY,
  18. GARP_LEAVE_IN,
  19. GARP_EMPTY,
  20. };
  21. struct garp_attr_hdr {
  22. u8 len;
  23. u8 event;
  24. u8 data[];
  25. };
  26. struct garp_skb_cb {
  27. u8 cur_type;
  28. };
  29. static inline struct garp_skb_cb *garp_cb(struct sk_buff *skb)
  30. {
  31. BUILD_BUG_ON(sizeof(struct garp_skb_cb) >
  32. FIELD_SIZEOF(struct sk_buff, cb));
  33. return (struct garp_skb_cb *)skb->cb;
  34. }
  35. enum garp_applicant_state {
  36. GARP_APPLICANT_INVALID,
  37. GARP_APPLICANT_VA,
  38. GARP_APPLICANT_AA,
  39. GARP_APPLICANT_QA,
  40. GARP_APPLICANT_LA,
  41. GARP_APPLICANT_VP,
  42. GARP_APPLICANT_AP,
  43. GARP_APPLICANT_QP,
  44. GARP_APPLICANT_VO,
  45. GARP_APPLICANT_AO,
  46. GARP_APPLICANT_QO,
  47. __GARP_APPLICANT_MAX
  48. };
  49. #define GARP_APPLICANT_MAX (__GARP_APPLICANT_MAX - 1)
  50. enum garp_event {
  51. GARP_EVENT_REQ_JOIN,
  52. GARP_EVENT_REQ_LEAVE,
  53. GARP_EVENT_R_JOIN_IN,
  54. GARP_EVENT_R_JOIN_EMPTY,
  55. GARP_EVENT_R_EMPTY,
  56. GARP_EVENT_R_LEAVE_IN,
  57. GARP_EVENT_R_LEAVE_EMPTY,
  58. GARP_EVENT_TRANSMIT_PDU,
  59. __GARP_EVENT_MAX
  60. };
  61. #define GARP_EVENT_MAX (__GARP_EVENT_MAX - 1)
  62. enum garp_action {
  63. GARP_ACTION_NONE,
  64. GARP_ACTION_S_JOIN_IN,
  65. GARP_ACTION_S_LEAVE_EMPTY,
  66. };
  67. struct garp_attr {
  68. struct rb_node node;
  69. enum garp_applicant_state state;
  70. u8 type;
  71. u8 dlen;
  72. unsigned char data[];
  73. };
  74. enum garp_applications {
  75. GARP_APPLICATION_GVRP,
  76. __GARP_APPLICATION_MAX
  77. };
  78. #define GARP_APPLICATION_MAX (__GARP_APPLICATION_MAX - 1)
  79. struct garp_application {
  80. enum garp_applications type;
  81. unsigned int maxattr;
  82. struct stp_proto proto;
  83. };
  84. struct garp_applicant {
  85. struct garp_application *app;
  86. struct net_device *dev;
  87. struct timer_list join_timer;
  88. spinlock_t lock;
  89. struct sk_buff_head queue;
  90. struct sk_buff *pdu;
  91. struct rb_root gid;
  92. struct rcu_head rcu;
  93. };
  94. struct garp_port {
  95. struct garp_applicant __rcu *applicants[GARP_APPLICATION_MAX + 1];
  96. struct rcu_head rcu;
  97. };
  98. int garp_register_application(struct garp_application *app);
  99. void garp_unregister_application(struct garp_application *app);
  100. int garp_init_applicant(struct net_device *dev, struct garp_application *app);
  101. void garp_uninit_applicant(struct net_device *dev,
  102. struct garp_application *app);
  103. int garp_request_join(const struct net_device *dev,
  104. const struct garp_application *app, const void *data,
  105. u8 len, u8 type);
  106. void garp_request_leave(const struct net_device *dev,
  107. const struct garp_application *app,
  108. const void *data, u8 len, u8 type);
  109. #endif /* _NET_GARP_H */