]> git.baikalelectronics.ru Git - kernel.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)
commit348f75d10f7b24dd1248968d05a2dad617458e98
tree379cb186c759641311ec2eed0c3e1aba9e30fa3c
parente7410529dd9612089d1e944674d5f49c659206ae
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