Skip to content

Commit

Permalink
ifconfig: make interface address without mask an error
Browse files Browse the repository at this point in the history
In commit d8237b9, 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
  • Loading branch information
emaste committed Jun 18, 2024
1 parent 1389314 commit e2ad879
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 28 deletions.
5 changes: 5 additions & 0 deletions UPDATING
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
32 changes: 4 additions & 28 deletions sbin/ifconfig/af_inet.c
Original file line number Diff line number Diff line change
Expand Up @@ -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.");
}
}

Expand All @@ -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
}
Expand Down

0 comments on commit e2ad879

Please sign in to comment.