Skip to content

Commit

Permalink
add cache.get_link_inet6_accept_ra && autoconf, and fix parsing of em…
Browse files Browse the repository at this point in the history
…pty netlink cache

factorize with adding_get_netlink_cache_accept_ra && _get_netlink_cache_auto
and correctly test if cache exist or not

the netlink cache can have empty value for an interface,
if the interface was not existing when we have populate the cache.
for example, a vlan interface created in pre-up by vlan module.

In this case, we return an empty string
  • Loading branch information
aderumier committed May 9, 2023
1 parent b5ba753 commit e56ffd9
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 13 deletions.
18 changes: 8 additions & 10 deletions ifupdown2/addons/address.py
Original file line number Diff line number Diff line change
Expand Up @@ -629,8 +629,8 @@ def process_addresses(self, ifaceobj, ifaceobj_getfunc=None, force_reapply=False
return

purge_v6_addresses = True
inet6conf = self.cache.get_link_inet6_conf(ifaceobj.name)
if not squash_addr_config and 'accept_ra' in inet6conf and inet6conf['accept_ra'] == 1:
running_accept_ra = self.cache.get_link_inet6_accept_ra(ifaceobj)
if running_accept_ra == '1' and not squash_addr_config:
self.logger.warning("%s: interface has ipv6 slaac enabled, skip purging existing ipv6 addresses" % ifname)
purge_v6_addresses = False

Expand Down Expand Up @@ -993,11 +993,8 @@ def _sysctl_config(self, ifaceobj):
addr_method = ifaceobj.addr_method
if addr_method not in ["auto"]:

inet6conf = self.cache.get_link_inet6_conf(ifaceobj.name)
running_accept_ra = str(inet6conf['accept_ra'])
running_autoconf = str(inet6conf['autoconf'])

try:
running_accept_ra = self.cache.get_link_inet6_accept_ra(ifaceobj)
accept_ra = ifaceobj.get_attr_value_first('accept-ra')
if accept_ra is None:
accept_ra = '0'
Expand All @@ -1007,6 +1004,7 @@ def _sysctl_config(self, ifaceobj):
%('/'.join(ifaceobj.name.split("."))),
accept_ra)

running_autoconf = self.cache.get_link_inet6_autoconf(ifaceobj)
autoconf = ifaceobj.get_attr_value_first('autoconf')
if autoconf is None:
autoconf = '0'
Expand Down Expand Up @@ -1370,16 +1368,16 @@ def _query_sysctl(self, ifaceobj, ifaceobjcurr):

accept_ra = ifaceobj.get_attr_value_first('accept-ra')
if accept_ra:
inet6conf = self.cache.get_link_inet6_conf(ifaceobj.name)
running_accept_ra = str(inet6conf['accept_ra'])
running_accept_ra = self.cache.get_link_inet6_accept_ra(ifaceobj)

ifaceobjcurr.update_config_with_status('accept_ra',
running_accept_ra,
accept_ra != running_accept_ra)

autoconf = ifaceobj.get_attr_value_first('autoconf')
if autoconf:
inet6conf = self.cache.get_link_inet6_conf(ifaceobj.name)
running_autoconf = str(inet6conf['autoconf'])
running_autoconf = self.cache.get_link_inet6_autoconf(ifaceobj)

ifaceobjcurr.update_config_with_status('autoconf',
running_autoconf,
autoconf != running_autoconf)
Expand Down
7 changes: 4 additions & 3 deletions ifupdown2/addons/auto.py
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,13 @@ def _up(self, ifaceobj):

try:
if 'inet6' in ifaceobj.addr_family:
inet6conf = self.cache.get_link_inet6_conf(ifaceobj.name)
if 'accept_ra' in inet6conf and inet6conf['accept_ra'] != 1:
running_accept_ra = self.cache.get_link_inet6_accept_ra(ifaceobj)
if running_accept_ra != '1':
self.sysctl_set('net.ipv6.conf.%s.accept_ra'
%('/'.join(ifaceobj.name.split("."))),
1)
if 'autoconf' in inet6conf and inet6conf['autoconf'] != 1:
running_autoconf = self.cache.get_link_inet6_autoconf(ifaceobj)
if running_autoconf != '1':
self.sysctl_set('net.ipv6.conf.%s.autoconf'
%('/'.join(ifaceobj.name.split("."))),
1)
Expand Down
16 changes: 16 additions & 0 deletions ifupdown2/lib/nlcache.py
Original file line number Diff line number Diff line change
Expand Up @@ -1188,6 +1188,22 @@ def get_link_inet6_conf(self, ifname):
except TypeError as e:
return self.__handle_type_error(inspect.currentframe().f_code.co_name, ifname, str(e), return_value=False)

def get_link_inet6_accept_ra(self, ifaceobj):
inet6conf = self.get_link_inet6_conf(ifaceobj.name)
if inet6conf and 'accept_ra' in inet6conf:
accept_ra = str(inet6conf['accept_ra'])
else:
accept_ra = ''
return accept_ra

def get_link_inet6_autoconf(self, ifaceobj):
inet6conf = self.get_link_inet6_conf(ifaceobj.name)
if inet6conf and 'autoconf' in inet6conf:
autoconf = str(inet6conf['autoconf'])
else:
autoconf = ''
return autoconf

#####################################################
#####################################################
#####################################################
Expand Down

0 comments on commit e56ffd9

Please sign in to comment.