ifconfig: Exit with a non-zero status when SIOCSIFFIB fails

Previously, setting an interface FIB to some invalid value would result
in a warning being printed, but the ifconfig command would exit with
status 0, but this is wrong.

Add a little regression test.

Reviewed by:	pouria, zlei, melifaro
MFC after:	2 weeks
Sponsored by:	Stormshield
Sponsored by:	Klara, Inc.
Differential Revision:	https://reviews.freebsd.org/D54918
This commit is contained in:
Mark Johnston
2026-01-28 16:11:47 +00:00
parent b41b6fdb3a
commit 2ea85a622b
3 changed files with 40 additions and 11 deletions
+6 -10
View File
@@ -69,14 +69,12 @@ setiffib(if_ctx *ctx, const char *val, int dummy __unused)
char *ep;
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX) {
warn("fib %s not valid", val);
return;
}
if (*ep != '\0' || fib > UINT_MAX)
errx(1, "fib %s not valid", val);
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSIFFIB, &ifr) < 0)
warn("ioctl (SIOCSIFFIB)");
err(1, "ioctl (SIOCSIFFIB)");
}
static void
@@ -87,14 +85,12 @@ settunfib(if_ctx *ctx, const char *val, int dummy __unused)
char *ep;
fib = strtoul(val, &ep, 0);
if (*ep != '\0' || fib > UINT_MAX) {
warn("fib %s not valid", val);
return;
}
if (*ep != '\0' || fib > UINT_MAX)
errx(1, "fib %s not valid", val);
ifr.ifr_fib = fib;
if (ioctl_ctx_ifr(ctx, SIOCSTUNFIB, &ifr) < 0)
warn("ioctl (SIOCSTUNFIB)");
err(1, "ioctl (SIOCSTUNFIB)");
}
static struct cmd fib_cmds[] = {
+2 -1
View File
@@ -1,5 +1,6 @@
NETBSD_ATF_TESTS_SH= nonexistent_test
ATF_TESTS_SH+= inet6
ATF_TESTS_SH+= ifconfig \
inet6
TEST_METADATA+= execenv="jail"
TEST_METADATA+= execenv_jail_params="vnet allow.raw_sockets"
+32
View File
@@ -0,0 +1,32 @@
# SPDX-License-Identifier: BSD-2-Clause
#
# Copyright (c) 2026 Stormshield
. $(atf_get_srcdir)/../../sys/common/vnet.subr
atf_test_case "badfib" "cleanup"
badfib_head()
{
atf_set descr "Test adding an interface to a non-existent FIB"
atf_set require.user root
}
badfib_body()
{
local epair
vnet_init
epair=$(vnet_mkepair)
atf_check -s exit:0 ifconfig ${epair}a fib 0
atf_check -s not-exit:0 -e not-empty \
ifconfig ${epair}a fib $(sysctl -n net.fibs)
}
badfib_cleanup()
{
vnet_cleanup
}
atf_init_test_cases()
{
atf_add_test_case badfib
}