]> 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)
commit92f842a5e70fc6cad51a51d4a81ebe3cb2e28eba
tree379cb186c759641311ec2eed0c3e1aba9e30fa3c
parent2689887b279790a9338ef1e94100e19748e772b1
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