From 8e9a3fcfa1965f619b9cd837b91c33a193f32935 Mon Sep 17 00:00:00 2001 From: Kinsey Moore Date: Thu, 4 Aug 2022 14:09:31 -0500 Subject: rtemslwip: Add functions for BSD compatibility Add wrappers where possible and new functionality required to run code developed for operation on *BSD. This also simplifies the code that utilizes rtems lwip locking and makes it more consistent. --- lwip.py | 4 +- rtemslwip/bsd_compat/ifaddrs.c | 105 +++ rtemslwip/bsd_compat/netdb.c | 115 +++ rtemslwip/bsd_compat/rtems-kernel-program.c | 89 +++ rtemslwip/bsd_compat_include/arpa/nameser.h | 0 rtemslwip/bsd_compat_include/bsd_compat.h | 36 + rtemslwip/bsd_compat_include/ifaddrs.h | 41 + .../machine/rtems-bsd-kernel-space.h | 0 .../bsd_compat_include/machine/rtems-bsd-thread.h | 33 + .../machine/rtems-bsd-user-space.h | 0 rtemslwip/bsd_compat_include/net/if_var.h | 0 rtemslwip/bsd_compat_include/net/route.h | 38 + rtemslwip/bsd_compat_include/netinet/in_systm.h | 0 rtemslwip/bsd_compat_include/netinet/in_var.h | 0 rtemslwip/bsd_compat_include/netinet/ip.h | 0 rtemslwip/bsd_compat_include/resolv.h | 32 + rtemslwip/bsd_compat_include/sys/kernel.h | 0 rtemslwip/bsd_compat_include/sysexits.h | 0 rtemslwip/common/network_compat.c | 57 ++ rtemslwip/common/rtems_lwip_io.c | 836 +++++++-------------- rtemslwip/common/rtems_lwip_sysdefs.c | 185 ----- rtemslwip/common/syslog.c | 6 + rtemslwip/include/rtems_lwip_int.h | 92 --- rtemslwip/zynqmp/lwipopts.h | 2 + 24 files changed, 844 insertions(+), 827 deletions(-) create mode 100644 rtemslwip/bsd_compat/ifaddrs.c create mode 100644 rtemslwip/bsd_compat/netdb.c create mode 100644 rtemslwip/bsd_compat/rtems-kernel-program.c create mode 100644 rtemslwip/bsd_compat_include/arpa/nameser.h create mode 100644 rtemslwip/bsd_compat_include/bsd_compat.h create mode 100644 rtemslwip/bsd_compat_include/ifaddrs.h create mode 100644 rtemslwip/bsd_compat_include/machine/rtems-bsd-kernel-space.h create mode 100644 rtemslwip/bsd_compat_include/machine/rtems-bsd-thread.h create mode 100644 rtemslwip/bsd_compat_include/machine/rtems-bsd-user-space.h create mode 100644 rtemslwip/bsd_compat_include/net/if_var.h create mode 100644 rtemslwip/bsd_compat_include/net/route.h create mode 100644 rtemslwip/bsd_compat_include/netinet/in_systm.h create mode 100644 rtemslwip/bsd_compat_include/netinet/in_var.h create mode 100644 rtemslwip/bsd_compat_include/netinet/ip.h create mode 100644 rtemslwip/bsd_compat_include/resolv.h create mode 100644 rtemslwip/bsd_compat_include/sys/kernel.h create mode 100644 rtemslwip/bsd_compat_include/sysexits.h create mode 100644 rtemslwip/common/network_compat.c delete mode 100644 rtemslwip/common/rtems_lwip_sysdefs.c delete mode 100644 rtemslwip/include/rtems_lwip_int.h diff --git a/lwip.py b/lwip.py index e63f4e6..251f11f 100644 --- a/lwip.py +++ b/lwip.py @@ -75,8 +75,8 @@ def build(bld): source_files.append('./uLan/ports/os/rtems/arch/sys_arch.c') source_files.append('./rtemslwip/common/syslog.c') source_files.append('./rtemslwip/common/rtems_lwip_io.c') - source_files.append('./rtemslwip/common/rtems_lwip_sysdefs.c') - + source_files.append('./rtemslwip/common/network_compat.c') + def walk_sources(path): sources = [] for root, dirs, files in os.walk(path): diff --git a/rtemslwip/bsd_compat/ifaddrs.c b/rtemslwip/bsd_compat/ifaddrs.c new file mode 100644 index 0000000..dc6b7f2 --- /dev/null +++ b/rtemslwip/bsd_compat/ifaddrs.c @@ -0,0 +1,105 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +static struct ifaddrs *create_ifaddr_from_netif(struct netif *netif) +{ + struct ifaddrs *ifaddr = malloc(sizeof(struct ifaddrs)); + if ( ifaddr == NULL ) { + return NULL; + } + ifaddr->ifa_next = NULL; + ifaddr->ifa_name = netif->name; + + ifaddr->ifa_flags = 0; + if ( netif->flags & NETIF_FLAG_UP ) { + ifaddr->ifa_flags |= IFF_RUNNING; + } + if ( netif->flags & NETIF_FLAG_LINK_UP ) { + ifaddr->ifa_flags |= IFF_UP; + } + if ( netif->flags & NETIF_FLAG_BROADCAST ) { + ifaddr->ifa_flags |= IFF_BROADCAST; + } + + ifaddr->ifa_addr = malloc(sizeof(struct sockaddr)); + ifaddr->ifa_netmask = malloc(sizeof(struct sockaddr)); + ifaddr->ifa_dstaddr = malloc(sizeof(struct sockaddr)); + if ( ifaddr->ifa_addr == NULL + || ifaddr->ifa_netmask == NULL + || ifaddr->ifa_dstaddr == NULL ) { + freeifaddrs(ifaddr); + return NULL; + } + + ifaddr->ifa_addr->sa_family = AF_INET; + ifaddr->ifa_netmask->sa_family = AF_INET; + ifaddr->ifa_dstaddr->sa_family = AF_INET; +#define inet_addr_from_ip4addr(target_inaddr, source_ipaddr) ((target_inaddr)->s_addr = ip4_addr_get_u32(source_ipaddr)) + inet_addr_from_ip4addr(&((struct sockaddr_in *)ifaddr->ifa_addr)->sin_addr, &netif->ip_addr.u_addr.ip4); + inet_addr_from_ip4addr(&((struct sockaddr_in *)ifaddr->ifa_netmask)->sin_addr, &netif->netmask.u_addr.ip4); + ((struct sockaddr_in *)ifaddr->ifa_netmask)->sin_addr.s_addr = netif->ip_addr.u_addr.ip4.addr & netif->netmask.u_addr.ip4.addr; + return ifaddr; +} + +int getifaddrs(struct ifaddrs **ifaddrs) +{ + struct netif *netif; + *ifaddrs = NULL; + + LWIP_ASSERT_CORE_LOCKED(); + + NETIF_FOREACH(netif) { + /* create ifaddr from netif */ + struct ifaddrs *ifaddr = create_ifaddr_from_netif(netif); + if ( ifaddr == NULL ) { + freeifaddrs(*ifaddrs); + *ifaddrs = NULL; + errno = ENOMEM; + return -1; + } + ifaddr->ifa_next = *ifaddrs; + *ifaddrs = ifaddr; + } + + return 0; +} + +void freeifaddrs(struct ifaddrs *ifaddrs) +{ + struct ifaddrs *ifaddr; + while ( ifaddrs != NULL ) { + ifaddr = ifaddrs; + ifaddrs = ifaddrs->ifa_next; + free(ifaddr->ifa_addr); + free(ifaddr->ifa_netmask); + free(ifaddr->ifa_dstaddr); + free(ifaddr); + } +} diff --git a/rtemslwip/bsd_compat/netdb.c b/rtemslwip/bsd_compat/netdb.c new file mode 100644 index 0000000..af6ba6f --- /dev/null +++ b/rtemslwip/bsd_compat/netdb.c @@ -0,0 +1,115 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +static uint16_t getserviceport(const char *target_service) { + FILE* file; + char service[16]; + char protocol[16]; + uint16_t target_port = 0, port; + int scan_result; + + if ( target_service == NULL ) { + return target_port; + } + + file = fopen(_PATH_SERVICES, "r"); + if ( file == NULL ) { + return target_port; + } + + while ( 1 ) { + scan_result = fscanf(file, "%15s%hu/%15s%*s%*[^\n]", service, &port, protocol); + + /* Check for end of file */ + if (scan_result == EOF) { + break; + } + + /* Check for bad line */ + if (scan_result < 3) { + continue; + } + + if ( strcmp(target_service, service) == 0 ) { + target_port = port; + break; + } + } + + fclose(file); + return target_port; +} + +#undef getaddrinfo +int getaddrinfo( + const char *nodename, + const char *servname, + const struct addrinfo *hints, + struct addrinfo **res) +{ + char aport[16]; + itoa(getserviceport(servname), aport, 10); + return lwip_getaddrinfo(nodename, aport, hints, res); +} + +#undef freeaddrinfo +void freeaddrinfo(struct addrinfo *a1) +{ + lwip_freeaddrinfo(a1); +} + +const char *gai_strerror(int err) +{ + switch ( err ) { + case EAI_OVERFLOW: return "EAI_OVERFLOW"; + case EAI_SOCKTYPE: return "EAI_SOCKTYPE"; + case EAI_SYSTEM: return "EAI_SYSTEM"; + case EAI_BADHINTS: return "EAI_BADHINTS"; + case EAI_PROTOCOL: return "EAI_PROTOCOL"; + case EAI_NONAME: return "EAI_NONAME"; + case EAI_SERVICE: return "EAI_SERVICE"; + case EAI_FAIL: return "EAI_FAIL"; + case EAI_MEMORY: return "EAI_MEMORY"; + case EAI_FAMILY: return "EAI_FAMILY"; + default: return "UNKNOWN EAI"; + } +} + +#include + +#undef if_nametoindex +unsigned int if_nametoindex(const char *ifname) +{ + return lwip_if_nametoindex(ifname); +} + +int res_init() +{ + return 0; +} diff --git a/rtemslwip/bsd_compat/rtems-kernel-program.c b/rtemslwip/bsd_compat/rtems-kernel-program.c new file mode 100644 index 0000000..ae80e51 --- /dev/null +++ b/rtemslwip/bsd_compat/rtems-kernel-program.c @@ -0,0 +1,89 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include + +#include +#include + +#undef printf +#define RTEMS_BSD_PROGRAM_NO_STRDUP_WRAP +#define RTEMS_BSD_PROGRAM_NO_STRNDUP_WRAP +#include + +#include +#include +#include +#include + +static size_t rtems_bsd_extension_index; + +static const rtems_extensions_table rtems_bsd_extensions = {}; + +/* + * This must only be run after the system has become multithreading such as in + * Init(). This must not be run as part of normal RTEMS initialization as part + * of a SYSINIT call. + */ +void rtems_bsd_compat_initialize(void) +{ + rtems_id ext_id; + rtems_status_code sc; + + sc = rtems_extension_create( + BSD_TASK_NAME, + &rtems_bsd_extensions, + &ext_id + ); + if (sc != RTEMS_SUCCESSFUL) { + printf("%s: cannot create extension\n", __func__); + rtems_task_suspend(RTEMS_SELF); + rtems_fatal_error_occurred(0xdeadbeef); + } + + rtems_bsd_extension_index = rtems_object_id_get_index(ext_id); +} + +static struct rtems_bsd_program_control ** +rtems_bsd_get_bsd_extension_ptr(void) +{ + Thread_Control *executing = _Thread_Get_executing(); + return ( struct rtems_bsd_program_control ** )&executing->extensions[rtems_bsd_extension_index]; +} + +struct rtems_bsd_program_control * +rtems_bsd_program_get_control_or_null(void) +{ + return *rtems_bsd_get_bsd_extension_ptr(); +} + +int +rtems_bsd_program_set_control(struct rtems_bsd_program_control *prog_ctrl) +{ + *rtems_bsd_get_bsd_extension_ptr() = prog_ctrl; + return 0; +} diff --git a/rtemslwip/bsd_compat_include/arpa/nameser.h b/rtemslwip/bsd_compat_include/arpa/nameser.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/bsd_compat.h b/rtemslwip/bsd_compat_include/bsd_compat.h new file mode 100644 index 0000000..f6691d2 --- /dev/null +++ b/rtemslwip/bsd_compat_include/bsd_compat.h @@ -0,0 +1,36 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMSLWIP_BSD_COMPAT_H +#define _RTEMSLWIP_BSD_COMPAT_H + +/* + * Initializes the BSD compatibility layer required for using BSD functionality + * under lwIP. Must be called from Init(). + */ +void rtems_bsd_compat_initialize(void); + +#endif diff --git a/rtemslwip/bsd_compat_include/ifaddrs.h b/rtemslwip/bsd_compat_include/ifaddrs.h new file mode 100644 index 0000000..f1be700 --- /dev/null +++ b/rtemslwip/bsd_compat_include/ifaddrs.h @@ -0,0 +1,41 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMSLWIP_IFADDRS_H +#define _RTEMSLWIP_IFADDRS_H +struct ifaddrs { + struct ifaddrs *ifa_next; + char *ifa_name; + unsigned int ifa_flags; + struct sockaddr *ifa_addr; + struct sockaddr *ifa_netmask; + struct sockaddr *ifa_dstaddr; +#define ifa_broadaddr ifa_dstaddr /* broadcast address interface */ +}; + +int getifaddrs(struct ifaddrs **); +void freeifaddrs(struct ifaddrs *); +#endif diff --git a/rtemslwip/bsd_compat_include/machine/rtems-bsd-kernel-space.h b/rtemslwip/bsd_compat_include/machine/rtems-bsd-kernel-space.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/machine/rtems-bsd-thread.h b/rtemslwip/bsd_compat_include/machine/rtems-bsd-thread.h new file mode 100644 index 0000000..7408d1c --- /dev/null +++ b/rtemslwip/bsd_compat_include/machine/rtems-bsd-thread.h @@ -0,0 +1,33 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMSLWIP_RTEMS_BSD_THREAD_H +#define _RTEMSLWIP_RTEMS_BSD_THREAD_H +#include +#include + +#define BSD_TASK_NAME rtems_build_name('_', 'B', 'S', 'D') +#endif diff --git a/rtemslwip/bsd_compat_include/machine/rtems-bsd-user-space.h b/rtemslwip/bsd_compat_include/machine/rtems-bsd-user-space.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/net/if_var.h b/rtemslwip/bsd_compat_include/net/if_var.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/net/route.h b/rtemslwip/bsd_compat_include/net/route.h new file mode 100644 index 0000000..9948aef --- /dev/null +++ b/rtemslwip/bsd_compat_include/net/route.h @@ -0,0 +1,38 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMSLWIP_ROUTE_H +#define _RTEMSLWIP_ROUTE_H +struct rt_metrics {}; + +struct rt_msghdr { + uint16_t rtm_msglen; + uint8_t rtm_version; + uint8_t rtm_type; +}; + +#define RTM_VERSION 5 +#endif diff --git a/rtemslwip/bsd_compat_include/netinet/in_systm.h b/rtemslwip/bsd_compat_include/netinet/in_systm.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/netinet/in_var.h b/rtemslwip/bsd_compat_include/netinet/in_var.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/netinet/ip.h b/rtemslwip/bsd_compat_include/netinet/ip.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/resolv.h b/rtemslwip/bsd_compat_include/resolv.h new file mode 100644 index 0000000..ef729fa --- /dev/null +++ b/rtemslwip/bsd_compat_include/resolv.h @@ -0,0 +1,32 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#ifndef _RTEMSLWIP_RESOLV_H +#define _RTEMSLWIP_RESOLV_H + +int res_init( void ); + +#endif diff --git a/rtemslwip/bsd_compat_include/sys/kernel.h b/rtemslwip/bsd_compat_include/sys/kernel.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/bsd_compat_include/sysexits.h b/rtemslwip/bsd_compat_include/sysexits.h new file mode 100644 index 0000000..e69de29 diff --git a/rtemslwip/common/network_compat.c b/rtemslwip/common/network_compat.c new file mode 100644 index 0000000..e13c56a --- /dev/null +++ b/rtemslwip/common/network_compat.c @@ -0,0 +1,57 @@ +/* + * Copyright (C) 2022 On-Line Applications Research Corporation (OAR) + * Written by Kinsey Moore + * + * 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. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ + +#include +#include +#include +#include +#include + +in_addr_t inet_addr(const char *cp) +{ + return ipaddr_addr(cp); +} + +int inet_aton(const char *cp, struct in_addr *addr) +{ + return ip4addr_aton(cp, (ip4_addr_t*)addr); +} + +char *inet_ntoa(struct in_addr addr) +{ + return ip4addr_ntoa((const ip4_addr_t*)&(addr)); +} + +char *inet_ntoa_r(struct in_addr addr, char *buf, socklen_t buflen) +{ + return ip4addr_ntoa_r((const ip4_addr_t*)&(addr), buf, buflen); +} + +#undef htons +uint16_t htons(uint16_t x) +{ + return lwip_htons(x); +} diff --git a/rtemslwip/common/rtems_lwip_io.c b/rtemslwip/common/rtems_lwip_io.c index 8aa28b5..ee34774 100644 --- a/rtemslwip/common/rtems_lwip_io.c +++ b/rtemslwip/common/rtems_lwip_io.c @@ -77,8 +77,6 @@ #include "lwip/sockets.h" #include "lwip/sys.h" -#include "rtems_lwip_int.h" - static const rtems_filesystem_file_handlers_r rtems_lwip_socket_handlers; static rtems_recursive_mutex rtems_lwip_mutex = @@ -173,45 +171,106 @@ int socket( int fd; int lwipfd; - if ( domain == rtems_lwip_sysdefs_PF_UNSPEC ) { - domain = PF_UNSPEC; - } else if ( domain == rtems_lwip_sysdefs_PF_INET ) { - domain = PF_INET; - } else if ( domain == rtems_lwip_sysdefs_PF_INET6 ) { - domain = PF_INET6; - } else { - errno = EINVAL; + rtems_lwip_semaphore_obtain(); + + lwipfd = lwip_socket( domain, type, 0 ); + if ( lwipfd < 0 ) { return -1; } - if ( type == rtems_lwip_sysdefs_SOCK_STREAM ) { - type = SOCK_STREAM; - } else if ( type == rtems_lwip_sysdefs_SOCK_DGRAM ) { - type = SOCK_DGRAM; - } else { - errno = EINVAL; + fd = rtems_lwip_make_sysfd_from_lwipfd( lwipfd ); - return -1; + if ( fd < 0 ) { + lwip_close( lwipfd ); } - rtems_lwip_semaphore_obtain(); + rtems_lwip_semaphore_release(); - lwipfd = lwip_socket( domain, type, 0 ); + return fd; +} - if ( lwipfd < 0 ) { - fd = -1; - } else { - fd = rtems_lwip_make_sysfd_from_lwipfd( lwipfd ); +static int setup_socketpair(int listener, int *socket_vector) +{ + union { + struct sockaddr addr; + struct sockaddr_in inaddr; + } a; + int reuse = 1; + socklen_t addrlen = sizeof(a.inaddr); + + memset(&a, 0, sizeof(a)); + a.inaddr.sin_family = AF_INET; + a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + a.inaddr.sin_port = 0; + + if (setsockopt(listener, SOL_SOCKET, SO_REUSEADDR, + (char*) &reuse, (socklen_t) sizeof(reuse)) == -1) { + return 1; + } - if ( fd < 0 ) { - lwip_close( lwipfd ); - } + if (bind(listener, &a.addr, sizeof(a.inaddr)) == -1) { + return 1; } - rtems_lwip_semaphore_release(); + memset(&a, 0, sizeof(a)); + if (getsockname(listener, &a.addr, &addrlen) == -1) { + return 1; + } - return fd; + a.inaddr.sin_addr.s_addr = htonl(INADDR_LOOPBACK); + a.inaddr.sin_family = AF_INET; + + if (listen(listener, 1) == -1) { + return 1; + } + + socket_vector[0] = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (socket_vector[0] == -1) { + return 1; + } + + if (connect(socket_vector[0], &a.addr, sizeof(a.inaddr)) == -1) { + return 1; + } + + socket_vector[1] = accept(listener, NULL, NULL); + if (socket_vector[1] == -1) { + return 1; + } + + close(listener); + return 0; +} + +/* Fake socketpair() support with a loopback TCP socket */ +int +socketpair(int domain, int type, int protocol, int *socket_vector) +{ + int listener; + int saved_errno; + + if (socket_vector == NULL) { + errno = EINVAL; + return -1; + } + socket_vector[0] = socket_vector[1] = -1; + + listener = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP); + if (listener == -1) + return -1; + + if (setup_socketpair(listener, socket_vector) == 0) { + return 0; + } + + saved_errno = errno; + close(listener); + close(socket_vector[0]); + close(socket_vector[1]); + errno = saved_errno; + socket_vector[0] = socket_vector[1] = -1; + return -1; } int bind( @@ -220,59 +279,17 @@ int bind( socklen_t namelen ) { - int ret = -1; int lwipfd; - int family; - struct sockaddr *lwipname; - socklen_t lwipnamelen; - struct sockaddr_in so_in; - - #if LWIP_IPV6 - struct sockaddr_in6 so_in6; - #endif - - family = rtems_lwip_sysdefs_sockaddr_get_family( name ); - - if ( ( family == rtems_lwip_sysdefs_AF_INET ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in_size ) ) { - so_in.sin_len = sizeof( so_in ); - so_in.sin_family = PF_INET; - so_in.sin_port = rtems_lwip_sysdefs_sockaddr_in_get_sin_port( name ); - so_in.sin_addr.s_addr = - rtems_lwip_sysdefs_sockaddr_in_get_sin_addr( name ); - lwipname = (struct sockaddr *) &so_in; - lwipnamelen = so_in.sin_len; - #if LWIP_IPV6 - } else if ( ( family == rtems_lwip_sysdefs_AF_INET6 ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in6_size ) ) { - so_in6.sin6_len = sizeof( so_in6 ); - so_in6.sin6_family = PF_INET6; - so_in6.sin6_port = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_port( name ); - memcpy( &so_in6.sin6_addr, - rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr_const( name ), - sizeof( so_in6.sin6_addr ) ); - so_in6.sin6_flowinfo = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_flowinfo( - name ); - so_in6.sin6_scope_id = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_scope_id( - name ); - lwipname = (struct sockaddr *) &so_in6; - lwipnamelen = so_in6.sin6_len; - #endif - } else { - errno = EINVAL; - - return -1; - } rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - ret = lwip_bind( lwipfd, lwipname, lwipnamelen ); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_bind( lwipfd, name, namelen ); } int connect( @@ -281,59 +298,17 @@ int connect( socklen_t namelen ) { - int ret = -1; int lwipfd; - int family; - struct sockaddr *lwipname; - socklen_t lwipnamelen; - struct sockaddr_in so_in; - - #if LWIP_IPV6 - struct sockaddr_in6 so_in6; - #endif - - family = rtems_lwip_sysdefs_sockaddr_get_family( name ); - - if ( ( family == rtems_lwip_sysdefs_AF_INET ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in_size ) ) { - so_in.sin_len = sizeof( so_in ); - so_in.sin_family = AF_INET; - so_in.sin_port = rtems_lwip_sysdefs_sockaddr_in_get_sin_port( name ); - so_in.sin_addr.s_addr = - rtems_lwip_sysdefs_sockaddr_in_get_sin_addr( name ); - lwipname = (struct sockaddr *) &so_in; - lwipnamelen = so_in.sin_len; - #if LWIP_IPV6 - } else if ( ( family == rtems_lwip_sysdefs_AF_INET6 ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in6_size ) ) { - so_in6.sin6_len = sizeof( so_in6 ); - so_in6.sin6_family = AF_INET6; - so_in6.sin6_port = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_port( name ); - memcpy( &so_in6.sin6_addr, - rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr_const( name ), - sizeof( so_in6.sin6_addr ) ); - so_in6.sin6_flowinfo = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_flowinfo( - name ); - so_in6.sin6_scope_id = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_scope_id( - name ); - lwipname = (struct sockaddr *) &so_in6; - lwipnamelen = so_in6.sin6_len; - #endif - } else { - errno = EINVAL; - - return -1; - } rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - ret = lwip_connect( lwipfd, lwipname, lwipnamelen ); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_connect( lwipfd, name, namelen ); } int listen( @@ -341,18 +316,17 @@ int listen( int backlog ) { - int ret = -1; int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - ret = lwip_listen( lwipfd, backlog ); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_listen( lwipfd, backlog ); } int accept( @@ -363,72 +337,25 @@ int accept( { int ret = -1; int lwipfd; - struct sockaddr *lwipname = name; - socklen_t lwipnamelen = *namelen; - struct sockaddr_in so_in; - - #if LWIP_IPV6 - struct sockaddr_in6 so_in6; - #endif rtems_lwip_semaphore_obtain(); - - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - - rtems_lwip_semaphore_release(); - lwipfd = lwip_accept( lwipfd, lwipname, &lwipnamelen ); - rtems_lwip_semaphore_obtain(); - } - + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); rtems_lwip_semaphore_release(); - if ( lwipfd < 0 ) - return lwipfd; - - if ( lwipname->sa_family == AF_INET ) { - memcpy( &so_in, lwipname, sizeof( so_in ) ); - rtems_lwip_sysdefs_sockaddr_set_len( name, - rtems_lwip_sysdefs_sockaddr_in_size ); - rtems_lwip_sysdefs_sockaddr_set_family( name, rtems_lwip_sysdefs_AF_INET ); - rtems_lwip_sysdefs_sockaddr_in_set_sin_port( name, so_in.sin_port ); - rtems_lwip_sysdefs_sockaddr_in_set_sin_addr( name, so_in.sin_addr.s_addr ); - #if LWIP_IPV6 - } else if ( lwipname->sa_family == AF_INET6 ) { - memcpy( &so_in6, lwipname, sizeof( so_in6 ) ); - rtems_lwip_sysdefs_sockaddr_set_len( name, - rtems_lwip_sysdefs_sockaddr_in6_size ); - rtems_lwip_sysdefs_sockaddr_set_family( name, - rtems_lwip_sysdefs_AF_INET6 ); - - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_port( name, so_in6.sin6_port ); - memcpy( rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr( name ), - &so_in6.sin6_addr, - sizeof( so_in6.sin6_addr ) ); - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_flowinfo( name, - so_in6.sin6_flowinfo ); - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_scope_id( name, - so_in6.sin6_scope_id ); - #endif - } else { - lwip_close( lwipfd ); - errno = EINVAL; - + if ( lwipfd < 0 ) { return -1; } + lwipfd = lwip_accept( lwipfd, name, namelen ); + rtems_lwip_semaphore_obtain(); ret = rtems_lwip_make_sysfd_from_lwipfd( lwipfd ); + rtems_lwip_semaphore_release(); if ( ret < 0 ) { - rtems_lwip_semaphore_release(); lwip_close( lwipfd ); - rtems_lwip_semaphore_obtain(); } - rtems_lwip_semaphore_release(); - - *namelen = rtems_lwip_sysdefs_sockaddr_get_len( name ); - return ret; } @@ -441,20 +368,17 @@ int shutdown( int how ) { - int ret = -1; int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - rtems_lwip_semaphore_release(); - ret = lwip_shutdown( lwipfd, how ); - rtems_lwip_semaphore_obtain(); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_shutdown( lwipfd, how ); } ssize_t recv( @@ -464,20 +388,17 @@ ssize_t recv( int flags ) { - int ret = -1; int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - rtems_lwip_semaphore_release(); - ret = lwip_recv( lwipfd, buf, len, flags ); - rtems_lwip_semaphore_obtain(); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_recv( lwipfd, buf, len, flags ); } ssize_t send( @@ -487,20 +408,17 @@ ssize_t send( int flags ) { - int ret = -1; int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - rtems_lwip_semaphore_release(); - ret = lwip_send( lwipfd, buf, len, flags ); - rtems_lwip_semaphore_obtain(); + if ( lwipfd < 0 ) { + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_send( lwipfd, buf, len, flags ); } ssize_t recvfrom( @@ -512,75 +430,20 @@ ssize_t recvfrom( socklen_t *namelen ) { - int ret = -1; int lwipfd; - struct sockaddr *lwipname = name; - socklen_t lwipnamelen = *namelen; - struct sockaddr_in so_in; - - #if LWIP_IPV6 - struct sockaddr_in6 so_in6; - #endif if ( name == NULL ) return recv( s, buf, len, flags ); rtems_lwip_semaphore_obtain(); - - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - rtems_lwip_semaphore_release(); - lwipfd = lwip_recvfrom( lwipfd, buf, len, flags, lwipname, &lwipnamelen ); - rtems_lwip_semaphore_obtain(); - } - + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); rtems_lwip_semaphore_release(); - if ( lwipfd < 0 ) - return lwipfd; - - if ( lwipname->sa_family == AF_INET ) { - memcpy( &so_in, lwipname, sizeof( so_in ) ); - rtems_lwip_sysdefs_sockaddr_set_len( name, - rtems_lwip_sysdefs_sockaddr_in_size ); - rtems_lwip_sysdefs_sockaddr_set_family( name, rtems_lwip_sysdefs_AF_INET ); - rtems_lwip_sysdefs_sockaddr_in_set_sin_port( name, so_in.sin_port ); - rtems_lwip_sysdefs_sockaddr_in_set_sin_addr( name, so_in.sin_addr.s_addr ); - #if LWIP_IPV6 - } else if ( lwipname->sa_family == AF_INET6 ) { - memcpy( &so_in6, lwipname, sizeof( so_in6 ) ); - rtems_lwip_sysdefs_sockaddr_set_len( name, - rtems_lwip_sysdefs_sockaddr_in6_size ); - rtems_lwip_sysdefs_sockaddr_set_family( name, - rtems_lwip_sysdefs_AF_INET6 ); - - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_port( name, so_in6.sin6_port ); - memcpy( rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr( name ), - &so_in6.sin6_addr, - sizeof( so_in6.sin6_addr ) ); - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_flowinfo( name, - so_in6.sin6_flowinfo ); - rtems_lwip_sysdefs_sockaddr_in6_set_sin6_scope_id( name, - so_in6.sin6_scope_id ); - #endif - } else { - lwip_close( lwipfd ); - errno = EINVAL; - + if ( lwipfd < 0 ) { return -1; } - rtems_lwip_semaphore_obtain(); - ret = rtems_lwip_make_sysfd_from_lwipfd( lwipfd ); - - if ( ret < 0 ) { - lwip_close( lwipfd ); - } - - rtems_lwip_semaphore_release(); - - *namelen = rtems_lwip_sysdefs_sockaddr_get_len( name ); - - return ret; + return lwip_recvfrom( lwipfd, buf, len, flags, name, namelen ); } ssize_t sendto( @@ -592,61 +455,118 @@ ssize_t sendto( socklen_t namelen ) { - int ret = -1; int lwipfd; - int family; - struct sockaddr *lwipname; - socklen_t lwipnamelen; - struct sockaddr_in so_in; - - #if LWIP_IPV6 - struct sockaddr_in6 so_in6; - #endif if ( name == NULL ) return send( s, buf, len, flags ); - family = rtems_lwip_sysdefs_sockaddr_get_family( name ); - - if ( ( family == rtems_lwip_sysdefs_AF_INET ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in_size ) ) { - so_in.sin_len = sizeof( so_in ); - so_in.sin_family = AF_INET; - so_in.sin_port = rtems_lwip_sysdefs_sockaddr_in_get_sin_port( name ); - so_in.sin_addr.s_addr = - rtems_lwip_sysdefs_sockaddr_in_get_sin_addr( name ); - lwipname = (struct sockaddr *) &so_in; - lwipnamelen = so_in.sin_len; - #if LWIP_IPV6 - } else if ( ( family == rtems_lwip_sysdefs_AF_INET6 ) && - ( namelen >= rtems_lwip_sysdefs_sockaddr_in6_size ) ) { - so_in6.sin6_len = sizeof( so_in6 ); - so_in6.sin6_family = AF_INET6; - so_in6.sin6_port = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_port( name ); - memcpy( &so_in6.sin6_addr, - rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr_const( name ), - sizeof( so_in6.sin6_addr ) ); - so_in6.sin6_flowinfo = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_flowinfo( - name ); - so_in6.sin6_scope_id = rtems_lwip_sysdefs_sockaddr_in6_get_sin6_scope_id( - name ); - lwipname = (struct sockaddr *) &so_in6; - lwipnamelen = so_in6.sin6_len; - #endif - } else { - errno = EINVAL; + rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); + if ( lwipfd < 0 ) { return -1; } + return lwip_sendto( lwipfd, buf, len, flags, name, namelen ); +} + +static int fdset_sysfd_to_lwipfd( int maxfdp1, fd_set *orig_set, fd_set *mapped_set ) +{ + int new_max = 0; + FD_ZERO( mapped_set ); + + if ( orig_set == NULL ) { + return new_max; + } + + for ( int sysfd = 0; sysfd < maxfdp1; sysfd++ ) { + int lwipfd; + + if ( FD_ISSET( sysfd, orig_set ) == 0 ) { + continue; + } + + lwipfd = rtems_lwip_sysfd_to_lwipfd( sysfd ); + if ( lwipfd < 0 ) { + return -1; + } + + if ( lwipfd > (new_max - 1) ) { + new_max = lwipfd + 1; + } + + FD_SET( lwipfd, mapped_set ); + } + return new_max; +} + +static void fdset_lwipfd_to_sysfd( int maxfdp1, fd_set *orig_set, fd_set *mapped_set ) +{ + fd_set new_orig_set; + + FD_ZERO( &new_orig_set ); + + if ( orig_set == NULL ) { + return; + } + + for ( int sysfd = 0; sysfd < maxfdp1; sysfd++ ) { + int lwipfd; + + if ( FD_ISSET( sysfd, orig_set ) == 0 ) { + continue; + } + + lwipfd = rtems_lwip_sysfd_to_lwipfd( sysfd ); + + if ( FD_ISSET( lwipfd, mapped_set ) == 0 ) { + continue; + } + + FD_SET( sysfd, &new_orig_set ); + } + + *orig_set = new_orig_set; +} + +int select(int maxfdp1, fd_set *readset, fd_set *writeset, fd_set *exceptset, + struct timeval *timeout) +{ + int rmaxp1; + int wmaxp1; + int emaxp1; + int newmaxfdp1; + int ret; + fd_set newread, newwrite, newexcept; + + /* Save original FD sets, */ + rtems_lwip_semaphore_obtain(); + rmaxp1 = fdset_sysfd_to_lwipfd( maxfdp1, readset, &newread ); + wmaxp1 = fdset_sysfd_to_lwipfd( maxfdp1, writeset, &newwrite ); + emaxp1 = fdset_sysfd_to_lwipfd( maxfdp1, exceptset, &newexcept ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) >= 0 ) { - rtems_lwip_semaphore_release(); - ret = lwip_sendto( lwipfd, buf, len, flags, lwipname, lwipnamelen ); - rtems_lwip_semaphore_obtain(); + if ( rmaxp1 < 0 || wmaxp1 < 0 || emaxp1 < 0 ) { + errno = ENOSYS; + return -1; + } + + newmaxfdp1 = rmaxp1; + if ( wmaxp1 > newmaxfdp1 ) { + newmaxfdp1 = wmaxp1; + } + if ( emaxp1 > newmaxfdp1 ) { + newmaxfdp1 = emaxp1; } + ret = lwip_select( newmaxfdp1, &newread, &newwrite, &newexcept, timeout ); + + rtems_lwip_semaphore_obtain(); + fdset_lwipfd_to_sysfd( maxfdp1, readset, &newread ); + fdset_lwipfd_to_sysfd( maxfdp1, writeset, &newwrite ); + fdset_lwipfd_to_sysfd( maxfdp1, exceptset, &newexcept ); rtems_lwip_semaphore_release(); return ret; @@ -750,6 +670,8 @@ ssize_t sendmsg( return ( ret ); } +#endif + /* * All `receive' operations end up calling this routine. */ @@ -759,113 +681,19 @@ ssize_t recvmsg( int flags ) { - int ret = -1; - int error; - struct uio auio; - struct iovec *iov; - int lwipfd; - struct mbuf *from = NULL, *control = NULL; - int i; - int len; + int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( so = rtems_lwip_sysfd_to_lwipfd( s ) ) == NULL ) { - rtems_lwip_semaphore_release(); - + if ( lwipfd < 0 ) { return -1; } - auio.uio_iov = mp->msg_iov; - auio.uio_iovcnt = mp->msg_iovlen; - auio.uio_segflg = UIO_USERSPACE; - auio.uio_rw = UIO_READ; - auio.uio_offset = 0; - auio.uio_resid = 0; - iov = mp->msg_iov; - - for ( i = 0; i < mp->msg_iovlen; i++, iov++ ) { - if ( ( auio.uio_resid += iov->iov_len ) < 0 ) { - errno = EINVAL; - rtems_lwip_semaphore_release(); - - return -1; - } - } - - len = auio.uio_resid; - mp->msg_flags = flags; - error = soreceive( so, &from, &auio, (struct mbuf **) NULL, - mp->msg_control ? &control : (struct mbuf **) NULL, - &mp->msg_flags ); - - if ( error ) { - if ( auio.uio_resid != len && ( error == EINTR || error == EWOULDBLOCK ) ) - error = 0; - } - - if ( error ) { - errno = error; - } else { - ret = len - auio.uio_resid; - - if ( mp->msg_name ) { - len = mp->msg_namelen; - - if ( ( len <= 0 ) || ( from == NULL ) ) { - len = 0; - } else { - if ( len > from->m_len ) - len = from->m_len; - - memcpy( mp->msg_name, mtod( from, caddr_t ), len ); - } - - mp->msg_namelen = len; - } - - if ( mp->msg_control ) { - struct mbuf *m; - void *ctlbuf; - - len = mp->msg_controllen; - m = control; - mp->msg_controllen = 0; - ctlbuf = mp->msg_control; - - while ( m && ( len > 0 ) ) { - unsigned int tocopy; - - if ( len >= m->m_len ) - tocopy = m->m_len; - else { - mp->msg_flags |= MSG_CTRUNC; - tocopy = len; - } - - memcpy( ctlbuf, mtod( m, caddr_t ), tocopy ); - ctlbuf += tocopy; - len -= tocopy; - m = m->m_next; - } - - mp->msg_controllen = ctlbuf - mp->msg_control; - } - } - - if ( from ) - m_freem( from ); - - if ( control ) - m_freem( control ); - - rtems_lwip_semaphore_release(); - - return ( ret ); + return lwip_recvmsg( lwipfd, mp, flags ); } -#endif - int setsockopt( int s, int level, @@ -874,54 +702,19 @@ int setsockopt( socklen_t len ) { - -#if 0 - int lwipfd; - struct mbuf *m = NULL; - int error; + int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( so = rtems_lwip_sysfd_to_lwipfd( s ) ) == NULL ) { - rtems_lwip_semaphore_release(); - - return -1; - } - - if ( len > MLEN ) { - errno = EINVAL; - rtems_lwip_semaphore_release(); - - return -1; - } - - if ( val ) { - error = sockargstombuf( &m, val, len, MT_SOOPTS ); - - if ( error ) { - errno = error; - rtems_lwip_semaphore_release(); - - return -1; - } - } - - error = sosetopt( so, level, name, m ); - - if ( error ) { - errno = error; - rtems_lwip_semaphore_release(); - + if ( lwipfd < 0 ) { return -1; } - rtems_lwip_semaphore_release(); -#endif - return 0; + return lwip_setsockopt( lwipfd, level, name, val, len ); } -#if 0 - int getsockopt( int s, int level, @@ -930,61 +723,21 @@ int getsockopt( socklen_t *avalsize ) { - int lwipfd; - struct mbuf *m = NULL, *m0; - char *val = aval; - int i, op, valsize; - int error; + int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( so = rtems_lwip_sysfd_to_lwipfd( s ) ) == NULL ) { - rtems_lwip_semaphore_release(); - - return -1; - } - - if ( val ) - valsize = *avalsize; - else - valsize = 0; - - if ( ( ( error = - sogetopt( so, level, name, - &m ) ) == 0 ) && val && valsize && m ) { - op = 0; - - while ( m && op < valsize ) { - i = valsize - op; - - if ( i > m->m_len ) - i = m->m_len; - - memcpy( val, mtod( m, caddr_t ), i ); - op += i; - val += i; - m0 = m; - MFREE( m0, m ); - } - - *avalsize = op; - } - - if ( m != NULL ) - (void) m_free( m ); - - if ( error ) { - errno = error; - rtems_lwip_semaphore_release(); - + if ( lwipfd < 0 ) { return -1; } - rtems_lwip_semaphore_release(); - - return 0; + return lwip_getsockopt( lwipfd, level, name, aval, avalsize ); } +#if 0 + static int getpeersockname( int s, struct sockaddr *name, @@ -1047,35 +800,40 @@ int getpeername( socklen_t *namelen ) { - int lwipfd; - int error; + int lwipfd; rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); - if ( ( lwipfd = rtems_lwip_sysfd_to_lwipfd( s ) ) < 0 ) { - rtems_lwip_semaphore_release(); - + if ( lwipfd < 0 ) { return -1; } - error = lwip_getpeername(lwipfd, name, namelen); - - rtems_lwip_semaphore_release(); - - return error; + return lwip_getpeername(lwipfd, name, namelen); } -#if 0 - int getsockname( int s, struct sockaddr *name, socklen_t *namelen ) { - return getpeersockname( s, name, namelen, 0 ); + int lwipfd; + + rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_sysfd_to_lwipfd( s ); + rtems_lwip_semaphore_release(); + + if ( lwipfd < 0 ) { + return -1; + } + + return lwip_getsockname( lwipfd, name, namelen ); } +#if 0 + int sysctl( const int *name, u_int namelen, @@ -1115,22 +873,16 @@ int sysctl( static int rtems_lwip_close( rtems_libio_t *iop ) { int lwipfd; - int ret; rtems_lwip_semaphore_obtain(); lwipfd = rtems_lwip_iop_to_lwipfd( iop ); + rtems_lwip_semaphore_release(); if ( lwipfd < 0 ) { - ret = -1; - } else { - rtems_lwip_semaphore_release(); - ret = lwip_close( lwipfd ); - rtems_lwip_semaphore_obtain(); + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_close( lwipfd ); } static ssize_t rtems_lwip_read( @@ -1140,22 +892,16 @@ static ssize_t rtems_lwip_read( ) { int lwipfd; - int ret; rtems_lwip_semaphore_obtain(); lwipfd = rtems_lwip_iop_to_lwipfd( iop ); + rtems_lwip_semaphore_release(); if ( lwipfd < 0 ) { - ret = -1; - } else { - rtems_lwip_semaphore_release(); - ret = lwip_read( lwipfd, buffer, count ); - rtems_lwip_semaphore_obtain(); + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_read( lwipfd, buffer, count ); } static ssize_t rtems_lwip_write( @@ -1165,22 +911,16 @@ static ssize_t rtems_lwip_write( ) { int lwipfd; - int ret; rtems_lwip_semaphore_obtain(); lwipfd = rtems_lwip_iop_to_lwipfd( iop ); + rtems_lwip_semaphore_release(); if ( lwipfd < 0 ) { - ret = -1; - } else { - rtems_lwip_semaphore_release(); - ret = lwip_write( lwipfd, buffer, count ); - rtems_lwip_semaphore_obtain(); + return -1; } - rtems_lwip_semaphore_release(); - - return ret; + return lwip_write( lwipfd, buffer, count ); } int so_ioctl( @@ -1262,30 +1002,25 @@ static int rtems_lwip_fcntl( int cmd ) { -#if 0 int lwipfd; - if ( cmd == F_SETFL ) { - rtems_lwip_semaphore_obtain(); - - if ( ( so = iop->data1 ) == NULL ) { - rtems_lwip_semaphore_release(); - - return EBADF; - } - - if ( rtems_libio_iop_is_no_delay( iop ) ) - so->so_state |= SS_NBIO; - else - so->so_state &= ~SS_NBIO; + rtems_lwip_semaphore_obtain(); + lwipfd = rtems_lwip_iop_to_lwipfd( iop ); + rtems_lwip_semaphore_release(); - rtems_lwip_semaphore_release(); + if ( lwipfd < 0 ) { + return -1; } - return 0; -#endif + /* + * Returning non-zero here for F_GETFL results in the call failing instead of + * passing back the value retrieved in the libio layer. + */ + if (cmd == F_GETFL) { + return 0; + } - return -1; + return lwip_fcntl( lwipfd, cmd, O_NONBLOCK ); } static int rtems_lwip_fstat( @@ -1321,3 +1056,8 @@ const char * inet_ntop(int af, const void *src, char *dst, socklen_t size){ return lwip_inet_ntop(af, src, dst, size); } + +int inet_pton(int af, const char *src, void *dst) +{ + return lwip_inet_pton(af, src, dst); +} diff --git a/rtemslwip/common/rtems_lwip_sysdefs.c b/rtemslwip/common/rtems_lwip_sysdefs.c deleted file mode 100644 index 3877811..0000000 --- a/rtemslwip/common/rtems_lwip_sysdefs.c +++ /dev/null @@ -1,185 +0,0 @@ -/* - * - * RTEMS Project (https://www.rtems.org/) - * - * Copyright (c) 2021 Vijay Kumar Banerjee . - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#include -#include -#include - -#include "rtems_lwip_int.h" - -int rtems_lwip_sysdefs_AF_UNSPEC = AF_UNSPEC; -int rtems_lwip_sysdefs_AF_UNIX = AF_UNIX; -int rtems_lwip_sysdefs_AF_INET = AF_INET; -int rtems_lwip_sysdefs_AF_INET6 = AF_INET6; -int rtems_lwip_sysdefs_PF_UNSPEC = PF_UNSPEC; -int rtems_lwip_sysdefs_PF_UNIX = PF_UNIX; -int rtems_lwip_sysdefs_PF_INET = PF_INET; -int rtems_lwip_sysdefs_PF_INET6 = PF_INET6; -int rtems_lwip_sysdefs_SOCK_STREAM = SOCK_STREAM; -int rtems_lwip_sysdefs_SOCK_DGRAM = SOCK_DGRAM; -int rtems_lwip_sysdefs_SOCK_RAW = SOCK_RAW; -int rtems_lwip_sysdefs_sockaddr_in_size = sizeof( struct sockaddr_in ); -int rtems_lwip_sysdefs_sockaddr_in6_size = sizeof( struct sockaddr_in6 ); - -int rtems_lwip_sysdefs_sockaddr_get_len( const void *sockaddr ) -{ - const struct sockaddr *so = sockaddr; - - return so->sa_len; -} - -int rtems_lwip_sysdefs_sockaddr_get_family( const void *sockaddr ) -{ - const struct sockaddr *so = sockaddr; - - return so->sa_family; -} - -uint16_t rtems_lwip_sysdefs_sockaddr_in_get_sin_port( const void *sockaddr ) -{ - const struct sockaddr_in *so = sockaddr; - - return so->sin_port; -} - -uint32_t rtems_lwip_sysdefs_sockaddr_in_get_sin_addr( const void *sockaddr ) -{ - const struct sockaddr_in *so = sockaddr; - - return so->sin_addr.s_addr; -} - -uint16_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_port( const void *sockaddr ) -{ - const struct sockaddr_in6 *so = sockaddr; - - return so->sin6_port; -} - -const uint8_t *rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr_const( - const void *sockaddr ) -{ - const struct sockaddr_in6 *so = sockaddr; - - return (uint8_t *) &so->sin6_addr; -} - -uint8_t *rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr( - void *sockaddr ) -{ - struct sockaddr_in6 *so = sockaddr; - - return (uint8_t *) &so->sin6_addr; -} - -uint32_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_flowinfo( - const void *sockaddr ) -{ - const struct sockaddr_in6 *so = sockaddr; - - return so->sin6_flowinfo; -} - -uint32_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_scope_id( - const void *sockaddr ) -{ - const struct sockaddr_in6 *so = sockaddr; - - return so->sin6_scope_id; -} - -void rtems_lwip_sysdefs_sockaddr_set_len( - void *sockaddr, - int len -) -{ - struct sockaddr *so = sockaddr; - - so->sa_len = len; -} - -void rtems_lwip_sysdefs_sockaddr_set_family( - void *sockaddr, - int family -) -{ - struct sockaddr *so = sockaddr; - - so->sa_family = family; -} - -void rtems_lwip_sysdefs_sockaddr_in_set_sin_port( - void *sockaddr, - uint16_t port -) -{ - struct sockaddr_in *so = sockaddr; - - so->sin_port = port; -} - -void rtems_lwip_sysdefs_sockaddr_in_set_sin_addr( - void *sockaddr, - uint32_t addr -) -{ - struct sockaddr_in *so = sockaddr; - - so->sin_addr.s_addr = addr; -} - -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_port( - void *sockaddr, - uint16_t port -) -{ - struct sockaddr_in6 *so = sockaddr; - - so->sin6_port = port; -} - -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_flowinfo( - void *sockaddr, - uint32_t flowinfo -) -{ - struct sockaddr_in6 *so = sockaddr; - - so->sin6_flowinfo = flowinfo; -} - -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_scope_id( - void *sockaddr, - uint32_t scope_id -) -{ - struct sockaddr_in6 *so = sockaddr; - - so->sin6_scope_id = scope_id; -} diff --git a/rtemslwip/common/syslog.c b/rtemslwip/common/syslog.c index 4da911e..658b4da 100644 --- a/rtemslwip/common/syslog.c +++ b/rtemslwip/common/syslog.c @@ -90,3 +90,9 @@ setlogmask (int pmask) LogMask = pmask; return (omask); } + +void +openlog(const char *ident, int option, int facility) +{ + /* Do nothing */ +} diff --git a/rtemslwip/include/rtems_lwip_int.h b/rtemslwip/include/rtems_lwip_int.h deleted file mode 100644 index 9d3d548..0000000 --- a/rtemslwip/include/rtems_lwip_int.h +++ /dev/null @@ -1,92 +0,0 @@ -/* - * - * RTEMS Project (https://www.rtems.org/) - * - * Copyright (c) 2021 Vijay Kumar Banerjee . - * 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. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR - * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT - * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, - * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT - * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, - * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY - * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT - * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE - * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. - */ - -#ifndef RTEMS_LWIP_INT_H -#define RTEMS_LWIP_INT_H - -#include - -extern int rtems_lwip_sysdefs_AF_UNSPEC; -extern int rtems_lwip_sysdefs_AF_UNIX; -extern int rtems_lwip_sysdefs_AF_INET; -extern int rtems_lwip_sysdefs_AF_INET6; -extern int rtems_lwip_sysdefs_PF_UNSPEC; -extern int rtems_lwip_sysdefs_PF_UNIX; -extern int rtems_lwip_sysdefs_PF_INET; -extern int rtems_lwip_sysdefs_PF_INET6; -extern int rtems_lwip_sysdefs_SOCK_STREAM; -extern int rtems_lwip_sysdefs_SOCK_DGRAM; -extern int rtems_lwip_sysdefs_SOCK_RAW; -extern int rtems_lwip_sysdefs_sockaddr_in_size; -extern int rtems_lwip_sysdefs_sockaddr_in6_size; - -int rtems_lwip_sysdefs_sockaddr_get_len( const void *sockaddr ); -int rtems_lwip_sysdefs_sockaddr_get_family( const void *sockaddr ); -uint16_t rtems_lwip_sysdefs_sockaddr_in_get_sin_port( const void *sockaddr ); -uint32_t rtems_lwip_sysdefs_sockaddr_in_get_sin_addr( const void *sockaddr ); -uint16_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_port( const void *sockaddr ); -const uint8_t *rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr_const( - const void *sockaddr ); -uint8_t *rtems_lwip_sysdefs_sockaddr_in6_get_sin6_addr_ptr( - void *sockaddr ); -uint32_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_flowinfo( - const void *sockaddr ); -uint32_t rtems_lwip_sysdefs_sockaddr_in6_get_sin6_scope_id( - const void *sockaddr ); - -void rtems_lwip_sysdefs_sockaddr_set_len( - void *sockaddr, - int len -); -void rtems_lwip_sysdefs_sockaddr_set_family( - void *sockaddr, - int family -); -void rtems_lwip_sysdefs_sockaddr_in_set_sin_port( - void *sockaddr, - uint16_t port -); -void rtems_lwip_sysdefs_sockaddr_in_set_sin_addr( - void *sockaddr, - uint32_t addr -); -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_port( - void *sockaddr, - uint16_t port -); -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_flowinfo( - void *sockaddr, - uint32_t flowinfo -); -void rtems_lwip_sysdefs_sockaddr_in6_set_sin6_scope_id( - void *sockaddr, - uint32_t scope_id -); - -#endif /*RTEMS_LWIP_INT_H*/ diff --git a/rtemslwip/zynqmp/lwipopts.h b/rtemslwip/zynqmp/lwipopts.h index a939ea2..2d358a3 100644 --- a/rtemslwip/zynqmp/lwipopts.h +++ b/rtemslwip/zynqmp/lwipopts.h @@ -36,6 +36,8 @@ #define LWIP_ARP 1 #define LWIP_NETIF_API 1 +/* Required for socketpair implementation */ +#define LWIP_NETIF_LOOPBACK 1 #define LWIP_IPV6 1 #define LWIP_IPV4 1 #define LWIP_TIMEVAL_PRIVATE 0 -- cgit v1.2.3