-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Issue #568 --------- Signed-off-by: Tommaso Bailetti <[email protected]>
- Loading branch information
Showing
4 changed files
with
159 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
#!/usr/bin/python3 | ||
|
||
# | ||
# Copyright (C) 2024 Nethesis S.r.l. | ||
# SPDX-License-Identifier: GPL-2.0-only | ||
# | ||
|
||
import json | ||
import sys | ||
|
||
from nethsec import conntrack | ||
from nethsec.utils import ValidationError, generic_error | ||
|
||
cmd = sys.argv[1] | ||
|
||
if cmd == 'list': | ||
print(json.dumps({ | ||
'list': {}, | ||
'drop': { | ||
'id': '' | ||
}, | ||
'drop_all': {} | ||
})) | ||
elif cmd == 'call': | ||
action = sys.argv[2] | ||
if action == 'list': | ||
print(json.dumps({ | ||
'data': conntrack.list_connections() | ||
})) | ||
elif action == 'drop': | ||
data = json.loads(sys.stdin.read()) | ||
if 'id' not in data: | ||
raise ValidationError('id', 'required') | ||
try: | ||
conntrack.drop_connection(data['id']) | ||
except ValueError as e: | ||
# this connection is not found, probably already dropped | ||
pass | ||
except RuntimeError as e: | ||
json.dump(generic_error('command failed'), sys.stdout) | ||
|
||
json.dump({'message': 'success'}, sys.stdout) | ||
elif action == 'drop_all': | ||
try: | ||
conntrack.drop_all_connections() | ||
json.dump({'message': 'success'}, sys.stdout) | ||
except RuntimeError as e: | ||
json.dump(generic_error('command failed'), sys.stdout) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
{ | ||
"conntrack-tool": { | ||
"description": "List and manage connection entries using conntrack", | ||
"write": {}, | ||
"read": { | ||
"ubus": { | ||
"ns.conntrack": [ | ||
"*" | ||
] | ||
} | ||
} | ||
} | ||
} |