@@ -610,7 +610,7 @@ def get_bonding_values(ip4_addr_cidr, attached_devices, bonding_policy, bond_pri
610610 return values
611611
612612
613- def set_network_configuration (device_type , interface_name , logical_type , interface_to_edit , protocol , zone , ip4_addr_cidr , ip4_gateway , ip6_enabled , ip6_address , ip6_gateway , attached_devices , bonding_policy , bond_primary_device , pppoe_username , pppoe_password , dhcp_client_id , dhcp_vendor_class , dhcp_hostname_to_send , dhcp_custom_hostname , uci ):
613+ def set_network_configuration (device_type , interface_name , logical_type , interface_to_edit , protocol , zone , ip4_addr_cidr , ip4_gateway , ip6_enabled , ip6_address , ip6_gateway , attached_devices , bonding_policy , bond_primary_device , pppoe_username , pppoe_password , dhcp_client_id , dhcp_vendor_class , dhcp_hostname_to_send , dhcp_custom_hostname , uci , metric : int = None ):
614614 if device_type == 'logical' and logical_type == 'bond' :
615615 values = get_bonding_values (
616616 ip4_addr_cidr , attached_devices , bonding_policy , bond_primary_device )
@@ -697,9 +697,26 @@ def set_network_configuration(device_type, interface_name, logical_type, interfa
697697 if interface_to_edit and delete_dhcp_hostname :
698698 uci .delete ('network' , interface_name , 'hostname' )
699699
700- # disable "force link" on red interfaces
701700 if zone == 'wan' :
701+ # disable "force link" on red interfaces
702702 values ['force_link' ] = '0'
703+ # assign metric if missing
704+ if metric is not None :
705+ values ["metric" ] = metric
706+ else :
707+ metrics = set ()
708+ for network in uci .get ("firewall" , "ns_wan" , "network" , dtype = str , default = [], list = True ):
709+ metric = uci .get ("network" , network , "metric" , default = None , dtype = int )
710+ if metric is not None :
711+ metrics .add (metric )
712+
713+ base_metric = 20
714+ while base_metric in metrics :
715+ base_metric += 10
716+ values ["metric" ] = base_metric
717+ else :
718+ # remove metric if interface changes zone
719+ values ['metric' ] = ''
703720
704721 for key , value in values .items ():
705722 uci .set ('network' , interface_name , key , value )
@@ -833,6 +850,7 @@ def configure_device(input_data):
833850 dhcp_vendor_class = input_data .get ('dhcp_vendor_class' )
834851 dhcp_hostname_to_send = input_data .get ('dhcp_hostname_to_send' )
835852 dhcp_custom_hostname = input_data .get ('dhcp_custom_hostname' )
853+ metric = input_data .get ('metric' )
836854 bridge_device_name = ''
837855
838856 # validate input data
@@ -848,7 +866,7 @@ def configure_device(input_data):
848866 device_name , device_type , interface_name , protocol , logical_type , bridge_device_name , uci )
849867
850868 set_network_configuration (device_type , interface_name , logical_type , interface_to_edit , protocol , zone , ip4_address , ip4_gateway , ip6_enabled , ip6_address , ip6_gateway ,
851- attached_devices , bonding_policy , bond_primary_device , pppoe_username , pppoe_password , dhcp_client_id , dhcp_vendor_class , dhcp_hostname_to_send , dhcp_custom_hostname , uci )
869+ attached_devices , bonding_policy , bond_primary_device , pppoe_username , pppoe_password , dhcp_client_id , dhcp_vendor_class , dhcp_hostname_to_send , dhcp_custom_hostname , uci , metric )
852870
853871 set_firewall_zone (interface_name , zone , interface_to_edit , uci )
854872
@@ -1180,6 +1198,7 @@ if cmd == 'list':
11801198 'dhcp_vendor_class' : 'string' ,
11811199 'dhcp_hostname_to_send' : 'string' ,
11821200 'dhcp_custom_hostname' : 'string' ,
1201+ 'metric' : 'integer'
11831202 },
11841203 'unconfigure-device' : {
11851204 'iface_name' : 'string' ,
0 commit comments