Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
1838f416
authored
Nov 14, 2014
by
Őry Máté
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: refactor magic
parent
85539a1f
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
14 additions
and
5 deletions
+14
-5
circle/firewall/models.py
+14
-5
No files found.
circle/firewall/models.py
View file @
1838f416
...
@@ -411,16 +411,22 @@ class Vlan(AclBase, models.Model):
...
@@ -411,16 +411,22 @@ class Vlan(AclBase, models.Model):
self
.
ipv6_template
=
tpl
self
.
ipv6_template
=
tpl
if
not
self
.
host_ipv6_prefixlen
:
if
not
self
.
host_ipv6_prefixlen
:
self
.
host_ipv6_prefixlen
=
prefixlen
self
.
host_ipv6_prefixlen
=
prefixlen
host4_bytes
=
self
.
_host_bytes
(
self
.
network4
.
prefixlen
,
4
)
host6_bytes
=
self
.
_host_bytes
(
self
.
network6
.
prefixlen
,
16
)
if
host4_bytes
>
host6_bytes
:
raise
ValidationError
(
_
(
"IPv6 network is too small to map IPv4 addresses to it."
))
@staticmethod
@staticmethod
def
_host_bytes
(
prefixlen
,
maxbytes
):
def
_host_bytes
(
prefixlen
,
maxbytes
):
return
int
(
ceil
((
maxbytes
-
prefixlen
/
8.0
)))
return
int
(
ceil
((
maxbytes
-
prefixlen
/
8.0
)))
@staticmethod
def
_append_hexa
(
s
,
v
,
lasthalf
):
if
lasthalf
:
# can use last half word
assert
s
[
-
1
]
==
"0"
or
s
[
-
1
]
.
endswith
(
"00"
)
if
s
[
-
1
]
.
endswith
(
"00"
):
s
[
-
1
]
=
s
[
-
1
][:
-
2
]
s
[
-
1
]
+=
"
%
({})02x"
.
format
(
v
)
s
[
-
1
]
.
lstrip
(
"0"
)
else
:
s
.
append
(
"
%
({})02x00"
.
format
(
v
))
@classmethod
@classmethod
def
_magic_ipv6_template
(
cls
,
network4
,
network6
,
verbose
=
None
):
def
_magic_ipv6_template
(
cls
,
network4
,
network6
,
verbose
=
None
):
"""Offer a sensible ipv6_template value.
"""Offer a sensible ipv6_template value.
...
@@ -438,6 +444,9 @@ class Vlan(AclBase, models.Model):
...
@@ -438,6 +444,9 @@ class Vlan(AclBase, models.Model):
"""
"""
host4_bytes
=
cls
.
_host_bytes
(
network4
.
prefixlen
,
4
)
host4_bytes
=
cls
.
_host_bytes
(
network4
.
prefixlen
,
4
)
host6_bytes
=
cls
.
_host_bytes
(
network6
.
prefixlen
,
16
)
host6_bytes
=
cls
.
_host_bytes
(
network6
.
prefixlen
,
16
)
if
host4_bytes
>
host6_bytes
:
raise
ValidationError
(
_
(
"IPv6 network is too small to map IPv4 addresses to it."
))
letters
=
ascii_letters
[
4
-
host4_bytes
:
4
]
letters
=
ascii_letters
[
4
-
host4_bytes
:
4
]
remove
=
host6_bytes
//
2
remove
=
host6_bytes
//
2
ipstr
=
network6
.
network
.
format
(
ipv6_full
)
ipstr
=
network6
.
network
.
format
(
ipv6_full
)
...
...
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