Currently NETNS_RUN_DIR is hardcoded and refers to /var/run/netns. However, some systems (e.g. Android) doesn't have /var which results in error attempts to create network namespaces on these systems. This change makes NETNS_RUN_DIR configurable at build time by allowing to pass environment variable to configre script.
For example: NETNS_RUN_DIR=/mnt/vendor/netns ./configure && make Tested: verified that iproute2 with configuration mentioned above creates namespaces in /mnt/vendor/netns Signed-off-by: Pavel Maltsev <pav...@google.com> --- configure | 3 +++ include/namespace.h | 3 +++ 2 files changed, 6 insertions(+) diff --git a/configure b/configure index 5ef5cd4c..a6a222da 100755 --- a/configure +++ b/configure @@ -213,6 +213,9 @@ EOF echo "IP_CONFIG_SETNS:=y" >>$CONFIG echo "yes" echo "CFLAGS += -DHAVE_SETNS" >>$CONFIG + if [ -n "$NETNS_RUN_DIR" ]; then + echo "CFLAGS += -DNETNS_RUN_DIR=\\\"$NETNS_RUN_DIR\\\"" >>$CONFIG + fi else echo "no" fi diff --git a/include/namespace.h b/include/namespace.h index aed7ce08..b8fb14df 100644 --- a/include/namespace.h +++ b/include/namespace.h @@ -8,7 +8,10 @@ #include <sys/syscall.h> #include <errno.h> +#ifndef NETNS_RUN_DIR #define NETNS_RUN_DIR "/var/run/netns" +#endif /* NETNS_RUN_DIR */ + #define NETNS_ETC_DIR "/etc/netns" #ifndef CLONE_NEWNET -- 2.17.0.441.gb46fe60e1d-goog