git: 01792dd7f27b - releng/14.0 - ifconfig: Fix default netmask calculation

From: Mark Johnston <markj_at_FreeBSD.org>
Date: Wed, 07 Aug 2024 13:44:41 UTC
The branch releng/14.0 has been updated by markj:

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

commit 01792dd7f27b3415e721f43f2d6e98df2346fd1f
Author:     Michael Gmelin <grembo@FreeBSD.org>
AuthorDate: 2024-06-12 16:11:52 +0000
Commit:     Mark Johnston <markj@FreeBSD.org>
CommitDate: 2024-08-07 13:31:10 +0000

    ifconfig: Fix default netmask calculation
    
    Approved by:    so
    Security:       FreeBSD-EN-24:14.ifconfig
    Reported by:    phk
    Reviewed by:    emaste, kp
    MFC after:      3 days
    Differential Revision:  https://reviews.freebsd.org/D45570
    
    (cherry picked from commit 8a9f0fa42b1c6cffd45459bb552e138083b00369)
    (cherry picked from commit 048ad7a9ef9fe15368ff287db5c705c8163f4e1c)
---
 sbin/ifconfig/af_inet.c | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)

diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
index 83b605e8c4cb..8032c7035c95 100644
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -445,7 +445,7 @@ in_exec_nl(if_ctx *ctx, unsigned long action, void *data)
 static void
 in_setdefaultmask_nl(void)
 {
-        struct in_px *px = sintab_nl[ADDR];
+	struct in_px *px = sintab_nl[ADDR];
 
 	in_addr_t i = ntohl(px->addr.s_addr);
 
@@ -456,11 +456,11 @@ in_setdefaultmask_nl(void)
 	 * we should return an error rather than warning.
 	 */
 	if (IN_CLASSA(i))
-		px->plen = IN_CLASSA_NSHIFT;
+		px->plen = 32 - IN_CLASSA_NSHIFT;
 	else if (IN_CLASSB(i))
-		px->plen = IN_CLASSB_NSHIFT;
+		px->plen = 32 - IN_CLASSB_NSHIFT;
 	else
-		px->plen = IN_CLASSC_NSHIFT;
+		px->plen = 32 - IN_CLASSC_NSHIFT;
 	px->maskset = true;
 }
 #endif