xref: /openbsd-src/sys/net/if_etherbridge.h (revision 67d751881dba0630e8ab00a616fda59eed61a352)
1 /*	$OpenBSD: if_etherbridge.h,v 1.5 2024/11/04 00:13:15 jsg Exp $ */
2 
3 /*
4  * Copyright (c) 2018, 2021 David Gwynne <dlg@openbsd.org>
5  *
6  * Permission to use, copy, modify, and distribute this software for any
7  * purpose with or without fee is hereby granted, provided that the above
8  * copyright notice and this permission notice appear in all copies.
9  *
10  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
11  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
12  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
13  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
14  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
15  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
16  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
17  */
18 
19 #ifndef _NET_ETHERBRIDGE_H_
20 #define _NET_ETHERBRIDGE_H_
21 
22 #define ETHERBRIDGE_TABLE_BITS		8
23 #define ETHERBRIDGE_TABLE_SIZE		(1U << ETHERBRIDGE_TABLE_BITS)
24 #define ETHERBRIDGE_TABLE_MASK		(ETHERBRIDGE_TABLE_SIZE - 1)
25 
26 struct etherbridge_ops {
27 	int	 (*eb_op_port_eq)(void *, void *, void *);
28 	void	*(*eb_op_port_take)(void *, void *);
29 	void	 (*eb_op_port_rele)(void *, void *);
30 	size_t	 (*eb_op_port_ifname)(void *, char *, size_t, void *);
31 	void	 (*eb_op_port_sa)(void *, struct sockaddr_storage *, void *);
32 };
33 
34 struct etherbridge;
35 
36 struct eb_entry {
37 	SMR_TAILQ_ENTRY(eb_entry)	 ebe_lentry;
38 	union {
39 		RBT_ENTRY(eb_entry)	 _ebe_tentry;
40 		TAILQ_ENTRY(eb_entry)	 _ebe_qentry;
41 	}				 _ebe_entries;
42 #define ebe_tentry	_ebe_entries._ebe_tentry
43 #define ebe_qentry	_ebe_entries._ebe_qentry
44 
45 	uint64_t			 ebe_addr;
46 	void				*ebe_port;
47 	unsigned int			 ebe_type;
48 #define EBE_DYNAMIC				0x0
49 #define EBE_STATIC				0x1
50 #define EBE_DEAD				0xdead
51 	time_t				 ebe_age;
52 
53 	struct etherbridge		*ebe_etherbridge;
54 	struct smr_entry		 ebe_smr_entry;
55 };
56 
57 SMR_TAILQ_HEAD(eb_list, eb_entry);
58 RBT_HEAD(eb_tree, eb_entry);
59 TAILQ_HEAD(eb_queue, eb_entry);
60 
61 struct etherbridge {
62 	const char			*eb_name;
63 	const struct etherbridge_ops	*eb_ops;
64 	void				*eb_cookie;
65 
66 	struct mutex			 eb_lock;
67 	unsigned int			 eb_num;
68 	unsigned int			 eb_max;
69 	int				 eb_max_age; /* seconds */
70 	struct timeout			 eb_tmo_age;
71 
72 	struct eb_list			*eb_table;
73 	struct eb_tree			 eb_tree;
74 
75 };
76 
77 int	 etherbridge_init(struct etherbridge *, const char *,
78 	     const struct etherbridge_ops *, void *);
79 int	 etherbridge_up(struct etherbridge *);
80 int	 etherbridge_down(struct etherbridge *);
81 void	 etherbridge_destroy(struct etherbridge *);
82 
83 void	 etherbridge_map(struct etherbridge *, void *, uint64_t);
84 void	 etherbridge_map_ea(struct etherbridge *, void *,
85 	     const struct ether_addr *);
86 void	*etherbridge_resolve(struct etherbridge *, uint64_t);
87 void	*etherbridge_resolve_ea(struct etherbridge *,
88 	     const struct ether_addr *);
89 void	 etherbridge_detach_port(struct etherbridge *, void *);
90 
91 /* ioctl support */
92 int	 etherbridge_set_max(struct etherbridge *, struct ifbrparam *);
93 int	 etherbridge_get_max(struct etherbridge *, struct ifbrparam *);
94 int	 etherbridge_set_tmo(struct etherbridge *, struct ifbrparam *);
95 int	 etherbridge_get_tmo(struct etherbridge *, struct ifbrparam *);
96 int	 etherbridge_rtfind(struct etherbridge *, struct ifbaconf *);
97 int	 etherbridge_add_addr(struct etherbridge *, void *,
98 	     const struct ether_addr *, unsigned int);
99 int	 etherbridge_del_addr(struct etherbridge *, const struct ether_addr *);
100 void	 etherbridge_flush(struct etherbridge *, uint32_t);
101 
102 #endif /* _NET_ETHERBRIDGE_H_ */
103