bugfix for ipv6 netif setup

This commit is contained in:
Joseph Henry
2018-07-25 14:01:12 -07:00
parent ac1f0e32ca
commit 7be4edb36d
3 changed files with 77 additions and 38 deletions

View File

@@ -107,8 +107,6 @@ await the next callback from the core */
#define LWIP_MAX_GUARDED_RX_BUF_SZ 1024 // number of frame pointers that can be cached waiting for receipt into core
#define LWIP_FRAMES_HANDLED_PER_CORE_CALL 16 // How many frames are handled per call from core
#define LWIP_NETIF_STATUS_CALLBACK 0
typedef signed char err_t;
#define ND6_DISCOVERY_INTERVAL 1000

View File

@@ -87,9 +87,15 @@
*/
#include "lwip/debug.h"
//#define LWIP_IPV6_MLD 1
//#define LWIP_IPV6_AUTOCONFIG 1
//#define LWIP_ICMP6 1
//#define LWIP_IPV6_NUM_ADDRESSES 6
// IP Protocol version
#define LWIP_IPV4 1
#define LWIP_IPV6 1
#define LWIP_NETIF_STATUS_CALLBACK 1
#define LWIP_IPV4 1
#define LWIP_IPV6 1
// --- DEBUG ---

View File

@@ -140,7 +140,6 @@ void my_tcpip_callback(void *arg)
DEBUG_ERROR("packet input error (ipv6, p=%p, netif=%p)", p, &lwipInterfaces[i]);
break;
}
}
}
} break;
@@ -335,61 +334,97 @@ void lwip_start_dhcp(void *netif)
#endif
}
static void netif_status_callback(struct netif *netif)
{
DEBUG_INFO("n=%p, %c%c, %d, o=%p, o6=%p, mc=%x:%x:%x:%x:%x:%x, hwln=%d, st=%p, flgs=%d\n",
netif,
netif->name[0],
netif->name[1],
netif->mtu,
netif->output,
netif->output_ip6,
netif->hwaddr[0],
netif->hwaddr[1],
netif->hwaddr[2],
netif->hwaddr[3],
netif->hwaddr[4],
netif->hwaddr[5],
netif->hwaddr_len,
netif->state,
netif->flags
);
}
ZeroTier::MAC _mac;
static err_t netif_init_4(struct netif *netif)
{
netif->hwaddr_len = 6;
netif->name[0] = 'e';
netif->name[1] = '0'+lwipInterfacesCount;
netif->linkoutput = lwip_eth_tx;
netif->output = etharp_output;
netif->mtu = ZT_MAX_MTU;
netif->flags = NETIF_FLAG_BROADCAST
| NETIF_FLAG_ETHARP
| NETIF_FLAG_ETHERNET
| NETIF_FLAG_IGMP
| NETIF_FLAG_LINK_UP
| NETIF_FLAG_UP;
_mac.copyTo(netif->hwaddr, netif->hwaddr_len);
netif->hwaddr_len = sizeof(netif->hwaddr);
return ERR_OK;
}
static err_t netif_init_6(struct netif *netif)
{
netif->hwaddr_len = 6;
netif->name[0] = 'e';
netif->name[1] = '0'+lwipInterfacesCount;
netif->linkoutput = lwip_eth_tx;
netif->output = etharp_output;
netif->output_ip6 = ethip6_output;
netif->mtu = ZT_MAX_MTU;
netif->flags = NETIF_FLAG_BROADCAST
| NETIF_FLAG_ETHARP
| NETIF_FLAG_ETHERNET
| NETIF_FLAG_IGMP
| NETIF_FLAG_MLD6;
_mac.copyTo(netif->hwaddr, netif->hwaddr_len);
netif->hwaddr_len = sizeof(netif->hwaddr);
return ERR_OK;
}
void lwip_init_interface(void *tapref, const ZeroTier::MAC &mac, const ZeroTier::InetAddress &ip)
{
char ipbuf[INET6_ADDRSTRLEN], nmbuf[INET6_ADDRSTRLEN];
char macbuf[ZT_MAC_ADDRSTRLEN];
DEBUG_EXTRA("lwipInterfacesCount=%d", lwipInterfacesCount);
struct netif *lwipdev = &lwipInterfaces[lwipInterfacesCount];
DEBUG_EXTRA("netif=%p", lwipdev);
_mac = mac;
if (ip.isV4()) {
static ip4_addr_t ipaddr, netmask, gw;
IP4_ADDR(&gw,127,0,0,1);
ipaddr.addr = *((u32_t *)ip.rawIpData());
netmask.addr = *((u32_t *)ip.netmask().rawIpData());
netif_add(lwipdev, &ipaddr, &netmask, &gw, NULL, tapif_init, tcpip_input);
netif_set_status_callback(lwipdev, netif_status_callback);
netif_add(lwipdev, &ipaddr, &netmask, &gw, NULL, netif_init_4, tcpip_input);
lwipdev->state = tapref;
lwipdev->output = etharp_output;
lwipdev->mtu = ZT_MAX_MTU;
lwipdev->name[0] = 'l';
lwipdev->name[1] = '0'+lwipInterfacesCount;
lwipdev->linkoutput = lwip_eth_tx;
lwipdev->hwaddr_len = 6;
mac.copyTo(lwipdev->hwaddr, lwipdev->hwaddr_len);
lwipdev->flags = 0;
lwipdev->flags = NETIF_FLAG_BROADCAST
| NETIF_FLAG_ETHARP
| NETIF_FLAG_IGMP
| NETIF_FLAG_LINK_UP
| NETIF_FLAG_UP;
netif_set_default(lwipdev);
netif_set_link_up(lwipdev);
netif_set_up(lwipdev);
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));
}
if (ip.isV6()) {
if (ip.isV6())
{
static ip6_addr_t ipaddr;
memcpy(&(ipaddr.addr), ip.rawIpData(), sizeof(ipaddr.addr));
lwipdev->mtu = ZT_MAX_MTU;
lwipdev->name[0] = 'l';
lwipdev->name[1] = '0'+lwipInterfacesCount;
lwipdev->hwaddr_len = 6;
lwipdev->linkoutput = lwip_eth_tx;
lwipdev->ip6_autoconfig_enabled = 1;
mac.copyTo(lwipdev->hwaddr, lwipdev->hwaddr_len);
netif_add(lwipdev, NULL, NULL, NULL, NULL, tapif_init, ethernet_input);
lwipdev->output_ip6 = ethip6_output;
netif_add(lwipdev, NULL, NULL, NULL, NULL, netif_init_6, tcpip_input);
netif_ip6_addr_set(lwipdev, 1, &ipaddr);
lwipdev->state = tapref;
netif_create_ip6_linklocal_address(lwipdev, 1);
s8_t idx = 1;
netif_add_ip6_address(lwipdev, &ipaddr, &idx);
netif_ip6_addr_set_state(lwipdev, 1, IP6_ADDR_TENTATIVE);
netif_set_status_callback(lwipdev, netif_status_callback);
netif_set_default(lwipdev);
netif_set_up(lwipdev);
netif_set_link_up(lwipdev);
netif_ip6_addr_set_state(lwipdev, 1, IP6_ADDR_TENTATIVE);
mac2str(macbuf, ZT_MAC_ADDRSTRLEN, lwipdev->hwaddr);
DEBUG_INFO("initialized netif as [mac=%s, addr=%s]", macbuf, ip.toString(ipbuf));
}