]> asedeno.scripts.mit.edu Git - linux.git/commit
tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device
authorKirill Tkhai <ktkhai@virtuozzo.com>
Wed, 14 Feb 2018 13:40:14 +0000 (16:40 +0300)
committerDavid S. Miller <davem@davemloft.net>
Thu, 15 Feb 2018 20:34:42 +0000 (15:34 -0500)
commitf2780d6d74756bc1d7ba32ff3dd0de4afd7c7e1e
tree379cb186c759641311ec2eed0c3e1aba9e30fa3c
parent24dce0800baaa508b1a8ccf01ae0a9c8e600a5aa
tun: Add ioctl() SIOCGSKNS cmd to allow obtaining net ns of tun device

This patch adds possibility to get tun device's net namespace fd
in the same way we allow to do that for sockets.

Socket ioctl numbers do not intersect with tun-specific, and there
is already SIOCSIFHWADDR used in tun code. So, SIOCGSKNS number
is choosen instead of custom-made for this functionality.

Note, that open_related_ns() uses plain get_net_ns() and it's safe
(net can't be already dead at this moment):

  tun socket is allocated via sk_alloc() with zero last arg (kern = 0).
  So, each alive socket increments net::count, and the socket is definitely
  alive during ioctl syscall.

Also, common variable net is introduced, so small cleanup in TUNSETIFF
is made.

Signed-off-by: Kirill Tkhai <ktkhai@virtuozzo.com>
Signed-off-by: David S. Miller <davem@davemloft.net>
drivers/net/tun.c