netmap_bdg.h revision 341477
1#ifndef _NET_NETMAP_BDG_H_ 2#define _NET_NETMAP_BDG_H_ 3 4#if defined(__FreeBSD__) 5#define BDG_RWLOCK_T struct rwlock // struct rwlock 6 7#define BDG_RWINIT(b) \ 8 rw_init_flags(&(b)->bdg_lock, "bdg lock", RW_NOWITNESS) 9#define BDG_WLOCK(b) rw_wlock(&(b)->bdg_lock) 10#define BDG_WUNLOCK(b) rw_wunlock(&(b)->bdg_lock) 11#define BDG_RLOCK(b) rw_rlock(&(b)->bdg_lock) 12#define BDG_RTRYLOCK(b) rw_try_rlock(&(b)->bdg_lock) 13#define BDG_RUNLOCK(b) rw_runlock(&(b)->bdg_lock) 14#define BDG_RWDESTROY(b) rw_destroy(&(b)->bdg_lock) 15 16#endif /* __FreeBSD__ */ 17 18/* $FreeBSD: stable/11/sys/dev/netmap/netmap_bdg.h 341477 2018-12-04 17:40:56Z vmaffione $ */ 19 20/* XXX Should go away after fixing find_bridge() - Michio */ 21#define NM_BDG_HASH 1024 /* forwarding table entries */ 22 23/* XXX revise this */ 24struct nm_hash_ent { 25 uint64_t mac; /* the top 2 bytes are the epoch */ 26 uint64_t ports; 27}; 28 29/* Default size for the Maximum Frame Size. */ 30#define NM_BDG_MFS_DEFAULT 1514 31 32/* 33 * nm_bridge is a descriptor for a VALE switch. 34 * Interfaces for a bridge are all in bdg_ports[]. 35 * The array has fixed size, an empty entry does not terminate 36 * the search, but lookups only occur on attach/detach so we 37 * don't mind if they are slow. 38 * 39 * The bridge is non blocking on the transmit ports: excess 40 * packets are dropped if there is no room on the output port. 41 * 42 * bdg_lock protects accesses to the bdg_ports array. 43 * This is a rw lock (or equivalent). 44 */ 45#define NM_BDG_IFNAMSIZ IFNAMSIZ 46struct nm_bridge { 47 /* XXX what is the proper alignment/layout ? */ 48 BDG_RWLOCK_T bdg_lock; /* protects bdg_ports */ 49 int bdg_namelen; 50 uint32_t bdg_active_ports; 51 char bdg_basename[NM_BDG_IFNAMSIZ]; 52 53 /* Indexes of active ports (up to active_ports) 54 * and all other remaining ports. 55 */ 56 uint32_t bdg_port_index[NM_BDG_MAXPORTS]; 57 /* used by netmap_bdg_detach_common() */ 58 uint32_t tmp_bdg_port_index[NM_BDG_MAXPORTS]; 59 60 struct netmap_vp_adapter *bdg_ports[NM_BDG_MAXPORTS]; 61 62 /* 63 * Programmable lookup functions to figure out the destination port. 64 * It returns either of an index of the destination port, 65 * NM_BDG_BROADCAST to broadcast this packet, or NM_BDG_NOPORT not to 66 * forward this packet. ring_nr is the source ring index, and the 67 * function may overwrite this value to forward this packet to a 68 * different ring index. 69 * The function is set by netmap_bdg_regops(). 70 */ 71 struct netmap_bdg_ops *bdg_ops; 72 73 /* 74 * Contains the data structure used by the bdg_ops.lookup function. 75 * By default points to *ht which is allocated on attach and used by the default lookup 76 * otherwise will point to the data structure received by netmap_bdg_regops(). 77 */ 78 void *private_data; 79 struct nm_hash_ent *ht; 80 81 /* Currently used to specify if the bridge is still in use while empty and 82 * if it has been put in exclusive mode by an external module, see netmap_bdg_regops() 83 * and netmap_bdg_create(). 84 */ 85#define NM_BDG_ACTIVE 1 86#define NM_BDG_EXCLUSIVE 2 87 uint8_t bdg_flags; 88 89 90#ifdef CONFIG_NET_NS 91 struct net *ns; 92#endif /* CONFIG_NET_NS */ 93}; 94 95static inline void * 96nm_bdg_get_auth_token(struct nm_bridge *b) 97{ 98 return b->ht; 99} 100 101/* bridge not in exclusive mode ==> always valid 102 * bridge in exclusive mode (created through netmap_bdg_create()) ==> check authentication token 103 */ 104static inline int 105nm_bdg_valid_auth_token(struct nm_bridge *b, void *auth_token) 106{ 107 return !(b->bdg_flags & NM_BDG_EXCLUSIVE) || b->ht == auth_token; 108} 109 110int netmap_get_bdg_na(struct nmreq_header *hdr, struct netmap_adapter **na, 111 struct netmap_mem_d *nmd, int create, struct netmap_bdg_ops *ops); 112 113struct nm_bridge *nm_find_bridge(const char *name, int create, struct netmap_bdg_ops *ops); 114int netmap_bdg_free(struct nm_bridge *b); 115void netmap_bdg_detach_common(struct nm_bridge *b, int hw, int sw); 116int netmap_vp_bdg_ctl(struct nmreq_header *hdr, struct netmap_adapter *na); 117int netmap_vp_reg(struct netmap_adapter *na, int onoff); 118int netmap_bwrap_reg(struct netmap_adapter *, int onoff); 119int netmap_vp_reg(struct netmap_adapter *na, int onoff); 120int netmap_vp_rxsync(struct netmap_kring *kring, int flags); 121int netmap_bwrap_notify(struct netmap_kring *kring, int flags); 122int netmap_bwrap_attach_common(struct netmap_adapter *na, 123 struct netmap_adapter *hwna); 124int netmap_bwrap_krings_create_common(struct netmap_adapter *na); 125void netmap_bwrap_krings_delete_common(struct netmap_adapter *na); 126#define NM_NEED_BWRAP (-2) 127#endif /* _NET_NETMAP_BDG_H_ */ 128 129