From 5d547e26e58ab03d4d2e6642e9b61d3c97c83258 Mon Sep 17 00:00:00 2001 From: Dirk Ziegelmeier Date: Mon, 18 Jun 2018 12:32:21 +0200 Subject: [PATCH] Clean up contrib repository - Delete old example applications that were partially unmaintained - Delete unused/untested netifs --- ports/unix/README | 12 - ports/unix/lib/Makefile | 52 --- ports/unix/lib/README | 31 -- ports/unix/lib/lwipopts.h | 440 --------------------- ports/unix/lib/unixlib.c | 97 ----- ports/unix/minimal/Makefile | 48 --- ports/unix/minimal/README | 12 - ports/unix/minimal/lwipopts.h | 462 ---------------------- ports/unix/minimal/main.c | 224 ----------- ports/unix/port/include/netif/delif.h | 42 -- ports/unix/port/include/netif/dropif.h | 41 -- ports/unix/port/include/netif/tcpdump.h | 41 -- ports/unix/port/include/netif/tunif.h | 41 -- ports/unix/port/include/netif/unixif.h | 40 -- ports/unix/port/netif/delif.c | 384 ------------------ ports/unix/port/netif/pcapif.c | 9 - ports/unix/port/netif/tapif.c | 4 - ports/unix/port/netif/tcpdump.c | 216 ---------- ports/unix/port/netif/tunif.c | 318 --------------- ports/unix/port/netif/unixif.c | 501 ------------------------ ports/unix/unixsim/CMakeLists.txt | 36 -- ports/unix/unixsim/Makefile | 59 --- ports/unix/unixsim/README | 61 --- ports/unix/unixsim/lwip_hooks.h | 49 --- ports/unix/unixsim/lwipopts.h | 401 ------------------- ports/unix/unixsim/simhost.c | 356 ----------------- ports/unix/unixsim/simnode.c | 167 -------- ports/unix/unixsim/simrouter.c | 187 --------- 28 files changed, 4331 deletions(-) delete mode 100644 ports/unix/lib/Makefile delete mode 100644 ports/unix/lib/README delete mode 100644 ports/unix/lib/lwipopts.h delete mode 100644 ports/unix/lib/unixlib.c delete mode 100644 ports/unix/minimal/Makefile delete mode 100644 ports/unix/minimal/README delete mode 100644 ports/unix/minimal/lwipopts.h delete mode 100644 ports/unix/minimal/main.c delete mode 100644 ports/unix/port/include/netif/delif.h delete mode 100644 ports/unix/port/include/netif/dropif.h delete mode 100644 ports/unix/port/include/netif/tcpdump.h delete mode 100644 ports/unix/port/include/netif/tunif.h delete mode 100644 ports/unix/port/include/netif/unixif.h delete mode 100644 ports/unix/port/netif/delif.c delete mode 100644 ports/unix/port/netif/tcpdump.c delete mode 100644 ports/unix/port/netif/tunif.c delete mode 100644 ports/unix/port/netif/unixif.c delete mode 100644 ports/unix/unixsim/CMakeLists.txt delete mode 100644 ports/unix/unixsim/Makefile delete mode 100644 ports/unix/unixsim/README delete mode 100644 ports/unix/unixsim/lwip_hooks.h delete mode 100644 ports/unix/unixsim/lwipopts.h delete mode 100644 ports/unix/unixsim/simhost.c delete mode 100644 ports/unix/unixsim/simnode.c delete mode 100644 ports/unix/unixsim/simrouter.c diff --git a/ports/unix/README b/ports/unix/README index 695d1ca..45d256d 100644 --- a/ports/unix/README +++ b/ports/unix/README @@ -12,9 +12,6 @@ testing lwIP applications. their helpers, some explicitly for Unix infrastructure, some generic (but most useful on an easy to debug system): - * delif: Network interface that inserts delay before receiving or sending - packages - * fifo: Helper for sio * list: Helper for unixif @@ -26,12 +23,3 @@ testing lwIP applications. * tapif: Network interface that is mapped to a tap interface (Unix user space layer 2 network device). Uses lwIP threads. - - * tcpdump: Utility functions to dump pbufs into a tcpdump formatted log - file - - * tunif: Network interface that is mapped to a tun interface (Unix user - space layer 3 network device). Uses lwIP threads. - - * unixif: Network interface that allows lwIP Unix programs to "meet" at Unix - socket address and exchange traffic over it. diff --git a/ports/unix/lib/Makefile b/ports/unix/lib/Makefile deleted file mode 100644 index a07b8f2..0000000 --- a/ports/unix/lib/Makefile +++ /dev/null @@ -1,52 +0,0 @@ -# -# Copyright (c) 2001, 2002 Swedish Institute of Computer Science. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# 2. 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. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. -# -# This file is part of the lwIP TCP/IP stack. -# -# Author: Adam Dunkels -# - -UNIXLIB=liblwip.a - -all: $(UNIXLIB) -.PHONY: all - -include ../Common.mk - -CFLAGS+=-fPIC - -clean: - rm -f *.o $(LWIPLIBCOMMON) *.s .depend* *.core core - -depend dep: .depend - -include .depend - -$(UNIXLIB): $(LWIPLIBCOMMON) unixlib.o - $(CC) -g -nostartfiles -shared -o $@ $^ - -.depend: unixlib.c $(LWIPFILES) - $(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend diff --git a/ports/unix/lib/README b/ports/unix/lib/README deleted file mode 100644 index cd6cc7b..0000000 --- a/ports/unix/lib/README +++ /dev/null @@ -1,31 +0,0 @@ -This directory contains an example of how to compile lwIP as a self -initialising shared library on Linux. - -Some brief instructions: - -* Compile the code: - - > make clean all - - This should produce liblwip4unixlib.so. This is the shared library. - -* Link an application against the shared library - - If you're using gcc you can do this by including -llwip4unixlib in -your link command. - -* Run your application - - Ensure that LD_LIBRARY_PATH includes the directory that contains -liblwip4unixlib.so (ie. this directory) - - - -If you are unsure about shared libraries and libraries on linux in -general, you might find this HOWTO useful: - - - - - -Kieran Mansley, October 2002. \ No newline at end of file diff --git a/ports/unix/lib/lwipopts.h b/ports/unix/lib/lwipopts.h deleted file mode 100644 index 5bd79f9..0000000 --- a/ports/unix/lib/lwipopts.h +++ /dev/null @@ -1,440 +0,0 @@ -/** - * @file - * - * lwIP Options Configuration - */ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_LWIPOPTS_H -#define LWIP_LWIPOPTS_H - -/* - * Include user defined options first. Anything not defined in these files - * will be set to standard values. Override anything you dont like! - */ -#include "lwipopts.h" -#include "lwip/debug.h" - -/* - ----------------------------------------------- - ---------- Platform specific locking ---------- - ----------------------------------------------- -*/ - -/** - * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain - * critical regions during buffer allocation, deallocation and memory - * allocation and deallocation. - */ -#define SYS_LIGHTWEIGHT_PROT 0 - -/** - * NO_SYS==1: Provides VERY minimal functionality. Otherwise, - * use lwIP facilities. - */ -#define NO_SYS 0 - -/* - ------------------------------------ - ---------- Memory options ---------- - ------------------------------------ -*/ - -/** - * MEM_ALIGNMENT: should be set to the alignment of the CPU - * 4 byte alignment -> #define MEM_ALIGNMENT 4 - * 2 byte alignment -> #define MEM_ALIGNMENT 2 - */ -#define MEM_ALIGNMENT 1U - -/** - * MEM_SIZE: the size of the heap memory. If the application will send - * a lot of data that needs to be copied, this should be set high. - */ -#define MEM_SIZE 1600 - -/* - ------------------------------------------------ - ---------- Internal Memory Pool Sizes ---------- - ------------------------------------------------ -*/ -/** - * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). - * If the application sends a lot of data out of ROM (or other static memory), - * this should be set high. - */ -#define MEMP_NUM_PBUF 16 - -/** - * MEMP_NUM_RAW_PCB: Number of raw connection PCBs - * (requires the LWIP_RAW option) - */ -#define MEMP_NUM_RAW_PCB 4 - -/** - * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One - * per active UDP "connection". - * (requires the LWIP_UDP option) - */ -#define MEMP_NUM_UDP_PCB 4 - -/** - * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB 4 - -/** - * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB_LISTEN 4 - -/** - * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_SEG 16 - -/** - * MEMP_NUM_REASSDATA: the number of simultaneously IP packets queued for - * reassembly (whole packets, not fragments!) - */ -#define MEMP_NUM_REASSDATA 1 - -/** - * MEMP_NUM_ARP_QUEUE: the number of simulateously queued outgoing - * packets (pbufs) that are waiting for an ARP request (to resolve - * their destination address) to finish. - * (requires the ARP_QUEUEING option) - */ -#define MEMP_NUM_ARP_QUEUE 2 - -/** - * MEMP_NUM_SYS_TIMEOUT: the number of simulateously active timeouts. - * (requires NO_SYS==0) - */ -#define MEMP_NUM_SYS_TIMEOUT 3 - -/** - * MEMP_NUM_NETBUF: the number of struct netbufs. - * (only needed if you use the sequential API, like api_lib.c) - */ -#define MEMP_NUM_NETBUF 2 - -/** - * MEMP_NUM_NETCONN: the number of struct netconns. - * (only needed if you use the sequential API, like api_lib.c) - */ -#define MEMP_NUM_NETCONN 4 - -/** - * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used - * for callback/timeout API communication. - * (only needed if you use tcpip.c) - */ -#define MEMP_NUM_TCPIP_MSG_API 8 - -/** - * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. - * (only needed if you use tcpip.c) - */ -#define MEMP_NUM_TCPIP_MSG_INPKT 8 - -/** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. - */ -#define PBUF_POOL_SIZE 8 - -/* - --------------------------------- - ---------- ARP options ---------- - --------------------------------- -*/ -/** - * LWIP_ARP==1: Enable ARP functionality. - */ -#define LWIP_ARP 1 - -/* - -------------------------------- - ---------- IP options ---------- - -------------------------------- -*/ -/** - * IP_FORWARD==1: Enables the ability to forward IP packets across network - * interfaces. If you are going to run lwIP on a device with only one network - * interface, define this to 0. - */ -#define IP_FORWARD 0 - -/** - * IP_OPTIONS: Defines the behavior for IP options. - * IP_OPTIONS_ALLOWED==0: All packets with IP options are dropped. - * IP_OPTIONS_ALLOWED==1: IP options are allowed (but not parsed). - */ -#define IP_OPTIONS_ALLOWED 1 - -/** - * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that - * this option does not affect outgoing packet sizes, which can be controlled - * via IP_FRAG. - */ -#define IP_REASSEMBLY 1 - -/** - * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note - * that this option does not affect incoming packet sizes, which can be - * controlled via IP_REASSEMBLY. - */ -#define IP_FRAG 1 - -/** - * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) - * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived - * in this time, the whole packet is discarded. - */ -#define IP_REASS_MAXAGE 3 - -/** - * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. - * Since the received pbufs are enqueued, be sure to configure - * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive - * packets even if the maximum amount of fragments is enqueued for reassembly! - */ -#define IP_REASS_MAX_PBUFS 4 - -/** - * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP - * fragmentation. Otherwise pbufs are allocated and reference the original - * packet data to be fragmented. -*/ -#define IP_FRAG_USES_STATIC_BUF 0 - -/** - * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. - */ -#define IP_DEFAULT_TTL 255 - -/* - ---------------------------------- - ---------- ICMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_ICMP==1: Enable ICMP module inside the IP stack. - * Be careful, disable that make your product non-compliant to RFC1122 - */ -#define LWIP_ICMP 1 - -/* - --------------------------------- - ---------- RAW options ---------- - --------------------------------- -*/ -/** - * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. - */ -#define LWIP_RAW 1 - -/* - ---------------------------------- - ---------- DHCP options ---------- - ---------------------------------- -*/ -/** - * LWIP_DHCP==1: Enable DHCP module. - */ -#define LWIP_DHCP 0 - - -/* - ------------------------------------ - ---------- AUTOIP options ---------- - ------------------------------------ -*/ -/** - * LWIP_AUTOIP==1: Enable AUTOIP module. - */ -#define LWIP_AUTOIP 0 - -/* - ---------------------------------- - ---------- SNMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_SNMP==1: Turn on SNMP module. UDP must be available for SNMP - * transport. - */ -#define LWIP_SNMP 0 - -/* - ---------------------------------- - ---------- IGMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_IGMP==1: Turn on IGMP module. - */ -#define LWIP_IGMP 0 - -/* - ---------------------------------- - ---------- DNS options ----------- - ---------------------------------- -*/ -/** - * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS - * transport. - */ -#define LWIP_DNS 0 - -/* - --------------------------------- - ---------- UDP options ---------- - --------------------------------- -*/ -/** - * LWIP_UDP==1: Turn on UDP. - */ -#define LWIP_UDP 1 - -/* - --------------------------------- - ---------- TCP options ---------- - --------------------------------- -*/ -/** - * LWIP_TCP==1: Turn on TCP. - */ -#define LWIP_TCP 1 - -#define LWIP_LISTEN_BACKLOG 0 - -/* - ---------------------------------- - ---------- Pbuf options ---------- - ---------------------------------- -*/ -/** - * PBUF_LINK_HLEN: the number of bytes that should be allocated for a - * link level header. The default is 14, the standard value for - * Ethernet. - */ -#define PBUF_LINK_HLEN 16 - -/** - * PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. The default is - * designed to accomodate single full size TCP frame in one pbuf, including - * TCP_MSS, IP header, and link header. -* - */ -#define PBUF_POOL_BUFSIZE LWIP_MEM_ALIGN_SIZE(TCP_MSS+40+PBUF_LINK_HLEN) - -/* - ------------------------------------ - ---------- LOOPIF options ---------- - ------------------------------------ -*/ -/** - * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c - */ -#define LWIP_HAVE_LOOPIF 0 - -/* - ---------------------------------------------- - ---------- Sequential layer options ---------- - ---------------------------------------------- -*/ - -/** - * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) - */ -#define LWIP_NETCONN 1 - -/* - ------------------------------------ - ---------- Socket options ---------- - ------------------------------------ -*/ -/** - * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) - */ -#define LWIP_SOCKET 1 - -/* - ---------------------------------------- - ---------- Statistics options ---------- - ---------------------------------------- -*/ -/** - * LWIP_STATS==1: Enable statistics collection in lwip_stats. - */ -#define LWIP_STATS 0 -/* - --------------------------------- - ---------- PPP options ---------- - --------------------------------- -*/ -/** - * PPP_SUPPORT==1: Enable PPP. - */ -#define PPP_SUPPORT 0 - - - -/* - --------------------------------------- - ---------- Threading options ---------- - --------------------------------------- -*/ - -#define LWIP_TCPIP_CORE_LOCKING 1 - -#if !NO_SYS -void sys_check_core_locking(void); -#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking() -void sys_mark_tcpip_thread(void); -#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread() - -#if LWIP_TCPIP_CORE_LOCKING -void sys_lock_tcpip_core(void); -#define LOCK_TCPIP_CORE() sys_lock_tcpip_core() -void sys_unlock_tcpip_core(void); -#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core() -#endif -#endif - -#endif /* LWIP_LWIPOPTS_H */ diff --git a/ports/unix/lib/unixlib.c b/ports/unix/lib/unixlib.c deleted file mode 100644 index a3d7e7f..0000000 --- a/ports/unix/lib/unixlib.c +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * Author: Kieran Mansley - * - * $Id: unixlib.c,v 1.10 2010/02/17 16:52:30 goldsimon Exp $ - */ - -/*-----------------------------------------------------------------------------------*/ -/* unixlib.c - * - * The initialisation functions for a shared library - * - * You may need to configure this file to your own needs - it is only an example - * of how lwIP can be used as a self initialising shared library. - * - * In particular, you should change the gateway, ipaddr, and netmask to be the values - * you would like the stack to use. - */ -/*-----------------------------------------------------------------------------------*/ -#include "lwip/init.h" -#include "lwip/sys.h" -#include "lwip/mem.h" -#include "lwip/memp.h" -#include "lwip/pbuf.h" -#include "lwip/tcp.h" -#include "lwip/tcpip.h" -#include "lwip/netif.h" -#include "lwip/stats.h" -#include "lwip/sockets.h" - -#include "netif/tapif.h" - -struct netif netif; - -void _init(void); -void _fini(void); - -static void -tcpip_init_done(void *arg) -{ - ip_addr_t ipaddr, netmask, gateway; - sys_sem_t *sem; - sem = (sys_sem_t *)arg; - - /* - CHANGE THESE to suit your own network configuration: - */ - IP4_ADDR(&gateway, 192,168,1,1); - IP4_ADDR(&ipaddr, 192,168,1,2); - IP4_ADDR(&netmask, 255,255,255,0); - - netif_set_default(netif_add(&netif, &ipaddr, &netmask, &gateway, NULL, tapif_init, - tcpip_input)); - netif_set_up(&netif); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif, 1); -#endif - sys_sem_signal(sem); -} - -void _init(void){ - sys_sem_t sem; - - if(sys_sem_new(&sem, 0) != ERR_OK) { - LWIP_ASSERT("failed to create semaphore", 0); - } - tcpip_init(tcpip_init_done, &sem); - sys_sem_wait(&sem); - sys_sem_free(&sem); -} - -void _fini(void){ -} diff --git a/ports/unix/minimal/Makefile b/ports/unix/minimal/Makefile deleted file mode 100644 index 7385fb1..0000000 --- a/ports/unix/minimal/Makefile +++ /dev/null @@ -1,48 +0,0 @@ -# -# Copyright (c) 2001, 2002 Swedish Institute of Computer Science. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# 2. 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. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. -# -# This file is part of the lwIP TCP/IP stack. -# -# Author: Adam Dunkels -# - -all ipv4 compile: echop -.PHONY: all - -include ../Common.mk - -clean: - rm -f *.o $(LWIPLIBCOMMON) $(APPLIB) echop .depend* *.core core - -depend dep: .depend - -include .depend - -.depend: main.c $(LWIPFILES) $(APPFILES) - $(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend - -echop: .depend $(LWIPLIBCOMMON) $(APPLIB) main.o $(APPFILES) - $(CC) $(CFLAGS) -o echop main.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS) diff --git a/ports/unix/minimal/README b/ports/unix/minimal/README deleted file mode 100644 index 81d7d47..0000000 --- a/ports/unix/minimal/README +++ /dev/null @@ -1,12 +0,0 @@ -This is an example of a very minimal lwIP project. It runs in a single -thread and runs a single example application - an echo server. The -echo application is implemented using the raw API. Additionally this -raw API example hosts the SNMPv1 agent for development purposes. - -In order to run the demo without root priviledges, you can create a -preconfigured tap device in advance and then run the application with the -interface passed in via an environment variable: - -$ sudo ip tuntap add dev tap0 mode tap user YOUR-USER-NAME -$ sudo ip a a dev tap0 192.168.0.1/24 -$ PRECONFIGURED_TAPIF=tap0 ./echop diff --git a/ports/unix/minimal/lwipopts.h b/ports/unix/minimal/lwipopts.h deleted file mode 100644 index e83dd47..0000000 --- a/ports/unix/minimal/lwipopts.h +++ /dev/null @@ -1,462 +0,0 @@ -/** - * @file - * - * lwIP Options Configuration - */ - -/* - * Copyright (c) 2001-2004 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_LWIPOPTS_H -#define LWIP_LWIPOPTS_H - -/* - ----------------------------------------------- - ---------- Platform specific locking ---------- - ----------------------------------------------- -*/ - -/** - * NO_SYS==1: Provides VERY minimal functionality. Otherwise, - * use lwIP facilities. - */ -#define NO_SYS 1 - -/** - * SYS_LIGHTWEIGHT_PROT==1: if you want inter-task protection for certain - * critical regions during buffer allocation, deallocation and memory - * allocation and deallocation. - */ -#define SYS_LIGHTWEIGHT_PROT 0 - -/* - ------------------------------------ - ---------- Memory options ---------- - ------------------------------------ -*/ -/** - * MEM_ALIGNMENT: should be set to the alignment of the CPU - * 4 byte alignment -> #define MEM_ALIGNMENT 4 - * 2 byte alignment -> #define MEM_ALIGNMENT 2 - */ -#define MEM_ALIGNMENT 1U - -/** - * MEM_SIZE: the size of the heap memory. If the application will send - * a lot of data that needs to be copied, this should be set high. - */ -#define MEM_SIZE 16000 - - -/* - ------------------------------------------------ - ---------- Internal Memory Pool Sizes ---------- - ------------------------------------------------ -*/ -/** - * MEMP_NUM_PBUF: the number of memp struct pbufs (used for PBUF_ROM and PBUF_REF). - * If the application sends a lot of data out of ROM (or other static memory), - * this should be set high. - */ -#define MEMP_NUM_PBUF 30 - -/** - * MEMP_NUM_RAW_PCB: Number of raw connection PCBs - * (requires the LWIP_RAW option) - */ -#define MEMP_NUM_RAW_PCB 4 - -/** - * MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One - * per active UDP "connection". - * (requires the LWIP_UDP option) - */ -#define MEMP_NUM_UDP_PCB 4 - -/** - * MEMP_NUM_TCP_PCB: the number of simulatenously active TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB 2 - -/** - * MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP connections. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_PCB_LISTEN 8 - -/** - * MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP segments. - * (requires the LWIP_TCP option) - */ -#define MEMP_NUM_TCP_SEG 16 - -/** - * MEMP_NUM_ARP_QUEUE: the number of simulateously queued outgoing - * packets (pbufs) that are waiting for an ARP request (to resolve - * their destination address) to finish. - * (requires the ARP_QUEUEING option) - */ -#define MEMP_NUM_ARP_QUEUE 2 - -/** - * MEMP_NUM_SYS_TIMEOUT: the number of simultaneously active timeouts. - * The default number of timeouts is calculated here for all enabled modules. - * The formula expects settings to be either '0' or '1'. - * - * To this default value, 1 was added for the snmp_increment timer. - */ -#define MEMP_NUM_SYS_TIMEOUT (LWIP_TCP + IP_REASSEMBLY + LWIP_ARP + (2*LWIP_DHCP) + LWIP_AUTOIP + LWIP_IGMP + LWIP_DNS + PPP_SUPPORT + (LWIP_IPV6 ? (1 + LWIP_IPV6_REASS + LWIP_IPV6_MLD) : 0)) + 1 - -/** - * MEMP_NUM_NETBUF: the number of struct netbufs. - * (only needed if you use the sequential API, like api_lib.c) - */ -#define MEMP_NUM_NETBUF 0 - -/** - * MEMP_NUM_NETCONN: the number of struct netconns. - * (only needed if you use the sequential API, like api_lib.c) - */ -#define MEMP_NUM_NETCONN 0 - -/** - * MEMP_NUM_TCPIP_MSG_API: the number of struct tcpip_msg, which are used - * for callback/timeout API communication. - * (only needed if you use tcpip.c) - */ -#define MEMP_NUM_TCPIP_MSG_API 0 - -/** - * MEMP_NUM_TCPIP_MSG_INPKT: the number of struct tcpip_msg, which are used - * for incoming packets. - * (only needed if you use tcpip.c) - */ -#define MEMP_NUM_TCPIP_MSG_INPKT 0 - -/** - * PBUF_POOL_SIZE: the number of buffers in the pbuf pool. - */ -#define PBUF_POOL_SIZE 32 - -/* - --------------------------------- - ---------- ARP options ---------- - --------------------------------- -*/ -/** - * LWIP_ARP==1: Enable ARP functionality. - */ -#define LWIP_ARP 1 - -/* - -------------------------------- - ---------- IP options ---------- - -------------------------------- -*/ -/** - * IP_FORWARD==1: Enables the ability to forward IP packets across network - * interfaces. If you are going to run lwIP on a device with only one network - * interface, define this to 0. - */ -#define IP_FORWARD 0 - -/** - * IP_OPTIONS: Defines the behavior for IP options. - * IP_OPTIONS==0_ALLOWED: All packets with IP options are dropped. - * IP_OPTIONS==1_ALLOWED: IP options are allowed (but not parsed). - */ -#define IP_OPTIONS_ALLOWED 1 - -/** - * IP_REASSEMBLY==1: Reassemble incoming fragmented IP packets. Note that - * this option does not affect outgoing packet sizes, which can be controlled - * via IP_FRAG. - */ -#define IP_REASSEMBLY 1 - -/** - * IP_FRAG==1: Fragment outgoing IP packets if their size exceeds MTU. Note - * that this option does not affect incoming packet sizes, which can be - * controlled via IP_REASSEMBLY. - */ -#define IP_FRAG 1 - -/** - * IP_REASS_MAXAGE: Maximum time (in multiples of IP_TMR_INTERVAL - so seconds, normally) - * a fragmented IP packet waits for all fragments to arrive. If not all fragments arrived - * in this time, the whole packet is discarded. - */ -#define IP_REASS_MAXAGE 3 - -/** - * IP_REASS_MAX_PBUFS: Total maximum amount of pbufs waiting to be reassembled. - * Since the received pbufs are enqueued, be sure to configure - * PBUF_POOL_SIZE > IP_REASS_MAX_PBUFS so that the stack is still able to receive - * packets even if the maximum amount of fragments is enqueued for reassembly! - */ -#define IP_REASS_MAX_PBUFS 10 - -/** - * IP_FRAG_USES_STATIC_BUF==1: Use a static MTU-sized buffer for IP - * fragmentation. Otherwise pbufs are allocated and reference the original - * packet data to be fragmented. - */ -#define IP_FRAG_USES_STATIC_BUF 0 - -/** - * IP_DEFAULT_TTL: Default value for Time-To-Live used by transport layers. - */ -#define IP_DEFAULT_TTL 255 - -/* - ---------------------------------- - ---------- ICMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_ICMP==1: Enable ICMP module inside the IP stack. - * Be careful, disable that make your product non-compliant to RFC1122 - */ -#define LWIP_ICMP 1 - -/** - * ICMP_TTL: Default value for Time-To-Live used by ICMP packets. - */ -#define ICMP_TTL (IP_DEFAULT_TTL) - -/* - --------------------------------- - ---------- RAW options ---------- - --------------------------------- -*/ -/** - * LWIP_RAW==1: Enable application layer to hook into the IP layer itself. - */ -#define LWIP_RAW 0 - -/* - ---------------------------------- - ---------- DHCP options ---------- - ---------------------------------- -*/ -/** - * LWIP_DHCP==1: Enable DHCP module. - */ -#define LWIP_DHCP 0 - -/* - ------------------------------------ - ---------- AUTOIP options ---------- - ------------------------------------ -*/ -/** - * LWIP_AUTOIP==1: Enable AUTOIP module. - */ -#define LWIP_AUTOIP 0 - -/* - ---------------------------------- - ---------- SNMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_SNMP==1: Turn on SNMP module. UDP must be available for SNMP - * transport. - */ -#define LWIP_SNMP 1 -#define LWIP_MIB2_CALLBACKS 0 -#define MIB2_STATS 1 - -/* - ---------------------------------- - ---------- IGMP options ---------- - ---------------------------------- -*/ -/** - * LWIP_IGMP==1: Turn on IGMP module. - */ -#define LWIP_IGMP 0 - -/* - ---------------------------------- - ---------- DNS options ----------- - ---------------------------------- -*/ -/** - * LWIP_DNS==1: Turn on DNS module. UDP must be available for DNS - * transport. - */ -#define LWIP_DNS 0 - -/* - --------------------------------- - ---------- UDP options ---------- - --------------------------------- -*/ -/** - * LWIP_UDP==1: Turn on UDP. - */ -#define LWIP_UDP 1 - -/** - * LWIP_UDPLITE==1: Turn on UDP-Lite. (Requires LWIP_UDP) - */ -#define LWIP_UDPLITE 0 - -/** - * UDP_TTL: Default Time-To-Live value. - */ -#define UDP_TTL (IP_DEFAULT_TTL) - -/* - --------------------------------- - ---------- TCP options ---------- - --------------------------------- -*/ -/** - * LWIP_TCP==1: Turn on TCP. - */ -#define LWIP_TCP 1 - -/* - ---------------------------------- - ---------- Pbuf options ---------- - ---------------------------------- -*/ -/** - * PBUF_LINK_HLEN: the number of bytes that should be allocated for a - * link level header. The default is 14, the standard value for - * Ethernet. - */ -#define PBUF_LINK_HLEN 16 - -/* - ------------------------------------ - ---------- LOOPIF options ---------- - ------------------------------------ -*/ -/** - * LWIP_HAVE_LOOPIF==1: Support loop interface (127.0.0.1) and loopif.c - */ -#define LWIP_HAVE_LOOPIF 0 - - -/* - ---------------------------------------------- - ---------- Sequential layer options ---------- - ---------------------------------------------- -*/ - -/** - * LWIP_NETCONN==1: Enable Netconn API (require to use api_lib.c) - */ -#define LWIP_NETCONN 0 - -/* - ------------------------------------ - ---------- Socket options ---------- - ------------------------------------ -*/ -/** - * LWIP_SOCKET==1: Enable Socket API (require to use sockets.c) - */ -#define LWIP_SOCKET 0 - -/* - ---------------------------------------- - ---------- Statistics options ---------- - ---------------------------------------- -*/ -/** - * LWIP_STATS==1: Enable statistics collection in lwip_stats. - */ -#define LWIP_STATS 1 - -/* - --------------------------------------- - ---------- Debugging options ---------- - --------------------------------------- -*/ - -#define TAPIF_DEBUG LWIP_DBG_ON -#define TUNIF_DEBUG LWIP_DBG_OFF -#define UNIXIF_DEBUG LWIP_DBG_OFF -#define DELIF_DEBUG LWIP_DBG_OFF -#define SIO_FIFO_DEBUG LWIP_DBG_OFF -#define TCPDUMP_DEBUG LWIP_DBG_ON -#define API_LIB_DEBUG LWIP_DBG_ON -#define API_MSG_DEBUG LWIP_DBG_ON -#define TCPIP_DEBUG LWIP_DBG_ON -#define NETIF_DEBUG LWIP_DBG_ON -#define SOCKETS_DEBUG LWIP_DBG_ON -#define DEMO_DEBUG LWIP_DBG_ON -#define IP_DEBUG LWIP_DBG_ON -#define IP_REASS_DEBUG LWIP_DBG_ON -#define RAW_DEBUG LWIP_DBG_ON -#define ICMP_DEBUG LWIP_DBG_ON -#define UDP_DEBUG LWIP_DBG_ON -#define TCP_DEBUG LWIP_DBG_ON -#define TCP_INPUT_DEBUG LWIP_DBG_ON -#define TCP_OUTPUT_DEBUG LWIP_DBG_ON -#define TCP_RTO_DEBUG LWIP_DBG_ON -#define TCP_CWND_DEBUG LWIP_DBG_ON -#define TCP_WND_DEBUG LWIP_DBG_ON -#define TCP_FR_DEBUG LWIP_DBG_ON -#define TCP_QLEN_DEBUG LWIP_DBG_ON -#define TCP_RST_DEBUG LWIP_DBG_ON - -extern unsigned char debug_flags; -#define LWIP_DBG_TYPES_ON debug_flags - -/* - --------------------------------------- - ---------- Threading options ---------- - --------------------------------------- -*/ - -#define LWIP_TCPIP_CORE_LOCKING 1 - -#if !NO_SYS -void sys_check_core_locking(void); -#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking() -void sys_mark_tcpip_thread(void); -#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread() - -#if LWIP_TCPIP_CORE_LOCKING -void sys_lock_tcpip_core(void); -#define LOCK_TCPIP_CORE() sys_lock_tcpip_core() -void sys_unlock_tcpip_core(void); -#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core() -#endif -#endif - -#endif /* LWIP_LWIPOPTS_H */ diff --git a/ports/unix/minimal/main.c b/ports/unix/minimal/main.c deleted file mode 100644 index eb7455e..0000000 --- a/ports/unix/minimal/main.c +++ /dev/null @@ -1,224 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * RT timer modifications by Christiaan Simons - */ - -#include -#include -#include - -#include "lwip/init.h" - -#include "lwip/debug.h" - -#include "lwip/mem.h" -#include "lwip/memp.h" -#include "lwip/sys.h" -#include "lwip/timeouts.h" - -#include "lwip/stats.h" - -#include "lwip/ip.h" -#include "lwip/ip4_frag.h" -#include "lwip/udp.h" -#include "lwip/tcp.h" -#include "netif/tapif.h" -#include "netif/etharp.h" - -#include "lwip/apps/snmp.h" -#include "lwip/apps/snmp_mib2.h" - -#include "examples/snmp/snmp_private_mib/private_mib.h" -#include "apps/udpecho_raw/udpecho_raw.h" -#include "apps/tcpecho_raw/tcpecho_raw.h" - -/* (manual) host IP configuration */ -static ip4_addr_t ipaddr, netmask, gw; - -#if LWIP_SNMP -/* SNMP trap destination cmd option */ -static unsigned char trap_flag; -static ip_addr_t trap_addr; - -static const struct snmp_mib *mibs[] = { - &mib2, - &mib_private -}; -#endif - -/* nonstatic debug cmd option, exported in lwipopts.h */ -unsigned char debug_flags; - -#if LWIP_SNMP -/* enable == 1, disable == 2 */ -u8_t snmpauthentraps_set = 2; -#endif - -static struct option longopts[] = { - /* turn on debugging output (if build with LWIP_DEBUG) */ - {"debug", no_argument, NULL, 'd'}, - /* help */ - {"help", no_argument, NULL, 'h'}, - /* gateway address */ - {"gateway", required_argument, NULL, 'g'}, - /* ip address */ - {"ipaddr", required_argument, NULL, 'i'}, - /* netmask */ - {"netmask", required_argument, NULL, 'm'}, - /* ping destination */ - {"trap_destination", required_argument, NULL, 't'}, - /* new command line options go here! */ - {NULL, 0, NULL, 0} -}; -#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1) - -static void -usage(void) -{ - unsigned char i; - - printf("options:\n"); - for (i = 0; i < NUM_OPTS; i++) { - printf("-%c --%s\n",longopts[i].val, longopts[i].name); - } -} - -int -main(int argc, char **argv) -{ - struct netif netif; - int ch; - char ip_str[16] = {0}, nm_str[16] = {0}, gw_str[16] = {0}; - - /* startup defaults (may be overridden by one or more opts) */ - IP4_ADDR(&gw, 192,168,0,1); - IP4_ADDR(&ipaddr, 192,168,0,2); - IP4_ADDR(&netmask, 255,255,255,0); - -#if LWIP_SNMP - trap_flag = 0; -#endif - /* use debug flags defined by debug.h */ - debug_flags = LWIP_DBG_OFF; - - while ((ch = getopt_long(argc, argv, "dhg:i:m:t:", longopts, NULL)) != -1) { - switch (ch) { - case 'd': - debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT); - break; - case 'h': - usage(); - exit(0); - break; - case 'g': - ip4addr_aton(optarg, &gw); - break; - case 'i': - ip4addr_aton(optarg, &ipaddr); - break; - case 'm': - ip4addr_aton(optarg, &netmask); - break; - case 't': -#if LWIP_SNMP - trap_flag = !0; - /* @todo: remove this authentraps tweak - when we have proper SET & non-volatile mem */ - snmpauthentraps_set = 1; - ipaddr_aton(optarg, &trap_addr); - strncpy(ip_str, ipaddr_ntoa(&trap_addr),sizeof(ip_str)); - printf("SNMP trap destination %s\n", ip_str); -#endif - break; - default: - usage(); - break; - } - } - argc -= optind; - argv += optind; - - strncpy(ip_str, ip4addr_ntoa(&ipaddr), sizeof(ip_str)); - strncpy(nm_str, ip4addr_ntoa(&netmask), sizeof(nm_str)); - strncpy(gw_str, ip4addr_ntoa(&gw), sizeof(gw_str)); - printf("Host at %s mask %s gateway %s\n", ip_str, nm_str, gw_str); - - -#ifdef PERF - perf_init("/tmp/minimal.perf"); -#endif /* PERF */ - - lwip_init(); - - printf("TCP/IP initialized.\n"); - - netif_add(&netif, &ipaddr, &netmask, &gw, NULL, tapif_init, ethernet_input); - netif_set_default(&netif); - netif_set_up(&netif); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif, 1); -#endif - -#if LWIP_SNMP - /* initialize our private example MIB */ - lwip_privmib_init(); - - /* snmp_trap_dst_ip_set(0,&trap_addr); */ - /* snmp_trap_dst_enable(0,trap_flag); */ - -#if SNMP_LWIP_MIB2 -#if SNMP_USE_NETCONN - snmp_threadsync_init(&snmp_mib2_lwip_locks, snmp_mib2_lwip_synchronizer); -#endif - snmp_mib2_set_syscontact_readonly((const u8_t*)"root", NULL); - snmp_mib2_set_syslocation_readonly((const u8_t*)"lwIP development PC", NULL); - snmp_mib2_set_sysdescr((const u8_t*)"minimal example", NULL); -#endif /* SNMP_LWIP_MIB2 */ - - /* snmp_set_snmpenableauthentraps(&snmpauthentraps_set); */ - snmp_set_mibs(mibs, LWIP_ARRAYSIZE(mibs)); - snmp_init(); -#endif /* LWIP_SNMP */ - - udpecho_raw_init(); - tcpecho_raw_init(); - - printf("Applications started.\n"); - - - while (1) { - /* poll netif, pass packet to lwIP */ - tapif_select(&netif); - - sys_check_timeouts(); - } - - return 0; -} diff --git a/ports/unix/port/include/netif/delif.h b/ports/unix/port/include/netif/delif.h deleted file mode 100644 index 6672a73..0000000 --- a/ports/unix/port/include/netif/delif.h +++ /dev/null @@ -1,42 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_DELIF_H -#define LWIP_DELIF_H - -#include "lwip/netif.h" - -#include "lwip/pbuf.h" - -err_t delif_init(struct netif *netif); -err_t delif_init_thread(struct netif *netif); - -#endif /* LWIP_DELIF_H */ diff --git a/ports/unix/port/include/netif/dropif.h b/ports/unix/port/include/netif/dropif.h deleted file mode 100644 index a173b5f..0000000 --- a/ports/unix/port/include/netif/dropif.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_DROPIF_H -#define LWIP_DROPIF_H - -#include "lwip/netif.h" - -#include "lwip/pbuf.h" - -err_t dropif_init(struct netif *netif); - -#endif /* LWIP_DROPIF_H */ diff --git a/ports/unix/port/include/netif/tcpdump.h b/ports/unix/port/include/netif/tcpdump.h deleted file mode 100644 index ecc41d3..0000000 --- a/ports/unix/port/include/netif/tcpdump.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_NETIF_TCPDUMP_H -#define LWIP_NETIF_TCPDUMP_H - -struct pbuf; -struct netif; - -void tcpdump_init(void); -void tcpdump(struct pbuf *p, struct netif *netif); - -#endif /* LWIP_NETIF_TCPDUMP_H */ diff --git a/ports/unix/port/include/netif/tunif.h b/ports/unix/port/include/netif/tunif.h deleted file mode 100644 index b425c06..0000000 --- a/ports/unix/port/include/netif/tunif.h +++ /dev/null @@ -1,41 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_TUNIF_H -#define LWIP_TUNIF_H - -#include "lwip/netif.h" - -#include "lwip/pbuf.h" - -err_t tunif_init(struct netif *netif); - -#endif /* LWIP_TUNIF_H */ diff --git a/ports/unix/port/include/netif/unixif.h b/ports/unix/port/include/netif/unixif.h deleted file mode 100644 index 10b782b..0000000 --- a/ports/unix/port/include/netif/unixif.h +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_UNIXIF_H -#define LWIP_UNIXIF_H - -#include "lwip/netif.h" - -err_t unixif_init_server(struct netif *netif); -err_t unixif_init_client(struct netif *netif); - -#endif /* LWIP_UNIXIF_H */ diff --git a/ports/unix/port/netif/delif.c b/ports/unix/port/netif/delif.c deleted file mode 100644 index 9e35fc1..0000000 --- a/ports/unix/port/netif/delif.c +++ /dev/null @@ -1,384 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include "lwip/opt.h" -#include "lwip/pbuf.h" - -#if !NO_SYS - -#include "lwip/debug.h" - -#include - -#include "lwip/def.h" -#include "netif/delif.h" - -#ifdef LWIP_UNIX_LINUX -#include "netif/tapif.h" -#else /* LWIP_UNIX_LINUX */ -#include "netif/tunif.h" -#endif /* LWIP_UNIX_LINUX */ - -#include "lwip/sys.h" -#include "lwip/timeouts.h" - -#ifndef DELIF_DEBUG -#define DELIF_DEBUG LWIP_DBG_OFF -#endif - -#define DELIF_INPUT_DROPRATE 0.1 -#define DELIF_OUTPUT_DROPRATE 0.1 - -#define DELIF_INPUT_DELAY 500 /* Miliseconds. */ -#define DELIF_OUTPUT_DELAY 500 /* Miliseconds. */ - -#define DELIF_TIMEOUT 10 - -struct delif { - err_t (* input)(struct pbuf *p, struct netif *inp); - struct netif *netif; -}; - -struct delif_pbuf { - struct delif_pbuf *next; - struct pbuf *p; - ip_addr_t ipaddr; - unsigned int time; -}; - -static struct delif_pbuf *input_list = NULL; -static struct delif_pbuf *output_list = NULL; -/*-----------------------------------------------------------------------------------*/ -static void -delif_input_timeout(void *arg) -{ - struct netif *netif; - struct delif *delif; - struct delif_pbuf *dp; - unsigned int timeout, now; - - timeout = DELIF_TIMEOUT; - - netif = (struct netif*)arg; - delif = (struct delif*)netif->state; - - /* Check if there is anything on the input list. */ - dp = input_list; - while (dp != NULL) { - now = sys_now(); - - if (dp->time <= now) { - delif->input(dp->p, netif); - if (dp->next != NULL) { - if (dp->next->time > now) { - timeout = dp->next->time - now; - } else { - timeout = 0; - } - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output_timeout: timeout %u.\n", timeout)); - - } - input_list = dp->next; - free(dp); - dp = input_list; - } else { - dp = dp->next; - } - } - - sys_timeout(timeout, delif_input_timeout, arg); -} -/*-----------------------------------------------------------------------------------*/ -static void -delif_output_timeout(void *arg) -{ - struct netif *netif; - struct delif *delif; - struct delif_pbuf *dp; - unsigned int timeout, now; - - timeout = DELIF_TIMEOUT; - - netif = (struct netif*)arg; - delif = (struct delif*)netif->state; - - /* Check if there is anything on the output list. */ - dp = output_list; - while (dp != NULL) { - now = sys_now(); - if (dp->time <= now) { - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output_timeout: now %u dp->time %u\n", - now, dp->time)); - -#if LWIP_IPV4 - if(!IP_IS_V6_VAL(dp->ipaddr)) { - delif->netif->output(delif->netif, dp->p, ip_2_ip4(&dp->ipaddr)); - } -#endif /* LWIP_IPV4 */ - -#if LWIP_IPV6 - if(IP_IS_V6_VAL(dp->ipaddr)) { - delif->netif->output_ip6(delif->netif, dp->p, ip_2_ip6(&dp->ipaddr)); - } -#endif /* LWIP_IPV6 */ - - if (dp->next != NULL) { - if (dp->next->time > now) { - timeout = dp->next->time - now; - } else { - timeout = 0; - } - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output_timeout: timeout %u.\n", timeout)); - - } - pbuf_free(dp->p); - - output_list = dp->next; - free(dp); - dp = output_list; - } else { - dp = dp->next; - } - } - - sys_timeout(timeout, delif_output_timeout, arg); -} -/*-----------------------------------------------------------------------------------*/ -static err_t -delif_output(struct netif *netif, struct pbuf *p, const ip_addr_t *ipaddr) -{ - struct delif_pbuf *dp, *np; - char *data; - - LWIP_UNUSED_ARG(netif); - - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output\n")); - -#ifdef DELIF_OUTPUT_DROPRATE - if (((double)rand()/(double)RAND_MAX) < DELIF_OUTPUT_DROPRATE) { - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output: Packet dropped\n")); - return ERR_BUF; - } -#endif /* DELIF_OUTPUT_DROPRATE */ - - LWIP_DEBUGF(DELIF_DEBUG, ("delif_output\n")); - - dp = (struct delif_pbuf*)malloc(sizeof(struct delif_pbuf)); - data = (char*)malloc(p->tot_len); - - pbuf_copy_partial(p, data, p->tot_len, 0); - - dp->p = pbuf_alloc(PBUF_LINK, 0, PBUF_ROM); - dp->p->payload = data; - dp->p->len = p->tot_len; - dp->p->tot_len = p->tot_len; - dp->ipaddr = *ipaddr; - dp->time = sys_now() + DELIF_OUTPUT_DELAY; - dp->next = NULL; - if (output_list == NULL) { - output_list = dp; - } else { - for(np = output_list; np->next != NULL; np = np->next); - np->next = dp; - } - - return ERR_OK; -} - -#if LWIP_IPV4 -static err_t -delif_output4(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) -{ - ip_addr_t ip; - if (ipaddr != NULL) { - ip_addr_copy_from_ip4(ip, *ipaddr); - } else { - ip = *IP_ADDR_ANY; - } - return delif_output(netif, p, &ip); -} -#endif /* LWIP_IPV4 */ - -#if LWIP_IPV6 -static err_t -delif_output6(struct netif *netif, struct pbuf *p, const ip6_addr_t *ipaddr) -{ - ip_addr_t ip; - if (ipaddr != NULL) { - ip_addr_copy_from_ip6(ip, *ipaddr); - } else { - ip = *IP6_ADDR_ANY; - } - return delif_output(netif, p, &ip); -} -#endif /* LWIP_IPV6 */ -/*-----------------------------------------------------------------------------------*/ -static err_t -delif_input(struct pbuf *p, struct netif *inp) -{ - struct delif_pbuf *dp, *np; - - LWIP_UNUSED_ARG(inp); - - LWIP_DEBUGF(DELIF_DEBUG, ("delif_input\n")); -#ifdef DELIF_INPUT_DROPRATE - if (((double)rand()/(double)RAND_MAX) < DELIF_INPUT_DROPRATE) { - LWIP_DEBUGF(DELIF_DEBUG, ("delif_input: Packet dropped\n")); - pbuf_free(p); - return ERR_OK; - } -#endif /* DELIF_INPUT_DROPRATE */ - - dp = (struct delif_pbuf*)malloc(sizeof(struct delif_pbuf)); - dp->p = p; - dp->time = sys_now() + DELIF_INPUT_DELAY; - dp->next = NULL; - - if (input_list == NULL) { - input_list = dp; - } else { - for(np = input_list; np->next != NULL; np = np->next); - np->next = dp; - } - - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -err_t -delif_init(struct netif *netif) -{ - struct delif *del; - - del = (struct delif*)malloc(sizeof(struct delif)); - if (!del) { - return ERR_MEM; - } - netif->state = del; - netif->name[0] = 'd'; - netif->name[1] = 'e'; - -#if LWIP_IPV4 - netif->output = delif_output4; -#endif /* LWIP_IPV4 */ -#if LWIP_IPV6 - netif->output_ip6 = delif_output6; -#endif /* LWIP_IPV6 */ - - del->netif = (struct netif*)malloc(sizeof(struct netif)); - if (!del->netif) { - free(del); - return ERR_MEM; - } - -#ifdef LWIP_UNIX_LINUX - tapif_init(del->netif); -#else /* LWIP_UNIX_LINUX */ - tunif_init(del->netif); -#endif /* LWIP_UNIX_LINUX */ - - del->input = netif->input; - del->netif->input = delif_input; - - sys_timeout(DELIF_TIMEOUT, delif_input_timeout, netif); - sys_timeout(DELIF_TIMEOUT, delif_output_timeout, netif); - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -static void -delif_thread(void *arg) -{ - struct netif *netif = (struct netif*)arg; - struct delif *del; - sys_sem_t sem; - - del = (struct delif*)netif->state; -#ifdef LWIP_UNIX_LINUX - tapif_init(del->netif); -#else /* LWIP_UNIX_LINUX */ - tunif_init(del->netif); -#endif /* LWIP_UNIX_LINUX */ - - sys_timeout(DELIF_TIMEOUT, delif_input_timeout, netif); - sys_timeout(DELIF_TIMEOUT, delif_output_timeout, netif); - - if(sys_sem_new(&sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - sys_sem_wait(&sem); -} -/*-----------------------------------------------------------------------------------*/ -err_t -delif_init_thread(struct netif *netif) -{ - struct delif *del; - - LWIP_DEBUGF(DELIF_DEBUG, ("delif_init_thread\n")); - - del = (struct delif*)malloc(sizeof(struct delif)); - if (!del) { - return ERR_MEM; - } - - netif->state = del; - netif->name[0] = 'd'; - netif->name[1] = 'e'; - - del->netif = (struct netif*)malloc(sizeof(struct netif)); - if (!del->netif) { - free(del); - return ERR_MEM; - } - -#if LWIP_IPV4 - netif->output = delif_output4; - netif_set_addr(del->netif, netif_ip4_addr(netif), netif_ip4_netmask(netif), netif_ip4_gw(netif)); -#endif /* LWIP_IPV4 */ - -#if LWIP_IPV6 - { - s8_t i; - netif->output_ip6 = delif_output6; - for(i=0; i < LWIP_IPV6_NUM_ADDRESSES; i++) { - netif_ip6_addr_set(del->netif, i, netif_ip6_addr(netif, i)); - } - } -#endif /* LWIP_IPV6 */ - - del->input = netif->input; - del->netif->input = delif_input; - - sys_thread_new("delif_thread", delif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ - -#endif /* !NO_SYS */ diff --git a/ports/unix/port/netif/pcapif.c b/ports/unix/port/netif/pcapif.c index afd0d08..2dcac48 100644 --- a/ports/unix/port/netif/pcapif.c +++ b/ports/unix/port/netif/pcapif.c @@ -55,16 +55,11 @@ #include "lwip/def.h" #include "lwip/mem.h" #include "lwip/pbuf.h" -#include "netif/unixif.h" #include "lwip/sys.h" #include "lwip/ip.h" -#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) -#include "netif/tcpdump.h" -#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ - struct pcapif { pcap_t *pd; sys_sem_t sem; @@ -107,10 +102,6 @@ timeout(void *arg) if (p != NULL) { pbuf_take(p, pcapif->pkt, pcapif->len); -#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) - tcpdump(p, netif); -#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ - ethhdr = p->payload; switch (lwip_htons(ethhdr->type)) { /* IP or ARP packet? */ diff --git a/ports/unix/port/netif/tapif.c b/ports/unix/port/netif/tapif.c index 75f8954..752e391 100644 --- a/ports/unix/port/netif/tapif.c +++ b/ports/unix/port/netif/tapif.c @@ -56,10 +56,6 @@ #include "netif/etharp.h" #include "lwip/ethip6.h" -#if defined(LWIP_DEBUG) && defined(LWIP_TCPDUMP) -#include "netif/tcpdump.h" -#endif /* LWIP_DEBUG && LWIP_TCPDUMP */ - #include "netif/tapif.h" #define IFCONFIG_BIN "/sbin/ifconfig " diff --git a/ports/unix/port/netif/tcpdump.c b/ports/unix/port/netif/tcpdump.c deleted file mode 100644 index 34adbd7..0000000 --- a/ports/unix/port/netif/tcpdump.c +++ /dev/null @@ -1,216 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include - -#include "lwip/opt.h" - -#if (LWIP_IPV4 || LWIP_IPV6) && LWIP_TCP /* @todo: fix IPv6 */ - -#include /* memcpy */ -#include "netif/tcpdump.h" -#include "lwip/pbuf.h" -#include "lwip/netif.h" -#include "lwip/ip.h" -#include "lwip/ip4.h" -#include "lwip/ip6.h" -#include "lwip/ip_addr.h" -#include "lwip/priv/tcp_priv.h" -#include "lwip/udp.h" -#include "lwip/inet.h" -#include "lwip/inet_chksum.h" - -#ifndef TCPDUMP_DEBUG -#define TCPDUMP_DEBUG LWIP_DBG_OFF -#endif - -static FILE *file = NULL; - -/*-----------------------------------------------------------------------------------*/ -void -tcpdump_init(void) -{ -#define TCPDUMP_FNAME "/tmp/tcpdump" - file = fopen(TCPDUMP_FNAME, "w"); - if (file == NULL) { - perror("tcpdump_init: cannot open \""TCPDUMP_FNAME"\" for writing"); - } - LWIP_DEBUGF(TCPDUMP_DEBUG, ("tcpdump: file %s\n", TCPDUMP_FNAME)); -} -/*-----------------------------------------------------------------------------------*/ -void -tcpdump(struct pbuf *p, struct netif* netif) -{ -#if LWIP_IPV4 - ip_addr_t src, dst; - struct ip_hdr *iphdr; -#if LWIP_UDP - struct udp_hdr *udphdr; -#endif -#if LWIP_TCP - struct tcp_hdr *tcphdr; - char flags[5]; - int i; - int len; - int offset; -#endif - - LWIP_UNUSED_ARG(netif); /* in case IPv6 is disabled */ - - if (file == NULL) { - return; - } - iphdr = (struct ip_hdr *)p->payload; - -#if LWIP_IPV6 - if(IPH_V(iphdr) == 6) { - struct ip6_hdr *ip6hdr = (struct ip6_hdr*)iphdr; - - /* create aligned copies if IPv6 src/dest addr */ - ip6_addr_copy_from_packed(*ip_2_ip6(&src), ip6hdr->src); - ip6_addr_assign_zone(ip_2_ip6(&src), IP6_UNKNOWN, netif); - IP_SET_TYPE_VAL(src, IPADDR_TYPE_V6); - - ip6_addr_copy_from_packed(*ip_2_ip6(&dst), ip6hdr->dest); - ip6_addr_assign_zone(ip_2_ip6(&dst), IP6_UNKNOWN, netif); - IP_SET_TYPE_VAL(dst, IPADDR_TYPE_V6); - - fprintf(file, "%s > %s: (IPv6, unsupported) ", - ip_ntoa(&src), - ip_ntoa(&dst)); - return; /* not supported */ - } -#endif - - if(IPH_V(iphdr) == 4) { - ip_addr_copy_from_ip4(src, iphdr->src); - ip_addr_copy_from_ip4(dst, iphdr->dest); - } - - switch (IPH_PROTO(iphdr)) { -#if LWIP_TCP - case IP_PROTO_TCP: - tcphdr = (struct tcp_hdr *)((char *)iphdr + IPH_HL(iphdr)); - - pbuf_header(p, -IP_HLEN); - if (ip_chksum_pseudo(p, IP_PROTO_TCP, p->tot_len, &src, &dst) != 0) { - LWIP_DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n")); - /* - fprintf(file, "chksum 0x%lx ", tcphdr->chksum); - tcphdr->chksum = 0; - fprintf(file, "should be 0x%lx ", inet_chksum_pseudo(p, (ip_addr_t *)&(iphdr->src), - (ip_addr_t *)&(iphdr->dest), IP_PROTO_TCP, p->tot_len));*/ - fprintf(file, "!chksum "); - } - - i = 0; - if (TCPH_FLAGS(tcphdr) & TCP_SYN) { - flags[i++] = 'S'; - } - if (TCPH_FLAGS(tcphdr) & TCP_PSH) { - flags[i++] = 'P'; - } - if (TCPH_FLAGS(tcphdr) & TCP_FIN) { - flags[i++] = 'F'; - } - if (TCPH_FLAGS(tcphdr) & TCP_RST) { - flags[i++] = 'R'; - } - if (i == 0) { - flags[i++] = '.'; - } - flags[i++] = 0; - - fprintf(file, "%s.%u > %s.%u: ", - ip_ntoa(&src), - lwip_ntohs(tcphdr->src), - ip_ntoa(&dst), - lwip_ntohs(tcphdr->dest)); - offset = TCPH_HDRLEN(tcphdr); - - len = lwip_ntohs(IPH_LEN(iphdr)) - offset * 4 - IP_HLEN; - if (len != 0 || flags[0] != '.') { - fprintf(file, "%s %u:%u(%u) ", flags, lwip_ntohl(tcphdr->seqno), - lwip_ntohl(tcphdr->seqno) + (u32_t)len, len); - } - if (TCPH_FLAGS(tcphdr) & TCP_ACK) { - fprintf(file, "ack %u ", lwip_ntohl(tcphdr->ackno)); - } - fprintf(file, "wnd %u\n", lwip_ntohs(tcphdr->wnd)); - - fflush(file); - - pbuf_header(p, IP_HLEN); - break; -#endif /* LWIP_TCP */ - -#if LWIP_UDP - case IP_PROTO_UDP: - udphdr = (struct udp_hdr *)((char *)iphdr + IPH_HL(iphdr)); - - pbuf_header(p, -IP_HLEN); - if (ip_chksum_pseudo(p, IP_PROTO_UDP, p->tot_len, &src, &dst) != 0) { - LWIP_DEBUGF(TCPDUMP_DEBUG, ("tcpdump: IP checksum failed!\n")); - /* - fprintf(file, "chksum 0x%lx ", tcphdr->chksum); - tcphdr->chksum = 0; - fprintf(file, "should be 0x%lx ", ip_chksum_pseudo(p, &src, &dst, IP_PROTO_TCP, p->tot_len));*/ - fprintf(file, "!chksum "); - } - - fprintf(file, "%s.%u > %s.%u: ", - ip_ntoa(&src), - lwip_ntohs(udphdr->src), - ip_ntoa(&dst), - lwip_ntohs(udphdr->dest)); - fprintf(file, "U "); - len = (int)(lwip_ntohs(IPH_LEN(iphdr)) - sizeof(struct udp_hdr) - IP_HLEN); - fprintf(file, " %d\n", len); - - fflush(file); - - pbuf_header(p, IP_HLEN); - break; -#endif /* LWIP_UDP */ - default: - LWIP_DEBUGF(TCPDUMP_DEBUG, ("unhandled IP protocol: %d\n", (int)IPH_PROTO(iphdr))); - break; - } -#else - LWIP_UNUSED_ARG(p); - LWIP_UNUSED_ARG(netif); -#endif -} - -#endif /* LWIP_IPV4 && LWIP_TCP */ - -/*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/port/netif/tunif.c b/ports/unix/port/netif/tunif.c deleted file mode 100644 index e0852fa..0000000 --- a/ports/unix/port/netif/tunif.c +++ /dev/null @@ -1,318 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include "netif/tunif.h" - -#include -#include -#include -#include -#include -#include -#include -#include - - -#include "lwip/debug.h" - -#include "lwip/opt.h" -#include "lwip/def.h" -#include "lwip/ip.h" -#include "lwip/mem.h" -#include "lwip/snmp.h" -#include "lwip/netif.h" -#include "lwip/pbuf.h" -#include "lwip/sys.h" - -#if LWIP_IPV4 /* @todo: IPv6 */ -#if !NO_SYS - -#define IFNAME0 't' -#define IFNAME1 'n' - -#ifndef TUNIF_DEBUG -#define TUNIF_DEBUG LWIP_DBG_OFF -#endif - -#define IFCONFIG_CALL "/sbin/ifconfig tun0 inet %d.%d.%d.%d %d.%d.%d.%d" - -struct tunif { - /* Add whatever per-interface state that is needed here. */ - int fd; -}; - -/* Forward declarations. */ -static void tunif_input(struct netif *netif); -static err_t tunif_output(struct netif *netif, struct pbuf *p, - const ip4_addr_t *ipaddr); - -static void tunif_thread(void *data); - -/*-----------------------------------------------------------------------------------*/ -static void -low_level_init(struct netif *netif) -{ - struct tunif *tunif; - char buf[sizeof(IFCONFIG_CALL) + 50]; - - tunif = (struct tunif *)netif->state; - - /* Obtain MAC address from network interface. */ - - /* Do whatever else is needed to initialize interface. */ - - tunif->fd = open("/dev/tun0", O_RDWR); - LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: fd %d\n", tunif->fd)); - if (tunif->fd == -1) { - perror("tunif_init"); - exit(1); - } - sprintf(buf, IFCONFIG_CALL, - ip4_addr1(netif_ip4_gw(netif)), - ip4_addr2(netif_ip4_gw(netif)), - ip4_addr3(netif_ip4_gw(netif)), - ip4_addr4(netif_ip4_gw(netif)), - ip4_addr1(netif_ip4_addr(netif)), - ip4_addr2(netif_ip4_addr(netif)), - ip4_addr3(netif_ip4_addr(netif)), - ip4_addr4(netif_ip4_addr(netif))); - - LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_init: system(\"%s\");\n", buf)); - if (system(buf) == 0) { - sys_thread_new("tunif_thread", tunif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - } -} -/*-----------------------------------------------------------------------------------*/ -/* - * low_level_output(): - * - * Should do the actual transmission of the packet. The packet is - * contained in the pbuf that is passed to the function. This pbuf - * might be chained. - * - */ -/*-----------------------------------------------------------------------------------*/ - -static err_t -low_level_output(struct netif *netif, struct tunif *tunif, struct pbuf *p) -{ - char buf[1500]; - ssize_t written; - - /* in case SNMP MIB2 is disabled */ - LWIP_UNUSED_ARG(netif); - - /* initiate transfer(); */ - -#if 0 - if (((double)rand()/(double)RAND_MAX) < 0.4) { - printf("drop output\n"); - return ERR_OK; /* ERR_OK because we simulate packet loss on cable */ - } -#endif - - if (p->tot_len > sizeof(buf)) { - MIB2_STATS_NETIF_INC(netif, ifoutdiscards); - perror("tunif: packet too large"); - return ERR_IF; - } - - pbuf_copy_partial(p, buf, p->tot_len, 0); - - /* signal that packet should be sent(); */ - written = write(tunif->fd, buf, p->tot_len); - if (written < p->tot_len) { - MIB2_STATS_NETIF_INC(netif, ifoutdiscards); - perror("tunif: write"); - return ERR_IF; - } else { - MIB2_STATS_NETIF_ADD(netif, ifoutoctets, (u32_t)written); - return ERR_OK; - } -} -/*-----------------------------------------------------------------------------------*/ -/* - * low_level_input(): - * - * Should allocate a pbuf and transfer the bytes of the incoming - * packet from the interface into the pbuf. - * - */ -/*-----------------------------------------------------------------------------------*/ -static struct pbuf * -low_level_input(struct tunif *tunif) -{ - struct pbuf *p; - ssize_t len; - char buf[1500]; - - /* Obtain the size of the packet and put it into the "len" - variable. */ - len = read(tunif->fd, buf, sizeof(buf)); - if((len <= 0) || (len > 0xffff)) { - return NULL; - } - - /* if (((double)rand()/(double)RAND_MAX) < 0.1) { - printf("drop\n"); - return NULL; - }*/ - - /* We allocate a pbuf chain of pbufs from the pool. */ - p = pbuf_alloc(PBUF_LINK, (u16_t)len, PBUF_POOL); - - if (p != NULL) { - pbuf_take(p, buf, (u16_t)len); - /* acknowledge that packet has been read(); */ - } else { - /* drop packet(); */ - } - - return p; -} -/*-----------------------------------------------------------------------------------*/ -static void -tunif_thread(void *arg) -{ - struct netif *netif; - struct tunif *tunif; - fd_set fdset; - int ret; - - netif = (struct netif *)arg; - tunif = (struct tunif *)netif->state; - - while (1) { - FD_ZERO(&fdset); - FD_SET(tunif->fd, &fdset); - - /* Wait for a packet to arrive. */ - ret = select(tunif->fd + 1, &fdset, NULL, NULL, NULL); - - if (ret == 1) { - /* Handle incoming packet. */ - tunif_input(netif); - } else if (ret == -1) { - perror("tunif_thread: select"); - } - } -} -/*-----------------------------------------------------------------------------------*/ -/* - * tunif_output(): - * - * This function is called by the TCP/IP stack when an IP packet - * should be sent. It calls the function called low_level_output() to - * do the actuall transmission of the packet. - * - */ -/*-----------------------------------------------------------------------------------*/ -static err_t -tunif_output(struct netif *netif, struct pbuf *p, - const ip4_addr_t *ipaddr) -{ - struct tunif *tunif; - LWIP_UNUSED_ARG(ipaddr); - - tunif = (struct tunif *)netif->state; - - return low_level_output(netif, tunif, p); - -} -/*-----------------------------------------------------------------------------------*/ -/* - * tunif_input(): - * - * This function should be called when a packet is ready to be read - * from the interface. It uses the function low_level_input() that - * should handle the actual reception of bytes from the network - * interface. - * - */ -/*-----------------------------------------------------------------------------------*/ -static void -tunif_input(struct netif *netif) -{ - struct tunif *tunif; - struct pbuf *p; - - - tunif = (struct tunif *)netif->state; - - p = low_level_input(tunif); - - if (p == NULL) { - LWIP_DEBUGF(TUNIF_DEBUG, ("tunif_input: low_level_input returned NULL\n")); - return; - } - -#if 0 -/* CS: ip_lookup() was removed */ - if (ip_lookup(p->payload, netif)) { -#endif - netif->input(p, netif); -#if 0 - } -#endif -} -/*-----------------------------------------------------------------------------------*/ -/* - * tunif_init(): - * - * Should be called at the beginning of the program to set up the - * network interface. It calls the function low_level_init() to do the - * actual setup of the hardware. - * - */ -/*-----------------------------------------------------------------------------------*/ -err_t -tunif_init(struct netif *netif) -{ - struct tunif *tunif; - - tunif = (struct tunif *)mem_malloc(sizeof(struct tunif)); - if (!tunif) { - return ERR_MEM; - } - netif->state = tunif; - netif->name[0] = IFNAME0; - netif->name[1] = IFNAME1; - netif->output = tunif_output; - - - low_level_init(netif); - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ - -#endif /* !NO_SYS */ -#endif /* LWIP_IPV4 */ diff --git a/ports/unix/port/netif/unixif.c b/ports/unix/port/netif/unixif.c deleted file mode 100644 index db833f2..0000000 --- a/ports/unix/port/netif/unixif.c +++ /dev/null @@ -1,501 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include "lwip/debug.h" - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -/*#include */ -/*#include */ - - -#include "lwip/stats.h" - -#include "lwip/def.h" -#include "lwip/mem.h" -#include "lwip/pbuf.h" -#include "netif/list.h" -#include "netif/unixif.h" -#include "lwip/sys.h" -#include "lwip/timeouts.h" - -#if LWIP_IPV4 /* @todo: IPv6 */ -#if !NO_SYS - -#include "netif/tcpdump.h" - -#define UNIXIF_BPS 512000 -#define UNIXIF_QUEUELEN 6 -/*#define UNIXIF_DROP_FIRST */ - -#ifndef UNIXIF_DEBUG -#define UNIXIF_DEBUG LWIP_DBG_OFF -#endif - -struct unixif_buf { - struct pbuf *p; - unsigned short len, tot_len; - void *payload; -}; - -struct unixif { - int fd; - sys_sem_t sem; - struct list *q; -}; - -static void unixif_thread(void *arg); -static void unixif_thread2(void *arg); - -/*-----------------------------------------------------------------------------------*/ -static int -unix_socket_client(const char *name) -{ - int fd; -#if !defined(LWIP_UNIX_LINUX) && !defined(LWIP_UNIX_CYGWIN) && !defined(__CYGWIN__) - int len; -#endif - struct sockaddr_un unix_addr; - - /* create a Unix domain stream socket */ - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - perror("unixif: unix_socket_client: socket"); - return(-1); - } - - /* fill socket address structure w/our address */ - memset(&unix_addr, 0, sizeof(unix_addr)); - unix_addr.sun_family = AF_UNIX; - snprintf(unix_addr.sun_path, sizeof(unix_addr.sun_path), "%s%05d", "/var/tmp/", getpid()); -#if !defined(LWIP_UNIX_LINUX) && !defined(LWIP_UNIX_CYGWIN) && !defined(__CYGWIN__) - len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) + - strlen(unix_addr.sun_path) + 1; - unix_addr.sun_len = len; -#endif /* LWIP_UNIX_LINUX */ - - unlink(unix_addr.sun_path); /* in case it already exists */ - if (bind(fd, (struct sockaddr *) &unix_addr, - sizeof(struct sockaddr_un)) < 0) { - perror("unixif: unix_socket_client: socket"); - return(-1); - } - if (chmod(unix_addr.sun_path, S_IRWXU | S_IRWXO) < 0) { - perror("unixif: unix_socket_client: socket"); - return(-1); - } - - /* fill socket address structure w/server's addr */ - memset(&unix_addr, 0, sizeof(unix_addr)); - unix_addr.sun_family = AF_UNIX; - strncpy(unix_addr.sun_path, name, sizeof(unix_addr.sun_path)); - unix_addr.sun_path[sizeof(unix_addr.sun_path)-1] = 0; /* ensure \0 termination */ -#if !defined(LWIP_UNIX_LINUX) && !defined(LWIP_UNIX_CYGWIN) && !defined(__CYGWIN__) - len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) + - strlen(unix_addr.sun_path) + 1; - unix_addr.sun_len = len; -#endif /* LWIP_UNIX_LINUX */ - if (connect(fd, (struct sockaddr *) &unix_addr, - sizeof(struct sockaddr_un)) < 0) { - perror("unixif: unix_socket_client: socket"); - return(-1); - } - return(fd); -} - -/*-----------------------------------------------------------------------------------*/ -static int -unix_socket_server(const char *name) -{ - int fd; -#if !defined(LWIP_UNIX_LINUX) && !defined(LWIP_UNIX_CYGWIN) && !defined(__CYGWIN__) - int len; -#endif - struct sockaddr_un unix_addr; - - /* create a Unix domain stream socket */ - if ((fd = socket(AF_UNIX, SOCK_STREAM, 0)) < 0) { - perror("unixif: unix_socket_server: socket"); - return(-1); - } - - unlink(name); /* in case it already exists */ - - /* fill in socket address structure */ - memset(&unix_addr, 0, sizeof(unix_addr)); - unix_addr.sun_family = AF_UNIX; - strncpy(unix_addr.sun_path, name, sizeof(unix_addr.sun_path)); - unix_addr.sun_path[sizeof(unix_addr.sun_path)-1] = 0; /* ensure \0 termination */ -#if !defined(LWIP_UNIX_LINUX) && !defined(LWIP_UNIX_CYGWIN) && !defined(__CYGWIN__) - len = sizeof(unix_addr.sun_len) + sizeof(unix_addr.sun_family) + - strlen(unix_addr.sun_path) + 1; - unix_addr.sun_len = len; -#endif /* LWIP_UNIX_LINUX */ - - /* bind the name to the descriptor */ - if (bind(fd, (struct sockaddr *) &unix_addr, - sizeof(struct sockaddr_un)) < 0) { - perror("unixif: unix_socket_server: bind"); - return(-1); - } - - if (chmod(unix_addr.sun_path, S_IRWXU | S_IRWXO) < 0) { - perror("unixif: unix_socket_server: chmod"); - return(-1); - } - - - if (listen(fd, 5) < 0) { /* tell kernel we're a server */ - perror("unixif: unix_socket_server: listen"); - return(-1); - } - - return(fd); -} -/*-----------------------------------------------------------------------------------*/ -static void -unixif_input_handler(void *data) -{ - struct netif *netif; - struct unixif *unixif; - char buf[1532]; - int plen; - ssize_t len; - u16_t len16; - struct pbuf *p; - - netif = (struct netif *)data; - unixif = (struct unixif *)netif->state; - - len = read(unixif->fd, &plen, sizeof(int)); - if (len < 0) { - perror("unixif_irq_handler: read"); - abort(); - } - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: len == %d plen == %d bytes\n", (int)len, plen)); - if (len == sizeof(int)) { - - if (plen < 20 || plen > 1500) { - LWIP_DEBUGF(UNIXIF_DEBUG, ("plen %d!\n", plen)); - return; - } - - len = read(unixif->fd, buf, (size_t)plen); - if (len < 0) { - perror("unixif_irq_handler: read"); - abort(); - } - if (len != plen) { - perror("unixif_irq_handler: read len != plen"); - abort(); - } - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: read %d bytes\n", (int)len)); - len16 = (u16_t)len; - p = pbuf_alloc(PBUF_LINK, len16, PBUF_POOL); - - if (p != NULL) { - pbuf_take(p, buf, len16); - LINK_STATS_INC(link.recv); -#if LWIP_IPV4 && LWIP_TCP - tcpdump(p, netif); -#endif - netif->input(p, netif); - } else { - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_irq_handler: could not allocate pbuf\n")); - } - - - } -} -/*-----------------------------------------------------------------------------------*/ -static void -unixif_thread(void *arg) -{ - struct netif *netif; - struct unixif *unixif; - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_thread: started.\n")); - - netif = (struct netif *)arg; - unixif = (struct unixif *)netif->state; - - - while (1) { - sys_sem_wait(&unixif->sem); - unixif_input_handler(netif); - } - -} -/*-----------------------------------------------------------------------------------*/ -static void -unixif_thread2(void *arg) -{ - struct netif *netif; - struct unixif *unixif; - fd_set fdset; - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_thread2: started.\n")); - - netif = (struct netif *)arg; - unixif = (struct unixif *)netif->state; - - while (1) { - FD_ZERO(&fdset); - FD_SET(unixif->fd, &fdset); - - if (select(unixif->fd + 1, &fdset, NULL, NULL, NULL) > 0) { - sys_sem_signal(&unixif->sem); - } - } -} -/*-----------------------------------------------------------------------------------*/ -static void unixif_output_timeout(void *arg); - -static err_t -unixif_output(struct netif *netif, struct pbuf *p, const ip4_addr_t *ipaddr) -{ - struct unixif *unixif; - struct unixif_buf *buf; - LWIP_UNUSED_ARG(ipaddr); - - unixif = (struct unixif *)netif->state; - - buf = (struct unixif_buf *)malloc(sizeof(struct unixif_buf)); - buf->p = p; - buf->len = p->len; - buf->tot_len = p->tot_len; - buf->payload = p->payload; - - if (list_elems(unixif->q) == 0) { - pbuf_ref(p); - list_push(unixif->q, buf); - sys_timeout((u32_t)p->tot_len * 8000 / UNIXIF_BPS, unixif_output_timeout, - netif); - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output: first on list\n")); - - } else { - pbuf_ref(p); - if (list_push(unixif->q, buf) == 0) { -#ifdef UNIXIF_DROP_FIRST - struct unixif_buf *buf2; - - buf2 = list_pop(unixif->q); - pbuf_free(buf2->p); - free(buf2); - list_push(unixif->q, buf); -#else - free(buf); - pbuf_free(p); - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output: drop\n")); - -#endif /* UNIXIF_DROP_FIRST */ - LINK_STATS_INC(link.drop); - - } else { - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output: on list\n")); - } - - } - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -static void -unixif_output_timeout(void *arg) -{ - struct pbuf *p, *q; - int i, j, len; - unsigned short plen, ptot_len; - struct unixif_buf *buf; - void *payload; - struct netif *netif; - struct unixif *unixif; - char *data; - - netif = (struct netif *)arg; - unixif = (struct unixif *)netif->state; - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output_timeout\n")); - - /* buf = unixif->q[0]; - unixif->q[0] = unixif->q[1]; - unixif->q[1] = NULL;*/ - buf = (struct unixif_buf *)list_pop(unixif->q); - - p = buf->p; - - plen = p->len; - ptot_len = p->tot_len; - payload = p->payload; - - p->len = buf->len; - p->tot_len = buf->tot_len; - p->payload = buf->payload; - - - if (p->tot_len == 0) { - - LWIP_DEBUGF(UNIXIF_DEBUG, ("p->len!\n")); - abort(); - } - data = (char *)malloc(p->tot_len); - - i = 0; - for(q = p; q != NULL; q = q->next) { - for(j = 0; j < q->len; j++) { - data[i] = ((char *)q->payload)[j]; - i++; - } - } - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_output: sending %d (%d) bytes\n", - p->len, p->tot_len)); - - len = p->tot_len; - if (write(unixif->fd, &len, sizeof(int)) == -1) { - perror("unixif_output: write"); - abort(); - } - - if (write(unixif->fd, data, p->tot_len) == -1) { - perror("unixif_output: write"); - abort(); - } -#if LWIP_IPV4 && LWIP_TCP - tcpdump(p, netif); -#endif - LINK_STATS_INC(link.xmit); - - free(data); - free(buf); - p->len = plen; - p->tot_len = ptot_len; - p->payload = payload; - - pbuf_free(p); - - /* if (unixif->q[0] != NULL) { - sys_timeout(unixif->q[0]->tot_len * 8000 / UNIXIF_BPS, - unixif_output_timeout, netif); - }*/ - if (list_elems(unixif->q) > 0) { - sys_timeout(((struct unixif_buf *)list_first(unixif->q))->tot_len * - 8000U / UNIXIF_BPS, - unixif_output_timeout, netif); - } -} -/*-----------------------------------------------------------------------------------*/ -err_t -unixif_init_server(struct netif *netif) -{ - int fd, fd2; - struct sockaddr_un addr; - socklen_t len; - struct unixif *unixif; - - fd = unix_socket_server("/tmp/unixif"); - - if (fd == -1) { - perror("unixif_server"); - abort(); - } - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_server: fd %d\n", fd)); - - unixif = (struct unixif *)malloc(sizeof(struct unixif)); - if (!unixif) { - return ERR_MEM; - } - netif->state = unixif; - netif->name[0] = 'u'; - netif->name[1] = 'n'; - netif->output = unixif_output; - unixif->q = list_new(UNIXIF_QUEUELEN); - - printf("Now run ./simnode.\n"); - len = sizeof(addr); - fd2 = accept(fd, (struct sockaddr *)&addr, &len); - - if (fd2 == -1) { - perror("unixif_accept"); - abort(); - } - - LWIP_DEBUGF(UNIXIF_DEBUG, ("unixif_accept: %d\n", fd2)); - - unixif->fd = fd2; - if(sys_sem_new(&unixif->sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - sys_thread_new("unixif_thread", unixif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - sys_thread_new("unixif_thread2", unixif_thread2, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ -err_t -unixif_init_client(struct netif *netif) -{ - struct unixif *unixif; - unixif = (struct unixif *)malloc(sizeof(struct unixif)); - if (!unixif) { - return ERR_MEM; - } - netif->state = unixif; - netif->name[0] = 'u'; - netif->name[1] = 'n'; - netif->output = unixif_output; - - unixif->fd = unix_socket_client("/tmp/unixif"); - if (unixif->fd == -1) { - perror("unixif_init"); - abort(); - } - unixif->q = list_new(UNIXIF_QUEUELEN); - if(sys_sem_new(&unixif->sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - sys_thread_new("unixif_thread", unixif_thread, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - sys_thread_new("unixif_thread2", unixif_thread2, netif, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - return ERR_OK; -} -/*-----------------------------------------------------------------------------------*/ - -#endif /* !NO_SYS */ -#endif /* LWIP_IPV4 */ diff --git a/ports/unix/unixsim/CMakeLists.txt b/ports/unix/unixsim/CMakeLists.txt deleted file mode 100644 index 42dc7a3..0000000 --- a/ports/unix/unixsim/CMakeLists.txt +++ /dev/null @@ -1,36 +0,0 @@ -cmake_minimum_required(VERSION 3.8) - -project(unixsim C) - -set(LWIP_CONTRIB_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../..) -set(LWIP_DIR ${CMAKE_CURRENT_SOURCE_DIR}/../../../../lwip) - -include(${LWIP_CONTRIB_DIR}/ports/CMakeCommon.cmake) - -include(${LWIP_DIR}/src/Filelists.cmake) -include(${LWIP_CONTRIB_DIR}/Filelists.cmake) -include(${LWIP_CONTRIB_DIR}/ports/unix/Filelists.cmake) - -add_definitions(-DLWIP_DEBUG) - -include_directories( - "${LWIP_DIR}/src/include" - "${LWIP_CONTRIB_DIR}/" - "${LWIP_CONTRIB_DIR}/ports/unix/port/include" - "${CMAKE_CURRENT_SOURCE_DIR}/" -) - -# lwipcontribaddons is specified multiple times in target_link_libraries because of cyclic dependency -# lwipcontribaddons call various functions in lwipcore -# lwipcore needs tcp_hook_isn from lwipcontribaddons - -add_executable(simhost simhost.c) -target_link_libraries(simhost lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribportunix lwipcore lwipcontribaddons) - -add_executable(simnode simnode.c) -target_link_libraries(simnode lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribportunix lwipcore lwipcontribaddons) - -add_executable(simrouter simrouter.c) -target_link_libraries(simrouter lwipcontribexamples lwipcontribapps lwipcontribaddons lwipallapps lwipcontribportunix lwipcore lwipcontribaddons) - -add_executable(makefsdata ${lwipmakefsdata_SRCS}) diff --git a/ports/unix/unixsim/Makefile b/ports/unix/unixsim/Makefile deleted file mode 100644 index 20767e9..0000000 --- a/ports/unix/unixsim/Makefile +++ /dev/null @@ -1,59 +0,0 @@ -# -# Copyright (c) 2001, 2002 Swedish Institute of Computer Science. -# All rights reserved. -# -# Redistribution and use in source and binary forms, with or without modification, -# are permitted provided that the following conditions are met: -# -# 1. Redistributions of source code must retain the above copyright notice, -# this list of conditions and the following disclaimer. -# 2. 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. -# 3. The name of the author may not be used to endorse or promote products -# derived from this software without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. -# -# This file is part of the lwIP TCP/IP stack. -# -# Author: Adam Dunkels -# - -all compile: simhost simrouter simnode makefsdata -.PHONY: all - -include ../Common.mk - -MAKEFSDATAOBJS=$(notdir $(MAKEFSDATAFILES:.c=.o)) - -clean: - rm -f *.o $(LWIPLIBCOMMON) $(APPLIB) simhost simnode simrouter *.s .depend* *.core core - -depend dep: .depend - -include .depend - -.depend: simhost.c simnode.c simrouter.c $(LWIPFILES) $(APPFILES) $(MAKEFSDATAFILES) - $(CCDEP) $(CFLAGS) -MM $^ > .depend || rm -f .depend - -simhost: .depend $(LWIPLIBCOMMON) $(APPLIB) simhost.o - $(CC) $(CFLAGS) -o simhost simhost.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS) - -simrouter: .depend $(LWIPLIBCOMMON) $(APPLIB) simrouter.o - $(CC) $(CFLAGS) -o simrouter simrouter.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS) - -simnode: .depend $(LWIPLIBCOMMON) $(APPLIB) simnode.o - $(CC) $(CFLAGS) -o simnode simnode.o -Wl,--start-group $(APPLIB) $(LWIPLIBCOMMON) -Wl,--end-group $(LDFLAGS) - -makefsdata: .depend $(MAKEFSDATAOBJS) - $(CC) $(CFLAGS) -o makefsdata $(MAKEFSDATAOBJS) diff --git a/ports/unix/unixsim/README b/ports/unix/unixsim/README deleted file mode 100644 index 949c917..0000000 --- a/ports/unix/unixsim/README +++ /dev/null @@ -1,61 +0,0 @@ -This directory contains an example of how a project using lwIP might -look. It is also the development platform of lwIP, since it can be run -as a user process under FreeBSD or Linux. There are also a number of -example applications (including a simple web server) in the apps/ -directory. - -Some short instructions on how to build and run lwIP on a FreeBSD or -Linux host. For FreeBSD, the tap interface must be enabled in the -kernel configuration and the kernel must be recompiled. The tap -interface is enabled by adding the line "pseudo-device tap" in the -kernel configuration. See Chapter 9 in the FreeBSD handbook for -instructions on how to build a custom FreeBSD kernel. - -For Linux you might need to create a device node with - - > mknod /dev/net/tun c 10 200 - -* Compile the code. This must be done by using GNU Make. Under - FreeBSD, GNU Make can be found in the ports collection under - /usr/ports/devel/gmake (type "make install distclean" to - install). Under Linux, GNU Make is the default "make". - - > gmake (FreeBSD) - - > make (Linux) - -* The compilation process produces the executable file "simhost". To - run this, you have to be root. - - > su (Type password for the root account) - # ./simhost - -* The lwIP TCP/IP stack is now running with IP address - 192.168.0.2. Some things that you can try: - - To see the packets that are going to and from the lwIP stack, run - tcpdump: - - # tcpdump -l -n -i tap0 - - You can ping lwIP: - - > ping 192.168.0.2 - - For a telnet shell, run: - - > telnet 192.168.0.2 - - Finally, "simhost" also includes a simple web server; the URL is - of course http://192.168.0.2/. - -* Simhost has some extra features that can be - selected with command line options. - - To enable runtime debug output (project must be build with -DLWIP_DEBUG): - - # ./simhost -d - - To ping any host, e.g. the gateway: - - # ./simhost -p 192.168.0.1 diff --git a/ports/unix/unixsim/lwip_hooks.h b/ports/unix/unixsim/lwip_hooks.h deleted file mode 100644 index 194e8b2..0000000 --- a/ports/unix/unixsim/lwip_hooks.h +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#ifndef LWIP_HOOKS_H -#define LWIP_HOOKS_H - -#ifdef __cplusplus -extern "C" { -#endif - -#include "addons/tcp_isn/tcp_isn.h" - -#define LWIP_HOOK_TCP_ISN lwip_hook_tcp_isn - -#ifdef __cplusplus -} -#endif - -#endif /* LWIP_HOOKS_H */ - diff --git a/ports/unix/unixsim/lwipopts.h b/ports/unix/unixsim/lwipopts.h deleted file mode 100644 index bc16a17..0000000 --- a/ports/unix/unixsim/lwipopts.h +++ /dev/null @@ -1,401 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ -#ifndef LWIP_LWIPOPTS_H -#define LWIP_LWIPOPTS_H - -#include "lwip/arch.h" - -#define LWIP_HOOK_FILENAME "lwip_hooks.h" - -#define LWIP_IPV4 1 -#define LWIP_IPV6 1 - -#define LWIP_DBG_MIN_LEVEL 0 -#define LWIP_COMPAT_SOCKETS 1 -#define TAPIF_DEBUG LWIP_DBG_ON -#define TUNIF_DEBUG LWIP_DBG_OFF -#define UNIXIF_DEBUG LWIP_DBG_OFF -#define DELIF_DEBUG LWIP_DBG_OFF -#define SIO_FIFO_DEBUG LWIP_DBG_OFF -#define TCPDUMP_DEBUG LWIP_DBG_ON - -#define SLIP_DEBUG LWIP_DBG_OFF -#define PPP_DEBUG LWIP_DBG_OFF -#define MEM_DEBUG LWIP_DBG_OFF -#define MEMP_DEBUG LWIP_DBG_OFF -#define PBUF_DEBUG LWIP_DBG_OFF -#define API_LIB_DEBUG LWIP_DBG_ON -#define API_MSG_DEBUG LWIP_DBG_ON -#define TCPIP_DEBUG LWIP_DBG_ON -#define NETIF_DEBUG LWIP_DBG_ON -#define SOCKETS_DEBUG LWIP_DBG_ON -#define DEMO_DEBUG LWIP_DBG_ON -#define IP_DEBUG LWIP_DBG_ON -#define IP_REASS_DEBUG LWIP_DBG_ON -#define RAW_DEBUG LWIP_DBG_ON -#define ICMP_DEBUG LWIP_DBG_ON -#define UDP_DEBUG LWIP_DBG_ON -#define TCP_DEBUG LWIP_DBG_ON -#define TCP_INPUT_DEBUG LWIP_DBG_ON -#define TCP_OUTPUT_DEBUG LWIP_DBG_ON -#define TCP_RTO_DEBUG LWIP_DBG_ON -#define TCP_CWND_DEBUG LWIP_DBG_ON -#define TCP_WND_DEBUG LWIP_DBG_ON -#define TCP_FR_DEBUG LWIP_DBG_ON -#define TCP_QLEN_DEBUG LWIP_DBG_ON -#define TCP_RST_DEBUG LWIP_DBG_ON - -extern unsigned char debug_flags; -#define LWIP_DBG_TYPES_ON debug_flags - -#define NO_SYS 0 -#define LWIP_SOCKET (NO_SYS==0) -#define LWIP_NETCONN (NO_SYS==0) -#define SO_REUSE 1 -#define IP_SOF_BROADCAST_RECV 1 -#define IP_SOF_BROADCAST 1 -#define SO_REUSE_RXTOALL 1 -#define LWIP_SO_RCVTIMEO (LWIP_SOCKET) - -/* ---------- Memory options ---------- */ -/* MEM_ALIGNMENT: should be set to the alignment of the CPU for which - lwIP is compiled. 4 byte alignment -> define MEM_ALIGNMENT to 4, 2 - byte alignment -> define MEM_ALIGNMENT to 2. */ -/* MSVC port: intel processors don't need 4-byte alignment, - but are faster that way! */ -#define MEM_ALIGNMENT 4U - -/* MEM_SIZE: the size of the heap memory. If the application will send -a lot of data that needs to be copied, this should be set high. */ -#define MEM_SIZE 10240 - -/* MEMP_NUM_PBUF: the number of memp struct pbufs. If the application - sends a lot of data out of ROM (or other static memory), this - should be set high. */ -#define MEMP_NUM_PBUF 16 -/* MEMP_NUM_RAW_PCB: the number of UDP protocol control blocks. One - per active RAW "connection". */ -#define MEMP_NUM_RAW_PCB 3 -/* MEMP_NUM_UDP_PCB: the number of UDP protocol control blocks. One - per active UDP "connection". */ -#define MEMP_NUM_UDP_PCB 7 -/* MEMP_NUM_TCP_PCB: the number of simulatenously active TCP - connections. */ -#define MEMP_NUM_TCP_PCB 6 -/* MEMP_NUM_TCP_PCB_LISTEN: the number of listening TCP - connections. */ -#define MEMP_NUM_TCP_PCB_LISTEN 9 -/* MEMP_NUM_TCP_SEG: the number of simultaneously queued TCP - segments. */ -#define MEMP_NUM_TCP_SEG 16 -/* MEMP_NUM_SYS_TIMEOUT: the number of simulateously active - timeouts. */ -#define MEMP_NUM_SYS_TIMEOUT 17 - -/* The following four are used only with the sequential API and can be - set to 0 if the application only will use the raw API. */ -/* MEMP_NUM_NETBUF: the number of struct netbufs. */ -#define MEMP_NUM_NETBUF 2 -/* MEMP_NUM_NETCONN: the number of struct netconns. */ -#define MEMP_NUM_NETCONN 11 -/* MEMP_NUM_TCPIP_MSG_*: the number of struct tcpip_msg, which is used - for sequential API communication and incoming packets. Used in - src/api/tcpip.c. */ -#define MEMP_NUM_TCPIP_MSG_API 16 -#define MEMP_NUM_TCPIP_MSG_INPKT 16 - -#define MEMP_OVERFLOW_CHECK 1 - -/* ---------- Pbuf options ---------- */ -/* PBUF_POOL_SIZE: the number of buffers in the pbuf pool. */ -#define PBUF_POOL_SIZE 200 - -/* PBUF_POOL_BUFSIZE: the size of each pbuf in the pbuf pool. */ -#define PBUF_POOL_BUFSIZE 128 - -/* PBUF_LINK_HLEN: the number of bytes that should be allocated for a - link level header. */ -#define PBUF_LINK_HLEN 16u - -/** SYS_LIGHTWEIGHT_PROT - * define SYS_LIGHTWEIGHT_PROT in lwipopts.h if you want inter-task protection - * for certain critical regions during buffer allocation, deallocation and memory - * allocation and deallocation. - */ -#define SYS_LIGHTWEIGHT_PROT 1 - -#define LWIP_TCPIP_TIMEOUT 1 - -/* ---------- TCP options ---------- */ -#define LWIP_TCP 1 -#define LWIP_ALTCP (LWIP_TCP) -#define TCP_TTL 255 - -#ifdef LWIP_HAVE_MBEDTLS -#define LWIP_ALTCP_TLS (LWIP_TCP) -#define LWIP_ALTCP_TLS_MBEDTLS (LWIP_TCP) -#endif - -#define TCP_LISTEN_BACKLOG 1 - -/* Controls if TCP should queue segments that arrive out of - order. Define to 0 if your device is low on memory. */ -#define TCP_QUEUE_OOSEQ 1 - -/* TCP Maximum segment size. */ -#define TCP_MSS 1024 - -/* TCP sender buffer space (bytes). */ -#define TCP_SND_BUF 2048 - -/* TCP sender buffer space (pbufs). This must be at least = 2 * - TCP_SND_BUF/TCP_MSS for things to work. */ -#define TCP_SND_QUEUELEN (4 * TCP_SND_BUF/TCP_MSS) - -/* TCP writable space (bytes). This must be less than or equal - to TCP_SND_BUF. It is the amount of space which must be - available in the tcp snd_buf for select to return writable */ -#define TCP_SNDLOWAT (TCP_SND_BUF/2) - -/* TCP receive window. */ -#define TCP_WND 8096 - -/* Maximum number of retransmissions of data segments. */ -#define TCP_MAXRTX 12 - -/* Maximum number of retransmissions of SYN segments. */ -#define TCP_SYNMAXRTX 4 - -/* ---------- ARP options ---------- */ -#define LWIP_ARP 1 -#define ARP_TABLE_SIZE 10 -#define ARP_QUEUEING 1 - -/* ---------- IP options ---------- */ -/* Define IP_FORWARD to 1 if you wish to have the ability to forward - IP packets across network interfaces. If you are going to run lwIP - on a device with only one network interface, define this to 0. */ -#define IP_FORWARD 1 - - -/* IP reassembly and segmentation.These are orthogonal even - * if they both deal with IP fragments */ -#define IP_REASSEMBLY 1 -#define IP_REASS_MAX_PBUFS 10 -#define MEMP_NUM_REASSDATA 10 -#define IP_FRAG 1 -#define IPV6_FRAG_COPYHEADER 1 -#define LWIP_IPV6_FRAG 1 - -#define LWIP_IGMP (LWIP_IPV4) - -/* ---------- ICMP options ---------- */ -#define ICMP_TTL 255 - -/* ---------- DHCP options ---------- */ -/* Define LWIP_DHCP to 1 if you want DHCP configuration of - interfaces. */ -#define LWIP_DHCP 0 - -#define LWIP_DHCP_GET_NTP_SRV (LWIP_DHCP) - -#define LWIP_IPV6_DHCP6 LWIP_IPV6 - -/* 1 if you want to do an ARP check on the offered address - (recommended if using DHCP). */ -#define DHCP_DOES_ARP_CHECK (LWIP_DHCP) - -/* ---------- AUTOIP options ------- */ -#define LWIP_AUTOIP (LWIP_DHCP) -#define LWIP_DHCP_AUTOIP_COOP (LWIP_DHCP) -#define LWIP_DHCP_AUTOIP_COOP_TRIES 3 - -/* ---------- NETBIOS options ---------- */ -#define LWIP_NETBIOS_RESPOND_NAME_QUERY 1 - -/* ---------- SNTP options --------- */ -#include "examples/sntp/sntp_example.h" -#define SNTP_SET_SYSTEM_TIME(s) sntp_set_system_time(s) - -/* ---------- SNMP options ---------- */ -#define LWIP_SNMP (LWIP_UDP) -#ifdef LWIP_HAVE_MBEDTLS -#define LWIP_SNMP_V3 (LWIP_SNMP) -#endif -#define MIB2_STATS (LWIP_SNMP) -#define SNMP_USE_NETCONN (LWIP_NETCONN) -#define SNMP_USE_RAW (!LWIP_NETCONN) - -/* ---------- DNS options ---------- */ -#define LWIP_DNS 1 - -/* ---------- MDNS options ---------- */ -#define LWIP_MDNS_RESPONDER 1 -#define LWIP_NUM_NETIF_CLIENT_DATA (LWIP_MDNS_RESPONDER) - -/* ---------- UDP options ---------- */ -#define LWIP_UDP 1 -#define UDP_TTL 255 - -/* ---------- RAW options ---------- */ -#define LWIP_RAW 1 -#define RAW_TTL 255 - -/* ---------- Statistics options ---------- */ -/* individual STATS options can be turned off by defining them to 0 - * (e.g #define TCP_STATS 0). All of them are turned off if LWIP_STATS - * is 0 - * */ - -#define LWIP_STATS 1 - -#define LWIP_NETIF_API 1 -#define LWIP_NETIF_STATUS_CALLBACK 1 -#define LWIP_NETIF_EXT_STATUS_CALLBACK 1 -#define LWIP_NETIF_HOSTNAME 0 - -/* ---------- SLIP options ---------- */ - -#define LWIP_HAVE_SLIPIF 0 /* Set > 0 for SLIP */ - -/* Maximum packet size that is received by this netif */ -#define SLIP_MAX_SIZE 1500 -#define sio_tryread sio_read - -/* ---------- 6LoWPAN options ---------- */ -#define LWIP_6LOWPAN 1 - -/* ---------- PPP options ---------- */ - -#define PPP_SUPPORT 1 /* Set > 0 for PPP */ -#define MPPE_SUPPORT PPP_SUPPORT -#define PPPOE_SUPPORT PPP_SUPPORT -#define PPPOL2TP_SUPPORT PPP_SUPPORT -#define PPPOS_SUPPORT PPP_SUPPORT - -#if PPP_SUPPORT > 0 - -#define NUM_PPP 1 /* Max PPP sessions. */ - - -/* Select modules to enable. Ideally these would be set in the makefile but - * we're limited by the command line length so you need to modify the settings - * in this file. - */ -#define PAP_SUPPORT 1 /* Set > 0 for PAP. */ -#define CHAP_SUPPORT 1 /* Set > 0 for CHAP. */ -#define MSCHAP_SUPPORT 0 /* Set > 0 for MSCHAP (NOT FUNCTIONAL!) */ -#define CBCP_SUPPORT 0 /* Set > 0 for CBCP (NOT FUNCTIONAL!) */ -#define CCP_SUPPORT 0 /* Set > 0 for CCP (NOT FUNCTIONAL!) */ -#define VJ_SUPPORT 1 /* Set > 0 for VJ header compression. */ -#define MD5_SUPPORT 1 /* Set > 0 for MD5 (see also CHAP) */ - - -/* - * Timeouts. - */ -#define FSM_DEFTIMEOUT 6 /* Timeout time in seconds */ -#define FSM_DEFMAXTERMREQS 2 /* Maximum Terminate-Request transmissions */ -#define FSM_DEFMAXCONFREQS 10 /* Maximum Configure-Request transmissions */ -#define FSM_DEFMAXNAKLOOPS 5 /* Maximum number of nak loops */ - -#define UPAP_DEFTIMEOUT 6 /* Timeout (seconds) for retransmitting req */ -#define UPAP_DEFREQTIME 30 /* Time to wait for auth-req from peer */ - -#define CHAP_DEFTIMEOUT 6 /* Timeout time in seconds */ -#define CHAP_DEFTRANSMITS 10 /* max # times to send challenge */ - - -/* Interval in seconds between keepalive echo requests, 0 to disable. */ -#if 1 -#define LCP_ECHOINTERVAL 0 -#else -#define LCP_ECHOINTERVAL 10 -#endif - -/* Number of unanswered echo requests before failure. */ -#define LCP_MAXECHOFAILS 3 - -/* Max Xmit idle time (in jiffies) before resend flag char. */ -#define PPP_MAXIDLEFLAG 100 - -/* - * Packet sizes - * - * Note - lcp shouldn't be allowed to negotiate stuff outside these - * limits. See lcp.h in the pppd directory. - * (XXX - these constants should simply be shared by lcp.c instead - * of living in lcp.h) - */ -#define PPP_MTU 1500 /* Default MTU (size of Info field) */ -#if 0 -#define PPP_MAXMTU 65535 - (PPP_HDRLEN + PPP_FCSLEN) -#else -#define PPP_MAXMTU 1500 /* Largest MTU we allow */ -#endif -#define PPP_MINMTU 64 -#define PPP_MRU 1500 /* default MRU = max length of info field */ -#define PPP_MAXMRU 1500 /* Largest MRU we allow */ -#define PPP_DEFMRU 296 /* Try for this */ -#define PPP_MINMRU 128 /* No MRUs below this */ - - -#define MAXNAMELEN 256 /* max length of hostname or name for auth */ -#define MAXSECRETLEN 256 /* max length of password or secret */ - -#endif /* PPP_SUPPORT > 0 */ - -#define LWIP_HTTPD_SSI 1 - -/* - --------------------------------------- - ---------- Threading options ---------- - --------------------------------------- -*/ - -#define LWIP_TCPIP_CORE_LOCKING 1 - -#if !NO_SYS -void sys_check_core_locking(void); -#define LWIP_ASSERT_CORE_LOCKED() sys_check_core_locking() -void sys_mark_tcpip_thread(void); -#define LWIP_MARK_TCPIP_THREAD() sys_mark_tcpip_thread() - -#if LWIP_TCPIP_CORE_LOCKING -void sys_lock_tcpip_core(void); -#define LOCK_TCPIP_CORE() sys_lock_tcpip_core() -void sys_unlock_tcpip_core(void); -#define UNLOCK_TCPIP_CORE() sys_unlock_tcpip_core() -#endif -#endif - -#endif /* LWIP_LWIPOPTS_H */ diff --git a/ports/unix/unixsim/simhost.c b/ports/unix/unixsim/simhost.c deleted file mode 100644 index e518eae..0000000 --- a/ports/unix/unixsim/simhost.c +++ /dev/null @@ -1,356 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include -#include -#include -#include - -#include "lwip/opt.h" - -#include "lwip/init.h" -#include "lwip/mem.h" -#include "lwip/memp.h" -#include "lwip/sys.h" -#include "lwip/timeouts.h" -#include "lwip/ip_addr.h" -#include "lwip/stats.h" -#include "lwip/tcp.h" -#include "lwip/inet_chksum.h" -#include "lwip/ip_addr.h" - -#include "arch/perf.h" - -#include "lwip/dns.h" -#include "lwip/dhcp.h" - -#include "lwip/tcpip.h" -#include "lwip/sockets.h" - -#include "netif/tapif.h" -#include "netif/tunif.h" -#include "netif/unixif.h" -#include "netif/dropif.h" -#include "netif/pcapif.h" -#include "netif/tcpdump.h" - -#ifndef LWIP_HAVE_SLIPIF -#define LWIP_HAVE_SLIPIF 0 -#endif -#if LWIP_HAVE_SLIPIF -#include "netif/slipif.h" -#define SLIP_PTY_TEST 1 -#endif - -#include "lwip/apps/httpd.h" -#include "apps/udpecho/udpecho.h" -#include "apps/tcpecho/tcpecho.h" -#include "apps/shell/shell.h" -#include "apps/chargen/chargen.h" -#include "apps/netio/netio.h" -#include "apps/ping/ping.h" -#include "lwip/apps/netbiosns.h" -#include "addons/tcp_isn/tcp_isn.h" - -#include "examples/mdns/mdns_example.h" -#include "examples/mqtt/mqtt_example.h" -#include "examples/ppp/pppos_example.h" -#include "examples/snmp/snmp_example.h" -#include "examples/sntp/sntp_example.h" -#include "examples/tftp/tftp_example.h" - -#if LWIP_RAW -#include "lwip/icmp.h" -#include "lwip/raw.h" -#endif - -#if LWIP_IPV4 -/* (manual) host IP configuration */ -static ip_addr_t ipaddr, netmask, gw; -#endif /* LWIP_IPV4 */ - -struct netif netif; - -/* ping out destination cmd option */ -static unsigned char ping_flag; -static ip_addr_t ping_addr; - -/* nonstatic debug cmd option, exported in lwipopts.h */ -unsigned char debug_flags; - -/** @todo add options for selecting netif, starting DHCP client etc */ -static struct option longopts[] = { - /* turn on debugging output (if build with LWIP_DEBUG) */ - {"debug", no_argument, NULL, 'd'}, - /* help */ - {"help", no_argument, NULL, 'h'}, -#if LWIP_IPV4 - /* gateway address */ - {"gateway", required_argument, NULL, 'g'}, - /* ip address */ - {"ipaddr", required_argument, NULL, 'i'}, - /* netmask */ - {"netmask", required_argument, NULL, 'm'}, - /* ping destination */ - {"ping", required_argument, NULL, 'p'}, -#endif /* LWIP_IPV4 */ - /* new command line options go here! */ - {NULL, 0, NULL, 0} -}; -#define NUM_OPTS ((sizeof(longopts) / sizeof(struct option)) - 1) - -static void init_netifs(void); - -static void -usage(void) -{ - unsigned char i; - - printf("options:\n"); - for (i = 0; i < NUM_OPTS; i++) { - printf("-%c --%s\n",longopts[i].val, longopts[i].name); - } -} - -static void -tcpip_init_done(void *arg) -{ - sys_sem_t *sem; - sem = (sys_sem_t *)arg; - - init_netifs(); - printf("Network interfaces initialized.\n"); - -#if LWIP_TCP - netio_init(); -#endif -#if LWIP_TCP && LWIP_NETCONN - tcpecho_init(); - shell_init(); - httpd_init(); -#endif -#if LWIP_UDP && LWIP_NETCONN - udpecho_init(); -#endif -#if LWIP_SOCKET - chargen_init(); -#endif - -#if LWIP_IPV4 - netbiosns_set_name("simhost"); - netbiosns_init(); -#endif /* LWIP_IPV4 */ - - mdns_example_init(); - mqtt_example_init(); - snmp_example_init(); - sntp_example_init(); - tftp_example_init(); - - sys_sem_signal(sem); -} - -/*-----------------------------------------------------------------------------------*/ -/*-----------------------------------------------------------------------------------*/ - -#if LWIP_HAVE_SLIPIF -/* (manual) host IP configuration */ -#if LWIP_IPV4 -static ip_addr_t ipaddr_slip, netmask_slip, gw_slip; -#endif /* LWIP_IPV4 */ -struct netif slipif; -#endif /* LWIP_HAVE_SLIPIF */ - -#if LWIP_NETIF_STATUS_CALLBACK -static void -netif_status_callback(struct netif *nif) -{ - printf("NETIF: %c%c%d is %s\n", nif->name[0], nif->name[1], nif->num, - netif_is_up(nif) ? "UP" : "DOWN"); -#if LWIP_IPV4 - printf("IPV4: Host at %s ", ip4addr_ntoa(netif_ip4_addr(nif))); - printf("mask %s ", ip4addr_ntoa(netif_ip4_netmask(nif))); - printf("gateway %s\n", ip4addr_ntoa(netif_ip4_gw(nif))); -#endif /* LWIP_IPV4 */ -#if LWIP_IPV6 - printf("IPV6: Host at %s\n", ip6addr_ntoa(netif_ip6_addr(nif, 0))); -#endif /* LWIP_IPV6 */ -#if LWIP_NETIF_HOSTNAME - printf("FQDN: %s\n", netif_get_hostname(nif)); -#endif /* LWIP_NETIF_HOSTNAME */ -} -#endif /* LWIP_NETIF_STATUS_CALLBACK */ - -static void -init_netifs(void) -{ -#if LWIP_HAVE_SLIPIF -#if SLIP_PTY_TEST - u8_t siodev_slip = 3; -#else - u8_t siodev_slip = 0; -#endif - -#if LWIP_IPV4 - netif_add(&slipif, ip_2_ip4(&ipaddr_slip), ip_2_ip4(&netmask_slip), ip_2_ip4(&gw_slip), - LWIP_PTR_NUMERIC_CAST(void*, siodev_slip), slipif_init, tcpip_input); -#else /* LWIP_IPV4 */ - netif_add(&slipif, (void*)&siodev_slip, slipif_init, tcpip_input); -#endif /* LWIP_IPV4 */ -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&slipif, 1); -#endif -#if LWIP_NETIF_STATUS_CALLBACK - netif_set_status_callback(&slipif, netif_status_callback); -#endif /* LWIP_NETIF_STATUS_CALLBACK */ - netif_set_link_up(&slipif); - netif_set_up(&slipif); -#endif /* LWIP_HAVE_SLIPIF */ - - pppos_example_init(); - -#if LWIP_IPV4 -#if LWIP_DHCP - IP_ADDR4(&gw, 0,0,0,0); - IP_ADDR4(&ipaddr, 0,0,0,0); - IP_ADDR4(&netmask, 0,0,0,0); -#endif /* LWIP_DHCP */ - netif_add(&netif, ip_2_ip4(&ipaddr), ip_2_ip4(&netmask), ip_2_ip4(&gw), NULL, tapif_init, tcpip_input); -#else /* LWIP_IPV4 */ - netif_add(&netif, NULL, tapif_init, tcpip_input); -#endif /* LWIP_IPV4 */ -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif, 1); - netif.ip6_autoconfig_enabled = 1; -#endif -#if LWIP_NETIF_STATUS_CALLBACK - netif_set_status_callback(&netif, netif_status_callback); -#endif /* LWIP_NETIF_STATUS_CALLBACK */ - netif_set_default(&netif); - netif_set_up(&netif); - -#if LWIP_DHCP - dhcp_start(&netif); -#endif /* LWIP_DHCP */ -} - -/*-----------------------------------------------------------------------------------*/ -int -main(int argc, char **argv) -{ - sys_sem_t sem; - int ch; - char ip_str[IPADDR_STRLEN_MAX] = {0}; - - /* startup defaults (may be overridden by one or more opts) */ -#if LWIP_IPV4 - IP_ADDR4(&gw, 192,168, 0,1); - IP_ADDR4(&netmask, 255,255,255,0); - IP_ADDR4(&ipaddr, 192,168, 0,2); -#if LWIP_HAVE_SLIPIF - IP_ADDR4(&gw_slip, 192,168, 2, 1); - IP_ADDR4(&netmask_slip, 255,255,255,255); - IP_ADDR4(&ipaddr_slip, 192,168, 2, 2); -#endif -#endif /* LWIP_IPV4 */ - - ping_flag = 0; - /* use debug flags defined by debug.h */ - debug_flags = LWIP_DBG_OFF; - - while ((ch = getopt_long(argc, argv, "dhg:i:m:p:", longopts, NULL)) != -1) { - switch (ch) { - case 'd': - debug_flags |= (LWIP_DBG_ON|LWIP_DBG_TRACE|LWIP_DBG_STATE|LWIP_DBG_FRESH|LWIP_DBG_HALT); - break; - case 'h': - usage(); - exit(0); - break; -#if LWIP_IPV4 - case 'g': - ipaddr_aton(optarg, &gw); - break; - case 'i': - ipaddr_aton(optarg, &ipaddr); - break; - case 'm': - ipaddr_aton(optarg, &netmask); - break; -#endif /* LWIP_IPV4 */ - case 'p': - ping_flag = !0; - ipaddr_aton(optarg, &ping_addr); - strncpy(ip_str,ipaddr_ntoa(&ping_addr),sizeof(ip_str)); - ip_str[sizeof(ip_str)-1] = 0; /* ensure \0 termination */ - printf("Using %s to ping\n", ip_str); - break; - default: - usage(); - break; - } - } - argc -= optind; - argv += optind; - -#ifdef PERF - perf_init("/tmp/simhost.perf"); -#endif /* PERF */ - - printf("System initialized.\n"); - - lwip_init_tcp_isn(sys_now(), (u8_t*)&netif); - - if(sys_sem_new(&sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - tcpip_init(tcpip_init_done, &sem); - sys_sem_wait(&sem); - printf("TCP/IP initialized.\n"); - -#if LWIP_SOCKET - if (ping_flag) { - ping_init(&ping_addr); - } -#endif - - printf("Applications started.\n"); - -#if 0 - stats_display(); -#endif - - /* Block forever. */ - pause(); - return 0; -} -/*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/unixsim/simnode.c b/ports/unix/unixsim/simnode.c deleted file mode 100644 index 6786565..0000000 --- a/ports/unix/unixsim/simnode.c +++ /dev/null @@ -1,167 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include "lwip/debug.h" - -#include - -#include "lwip/mem.h" -#include "lwip/memp.h" -#include "lwip/sys.h" -#include "lwip/tcp.h" -#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */ -#include "lwip/timeouts.h" - -#include "lwip/stats.h" - -#include "lwip/tcpip.h" - -#include "netif/unixif.h" -#include "netif/dropif.h" - -#include "netif/tcpdump.h" - -#include "lwip/ip_addr.h" - -#include "arch/perf.h" - -#include "lwip/apps/httpd.h" -#include "apps/udpecho/udpecho.h" -#include "apps/tcpecho/tcpecho.h" -#include "apps/shell/shell.h" - -#if LWIP_IPV4 /* @todo: IPv6 */ - -/* nonstatic debug cmd option, exported in lwipopts.h */ -unsigned char debug_flags; - -/*-----------------------------------------------------------------------------------*/ -static void -tcp_timeout(void *data) -{ - LWIP_UNUSED_ARG(data); -#if TCP_DEBUG && LWIP_TCP - tcp_debug_print_pcbs(); -#endif /* TCP_DEBUG */ - sys_timeout(5000, tcp_timeout, NULL); -} -/*-----------------------------------------------------------------------------------*/ -struct netif netif_unix; -/*-----------------------------------------------------------------------------------*/ -static void -tcpip_init_done(void *arg) -{ - ip4_addr_t ipaddr, netmask, gw; - sys_sem_t *sem; - sem = (sys_sem_t *)arg; - - IP4_ADDR(&gw, 192,168,1,1); - IP4_ADDR(&ipaddr, 192,168,1,2); - IP4_ADDR(&netmask, 255,255,255,0); - - netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_client, - tcpip_input)); - netif_set_up(&netif_unix); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif_unix, 1); -#endif - /* netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1, - tcpip_input)); */ - -#if LWIP_NETCONN - tcpecho_init(); - shell_init(); -#if LWIP_IPV4 && LWIP_TCP - httpd_init(); -#endif - udpecho_init(); -#endif - - printf("Applications started.\n"); - - sys_timeout(5000, tcp_timeout, NULL); - - sys_sem_signal(sem); -} -/*-----------------------------------------------------------------------------------*/ - -static void -main_thread(void *arg) -{ - sys_sem_t sem; - LWIP_UNUSED_ARG(arg); - - if(sys_sem_new(&sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - tcpip_init(tcpip_init_done, &sem); - sys_sem_wait(&sem); - printf("TCP/IP initialized.\n"); - - /* Block forever. */ - sys_sem_wait(&sem); -} -/*-----------------------------------------------------------------------------------*/ -int -main(void) -{ -#ifdef PERF - perf_init("/tmp/client.perf"); -#endif /* PERF */ - -#if LWIP_IPV4 && LWIP_TCP - tcpdump_init(); -#endif - - printf("System initialized.\n"); - - sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - pause(); - return 0; -} - -#else /* LWIP_IPV4 */ - -int -main(int argc, char **argv) -{ - LWIP_UNUSED_ARG(argc); - LWIP_UNUSED_ARG(argv); - - printf("simnode only works with IPv4\n"); - - return 0; -} - -#endif /* LWIP_IPV4 */ - -/*-----------------------------------------------------------------------------------*/ diff --git a/ports/unix/unixsim/simrouter.c b/ports/unix/unixsim/simrouter.c deleted file mode 100644 index ec01a15..0000000 --- a/ports/unix/unixsim/simrouter.c +++ /dev/null @@ -1,187 +0,0 @@ -/* - * Copyright (c) 2001-2003 Swedish Institute of Computer Science. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without modification, - * are permitted provided that the following conditions are met: - * - * 1. Redistributions of source code must retain the above copyright notice, - * this list of conditions and the following disclaimer. - * 2. 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. - * 3. The name of the author may not be used to endorse or promote products - * derived from this software without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``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 AUTHOR 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. - * - * This file is part of the lwIP TCP/IP stack. - * - * Author: Adam Dunkels - * - */ - -#include "lwip/debug.h" - -#include - -#include "lwip/mem.h" -#include "lwip/memp.h" -#include "lwip/sys.h" -#include "lwip/tcp.h" -#include "lwip/priv/tcp_priv.h" /* for tcp_debug_print_pcbs() */ -#include "lwip/timeouts.h" - -#include "lwip/stats.h" -#include "lwip/tcpip.h" - -#include "netif/tapif.h" -#include "netif/unixif.h" -#include "netif/dropif.h" -#include "netif/tcpdump.h" - -#include "lwip/ip_addr.h" - -#include "arch/perf.h" - -#include "lwip/apps/httpd.h" -#include "apps/udpecho/udpecho.h" -#include "apps/tcpecho/tcpecho.h" -#include "apps/shell/shell.h" - -#if LWIP_IPV4 /* @todo: IPv6 */ - -/* nonstatic debug cmd option, exported in lwipopts.h */ -unsigned char debug_flags; - -/*-----------------------------------------------------------------------------------*/ -static void -tcp_timeout(void *data) -{ - LWIP_UNUSED_ARG(data); -#if TCP_DEBUG && LWIP_TCP - tcp_debug_print_pcbs(); -#endif /* TCP_DEBUG */ - sys_timeout(5000, tcp_timeout, NULL); -} -/*-----------------------------------------------------------------------------------*/ - -struct netif netif_tap, netif_unix; - -/*-----------------------------------------------------------------------------------*/ -static void -tcpip_init_done(void *arg) -{ - ip4_addr_t ipaddr, netmask, gw; - sys_sem_t *sem; - sem = (sys_sem_t *)arg; - - IP4_ADDR(&gw, 192,168,0,1); - IP4_ADDR(&ipaddr, 192,168,0,2); - IP4_ADDR(&netmask, 255,255,255,0); - - netif_set_default(netif_add(&netif_tap, &ipaddr, &netmask, &gw, NULL, tapif_init, - tcpip_input)); - netif_set_up(&netif_tap); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif_tap, 1); -#endif - - IP4_ADDR(&gw, 192,168,1,1); - IP4_ADDR(&ipaddr, 192,168,1,1); - IP4_ADDR(&netmask, 255,255,255,0); - netif_set_default(netif_add(&netif_unix, &ipaddr, &netmask, &gw, NULL, unixif_init_server, - tcpip_input)); - netif_set_up(&netif_unix); -#if LWIP_IPV6 - netif_create_ip6_linklocal_address(&netif_unix, 1); -#endif - - if(system("route add 192.168.1.1 192.168.0.2") != 0) { - return; - } - - if(system("route add 192.168.1.2 192.168.0.2") != 0) { - return; - } - - - /*netif_set_default(netif_add(&ipaddr, &netmask, &gw, NULL, sioslipif_init1, - tcpip_input)); */ - -#if LWIP_NETCONN - tcpecho_init(); - shell_init(); -#if LWIP_IPV4 && LWIP_TCP - httpd_init(); -#endif - udpecho_init(); -#endif - - printf("Applications started.\n"); - - sys_timeout(5000, tcp_timeout, NULL); - - sys_sem_signal(sem); -} - - -static void -main_thread(void *arg) -{ - sys_sem_t sem; - LWIP_UNUSED_ARG(arg); - - if(sys_sem_new(&sem, 0) != ERR_OK) { - LWIP_ASSERT("Failed to create semaphore", 0); - } - tcpip_init(tcpip_init_done, &sem); - sys_sem_wait(&sem); - printf("TCP/IP initialized.\n"); - - /* Block forever. */ - sys_sem_wait(&sem); -} -/*-----------------------------------------------------------------------------------*/ -int -main(void) -{ -#ifdef PERF - perf_init("/tmp/client.perf"); -#endif /* PERF */ - -#if LWIP_IPV4 && LWIP_TCP - tcpdump_init(); -#endif - - printf("System initialized.\n"); - sys_thread_new("main_thread", main_thread, NULL, DEFAULT_THREAD_STACKSIZE, DEFAULT_THREAD_PRIO); - pause(); - return 0; -} - -#else /* LWIP_IPV4 */ - -int -main(int argc, char **argv) -{ - LWIP_UNUSED_ARG(argc); - LWIP_UNUSED_ARG(argv); - - printf("simrouter only works with IPv4\n"); - - return 0; -} - -#endif /* LWIP_IPV4 */ - -/*-----------------------------------------------------------------------------------*/