From 285e38822fc7d38eea16e869897d6fd51ed4655e Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 19 Nov 2016 23:46:23 +0100 Subject: [PATCH] switch to LwIP 2.0.0 with dual-stack support (IPv4+IPv6) --- hermit/Makefile | 4 +-- hermit/drivers/net/e1000.c | 10 ++++++- hermit/drivers/net/mmnif.c | 5 +++- hermit/drivers/net/rtl8139.c | 9 +++++- hermit/include/netinet/in.h | 1 - hermit/include/sys/uio.h | 54 ------------------------------------ hermit/kernel/main.c | 47 ++++++++++++------------------- hermit/kernel/syscall.c | 1 - hermit/lwip | 2 +- hermit/usr/Makefile | 1 - 10 files changed, 42 insertions(+), 92 deletions(-) delete mode 100644 hermit/include/sys/uio.h diff --git a/hermit/Makefile b/hermit/Makefile index 122cb6a31..7b3a04e17 100644 --- a/hermit/Makefile +++ b/hermit/Makefile @@ -3,7 +3,7 @@ TOPDIR := $(shell pwd) ARCH = x86 NAME = libhermit.a DRIVERDIRS = drivers/net -LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/netif +LWIPDIRS = lwip/src/arch lwip/src/api lwip/src/core lwip/src/core/ipv4 lwip/src/core/ipv6 lwip/src/netif KERNDIRS = kernel mm libkern arch/$(ARCH)/kernel arch/$(ARCH)/mm $(LWIPDIRS) $(DRIVERDIRS) SUBDIRS = $(KERNDIRS) GIT_VERSION := $(shell git describe --abbrev=6 --dirty --always --tags) @@ -35,7 +35,7 @@ MAKE = make NASM = nasm NASMFLAGS = -felf64 -g -i$(TOPDIR)/include/hermit/ -INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/lwip/src/include/ipv4 -I$(TOPDIR)/drivers +INCLUDE = -I$(TOPDIR)/include -I$(TOPDIR)/arch/$(ARCH)/include -I$(TOPDIR)/lwip/src/include -I$(TOPDIR)/drivers CFLAGS = -DVERSION=\"$(GIT_VERSION)\" -g -m64 -Wall -O2 -mno-red-zone -fno-var-tracking-assignments -fstrength-reduce -fomit-frame-pointer -finline-functions -ffreestanding -nostdinc -fno-stack-protector -mno-sse -mno-mmx -mno-sse2 -mno-3dnow -mno-avx -fno-delete-null-pointer-checks -falign-jumps=1 -falign-loops=1 -mno-80387 -mno-fp-ret-in-387 -mskip-rax-setup -fno-common -Wframe-larger-than=1024 -fno-strict-aliasing -fno-asynchronous-unwind-tables -fno-strict-overflow -maccumulate-outgoing-args $(INCLUDE) AR = ar ARFLAGS = rsv diff --git a/hermit/drivers/net/e1000.c b/hermit/drivers/net/e1000.c index 2ec19526f..8fb4f4b57 100644 --- a/hermit/drivers/net/e1000.c +++ b/hermit/drivers/net/e1000.c @@ -40,6 +40,8 @@ #include #include #include +#include +#include #include #include @@ -562,10 +564,16 @@ err_t e1000if_init(struct netif* netif) /* maximum transfer unit */ netif->mtu = 1500; /* broadcast capability */ - netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP; + netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_LINK_UP | NETIF_FLAG_MLD6; e1000if->ethaddr = (struct eth_addr *)netif->hwaddr; +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; + netif_create_ip6_linklocal_address(netif, 1); + netif->ip6_autoconfig_enabled = 1; +#endif + return ERR_OK; oom: diff --git a/hermit/drivers/net/mmnif.c b/hermit/drivers/net/mmnif.c index fe496bd19..524e2edbd 100644 --- a/hermit/drivers/net/mmnif.c +++ b/hermit/drivers/net/mmnif.c @@ -54,6 +54,7 @@ #include #include /* lwip netif */ +#include #include /* inteface stats */ #include /* ethernet arp packets */ #include /* struct iphdr */ @@ -302,7 +303,7 @@ void mmnif_print_driver_status(void) static uint8_t mmnif_get_destination(struct netif *netif, struct pbuf *p) { struct ip_hdr *iphdr; - ip_addr_p_t ip; + ip4_addr_p_t ip; /* grab the destination ip address out of the ip header * for internal routing the last ocet is interpreted as core ID. @@ -687,6 +688,8 @@ err_t mmnif_init(struct netif *netif) /* broadcast capability, keep all default flags */ //netif->flags |= NETIF_FLAG_BROADCAST; + /* set link up */ + netif->flags |= NETIF_FLAG_LINK_UP; /* hardware address length */ netif->hwaddr_len = 0; diff --git a/hermit/drivers/net/rtl8139.c b/hermit/drivers/net/rtl8139.c index aaa50bb2e..e3e5bd0e0 100644 --- a/hermit/drivers/net/rtl8139.c +++ b/hermit/drivers/net/rtl8139.c @@ -41,6 +41,8 @@ #include #include #include +#include +#include #include #include @@ -481,7 +483,12 @@ err_t rtl8139if_init(struct netif* netif) /* maximum transfer unit */ netif->mtu = 1500; /* broadcast capability */ - netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP; + netif->flags |= NETIF_FLAG_BROADCAST | NETIF_FLAG_ETHARP | NETIF_FLAG_IGMP | NETIF_FLAG_LINK_UP | NETIF_FLAG_MLD6; +#if LWIP_IPV6 + netif->output_ip6 = ethip6_output; + netif_create_ip6_linklocal_address(netif, 1); + netif->ip6_autoconfig_enabled = 1; +#endif return ERR_OK; } diff --git a/hermit/include/netinet/in.h b/hermit/include/netinet/in.h index 0a8eb2663..dbb542a0e 100644 --- a/hermit/include/netinet/in.h +++ b/hermit/include/netinet/in.h @@ -14,7 +14,6 @@ #include #include #include -#include #ifdef __cplusplus { diff --git a/hermit/include/sys/uio.h b/hermit/include/sys/uio.h deleted file mode 100644 index 159d5469a..000000000 --- a/hermit/include/sys/uio.h +++ /dev/null @@ -1,54 +0,0 @@ -/* - * Copyright (c) 2015, Stefan Lankes, RWTH Aachen University - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions are met: - * * Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * * Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * * Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this - * software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE - * DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY - * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES - * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; - * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND - * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS - * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef __SYS_MMAN_H__ -#define __SYS_MMAN_H__ - -/** - * @author Stefan Lankes - * @file include/hermit/uio.h - * @brief Definition of struct iovec - */ - -#include - -#ifdef __cplusplus -extern "C" { -#endif - -/* Structure for scatter/gather I/O. */ -struct iovec -{ - void *iov_base; /* Pointer to data. */ - size_t iov_len; /* Length of data. */ -}; - -#ifdef __cplusplus -} -#endif - -#endif diff --git a/hermit/kernel/main.c b/hermit/kernel/main.c index c512fde6b..2b13d9dde 100644 --- a/hermit/kernel/main.c +++ b/hermit/kernel/main.c @@ -44,12 +44,13 @@ #include #include #include +#include #include #include #include #include #include -#include +#include #include #include #include @@ -61,9 +62,6 @@ #define HERMIT_PORT 0x494E #define HERMIT_MAGIC 0x7E317 -// set to one if the single-kernel version should use a DHCP server -#define USE_DHCP 1 - static struct netif default_netif; static const int sobufsize = 131072; @@ -162,9 +160,9 @@ static void tcpip_init_done(void* arg) static int init_netifs(void) { - struct ip_addr ipaddr; - struct ip_addr netmask; - struct ip_addr gw; + ip_addr_t ipaddr; + ip_addr_t netmask; + ip_addr_t gw; sys_sem_t sem; err_t err; @@ -182,9 +180,9 @@ static int init_netifs(void) if (!is_single_kernel()) { /* Set network address variables */ - IP4_ADDR(&gw, 192,168,28,1); - IP4_ADDR(&ipaddr, 192,168,28,isle+2); - IP4_ADDR(&netmask, 255,255,255,0); + IP_ADDR4(&gw, 192,168,28,1); + IP_ADDR4(&ipaddr, 192,168,28,isle+2); + IP_ADDR4(&netmask, 255,255,255,0); /* register our Memory Mapped Virtual IP interface in the lwip stack * and tell him how to use the interface: @@ -195,13 +193,13 @@ static int init_netifs(void) * - ip_input : tells him that he should use ip_input */ #if LWIP_TCPIP_CORE_LOCKING_INPUT - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, mmnif_init, ip_input)) != ERR_OK) + if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, mmnif_init, ip_input)) != ERR_OK) #else /* * Note: Our drivers guarantee that the input function will be called in the context of the tcpip thread. * => Therefore, we are able to use ip_input instead of tcpip_input */ - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, mmnif_init, ip_input)) != ERR_OK) + if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, mmnif_init, ip_input)) != ERR_OK) #endif { LOG_ERROR("Unable to add the intra network interface: err = %d\n", err); @@ -212,22 +210,16 @@ static int init_netifs(void) netifapi_netif_set_default(&default_netif); netifapi_netif_set_up(&default_netif); } else { -#if USE_DHCP /* Clear network address because we use DHCP to get an ip address */ - IP4_ADDR(&gw, 0,0,0,0); - IP4_ADDR(&ipaddr, 0,0,0,0); - IP4_ADDR(&netmask, 0,0,0,0); -#else - IP4_ADDR(&gw, 10,0,2,2); - IP4_ADDR(&ipaddr, 10,0,2,15); - IP4_ADDR(&netmask, 255,255,255,0); -#endif + IP_ADDR4(&gw, 0,0,0,0); + IP_ADDR4(&ipaddr, 0,0,0,0); + IP_ADDR4(&netmask, 0,0,0,0); /* Note: Our drivers guarantee that the input function will be called in the context of the tcpip thread. * => Therefore, we are able to use ethernet_input instead of tcpip_input */ - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, rtl8139if_init, ethernet_input)) == ERR_OK) + if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, rtl8139if_init, ethernet_input)) == ERR_OK) goto success; - if ((err = netifapi_netif_add(&default_netif, &ipaddr, &netmask, &gw, NULL, e1000if_init, ethernet_input)) == ERR_OK) + if ((err = netifapi_netif_add(&default_netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, e1000if_init, ethernet_input)) == ERR_OK) goto success; LOG_ERROR("Unable to add the network interface: err = %d\n", err); @@ -236,19 +228,19 @@ static int init_netifs(void) success: netifapi_netif_set_default(&default_netif); + netifapi_netif_set_up(&default_netif); -#if USE_DHCP LOG_INFO("Starting DHCPD...\n"); netifapi_dhcp_start(&default_netif); int mscnt = 0; /* wait for ip address */ - while(!default_netif.ip_addr.addr) { + while(!ip_2_ip4(&default_netif.ip_addr)->addr) { uint64_t end_tsc, start_tsc = rdtsc(); #if 1 do { - if (default_netif.ip_addr.addr) + if (ip_2_ip4(&default_netif.ip_addr)->addr) return 0; check_workqueues(); end_tsc = rdtsc(); @@ -264,9 +256,6 @@ success: mscnt = 0; } } -#else - netifapi_netif_set_up(&default_netif); -#endif } return 0; diff --git a/hermit/kernel/syscall.c b/hermit/kernel/syscall.c index db4d15513..f738cb264 100644 --- a/hermit/kernel/syscall.c +++ b/hermit/kernel/syscall.c @@ -37,7 +37,6 @@ #include #include #include -#include #include #include diff --git a/hermit/lwip b/hermit/lwip index b20b9a2c2..6d1ec9cc7 160000 --- a/hermit/lwip +++ b/hermit/lwip @@ -1 +1 @@ -Subproject commit b20b9a2c2532c0713122053ce57f2970c538ca1a +Subproject commit 6d1ec9cc709892e9a30461b85df2161f556e4af6 diff --git a/hermit/usr/Makefile b/hermit/usr/Makefile index baea65b07..2b240b166 100644 --- a/hermit/usr/Makefile +++ b/hermit/usr/Makefile @@ -81,7 +81,6 @@ headers: $Q$(CP) -R ../lwip/src/include/posix/* $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/ $Q$(CP) -R ../lwip/src/include/arch $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/ $Q$(CP) -R ../lwip/src/include/lwip* $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/ - $Q$(CP) -R ../lwip/src/include/ipv4/lwip/* $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/lwip/ $Q$(CP) -R ../include/neti* $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/ $Q$(CP) -R ../include/sys $(TOPDIR)/$(ARCH)/$(CROSSCOMPREFIX)/include/