diff options
author | Lubomir Rintel <lkundrak@v3.sk> | 2018-11-09 14:56:24 +0100 |
---|---|---|
committer | Lubomir Rintel <lkundrak@v3.sk> | 2018-11-21 11:46:21 +0100 |
commit | 2a7e60d7244b20771933db61ee5a1c76bcb768a9 (patch) | |
tree | 57dd926074b98e1ceb59c637c53056ae653c538b | |
parent | 42e4d0984413fdd1b079e552bfd8a2fcf1662140 (diff) | |
download | NetworkManager-2a7e60d7244b20771933db61ee5a1c76bcb768a9.tar.gz |
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.
-rw-r--r-- | clients/cli/devices.c | 27 |
1 files changed, 26 insertions, 1 deletions
diff --git a/clients/cli/devices.c b/clients/cli/devices.c index 8e26a14450..f1211071e8 100644 --- a/clients/cli/devices.c +++ b/clients/cli/devices.c @@ -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)) |