diff --git a/src/libnm-core-aux-extern/nm-libnm-core-aux.c b/src/libnm-core-aux-extern/nm-libnm-core-aux.c index 6c45ecf728..4182f59ccc 100644 --- a/src/libnm-core-aux-extern/nm-libnm-core-aux.c +++ b/src/libnm-core-aux-extern/nm-libnm-core-aux.c @@ -8,6 +8,7 @@ #include "nm-libnm-core-aux.h" #include "libnm-core-aux-intern/nm-libnm-core-utils.h" +#include "libnm-glib-aux/nm-str-buf.h" /*****************************************************************************/ @@ -434,3 +435,38 @@ nm_utils_team_link_watcher_from_string(const char *str, GError **error) return watcher; } + +/*****************************************************************************/ + +/** + * _nm_ip_route_to_string: + * @route: route to get information about + * @strbuf: NMStrBuf to store information about route + * + * Gets available information about route and prints it into buffer + */ +void +_nm_ip_route_to_string(NMIPRoute *route, NMStrBuf *strbuf) +{ + const char *next_hop; + gint64 metric; + + nm_assert(route); + nm_assert(strbuf); + + next_hop = nm_ip_route_get_next_hop(route); + metric = nm_ip_route_get_metric(route); + + nm_str_buf_append_printf(strbuf, + "%s/%u", + nm_ip_route_get_dest(route), + nm_ip_route_get_prefix(route)); + + if (next_hop) { + nm_str_buf_append_printf(strbuf, " via %s", next_hop); + } + + if (metric != -1) { + nm_str_buf_append_printf(strbuf, " metric %" G_GINT64_FORMAT, metric); + } +} diff --git a/src/libnm-core-aux-extern/nm-libnm-core-aux.h b/src/libnm-core-aux-extern/nm-libnm-core-aux.h index 905f24331e..e45e98ab2d 100644 --- a/src/libnm-core-aux-extern/nm-libnm-core-aux.h +++ b/src/libnm-core-aux-extern/nm-libnm-core-aux.h @@ -7,6 +7,7 @@ #define __NM_LIBNM_CORE_AUX_H__ #include "nm-setting-team.h" +#include "nm-setting-ip-config.h" typedef enum { NM_TEAM_LINK_WATCHER_TYPE_NONE = 0, @@ -33,6 +34,9 @@ typedef enum { char *nm_utils_team_link_watcher_to_string(const NMTeamLinkWatcher *watcher); +struct _NMStrBuf; +void _nm_ip_route_to_string(NMIPRoute *route, struct _NMStrBuf *strbuf); + NMTeamLinkWatcher *nm_utils_team_link_watcher_from_string(const char *str, GError **error); #endif /* __NM_LIBNM_CORE_AUX_H__ */ 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)); } }