ifconfig: make interface address without mask an error

In commit d8237b9555, as part of the deprecation of IPv4 address
classes, Mike Karels introduced a warning in ifconfig for setting an
address without a width or mask.  The commit message says "This will
hopefully be an error in the future."

As the warning has been included in releases from FreeBSD 13.1 on, and
sufficient time has passed, turn this into an error.

Reviewed by:	allanjude, olce, grembo, philip, gordon
Relnotes:	Yes
Sponsored by:	The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D45585
This commit is contained in:
Ed Maste 2024-06-13 13:37:32 -04:00
parent 1389314d53
commit e2ad879d4c
2 changed files with 9 additions and 28 deletions

View file

@ -27,6 +27,11 @@ NOTE TO PEOPLE WHO THINK THAT FreeBSD 15.x IS SLOW:
world, or to merely disable the most expensive debugging functionality
at runtime, run "ln -s 'abort:false,junk:false' /etc/malloc.conf".)
20240617:
ifconfig now treats IPv4 addresses without a width or mask as an error.
Specify the desired mask or width along with the IP address on the
ifconfig command line and in rc.conf.
20240428:
OpenBSM auditing runtime (auditd, etc.) has been moved into the new
package FreeBSD-audit. If you use OpenBSM auditing and pkgbase, you

View file

@ -436,36 +436,13 @@ in_exec_nl(if_ctx *ctx, unsigned long action, void *data)
return (e.error);
}
static void
in_setdefaultmask_nl(void)
{
struct in_px *px = sintab_nl[ADDR];
in_addr_t i = ntohl(px->addr.s_addr);
/*
* If netmask isn't supplied, use historical default.
* This is deprecated for interfaces other than loopback
* or point-to-point; warn in other cases. In the future
* we should return an error rather than warning.
*/
if (IN_CLASSA(i))
px->plen = 32 - IN_CLASSA_NSHIFT;
else if (IN_CLASSB(i))
px->plen = 32 - IN_CLASSB_NSHIFT;
else
px->plen = 32 - IN_CLASSC_NSHIFT;
px->maskset = true;
}
#endif
static void
warn_nomask(int ifflags)
err_nomask(int ifflags)
{
if ((ifflags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) {
warnx("WARNING: setting interface address without mask "
"is deprecated,\ndefault mask may not be correct.");
errx(1, "ERROR: setting interface address without mask is no longer supported.");
}
}
@ -474,12 +451,11 @@ in_postproc(if_ctx *ctx __unused, int newaddr, int ifflags)
{
#ifdef WITHOUT_NETLINK
if (sintab[ADDR]->sin_len != 0 && sintab[MASK]->sin_len == 0 && newaddr) {
warn_nomask(ifflags);
err_nomask(ifflags);
}
#else
if (sintab_nl[ADDR]->addrset && !sintab_nl[ADDR]->maskset && newaddr) {
warn_nomask(ifflags);
in_setdefaultmask_nl();
err_nomask(ifflags);
}
#endif
}