mirror of
https://gitlab.freedesktop.org/NetworkManager/NetworkManager.git
synced 2026-05-09 05:58:01 +02: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
f42e422b69
commit
2b4b8d7e7e
2 changed files with 38 additions and 0 deletions
|
|
@ -1306,3 +1306,39 @@ nm_connection_get_unreachable_gateways(NMConnection *connection)
|
||||||
|
|
||||||
return NULL;
|
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);
|
||||||
|
|
||||||
|
NM_PRAGMA_WARNING_DISABLE("-Wformat-nonliteral")
|
||||||
|
if (translate)
|
||||||
|
return g_strdup_printf(_(msg), gw_list);
|
||||||
|
return g_strdup_printf(msg, gw_list);
|
||||||
|
NM_PRAGMA_WARNING_REENABLE
|
||||||
|
}
|
||||||
|
|
|
||||||
|
|
@ -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);
|
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 */
|
/* Wi-Fi frequencies range for each band */
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue