libnm-core-aux: add function which prints information about route

Add function which will take route passed as argument and
print available information about the route into buffer.

The information are destination, prefix and then depending on route
next hop and metric.
This commit is contained in:
Vojtech Bubela 2021-07-28 16:00:56 +02:00 committed by Thomas Haller
parent d196e4962b
commit 30b8c71198
No known key found for this signature in database
GPG key ID: 29C2366E4DFC5728
2 changed files with 40 additions and 0 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__ */