Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
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
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kirill Smelkov
slapos
Commits
d3dc7357
Commit
d3dc7357
authored
Oct 23, 2023
by
Kirill Smelkov
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
.
parent
5ce62b9a
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
42 additions
and
30 deletions
+42
-30
software/ors-amarisoft/instance-enb.jinja2.cfg
software/ors-amarisoft/instance-enb.jinja2.cfg
+1
-0
software/ors-amarisoft/ru/libinstance.jinja2.cfg
software/ors-amarisoft/ru/libinstance.jinja2.cfg
+10
-4
software/ors-amarisoft/ru/tapsplit
software/ors-amarisoft/ru/tapsplit
+31
-26
No files found.
software/ors-amarisoft/instance-enb.jinja2.cfg
View file @
d3dc7357
...
...
@@ -147,6 +147,7 @@ context =
import json_module json
import netaddr netaddr
section directory directory
section vtap vtap
json iru_dict {{ rulib.iru_dict | tojson }}
[dnsmasq-service]
...
...
software/ors-amarisoft/ru/libinstance.jinja2.cfg
View file @
d3dc7357
...
...
@@ -77,10 +77,16 @@ addr = {{ slap_configuration['tap-ipv6-addr'] }}
{%- else %}
{%- for i in range(1,ntap+1) %}
[vtap.{{ slap_configuration['tap-name'] }}-{{ i }}]
network = ...
gateway = ... network[1]
addr = ... network.last
{%- set tap = slap_configuration['tap-name'] }}-{{ i }} %}
[vtap.{{ tap }}]
recipt = slapos.recipe.build
init =
tapsplit = __import__('{{ ru_tapsplit }}')
net = tapsplit.ifnet6('{{ tap }}')
options['network'] = str(net)
options['gateway'] = str(net[1])
options['addr'] = str(net[-1])
{%- endfor %}
{%- endif %}
...
...
software/ors-amarisoft/ru/tapsplit
View file @
d3dc7357
...
...
@@ -36,8 +36,37 @@ def main():
n
=
int
(
sys
.
argv
[
2
])
assert
n
>=
0
,
n
# determine tap's
address, network
and owner
# determine tap's
network address
and owner
owner
=
readfile
(
sysnet
(
tap
)
+
'/owner'
)
.
strip
()
net
=
ifnet6
(
tap
)
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
))
# do the split
for
i
,
subnet
in
enumerate
(
net
.
subnet
(
net
.
prefixlen
+
ptake
)):
if
i
==
0
:
print
(
'preserve %s'
%
subnet
)
continue
# leave this range for original tap
subtap
=
'%s-%d'
%
(
tap
,
i
)
print
(
'-> %s %s'
%
(
subtap
,
subnet
))
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'
)
run
(
'ip'
,
'route'
,
'add'
,
str
(
subnet
[
1
]),
'dev'
,
subtap
)
run
(
'ip'
,
'route'
,
'add'
,
str
(
subnet
),
'dev'
,
subtap
,
'via'
,
str
(
subnet
[
1
]))
# ifnet6 returns IPv6 network address associated with given interface.
def
ifnet6
(
ifname
):
addr
=
None
net
=
None
prefixlen
=
None
...
...
@@ -63,31 +92,7 @@ def main():
# normalize network
# ex 2401:5180:0:66:a7ff:ffff:ffff:ffff/71 -> 2401:5180:0:66:a600::/71
net
=
net
.
cidr
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
))
# do the split
for
i
,
subnet
in
enumerate
(
net
.
subnet
(
prefixlen
+
ptake
)):
if
i
==
0
:
print
(
'preserve %s'
%
subnet
)
continue
# leave this range for original tap
subtap
=
'%s-%d'
%
(
tap
,
i
)
print
(
'-> %s %s'
%
(
subtap
,
subnet
))
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'
)
run
(
'ip'
,
'route'
,
'add'
,
str
(
subnet
[
1
]),
'dev'
,
subtap
)
run
(
'ip'
,
'route'
,
'add'
,
str
(
subnet
),
'dev'
,
subtap
,
'via'
,
str
(
subnet
[
1
]))
return
net
# sysnet returns path on /sys corresponding to given interface.
def
sysnet
(
ifname
):
...
...
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