mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2025-12-20 07:00:05 +01:00
cli: limit number of shown addresses/routes in nmcli overview
If you add a large number of addresses/routes, then the output of
`nmcli` is unusable. It also doesn't seem too useful.
Limit the number to show up to 10 addresses and 10 routes.
If there are more than 10 addresses, then print an 11th line with
inet4 ... N more
Actually, if there are exactly 11 addresses, then don't waste an extra
line to print "1 more". Instead, still print the 11th address. Same for
routes.
This commit is contained in:
parent
39d900593b
commit
a7a36cde83
2 changed files with 17 additions and 0 deletions
1
NEWS
1
NEWS
|
|
@ -15,6 +15,7 @@ Overview of changes since NetworkManager-1.44
|
|||
* Honor udev property ID_NET_MANAGED_BY to only manage an interface
|
||||
when set to "org.freedesktop.NetworkManager".
|
||||
* Drop build support with Python2. Python3 is now required.
|
||||
* nmcli: limit number of printed addresses/routes in `nmcli` overview to 10.
|
||||
|
||||
=============================================
|
||||
NetworkManager-1.44
|
||||
|
|
|
|||
|
|
@ -1412,6 +1412,8 @@ static void
|
|||
ac_overview(NmCli *nmc, NMActiveConnection *ac)
|
||||
{
|
||||
nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT_A(NM_UTILS_GET_NEXT_REALLOC_SIZE_488, FALSE);
|
||||
const guint MAX_ADDRESSES = 10;
|
||||
const guint MAX_ROUTES = 10;
|
||||
int IS_IPv4;
|
||||
|
||||
if (nm_active_connection_get_controller(ac)) {
|
||||
|
|
@ -1451,6 +1453,15 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac)
|
|||
IS_IPv4 ? '4' : '6',
|
||||
nm_ip_address_get_address(a),
|
||||
nm_ip_address_get_prefix(a));
|
||||
|
||||
if (i >= MAX_ADDRESSES - 1u && p->len - i > 2u) {
|
||||
/* Print always at least MAX_ADDRESSES fully.
|
||||
* If there are MAX_ADDRESSES+1 addresses, print them all fully.
|
||||
* If there are more addresses, print MAX_ADDRESSES fully, and a
|
||||
* "N more" line. */
|
||||
nmc_print("\tinet%c ... %u more\n", IS_IPv4 ? '4' : '6', p->len - i - 1u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
p = nm_ip_config_get_routes(ip);
|
||||
|
|
@ -1461,6 +1472,11 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac)
|
|||
_nm_ip_route_to_string(a, &str);
|
||||
|
||||
nmc_print("\troute%c %s\n", IS_IPv4 ? '4' : '6', nm_str_buf_get_str(&str));
|
||||
|
||||
if (i >= MAX_ROUTES - 1u && p->len - i > 2u) {
|
||||
nmc_print("\troute%c ... %u more\n", IS_IPv4 ? '4' : '6', p->len - i - 1u);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue