When interfaces are configured the configuring program needs to be in same namespace as the interface operates in. This patch make this switch just before any file descriptor is opened. As long as the file descriptor remain open, it does not matter if program later on switch to other namespace.
Signed-off-by: Anders Selhammer <anders.selham...@est.tech> --- clock.c | 3 +++ ptp4l.c | 9 ++++++++- transport.c | 7 +++++++ 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/clock.c b/clock.c index 56bc79b..c494200 100644 --- a/clock.c +++ b/clock.c @@ -959,6 +959,9 @@ struct clock *clock_create(enum clock_type type, struct config *config, c->timestamping = timestamping; required_modes = clock_required_modes(c); STAILQ_FOREACH(iface, &config->interfaces, list) { + if (sk_reassociate_namespace(config_get_string(config, iface->name, "network_namespace"))) { + return NULL; + } rtnl_get_ts_device(iface->name, iface->ts_label); ensure_ts_label(iface); sk_get_ts_info(iface->ts_label, &iface->ts_info); diff --git a/ptp4l.c b/ptp4l.c index 3a9f084..598d71d 100644 --- a/ptp4l.c +++ b/ptp4l.c @@ -241,6 +241,10 @@ int main(int argc, char *argv[]) goto out; } + if (sk_init_initial_namespace_fd() < 0) { + goto out; + } + clock = clock_create(type, cfg, req_phc); if (!clock) { fprintf(stderr, "failed to create a clock\n"); @@ -254,8 +258,11 @@ int main(int argc, char *argv[]) break; } out: - if (clock) + if (clock) { clock_destroy(clock); + } + + sk_close_initial_namespace_fd(); config_destroy(cfg); return err; } diff --git a/transport.c b/transport.c index 9366fbf..4ae22f6 100644 --- a/transport.c +++ b/transport.c @@ -21,7 +21,10 @@ #include "transport.h" #include "transport_private.h" +#include "config.h" +#include "print.h" #include "raw.h" +#include "sk.h" #include "udp.h" #include "udp6.h" #include "uds.h" @@ -34,6 +37,10 @@ int transport_close(struct transport *t, struct fdarray *fda) int transport_open(struct transport *t, struct interface *iface, struct fdarray *fda, enum timestamp_type tt) { + if (sk_reassociate_namespace(config_get_string(t->cfg, iface->name, "network_namespace"))) { + pr_err("sk_reassociate_namespace failed"); + return -1; + } return t->open(t, iface, fda, tt); } -- 1.8.3.1 _______________________________________________ Linuxptp-devel mailing list Linuxptp-devel@lists.sourceforge.net https://lists.sourceforge.net/lists/listinfo/linuxptp-devel