From c85fe67ebcd9e7737ad924a154e62e63671827d0 Mon Sep 17 00:00:00 2001 From: Xiang Xiao Date: Sun, 29 Mar 2020 21:43:44 +0800 Subject: [PATCH] net/loopback: Move g_lo_* global variable to libc/net/ so netdb could reuse these global variable directly Signed-off-by: Xiang Xiao Change-Id: Iaa26ddbdaf416f64d43c6e8888a14bbe0c3405eb --- libs/libc/net/Make.defs | 4 + .../libc/net/lib_loopback.c | 4 +- libs/libc/netdb/lib_gethostbynamer.c | 30 +------- net/Kconfig | 1 - net/Makefile | 1 - net/README.txt | 1 - net/loopback/Kconfig | 4 - net/loopback/Make.defs | 47 ----------- net/loopback/loopback.h | 77 ------------------- 9 files changed, 6 insertions(+), 163 deletions(-) rename net/loopback/lo_globals.c => libs/libc/net/lib_loopback.c (98%) delete mode 100644 net/loopback/Kconfig delete mode 100644 net/loopback/Make.defs delete mode 100644 net/loopback/loopback.h diff --git a/libs/libc/net/Make.defs b/libs/libc/net/Make.defs index 15ec22ecf0..d4c8d20b1c 100644 --- a/libs/libc/net/Make.defs +++ b/libs/libc/net/Make.defs @@ -43,6 +43,10 @@ ifeq ($(CONFIG_NET),y) CSRCS += lib_recvmsg.c lib_sendmsg.c lib_shutdown.c endif +ifeq ($(CONFIG_NET_LOOPBACK),y) +CSRCS += lib_loopback.c +endif + # Routing table support ifeq ($(CONFIG_NET_ROUTE),y) diff --git a/net/loopback/lo_globals.c b/libs/libc/net/lib_loopback.c similarity index 98% rename from net/loopback/lo_globals.c rename to libs/libc/net/lib_loopback.c index d6be4a5ab3..b25cae772b 100644 --- a/net/loopback/lo_globals.c +++ b/libs/libc/net/lib_loopback.c @@ -1,5 +1,5 @@ /**************************************************************************** - * net/loopback/lo_globals.c + * libs/libc/net/lib_loopback.c * * Copyright (C) 2015, 2017 Gregory Nutt. All rights reserved. * Author: Gregory Nutt @@ -41,8 +41,6 @@ #include -#include "loopback/loopback.h" - #ifdef CONFIG_NET_LOOPBACK /**************************************************************************** diff --git a/libs/libc/netdb/lib_gethostbynamer.c b/libs/libc/netdb/lib_gethostbynamer.c index 2b4ec7849b..958a2fe976 100644 --- a/libs/libc/netdb/lib_gethostbynamer.c +++ b/libs/libc/netdb/lib_gethostbynamer.c @@ -70,34 +70,6 @@ struct hostent_info_s char hi_data[1]; }; -/**************************************************************************** - * Public Data - ****************************************************************************/ - -/* In the FLAT build, there is a single copy of this global variable that - * can be accessed from application or OS code. In the protected and - * kernel build modes, however, there must be separate copies of OS and - * users spaces. - */ - -#if !defined(CONFIG_BUILD_FLAT) && !defined(__KERNEL__) -/* Local loopback addresses for user mode */ - -#ifdef CONFIG_NET_IPv4 - -const in_addr_t g_lo_ipv4addr = HTONL(0x7f000001); - -#else /* CONFIG_NET_IPv6 */ - -const net_ipv6addr_t g_lo_ipv6addr = -{ - HTONS(0), HTONS(0), HTONS(0), HTONS(0), - HTONS(0), HTONS(0), HTONS(0), HTONS(1) -}; - -#endif -#endif /* !CONFIG_BUILD_FLAT && !__KERNEL__ */ - /**************************************************************************** * Private functions ****************************************************************************/ @@ -269,7 +241,7 @@ static int lib_localhost(FAR const char *name, FAR struct hostent *host, FAR char *dest; int namelen; - if (strcmp(name, "localhost") == 0) + if (strcmp(name, g_lo_hostname) == 0) { /* Yes.. it is the localhost */ diff --git a/net/Kconfig b/net/Kconfig index 81b56a82cc..fed3d01259 100644 --- a/net/Kconfig +++ b/net/Kconfig @@ -354,7 +354,6 @@ source "net/icmpv6/Kconfig" source "net/mld/Kconfig" source "net/igmp/Kconfig" source "net/arp/Kconfig" -source "net/loopback/Kconfig" source "net/procfs/Kconfig" source "net/usrsock/Kconfig" source "net/utils/Kconfig" diff --git a/net/Makefile b/net/Makefile index dfdbbb97f7..2890aafd7b 100644 --- a/net/Makefile +++ b/net/Makefile @@ -74,7 +74,6 @@ include bluetooth/Make.defs include ieee802154/Make.defs include devif/Make.defs include ipforward/Make.defs -include loopback/Make.defs include route/Make.defs include procfs/Make.defs include usrsock/Make.defs diff --git a/net/README.txt b/net/README.txt index 98d1b6d27a..d8158171bf 100644 --- a/net/README.txt +++ b/net/README.txt @@ -17,7 +17,6 @@ Directory Structure +- inet - PF_INET/PF_INET6 socket interface +- ipforward - IP forwarding logic +- local - Unix domain (local) sockets - +- loopback - Local loopback +- mld - Multicast Listener Discovery (MLD) +- neighbor - Neighbor Discovery Protocol (IPv6) +- netdev - Socket network device interface diff --git a/net/loopback/Kconfig b/net/loopback/Kconfig deleted file mode 100644 index f72f3c094c..0000000000 --- a/net/loopback/Kconfig +++ /dev/null @@ -1,4 +0,0 @@ -# -# For a description of the syntax of this configuration file, -# see the file kconfig-language.txt in the NuttX tools repository. -# diff --git a/net/loopback/Make.defs b/net/loopback/Make.defs deleted file mode 100644 index 097be782f9..0000000000 --- a/net/loopback/Make.defs +++ /dev/null @@ -1,47 +0,0 @@ -############################################################################ -# net/loopback/Make.defs -# -# Copyright (C) 2015 Gregory Nutt. All rights reserved. -# Author: Gregory Nutt -# -# 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. Neither the name NuttX nor the names of its contributors may be -# used to endorse or promote products derived from this software -# without specific prior written permission. -# -# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS -# "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT -# LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS -# FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE -# 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. -# -############################################################################ - -ifeq ($(CONFIG_NET_LOOPBACK),y) - -# Local loopback support - -NETDEV_CSRCS += lo_globals.c - -# Include routing table build support - -DEPPATH += --dep-path loopback -VPATH += :loopback - -endif diff --git a/net/loopback/loopback.h b/net/loopback/loopback.h deleted file mode 100644 index 50d7148265..0000000000 --- a/net/loopback/loopback.h +++ /dev/null @@ -1,77 +0,0 @@ -/**************************************************************************** - * net/route/route.h - * - * Copyright (C) 2013-2014 Gregory Nutt. All rights reserved. - * Author: Gregory Nutt - * - * 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. Neither the name NuttX nor the names of its contributors may be - * used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS - * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT - * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS - * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE - * 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 __NET_LOOPBACK_LOOBACK_H -#define __NET_LOOPBACK_LOOBACK_H - -/**************************************************************************** - * Included Files - ****************************************************************************/ - -#include - -#ifdef CONFIG_NET_LOOPBACK - -/**************************************************************************** - * Pre-processor Definitions - ****************************************************************************/ - -/**************************************************************************** - * Public Types - ****************************************************************************/ - -/**************************************************************************** - * Public Data - ****************************************************************************/ - -#ifdef __cplusplus -#define EXTERN extern "C" -extern "C" -{ -#else -#define EXTERN extern -#endif - -/**************************************************************************** - * Public Function Prototypes - ****************************************************************************/ - -#undef EXTERN -#ifdef __cplusplus -} -#endif - -#endif /* CONFIG_NET_LOOPBACK */ -#endif /* __NET_LOOPBACK_LOOBACK_H */