@@ -383,8 +383,8 @@ def remove_ip(self, interface_name: str, ip_address: str) -> None:
383383
384384 self ._update_interface_settings (interface_name , saved_interface )
385385
386- def get_interface_by_name (self , name : str ) -> NetworkInterface :
387- for interface in self .get_ethernet_interfaces ():
386+ def get_interface_by_name (self , name : str , include_dhcp_markers : bool = False ) -> NetworkInterface :
387+ for interface in self .get_ethernet_interfaces (include_dhcp_markers ):
388388 if interface .name == name :
389389 return interface
390390 raise ValueError (f"No interface with name '{ name } ' is present." )
@@ -393,11 +393,13 @@ def get_saved_interface_by_name(self, name: str) -> Optional[NetworkInterface]:
393393 return next ((i for i in self ._settings .content if i .name == name ), None )
394394
395395 # pylint: disable=too-many-locals
396- def get_interfaces (self , filter_wifi : bool = False ) -> List [NetworkInterface ]:
396+ def get_interfaces (self , filter_wifi : bool = False , include_dhcp_markers : bool = False ) -> List [NetworkInterface ]:
397397 """Get interfaces information
398398
399399 Args:
400400 filter_wifi (boolean, optional): Enable wifi interface filtering
401+ include_dynamic_markers (boolean, optional): DHCP marker is the IP 0.0.0.0 AddressMode.Client, used to
402+ inform cable guy that a dynamic IP should be acquired if available.
401403
402404 Returns:
403405 List of NetworkInterface instances available
@@ -431,6 +433,20 @@ def get_interfaces(self, filter_wifi: bool = False) -> List[NetworkInterface]:
431433 else :
432434 mode = AddressMode .Unmanaged if is_static_ip and valid_ip else AddressMode .Client
433435 valid_addresses .append (InterfaceAddress (ip = ip , mode = mode ))
436+ # Check if there is a 0.0.0.0 AddressMode.Client in current interface on self._settings.content and if not in valid_addresses add it
437+ interface_settings = self .get_saved_interface_by_name (interface )
438+ if (
439+ include_dhcp_markers
440+ and interface_settings
441+ and any (
442+ str (address .ip ) == "0.0.0.0" and address .mode == AddressMode .Client
443+ for address in interface_settings .addresses
444+ )
445+ and not any (
446+ str (address .ip ) == "0.0.0.0" and address .mode == AddressMode .Client for address in valid_addresses
447+ )
448+ ):
449+ valid_addresses .append (InterfaceAddress (ip = "0.0.0.0" , mode = AddressMode .Client ))
434450 info = self .get_interface_info (interface )
435451 saved_interface = self .get_saved_interface_by_name (interface )
436452 # Get priority from saved interface or from current interface metrics, defaulting to None if neither exists
@@ -453,13 +469,13 @@ def get_interfaces(self, filter_wifi: bool = False) -> List[NetworkInterface]:
453469
454470 return result
455471
456- def get_ethernet_interfaces (self ) -> List [NetworkInterface ]:
472+ def get_ethernet_interfaces (self , include_dhcp_markers : bool = False ) -> List [NetworkInterface ]:
457473 """Get ethernet interfaces information
458474
459475 Returns:
460476 List of NetworkInterface instances available
461477 """
462- return self .get_interfaces (filter_wifi = True )
478+ return self .get_interfaces (filter_wifi = True , include_dhcp_markers = include_dhcp_markers )
463479
464480 def get_interface_ndb (self , interface_name : str ) -> Any :
465481 """Get interface NDB information for interface
@@ -634,7 +650,7 @@ def _execute_route(self, action: str, interface_name: str, route: Route) -> None
634650 raise
635651
636652 # Update settings
637- current_interface = self .get_interface_by_name (interface_name )
653+ current_interface = self .get_interface_by_name (interface_name , include_dhcp_markers = True )
638654 for current_route in current_interface .routes :
639655 if current_route .destination_parsed == route .destination_parsed and current_route .gateway == route .gateway :
640656 current_route .managed = route .managed
0 commit comments