diff options
author | hagbard <vyosdev@derith.de> | 2019-02-04 12:14:26 -0800 |
---|---|---|
committer | hagbard <vyosdev@derith.de> | 2019-02-04 12:14:26 -0800 |
commit | 1a5b8f62569be1a9475ba2848da36fe2f74021b9 (patch) | |
tree | 11b4d00d147a7db4758dd2d182c3d02ce6c5d578 /src/conf_mode/wireguard.py | |
parent | 94860b853a41ce241598cb55966f4c2841cd2c1b (diff) | |
download | vyos-1x-1a5b8f62569be1a9475ba2848da36fe2f74021b9.tar.gz vyos-1x-1a5b8f62569be1a9475ba2848da36fe2f74021b9.zip |
enhancement: T1225 - wireguard implement 'set int wireguard wg0 peer name disable' to disable single peers
Diffstat (limited to 'src/conf_mode/wireguard.py')
-rwxr-xr-x | src/conf_mode/wireguard.py | 42 |
1 files changed, 23 insertions, 19 deletions
diff --git a/src/conf_mode/wireguard.py b/src/conf_mode/wireguard.py index c167366f1..e893dba47 100755 --- a/src/conf_mode/wireguard.py +++ b/src/conf_mode/wireguard.py @@ -104,26 +104,27 @@ def get_config(): ### peers if c.exists(cnf + ' peer'): for p in c.list_nodes(cnf + ' peer'): - config_data['interfaces'][intfc]['peer'].update( + if not c.exists(cnf + ' peer ' + p + ' disable'): + config_data['interfaces'][intfc]['peer'].update( { - p : { + p : { 'allowed-ips' : [], 'endpoint' : '', 'pubkey' : '' - } + } } - ) - if c.exists(cnf + ' peer ' + p + ' pubkey'): - config_data['interfaces'][intfc]['peer'][p]['pubkey'] = c.return_value(cnf + ' peer ' + p + ' pubkey') - if c.exists(cnf + ' peer ' + p + ' allowed-ips'): - config_data['interfaces'][intfc]['peer'][p]['allowed-ips'] = c.return_values(cnf + ' peer ' + p + ' allowed-ips') - if c.exists(cnf + ' peer ' + p + ' endpoint'): - config_data['interfaces'][intfc]['peer'][p]['endpoint'] = c.return_value(cnf + ' peer ' + p + ' endpoint') - if c.exists(cnf + ' peer ' + p + ' persistent-keepalive'): - config_data['interfaces'][intfc]['peer'][p]['persistent-keepalive'] = c.return_value(cnf + ' peer ' + p + ' persistent-keepalive') - if c.exists(cnf + ' peer ' + p + ' preshared-key'): - config_data['interfaces'][intfc]['peer'][p]['psk'] = c.return_value(cnf + ' peer ' + p + ' preshared-key') - + ) + if c.exists(cnf + ' peer ' + p + ' pubkey'): + config_data['interfaces'][intfc]['peer'][p]['pubkey'] = c.return_value(cnf + ' peer ' + p + ' pubkey') + if c.exists(cnf + ' peer ' + p + ' allowed-ips'): + config_data['interfaces'][intfc]['peer'][p]['allowed-ips'] = c.return_values(cnf + ' peer ' + p + ' allowed-ips') + if c.exists(cnf + ' peer ' + p + ' endpoint'): + config_data['interfaces'][intfc]['peer'][p]['endpoint'] = c.return_value(cnf + ' peer ' + p + ' endpoint') + if c.exists(cnf + ' peer ' + p + ' persistent-keepalive'): + config_data['interfaces'][intfc]['peer'][p]['persistent-keepalive'] = c.return_value(cnf + ' peer ' + p + ' persistent-keepalive') + if c.exists(cnf + ' peer ' + p + ' preshared-key'): + config_data['interfaces'][intfc]['peer'][p]['psk'] = c.return_value(cnf + ' peer ' + p + ' preshared-key') + return config_data def verify(c): @@ -238,17 +239,20 @@ def apply(c): sl.syslog(sl.LOG_NOTICE, "setting mtu to " + mtu + " on " + intf) subprocess.call(['ip l set mtu ' + mtu + ' dev ' + intf + ' &>/dev/null'], shell=True) + ### persistent-keepalive - for p in c_eff.list_nodes(intf + ' peer'): + for p in c['interfaces'][intf]['peer']: val_eff = "" val = "" + + try: + val = c['interfaces'][intf]['peer'][p]['persistent-keepalive'] + except KeyError: + pass if c_eff.exists_effective(intf + ' peer ' + p + ' persistent-keepalive'): val_eff = c_eff.return_effective_value(intf + ' peer ' + p + ' persistent-keepalive') - if 'persistent-keepalive' in c['interfaces'][intf]['peer'][p]: - val = c['interfaces'][intf]['peer'][p]['persistent-keepalive'] - ### disable keepalive if val_eff and not val: c['interfaces'][intf]['peer'][p]['persistent-keepalive'] = 0 |