[PATCH] run.py: add tap option

9 views
Skip to first unread message

Wonsup Yoon

unread,
Apr 13, 2020, 10:00:52 AM4/13/20
to osv...@googlegroups.com, Wonsup Yoon
Currently, OSv needs root permission for tap networking.
However, if we have a tap interface with proper permission,
we can do tap networking without root permission.

This adds --tap option to specify tap interface.
It enables tap networking without root permission.

Usage:

On root:

adduser user1 kvm # allow user 1 to use kvm
tunctl -u user1 -t user1_tap0 # add tap interface for user1

On user1 (without root/sudo):

./scripts/run.py -n --tap user1_tap0

Signed-off-by: Wonsup Yoon <pus...@kaist.ac.kr>
---
scripts/run.py | 6 +++++-
1 file changed, 5 insertions(+), 1 deletion(-)

diff --git a/scripts/run.py b/scripts/run.py
index 26177d57..034228b1 100755
--- a/scripts/run.py
+++ b/scripts/run.py
@@ -190,7 +190,9 @@ def start_osv_qemu(options):
net_device_options.append('mac=%s' % options.mac)

if options.networking:
- if options.vhost:
+ if options.tap:
+ args += ["-netdev", "tap,id=hn%d,ifname=%s,script=no,downscript=no" % (idx, options.tap)]
+ elif options.vhost:
args += ["-netdev", "tap,id=hn%d,script=%s,vhost=on" % (idx, os.path.join(osv_base, "scripts/qemu-ifup.sh"))]
else:
for bridge_helper_dir in ['/usr/libexec', '/usr/lib/qemu']:
@@ -489,6 +491,8 @@ if __name__ == "__main__":
help="bridge name for tap networking")
parser.add_argument("-v", "--vhost", action="store_true",
help="needs root. tap networking and vhost")
+ parser.add_argument("-t", "--tap", action="store",
+ help="tap interface name")
parser.add_argument("-m", "--memsize", action="store", default="2G",
help="specify memory: ex. 1G, 2G, ...")
parser.add_argument("-c", "--vcpus", action="store", default="4",
--
2.20.1



Pekka Enberg

unread,
Apr 15, 2020, 3:51:07 AM4/15/20
to Wonsup Yoon, Waldek Kozaczuk, OSv Development
On Mon, Apr 13, 2020 at 5:00 PM Wonsup Yoon <pus...@kaist.ac.kr> wrote:
> Currently, OSv needs root permission for tap networking.
> However, if we have a tap interface with proper permission,
> we can do tap networking without root permission.
>
> This adds --tap option to specify tap interface.
> It enables tap networking without root permission.
>
> Usage:
>
> On root:
>
> adduser user1 kvm # allow user 1 to use kvm
> tunctl -u user1 -t user1_tap0 # add tap interface for user1
>
> On user1 (without root/sudo):
>
> ./scripts/run.py -n --tap user1_tap0
>
> Signed-off-by: Wonsup Yoon <pus...@kaist.ac.kr>

Reviewed-by: Pekka Enberg <pen...@scylladb.com>

Commit Bot

unread,
Apr 15, 2020, 4:16:05 PM4/15/20
to osv...@googlegroups.com, Wonsup Yoon
From: Wonsup Yoon <pus...@kaist.ac.kr>
Committer: Waldemar Kozaczuk <jwkoz...@gmail.com>
Branch: master

run.py: add tap option

Currently, OSv needs root permission for tap networking.
However, if we have a tap interface with proper permission,
we can do tap networking without root permission.

This adds --tap option to specify tap interface.
It enables tap networking without root permission.

Usage:

On root:

adduser user1 kvm # allow user 1 to use kvm
tunctl -u user1 -t user1_tap0 # add tap interface for user1

On user1 (without root/sudo):

./scripts/run.py -n --tap user1_tap0

Signed-off-by: Wonsup Yoon <pus...@kaist.ac.kr>
Message-Id: <20200413140011...@kaist.ac.kr>

---
diff --git a/scripts/run.py b/scripts/run.py
--- a/scripts/run.py
+++ b/scripts/run.py
@@ -190,7 +190,9 @@ def start_osv_qemu(options):
net_device_options.append('mac=%s' % options.mac)

if options.networking:
- if options.vhost:
+ if options.tap:
+ args += ["-netdev", "tap,id=hn%d,ifname=%s,script=no,downscript=no" % (idx, options.tap)]
+ elif options.vhost:
args += ["-netdev", "tap,id=hn%d,script=%s,vhost=on" % (idx, os.path.join(osv_base, "scripts/qemu-ifup.sh"))]
else:
for bridge_helper_dir in ['/usr/libexec', '/usr/lib/qemu']:
@@ -489,6 +491,8 @@ def main(options):
Reply all
Reply to author
Forward
0 new messages