MINOR: namespaces: don't build namespace.c if disabled
When namespaces are disabled, support is still reported because the file is built with almost nothing in it but built anyway. Instead of extending the scope of the numerous ifdefs in this file, better avoid building it when namespaces are diabled. In this case we define my_socketat() as an inline function mapping directly to socket(). The struct netns_entry still needs to be defined because it's used by various other functions in the code.
This commit is contained in:
parent
691fe39284
commit
7520e4ff57
3
Makefile
3
Makefile
|
@ -871,6 +871,7 @@ endif
|
||||||
ifneq ($(USE_NS),)
|
ifneq ($(USE_NS),)
|
||||||
OPTIONS_CFLAGS += -DCONFIG_HAP_NS
|
OPTIONS_CFLAGS += -DCONFIG_HAP_NS
|
||||||
BUILD_OPTIONS += $(call ignore_implicit,USE_NS)
|
BUILD_OPTIONS += $(call ignore_implicit,USE_NS)
|
||||||
|
OPTIONS_OBJS += src/namespace.o
|
||||||
endif
|
endif
|
||||||
|
|
||||||
#### Global link options
|
#### 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/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/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/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/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/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 \
|
src/protocol.o src/lru.o src/hdr_idx.o src/hpack-huff.o \
|
||||||
|
|
|
@ -4,9 +4,6 @@
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <ebistree.h>
|
#include <ebistree.h>
|
||||||
|
|
||||||
struct netns_entry;
|
|
||||||
int my_socketat(const struct netns_entry *ns, int domain, int type, int protocol);
|
|
||||||
|
|
||||||
#ifdef CONFIG_HAP_NS
|
#ifdef CONFIG_HAP_NS
|
||||||
|
|
||||||
struct netns_entry
|
struct netns_entry
|
||||||
|
@ -16,10 +13,21 @@ struct netns_entry
|
||||||
int fd;
|
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);
|
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);
|
const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name_len);
|
||||||
|
|
||||||
int netns_init(void);
|
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 /* CONFIG_HAP_NS */
|
||||||
|
|
||||||
#endif /* _NAMESPACE_H */
|
#endif /* _NAMESPACE_H */
|
||||||
|
|
|
@ -17,8 +17,6 @@
|
||||||
#include <proto/log.h>
|
#include <proto/log.h>
|
||||||
#include <types/global.h>
|
#include <types/global.h>
|
||||||
|
|
||||||
#ifdef CONFIG_HAP_NS
|
|
||||||
|
|
||||||
/* Opens the namespace <ns_name> and returns the FD or -1 in case of error
|
/* Opens the namespace <ns_name> and returns the FD or -1 in case of error
|
||||||
* (check errno).
|
* (check errno).
|
||||||
*/
|
*/
|
||||||
|
@ -88,7 +86,6 @@ const struct netns_entry* netns_store_lookup(const char *ns_name, size_t ns_name
|
||||||
else
|
else
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
/* Opens a socket in the namespace described by <ns> with the parameters <domain>,
|
/* Opens a socket in the namespace described by <ns> with the parameters <domain>,
|
||||||
* <type> and <protocol> and returns the FD or -1 in case of error (check errno).
|
* <type> and <protocol> 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;
|
int sock;
|
||||||
|
|
||||||
#ifdef CONFIG_HAP_NS
|
|
||||||
if (default_namespace >= 0 && ns && setns(ns->fd, CLONE_NEWNET) == -1)
|
if (default_namespace >= 0 && ns && setns(ns->fd, CLONE_NEWNET) == -1)
|
||||||
return -1;
|
return -1;
|
||||||
#endif
|
|
||||||
sock = socket(domain, type, protocol);
|
sock = socket(domain, type, protocol);
|
||||||
|
|
||||||
#ifdef CONFIG_HAP_NS
|
|
||||||
if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) {
|
if (default_namespace >= 0 && ns && setns(default_namespace, CLONE_NEWNET) == -1) {
|
||||||
close(sock);
|
close(sock);
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
return sock;
|
return sock;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue