aboutgitcodebugslistschat
path: root/conf.c
diff options
context:
space:
mode:
authorStefano Brivio <sbrivio@redhat.com>2022-02-18 16:12:11 +0100
committerStefano Brivio <sbrivio@redhat.com>2022-02-21 13:41:13 +0100
commit745a9ba4284cbe055aac3fadb57efe531c4e3a96 (patch)
tree6283140095f6652d119fbf619890269b3d1d869d /conf.c
parent6c931118643c8fa35935ddbd920cb669dec10021 (diff)
downloadpasst-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar.gz
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar.bz2
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar.lz
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar.xz
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.tar.zst
passt-745a9ba4284cbe055aac3fadb57efe531c4e3a96.zip
pasta: By default, quit if filesystem-bound net namespace goes away
This should be convenient for users managing filesystem-bound network namespaces: monitor the base directory of the namespace and exit if the namespace given as PATH or NAME target is deleted. We can't add an inotify watch directly on the namespace directory, that won't work with nsfs. Add an option to disable this behaviour, --no-netns-quit. Signed-off-by: Stefano Brivio <sbrivio@redhat.com>
Diffstat (limited to 'conf.c')
-rw-r--r--conf.c43
1 files changed, 33 insertions, 10 deletions
diff --git a/conf.c b/conf.c
index 21e9bc0..9851575 100644
--- a/conf.c
+++ b/conf.c
@@ -20,6 +20,7 @@
#include <sched.h>
#include <sys/types.h>
#include <sys/stat.h>
+#include <libgen.h>
#include <limits.h>
#include <stdlib.h>
#include <stdint.h>
@@ -414,20 +415,34 @@ static int conf_ns_opt(struct ctx *c,
nfd = open(netns, O_RDONLY);
- if (nfd >= 0 && (ufd >= 0 || c->netns_only)) {
- c->pasta_netns_fd = nfd;
- c->pasta_userns_fd = ufd;
+ if (nfd == -1 || (ufd == -1 && !c->netns_only)) {
+ if (nfd >= 0)
+ close(nfd);
- NS_CALL(conf_ns_check, c);
- if (c->pasta_netns_fd >= 0)
- return 0;
+ if (ufd >= 0)
+ close(ufd);
+
+ continue;
}
- if (nfd >= 0)
- close(nfd);
+ c->pasta_netns_fd = nfd;
+ c->pasta_userns_fd = ufd;
+
+ NS_CALL(conf_ns_check, c);
+
+ if (c->pasta_netns_fd >= 0) {
+ char buf[PATH_MAX];
+
+ if (try == 0 || c->no_netns_quit)
+ return 0;
+
+ strncpy(buf, netns, PATH_MAX);
+ strncpy(c->netns_base, basename(buf), PATH_MAX - 1);
+ strncpy(buf, netns, PATH_MAX);
+ strncpy(c->netns_dir, dirname(buf), PATH_MAX - 1);
- if (ufd >= 0)
- close(ufd);
+ return 0;
+ }
}
c->netns_only = netns_only_reset;
@@ -813,6 +828,7 @@ void conf(struct ctx *c, int argc, char **argv)
{"dhcp-search", no_argument, NULL, 7 },
{"no-dhcp-search", no_argument, NULL, 8 },
{"dns-forward", required_argument, NULL, 9 },
+ {"no-netns-quit", no_argument, NULL, 10 },
{ 0 },
};
struct get_bound_ports_ns_arg ns_ports_arg = { .c = c };
@@ -937,6 +953,13 @@ void conf(struct ctx *c, int argc, char **argv)
err("Invalid DNS forwarding address: %s", optarg);
usage(argv[0]);
break;
+ case 10:
+ if (c->mode != MODE_PASTA) {
+ err("--no-netns-quit is for pasta mode only");
+ usage(argv[0]);
+ }
+ c->no_netns_quit = 1;
+ break;
case 'd':
if (c->debug) {
err("Multiple --debug options given");