cli/devices: sort hotspots above in nmcli output

In general we want to keep the connections that the user is most likely
to want to see topmost. Default connections should be close to the top,
but the connections that are likely to have been brought up manually
shall be above them. It applies to VPN connections and should apply to
Hotspots too.
This commit is contained in:
Lubomir Rintel 2018-11-09 14:56:24 +01:00
parent 42e4d09844
commit 2a7e60d724

View file

@ -905,6 +905,8 @@ compare_devices (const void *a, const void *b)
NMDevice *db = *(NMDevice **)b;
NMActiveConnection *da_ac;
NMActiveConnection *db_ac;
NMSettingIPConfig *s_ip;
NMRemoteConnection *conn;
NMIPConfig *da_ip;
NMIPConfig *db_ip;
int da_num_addrs;
@ -927,7 +929,30 @@ compare_devices (const void *a, const void *b)
if (cmp != 0)
return cmp;
/* VPNs go on the top if possible */
/* Shared connections (likely hotspots) go on the top if possible */
conn = da_ac ? nm_active_connection_get_connection (da_ac) : NULL;
s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL;
if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0)
cmp--;
conn = db_ac ? nm_active_connection_get_connection (db_ac) : NULL;
s_ip = conn ? nm_connection_get_setting_ip6_config (NM_CONNECTION (conn)) : NULL;
if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP6_CONFIG_METHOD_SHARED) == 0)
cmp++;
if (cmp != 0)
return cmp;
conn = da_ac ? nm_active_connection_get_connection (da_ac) : NULL;
s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL;
if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0)
cmp--;
conn = db_ac ? nm_active_connection_get_connection (db_ac) : NULL;
s_ip = conn ? nm_connection_get_setting_ip4_config (NM_CONNECTION (conn)) : NULL;
if (s_ip && strcmp (nm_setting_ip_config_get_method (s_ip), NM_SETTING_IP4_CONFIG_METHOD_SHARED) == 0)
cmp++;
if (cmp != 0)
return cmp;
/* VPNs go next */
if (da_ac && !nm_active_connection_get_vpn (da_ac))
cmp++;
if (db_ac && !nm_active_connection_get_vpn (db_ac))