Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix Bookworm networking at once #3059

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 21 additions & 11 deletions core/services/cable_guy/api/manager.py
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ def set_configuration(self, interface: NetworkInterface) -> None:
Args:
interface: NetworkInterface
"""
self.network_handler.cleanup_interface_connections(interface.name)
interfaces = self.get_ethernet_interfaces()
valid_names = [interface.name for interface in interfaces]
if interface.name not in valid_names:
Expand All @@ -100,11 +101,10 @@ def set_configuration(self, interface: NetworkInterface) -> None:
self.flush_interface(interface.name)
self.remove_dhcp_server_from_interface(interface.name)

# Even if it happened to receive more than one dynamic IP, only one trigger is necessary
if any(address.mode == AddressMode.Client for address in interface.addresses):
logger.info(f"Triggering dynamic IP acquisition for interface '{interface.name}'.")
self.trigger_dynamic_ip_acquisition(interface.name)

if interface.addresses:
# bring interface up
interface_index = self._get_interface_index(interface.name)
self.ipr.link("set", index=interface_index, state="up")
logger.info(f"Configuring addresses for interface '{interface.name}': {interface.addresses}.")
for address in interface.addresses:
if address.mode == AddressMode.Unmanaged:
Expand All @@ -113,6 +113,10 @@ def set_configuration(self, interface: NetworkInterface) -> None:
elif address.mode == AddressMode.Server:
logger.info(f"Adding DHCP server with gateway '{address.ip}' to interface '{interface.name}'.")
self.add_dhcp_server_to_interface(interface.name, address.ip)
# Even if it happened to receive more than one dynamic IP, only one trigger is necessary
if any(address.mode == AddressMode.Client for address in interface.addresses):
logger.info(f"Triggering dynamic IP acquisition for interface '{interface.name}'.")
self.trigger_dynamic_ip_acquisition(interface.name)

def _get_wifi_interfaces(self) -> List[str]:
"""Get wifi interface list
Expand Down Expand Up @@ -246,10 +250,17 @@ def trigger_dynamic_ip_acquisition(self, interface_name: str) -> None:
Args:
interface_name (str): Interface name
"""
logger.info(f"Restarting interface {interface_name} to trigger dynamic IP acquisition.")
self.enable_interface(interface_name, False)
time.sleep(1)
self.enable_interface(interface_name, True)
try:
self.network_handler.trigger_dynamic_ip_acquisition(interface_name)
return
except NotImplementedError as error:
logger.info(f"Handler does not support triggering dynamic IP acquisition. {error}")
logger.info(f"Restarting interface {interface_name} to trigger dynamic IP acquisition.")
self.enable_interface(interface_name, enable=False)
time.sleep(1)
self.enable_interface(interface_name, enable=True)
except Exception as error:
logger.error(f"Failed to trigger dynamic IP acquisition for interface {interface_name}. {error}")

def add_static_ip(self, interface_name: str, ip: str) -> None:
"""Set ip address for a specific interface
Expand All @@ -258,6 +269,7 @@ def add_static_ip(self, interface_name: str, ip: str) -> None:
interface_name (str): Interface name
ip (str): Desired ip address
"""

logger.info(f"Adding static IP '{ip}' to interface '{interface_name}'.")
self.network_handler.add_static_ip(interface_name, ip)
interface_index = self._get_interface_index(interface_name)
Expand All @@ -280,8 +292,6 @@ def remove_ip(self, interface_name: str, ip_address: str) -> None:
and self._dhcp_server_on_interface(interface_name).ipv4_gateway == ip_address
):
self.remove_dhcp_server_from_interface(interface_name)
interface_index = self._get_interface_index(interface_name)
self.ipr.addr("del", index=interface_index, address=ip_address, prefixlen=24)
self.network_handler.remove_static_ip(interface_name, ip_address)
except Exception as error:
raise RuntimeError(f"Cannot delete IP '{ip_address}' from interface {interface_name}.") from error
Expand Down
Loading
Loading