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