mirror of
https://git.savannah.nongnu.org/git/lwip.git
synced 2026-05-23 00:27:09 +08:00
Added a simple multi-netif 802.1d bridge implementation to show that a multi-port netif works (see task #14369)
This commit is contained in:
81
src/include/netif/bridgeif.h
Normal file
81
src/include/netif/bridgeif.h
Normal file
@@ -0,0 +1,81 @@
|
||||
/**
|
||||
* @file
|
||||
* lwIP netif implementing an IEEE 802.1D MAC Bridge
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Simon Goldschmidt.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt <goldsimon@gmx.de>
|
||||
*
|
||||
*/
|
||||
#ifndef LWIP_HDR_NETIF_BRIDGEIF_H
|
||||
#define LWIP_HDR_NETIF_BRIDGEIF_H
|
||||
|
||||
#include "netif/bridgeif_opts.h"
|
||||
|
||||
#include "lwip/err.h"
|
||||
#include "lwip/prot/ethernet.h"
|
||||
|
||||
struct netif;
|
||||
|
||||
#if (BRIDGEIF_MAX_PORTS < 0) || (BRIDGEIF_MAX_PORTS >= 64)
|
||||
#error BRIDGEIF_MAX_PORTS must be [1..63]
|
||||
#elif BRIDGEIF_MAX_PORTS < 8
|
||||
typedef u8_t bridgeif_portmask_t;
|
||||
#elif BRIDGEIF_MAX_PORTS < 16
|
||||
typedef u16_t bridgeif_portmask_t;
|
||||
#elif BRIDGEIF_MAX_PORTS < 32
|
||||
typedef u32_t bridgeif_portmask_t;
|
||||
#elif BRIDGEIF_MAX_PORTS < 64
|
||||
typedef u64_t bridgeif_portmask_t;
|
||||
#endif
|
||||
|
||||
#define BR_FLOOD ((bridgeif_portmask_t)-1)
|
||||
|
||||
|
||||
typedef struct bridgeif_initdata_s {
|
||||
struct eth_addr ethaddr;
|
||||
u8_t max_ports;
|
||||
u16_t max_fdb_dynamic_entries;
|
||||
u16_t max_fdb_static_entries;
|
||||
} bridgeif_initdata_t;
|
||||
|
||||
/* Use this for constant initialization of a bridgeif_initdat_t
|
||||
(ethaddr must be passed as pointer)*/
|
||||
#define BRIDGEIF_INITDATA1(max_ports, max_fdb_dynamic_entries, max_fdb_static_entries, ethaddr) {ethaddr, max_ports, max_fdb_dynamic_entries, max_fdb_static_entries}
|
||||
/* Use this for constant initialization of a bridgeif_initdat_t
|
||||
(each byte of ethaddr must be passed)*/
|
||||
#define BRIDGEIF_INITDATA2(max_ports, max_fdb_dynamic_entries, max_fdb_static_entries, e0, e1, e2, e3, e4, e5) {max_ports, max_fdb_dynamic_entries, max_fdb_static_entries, {{e0, e1, e2, e3, e4, e5}}
|
||||
|
||||
err_t bridgeif_init(struct netif *netif);
|
||||
err_t bridgeif_add_port(struct netif *bridgeif, struct netif *portif);
|
||||
err_t bridgeif_fdb_add(struct netif *bridgeif, const struct eth_addr *addr, bridgeif_portmask_t ports);
|
||||
err_t bridgeif_fdb_remove(struct netif *bridgeif, const struct eth_addr *addr);
|
||||
|
||||
#endif /* LWIP_HDR_NETIF_BRIDGEIF_H */
|
||||
85
src/include/netif/bridgeif_opts.h
Normal file
85
src/include/netif/bridgeif_opts.h
Normal file
@@ -0,0 +1,85 @@
|
||||
/**
|
||||
* @file
|
||||
* lwIP netif implementing an IEEE 802.1D MAC Bridge
|
||||
*/
|
||||
|
||||
/*
|
||||
* Copyright (c) 2017 Simon Goldschmidt.
|
||||
* All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without modification,
|
||||
* are permitted provided that the following conditions are met:
|
||||
*
|
||||
* 1. Redistributions of source code must retain the above copyright notice,
|
||||
* this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright notice,
|
||||
* this list of conditions and the following disclaimer in the documentation
|
||||
* and/or other materials provided with the distribution.
|
||||
* 3. The name of the author may not be used to endorse or promote products
|
||||
* derived from this software without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
|
||||
* WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
|
||||
* MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
|
||||
* SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
|
||||
* EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
|
||||
* OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
|
||||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
|
||||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
|
||||
* IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
|
||||
* OF SUCH DAMAGE.
|
||||
*
|
||||
* This file is part of the lwIP TCP/IP stack.
|
||||
*
|
||||
* Author: Simon Goldschmidt <goldsimon@gmx.de>
|
||||
*
|
||||
*/
|
||||
|
||||
#ifndef LWIP_HDR_NETIF_BRIDGEIF_OPTS_H
|
||||
#define LWIP_HDR_NETIF_BRIDGEIF_OPTS_H
|
||||
|
||||
#include "lwip/opt.h"
|
||||
|
||||
/** BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT==1: set port netif's 'input' function
|
||||
* to call directly into bridgeif code and on top of that, directly call into
|
||||
* the selected forwarding port's 'linkoutput' function.
|
||||
* This means that the bridgeif input/output path is protected from concurrent access
|
||||
* but as well, the port netif's drivers must correctly handle concurrent access!
|
||||
* == 0 (default): get into tcpip_thread for every input packet (no multithreading)
|
||||
*/
|
||||
#ifndef BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT
|
||||
#define BRIDGEIF_PORT_NETIFS_OUTPUT_DIRECT 0
|
||||
#endif
|
||||
|
||||
/** BRIDGEIF_EXTERNAL_FDB==1: use an external implementation for the forwarding
|
||||
* database which is possibly faster than our example implementation.
|
||||
* (Watch out for concurrent access!)
|
||||
*/
|
||||
#ifndef BRIDGEIF_EXTERNAL_FDB
|
||||
#define BRIDGEIF_EXTERNAL_FDB 0
|
||||
#endif
|
||||
|
||||
/** BRIDGEIF_MAX_PORTS: this is used to create a typedef used for forwarding
|
||||
* bit-fields: the number of bits required is this + 1 (for the internal/cpu port)
|
||||
* (63 is the maximum, resulting in an u64_t for the bit mask)
|
||||
*/
|
||||
#ifndef BRIDGEIF_MAX_PORTS
|
||||
#define BRIDGEIF_MAX_PORTS 7
|
||||
#endif
|
||||
|
||||
/** BRIDGEIF_DEBUG: Enable generic debugging in bridgeif.c. */
|
||||
#ifndef BRIDGEIF_DEBUG
|
||||
#define BRIDGEIF_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
/** BRIDGEIF_DEBUG: Enable FDB debugging in bridgeif.c. */
|
||||
#ifndef BRIDGEIF_FDB_DEBUG
|
||||
#define BRIDGEIF_FDB_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
/** BRIDGEIF_DEBUG: Enable forwarding debugging in bridgeif.c. */
|
||||
#ifndef BRIDGEIF_FW_DEBUG
|
||||
#define BRIDGEIF_FW_DEBUG LWIP_DBG_OFF
|
||||
#endif
|
||||
|
||||
#endif /* LWIP_HDR_NETIF_BRIDGEIF_OPTS_H */
|
||||
Reference in New Issue
Block a user