diff options
Diffstat (limited to 'src')
-rwxr-xr-x | src/completion/list_wlm_peers.sh | 6 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-bonding.py | 7 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-bridge.py | 7 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-ethernet.py | 22 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-pppoe.py | 28 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-pseudo-ethernet.py | 7 | ||||
-rwxr-xr-x | src/conf_mode/interfaces-wireless.py | 7 | ||||
-rwxr-xr-x | src/migration-scripts/interfaces/9-to-10 | 64 | ||||
-rwxr-xr-x | src/services/vyos-hostsd | 14 | ||||
-rwxr-xr-x | src/system/on-dhcp-event.sh | 12 |
10 files changed, 132 insertions, 42 deletions
diff --git a/src/completion/list_wlm_peers.sh b/src/completion/list_wlm_peers.sh deleted file mode 100755 index 12dd00650..000000000 --- a/src/completion/list_wlm_peers.sh +++ /dev/null @@ -1,6 +0,0 @@ -#!/bin/sh - -if [ -d /etc/ppp/peers ]; then - cd /etc/ppp/peers - ls wlm* -fi diff --git a/src/conf_mode/interfaces-bonding.py b/src/conf_mode/interfaces-bonding.py index d87e0cd0e..c2081b8c3 100755 --- a/src/conf_mode/interfaces-bonding.py +++ b/src/conf_mode/interfaces-bonding.py @@ -302,8 +302,11 @@ def apply(bond): if bond['dhcpv6_temporary']: b.dhcp.v6.options['dhcpv6_temporary'] = True - if bond['dhcpv6_pd']: - b.dhcp.v6.options['dhcpv6_pd'] = bond['dhcpv6_pd'] + if bond['dhcpv6_pd_length']: + b.dhcp.v6.options['dhcpv6_pd_length'] = bond['dhcpv6_pd_length'] + + if bond['dhcpv6_pd_interfaces']: + b.dhcp.v6.options['dhcpv6_pd_interfaces'] = bond['dhcpv6_pd_interfaces'] # ignore link state changes b.set_link_detect(bond['disable_link_detect']) diff --git a/src/conf_mode/interfaces-bridge.py b/src/conf_mode/interfaces-bridge.py index af5372e21..1e4fa5816 100755 --- a/src/conf_mode/interfaces-bridge.py +++ b/src/conf_mode/interfaces-bridge.py @@ -324,8 +324,11 @@ def apply(bridge): if bridge['dhcpv6_temporary']: br.dhcp.v6.options['dhcpv6_temporary'] = True - if bridge['dhcpv6_pd']: - br.dhcp.v6.options['dhcpv6_pd'] = br['dhcpv6_pd'] + if bridge['dhcpv6_pd_length']: + br.dhcp.v6.options['dhcpv6_pd_length'] = br['dhcpv6_pd_length'] + + if bridge['dhcpv6_pd_interfaces']: + br.dhcp.v6.options['dhcpv6_pd_interfaces'] = br['dhcpv6_pd_interfaces'] # assign/remove VRF br.set_vrf(bridge['vrf']) diff --git a/src/conf_mode/interfaces-ethernet.py b/src/conf_mode/interfaces-ethernet.py index ef958e9f8..8d657acba 100755 --- a/src/conf_mode/interfaces-ethernet.py +++ b/src/conf_mode/interfaces-ethernet.py @@ -173,6 +173,10 @@ def verify(eth): f'Interface "{eth["intf"]}" cannot be member of VRF "{eth["vrf"]}" ' f'and "{memberof}" at the same time!')) + if eth['mac'] and eth['is_bond_member']: + print('WARNING: "mac {0}" command will be ignored because {1} is a part of {2}'\ + .format(eth['mac'], eth['intf'], eth['is_bond_member'])) + # use common function to verify VLAN configuration verify_vlan_config(eth) return None @@ -204,8 +208,11 @@ def apply(eth): if eth['dhcpv6_temporary']: e.dhcp.v6.options['dhcpv6_temporary'] = True - if eth['dhcpv6_pd']: - e.dhcp.v6.options['dhcpv6_pd'] = e['dhcpv6_pd'] + if eth['dhcpv6_pd_length']: + e.dhcp.v6.options['dhcpv6_pd_length'] = eth['dhcpv6_pd_length'] + + if eth['dhcpv6_pd_interfaces']: + e.dhcp.v6.options['dhcpv6_pd_interfaces'] = eth['dhcpv6_pd_interfaces'] # ignore link state changes e.set_link_detect(eth['disable_link_detect']) @@ -239,11 +246,12 @@ def apply(eth): e.del_ipv6_eui64_address(addr) # Change interface MAC address - re-set to real hardware address (hw-id) - # if custom mac is removed - if eth['mac']: - e.set_mac(eth['mac']) - elif eth['hw_id']: - e.set_mac(eth['hw_id']) + # if custom mac is removed. Skip if bond member. + if not eth['is_bond_member']: + if eth['mac']: + e.set_mac(eth['mac']) + elif eth['hw_id']: + e.set_mac(eth['hw_id']) # Add IPv6 EUI-based addresses for addr in eth['ipv6_eui64_prefix']: diff --git a/src/conf_mode/interfaces-pppoe.py b/src/conf_mode/interfaces-pppoe.py index ac0022dc1..231672490 100755 --- a/src/conf_mode/interfaces-pppoe.py +++ b/src/conf_mode/interfaces-pppoe.py @@ -21,15 +21,17 @@ from copy import deepcopy from netifaces import interfaces from vyos.config import Config +from vyos.configdict import dhcpv6_pd_default_data from vyos.ifconfig import Interface +from vyos.template import render from vyos.util import chown, chmod_755, call from vyos import ConfigError -from vyos.template import render from vyos import airbag airbag.enable() default_config_data = { + **dhcpv6_pd_default_data, 'access_concentrator': '', 'auth_username': '', 'auth_password': '', @@ -38,7 +40,6 @@ default_config_data = { 'deleted': False, 'description': '\0', 'disable': False, - 'dhcpv6_pd': [], 'intf': '', 'idle_timeout': '', 'ipv6_autoconf': False, @@ -139,15 +140,24 @@ def get_config(): if conf.exists('vrf'): pppoe['vrf'] = conf.return_value(['vrf']) - if conf.exists(['dhcpv6-options', 'delegate']): - for interface in conf.list_nodes(['dhcpv6-options', 'delegate']): + if conf.exists(['dhcpv6-options', 'prefix-delegation']): + dhcpv6_pd_path = base_path + [pppoe['intf'], + 'dhcpv6-options', 'prefix-delegation'] + conf.set_level(dhcpv6_pd_path) + + # retriebe DHCPv6-PD prefix helper length as some ISPs only hand out a + # /64 by default (https://phabricator.vyos.net/T2506) + if conf.exists(['length']): + pppoe['dhcpv6_pd_length'] = conf.return_value(['length']) + + for interface in conf.list_nodes(['interface']): + conf.set_level(dhcpv6_pd_path + ['interface', interface]) pd = { 'ifname': interface, 'sla_id': '', 'sla_len': '', 'if_id': '' } - conf.set_level(base_path + [pppoe['intf'], 'dhcpv6-options', 'delegate', interface]) if conf.exists(['sla-id']): pd['sla_id'] = conf.return_value(['sla-id']) @@ -155,10 +165,10 @@ def get_config(): if conf.exists(['sla-len']): pd['sla_len'] = conf.return_value(['sla-len']) - if conf.exists(['interface-id']): - pd['if_id'] = conf.return_value(['interface-id']) + if conf.exists(['address']): + pd['if_id'] = conf.return_value(['address']) - pppoe['dhcpv6_pd'].append(pd) + pppoe['dhcpv6_pd_interfaces'].append(pd) return pppoe @@ -225,7 +235,7 @@ def generate(pppoe): render(script_pppoe_ipv6_up, 'pppoe/ipv6-up.script.tmpl', pppoe, trim_blocks=True, permission=0o755) - if len(pppoe['dhcpv6_pd']) > 0: + if len(pppoe['dhcpv6_pd_interfaces']) > 0: # ipv6.tmpl relies on ifname - this should be made consitent in the # future better then double key-ing the same value pppoe['ifname'] = intf diff --git a/src/conf_mode/interfaces-pseudo-ethernet.py b/src/conf_mode/interfaces-pseudo-ethernet.py index 96ec5602d..b142688f6 100755 --- a/src/conf_mode/interfaces-pseudo-ethernet.py +++ b/src/conf_mode/interfaces-pseudo-ethernet.py @@ -174,8 +174,11 @@ def apply(peth): if peth['dhcpv6_temporary']: p.dhcp.v6.options['dhcpv6_temporary'] = True - if peth['dhcpv6_pd']: - p.dhcp.v6.options['dhcpv6_pd'] = peth['dhcpv6_pd'] + if peth['dhcpv6_pd_length']: + p.dhcp.v6.options['dhcpv6_pd_length'] = peth['dhcpv6_pd_length'] + + if peth['dhcpv6_pd_interfaces']: + p.dhcp.v6.options['dhcpv6_pd_interfaces'] = peth['dhcpv6_pd_interfaces'] # ignore link state changes p.set_link_detect(peth['disable_link_detect']) diff --git a/src/conf_mode/interfaces-wireless.py b/src/conf_mode/interfaces-wireless.py index 328632036..0162b642c 100755 --- a/src/conf_mode/interfaces-wireless.py +++ b/src/conf_mode/interfaces-wireless.py @@ -594,8 +594,11 @@ def apply(wifi): if wifi['dhcpv6_temporary']: w.dhcp.v6.options['dhcpv6_temporary'] = True - if wifi['dhcpv6_pd']: - w.dhcp.v6.options['dhcpv6_pd'] = wifi['dhcpv6_pd'] + if wifi['dhcpv6_pd_length']: + w.dhcp.v6.options['dhcpv6_pd_length'] = wifi['dhcpv6_pd_length'] + + if wifi['dhcpv6_pd_interfaces']: + w.dhcp.v6.options['dhcpv6_pd_interfaces'] = wifi['dhcpv6_pd_interfaces'] # ignore link state changes w.set_link_detect(wifi['disable_link_detect']) diff --git a/src/migration-scripts/interfaces/9-to-10 b/src/migration-scripts/interfaces/9-to-10 new file mode 100755 index 000000000..4aa2c42b5 --- /dev/null +++ b/src/migration-scripts/interfaces/9-to-10 @@ -0,0 +1,64 @@ +#!/usr/bin/env python3 +# +# Copyright (C) 2020 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/>. + +# - rename CLI node 'dhcpv6-options delgate' to 'dhcpv6-options prefix-delegation +# interface' +# - rename CLI node 'interface-id' for prefix-delegation to 'address' as it +# represents the local interface IPv6 address assigned by DHCPv6-PD + +from sys import exit, argv +from vyos.configtree import ConfigTree + +if __name__ == '__main__': + if (len(argv) < 1): + print("Must specify file name!") + exit(1) + + file_name = argv[1] + with open(file_name, 'r') as f: + config_file = f.read() + + config = ConfigTree(config_file) + + for intf_type in config.list_nodes(['interfaces']): + for intf in config.list_nodes(['interfaces', intf_type]): + # cache current config tree + base_path = ['interfaces', intf_type, intf, 'dhcpv6-options', + 'delegate'] + + if config.exists(base_path): + # cache new config tree + new_path = ['interfaces', intf_type, intf, 'dhcpv6-options', + 'prefix-delegation'] + if not config.exists(new_path): + config.set(new_path) + + # copy to new node + config.copy(base_path, new_path + ['interface']) + + # rename interface-id to address + for interface in config.list_nodes(new_path + ['interface']): + config.rename(new_path + ['interface', interface, 'interface-id'], 'address') + + # delete old noe + config.delete(base_path) + + try: + with open(file_name, 'w') as f: + f.write(config.to_string()) + except OSError as e: + print("Failed to save the modified config: {}".format(e)) + exit(1) diff --git a/src/services/vyos-hostsd b/src/services/vyos-hostsd index 6017cea82..bf5d67cfa 100755 --- a/src/services/vyos-hostsd +++ b/src/services/vyos-hostsd @@ -28,6 +28,7 @@ import zmq import collections import jinja2 +from vyos.util import popen, process_named_running debug = True @@ -212,13 +213,17 @@ def handle_message(msg_json): op = get_option(msg, 'op') _type = get_option(msg, 'type') + changes = 0 + if op == 'delete': tag = get_option(msg, 'tag') if _type == 'name_servers': delete_name_servers(STATE, tag) + changes += 1 elif _type == 'hosts': delete_hosts(STATE, tag) + changes += 1 else: raise ValueError("Unknown message type {0}".format(_type)) elif op == 'add': @@ -226,8 +231,10 @@ def handle_message(msg_json): entries = get_option(msg, 'data') if _type == 'name_servers': add_name_servers(STATE, entries, tag) + changes += 1 elif _type == 'hosts': add_hosts(STATE, entries, tag) + changes += 1 else: raise ValueError("Unknown message type {0}".format(_type)) elif op == 'set': @@ -236,6 +243,7 @@ def handle_message(msg_json): data = get_option(msg, 'data') if _type == 'host_name': set_host_name(STATE, data) + changes += 1 else: raise ValueError("Unknown message type {0}".format(_type)) elif op == 'get': @@ -255,6 +263,12 @@ def handle_message(msg_json): with open(STATE_FILE, 'w') as f: json.dump(STATE, f) + if changes > 0: + if process_named_running("pdns_recursor"): + (ret,return_code) = popen("sudo rec_control --socket-dir=/run/powerdns reload-zones") + if return_code > 0: + logger.exception("PowerDNS rec_control failed to reload") + def exit_handler(sig, frame): """ Clean up the state when shutdown correctly """ logger.info("Cleaning up state") diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh index 385ae460f..57f492401 100755 --- a/src/system/on-dhcp-event.sh +++ b/src/system/on-dhcp-event.sh @@ -20,7 +20,6 @@ client_ip=$3 client_mac=$4 domain=$5 file=/etc/hosts -changes=0 if [ -z "$client_name" ]; then logger -s -t on-dhcp-event "Client name was empty, using MAC \"$client_mac\" instead" @@ -44,13 +43,11 @@ case "$action" in fi # add host /usr/bin/vyos-hostsd-client --add-hosts --tag "DHCP-$client_ip" --host "$client_fqdn_name,$client_ip" - ((changes++)) ;; release) # delete mapping for released address # delete host /usr/bin/vyos-hostsd-client --delete-hosts --tag "DHCP-$client_ip" - ((changes++)) ;; *) @@ -59,15 +56,6 @@ case "$action" in ;; esac -if [ $changes -gt 0 ]; then - echo Success - pid=`pgrep pdns_recursor` - if [ -n "$pid" ]; then - sudo rec_control --socket-dir=/run/powerdns reload-zones - fi -else - echo No changes made -fi exit 0 |