nmcli: emit warning for unreachable gateways

This commit is contained in:
Beniamino Galvani 2026-02-12 17:22:42 +01:00
parent 7ea67e682f
commit 4bd025d95f
3 changed files with 55 additions and 0 deletions

View file

@ -5645,6 +5645,7 @@ connection_warnings(NmCli *nmc, NMConnection *connection)
guint i, found;
const char *id;
const char *deprecated;
gs_free char *gw_warning = NULL;
deprecated = nmc_connection_check_deprecated(NM_CONNECTION(connection));
if (deprecated)
@ -5673,6 +5674,10 @@ connection_warnings(NmCli *nmc, NMConnection *connection)
nm_connection_get_uuid(NM_CONNECTION(connection)),
found);
}
gw_warning = nm_connection_get_unreachable_gateways_warning(connection, TRUE);
if (gw_warning)
nmc_printerr("Warning: %s.\n", gw_warning);
}
static void

View file

@ -0,0 +1,15 @@
size: 683
location: src/tests/client/test-client.py:test_005()/1
cmd: $NMCLI c add type ethernet ifname eth0 con-name con-xx1 ipv4.method manual ipv4.addresses 192.168.1.1/24 ipv4.gateway 192.168.2.1 ipv4.routes '192.168.4.4 192.168.4.1'
lang: C
returncode: 0
stdout: 80 bytes
>>>
Connection 'con-xx1' (UUID-con-xx1-REPLACED-REPLACED-REPLA) successfully added.
<<<
stderr: 300 bytes
>>>
Warning: the following gateways are not directly reachable from any configured address or route: 192.168.2.1, 192.168.4.1. 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.
<<<

View file

@ -2222,6 +2222,41 @@ class TestNmcli(unittest.TestCase):
replace_stdout=replace_uuids,
)
@nm_test
def test_005(self):
self.init_001()
replace_uuids = []
replace_uuids.append(
self.ctx.srv.ReplaceTextConUuid(
"con-xx1", "UUID-con-xx1-REPLACED-REPLACED-REPLA"
)
)
# Check the warning about unreachable gateways
self.call_nmcli(
[
"c",
"add",
"type",
"ethernet",
"ifname",
"eth0",
"con-name",
"con-xx1",
"ipv4.method",
"manual",
"ipv4.addresses",
"192.168.1.1/24",
"ipv4.gateway",
"192.168.2.1",
"ipv4.routes",
"192.168.4.4 192.168.4.1",
],
replace_stdout=replace_uuids,
)
@nm_test_no_dbus
def test_offline(self):
# Make sure we're not using D-Bus