Operation not permitted for TUNSETIFF

445 views Asked by At

i am trying to open a TUN device and using ioctl with operation code TUNSETIFF and getting operation not permitted error.

environment

PRETTY_NAME="Ubuntu 22.04.1 LTS"

$ docker --version
Docker version 20.10.17, build 100c701

Python 3.10.6

using following command to run the container

docker run --rm -it --network host --cap-add=NET_ADMIN --device=/dev/net/tun ubuntutest bash -c "tuntaptest.py"

i have tried following options docker run --rm -it --network host --privileged docker run --rm -it --network host --cap-add=SYS_ADMIN nothing has worked so far

code snapshot

TUNSETIFF: int = 0x400454ca
IFF_TUN: int = 0x0001
IFF_NO_PI: int = 0x1000

tun = open('/dev/net/tun', 'r+b', buffering=0)
ifr: bytes = struct.pack('!16sH', bytes('tun0', 'utf-8'), IFF_TUN | IFF_NO_PI)
fcntl.ioctl(self.tun, TUNSETIFF, ifr)
0

There are 0 answers