18c2ecf20Sopenharmony_ci/* SPDX-License-Identifier: GPL-2.0 */ 28c2ecf20Sopenharmony_ci#ifndef _NET_GARP_H 38c2ecf20Sopenharmony_ci#define _NET_GARP_H 48c2ecf20Sopenharmony_ci 58c2ecf20Sopenharmony_ci#include <net/stp.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define GARP_PROTOCOL_ID 0x1 88c2ecf20Sopenharmony_ci#define GARP_END_MARK 0x0 98c2ecf20Sopenharmony_ci 108c2ecf20Sopenharmony_cistruct garp_pdu_hdr { 118c2ecf20Sopenharmony_ci __be16 protocol; 128c2ecf20Sopenharmony_ci}; 138c2ecf20Sopenharmony_ci 148c2ecf20Sopenharmony_cistruct garp_msg_hdr { 158c2ecf20Sopenharmony_ci u8 attrtype; 168c2ecf20Sopenharmony_ci}; 178c2ecf20Sopenharmony_ci 188c2ecf20Sopenharmony_cienum garp_attr_event { 198c2ecf20Sopenharmony_ci GARP_LEAVE_ALL, 208c2ecf20Sopenharmony_ci GARP_JOIN_EMPTY, 218c2ecf20Sopenharmony_ci GARP_JOIN_IN, 228c2ecf20Sopenharmony_ci GARP_LEAVE_EMPTY, 238c2ecf20Sopenharmony_ci GARP_LEAVE_IN, 248c2ecf20Sopenharmony_ci GARP_EMPTY, 258c2ecf20Sopenharmony_ci}; 268c2ecf20Sopenharmony_ci 278c2ecf20Sopenharmony_cistruct garp_attr_hdr { 288c2ecf20Sopenharmony_ci u8 len; 298c2ecf20Sopenharmony_ci u8 event; 308c2ecf20Sopenharmony_ci u8 data[]; 318c2ecf20Sopenharmony_ci}; 328c2ecf20Sopenharmony_ci 338c2ecf20Sopenharmony_cistruct garp_skb_cb { 348c2ecf20Sopenharmony_ci u8 cur_type; 358c2ecf20Sopenharmony_ci}; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_cistatic inline struct garp_skb_cb *garp_cb(struct sk_buff *skb) 388c2ecf20Sopenharmony_ci{ 398c2ecf20Sopenharmony_ci BUILD_BUG_ON(sizeof(struct garp_skb_cb) > 408c2ecf20Sopenharmony_ci sizeof_field(struct sk_buff, cb)); 418c2ecf20Sopenharmony_ci return (struct garp_skb_cb *)skb->cb; 428c2ecf20Sopenharmony_ci} 438c2ecf20Sopenharmony_ci 448c2ecf20Sopenharmony_cienum garp_applicant_state { 458c2ecf20Sopenharmony_ci GARP_APPLICANT_INVALID, 468c2ecf20Sopenharmony_ci GARP_APPLICANT_VA, 478c2ecf20Sopenharmony_ci GARP_APPLICANT_AA, 488c2ecf20Sopenharmony_ci GARP_APPLICANT_QA, 498c2ecf20Sopenharmony_ci GARP_APPLICANT_LA, 508c2ecf20Sopenharmony_ci GARP_APPLICANT_VP, 518c2ecf20Sopenharmony_ci GARP_APPLICANT_AP, 528c2ecf20Sopenharmony_ci GARP_APPLICANT_QP, 538c2ecf20Sopenharmony_ci GARP_APPLICANT_VO, 548c2ecf20Sopenharmony_ci GARP_APPLICANT_AO, 558c2ecf20Sopenharmony_ci GARP_APPLICANT_QO, 568c2ecf20Sopenharmony_ci __GARP_APPLICANT_MAX 578c2ecf20Sopenharmony_ci}; 588c2ecf20Sopenharmony_ci#define GARP_APPLICANT_MAX (__GARP_APPLICANT_MAX - 1) 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_cienum garp_event { 618c2ecf20Sopenharmony_ci GARP_EVENT_REQ_JOIN, 628c2ecf20Sopenharmony_ci GARP_EVENT_REQ_LEAVE, 638c2ecf20Sopenharmony_ci GARP_EVENT_R_JOIN_IN, 648c2ecf20Sopenharmony_ci GARP_EVENT_R_JOIN_EMPTY, 658c2ecf20Sopenharmony_ci GARP_EVENT_R_EMPTY, 668c2ecf20Sopenharmony_ci GARP_EVENT_R_LEAVE_IN, 678c2ecf20Sopenharmony_ci GARP_EVENT_R_LEAVE_EMPTY, 688c2ecf20Sopenharmony_ci GARP_EVENT_TRANSMIT_PDU, 698c2ecf20Sopenharmony_ci __GARP_EVENT_MAX 708c2ecf20Sopenharmony_ci}; 718c2ecf20Sopenharmony_ci#define GARP_EVENT_MAX (__GARP_EVENT_MAX - 1) 728c2ecf20Sopenharmony_ci 738c2ecf20Sopenharmony_cienum garp_action { 748c2ecf20Sopenharmony_ci GARP_ACTION_NONE, 758c2ecf20Sopenharmony_ci GARP_ACTION_S_JOIN_IN, 768c2ecf20Sopenharmony_ci GARP_ACTION_S_LEAVE_EMPTY, 778c2ecf20Sopenharmony_ci}; 788c2ecf20Sopenharmony_ci 798c2ecf20Sopenharmony_cistruct garp_attr { 808c2ecf20Sopenharmony_ci struct rb_node node; 818c2ecf20Sopenharmony_ci enum garp_applicant_state state; 828c2ecf20Sopenharmony_ci u8 type; 838c2ecf20Sopenharmony_ci u8 dlen; 848c2ecf20Sopenharmony_ci unsigned char data[]; 858c2ecf20Sopenharmony_ci}; 868c2ecf20Sopenharmony_ci 878c2ecf20Sopenharmony_cienum garp_applications { 888c2ecf20Sopenharmony_ci GARP_APPLICATION_GVRP, 898c2ecf20Sopenharmony_ci __GARP_APPLICATION_MAX 908c2ecf20Sopenharmony_ci}; 918c2ecf20Sopenharmony_ci#define GARP_APPLICATION_MAX (__GARP_APPLICATION_MAX - 1) 928c2ecf20Sopenharmony_ci 938c2ecf20Sopenharmony_cistruct garp_application { 948c2ecf20Sopenharmony_ci enum garp_applications type; 958c2ecf20Sopenharmony_ci unsigned int maxattr; 968c2ecf20Sopenharmony_ci struct stp_proto proto; 978c2ecf20Sopenharmony_ci}; 988c2ecf20Sopenharmony_ci 998c2ecf20Sopenharmony_cistruct garp_applicant { 1008c2ecf20Sopenharmony_ci struct garp_application *app; 1018c2ecf20Sopenharmony_ci struct net_device *dev; 1028c2ecf20Sopenharmony_ci struct timer_list join_timer; 1038c2ecf20Sopenharmony_ci 1048c2ecf20Sopenharmony_ci spinlock_t lock; 1058c2ecf20Sopenharmony_ci struct sk_buff_head queue; 1068c2ecf20Sopenharmony_ci struct sk_buff *pdu; 1078c2ecf20Sopenharmony_ci struct rb_root gid; 1088c2ecf20Sopenharmony_ci struct rcu_head rcu; 1098c2ecf20Sopenharmony_ci}; 1108c2ecf20Sopenharmony_ci 1118c2ecf20Sopenharmony_cistruct garp_port { 1128c2ecf20Sopenharmony_ci struct garp_applicant __rcu *applicants[GARP_APPLICATION_MAX + 1]; 1138c2ecf20Sopenharmony_ci struct rcu_head rcu; 1148c2ecf20Sopenharmony_ci}; 1158c2ecf20Sopenharmony_ci 1168c2ecf20Sopenharmony_ciint garp_register_application(struct garp_application *app); 1178c2ecf20Sopenharmony_civoid garp_unregister_application(struct garp_application *app); 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_ciint garp_init_applicant(struct net_device *dev, struct garp_application *app); 1208c2ecf20Sopenharmony_civoid garp_uninit_applicant(struct net_device *dev, 1218c2ecf20Sopenharmony_ci struct garp_application *app); 1228c2ecf20Sopenharmony_ci 1238c2ecf20Sopenharmony_ciint garp_request_join(const struct net_device *dev, 1248c2ecf20Sopenharmony_ci const struct garp_application *app, const void *data, 1258c2ecf20Sopenharmony_ci u8 len, u8 type); 1268c2ecf20Sopenharmony_civoid garp_request_leave(const struct net_device *dev, 1278c2ecf20Sopenharmony_ci const struct garp_application *app, 1288c2ecf20Sopenharmony_ci const void *data, u8 len, u8 type); 1298c2ecf20Sopenharmony_ci 1308c2ecf20Sopenharmony_ci#endif /* _NET_GARP_H */ 131