git: e2ad879d4c60 - main - ifconfig: make interface address without mask an error

From: Ed Maste <emaste_at_FreeBSD.org>
Date: Tue, 18 Jun 2024 00:21:18 UTC
The branch main has been updated by emaste:

URL: https://cgit.FreeBSD.org/src/commit/?id=e2ad879d4c60fb22e768da5caec92920bc5f626b

commit e2ad879d4c60fb22e768da5caec92920bc5f626b
Author:     Ed Maste <emaste@FreeBSD.org>
AuthorDate: 2024-06-13 17:37:32 +0000
Commit:     Ed Maste <emaste@FreeBSD.org>
CommitDate: 2024-06-18 00:21:06 +0000

    ifconfig: make interface address without mask an error
    
    In commit d8237b955528, 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
---
 UPDATING                |  5 +++++
 sbin/ifconfig/af_inet.c | 32 ++++----------------------------
 2 files changed, 9 insertions(+), 28 deletions(-)

diff --git a/UPDATING b/UPDATING
index 98d8b58dcd20..2b6f9cb0d956 100644
--- a/UPDATING
+++ b/UPDATING
@@ -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
diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
index e21956cfc4fd..4fd74d481b3a 100644
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -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
 }