Thomas Haller 2021-08-02 09:44:08 +02:00
commit 13a5c38d58
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
3 changed files with 55 additions and 6 deletions

View file

@ -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);
}
}

View file

@ -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__ */

View file

@ -7,10 +7,10 @@
#include <stdlib.h>
#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));
}
}