mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-02-24 21:50:34 +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
73d0d2cbb5
commit
7ea67e682f
2 changed files with 44 additions and 0 deletions
|
|
@ -1306,3 +1306,45 @@ 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;
|
||||
|
||||
gateways = nm_connection_get_unreachable_gateways(connection);
|
||||
if (!gateways)
|
||||
return NULL;
|
||||
|
||||
gw_list = g_strjoinv(", ", (char **) gateways);
|
||||
|
||||
/* Keep the following two strings in sync. */
|
||||
if (translate) {
|
||||
return g_strdup_printf(
|
||||
_("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"),
|
||||
gw_list);
|
||||
}
|
||||
|
||||
return g_strdup_printf(
|
||||
"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",
|
||||
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