Commit e69f3905 authored by Kirill Smelkov's avatar Kirill Smelkov

.

parent 8350a952
...@@ -5,6 +5,7 @@ import netifaces ...@@ -5,6 +5,7 @@ import netifaces
import netaddr import netaddr
from socket import AF_INET6 from socket import AF_INET6
from math import log2, ceil from math import log2, ceil
from os.path import exists
import sys import sys
import subprocess import subprocess
...@@ -16,7 +17,7 @@ def main(): ...@@ -16,7 +17,7 @@ def main():
assert n > 0, n assert n > 0, n
# determine tap's address, network and owner # determine tap's address, network and owner
owner = readfile('/sys/devices/virtual/net/%s/owner' % tap) .strip() owner = readfile(sysnet(tap, 'owner')) .strip()
addr = None addr = None
net = None net = None
prefixlen = None prefixlen = None
...@@ -55,10 +56,20 @@ def main(): ...@@ -55,10 +56,20 @@ def main():
continue # leave this range for original tap continue # leave this range for original tap
subtap = '%s-%d' % (tap, i) subtap = '%s-%d' % (tap, i)
print('-> %s %s' % (subtap, subnet)) print('-> %s %s' % (subtap, subnet))
if exists(sysnet(subtap)):
run('ip', 'link', 'del', subtap)
run('ip', 'tuntap', 'add', 'dev', subtap, 'mode', 'tap', 'user', owner) run('ip', 'tuntap', 'add', 'dev', subtap, 'mode', 'tap', 'user', owner)
run('ip', 'link', 'set', subtap, 'up') run('ip', 'link', 'set', subtap, 'up')
# sysnet returns path on /sys corresponding to given interface.
def sysnet(ifname, subpath=None):
path = '/sys/devices/virtual/net/%s' % ifname
if subpath is not None:
path += '/'+subpath
return path
def run(*argv): def run(*argv):
print('# %s' % ' '.join(argv)) print('# %s' % ' '.join(argv))
subprocess.check_call(argv) subprocess.check_call(argv)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment