summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorzy <[email protected]>2024-01-12 02:56:19 -0500
committerzy <[email protected]>2024-01-12 02:56:19 -0500
commit89cd5f23ba48ad95473f4a19ee87471e07ecbf34 (patch)
tree24b214a316817766e3746c14bf3d7eee55041581
parentc2b368833d5b4cdb8e1c3b999fc17b2b72f6bb47 (diff)
add linux tap -> netif
-rw-r--r--src/Controls.cpp15
-rw-r--r--src/LwipLinuxTap.cpp20
-rw-r--r--src/LwipLinuxTap.h11
3 files changed, 46 insertions, 0 deletions
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 <lwip/tcpip.h>
+#include "LwipLinuxTap.h"
+
#include <string.h>
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