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
13db8991
Commit
13db8991
authored
Feb 02, 2020
by
Haw Loeung
Committed by
Brian May
Feb 03, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added nft_chain_exists() and fixed nft to use that
parent
84076f29
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
28 additions
and
4 deletions
+28
-4
linux.py
sshuttle/linux.py
+26
-0
nft.py
sshuttle/methods/nft.py
+2
-4
No files found.
sshuttle/linux.py
View file @
13db8991
...
@@ -68,6 +68,32 @@ def nft(family, table, action, *args):
...
@@ -68,6 +68,32 @@ def nft(family, table, action, *args):
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
rv
))
raise
Fatal
(
'
%
r returned
%
d'
%
(
argv
,
rv
))
def
nft_chain_exists
(
family
,
table
,
name
):
if
family
==
socket
.
AF_INET
:
fam
=
'ip'
elif
family
==
socket
.
AF_INET6
:
fam
=
'ip6'
else
:
raise
Exception
(
'Unsupported family "
%
s"'
%
family_to_string
(
family
))
argv
=
[
'nft'
,
'list'
,
'chain'
,
fam
,
table
,
name
]
debug1
(
'>>
%
s
\n
'
%
' '
.
join
(
argv
))
env
=
{
'PATH'
:
os
.
environ
[
'PATH'
],
'LC_ALL'
:
"C"
,
}
try
:
table_exists
=
False
output
=
ssubprocess
.
check_output
(
argv
,
env
=
env
,
stderr
=
ssubprocess
.
STDOUT
)
for
line
in
output
.
decode
(
'ASCII'
)
.
split
(
'
\n
'
):
if
line
.
startswith
(
'table
%
s
%
s '
%
(
fam
,
table
)):
table_exists
=
True
if
table_exists
and
(
'chain
%
s {'
%
name
)
in
line
:
return
True
except
ssubprocess
.
CalledProcessError
:
return
False
def
nft_get_handle
(
expression
,
chain
):
def
nft_get_handle
(
expression
,
chain
):
cmd
=
'nft'
cmd
=
'nft'
argv
=
[
cmd
,
'list'
,
expression
,
'-a'
]
argv
=
[
cmd
,
'list'
,
expression
,
'-a'
]
...
...
sshuttle/methods/nft.py
View file @
13db8991
import
socket
import
socket
from
sshuttle.firewall
import
subnet_weight
from
sshuttle.firewall
import
subnet_weight
from
sshuttle.helpers
import
Fatal
,
log
from
sshuttle.helpers
import
Fatal
,
log
from
sshuttle.linux
import
nft
,
nft_get_handle
,
nonfatal
from
sshuttle.linux
import
nft
,
nft_get_handle
,
n
ft_chain_exists
,
n
onfatal
from
sshuttle.methods
import
BaseMethod
from
sshuttle.methods
import
BaseMethod
...
@@ -28,10 +28,8 @@ class Method(BaseMethod):
...
@@ -28,10 +28,8 @@ class Method(BaseMethod):
for
chain
in
[
'prerouting'
,
'postrouting'
,
'output'
]:
for
chain
in
[
'prerouting'
,
'postrouting'
,
'output'
]:
rules
=
'{{ type nat hook {} priority -100; policy accept; }}'
\
rules
=
'{{ type nat hook {} priority -100; policy accept; }}'
\
.
format
(
chain
)
.
format
(
chain
)
try
:
if
not
nft_chain_exists
(
family
,
table
,
chain
)
:
_nft
(
'add chain'
,
chain
,
rules
)
_nft
(
'add chain'
,
chain
,
rules
)
except
Fatal
:
log
(
'Chain {} already exists, ignoring
\n
'
.
format
(
chain
))
chain
=
'sshuttle-
%
s'
%
port
chain
=
'sshuttle-
%
s'
%
port
...
...
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