From nobody Thu May 25 15:03:57 2023 X-Original-To: dev-commits-src-main@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 4QRrt54NBZz4V5k5; Thu, 25 May 2023 15:03:57 +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 4QRrt53wybz3CMG; Thu, 25 May 2023 15:03:57 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685027037; 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=+Xo3Fh7FIsN+PJJT+olGJnNXQ9wJ0BsWBEu8ZpgcSHU=; b=nfNrTuvdjecMDZbdbwkJh+ZXVBov2fsXT7OYiELIhsGp+tVn/5EK7saibaLXH2URboag+Y 8czgL/dkfOzQTcwDS84RQa+GvGAWzs87ObYisBo9QIf3fOqzYAFQPjqsB9Tw2HuqsNmQwP 8hppGH7AYxLPZNIx3PiUgh+5K9E4uUVfLzkUlOMaSnR2L/HzLrBrl4V52qq7YkXXYztYfE omJnncyCyzXoZ0mdfb9h6ozJxmlS08LAzHGq/bg6QqgEtNmXbF4kyxZV3QW3hDIVUtTSrF UhaumIkZ6A2EznSHr3sxkgHZvCPDM1rNIBgs4ag2bJDr5+56iVPWw+hQEFNx1w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1685027037; 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=+Xo3Fh7FIsN+PJJT+olGJnNXQ9wJ0BsWBEu8ZpgcSHU=; b=e5cZ9o+eIw2zazh06nD6mBcw1/1IS44RUmaAKG4xCzrQziiFv2cfjkbuVq4mAs7Zztibln mCAGYUTqXtJUxeHzIW4Gi8ZMQHaS1kM0bg1Us3/g9Xt0YT7Hr+U8HcBfC55Dx2Q2Bx2lfA XkNPV8QC45HFMyZfVP36LsLZU/93TEGMFE7sAh/Ms4yXRQHYjlaWSwWdmhISd9UMOPx3/H BbmYRD3PCVdeeKTcakw4Kpj70dp2WZt7R2GY50OCs6tBewBW21fx5EGzkbe/RxVqEdcPA+ R9HEjo4PeWwn1n+fE0LWJKm1O5G18ypqHO9185G8PTMg+eR1lUS0MPIGzyUGdg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1685027037; a=rsa-sha256; cv=none; b=kz0pDKQLio3qZ5CY6rN4xN5LPlBY+hDRdVqETS2XSByD1VxNBSBJ3NS/AYKf4DIyh4xd2N yfahMzCkZwewkbE3LKoFbWZYtaEUGrZ8sP5kdFqkaslYuv2aOKjTYLhyb4OdAhjsut0gau VKsDTm5rhncmsVL/LMw8g/weGCJ1W829ZJEaDxd8HF41g+mnbQEl/YsykVUZy6WDa/5VKZ DU5lW46gbcgv1uP6gMeCpRNuW3Zrl8uFDrUyp2Wj3+zQNuUDOcBA5t6Z0MOQ+7rz0NTkN8 7HHQ8XHCZvOsVN57RrQGGnUdRvc1gcOtwYOE1hZs7XETYDC1Ku2s6JRnTySPhg== 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 4QRrt52zzgzVFw; Thu, 25 May 2023 15:03:57 +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 34PF3vJT029533; Thu, 25 May 2023 15:03:57 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 34PF3vGo029532; Thu, 25 May 2023 15:03:57 GMT (envelope-from git) Date: Thu, 25 May 2023 15:03:57 GMT Message-Id: <202305251503.34PF3vGo029532@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: "Alexander V. Chernikov" Subject: git: 6d204407ec6e - main - ifconfig: fix ifconfig IFX inet[6] ADDR -alias List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-main@freebsd.org X-BeenThere: dev-commits-src-main@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: melifaro X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 6d204407ec6eb3403306578a2550a92b8560d92b Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=6d204407ec6eb3403306578a2550a92b8560d92b commit 6d204407ec6eb3403306578a2550a92b8560d92b Author: Alexander V. Chernikov AuthorDate: 2023-05-25 14:50:57 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-05-25 15:03:35 +0000 ifconfig: fix ifconfig IFX inet[6] ADDR -alias Internally, inet and inet6 family handlers store state for address addition and deletion separately, as, for example, "ifconfig lo0 inet 127.0.0.2/32" triggers a) deletion of the first interface address and b) addition of a new one. The current logic behind handling "-alias" being the last argument is to copy the address from "addition" state to the "deletion" state. It is done by the generic ifconfig code, which explicitly typecasts opaque handler state pointers to "struct ifreq", which doesn't work in the Netlink case. Fix this by introducing family-specific "af_copyaddr" handler, which removes the peeking & typecasting logic from the generic code. Reported by: otis Tested by: otis --- sbin/ifconfig/af_inet.c | 14 ++++++++++++++ sbin/ifconfig/af_inet6.c | 14 ++++++++++++++ sbin/ifconfig/ifconfig.c | 11 ++++------- sbin/ifconfig/ifconfig.h | 2 ++ 4 files changed, 34 insertions(+), 7 deletions(-) diff --git a/sbin/ifconfig/af_inet.c b/sbin/ifconfig/af_inet.c index 73decb229d0f..76787e62d908 100644 --- a/sbin/ifconfig/af_inet.c +++ b/sbin/ifconfig/af_inet.c @@ -201,6 +201,12 @@ static struct sockaddr_in *sintab[] = { SIN(in_addreq.ifra_mask), SIN(in_addreq.ifra_broadaddr) }; +static void +in_copyaddr(if_ctx *ctx, int to, int from) +{ + memcpy(sintab[to], sintab[from], sizeof(struct sockaddr_in)); +} + static void in_getaddr(const char *s, int which) { @@ -256,6 +262,13 @@ static struct in_px *sintab_nl[] = { &in_add.brd_addr, /* BRDADDR*/ }; +static void +in_copyaddr(if_ctx *ctx, int to, int from) +{ + sintab_nl[to]->addr = sintab_nl[from]->addr; + sintab_nl[to]->addrset = sintab_nl[from]->addrset; +} + static void in_getip(const char *addr_str, struct in_addr *ip) { @@ -537,6 +550,7 @@ static struct afswtch af_inet = { .af_status = in_status_nl, #endif .af_getaddr = in_getaddr, + .af_copyaddr = in_copyaddr, .af_postproc = in_postproc, .af_status_tunnel = in_status_tunnel, .af_settunnel = in_set_tunnel, diff --git a/sbin/ifconfig/af_inet6.c b/sbin/ifconfig/af_inet6.c index d5418b827789..f735afdc8797 100644 --- a/sbin/ifconfig/af_inet6.c +++ b/sbin/ifconfig/af_inet6.c @@ -421,6 +421,13 @@ static struct in6_px *sin6tab_nl[] = { &in6_add.dst_addr, /* DSTADDR*/ }; +static void +in6_copyaddr(if_ctx *ctx, int to, int from) +{ + sin6tab_nl[to]->addr = sin6tab_nl[from]->addr; + sin6tab_nl[to]->set = sin6tab_nl[from]->set; +} + static void in6_getaddr(const char *addr_str, int which) { @@ -504,6 +511,12 @@ static struct sockaddr_in6 *sin6tab[] = { &in6_addreq.ifra_prefixmask, &in6_addreq.ifra_dstaddr }; +static void +in6_copyaddr(if_ctx *ctx, int to, int from) +{ + memcpy(sin6tab[to], sin6tab[from], sizeof(struct sockaddr_in6)); +} + static void in6_getprefix(const char *plen, int which) { @@ -733,6 +746,7 @@ static struct afswtch af_inet6 = { .af_status = in6_status_nl, #endif .af_getaddr = in6_getaddr, + .af_copyaddr = in6_copyaddr, #ifdef WITHOUT_NETLINK .af_getprefix = in6_getprefix, #endif diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 8ae7920e6ea9..84df15a58ce1 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -1327,19 +1327,16 @@ notealias(if_ctx *ctx, const char *addr, int param) { const struct afswtch *afp = ctx->afp; -#define rqtosa(x) (&(((struct ifreq *)(afp->x))->ifr_addr)) - if (setaddr && doalias == 0 && param < 0) - if (afp->af_addreq != NULL && afp->af_ridreq != NULL) - bcopy((caddr_t)rqtosa(af_addreq), - (caddr_t)rqtosa(af_ridreq), - rqtosa(af_addreq)->sa_len); + if (setaddr && doalias == 0 && param < 0) { + if (afp->af_copyaddr != NULL) + afp->af_copyaddr(ctx, RIDADDR, ADDR); + } doalias = param; if (param < 0) { clearaddr = 1; newaddr = 0; } else clearaddr = 0; -#undef rqtosa } static void diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 62dc0bdfe1f4..054e7a12f488 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -174,6 +174,7 @@ typedef void af_status_f(if_ctx *ctx, const struct ifaddrs *); typedef void af_other_status_f(if_ctx *ctx); typedef void af_postproc_f(if_ctx *ctx, int newaddr, int ifflags); typedef int af_exec_f(if_ctx *ctx, unsigned long action, void *data); +typedef void af_copyaddr_f(if_ctx *ctx, int to, int from); struct afswtch { const char *af_name; /* as given on cmd line, e.g. "inet" */ @@ -194,6 +195,7 @@ struct afswtch { #endif af_other_status_f *af_other_status; void (*af_getaddr)(const char *, int); + af_copyaddr_f *af_copyaddr; /* Copy address between ADDR */ /* parse prefix method (IPv6) */ void (*af_getprefix)(const char *, int); af_postproc_f *af_postproc;