diff --git a/Makefile b/Makefile index 3b089d227c..965d89d66c 100644 --- a/Makefile +++ b/Makefile @@ -871,6 +871,7 @@ endif ifneq ($(USE_NS),) OPTIONS_CFLAGS += -DCONFIG_HAP_NS BUILD_OPTIONS += $(call ignore_implicit,USE_NS) +OPTIONS_OBJS += src/namespace.o endif #### Global link options @@ -916,7 +917,7 @@ OBJS = src/proto_http.o src/cfgparse.o src/server.o src/stream.o \ src/hpack-dec.o src/memory.o src/lb_fwrr.o src/lb_chash.o \ src/lb_fas.o src/hathreads.o src/chunk.o src/lb_map.o \ src/xxhash.o src/regex.o src/shctx.o src/buffer.o src/action.o \ - src/h1.o src/compression.o src/pipe.o src/namespace.o \ + src/h1.o src/compression.o src/pipe.o \ src/sha1.o src/hpack-tbl.o src/hpack-enc.o src/uri_auth.o \ src/time.o src/proto_udp.o src/arg.o src/signal.o \ src/protocol.o src/lru.o src/hdr_idx.o src/hpack-huff.o \ diff --git a/include/common/namespace.h b/include/common/namespace.h index fa4185db61..7aacff9681 100644 --- a/include/common/namespace.h +++ b/include/common/namespace.h @@ -4,9 +4,6 @@ #include #include -struct netns_entry; -int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol); - #ifdef CONFIG_HAP_NS struct netns_entry @@ -16,10 +13,21 @@ struct netns_entry int fd; }; +int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol); struct netns_entry* netns_store_insert(const char *ns_name); const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name_len); int netns_init(void); + +#else /* no namespace support */ + +struct netns_entry; + +static inline int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol) +{ + return socket(domain, type, protocol); +} + #endif /* CONFIG_HAP_NS */ #endif /* _NAMESPACE_H */ diff --git a/src/namespace.c b/src/namespace.c index 93d92480dd..72f5079ebd 100644 --- a/src/namespace.c +++ b/src/namespace.c @@ -17,8 +17,6 @@ #include #include -#ifdef CONFIG_HAP_NS - /* Opens the namespace and returns the FD or -1 in case of error * (check errno). */ @@ -88,7 +86,6 @@ const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name else return NULL; } -#endif /* Opens a socket in the namespace described by with the parameters , * and and returns the FD or -1 in case of error (check errno). @@ -97,19 +94,15 @@ int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol { int sock; -#ifdef CONFIG_HAP_NS if (default_namespace >= 0 && ns && setns(ns->fd, CLONE_NEWNET) == -1) return -1; -#endif + sock = socket(domain, type, protocol); -#ifdef CONFIG_HAP_NS if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) { close(sock); return -1; } -#endif - return sock; }