Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
S
sshuttle
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
pub
sshuttle
Commits
4db9b372
Commit
4db9b372
authored
Jun 06, 2011
by
Brian May
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make iptables functions work with any table, not just nat.
parent
061e6a09
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
8 additions
and
7 deletions
+8
-7
firewall.py
firewall.py
+8
-7
No files found.
firewall.py
View file @
4db9b372
...
@@ -14,12 +14,12 @@ def nonfatal(func, *args):
...
@@ -14,12 +14,12 @@ def nonfatal(func, *args):
log
(
'error:
%
s
\n
'
%
e
)
log
(
'error:
%
s
\n
'
%
e
)
def
ipt_chain_exists
(
family
,
name
):
def
ipt_chain_exists
(
family
,
table
,
name
):
if
family
==
socket
.
AF_INET
:
if
family
==
socket
.
AF_INET
:
cmd
=
'iptables'
cmd
=
'iptables'
else
:
else
:
raise
Exception
(
'Unsupported family "
%
s"'
%
family_to_string
(
family
))
raise
Exception
(
'Unsupported family "
%
s"'
%
family_to_string
(
family
))
argv
=
[
cmd
,
'-t'
,
'nat'
,
'-nL'
]
argv
=
[
cmd
,
'-t'
,
table
,
'-nL'
]
p
=
ssubprocess
.
Popen
(
argv
,
stdout
=
ssubprocess
.
PIPE
)
p
=
ssubprocess
.
Popen
(
argv
,
stdout
=
ssubprocess
.
PIPE
)
for
line
in
p
.
stdout
:
for
line
in
p
.
stdout
:
if
line
.
startswith
(
'Chain
%
s '
%
name
):
if
line
.
startswith
(
'Chain
%
s '
%
name
):
...
@@ -29,9 +29,9 @@ def ipt_chain_exists(family, name):
...
@@ -29,9 +29,9 @@ def ipt_chain_exists(family, name):
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
rv
))
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
rv
))
def
_ipt
(
family
,
*
args
):
def
_ipt
(
family
,
table
,
*
args
):
if
family
==
socket
.
AF_INET
:
if
family
==
socket
.
AF_INET
:
argv
=
[
'iptables'
,
'-t'
,
'nat'
]
+
list
(
args
)
argv
=
[
'iptables'
,
'-t'
,
table
]
+
list
(
args
)
else
:
else
:
raise
Exception
(
'Unsupported family "
%
s"'
%
family_to_string
(
family
))
raise
Exception
(
'Unsupported family "
%
s"'
%
family_to_string
(
family
))
debug1
(
'>>
%
s
\n
'
%
' '
.
join
(
argv
))
debug1
(
'>>
%
s
\n
'
%
' '
.
join
(
argv
))
...
@@ -70,15 +70,16 @@ def do_iptables(port, dnsport, family, subnets):
...
@@ -70,15 +70,16 @@ def do_iptables(port, dnsport, family, subnets):
if
family
!=
socket
.
AF_INET
:
if
family
!=
socket
.
AF_INET
:
raise
Exception
(
'Address family "
%
s" unsupported by nat method'
%
family_to_string
(
family
))
raise
Exception
(
'Address family "
%
s" unsupported by nat method'
%
family_to_string
(
family
))
table
=
"nat"
def
ipt
(
*
args
):
def
ipt
(
*
args
):
return
_ipt
(
family
,
*
args
)
return
_ipt
(
family
,
table
,
*
args
)
def
ipt_ttl
(
*
args
):
def
ipt_ttl
(
*
args
):
return
_ipt_ttl
(
family
,
*
args
)
return
_ipt_ttl
(
family
,
table
,
*
args
)
chain
=
'sshuttle-
%
s'
%
port
chain
=
'sshuttle-
%
s'
%
port
# basic cleanup/setup of chains
# basic cleanup/setup of chains
if
ipt_chain_exists
(
family
,
chain
):
if
ipt_chain_exists
(
family
,
table
,
chain
):
nonfatal
(
ipt
,
'-D'
,
'OUTPUT'
,
'-j'
,
chain
)
nonfatal
(
ipt
,
'-D'
,
'OUTPUT'
,
'-j'
,
chain
)
nonfatal
(
ipt
,
'-D'
,
'PREROUTING'
,
'-j'
,
chain
)
nonfatal
(
ipt
,
'-D'
,
'PREROUTING'
,
'-j'
,
chain
)
nonfatal
(
ipt
,
'-F'
,
chain
)
nonfatal
(
ipt
,
'-F'
,
chain
)
...
...
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