Zephyr API Documentation 4.5.99
A Scalable Open Source RTOS
Loading...
Searching...
No Matches
ethernet_bridge.h
Go to the documentation of this file.
1
8
9/*
10 * Copyright (c) 2021 BayLibre SAS
11 * Copyright (c) 2024 Nordic Semiconductor
12 * SPDX-FileCopyrightText: Copyright 2025 NXP
13 *
14 * SPDX-License-Identifier: Apache-2.0
15 */
16
17#ifndef ZEPHYR_INCLUDE_NET_ETHERNET_BRIDGE_H_
18#define ZEPHYR_INCLUDE_NET_ETHERNET_BRIDGE_H_
19
20#include <zephyr/sys/slist.h>
22#include <zephyr/net/ethernet.h>
23
24#ifdef __cplusplus
25extern "C" {
26#endif
27
36
38
39#if defined(CONFIG_NET_ETHERNET_BRIDGE)
40#define NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT CONFIG_NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT
41#else
42#define NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT 1
43#endif
44
45/* Forwarding state of a bridge port, as in IEEE 802.1D-2004 7.4 */
46enum eth_bridge_port_state {
47 /* Frames are neither forwarded nor learned from */
48 ETH_BRIDGE_PORT_STATE_DISCARDING = 0,
49 /* Source addresses are learned, frames are not forwarded */
50 ETH_BRIDGE_PORT_STATE_LEARNING,
51 /* Frames are learned from and forwarded */
52 ETH_BRIDGE_PORT_STATE_FORWARDING,
53};
54
55/* One Ethernet interface bridged by a bridge interface */
56struct eth_bridge_port {
57 /* The bridged Ethernet interface, NULL if the slot is free */
58 struct net_if *iface;
59
60 /* Port state, an enum eth_bridge_port_state. Read without the
61 * bridge lock in the data path.
62 */
64};
65
66struct eth_bridge_iface_context {
67 /* Lock to protect access to the port array below */
68 struct k_mutex lock;
69
70 /* The actual bridge virtual interface */
71 struct net_if *iface;
72
73 /* What Ethernet interfaces are bridged together */
74 struct eth_bridge_port ports[NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT];
75
76 /* How many interfaces are bridged atm */
77 size_t count;
78
79 /* Bridge instance id */
80 int id;
81
82 /* Has user configured the bridge */
83 bool is_setup : 1;
84
85 /* Is the interface enabled or not */
86 bool status : 1;
87};
88
90
107int eth_bridge_iface_add(struct net_if *br, struct net_if *iface);
108
122int eth_bridge_iface_remove(struct net_if *br, struct net_if *iface);
123
132
141
149typedef void (*eth_bridge_cb_t)(struct eth_bridge_iface_context *br, void *user_data);
150
159void net_eth_bridge_foreach(eth_bridge_cb_t cb, void *user_data);
160
168static inline bool net_eth_iface_is_bridged(struct ethernet_context *ctx)
169{
170#if defined(CONFIG_NET_ETHERNET_BRIDGE)
171 struct eth_bridge_iface_context *br_ctx;
172 const struct device *br_dev;
173
174 NET_ASSERT(ctx != NULL);
175
176 if (ctx->bridge == NULL) {
177 return false;
178 }
179
180 br_dev = net_if_get_device(ctx->bridge);
181
182 br_ctx = (struct eth_bridge_iface_context *)br_dev->data;
183 if (br_ctx->is_setup) {
184 return true;
185 }
186#endif
187 return false;
188}
189
197static inline struct net_if *net_eth_get_bridge(struct ethernet_context *ctx)
198{
199#if defined(CONFIG_NET_ETHERNET_BRIDGE)
200 NET_ASSERT(ctx != NULL);
201
202 return ctx->bridge;
203#else
204 return NULL;
205#endif
206}
207
217enum net_verdict eth_bridge_input_process(struct net_if *iface, struct net_pkt *pkt,
218 struct net_if **dst_iface);
219
223
224#ifdef __cplusplus
225}
226#endif
227
228#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_BRIDGE_H_ */
Ethernet.
long atomic_t
Atomic integer variable.
Definition atomic_types.h:34
static bool net_eth_iface_is_bridged(struct ethernet_context *ctx)
Check if the iface is bridged.
Definition ethernet_bridge.h:168
int eth_bridge_iface_add(struct net_if *br, struct net_if *iface)
Add an Ethernet network interface to a bridge.
void net_eth_bridge_foreach(eth_bridge_cb_t cb, void *user_data)
Go through all the bridge context instances in order to get information about them.
int eth_bridge_iface_remove(struct net_if *br, struct net_if *iface)
Remove an Ethernet network interface from a bridge.
struct net_if * eth_bridge_get_by_index(int index)
Get bridge instance according to index.
enum net_verdict eth_bridge_input_process(struct net_if *iface, struct net_pkt *pkt, struct net_if **dst_iface)
Process pkt received on bridged interface.
void(* eth_bridge_cb_t)(struct eth_bridge_iface_context *br, void *user_data)
Callback used while iterating over bridge instances.
Definition ethernet_bridge.h:149
static struct net_if * net_eth_get_bridge(struct ethernet_context *ctx)
Get bridge iface.
Definition ethernet_bridge.h:197
int eth_bridge_get_index(struct net_if *br)
Get bridge index according to pointer.
net_verdict
Net Verdict.
Definition net_core.h:84
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:1205
state
Definition parser_state.h:29
Header file for the single-linked list API.
Runtime device structure (in ROM) per driver instance.
Definition device.h:543
void * data
Address of the device instance private data.
Definition device.h:553
Network Interface structure.
Definition net_if.h:875
Network packet.
Definition net_pkt.h:119
Iterable sections helpers.