From 9d40226b009b93ee6e64eef82690eba5056596e8 Mon Sep 17 00:00:00 2001 From: Vojtech Bubela Date: Wed, 28 Jul 2021 16:01:15 +0200 Subject: [PATCH] nmcli: edit output of nmcli so it shows more inormation about routes Edit nmcli command to show additional information about the routes (both route4 and route6). If there is information about next hop or metric in the route structure it will be shown in addition to destination and prefix. --- src/nmcli/general.c | 21 +++++++++++++++------ 1 file changed, 15 insertions(+), 6 deletions(-) diff --git a/src/nmcli/general.c b/src/nmcli/general.c index 225d3d8af2..d87df17a9d 100644 --- a/src/nmcli/general.c +++ b/src/nmcli/general.c @@ -7,10 +7,10 @@ #include -#include "libnm-core-aux-intern/nm-common-macros.h" - #include "libnm-glib-aux/nm-dbus-aux.h" #include "libnmc-base/nm-client-utils.h" +#include "libnm-core-aux-extern/nm-libnm-core-aux.h" +#include "libnm-glib-aux/nm-str-buf.h" #include "polkit-agent.h" #include "utils.h" @@ -1392,8 +1392,9 @@ device_overview(NmCli *nmc, NMDevice *device) static void ac_overview(NmCli *nmc, NMActiveConnection *ac) { - GString * outbuf = g_string_sized_new(80); - NMIPConfig *ip; + GString * outbuf = g_string_sized_new(80); + NMIPConfig * ip; + nm_auto_str_buf NMStrBuf str = NM_STR_BUF_INIT(NM_UTILS_GET_NEXT_REALLOC_SIZE_104, FALSE); if (nm_active_connection_get_master(ac)) { g_string_append_printf(outbuf, @@ -1426,7 +1427,11 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac) p = nm_ip_config_get_routes(ip); for (i = 0; i < p->len; i++) { NMIPRoute *a = p->pdata[i]; - g_print("\troute4 %s/%d\n", nm_ip_route_get_dest(a), nm_ip_route_get_prefix(a)); + + nm_str_buf_reset(&str); + _nm_ip_route_to_string(a, &str); + + g_print("\troute4 %s\n", nm_str_buf_get_str(&str)); } } @@ -1444,7 +1449,11 @@ ac_overview(NmCli *nmc, NMActiveConnection *ac) p = nm_ip_config_get_routes(ip); for (i = 0; i < p->len; i++) { NMIPRoute *a = p->pdata[i]; - g_print("\troute6 %s/%d\n", nm_ip_route_get_dest(a), nm_ip_route_get_prefix(a)); + + nm_str_buf_reset(&str); + _nm_ip_route_to_string(a, &str); + + g_print("\troute6 %s\n", nm_str_buf_get_str(&str)); } }