summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorChristian Poessinger <christian@poessinger.com>2019-08-28 10:59:09 +0200
committerChristian Poessinger <christian@poessinger.com>2019-08-28 10:59:13 +0200
commit71f7a947539963112c61fef2a5f278d524d71198 (patch)
treebe8931304ae58b19a23ffa2d23e75e4ebc1c0ec2
parente4f1bbb270f0afea295646764516675bbcfe0be5 (diff)
downloadvyos-1x-71f7a947539963112c61fef2a5f278d524d71198.tar.gz
vyos-1x-71f7a947539963112c61fef2a5f278d524d71198.zip
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.
-rwxr-xr-xsrc/conf_mode/interface-bridge.py38
1 files changed, 32 insertions, 6 deletions
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']: