Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
Gelencsér Szabolcs
/
fwdriver
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
0
Merge Requests
0
Wiki
Members
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
5283434f
authored
Oct 12, 2014
by
Bach Dániel
Committed by
Your Name
Oct 14, 2014
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
remove NETNS arg
parent
cc4e9a06
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
12 additions
and
12 deletions
+12
-12
fw.py
+9
-9
ovs.py
+2
-2
utils.py
+1
-1
No files found.
fw.py
View file @
5283434f
...
@@ -5,7 +5,7 @@ import json
...
@@ -5,7 +5,7 @@ import json
import
logging
import
logging
from
ovs
import
Switch
from
ovs
import
Switch
from
utils
import
(
NETNS
,
ns_exec
,
sudo
,
ADDRESSES
,
from
utils
import
(
ns_exec
,
sudo
,
ADDRESSES
,
dhcp_no_free_re
,
dhcp_ack_re
)
dhcp_no_free_re
,
dhcp_ack_re
)
DHCP_LOGFILE
=
getenv
(
'DHCP_LOGFILE'
,
'/var/log/syslog'
)
DHCP_LOGFILE
=
getenv
(
'DHCP_LOGFILE'
,
'/var/log/syslog'
)
...
@@ -29,8 +29,8 @@ logger = logging.getLogger(__name__)
...
@@ -29,8 +29,8 @@ logger = logging.getLogger(__name__)
@task
(
name
=
"firewall.reload_firewall"
)
@task
(
name
=
"firewall.reload_firewall"
)
def
reload_firewall
(
data4
,
data6
,
save_config
=
True
):
def
reload_firewall
(
data4
,
data6
,
save_config
=
True
):
try
:
try
:
ns_exec
(
NETNS
,
(
'ip6tables-restore'
,
'-c'
),
data6
)
ns_exec
((
'ip6tables-restore'
,
'-c'
),
data6
)
ns_exec
(
NETNS
,
(
'iptables-restore'
,
'-c'
),
data4
)
ns_exec
((
'iptables-restore'
,
'-c'
),
data4
)
except
:
except
:
logging
.
critical
(
'Unhandled exception: '
,
exc_info
=
True
)
logging
.
critical
(
'Unhandled exception: '
,
exc_info
=
True
)
raise
raise
...
@@ -60,7 +60,7 @@ def reload_firewall_vlan(data, save_config=True):
...
@@ -60,7 +60,7 @@ def reload_firewall_vlan(data, save_config=True):
json
.
dump
(
data
,
f
)
json
.
dump
(
data
,
f
)
try
:
try
:
ns_exec
(
NETNS
,
(
'ip'
,
'ro'
,
'add'
,
'default'
,
'via'
,
ns_exec
((
'ip'
,
'ro'
,
'add'
,
'default'
,
'via'
,
getenv
(
'GATEWAY'
,
'152.66.243.254'
)))
getenv
(
'GATEWAY'
,
'152.66.243.254'
)))
except
:
except
:
pass
pass
...
@@ -82,7 +82,7 @@ def ipset_save(data):
...
@@ -82,7 +82,7 @@ def ipset_save(data):
data_new
=
[
x
[
'ipv4'
]
for
x
in
data
]
data_new
=
[
x
[
'ipv4'
]
for
x
in
data
]
data_old
=
[]
data_old
=
[]
lines
=
ns_exec
(
NETNS
,
(
'ipset'
,
'save'
,
'blacklist'
))
lines
=
ns_exec
((
'ipset'
,
'save'
,
'blacklist'
))
for
line
in
lines
.
splitlines
():
for
line
in
lines
.
splitlines
():
x
=
r
.
match
(
line
.
rstrip
())
x
=
r
.
match
(
line
.
rstrip
())
if
x
:
if
x
:
...
@@ -101,7 +101,7 @@ def ipset_restore(l_add, l_del):
...
@@ -101,7 +101,7 @@ def ipset_restore(l_add, l_del):
ipset
+=
[
'add blacklist
%
s'
%
x
for
x
in
l_add
]
ipset
+=
[
'add blacklist
%
s'
%
x
for
x
in
l_add
]
ipset
+=
[
'del blacklist
%
s'
%
x
for
x
in
l_del
]
ipset
+=
[
'del blacklist
%
s'
%
x
for
x
in
l_del
]
ns_exec
(
NETNS
,
(
'ipset'
,
'restore'
,
'-exist'
),
ns_exec
((
'ipset'
,
'restore'
,
'-exist'
),
'
\n
'
.
join
(
ipset
)
+
'
\n
'
)
'
\n
'
.
join
(
ipset
)
+
'
\n
'
)
...
@@ -137,9 +137,9 @@ def get_dhcp_clients():
...
@@ -137,9 +137,9 @@ def get_dhcp_clients():
def
start_firewall
():
def
start_firewall
():
try
:
try
:
ns_exec
(
NETNS
,
(
'ipset'
,
'create'
,
'blacklist
'
,
ns_exec
(
(
'ipset'
,
'create'
,
'blacklist'
,
'hash:ip
'
,
'hash:ip'
,
'family'
,
'inet'
,
'hashsize
'
,
'family'
,
'inet'
,
'hashsize'
,
'4096'
,
'maxelem
'
,
'4096'
,
'maxelem'
,
'65536'
))
'65536'
))
except
:
except
:
pass
pass
try
:
try
:
...
...
ovs.py
View file @
5283434f
...
@@ -55,7 +55,7 @@ class Interface(object):
...
@@ -55,7 +55,7 @@ class Interface(object):
def
_run
(
self
,
*
args
):
def
_run
(
self
,
*
args
):
args
=
(
'ip'
,
'addr'
,
)
+
args
args
=
(
'ip'
,
'addr'
,
)
+
args
return
ns_exec
(
NETNS
,
args
)
return
ns_exec
(
args
)
def
show
(
self
):
def
show
(
self
):
retval
=
[]
retval
=
[]
...
@@ -79,7 +79,7 @@ class Interface(object):
...
@@ -79,7 +79,7 @@ class Interface(object):
def
up
(
self
):
def
up
(
self
):
if
self
.
is_veth
:
if
self
.
is_veth
:
ns_exec
(
NETNS
,
(
'ip'
,
'link'
,
'set'
,
'up'
,
self
.
name
))
ns_exec
((
'ip'
,
'link'
,
'set'
,
'up'
,
self
.
name
))
sudo
((
'ip'
,
'link'
,
'set'
,
'up'
,
self
.
external_name
))
sudo
((
'ip'
,
'link'
,
'set'
,
'up'
,
self
.
external_name
))
def
migrate
(
self
):
def
migrate
(
self
):
...
...
utils.py
View file @
5283434f
...
@@ -44,6 +44,6 @@ def sudo(args, stdin=None):
...
@@ -44,6 +44,6 @@ def sudo(args, stdin=None):
return
stdout
return
stdout
def
ns_exec
(
netns
,
args
,
stdin
=
None
):
def
ns_exec
(
args
,
stdin
=
None
):
return
sudo
((
'/sbin/ip'
,
'netns'
,
'exec'
,
return
sudo
((
'/sbin/ip'
,
'netns'
,
'exec'
,
NETNS
)
+
args
,
stdin
)
NETNS
)
+
args
,
stdin
)
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