From afc82770cce851da31267829f1726f85093d9d76 Mon Sep 17 00:00:00 2001 From: Christian Poessinger Date: Tue, 8 Oct 2019 21:23:57 +0200 Subject: Python/ifconfig: T1557: add generic support for DHCP client options --- src/conf_mode/interface-bonding.py | 15 ++++++++++++--- src/conf_mode/interface-bridge.py | 33 +++++++++++++++++++++++++++++++++ src/conf_mode/interface-ethernet.py | 28 +++++++++++++++++++++++++--- 3 files changed, 70 insertions(+), 6 deletions(-) (limited to 'src') diff --git a/src/conf_mode/interface-bonding.py b/src/conf_mode/interface-bonding.py index 4d5009c73..7caf9e0e8 100755 --- a/src/conf_mode/interface-bonding.py +++ b/src/conf_mode/interface-bonding.py @@ -368,9 +368,18 @@ def apply(bond): # update interface description used e.g. within SNMP b.set_alias(bond['description']) - # - # missing DHCP/DHCPv6 options go here - # + # get DHCP config dictionary and update values + opt = b.get_dhcp_options() + + if bond['dhcp_client_id']: + opt['client_id'] = bond['dhcp_client_id'] + + if bond['dhcp_hostname']: + opt['hostname'] = bond['dhcp_hostname'] + + # store DHCP config dictionary - used later on when addresses + # are requested + b.set_dhcp_options(opt) # ignore link state changes b.set_link_detect(bond['disable_link_detect']) diff --git a/src/conf_mode/interface-bridge.py b/src/conf_mode/interface-bridge.py index 37b5c4979..b2755547c 100755 --- a/src/conf_mode/interface-bridge.py +++ b/src/conf_mode/interface-bridge.py @@ -32,6 +32,10 @@ default_config_data = { 'arp_cache_tmo': 30, 'description': '', 'deleted': False, + 'dhcp_client_id': '', + 'dhcp_hostname': '', + 'dhcpv6_prm_only': False, + 'dhcpv6_temporary': False, 'disable': False, 'disable_link_detect': 1, 'forwarding_delay': 14, @@ -81,6 +85,22 @@ def get_config(): if conf.exists('description'): bridge['description'] = conf.return_value('description') + # get DHCP client identifier + if conf.exists('dhcp-options client-id'): + bridge['dhcp_client_id'] = conf.return_value('dhcp-options client-id') + + # DHCP client host name (overrides the system host name) + if conf.exists('dhcp-options host-name'): + bridge['dhcp_hostname'] = conf.return_value('dhcp-options host-name') + + # DHCPv6 only acquire config parameters, no address + if conf.exists('dhcpv6-options parameters-only'): + bridge['dhcpv6_prm_only'] = conf.return_value('dhcpv6-options parameters-only') + + # DHCPv6 temporary IPv6 address + if conf.exists('dhcpv6-options temporary'): + bridge['dhcpv6_temporary'] = conf.return_value('dhcpv6-options temporary') + # Disable this bridge interface if conf.exists('disable'): bridge['disable'] = True @@ -203,6 +223,19 @@ def apply(bridge): # update interface description used e.g. within SNMP br.set_alias(bridge['description']) + # get DHCP config dictionary and update values + opt = br.get_dhcp_options() + + if bridge['dhcp_client_id']: + opt['client_id'] = bridge['dhcp_client_id'] + + if bridge['dhcp_hostname']: + opt['hostname'] = bridge['dhcp_hostname'] + + # store DHCP config dictionary - used later on when addresses + # are requested + br.set_dhcp_options(opt) + # Change interface MAC address if bridge['mac']: br.set_mac(bridge['mac']) diff --git a/src/conf_mode/interface-ethernet.py b/src/conf_mode/interface-ethernet.py index 317da5772..5f9b4d8b0 100755 --- a/src/conf_mode/interface-ethernet.py +++ b/src/conf_mode/interface-ethernet.py @@ -66,6 +66,19 @@ def apply_vlan_config(vlan, config): if type(vlan) != type(VLANIf("lo")): raise TypeError() + # get DHCP config dictionary and update values + opt = vlan.get_dhcp_options() + + if config['dhcp_client_id']: + opt['client_id'] = config['dhcp_client_id'] + + if config['dhcp_hostname']: + opt['hostname'] = config['dhcp_hostname'] + + # store DHCP config dictionary - used later on when addresses + # are requested + vlan.set_dhcp_options(opt) + # update interface description used e.g. within SNMP vlan.set_alias(config['description']) # ignore link state changes @@ -273,9 +286,18 @@ def apply(eth): # update interface description used e.g. within SNMP e.set_alias(eth['description']) - # - # missing DHCP/DHCPv6 options go here - # + # get DHCP config dictionary and update values + opt = e.get_dhcp_options() + + if eth['dhcp_client_id']: + opt['client_id'] = eth['dhcp_client_id'] + + if eth['dhcp_hostname']: + opt['hostname'] = eth['dhcp_hostname'] + + # store DHCP config dictionary - used later on when addresses + # are requested + e.set_dhcp_options(opt) # ignore link state changes e.set_link_detect(eth['disable_link_detect']) -- cgit v1.2.3