mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-03-10 02:00:36 +01:00
libnm-core: add function to get a warning message for unreachable gateways
We are going to print the same warning message in different places (the daemon, nmcli, nmtui). Add a function to return the message. Note that the message needs to be translated in clients but not in the daemon logs.
This commit is contained in:
parent
c7bbf9d3b3
commit
b62bbdfc3a
2 changed files with 38 additions and 0 deletions
|
|
@ -1306,3 +1306,39 @@ nm_connection_get_unreachable_gateways(NMConnection *connection)
|
|||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
/**
|
||||
* nm_connection_get_unreachable_gateways_warning:
|
||||
* @connection: the #NMConnection
|
||||
* @translate: whether to translate the message (use %TRUE for user-facing
|
||||
* tools like nmcli, %FALSE for daemon logs)
|
||||
*
|
||||
* Checks whether there are unreachable gateways in the connection and returns
|
||||
* a formatted warning message if so.
|
||||
*
|
||||
* Returns: a warning message string, or %NULL if all gateways are reachable.
|
||||
* Free with g_free().
|
||||
*/
|
||||
char *
|
||||
nm_connection_get_unreachable_gateways_warning(NMConnection *connection, gboolean translate)
|
||||
{
|
||||
gs_free const char **gateways = NULL;
|
||||
gs_free char *gw_list = NULL;
|
||||
const char *msg =
|
||||
N_("the following gateways are not directly reachable from any configured address or "
|
||||
"route: %s. NetworkManager currently adds on-link routes for them automatically, "
|
||||
"but this will change in the future. Consider adding addresses or routes whose "
|
||||
"subnets cover these gateways");
|
||||
|
||||
gateways = nm_connection_get_unreachable_gateways(connection);
|
||||
if (!gateways)
|
||||
return NULL;
|
||||
|
||||
gw_list = g_strjoinv(", ", (char **) gateways);
|
||||
|
||||
if (translate) {
|
||||
return g_strdup_printf(_(msg), gw_list);
|
||||
} else {
|
||||
return g_strdup_printf(msg, gw_list);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -346,6 +346,8 @@ gboolean nm_setting_ovs_other_config_check_val(const char *val, GError **error);
|
|||
|
||||
const char **nm_connection_get_unreachable_gateways(NMConnection *connection);
|
||||
|
||||
char *nm_connection_get_unreachable_gateways_warning(NMConnection *connection, gboolean translate);
|
||||
|
||||
/*****************************************************************************/
|
||||
|
||||
/* Wi-Fi frequencies range for each band */
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue