zephyr/subsys/net/l2/ethernet/bridge.h
Jukka Rissanen 6986b1ef71 net: bridge: Overhaul the code to use virtual interfaces
The legacy bridging code prevented normal IP traffic to the
bridged Ethernet interfaces. This is not intuitive and differs
how bridging setup works in Linux. This commit changes that and
creates a separate virtual interface that is doing the actual
bridging. This enables the bridged Ethernet interfaces to work
normally and provide IP connectivity.

How this works in practice:

* User needs to enable CONFIG_NET_ETHERNET_BRIDGE
* User needs to have a device with more than one Ethernet
  interface
* After booting, the net-shell or program API can be used
  to add interfaces to the bridge like this.
     net bridge addif 1 3 2
  where the 1 is the bridge interface index and
  2 and 3 are the Ethernet interface indices.
* The bridging is then finally enabled / started when the
  bridge interface 1 is taken up
     net iface up 1
* If bridged interfaces are removed from the bridge (minimum
  of two interfaces are needed there), then the bridging is
  disabled automatically. The bridge interface stays up in
  this case and can be taken down manually.

Signed-off-by: Jukka Rissanen <jukka.rissanen@nordicsemi.no>
2024-09-06 18:01:15 -04:00

41 lines
707 B
C

/*
* Copyright (c) 2021 BayLibre SAS
* Copyright (c) 2024 Nordic Semiconductor
*
* SPDX-License-Identifier: Apache-2.0
*/
#ifndef __BRIDGE_H
#define __BRIDGE_H
static inline bool net_eth_iface_is_bridged(struct ethernet_context *ctx)
{
#if defined(CONFIG_NET_ETHERNET_BRIDGE)
struct eth_bridge_iface_context *br_ctx;
if (ctx->bridge == NULL) {
return false;
}
br_ctx = net_if_get_device(ctx->bridge)->data;
if (br_ctx->is_setup) {
return true;
}
return false;
#else
return false;
#endif
}
static inline struct net_if *net_eth_get_bridge(struct ethernet_context *ctx)
{
#if defined(CONFIG_NET_ETHERNET_BRIDGE)
return ctx->bridge;
#else
return NULL;
#endif
}
#endif /* __BRIDGE_H */