Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gutyán Gábor
/
circlestack
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
68b9fe68
authored
Jul 10, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
firewall: ignore unmanaged vlans
parent
47a01c9a
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
32 additions
and
25 deletions
+32
-25
circle/firewall/fw.py
+2
-1
circle/firewall/models.py
+30
-24
No files found.
circle/firewall/fw.py
View file @
68b9fe68
...
@@ -319,7 +319,8 @@ def dhcp():
...
@@ -319,7 +319,8 @@ def dhcp():
def
vlan
():
def
vlan
():
obj
=
Vlan
.
objects
.
values
(
'vid'
,
'name'
,
'network4'
,
'network6'
)
obj
=
Vlan
.
objects
.
filter
(
managed
=
True
)
.
values
(
'vid'
,
'name'
,
'network4'
,
'network6'
)
retval
=
{
x
[
'name'
]:
{
'tag'
:
x
[
'vid'
],
retval
=
{
x
[
'name'
]:
{
'tag'
:
x
[
'vid'
],
'type'
:
'internal'
,
'type'
:
'internal'
,
'interfaces'
:
[
x
[
'name'
]],
'interfaces'
:
[
x
[
'name'
]],
...
...
circle/firewall/models.py
View file @
68b9fe68
...
@@ -189,19 +189,31 @@ class Rule(models.Model):
...
@@ -189,19 +189,31 @@ class Rule(models.Model):
def
get_absolute_url
(
self
):
def
get_absolute_url
(
self
):
return
(
'network.rule'
,
None
,
{
'pk'
:
self
.
pk
})
return
(
'network.rule'
,
None
,
{
'pk'
:
self
.
pk
})
@staticmethod
def
get_chain_name
(
self
,
local
,
remote
):
def
get_chain_name
(
local
,
remote
,
direction
):
if
local
:
# host or vlan
if
direction
==
'in'
:
if
self
.
direction
==
'in'
:
# remote -> local
# remote -> local
return
'
%
s_
%
s'
%
(
remote
,
local
)
return
'
%
s_
%
s'
%
(
remote
.
name
,
local
.
name
)
else
:
else
:
# local -> remote
# local -> remote
return
'
%
s_
%
s'
%
(
local
,
remote
)
return
'
%
s_
%
s'
%
(
local
.
name
,
remote
.
name
)
# firewall rule
elif
self
.
firewall_id
:
return
'INPUT'
if
self
.
direction
==
'in'
else
'OUTPUT'
def
get_dport_sport
(
self
):
if
self
.
direction
==
'in'
:
return
self
.
dport
,
self
.
sport
else
:
return
self
.
sport
,
self
.
dport
def
get_ipt_rules
(
self
,
host
=
None
):
def
get_ipt_rules
(
self
,
host
=
None
):
# action
# action
action
=
'LOG_ACC'
if
self
.
action
==
'accept'
else
'LOG_DROP'
action
=
'LOG_ACC'
if
self
.
action
==
'accept'
else
'LOG_DROP'
# 'chain_name': rule dict
retval
=
{}
# src and dst addresses
# src and dst addresses
src
=
None
src
=
None
dst
=
None
dst
=
None
...
@@ -212,34 +224,28 @@ class Rule(models.Model):
...
@@ -212,34 +224,28 @@ class Rule(models.Model):
dst
=
ip
dst
=
ip
else
:
else
:
src
=
ip
src
=
ip
vlan
=
host
.
vlan
# src and dst ports
elif
self
.
vlan_id
:
if
self
.
direction
==
'in'
:
vlan
=
self
.
vlan
dport
=
self
.
dport
sport
=
self
.
sport
else
:
else
:
dport
=
self
.
sport
vlan
=
None
sport
=
self
.
dport
# 'chain_name': rule dict
if
vlan
and
not
vlan
.
managed
:
retval
=
{}
return
retval
# src and dst ports
dport
,
sport
=
self
.
get_dport_sport
()
# process foreign vlans
# process foreign vlans
for
foreign_vlan
in
self
.
foreign_network
.
vlans
.
all
():
for
foreign_vlan
in
self
.
foreign_network
.
vlans
.
all
():
if
not
foreign_vlan
.
managed
:
continue
r
=
IptRule
(
priority
=
self
.
weight
,
action
=
action
,
r
=
IptRule
(
priority
=
self
.
weight
,
action
=
action
,
proto
=
self
.
proto
,
extra
=
self
.
extra
,
proto
=
self
.
proto
,
extra
=
self
.
extra
,
comment
=
'Rule #
%
s'
%
self
.
pk
,
comment
=
'Rule #
%
s'
%
self
.
pk
,
src
=
src
,
dst
=
dst
,
dport
=
dport
,
sport
=
sport
)
src
=
src
,
dst
=
dst
,
dport
=
dport
,
sport
=
sport
)
# host, hostgroup or vlan rule
chain_name
=
self
.
get_chain_name
(
local
=
vlan
,
remote
=
foreign_vlan
)
if
host
or
self
.
vlan_id
:
local_vlan
=
host
.
vlan
.
name
if
host
else
self
.
vlan
.
name
chain_name
=
Rule
.
get_chain_name
(
local
=
local_vlan
,
remote
=
foreign_vlan
.
name
,
direction
=
self
.
direction
)
# firewall rule
elif
self
.
firewall_id
:
chain_name
=
'INPUT'
if
self
.
direction
==
'in'
else
'OUTPUT'
retval
[
chain_name
]
=
r
retval
[
chain_name
]
=
r
return
retval
return
retval
...
...
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