diff options
author | Daniil Baturin <daniil@vyos.io> | 2025-01-24 18:13:08 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2025-01-24 18:13:08 +0000 |
commit | 2f8d231f4ae16cd49a36bc3d5e11b25db1501240 (patch) | |
tree | 1a5c6d3fb9acbbb23fa47084c7b4d9676b061b5a /src/op_mode | |
parent | f0e05ba825f5f154c570487d1b189a8be6f3b121 (diff) | |
parent | 98414a69f0018915ac999f51975618dd5fbe817d (diff) | |
download | vyos-1x-2f8d231f4ae16cd49a36bc3d5e11b25db1501240.tar.gz vyos-1x-2f8d231f4ae16cd49a36bc3d5e11b25db1501240.zip |
Merge pull request #4200 from sskaje/T4930-1
T4930: Allow WireGuard peers via DNS hostname
Diffstat (limited to 'src/op_mode')
-rwxr-xr-x | src/op_mode/reset_wireguard.py | 55 |
1 files changed, 55 insertions, 0 deletions
diff --git a/src/op_mode/reset_wireguard.py b/src/op_mode/reset_wireguard.py new file mode 100755 index 000000000..1fcfb31b5 --- /dev/null +++ b/src/op_mode/reset_wireguard.py @@ -0,0 +1,55 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2025 VyOS maintainers and contributors +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License version 2 or later as +# published by the Free Software Foundation. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program. If not, see <http://www.gnu.org/licenses/>. + +import sys +import typing + +import vyos.opmode + +from vyos.ifconfig import WireGuardIf +from vyos.configquery import ConfigTreeQuery + + +def _verify(func): + """Decorator checks if WireGuard interface config exists""" + from functools import wraps + + @wraps(func) + def _wrapper(*args, **kwargs): + config = ConfigTreeQuery() + interface = kwargs.get('interface') + if not config.exists(['interfaces', 'wireguard', interface]): + unconf_message = f'WireGuard interface {interface} is not configured' + raise vyos.opmode.UnconfiguredSubsystem(unconf_message) + return func(*args, **kwargs) + + return _wrapper + + +@_verify +def reset_peer(interface: str, peer: typing.Optional[str] = None): + intf = WireGuardIf(interface, create=False, debug=False) + return intf.operational.reset_peer(peer) + + +if __name__ == '__main__': + try: + res = vyos.opmode.run(sys.modules[__name__]) + if res: + print(res) + except (ValueError, vyos.opmode.Error) as e: + print(e) + sys.exit(1) |