diff options
| author | Mark Johnston <markj@FreeBSD.org> | 2026-01-28 16:11:47 +0000 |
|---|---|---|
| committer | Mark Johnston <markj@FreeBSD.org> | 2026-01-28 16:11:47 +0000 |
| commit | 2ea85a622bcba92a7b58901d6a6e945df3022c4e (patch) | |
| tree | 36e0b050d5d498cf7032a973ce3667d40c8c05bd | |
| parent | b41b6fdb3a1635de4c2a9280aab12b83e3aeffc5 (diff) | |
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
| -rw-r--r-- | sbin/ifconfig/iffib.c | 16 | ||||
| -rw-r--r-- | sbin/ifconfig/tests/Makefile | 3 | ||||
| -rw-r--r-- | sbin/ifconfig/tests/ifconfig.sh | 32 |
3 files changed, 40 insertions, 11 deletions
diff --git a/sbin/ifconfig/iffib.c b/sbin/ifconfig/iffib.c index a99dd6885d08..c1f9b3defb40 100644 --- a/sbin/ifconfig/iffib.c +++ b/sbin/ifconfig/iffib.c @@ -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[] = { diff --git a/sbin/ifconfig/tests/Makefile b/sbin/ifconfig/tests/Makefile index e902f262552a..8203c97cb013 100644 --- a/sbin/ifconfig/tests/Makefile +++ b/sbin/ifconfig/tests/Makefile @@ -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" diff --git a/sbin/ifconfig/tests/ifconfig.sh b/sbin/ifconfig/tests/ifconfig.sh new file mode 100644 index 000000000000..f95581ea97ba --- /dev/null +++ b/sbin/ifconfig/tests/ifconfig.sh @@ -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 +} |
