From 89cd5f23ba48ad95473f4a19ee87471e07ecbf34 Mon Sep 17 00:00:00 2001 From: zy Date: Fri, 12 Jan 2024 02:56:19 -0500 Subject: [PATCH] add linux tap -> netif --- src/Controls.cpp | 15 +++++++++++++++ src/LwipLinuxTap.cpp | 20 ++++++++++++++++++++ src/LwipLinuxTap.h | 11 +++++++++++ 3 files changed, 46 insertions(+) create mode 100644 src/LwipLinuxTap.cpp create mode 100644 src/LwipLinuxTap.h diff --git a/src/Controls.cpp b/src/Controls.cpp index 8aa0a72..a8acfdb 100644 --- a/src/Controls.cpp +++ b/src/Controls.cpp @@ -22,6 +22,10 @@ #include "Signals.hpp" #include "VirtualTap.hpp" + +#include +#include "LwipLinuxTap.h" + #include using namespace ZeroTier; @@ -559,9 +563,20 @@ void* _runNodeService(void* arg) return NULL; } +void testtap(){ + tcpip_init(nullptr, nullptr); + ip4_addr_t ipaddr, netmask, gw; + IP4_ADDR(&gw, 172, 2, 0, 1); + IP4_ADDR(&ipaddr, 172, 2, 0, 100); + IP4_ADDR(&netmask, 255, 255, 255, 0); + init_default_netif(&ipaddr, &netmask, &gw); + netif_set_up(&get_default_netif()); +} + int zts_node_start() { ACQUIRE_SERVICE_OFFLINE(); + testtap(); // Start TCP/IP stack zts_lwip_driver_init(); // Start callback thread diff --git a/src/LwipLinuxTap.cpp b/src/LwipLinuxTap.cpp new file mode 100644 index 0000000..68fc876 --- /dev/null +++ b/src/LwipLinuxTap.cpp @@ -0,0 +1,20 @@ +#include "lwip/netif.h" +#include "lwip/ip_addr.h" +#include "lwip/tcpip.h" +extern "C" { +#include "netif/tapif.h" +} + +static netif default_network_interface; + +void init_default_netif(const ip4_addr_t* ipaddr, const ip4_addr_t* netmask, const ip4_addr_t* gw) +{ + netif_add(&default_network_interface, ipaddr, netmask, gw, nullptr, tapif_init, tcpip_input); + + netif_set_default(&default_network_interface); +} + +netif& get_default_netif() +{ + return default_network_interface; +} diff --git a/src/LwipLinuxTap.h b/src/LwipLinuxTap.h new file mode 100644 index 0000000..d81691d --- /dev/null +++ b/src/LwipLinuxTap.h @@ -0,0 +1,11 @@ +#ifndef LWIP_LINUX_UNIX_TAP_NETWORK_INTERFACE_H +#define LWIP_LINUX_UNIX_TAP_NETWORK_INTERFACE_H + +#include "lwip/netif.h" + +void init_default_netif(const ip4_addr_t* ipaddr, const ip4_addr_t* netmask, const ip4_addr_t* gw); + +netif& get_default_netif(); + + +#endif //LWIP_LINUX_UNIX_TAP_NETWORK_INTERFACE_H \ No newline at end of file