From 71f7a947539963112c61fef2a5f278d524d71198 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Wed, 28 Aug 2019 10:59:09 +0200 Subject: bridge: T1615: add missing support for DHCP/DHCPv6 interface address This feature is not well supported by pyroute2 and thus uses the proof-of-concept vyos.interfaceconfig library. Maybe it's a better idea to write our own library from scratch. --- src/conf_mode/interface-bridge.py | 38 ++++++++++++++++++++++++++++++++------ 1 file changed, 32 insertions(+), 6 deletions(-) (limited to 'src/conf_mode') diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index c1527e4a7..9918cbec7 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -22,6 +22,8 @@ from sys import exit from pyroute2 import IPDB from netifaces import interfaces from vyos.config import Config +from vyos.validate import is_ip +from vyos.interfaceconfig import Interface as IF from vyos import ConfigError default_config_data = { @@ -62,7 +64,9 @@ def get_config(): # Check if bridge has been removed if not conf.exists('interfaces bridge ' + bridge['intf']): bridge['deleted'] = True - return bridge + # we should not bail out early here b/c we should + # find possible DHCP interfaces later on. + # DHCP interfaces invoke dhclient which should be stopped, too # set new configuration level conf.set_level('interfaces bridge ' + bridge['intf']) @@ -185,6 +189,13 @@ def apply(bridge): # delete bridge interface with ipdb.interfaces[ brif ] as br: br.remove() + + # stop DHCP(v6) clients if configured + for addr in bridge['address_remove']: + if addr == 'dhcp': + IF(brif).del_dhcpv4() + elif addr == 'dhcpv6': + IF(brif).del_dhcpv6() except: pass else: @@ -225,16 +236,31 @@ def apply(bridge): for intf in bridge['member_remove']: br.del_port( intf['name'] ) - # configure bridge member interfaces + # add interfaces to bridge for member in bridge['member']: - # add interface br.add_port(member['name']) - # Configure interface address(es) + # remove configured network interface addresses/DHCP(v6) configuration for addr in bridge['address_remove']: - br.del_ip(addr) + try: + is_ip(addr) + br.del_ip(addr) + except ValueError: + if addr == 'dhcp': + IF(brif).del_dhcpv4() + elif addr == 'dhcpv6': + IF(brif).del_dhcpv6() + + # add configured network interface addresses/DHCP(v6) configuration for addr in bridge['address']: - br.add_ip(addr) + try: + is_ip(addr) + br.add_ip(addr) + except: + if addr == 'dhcp': + IF(brif).set_dhcpv4() + elif addr == 'dhcpv6': + IF(brif).set_dhcpv6() # up/down interface if bridge['disable']: -- cgit v1.2.3