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