diff --git a/pkg/lwip/contrib/netdev/lwip_netdev.c b/pkg/lwip/contrib/netdev/lwip_netdev.c index e70e4eacee..c256d3ddbe 100644 --- a/pkg/lwip/contrib/netdev/lwip_netdev.c +++ b/pkg/lwip/contrib/netdev/lwip_netdev.c @@ -21,6 +21,7 @@ #include "lwip/ethip6.h" #include "lwip/netif.h" #include "lwip/netifapi.h" +#include "lwip/netif/compat.h" #include "lwip/netif/netdev.h" #include "lwip/opt.h" #include "lwip/pbuf.h" @@ -192,7 +193,6 @@ err_t lwip_netdev_init(struct netif *netif) } netif->flags |= NETIF_FLAG_IGMP; netif->flags |= NETIF_FLAG_MLD6; - netdev->context = netif; #if LWIP_IPV6_AUTOCONFIG netif->ip6_autoconfig_enabled = 1; #endif @@ -279,7 +279,8 @@ static void _event_cb(netdev_t *dev, netdev_event_t event) } } else { - struct netif *netif = dev->context; + lwip_netif_t *compat_netif = dev->context; + struct netif *netif = &compat_netif->lwip_netif; switch (event) { case NETDEV_EVENT_RX_COMPLETE: { struct pbuf *p = _get_recv_pkt(dev); diff --git a/pkg/lwip/include/lwip/netif/compat.h b/pkg/lwip/include/lwip/netif/compat.h new file mode 100644 index 0000000000..0a3c97f9e4 --- /dev/null +++ b/pkg/lwip/include/lwip/netif/compat.h @@ -0,0 +1,43 @@ +/* + * Copyright (C) 2021 Google LLC + * + * This file is subject to the terms and conditions of the GNU Lesser + * General Public License v2.1. See the file LICENSE in the top level + * directory for more details. + */ + +/** + * @ingroup pkg_lwip + * + * @{ + * + * @file + * @brief lwIP definition based on common netif_t struct for network + * stack-independent API. + * + * @author Erik Ekman + */ +#ifndef LWIP_NETIF_COMPAT_H +#define LWIP_NETIF_COMPAT_H + +#include "lwip/netif.h" +#include "net/netif.h" + +#ifdef __cplusplus +extern "C" { +#endif + +/** + * @brief Representation of a network interface + */ +typedef struct { + netif_t common_netif; /**< network interface descriptor */ + struct netif lwip_netif; /**< lwIP interface data */ +} lwip_netif_t; + +#ifdef __cplusplus +} +#endif + +#endif /* LWIP_NETIF_COMPAT_H */ +/** @} */ diff --git a/pkg/lwip/include/lwip/netif/netdev.h b/pkg/lwip/include/lwip/netif/netdev.h index c3b1ec77cf..2163021a9f 100644 --- a/pkg/lwip/include/lwip/netif/netdev.h +++ b/pkg/lwip/include/lwip/netif/netdev.h @@ -46,6 +46,7 @@ extern "C" { * to an existing netdev_t instance * * @pre netif->state is set to an existing netdev_t instance. + * netif->state->context pointing to the lwip_netif_t containing this netif. * * @param[in] netif The network interface intended to be initialized. * diff --git a/pkg/lwip/include/lwip_init_devs.h b/pkg/lwip/include/lwip_init_devs.h index 3e65453ba3..d0344f4fb4 100644 --- a/pkg/lwip/include/lwip_init_devs.h +++ b/pkg/lwip/include/lwip_init_devs.h @@ -24,7 +24,7 @@ extern "C" { #endif -#include "lwip/netif.h" +#include "lwip/netif/compat.h" #include "net/netdev.h" #include "xfa.h" @@ -39,7 +39,7 @@ void lwip_netif_init_devs(void); * The netif will be set up using the `lwip_netdev_init` helper. * The first netif added will be marked as the default route. */ -struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state); +struct netif *lwip_add_ethernet(lwip_netif_t *netif, netdev_t *state); #if IS_USED(MODULE_LWIP_SIXLOWPAN) /** @@ -50,7 +50,7 @@ struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state); * * The netif will be set up using the `lwip_netdev_init` helper. */ -struct netif *lwip_add_6lowpan(struct netif *netif, netdev_t *state); +struct netif *lwip_add_6lowpan(lwip_netif_t *netif, netdev_t *state); #endif /* MODULE_LWIP_SIXLOWPAN */ typedef void (*lwip_netif_setup_func_t)(void); diff --git a/pkg/lwip/init_devs/auto_init_at86rf215.c b/pkg/lwip/init_devs/auto_init_at86rf215.c index 6932026581..6e2b2cd9fc 100644 --- a/pkg/lwip/init_devs/auto_init_at86rf215.c +++ b/pkg/lwip/init_devs/auto_init_at86rf215.c @@ -28,7 +28,7 @@ #define USED_BANDS (IS_USED(MODULE_AT86RF215_SUBGHZ) + IS_USED(MODULE_AT86RF215_24GHZ)) #define NETIF_AT86RF215_NUMOF ARRAY_SIZE(at86rf215_params) -static struct netif netif[NETIF_AT86RF215_NUMOF * USED_BANDS]; +static lwip_netif_t netif[NETIF_AT86RF215_NUMOF * USED_BANDS]; static at86rf215_t at86rf215_devs[NETIF_AT86RF215_NUMOF * USED_BANDS]; static void auto_init_at86rf215(void) @@ -38,8 +38,8 @@ static void auto_init_at86rf215(void) at86rf215_t *dev_09 = NULL; at86rf215_t *dev_24 = NULL; - struct netif *netif_09 = NULL; - struct netif *netif_24 = NULL; + lwip_netif_t *netif_09 = NULL; + lwip_netif_t *netif_24 = NULL; if (IS_USED(MODULE_AT86RF215_SUBGHZ)) { dev_09 = &at86rf215_devs[i]; diff --git a/pkg/lwip/init_devs/auto_init_at86rf2xx.c b/pkg/lwip/init_devs/auto_init_at86rf2xx.c index 6063471264..b017120a66 100644 --- a/pkg/lwip/init_devs/auto_init_at86rf2xx.c +++ b/pkg/lwip/init_devs/auto_init_at86rf2xx.c @@ -27,7 +27,7 @@ #define NETIF_AT86RF2XX_NUMOF ARRAY_SIZE(at86rf2xx_params) -static struct netif netif[NETIF_AT86RF2XX_NUMOF]; +static lwip_netif_t netif[NETIF_AT86RF2XX_NUMOF]; static at86rf2xx_t at86rf2xx_devs[NETIF_AT86RF2XX_NUMOF]; static void auto_init_at86rf2xx(void) diff --git a/pkg/lwip/init_devs/auto_init_atwinc15x0.c b/pkg/lwip/init_devs/auto_init_atwinc15x0.c index 11b98f58f7..78a4b5a086 100644 --- a/pkg/lwip/init_devs/auto_init_atwinc15x0.c +++ b/pkg/lwip/init_devs/auto_init_atwinc15x0.c @@ -27,7 +27,7 @@ #define NETIF_ATWINC_NUMOF ARRAY_SIZE(atwinc15x0_params) -static struct netif netif[NETIF_ATWINC_NUMOF]; +static lwip_netif_t netif[NETIF_ATWINC_NUMOF]; static atwinc15x0_t atwinc15x0_devs[NETIF_ATWINC_NUMOF]; static void auto_init_atwinc15x0(void) diff --git a/pkg/lwip/init_devs/auto_init_cc2538_rf.c b/pkg/lwip/init_devs/auto_init_cc2538_rf.c index 24539fd4fa..afbd4189b0 100644 --- a/pkg/lwip/init_devs/auto_init_cc2538_rf.c +++ b/pkg/lwip/init_devs/auto_init_cc2538_rf.c @@ -25,7 +25,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -static struct netif netif; +static lwip_netif_t netif; static netdev_ieee802154_submac_t cc2538_rf_netdev; static void auto_init_cc2538_rf(void) diff --git a/pkg/lwip/init_devs/auto_init_dose.c b/pkg/lwip/init_devs/auto_init_dose.c index 604d67b81b..09abe2c851 100644 --- a/pkg/lwip/init_devs/auto_init_dose.c +++ b/pkg/lwip/init_devs/auto_init_dose.c @@ -27,7 +27,7 @@ #define NETIF_DOSE_NUMOF ARRAY_SIZE(dose_params) -static struct netif netif[NETIF_DOSE_NUMOF]; +static lwip_netif_t netif[NETIF_DOSE_NUMOF]; static dose_t dose_devs[NETIF_DOSE_NUMOF]; static void auto_init_dose(void) diff --git a/pkg/lwip/init_devs/auto_init_enc28j60.c b/pkg/lwip/init_devs/auto_init_enc28j60.c index 932036d30a..42c18d9880 100644 --- a/pkg/lwip/init_devs/auto_init_enc28j60.c +++ b/pkg/lwip/init_devs/auto_init_enc28j60.c @@ -27,7 +27,7 @@ #define NETIF_ENC28J60_NUMOF ARRAY_SIZE(enc28j60_params) -static struct netif netif[NETIF_ENC28J60_NUMOF]; +static lwip_netif_t netif[NETIF_ENC28J60_NUMOF]; static enc28j60_t enc28j60_devs[NETIF_ENC28J60_NUMOF]; static void auto_init_enc28j60(void) diff --git a/pkg/lwip/init_devs/auto_init_esp_eth.c b/pkg/lwip/init_devs/auto_init_esp_eth.c index 319ea23114..4212420c94 100644 --- a/pkg/lwip/init_devs/auto_init_esp_eth.c +++ b/pkg/lwip/init_devs/auto_init_esp_eth.c @@ -27,7 +27,7 @@ extern esp_eth_netdev_t _esp_eth_dev; extern void esp_eth_setup(esp_eth_netdev_t* dev); -static struct netif netif; +static lwip_netif_t netif; static void auto_init_esp_eth(void) { diff --git a/pkg/lwip/init_devs/auto_init_esp_wifi.c b/pkg/lwip/init_devs/auto_init_esp_wifi.c index 8b2c187928..9256b88d3a 100644 --- a/pkg/lwip/init_devs/auto_init_esp_wifi.c +++ b/pkg/lwip/init_devs/auto_init_esp_wifi.c @@ -27,7 +27,7 @@ extern esp_wifi_netdev_t _esp_wifi_dev; extern void esp_wifi_setup(esp_wifi_netdev_t *dev); -static struct netif netif; +static lwip_netif_t netif; static void auto_init_esp_wifi(void) { diff --git a/pkg/lwip/init_devs/auto_init_ethos.c b/pkg/lwip/init_devs/auto_init_ethos.c index 96270ced65..c3058b40ac 100644 --- a/pkg/lwip/init_devs/auto_init_ethos.c +++ b/pkg/lwip/init_devs/auto_init_ethos.c @@ -27,7 +27,7 @@ #define NETIF_ETHOS_NUMOF ARRAY_SIZE(ethos_params) -static struct netif netif[NETIF_ETHOS_NUMOF]; +static lwip_netif_t netif[NETIF_ETHOS_NUMOF]; static ethos_t ethos_devs[NETIF_ETHOS_NUMOF]; static uint8_t _inbuf[NETIF_ETHOS_NUMOF][2048]; diff --git a/pkg/lwip/init_devs/auto_init_mrf24j40.c b/pkg/lwip/init_devs/auto_init_mrf24j40.c index 3926db819f..1fb59decad 100644 --- a/pkg/lwip/init_devs/auto_init_mrf24j40.c +++ b/pkg/lwip/init_devs/auto_init_mrf24j40.c @@ -28,7 +28,7 @@ #define NETIF_MRF24J40_NUMOF ARRAY_SIZE(mrf24j40_params) -static struct netif netif[NETIF_MRF24J40_NUMOF]; +static lwip_netif_t netif[NETIF_MRF24J40_NUMOF]; static mrf24j40_t mrf24j40_devs[NETIF_MRF24J40_NUMOF]; static void auto_init_mrf24j40(void) diff --git a/pkg/lwip/init_devs/auto_init_netdev_tap.c b/pkg/lwip/init_devs/auto_init_netdev_tap.c index 2939498854..f0f10c359c 100644 --- a/pkg/lwip/init_devs/auto_init_netdev_tap.c +++ b/pkg/lwip/init_devs/auto_init_netdev_tap.c @@ -27,7 +27,7 @@ #define NETIF_TAP_NUMOF (NETDEV_TAP_MAX) -static struct netif netif[NETIF_TAP_NUMOF]; +static lwip_netif_t netif[NETIF_TAP_NUMOF]; static netdev_tap_t netdev_taps[NETIF_TAP_NUMOF]; static void auto_init_netdev_tap(void) diff --git a/pkg/lwip/init_devs/auto_init_nrf802154.c b/pkg/lwip/init_devs/auto_init_nrf802154.c index 829137add2..59aae8ad44 100644 --- a/pkg/lwip/init_devs/auto_init_nrf802154.c +++ b/pkg/lwip/init_devs/auto_init_nrf802154.c @@ -25,7 +25,7 @@ #define ENABLE_DEBUG 0 #include "debug.h" -static struct netif netif; +static lwip_netif_t netif; static netdev_ieee802154_submac_t nrf802154_netdev; static void auto_init_nrf802154(void) diff --git a/pkg/lwip/init_devs/auto_init_sam0_eth.c b/pkg/lwip/init_devs/auto_init_sam0_eth.c index e3068d16b4..822f5e35c1 100644 --- a/pkg/lwip/init_devs/auto_init_sam0_eth.c +++ b/pkg/lwip/init_devs/auto_init_sam0_eth.c @@ -27,7 +27,7 @@ static netdev_t sam0_eth; extern void sam0_eth_setup(netdev_t *netdev); -static struct netif netif; +static lwip_netif_t netif; static void auto_init_sam0_eth(void) { diff --git a/pkg/lwip/init_devs/auto_init_socket_zep.c b/pkg/lwip/init_devs/auto_init_socket_zep.c index 3dca78c9b3..ce18cf8ef6 100644 --- a/pkg/lwip/init_devs/auto_init_socket_zep.c +++ b/pkg/lwip/init_devs/auto_init_socket_zep.c @@ -27,7 +27,7 @@ #define NETIF_SOCKET_ZEP_NUMOF ARRAY_SIZE(socket_zep_params) -static struct netif netif[NETIF_SOCKET_ZEP_NUMOF]; +static lwip_netif_t netif[NETIF_SOCKET_ZEP_NUMOF]; static socket_zep_t socket_zep_devs[NETIF_SOCKET_ZEP_NUMOF]; static void auto_init_socket_zep(void) diff --git a/pkg/lwip/init_devs/auto_init_stm32_eth.c b/pkg/lwip/init_devs/auto_init_stm32_eth.c index 864059d620..d1d48e1ade 100644 --- a/pkg/lwip/init_devs/auto_init_stm32_eth.c +++ b/pkg/lwip/init_devs/auto_init_stm32_eth.c @@ -27,7 +27,7 @@ static netdev_t stm32_eth; extern void stm32_eth_netdev_setup(netdev_t *netdev); -static struct netif netif; +static lwip_netif_t netif; static void auto_init_stm32_eth(void) { diff --git a/pkg/lwip/init_devs/init.c b/pkg/lwip/init_devs/init.c index c5ea854e96..fbc25351a7 100644 --- a/pkg/lwip/init_devs/init.c +++ b/pkg/lwip/init_devs/init.c @@ -18,6 +18,7 @@ #include "kernel_defines.h" #include "lwip_init_devs.h" #include "lwip/tcpip.h" +#include "lwip/netif/compat.h" #include "lwip/netif/netdev.h" #include "netif/lowpan6.h" #include "xfa.h" @@ -50,10 +51,21 @@ void lwip_netif_init_devs(void) } } -struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state) +static struct netif *setup_netif(lwip_netif_t *netif, netdev_t *state, + netif_input_fn input_fn) { - struct netif *_if = netif_add_noaddr(netif, state, lwip_netdev_init, - tcpip_input); + state->context = netif; + struct netif *_if = netif_add_noaddr(&netif->lwip_netif, state, lwip_netdev_init, + input_fn); + if (_if) { + netif_register(&netif->common_netif); + } + return _if; +} + +struct netif *lwip_add_ethernet(lwip_netif_t *netif, netdev_t *state) +{ + struct netif *_if = setup_netif(netif, state, tcpip_input); if (_if && netif_default == NULL) { netif_set_default(_if); } @@ -61,9 +73,9 @@ struct netif *lwip_add_ethernet(struct netif *netif, netdev_t *state) } #if IS_USED(MODULE_LWIP_SIXLOWPAN) -struct netif *lwip_add_6lowpan(struct netif *netif, netdev_t *state) +struct netif *lwip_add_6lowpan(lwip_netif_t *netif, netdev_t *state) { - return netif_add_noaddr(netif, state, lwip_netdev_init, tcpip_6lowpan_input); + return setup_netif(netif, state, tcpip_6lowpan_input); } #endif /* MODULE_LWIP_SIXLOWPAN */