Re: Identifying network namespaces (was: Network namespacemanipulation with file descriptors)

From: David Lamparter
Date: Wed May 18 2011 - 09:53:24 EST


On Wed, May 18, 2011 at 04:03:03PM +0300, Alexey Dobriyan wrote:
> On Wed, May 18, 2011 at 3:43 PM, David Lamparter <equinox@xxxxxxxxxx> wrote:
> > - Â processes cannot easily be cross referenced with each other
> >
> > Âin the case of user space stuff running astray - like management
> > Âsoftware crashing, routing daemons screwing up, etc. - it becomes
> > Âfairly difficult to shut down a network namespace (or even reaquire
> > Âphysical devices that have been reassigned)
>
> It shutdowns itself when last process using netns disappeares,
> so if you kill your routing daemons you should be fine.
> Physical netdevices are moved to init_net.

Now assume I'm running pptpd, which forks a new pppd for each
connection. Even if I kill pptpd, the pppd keeps running... now how do I
find the pppds that belong to that one namespace that I'm trying to
get rid of?

> > - Â namespaces cannot adequately be identified to the user
> >
> > Âfor debugging, some kernel messages become useless. most prominently,
> > Â"unregister_netdevice: waiting for lo to become free. Usage count = 123"
> > Âcould certainly use some clarification, *which* lo is meant...
>
> There is no "netns %p" or something, because right now the only unique
> netns identifier is kernel pointer (which better not be exposed to userspace).
> Printing such thing would be quite useless since it's not printed
> at netns creation.

I agree printing the kernel pointer is point-less.

> > So, considering this set of premises (feedback welcome) I looked for
> > some suitable means of identification. I discarded going for any process
> > identifiers since Eric's patches allow for network namespaces without
> > any process holding a reference, using bind mounts instead.
>
> If anything it should be netns->id, /proc/*/netns outputting id
> where id is not derived from kernel pointer.
>
> > Solution?
> > [ using lo interface index ]
>
> What a hack! :-)

Well, you could create another counter and count it up on namespace
creation. But the interface index is readily available to userspace as
is, and it uniquely identifies the network namespace.

(Stupidest thing you can do to break this is renaming the loopback
device; but even if you do that userspace can still look at the LOOPBACK
flag.)


-David

--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@xxxxxxxxxxxxxxx
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/