Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
slapos
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Lu Xu
slapos
Commits
ea98e50b
Commit
ea98e50b
authored
Oct 23, 2023
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
12cbc920
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
10 deletions
+14
-10
software/ors-amarisoft/ru/tapsplit
software/ors-amarisoft/ru/tapsplit
+14
-10
No files found.
software/ors-amarisoft/ru/tapsplit
View file @
ea98e50b
#!/usr/bin/env python
"""XXX doc"""
"""Program tapsplit brings tap interface into state with several children
interfaces each covering part of original interface address space.
Usage: tapsplit <interface> <nchildren>
"""
import
netifaces
import
netaddr
...
...
@@ -14,10 +18,10 @@ import subprocess
def
main
():
tap
=
sys
.
argv
[
1
]
n
=
int
(
sys
.
argv
[
2
])
assert
n
>
0
,
n
assert
n
>
=
0
,
n
# determine tap's address, network and owner
owner
=
readfile
(
sysnet
(
tap
,
'owner'
)
)
.
strip
()
owner
=
readfile
(
sysnet
(
tap
)
+
'/owner'
)
.
strip
()
addr
=
None
net
=
None
prefixlen
=
None
...
...
@@ -46,6 +50,11 @@ def main():
print
(
'%s: split %s by %d'
%
(
tap
,
net
,
n
))
# cleanup existing children
for
ifname
in
netifaces
.
interfaces
():
if
ifname
.
startswith
(
'%s-'
%
tap
):
run
(
'ip'
,
'link'
,
'del'
,
ifname
)
# see how much prefix bits we need to take to divide by n
n
+=
1
# also leaving first range for the original tap
ptake
=
ceil
(
log2
(
n
))
...
...
@@ -56,8 +65,6 @@ def main():
continue
# leave this range for original tap
subtap
=
'%s-%d'
%
(
tap
,
i
)
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'
,
'link'
,
'set'
,
subtap
,
'up'
)
run
(
'ip'
,
'addr'
,
'add'
,
str
(
subnet
),
'dev'
,
subtap
,
'noprefixroute'
)
...
...
@@ -66,11 +73,8 @@ def main():
# 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
sysnet
(
ifname
):
return
'/sys/devices/virtual/net/%s'
%
ifname
def
run
(
*
argv
):
print
(
' # %s'
%
' '
.
join
(
argv
))
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment