garp.h 2.7 KB

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