8
8
9
9
/*
10
10
* Copyright (c) 2021 BayLibre SAS
11
+ * Copyright (c) 2024 Nordic Semiconductor
11
12
*
12
13
* SPDX-License-Identifier: Apache-2.0
13
14
*/
@@ -33,42 +34,36 @@ extern "C" {
33
34
34
35
/** @cond INTERNAL_HIDDEN */
35
36
36
- struct eth_bridge {
37
+ #if defined(CONFIG_NET_ETHERNET_BRIDGE )
38
+ #define NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT CONFIG_NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT
39
+ #else
40
+ #define NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT 1
41
+ #endif
42
+
43
+ struct eth_bridge_iface_context {
44
+ /* Lock to protect access to interface array below */
37
45
struct k_mutex lock ;
38
- sys_slist_t interfaces ;
39
- sys_slist_t listeners ;
40
- bool initialized ;
41
- };
42
46
43
- #define ETH_BRIDGE_INITIALIZER (obj ) \
44
- { \
45
- .lock = { }, \
46
- .interfaces = SYS_SLIST_STATIC_INIT(&obj.interfaces), \
47
- .listeners = SYS_SLIST_STATIC_INIT(&obj.listeners), \
48
- }
47
+ /* The actual bridge virtual interface */
48
+ struct net_if * iface ;
49
49
50
- /** @endcond */
50
+ /* What Ethernet interfaces are bridged together */
51
+ struct net_if * eth_iface [NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT ];
51
52
52
- /**
53
- * @brief Statically define and initialize a bridge instance.
54
- *
55
- * @param name Name of the bridge object
56
- */
57
- #define ETH_BRIDGE_INIT (name ) \
58
- STRUCT_SECTION_ITERABLE(eth_bridge, name) = \
59
- ETH_BRIDGE_INITIALIZER(name)
53
+ /* How many interfaces are bridged atm */
54
+ size_t count ;
60
55
61
- /** @cond INTERNAL_HIDDEN */
56
+ /* Bridge instance id */
57
+ int id ;
62
58
63
- struct eth_bridge_iface_context {
64
- sys_snode_t node ;
65
- struct eth_bridge * instance ;
66
- bool allow_tx ;
67
- } ;
59
+ /* Is the bridge interface initialized */
60
+ bool is_init : 1 ;
61
+
62
+ /* Has user configured the bridge */
63
+ bool is_setup : 1 ;
68
64
69
- struct eth_bridge_listener {
70
- sys_snode_t node ;
71
- struct k_fifo pkt_queue ;
65
+ /* Is the interface enabled or not */
66
+ bool status : 1 ;
72
67
};
73
68
74
69
/** @endcond */
@@ -77,77 +72,32 @@ struct eth_bridge_listener {
77
72
* @brief Add an Ethernet network interface to a bridge
78
73
*
79
74
* This adds a network interface to a bridge. The interface is then put
80
- * into promiscuous mode, all packets received by this interface are sent
81
- * to the bridge, and any other packets sent to the bridge (with some
82
- * exceptions) are transmitted via this interface.
83
- *
84
- * For transmission from the bridge to occur via this interface, it is
85
- * necessary to enable TX mode with eth_bridge_iface_tx(). TX mode is
86
- * initially disabled.
75
+ * into promiscuous mode. After more than one Ethernet interfaces are
76
+ * added to the bridge interface, the bridge interface is setup.
77
+ * After the setup is done, the bridge interface can be brought up so
78
+ * that it can start bridging L2 traffic.
87
79
*
88
- * Once an interface is added to a bridge, all its incoming traffic is
89
- * diverted to the bridge. However, packets sent out with net_if_queue_tx()
90
- * via this interface are not subjected to the bridge.
91
- *
92
- * @param br A pointer to an initialized bridge object
80
+ * @param br A pointer to a bridge interface
93
81
* @param iface Interface to add
94
82
*
95
83
* @return 0 if OK, negative error code otherwise.
96
84
*/
97
- int eth_bridge_iface_add (struct eth_bridge * br , struct net_if * iface );
85
+ int eth_bridge_iface_add (struct net_if * br , struct net_if * iface );
98
86
99
87
/**
100
- * @brief Remove an Ethernet network interface from a bridge
88
+ * @brief Remove an Ethernet network interface from a bridge.
101
89
*
102
- * @param br A pointer to an initialized bridge object
103
- * @param iface Interface to remove
90
+ * If the bridge interface setup has only one Ethernet interface left
91
+ * after this function call, the bridge is disabled as it cannot bridge
92
+ * the L2 traffic any more. The bridge interface is left in UP state
93
+ * if this case.
104
94
*
105
- * @return 0 if OK, negative error code otherwise.
106
- */
107
- int eth_bridge_iface_remove (struct eth_bridge * br , struct net_if * iface );
108
-
109
- /**
110
- * @brief Enable/disable transmission mode for a bridged interface
111
- *
112
- * When TX mode is off, the interface may receive packets and send them to
113
- * the bridge but no packets coming from the bridge will be sent through this
114
- * interface. When TX mode is on, both incoming and outgoing packets are
115
- * allowed.
116
- *
117
- * @param iface Interface to configure
118
- * @param allow true to activate TX mode, false otherwise
119
- *
120
- * @return 0 if OK, negative error code otherwise.
121
- */
122
- int eth_bridge_iface_allow_tx (struct net_if * iface , bool allow );
123
-
124
- /**
125
- * @brief Add (register) a listener to the bridge
126
- *
127
- * This lets a software listener register a pointer to a provided FIFO for
128
- * receiving packets sent to the bridge. The listener is responsible for
129
- * emptying the FIFO with k_fifo_get() which will return a struct net_pkt
130
- * pointer, and releasing the packet with net_pkt_unref() when done with it.
131
- *
132
- * The listener wishing not to receive any more packets should simply
133
- * unregister itself with eth_bridge_listener_remove().
134
- *
135
- * @param br A pointer to an initialized bridge object
136
- * @param l A pointer to an initialized listener instance.
137
- *
138
- * @return 0 if OK, negative error code otherwise.
139
- */
140
- int eth_bridge_listener_add (struct eth_bridge * br , struct eth_bridge_listener * l );
141
-
142
- /**
143
- * @brief Remove (unregister) a listener from the bridge
144
- *
145
- * @param br A pointer to an initialized bridge object
146
- * @param l A pointer to the listener instance to be removed.
95
+ * @param br A pointer to a bridge interface
96
+ * @param iface Interface to remove
147
97
*
148
98
* @return 0 if OK, negative error code otherwise.
149
99
*/
150
- int eth_bridge_listener_remove (struct eth_bridge * br , struct eth_bridge_listener * l );
100
+ int eth_bridge_iface_remove (struct net_if * br , struct net_if * iface );
151
101
152
102
/**
153
103
* @brief Get bridge index according to pointer
@@ -156,28 +106,28 @@ int eth_bridge_listener_remove(struct eth_bridge *br, struct eth_bridge_listener
156
106
*
157
107
* @return Bridge index
158
108
*/
159
- int eth_bridge_get_index (struct eth_bridge * br );
109
+ int eth_bridge_get_index (struct net_if * br );
160
110
161
111
/**
162
112
* @brief Get bridge instance according to index
163
113
*
164
114
* @param index Bridge instance index
165
115
*
166
- * @return Pointer to bridge instance or NULL if not found.
116
+ * @return Pointer to bridge interface or NULL if not found.
167
117
*/
168
- struct eth_bridge * eth_bridge_get_by_index (int index );
118
+ struct net_if * eth_bridge_get_by_index (int index );
169
119
170
120
/**
171
121
* @typedef eth_bridge_cb_t
172
122
* @brief Callback used while iterating over bridge instances
173
123
*
174
- * @param br Pointer to bridge instance
124
+ * @param br Pointer to bridge context instance
175
125
* @param user_data User supplied data
176
126
*/
177
- typedef void (* eth_bridge_cb_t )(struct eth_bridge * br , void * user_data );
127
+ typedef void (* eth_bridge_cb_t )(struct eth_bridge_iface_context * br , void * user_data );
178
128
179
129
/**
180
- * @brief Go through all the bridge instances in order to get
130
+ * @brief Go through all the bridge context instances in order to get
181
131
* information about them. This is mainly useful in
182
132
* net-shell to print data about currently active bridges.
183
133
*
0 commit comments