Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Fukász Rómeó Ervin
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
A prog2-höz tartozó friss repo anyagok itt elérhetőek:
https://git.iit.bme.hu/
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
Show 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):
self
.
ipv6_template
=
tpl
if
not
self
.
host_ipv6_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
def
_host_bytes
(
prefixlen
,
maxbytes
):
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
def
_magic_ipv6_template
(
cls
,
network4
,
network6
,
verbose
=
None
):
"""Offer a sensible ipv6_template value.
...
...
@@ -438,6 +444,9 @@ class Vlan(AclBase, models.Model):
"""
host4_bytes
=
cls
.
_host_bytes
(
network4
.
prefixlen
,
4
)
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
]
remove
=
host6_bytes
//
2
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