git: a3930cd46ce6 - main - ifconfig: use default (more rigid) WARNS level.

From: Alexander V. Chernikov <melifaro_at_FreeBSD.org>
Date: Fri, 16 Jun 2023 07:19:45 UTC
The branch main has been updated by melifaro:

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

commit a3930cd46ce6b3d6234044c5ed6970851ef3b967
Author:     Alexander V. Chernikov <melifaro@FreeBSD.org>
AuthorDate: 2023-06-14 13:21:17 +0000
Commit:     Alexander V. Chernikov <melifaro@FreeBSD.org>
CommitDate: 2023-06-16 07:19:22 +0000

    ifconfig: use default (more rigid) WARNS level.
    
    It helps catch more errors at compile time.
    
    Reviewed by:    kp
    Differential Revision: https://reviews.freebsd.org/D40536
    MFC after:      2 weeks
---
 sbin/ifconfig/Makefile      |  1 -
 sbin/ifconfig/af_inet.c     | 10 +++++-----
 sbin/ifconfig/af_inet6.c    | 23 +++++++++++------------
 sbin/ifconfig/af_link.c     |  2 +-
 sbin/ifconfig/ifconfig.c    |  5 ++---
 sbin/ifconfig/ifconfig.h    | 12 ++++++++++++
 sbin/ifconfig/ifieee80211.c |  6 +++---
 7 files changed, 34 insertions(+), 25 deletions(-)

diff --git a/sbin/ifconfig/Makefile b/sbin/ifconfig/Makefile
index 9b9df6ab9f78..4b2f92b1597c 100644
--- a/sbin/ifconfig/Makefile
+++ b/sbin/ifconfig/Makefile
@@ -80,7 +80,6 @@ CFLAGS+=-DWITHOUT_NETLINK
 MAN=	ifconfig.8
 
 CFLAGS+= -Wall -Wmissing-prototypes -Wcast-qual -Wwrite-strings -Wnested-externs
-WARNS?=	2
 
 HAS_TESTS=
 SUBDIR.${MK_TESTS}+= tests
diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c
index 0c6ae253cbd4..83b605e8c4cb 100644
--- a/sbin/ifconfig/af_inet.c
+++ b/sbin/ifconfig/af_inet.c
@@ -105,20 +105,20 @@ in_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
 {
 	struct sockaddr_in *sin, null_sin = {};
 
-	sin = (struct sockaddr_in *)ifa->ifa_addr;
+	sin = satosin(ifa->ifa_addr);
 	if (sin == NULL)
 		return;
 
 	print_addr(sin);
 
 	if (ifa->ifa_flags & IFF_POINTOPOINT) {
-		sin = (struct sockaddr_in *)ifa->ifa_dstaddr;
+		sin = satosin(ifa->ifa_dstaddr);
 		if (sin == NULL)
 			sin = &null_sin;
 		printf(" --> %s", inet_ntoa(sin->sin_addr));
 	}
 
-	sin = (struct sockaddr_in *)ifa->ifa_netmask;
+	sin = satosin(ifa->ifa_netmask);
 	if (sin == NULL)
 		sin = &null_sin;
 	if (f_inet != NULL && strcmp(f_inet, "cidr") == 0) {
@@ -139,7 +139,7 @@ in_status(if_ctx *ctx __unused, const struct ifaddrs *ifa)
 		printf(" netmask 0x%lx", (unsigned long)ntohl(sin->sin_addr.s_addr));
 
 	if (ifa->ifa_flags & IFF_BROADCAST) {
-		sin = (struct sockaddr_in *)ifa->ifa_broadaddr;
+		sin = satosin(ifa->ifa_broadaddr);
 		if (sin != NULL && sin->sin_addr.s_addr != 0)
 			printf(" broadcast %s", inet_ntoa(sin->sin_addr));
 	}
@@ -202,7 +202,7 @@ static struct sockaddr_in *sintab[] = {
 };
 
 static void
-in_copyaddr(if_ctx *ctx, int to, int from)
+in_copyaddr(if_ctx *ctx __unused, int to, int from)
 {
 	memcpy(sintab[to], sintab[from], sizeof(struct sockaddr_in));
 }
diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c
index 1acfc28cad94..a0138e9b3de6 100644
--- a/sbin/ifconfig/af_inet6.c
+++ b/sbin/ifconfig/af_inet6.c
@@ -299,7 +299,7 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
 	u_int32_t flags6;
 	struct in6_addrlifetime lifetime;
 
-	sin = (struct sockaddr_in6 *)ifa->ifa_addr;
+	sin = satosin6(ifa->ifa_addr);
 	if (sin == NULL)
 		return;
 
@@ -328,7 +328,7 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
 	print_addr(sin);
 
 	if (ifa->ifa_flags & IFF_POINTOPOINT) {
-		sin = (struct sockaddr_in6 *)ifa->ifa_dstaddr;
+		sin = satosin6(ifa->ifa_dstaddr);
 		/*
 		 * some of the interfaces do not have valid destination
 		 * address.
@@ -337,16 +337,16 @@ in6_status(if_ctx *ctx, const struct ifaddrs *ifa)
 			print_p2p(sin);
 	}
 
-	sin = (struct sockaddr_in6 *)ifa->ifa_netmask;
+	sin = satosin6(ifa->ifa_netmask);
 	if (sin == NULL)
 		sin = &null_sin;
 	print_mask(prefix(&sin->sin6_addr, sizeof(struct in6_addr)));
 
 	print_flags(flags6);
 
-	if (((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id)
+	if ((satosin6(ifa->ifa_addr))->sin6_scope_id)
 		printf(" scopeid 0x%x",
-		    ((struct sockaddr_in6 *)(ifa->ifa_addr))->sin6_scope_id);
+		    (satosin6(ifa->ifa_addr))->sin6_scope_id);
 
 	if (ip6lifetime && (lifetime.ia6t_preferred || lifetime.ia6t_expire)) {
 		struct timespec now;
@@ -510,7 +510,7 @@ static struct	sockaddr_in6 *sin6tab[] = {
 };
 
 static void
-in6_copyaddr(if_ctx *ctx, int to, int from)
+in6_copyaddr(if_ctx *ctx __unused, int to, int from)
 {
 	memcpy(sin6tab[to], sin6tab[from], sizeof(struct sockaddr_in6));
 }
@@ -675,15 +675,14 @@ in6_status_tunnel(if_ctx *ctx)
 static void
 in6_set_tunnel(if_ctx *ctx, struct addrinfo *srcres, struct addrinfo *dstres)
 {
-	struct in6_aliasreq in6_addreq; 
+	struct in6_aliasreq in6_req = {}; 
 
-	memset(&in6_addreq, 0, sizeof(in6_addreq));
-	strlcpy(in6_addreq.ifra_name, ctx->ifname, sizeof(in6_addreq.ifra_name));
-	memcpy(&in6_addreq.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
-	memcpy(&in6_addreq.ifra_dstaddr, dstres->ai_addr,
+	strlcpy(in6_req.ifra_name, ctx->ifname, sizeof(in6_req.ifra_name));
+	memcpy(&in6_req.ifra_addr, srcres->ai_addr, srcres->ai_addr->sa_len);
+	memcpy(&in6_req.ifra_dstaddr, dstres->ai_addr,
 	    dstres->ai_addr->sa_len);
 
-	if (ioctl_ctx(ctx, SIOCSIFPHYADDR_IN6, &in6_addreq) < 0)
+	if (ioctl_ctx(ctx, SIOCSIFPHYADDR_IN6, &in6_req) < 0)
 		warn("SIOCSIFPHYADDR_IN6");
 }
 
diff --git a/sbin/ifconfig/af_link.c b/sbin/ifconfig/af_link.c
index e66266ece86b..17de87539d9a 100644
--- a/sbin/ifconfig/af_link.c
+++ b/sbin/ifconfig/af_link.c
@@ -120,7 +120,7 @@ link_status(if_ctx *ctx, const struct ifaddrs *ifa)
 	int rc, sock_hw;
 	static const u_char laggaddr[6] = {0};
 
-	sdl = (struct sockaddr_dl *) ifa->ifa_addr;
+	sdl = satosdl(ifa->ifa_addr);
 	if (sdl == NULL || sdl->sdl_alen == 0)
 		return;
 
diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c
index 24462f76e96c..f3d16fc052f6 100644
--- a/sbin/ifconfig/ifconfig.c
+++ b/sbin/ifconfig/ifconfig.c
@@ -811,7 +811,7 @@ list_interfaces_ioctl(if_ctx *ctx)
 		if (args->ifname != NULL && strcmp(args->ifname, ifa->ifa_name) != 0)
 			continue;
 		if (ifa->ifa_addr->sa_family == AF_LINK)
-			sdl = (const struct sockaddr_dl *) ifa->ifa_addr;
+			sdl = satosdl_c(ifa->ifa_addr);
 		else
 			sdl = NULL;
 		if (cp != NULL && strcmp(cp, ifa->ifa_name) == 0 && !args->namesonly)
@@ -1737,8 +1737,7 @@ print_description(if_ctx *ctx)
  * specified, show only it; otherwise, show them all.
  */
 static void
-status(if_ctx *ctx, const struct sockaddr_dl *sdl,
-	struct ifaddrs *ifa)
+status(if_ctx *ctx, const struct sockaddr_dl *sdl __unused, struct ifaddrs *ifa)
 {
 	struct ifaddrs *ift;
 	int s, old_s;
diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h
index 49f907367b7a..c97ef447a3b3 100644
--- a/sbin/ifconfig/ifconfig.h
+++ b/sbin/ifconfig/ifconfig.h
@@ -314,3 +314,15 @@ satosin(struct sockaddr *sa)
 {
 	return ((struct sockaddr_in *)(void *)sa);
 }
+
+static inline struct sockaddr_dl *
+satosdl(struct sockaddr *sa)
+{
+	return ((struct sockaddr_dl *)(void *)sa);
+}
+
+static inline const struct sockaddr_dl *
+satosdl_c(const struct sockaddr *sa)
+{
+	return ((const struct sockaddr_dl *)(const void *)sa);
+}
diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c
index 480a8472f293..967385b2377d 100644
--- a/sbin/ifconfig/ifieee80211.c
+++ b/sbin/ifconfig/ifieee80211.c
@@ -196,7 +196,7 @@ static struct ieee80211_txparams_req txparams;
 static int gottxparams = 0;
 static struct ieee80211_channel curchan;
 static int gotcurchan = 0;
-static struct ifmediareq *ifmr;
+static struct ifmediareq *global_ifmr;
 static int htconf = 0;
 static	int gothtconf = 0;
 
@@ -239,7 +239,7 @@ getchaninfo(if_ctx *ctx)
 	if (get80211(ctx, IEEE80211_IOC_CHANINFO, chaninfo,
 	    IEEE80211_CHANINFO_SIZE(MAXCHAN)) < 0)
 		err(1, "unable to get channel information");
-	ifmr = ifmedia_getstate(ctx);
+	global_ifmr = ifmedia_getstate(ctx);
 	gethtconf(ctx);
 	getvhtconf(ctx);
 }
@@ -317,7 +317,7 @@ promote(unsigned int i)
 	 *     the socket descriptor down to here so we can make
 	 *     the ifmedia_getstate call ourselves.
 	 */
-	int chanmode = ifmr != NULL ? IFM_MODE(ifmr->ifm_current) : IFM_AUTO;
+	int chanmode = global_ifmr != NULL ? IFM_MODE(global_ifmr->ifm_current) : IFM_AUTO;
 
 	/* when ambiguous promote to ``best'' */
 	/* NB: we abitrarily pick HT40+ over HT40- */