Hi Pablo, On Sun, Jan 12, 2020 at 11:40:27AM +0100, Pablo Neira Ayuso wrote: > On Sun, Jan 12, 2020 at 11:28:02AM +0100, Pablo Neira Ayuso wrote: > > On Fri, Jan 10, 2020 at 01:53:11PM +0100, Phil Sutter wrote: > > > On Thu, Jan 09, 2020 at 06:21:13PM +0100, Pablo Neira Ayuso wrote: > > > [...] > > > > diff --git a/include/nftables/libnftables.h b/include/nftables/libnftables.h > > > > index 765b20dd71ee..887628959ac6 100644 > > > > --- a/include/nftables/libnftables.h > > > > +++ b/include/nftables/libnftables.h > > > > @@ -34,10 +34,13 @@ enum nft_debug_level { > > > > * Possible flags to pass to nft_ctx_new() > > > > */ > > > > #define NFT_CTX_DEFAULT 0 > > > > +#define NFT_CTX_NETNS 1 > > > > > > What is this needed for? > > > > The socket is initialized from nft_ctx_init(), and such initialization > > needs to happen after the netns switch. > > s/nft_ctx_init()/nft_ctx_new() Ah, I missed that socket init in nft_ctx_new() happens only if flags is zero. > > > > struct nft_ctx *nft_ctx_new(uint32_t flags); > > > > void nft_ctx_free(struct nft_ctx *ctx); > > > > > > > > +int nft_ctx_set_netns(struct nft_ctx *ctx, const char *netns); > > > > > > Is there a way to select init ns again? > > > > AFAIK, setns() does not let you go back to init ns once set. I noticed something I find worse, namely that libnftables as a library changes the application's netns. Anything it does after changing the context's netns applies to that netns only, no matter if it's creating a new nft context with NFT_CtX_DEFAULT flag or call iproute via system(). If we can't find a way to exit the netns again, one can safely assume that we are trapping a user's application in a netns with this feature. Maybe we should restrict per-netns operation to nft utility and perform the netns switch there? Maybe we could provide a "switch_netns()" routine in libnftables which is not bound to nft context so users may use it in their application? Cheers, Phil