From nobody Fri Dec 10 16:29:10 2021 X-Original-To: dev-commits-src-all@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id C9B5818D683C; Fri, 10 Dec 2021 16:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4J9bvW1NQLz3Ds6; Fri, 10 Dec 2021 16:29:11 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id E0CB51DA85; Fri, 10 Dec 2021 16:29:10 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1BAGTANp076909; Fri, 10 Dec 2021 16:29:10 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1BAGTAg8076908; Fri, 10 Dec 2021 16:29:10 GMT (envelope-from git) Date: Fri, 10 Dec 2021 16:29:10 GMT Message-Id: <202112101629.1BAGTAg8076908@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Mike Karels Subject: git: 4dbba5ab609c - stable/13 - ifconfig: warn if setting an Internet address without mask List-Id: Commit messages for all branches of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-all List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: karels X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 4dbba5ab609c9285d734a147e5d876fa393d1403 Auto-Submitted: auto-generated ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1639153751; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=quHZ3BXP25dojx9cg0ZjIFoxZwymIXa24rBj8OJZ858=; b=U2XKX8uwYbbeZBQbUQ1ws6OQvOlKik1YFNajdo99TKpSmq/5nsLP5Zdl0XOABkeWGhE1zg MtMIwOZu1b9Niq8oT5siY/YP3xSt6c8r8iA2TngNsBiQyTL7dLMhXCV2cgeCmroQeMq23L 9DCgb9zY7wmBZP8Fpb1QkOqfT20CEXbbQfskPjvsmgd4YkGPLDJ0t0k5COHryLU+HQjflV JW/H/0crrJ9+x99uwmvQKKndSSpDkMznte03YCgyC0pWBH6np7cnQx3KXCCEo0vsrQokZO mAMS4UIs5+/AmdZTQExx/5Je8LmrPQS0fI71Ab6NQUEDnynnmHbHR7ONUprt2w== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1639153751; a=rsa-sha256; cv=none; b=ALtd/UITYnT/THeKhRPyFd4lh0xHoluy6X2pzx9U4X1XaJhAn1WIt3YVafKIrcSBZZmGH4 XgCzEuALmmxQlzE2Lhvc0ZsXFa0EJynB1aEmVQ7YkqVgiGbZJthbcnwCCSlE6IvyHrArNO VGwFzuSRU+iwPdvXkllcJfY69aJpJ7lBAZxIFDrwjlFFQmi2dAopITdJKA9WqXx8Ut8mfL 8EK59QKkBYCHvwk7vTPm98nYefSGBsyrZzSlF3fhiIImLh5TZSgI7X1wArIfImpLmykecC MSnpYweb8a0umCuicjMfSZH0nAmVoiqOl8xv9fndpoe4wD9ZNrITtu5oqSabcA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by karels: URL: https://cgit.FreeBSD.org/src/commit/?id=4dbba5ab609c9285d734a147e5d876fa393d1403 commit 4dbba5ab609c9285d734a147e5d876fa393d1403 Author: Mike Karels AuthorDate: 2021-10-28 14:32:31 +0000 Commit: Mike Karels CommitDate: 2021-12-10 16:24:51 +0000 ifconfig: warn if setting an Internet address without mask Add a postproc function for af_inet, and add interface flags as a parameter. Check there if setting an address without a mask unless the interface is loopback or point-to-point, where mask is not really meaningful; warn if so. This will hopefully be an error in the future. (cherry picked from commit d8237b95552807e937fc389c7e2237679ef0c984) --- sbin/ifconfig/af_inet.c | 11 +++++++++++ sbin/ifconfig/af_inet6.c | 3 ++- sbin/ifconfig/ifconfig.c | 16 +++++++++------- sbin/ifconfig/ifconfig.h | 3 ++- 4 files changed, 24 insertions(+), 9 deletions(-) diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c index 3d44a4c0b992..c5c40de155d6 100644 --- a/sbin/ifconfig/af_inet.c +++ b/sbin/ifconfig/af_inet.c @@ -175,6 +175,16 @@ in_getaddr(const char *s, int which) errx(1, "%s: bad value", s); } +static void +in_postproc(int s, const struct afswtch *afp, int newaddr, int ifflags) +{ + if (sintab[ADDR]->sin_len != 0 && sintab[MASK]->sin_len == 0 && + newaddr && (ifflags & (IFF_POINTOPOINT | IFF_LOOPBACK)) == 0) { + warnx("WARNING: setting interface address without mask " + "is deprecated,\ndefault mask may not be correct."); + } +} + static void in_status_tunnel(int s) { @@ -222,6 +232,7 @@ static struct afswtch af_inet = { .af_af = AF_INET, .af_status = in_status, .af_getaddr = in_getaddr, + .af_postproc = in_postproc, .af_status_tunnel = in_status_tunnel, .af_settunnel = in_set_tunnel, .af_difaddr = SIOCDIFADDR, diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index 50568de4f148..08902b934ad8 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -419,7 +419,8 @@ sec2str(time_t total) } static void -in6_postproc(int s, const struct afswtch *afp) +in6_postproc(int s, const struct afswtch *afp, int newaddr __unused, + int ifflags __unused) { if (explicit_prefix == 0) { /* Aggregatable address architecture defines all prefixes diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 5e114b43c126..0423b3593504 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -116,7 +116,7 @@ static void status(const struct afswtch *afp, const struct sockaddr_dl *sdl, static void tunnel_status(int s); static _Noreturn void usage(void); -static int getifflags(const char *ifname, int us); +static int getifflags(const char *ifname, int us, bool err_ok); static struct afswtch *af_getbyname(const char *name); static struct afswtch *af_getbyfamily(int af); @@ -603,7 +603,7 @@ main(int argc, char *argv[]) if (iflen >= sizeof(name)) { warnx("%s: interface name too long, skipping", ifname); } else { - flags = getifflags(name, -1); + flags = getifflags(name, -1, false); if (!(((flags & IFF_CANTCONFIG) != 0) || (downonly && (flags & IFF_UP) != 0) || (uponly && (flags & IFF_UP) == 0))) @@ -1000,7 +1000,7 @@ top: * Do any post argument processing required by the address family. */ if (afp->af_postproc != NULL) - afp->af_postproc(s, afp); + afp->af_postproc(s, afp, newaddr, getifflags(name, s, true)); /* * Do deferred callbacks registered while processing * command-line arguments. @@ -1179,7 +1179,7 @@ setifdstaddr(const char *addr, int param __unused, int s, } static int -getifflags(const char *ifname, int us) +getifflags(const char *ifname, int us, bool err_ok) { struct ifreq my_ifr; int s; @@ -1192,8 +1192,10 @@ getifflags(const char *ifname, int us) } else s = us; if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&my_ifr) < 0) { - Perror("ioctl (SIOCGIFFLAGS)"); - exit(1); + if (!err_ok) { + Perror("ioctl (SIOCGIFFLAGS)"); + exit(1); + } } if (us < 0) close(s); @@ -1211,7 +1213,7 @@ setifflags(const char *vname, int value, int s, const struct afswtch *afp) struct ifreq my_ifr; int flags; - flags = getifflags(name, s); + flags = getifflags(name, s, false); if (value < 0) { value = -value; flags &= ~value; diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index ea541c5e9257..2c0b8a100b0d 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -110,7 +110,8 @@ struct afswtch { void (*af_getaddr)(const char *, int); /* parse prefix method (IPv6) */ void (*af_getprefix)(const char *, int); - void (*af_postproc)(int s, const struct afswtch *); + void (*af_postproc)(int s, const struct afswtch *, + int newaddr, int ifflags); u_long af_difaddr; /* set dst if address ioctl */ u_long af_aifaddr; /* set if address ioctl */ void *af_ridreq; /* */