diff options
| author | Christian Breunig <christian@breunig.cc> | 2026-11-07 22:15:37 +0100 |
|---|---|---|
| committer | Christian Breunig <christian@breunig.cc> | 2026-11-07 22:19:52 +0100 |
| commit | 504e08645611571f75cd373abb02be933aaa42b5 (patch) | |
| tree | 05d88dc662fa5b8a74d2748554d5dc142379717e /python | |
| parent | 51161f7e8e32580540e76c88ba2bd3c0619dac2c (diff) | |
| download | vyos-1x-504e08645611571f75cd373abb02be933aaa42b5.tar.gz vyos-1x-504e08645611571f75cd373abb02be933aaa42b5.zip | |
wwan: T9388: work out the bearer address families in one place
Which address families an interface takes from its bearer was derived
from "address dhcp", "address dhcpv6" and "ipv6 address autoconf" in
three places: the connect options, the FRR default routes and the
re-apply after a re-dial. Share a single helper so they cannot drift
apart. No functional change.
Diffstat (limited to 'python')
| -rw-r--r-- | python/vyos/configdict.py | 11 | ||||
| -rw-r--r-- | python/vyos/ifconfig/wwan.py | 12 | ||||
| -rw-r--r-- | python/vyos/utils/wwan.py | 21 |
3 files changed, 19 insertions, 25 deletions
diff --git a/python/vyos/configdict.py b/python/vyos/configdict.py index 89488126f..0a94cb84f 100644 --- a/python/vyos/configdict.py +++ b/python/vyos/configdict.py @@ -23,6 +23,7 @@ from vyos.config import Config from vyos.config import ConfigDict from vyos.utils.dict import dict_search from vyos.utils.process import cmdl +from vyos.utils.wwan import bearer_families def retrieve_config(path_hash, base_path, config): """ @@ -495,15 +496,7 @@ def get_wwan_interfaces(conf, vrf=None): if 'disable' in ifconfig: continue - options = {} - address = ifconfig.get('address', []) - if 'dhcp' in address: - options.update({'ipv4': {}}) - if ( - 'dhcpv6' in address - or dict_search('ipv6.address.autoconf', ifconfig) is not None - ): - options.update({'ipv6': {}}) + options = {family: {} for family in bearer_families(ifconfig)} if not options: continue diff --git a/python/vyos/ifconfig/wwan.py b/python/vyos/ifconfig/wwan.py index 4cf0127a2..3358c8da1 100644 --- a/python/vyos/ifconfig/wwan.py +++ b/python/vyos/ifconfig/wwan.py @@ -23,6 +23,7 @@ from vyos.utils.dict import dict_search from vyos.utils.misc import wait_for from vyos.utils.process import cmdl from vyos.utils.process import is_systemd_service_active +from vyos.utils.wwan import bearer_families from vyos.utils.wwan import get_bearer_address from vyos.utils.wwan import get_bearer_router from vyos.utils.wwan import modem_index @@ -139,17 +140,8 @@ class WWANIf(Interface): does. Returns False if there is no connected bearer yet, or a static one lacks its address, and the caller should try again.""" self.config = config - address = config.get('address') or [] - families = [] - if 'dhcp' in address: - families.append('ipv4') - if ( - 'dhcpv6' in address - or dict_search('ipv6.address.autoconf', config) is not None - ): - families.append('ipv6') complete = True - for family in families: + for family in bearer_families(config): bearer, method = self._wait_for_bearer_method(family) if method == 'static': if not self._apply_bearer_address(bearer, family): diff --git a/python/vyos/utils/wwan.py b/python/vyos/utils/wwan.py index e42adea16..949fbbeba 100644 --- a/python/vyos/utils/wwan.py +++ b/python/vyos/utils/wwan.py @@ -168,6 +168,17 @@ def start_modem_manager(ifname: str) -> None: return None +def bearer_families(config: dict) -> list: + """ Address families a WWAN interface is configured to get from the + bearer of its modem, as a list of 'ipv4' and/or 'ipv6' """ + families = [] + address = config.get('address', []) + if 'dhcp' in address: + families.append('ipv4') + if 'dhcpv6' in address or dict_search('ipv6.address.autoconf', config) != None: + families.append('ipv6') + return families + def connect_options(config: dict) -> str: """ Build the mmcli --simple-connect option string for a WWAN interface. @@ -175,14 +186,12 @@ def connect_options(config: dict) -> str: get_interface_dict() in conf_mode or op_mode_config_dict() in an op-mode context - both are key-mangled the same way, so both are accepted here. """ - ip_type = 'ipv4' - address = config.get('address', []) - slaac = dict_search('ipv6.address.autoconf', config) != None - if 'dhcp' in address and ('dhcpv6' in address or slaac): + families = bearer_families(config) + if families == ['ipv4', 'ipv6']: ip_type = 'ipv4v6' - elif 'dhcpv6' in address or slaac: + elif families == ['ipv6']: ip_type = 'ipv6' - elif 'dhcp' in address: + else: ip_type = 'ipv4' options = f'ip-type={ip_type},apn=' + config['apn'] |
