Zephyr API Documentation 4.3.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
45struct eth_bridge_iface_context {
46 /* Lock to protect access to interface array below */
47 struct k_mutex lock;
48
49 /* The actual bridge virtual interface */
50 struct net_if *iface;
51
52 /* What Ethernet interfaces are bridged together */
53 struct net_if *eth_iface[NET_ETHERNET_BRIDGE_ETH_INTERFACE_COUNT];
54
55 /* How many interfaces are bridged atm */
56 size_t count;
57
58 /* Bridge instance id */
59 int id;
60
61 /* Is the bridge interface initialized */
62 bool is_init : 1;
63
64 /* Has user configured the bridge */
65 bool is_setup : 1;
66
67 /* Is the interface enabled or not */
68 bool status : 1;
69};
70
72
87int eth_bridge_iface_add(struct net_if *br, struct net_if *iface);
88
102int eth_bridge_iface_remove(struct net_if *br, struct net_if *iface);
103
112
121
129typedef void (*eth_bridge_cb_t)(struct eth_bridge_iface_context *br, void *user_data);
130
139void net_eth_bridge_foreach(eth_bridge_cb_t cb, void *user_data);
140
148static inline bool net_eth_iface_is_bridged(struct ethernet_context *ctx)
149{
150#if defined(CONFIG_NET_ETHERNET_BRIDGE)
151 struct eth_bridge_iface_context *br_ctx;
152
153 if (ctx->bridge == NULL) {
154 return false;
155 }
156
157 br_ctx = net_if_get_device(ctx->bridge)->data;
158 if (br_ctx->is_setup) {
159 return true;
160 }
161#endif
162 return false;
163}
164
172static inline struct net_if *net_eth_get_bridge(struct ethernet_context *ctx)
173{
174#if defined(CONFIG_NET_ETHERNET_BRIDGE)
175 return ctx->bridge;
176#else
177 return NULL;
178#endif
179}
180
189enum net_verdict eth_bridge_input_process(struct net_if *iface, struct net_pkt *pkt);
190
194
195#ifdef __cplusplus
196}
197#endif
198
199#endif /* ZEPHYR_INCLUDE_NET_ETHERNET_BRIDGE_H_ */
Ethernet.
static bool net_eth_iface_is_bridged(struct ethernet_context *ctx)
Check if the iface is bridged.
Definition ethernet_bridge.h:148
int eth_bridge_iface_add(struct net_if *br, struct net_if *iface)
Add an Ethernet network interface to a bridge.
enum net_verdict eth_bridge_input_process(struct net_if *iface, struct net_pkt *pkt)
Process pkt received on bridged interface.
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.
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:129
static struct net_if * net_eth_get_bridge(struct ethernet_context *ctx)
Get bridge iface.
Definition ethernet_bridge.h:172
int eth_bridge_get_index(struct net_if *br)
Get bridge index according to pointer.
net_verdict
Net Verdict.
Definition net_core.h:109
static const struct device * net_if_get_device(struct net_if *iface)
Get an network interface's device.
Definition net_if.h:1050
#define NULL
Definition iar_missing_defs.h:20
void * data
Address of the device instance private data.
Definition device.h:523
Network Interface structure.
Definition net_if.h:726
Network packet.
Definition net_pkt.h:91