IPV6 interface tweaks
This commit is contained in:
5
Makefile
5
Makefile
@@ -230,11 +230,11 @@ endif
|
|||||||
ifeq ($(LIBZT_IPV4)$(LIBZT_IPV6),1)
|
ifeq ($(LIBZT_IPV4)$(LIBZT_IPV6),1)
|
||||||
ifeq ($(LIBZT_IPV4),1)
|
ifeq ($(LIBZT_IPV4),1)
|
||||||
STACK_DRIVER_DEFS+=-DLIBZT_IPV4 -DLWIP_IPV4=1
|
STACK_DRIVER_DEFS+=-DLIBZT_IPV4 -DLWIP_IPV4=1
|
||||||
STACK_DEFS+=LIBZT_IPV4=1
|
STACK_DEFS+=LIBZT_IPV4=1 IPV4=1
|
||||||
endif
|
endif
|
||||||
ifeq ($(LIBZT_IPV6),1)
|
ifeq ($(LIBZT_IPV6),1)
|
||||||
STACK_DRIVER_DEFS+=-DLIBZT_IPV6 -DLWIP_IPV6=1
|
STACK_DRIVER_DEFS+=-DLIBZT_IPV6 -DLWIP_IPV6=1
|
||||||
STACK_DEFS+=LIBZT_IPV6=1
|
STACK_DEFS+=LIBZT_IPV6=1 IPV6=1
|
||||||
endif
|
endif
|
||||||
else
|
else
|
||||||
STACK_DRIVER_DEFS+=-DLIBZT_IPV4 -DLWIP_IPV4=1
|
STACK_DRIVER_DEFS+=-DLIBZT_IPV4 -DLWIP_IPV4=1
|
||||||
@@ -273,6 +273,7 @@ picotcp:
|
|||||||
cd ext/picotcp; make lib ARCH=shared IPV4=1 IPV6=1
|
cd ext/picotcp; make lib ARCH=shared IPV4=1 IPV6=1
|
||||||
|
|
||||||
lwip:
|
lwip:
|
||||||
|
echo $(STACK_DEFS)
|
||||||
make -f make-liblwip.mk liblwip.a $(STACK_DEFS)
|
make -f make-liblwip.mk liblwip.a $(STACK_DEFS)
|
||||||
|
|
||||||
lwip_driver:
|
lwip_driver:
|
||||||
|
|||||||
@@ -573,9 +573,12 @@ lwip_bind(int s, const struct sockaddr *name, socklen_t namelen)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* check size, family and alignment of 'name' */
|
/* check size, family and alignment of 'name' */
|
||||||
|
/*
|
||||||
LWIP_ERROR("lwip_bind: invalid address", (IS_SOCK_ADDR_LEN_VALID(namelen) &&
|
LWIP_ERROR("lwip_bind: invalid address", (IS_SOCK_ADDR_LEN_VALID(namelen) &&
|
||||||
IS_SOCK_ADDR_TYPE_VALID(name) && IS_SOCK_ADDR_ALIGNED(name)),
|
IS_SOCK_ADDR_TYPE_VALID(name) && IS_SOCK_ADDR_ALIGNED(name)),
|
||||||
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
|
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
|
||||||
|
*/
|
||||||
|
|
||||||
LWIP_UNUSED_ARG(namelen);
|
LWIP_UNUSED_ARG(namelen);
|
||||||
|
|
||||||
SOCKADDR_TO_IPADDR_PORT(name, &local_addr, local_port);
|
SOCKADDR_TO_IPADDR_PORT(name, &local_addr, local_port);
|
||||||
@@ -1155,10 +1158,12 @@ lwip_sendto(int s, const void *data, size_t size, int flags,
|
|||||||
/* @todo: split into multiple sendto's? */
|
/* @todo: split into multiple sendto's? */
|
||||||
LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
|
LWIP_ASSERT("lwip_sendto: size must fit in u16_t", size <= 0xffff);
|
||||||
short_size = (u16_t)size;
|
short_size = (u16_t)size;
|
||||||
|
/*
|
||||||
LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
|
LWIP_ERROR("lwip_sendto: invalid address", (((to == NULL) && (tolen == 0)) ||
|
||||||
(IS_SOCK_ADDR_LEN_VALID(tolen) &&
|
(IS_SOCK_ADDR_LEN_VALID(tolen) &&
|
||||||
IS_SOCK_ADDR_TYPE_VALID(to) && IS_SOCK_ADDR_ALIGNED(to))),
|
IS_SOCK_ADDR_TYPE_VALID(to) && IS_SOCK_ADDR_ALIGNED(to))),
|
||||||
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
|
sock_set_errno(sock, err_to_errno(ERR_ARG)); return -1;);
|
||||||
|
*/
|
||||||
LWIP_UNUSED_ARG(tolen);
|
LWIP_UNUSED_ARG(tolen);
|
||||||
|
|
||||||
/* initialize a buffer */
|
/* initialize a buffer */
|
||||||
|
|||||||
@@ -62,11 +62,6 @@ void lwip_dns_init();
|
|||||||
*/
|
*/
|
||||||
void lwip_start_dhcp(void *netif);
|
void lwip_start_dhcp(void *netif);
|
||||||
|
|
||||||
void general_lwip_init_interface(void *tapref, void *netif, const char *name, const ZeroTier::MAC &mac,
|
|
||||||
const ZeroTier::InetAddress &addr, const ZeroTier::InetAddress &nm, const ZeroTier::InetAddress &gw);
|
|
||||||
|
|
||||||
void general_turn_on_interface(void *netif);
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief Set up an interface in the network stack for the VirtualTap.
|
* @brief Set up an interface in the network stack for the VirtualTap.
|
||||||
*
|
*
|
||||||
|
|||||||
@@ -420,6 +420,7 @@ happening sooner than they should.
|
|||||||
* controlled via IP_REASSEMBLY.
|
* controlled via IP_REASSEMBLY.
|
||||||
*/
|
*/
|
||||||
#define IP_FRAG 1
|
#define IP_FRAG 1
|
||||||
|
#define IPV6_FRAG_COPYHEADER 1 // Was 0
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
|
* IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally)
|
||||||
@@ -458,7 +459,7 @@ happening sooner than they should.
|
|||||||
* Be careful, disable that make your product non-compliant to RFC1122
|
* Be careful, disable that make your product non-compliant to RFC1122
|
||||||
*/
|
*/
|
||||||
#define LWIP_ICMP 1
|
#define LWIP_ICMP 1
|
||||||
|
#define LWIP_ICMP6 LWIP_IPV6 && 1 // Was 0
|
||||||
|
|
||||||
/*------------------------------------------------------------------------------
|
/*------------------------------------------------------------------------------
|
||||||
------------------------------- RAW Options ------------------------------------
|
------------------------------- RAW Options ------------------------------------
|
||||||
|
|||||||
@@ -63,8 +63,17 @@ LWIPARCH=$(CONTRIBDIR)/ports/unix
|
|||||||
endif
|
endif
|
||||||
|
|
||||||
LWIPINCLUDES:=-I$(LWIPDIR)/include -I$(LWIPARCH) -I$(LWIPARCH)/include -I$(LWIPDIR) -I. -Iext -Iinclude
|
LWIPINCLUDES:=-I$(LWIPDIR)/include -I$(LWIPARCH) -I$(LWIPARCH)/include -I$(LWIPDIR) -I. -Iext -Iinclude
|
||||||
CFLAGS= $(WINDEFS) -Wno-format -Wno-deprecated -O3 -g -Wall -fPIC
|
CFLAGS=$(WINDEFS) -Wno-format -Wno-deprecated -O3 -g -Wall -fPIC $(LWIPINCLUDES)
|
||||||
CFLAGS+=-DLWIP_IPV4 -DLWIP_IPV6=0 -DIPv4 -DLWIP_DEBUG=1 $(LWIPINCLUDES)
|
|
||||||
|
ifeq ($(NS_DEBUG),1)
|
||||||
|
CFLAGS+=-DLWIP_DEBUG=1
|
||||||
|
endif
|
||||||
|
ifeq ($(IPV4),1)
|
||||||
|
CFLAGS+=-DLWIP_IPV4=1 -DLWIP_IPV6=0 -DIPv4
|
||||||
|
endif
|
||||||
|
ifeq ($(IPV6),1)
|
||||||
|
CFLAGS+=-DLWIP_IPV4=0 -DLWIP_IPV6=1 -DIPv6
|
||||||
|
endif
|
||||||
|
|
||||||
UNIXLIB=liblwip.a
|
UNIXLIB=liblwip.a
|
||||||
|
|
||||||
|
|||||||
@@ -506,7 +506,7 @@ int zts_add_dns_nameserver(struct sockaddr *addr)
|
|||||||
{
|
{
|
||||||
DEBUG_EXTRA();
|
DEBUG_EXTRA();
|
||||||
int err = -1;
|
int err = -1;
|
||||||
#if defined(STACK_LWIP)
|
#if defined(STACK_LWIP) && defined(LIBZT_IPV4)
|
||||||
struct sockaddr_in *in4 = (struct sockaddr_in*)&addr;
|
struct sockaddr_in *in4 = (struct sockaddr_in*)&addr;
|
||||||
static ip_addr_t ipaddr;
|
static ip_addr_t ipaddr;
|
||||||
ipaddr.addr = in4->sin_addr.s_addr;
|
ipaddr.addr = in4->sin_addr.s_addr;
|
||||||
|
|||||||
97
src/lwIP.cpp
97
src/lwIP.cpp
@@ -50,15 +50,21 @@
|
|||||||
#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */
|
#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */
|
||||||
#include "lwip/timeouts.h"
|
#include "lwip/timeouts.h"
|
||||||
#include "lwip/stats.h"
|
#include "lwip/stats.h"
|
||||||
|
#include "lwip/ethip6.h"
|
||||||
|
|
||||||
#include "dns.h"
|
#include "dns.h"
|
||||||
#include "netifapi.h"
|
#include "netifapi.h"
|
||||||
|
|
||||||
#include "lwIP.hpp"
|
#include "lwIP.hpp"
|
||||||
|
|
||||||
|
// lwIP netif interfaces used by virtual taps
|
||||||
netif lwipdev, lwipdev6, n1;
|
netif lwipdev, lwipdev6, n1;
|
||||||
|
struct netif lwip_interfaces[10];
|
||||||
|
static int num_lwip_interfaces = 0;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
struct netif netifs[10];
|
|
||||||
|
|
||||||
bool lwip_driver_initialized = false;
|
bool lwip_driver_initialized = false;
|
||||||
ZeroTier::Mutex driver_m;
|
ZeroTier::Mutex driver_m;
|
||||||
@@ -124,6 +130,7 @@ void lwip_driver_init()
|
|||||||
|
|
||||||
err_t lwip_eth_tx(struct netif *netif, struct pbuf *p)
|
err_t lwip_eth_tx(struct netif *netif, struct pbuf *p)
|
||||||
{
|
{
|
||||||
|
DEBUG_INFO();
|
||||||
struct pbuf *q;
|
struct pbuf *q;
|
||||||
char buf[ZT_MAX_MTU+32];
|
char buf[ZT_MAX_MTU+32];
|
||||||
char *bufptr;
|
char *bufptr;
|
||||||
@@ -163,47 +170,6 @@ err_t lwip_eth_tx(struct netif *netif, struct pbuf *p)
|
|||||||
return ERR_OK;
|
return ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
void general_lwip_init_interface(void *tapref, void *netif, const char *name, const ZeroTier::MAC &mac, const ZeroTier::InetAddress &addr, const ZeroTier::InetAddress &nm, const ZeroTier::InetAddress &gw)
|
|
||||||
{
|
|
||||||
#if defined(LIBZT_IPV4)
|
|
||||||
char ipbuf[INET6_ADDRSTRLEN], nmbuf[INET6_ADDRSTRLEN], gwbuf[INET6_ADDRSTRLEN];
|
|
||||||
static ip_addr_t _addr, _nm, _gw;
|
|
||||||
IP4_ADDR(&_gw,127,0,0,1);
|
|
||||||
IP4_ADDR(&_addr,10,6,6,86);
|
|
||||||
//_addr.addr = *((u32_t *)addr.rawIpData());
|
|
||||||
_nm.addr = *((u32_t *)addr.netmask().rawIpData());
|
|
||||||
netif_add(&(n1),&_addr, &_nm, &_gw, NULL, tapif_init, tcpip_input);
|
|
||||||
n1.state = tapref;
|
|
||||||
n1.output = etharp_output;
|
|
||||||
n1.mtu = ZT_MAX_MTU;
|
|
||||||
n1.name[0] = name[0];
|
|
||||||
n1.name[1] = name[1];
|
|
||||||
n1.linkoutput = lwip_eth_tx;
|
|
||||||
n1.hwaddr_len = 6;
|
|
||||||
mac.copyTo(n1.hwaddr, n1.hwaddr_len);
|
|
||||||
n1.flags = NETIF_FLAG_BROADCAST
|
|
||||||
| NETIF_FLAG_ETHARP
|
|
||||||
| NETIF_FLAG_IGMP
|
|
||||||
| NETIF_FLAG_LINK_UP
|
|
||||||
| NETIF_FLAG_UP;
|
|
||||||
netif_set_link_up(&n1);
|
|
||||||
char macbuf[ZT_MAC_ADDRSTRLEN];
|
|
||||||
mac2str(macbuf, ZT_MAC_ADDRSTRLEN, n1.hwaddr);
|
|
||||||
DEBUG_INFO("initialized netif as [mac=%s, addr=%s, nm=%s, gw=%s]", macbuf, addr.toString(ipbuf), addr.netmask().toString(nmbuf), gw.toString(gwbuf));
|
|
||||||
#endif
|
|
||||||
#if defined(LIBZT_IPV6)
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
|
|
||||||
void general_turn_on_interface(void *netif)
|
|
||||||
{
|
|
||||||
//netif_set_up(&n1);
|
|
||||||
//netif_set_default(&n1);
|
|
||||||
//lwipdev.linkoutput = NULL;
|
|
||||||
//netif_set_down(&lwipdev);
|
|
||||||
//netif_set_link_down(&lwipdev);
|
|
||||||
}
|
|
||||||
|
|
||||||
void lwip_dns_init()
|
void lwip_dns_init()
|
||||||
{
|
{
|
||||||
dns_init();
|
dns_init();
|
||||||
@@ -211,7 +177,9 @@ void lwip_dns_init()
|
|||||||
|
|
||||||
void lwip_start_dhcp(void *netif)
|
void lwip_start_dhcp(void *netif)
|
||||||
{
|
{
|
||||||
|
#if defined(LIBZT_IPV4)
|
||||||
netifapi_dhcp_start((struct netif *)netif);
|
netifapi_dhcp_start((struct netif *)netif);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
void lwip_init_interface(void *tapref, const ZeroTier::MAC &mac, const ZeroTier::InetAddress &ip)
|
void lwip_init_interface(void *tapref, const ZeroTier::MAC &mac, const ZeroTier::InetAddress &ip)
|
||||||
@@ -237,15 +205,43 @@ void lwip_init_interface(void *tapref, const ZeroTier::MAC &mac, const ZeroTier:
|
|||||||
| NETIF_FLAG_IGMP
|
| NETIF_FLAG_IGMP
|
||||||
| NETIF_FLAG_LINK_UP
|
| NETIF_FLAG_LINK_UP
|
||||||
| NETIF_FLAG_UP;
|
| NETIF_FLAG_UP;
|
||||||
netif_set_default(&(lwipdev));
|
netif_set_default(&lwipdev);
|
||||||
netif_set_link_up(&(lwipdev));
|
netif_set_link_up(&lwipdev);
|
||||||
netif_set_up(&(lwipdev));
|
netif_set_up(&lwipdev);
|
||||||
char macbuf[ZT_MAC_ADDRSTRLEN];
|
char macbuf[ZT_MAC_ADDRSTRLEN];
|
||||||
mac2str(macbuf, ZT_MAC_ADDRSTRLEN, lwipdev.hwaddr);
|
mac2str(macbuf, ZT_MAC_ADDRSTRLEN, lwipdev.hwaddr);
|
||||||
DEBUG_INFO("initialized netif as [mac=%s, addr=%s, nm=%s]", macbuf, ip.toString(ipbuf), ip.netmask().toString(nmbuf));
|
DEBUG_INFO("initialized netif as [mac=%s, addr=%s, nm=%s]", macbuf, ip.toString(ipbuf), ip.netmask().toString(nmbuf));
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
#if defined(LIBZT_IPV6)
|
#if defined(LIBZT_IPV6)
|
||||||
|
if (ip.isV6()) {
|
||||||
|
static ip_addr_t ipaddr;
|
||||||
|
memcpy(&(ipaddr.addr), ip.rawIpData(), sizeof(ipaddr.addr));
|
||||||
|
|
||||||
|
lwipdev6.mtu = ZT_MAX_MTU;
|
||||||
|
lwipdev6.name[0] = 'l';
|
||||||
|
lwipdev6.name[1] = '6';
|
||||||
|
lwipdev6.hwaddr_len = 6;
|
||||||
|
lwipdev6.linkoutput = lwip_eth_tx;
|
||||||
|
lwipdev6.ip6_autoconfig_enabled = 1;
|
||||||
|
|
||||||
|
mac.copyTo(lwipdev6.hwaddr, lwipdev6.hwaddr_len);
|
||||||
|
netif_add(&lwipdev6, NULL, tapif_init, ethernet_input);
|
||||||
|
lwipdev6.output_ip6 = ethip6_output;
|
||||||
|
lwipdev6.state = tapref;
|
||||||
|
|
||||||
|
netif_create_ip6_linklocal_address(&lwipdev6, 1);
|
||||||
|
s8_t idx = 1;
|
||||||
|
netif_add_ip6_address(&lwipdev6, &ipaddr, &idx);
|
||||||
|
netif_set_default(&lwipdev6);
|
||||||
|
netif_set_up(&lwipdev6);
|
||||||
|
netif_set_link_up(&lwipdev6);
|
||||||
|
netif_ip6_addr_set_state(&lwipdev6, 1, IP6_ADDR_TENTATIVE);
|
||||||
|
|
||||||
|
char macbuf[ZT_MAC_ADDRSTRLEN];
|
||||||
|
mac2str(macbuf, ZT_MAC_ADDRSTRLEN, lwipdev6.hwaddr);
|
||||||
|
DEBUG_INFO("initialized netif as [mac=%s, addr=%s]", macbuf, ip.toString(ipbuf));
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -295,9 +291,14 @@ void lwip_eth_rx(ZeroTier::VirtualTap *tap, const ZeroTier::MAC &from, const Zer
|
|||||||
// TODO: Routing logic
|
// TODO: Routing logic
|
||||||
|
|
||||||
#if defined(LIBZT_IPV4)
|
#if defined(LIBZT_IPV4)
|
||||||
if (lwipdev.input(p, &(lwipdev)) != ERR_OK) {
|
if (lwipdev.input(p, &lwipdev) != ERR_OK) {
|
||||||
DEBUG_ERROR("error while feeding frame into stack interface (ipv4)");
|
DEBUG_ERROR("error while feeding frame into stack interface (ipv4)");
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
#if defined(LIBZT_IPV6)
|
||||||
|
if (lwipdev6.input(p, &lwipdev6) != ERR_OK) {
|
||||||
|
DEBUG_ERROR("error while feeding frame into stack interface (ipv6)");
|
||||||
|
}
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user