From e5e56ca6249f82ffcdd9f1b8496bedaccf0461d3 Mon Sep 17 00:00:00 2001 From: "A. Wilcox" Date: Wed, 2 Dec 2020 20:26:58 -0600 Subject: ifupdown-ng NMSA: Add most of ipv4_enabled --- ncserver/module/nms_ifupdownng.py | 44 +++++++++++++++++++++++++++++---------- 1 file changed, 33 insertions(+), 11 deletions(-) (limited to 'ncserver/module/nms_ifupdownng.py') diff --git a/ncserver/module/nms_ifupdownng.py b/ncserver/module/nms_ifupdownng.py index 66f2d19..e88a063 100644 --- a/ncserver/module/nms_ifupdownng.py +++ b/ncserver/module/nms_ifupdownng.py @@ -261,7 +261,7 @@ def get_sysctl_bool(iface: str, parameter: str) -> bool: return False -def get_sysctl_int(iface: str, parameter: str) -> int: +def get_sysctl_int(iface: str, parameter: str): """Retrieve the specified integer from sysctl.conf.""" value = get_sysctl(iface, parameter) if value is None: @@ -270,6 +270,22 @@ def get_sysctl_int(iface: str, parameter: str) -> int: return int(value) +def get_ipv4en(iface: str, _) -> bool: + """Retrieve IPv4 enablement status for the specified interface.""" + executors = _find_many(iface, 'use') + v4_execs = ('dhcp', 'apipa', 'loopback') + if any(executor in executors for executor in v4_execs): + # We can't guarantee that DHCPv4 is in use on this interface, + # but we can't guarantee it isn't, either. + return True + + if any('.' in addr for addr in list_addresses(iface)): + # IPv4 addresses contain '.'s, others don't. + return True + + return False + + def get_ipv6en(iface: str, parameter: str): """Retrieve IPv6 enablement status for the specified interface.""" return not get_sysctl_bool(iface, parameter) @@ -319,6 +335,11 @@ def live_sysctl_int(iface: str, parameter: str) -> int: return int(value) +def live_ipv4en(iface: str, _) -> bool: + """Retrieve the current IPv4 status for the specified interface.""" + raise NotImplementedError + + def live_ipv6en(iface: str, parameter: str): """Retrieve current IPv6 status for the specified interface.""" return not live_sysctl_bool(iface, parameter) @@ -371,6 +392,11 @@ def set_sysctl_int(iface: str, parameter: str, value: int): set_sysctl(iface, parameter, str(value)) +def set_ipv4en(iface: str, _, value: bool): + """Set the IPv4 enabled flag.""" + raise NotImplementedError + + def set_ipv6en(iface: str, parameter: str, value: bool): """Set IPv6 enabled/disabled for the specified interface.""" set_sysctl_bool(iface, parameter, not value) @@ -447,6 +473,11 @@ def unset_sysctl(iface: str, parameter: str): _sysctl_save() +def unset_ipv4en(iface: str, _): + """Unset the IPv4 enabled flag.""" + raise NotImplementedError + + def unset_slaac(iface: str, parameter: str): """Set SLAAC parameters for the specified interface.""" curr_global = get_slaac(iface, 'ipv6_slaac_globaladdr') @@ -475,7 +506,7 @@ _PARAMETERS = { # "name": (getter, live getter, setter, unsetter) 'description': (get_one_eni, get_one_eni, set_desc, unset_one_eni), 'enabled': (get_one_eni, get_one_eni, set_auto, unset_one_eni), - # XXX TODO: ipv4_enabled + 'ipv4_enabled': (get_ipv4en, live_ipv4en, set_ipv4en, unset_ipv4en), 'ipv4_forwarding': (get_sysctl_bool, live_sysctl_bool, set_sysctl_bool, unset_sysctl), 'ipv4_mtu': (get_one_eni, live_ipv4_mtu, @@ -567,15 +598,6 @@ def curr_param(iface: str, parameter: str): _load_config() # Won't read from sysctl.conf so don't need to _load_sysctl_cfg. - # XXX how do we want to handle interfaces that are missing from /e/n/i - # but are still present in the system? - if iface not in _CONFIG.keys(): - LOGGER.warning( - _("requested parameter %s for non-existent interface %s"), - parameter, iface - ) - return None - if parameter not in _PARAMETERS.keys(): LOGGER.error(_("requested non-existent parameter %s for interface %s"), parameter, iface) -- cgit v1.2.3-60-g2f50