Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
S
slapos.core
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
Xavier Thompson
slapos.core
Commits
b1a9fec6
Commit
b1a9fec6
authored
Nov 02, 2022
by
Xavier Thompson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
slapformat: WIP: Tap IPv6: default to last address of range
parent
756481fc
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
12 additions
and
24 deletions
+12
-24
slapos/format.py
slapos/format.py
+12
-24
No files found.
slapos/format.py
View file @
b1a9fec6
...
@@ -474,7 +474,7 @@ class Tap(object):
...
@@ -474,7 +474,7 @@ class Tap(object):
"Options %r and %r for tap %s must either both be provided or neither"
,
"Options %r and %r for tap %s must either both be provided or neither"
,
'ipv4_gateway'
,
'ipv4_address'
,
name
'ipv4_gateway'
,
'ipv4_address'
,
name
)
)
el
if
ipv4_address
:
if
ipv4_address
:
self
.
ipv4_gateway
=
ipaddress
.
IPv4Interface
(
ipv4_gateway
)
self
.
ipv4_gateway
=
ipaddress
.
IPv4Interface
(
ipv4_gateway
)
self
.
ipv4_address
=
ipaddress
.
IPv4Interface
(
ipv4_address
)
self
.
ipv4_address
=
ipaddress
.
IPv4Interface
(
ipv4_address
)
elif
interface
.
tap_ipv4_network
:
elif
interface
.
tap_ipv4_network
:
...
@@ -482,23 +482,27 @@ class Tap(object):
...
@@ -482,23 +482,27 @@ class Tap(object):
self
.
ipv4_address
=
interface
.
getTapIPv4Range
(
index
)
self
.
ipv4_address
=
interface
.
getTapIPv4Range
(
index
)
# Tap IPv6: host-to-tap gateway and tap-to-host address
# Tap IPv6: host-to-tap gateway and tap-to-host address
ipv6_gateway
=
options
[
'ipv6_gateway'
]
ipv6_gateway
=
options
[
'ipv6_gateway'
]
if
ipv6_gateway
:
self
.
ipv6_gateway
=
ipaddress
.
IPv4Interface
(
ipv6_gateway
)
ipv6_address
=
options
[
'ipv6_address'
]
ipv6_address
=
options
[
'ipv6_address'
]
if
not
ipv6_gateway
and
ipv6_address
:
conf
.
wrong
(
"Options %r for tap %s must not be provided without option %r"
,
'ipv6_address'
,
'ipv6_gateway'
,
name
)
if
ipv6_gateway
:
self
.
ipv6_gateway
=
ipv6_gateway
=
ipaddress
.
IPv6Interface
(
ipv6_gateway
)
if
ipv6_address
:
if
ipv6_address
:
self
.
ipv6_address
=
ipaddress
.
IPv6Interface
(
ipv6_address
)
self
.
ipv6_address
=
ipaddress
.
IPv6Interface
(
ipv6_address
)
else
:
self
.
ipv6_address
=
addressFromNetwork
(
ipv6_gateway
.
network
,
-
1
)
elif
conf
.
tap_ipv6
:
elif
conf
.
tap_ipv6
:
self
.
ipv6_gateway
=
interface
.
getTapIPv6Range
(
index
)
self
.
ipv6_gateway
=
i
pv6_gateway
=
i
nterface
.
getTapIPv6Range
(
index
)
# If needed, ipv6_address will be set to link-local in format
self
.
ipv6_address
=
addressFromNetwork
(
ipv6_gateway
.
network
,
-
1
)
def
format
(
self
,
interface
,
user
):
def
format
(
self
,
interface
,
user
):
tap
=
self
.
name
tap
=
self
.
name
conf
=
interface
.
conf
conf
=
interface
.
conf
# Create/ensure TAP interface
# Create/ensure TAP interface
self
.
ensureTap
(
user
,
conf
)
self
.
ensureTap
(
user
,
conf
)
# Find link local address if needed
if
self
.
ipv6_gateway
and
not
self
.
ipv6_address
:
self
.
ipv6_address
=
interface
.
getIPv6LinkLocalAddress
(
tap
)
# Create/ensure IPv4 routes
# Create/ensure IPv4 routes
self
.
ensureIPv4Routes
(
conf
)
self
.
ensureIPv4Routes
(
conf
)
# Create/ensure IPv6 routes
# Create/ensure IPv6 routes
...
@@ -663,22 +667,6 @@ class Interface(object):
...
@@ -663,22 +667,6 @@ class Interface(object):
result
=
network
result
=
network
return
result
return
result
def
getIPv6LinkLocalAddress
(
self
,
interface
):
try
:
addresses
=
netifaces
.
ifaddresses
(
interface
)[
AF_INET6
]
except
KeyError
:
addresses
=
()
for
a
in
addresses
:
address
=
a
[
'addr'
].
split
(
'%'
)[
0
]
netmask
=
a
[
'netmask'
].
split
(
'/'
)[
-
1
]
ip
=
ipaddress
.
IPv6Interface
(
'%s/%s'
%
(
address
,
netmask
))
if
ip
.
is_link_local
:
return
ip
self
.
conf
.
abort
(
"No link-local IPv6 address found on %s"
,
interface
)
def
getComputerIPv6Addr
(
self
):
def
getComputerIPv6Addr
(
self
):
return
addressFromNetwork
(
self
.
ipv6_network
,
1
)
return
addressFromNetwork
(
self
.
ipv6_network
,
1
)
...
...
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