From nobody Tue Jun 13 06:27:00 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 4QgJVs37Ndz4dLlm; Tue, 13 Jun 2023 06:27:01 +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 4QgJVs0DMJz3nHB; Tue, 13 Jun 2023 06:27:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686637621; 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=ALmqh/k92kBwraOQU1YgZTmme/t9afzPZ6aywjjgy1M=; b=RxSYho6XUpZjASyiwm81fpkKXaiICksIJAGDJiaMB3C7HTkb2DtWsiYNc07gVikdwL9TCK mNFzjTyDz6jvN6yk7MNW9Or4cMu7LhEBZcn4Myihmsz+Ze1dv9/OoMOeHtPn0jcKysFmhI zoBXV8udpTeNBnv+HodjV0sydeF2jjUYwv6S8zBcy6UGJM+Bwm/bxvjI3JLptWMj7VZ/nj /JPhRUmyPfZ9n7MpCxX/teHi1GIkhWXRRfMqdmx+ynug5Fkk68xHUkRXZKMcjWOSf1DjA7 1ghxVTN1mthq9Gnc30kBI+5pCJrBDbKaUWglJcKjFR1qpatrJK/m1d6ib0iyng== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1686637621; 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=ALmqh/k92kBwraOQU1YgZTmme/t9afzPZ6aywjjgy1M=; b=GltT6XGelNLeaHYQy3cGA2NrXImoCESUbV3u1FMojLA6WvYjekTSL4IF9WFZpx1RFTuJaP fiVGhBxJhOZvd4zgmHeb7Qp4PRZ2ixL0yDSp4eXj/cwskPQqEnFf40xwmANte2tkFuHL/9 jLmi7nnHyALPwtUte86Bv7IxGtgEa/DEeAQkMMHBpzEyZdO+79O8BLM7wnZkl6toobs+Zd +83bCBqjsRfG6SskjmGJLhUFNy3hVvyoX+h3kgLixMMYPmKrL77OxAgArXreniUYkg3TOx 9wxfvt+r9RNKV8rhQlUMJC2ElmkHuE6Og4F/yLvEiXGQEFdkdBfgpUXjfVAGDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1686637621; a=rsa-sha256; cv=none; b=qCh8iE9Jrxu2MRYPiRjQZKMzZxRQPQh3TnUCgJc9G82ZwER1YfMPxUgHGaaK5yjrmD1EOY DWR/974hIZunrXKZsYcn5f2tfHRgeZ8sKXjj30RX7S7z7GD3/kQyR/F8BwXg0/VRqynm6I T2HqRFwQBsyWWYlDve5XrDWvhAcNwl1Q6mF2PeR2uXYSNiEKumvnE3CE+PQH1daCVStYiz R1l+ofDtr+/50AskquMALh4o9eEf1HzWlTiglBYCReRnifInhQB1PhThVBtXLm0WEyn5gB QQ6yHZ3y3o0Tdz9GGplMht6Rk+75225lfREcUt/g7akNF80vMrIMthyBYpEzew== 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 4QgJVr5XwWz19x8; Tue, 13 Jun 2023 06:27:00 +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 35D6R0iB030998; Tue, 13 Jun 2023 06:27:00 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 35D6R0SB030997; Tue, 13 Jun 2023 06:27:00 GMT (envelope-from git) Date: Tue, 13 Jun 2023 06:27:00 GMT Message-Id: <202306130627.35D6R0SB030997@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: 4106282ec41d - main - ifconfig: remove global 'printifname' variable. 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: 4106282ec41d92b98c29e25316d11d93600a8f23 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by melifaro: URL: https://cgit.FreeBSD.org/src/commit/?id=4106282ec41d92b98c29e25316d11d93600a8f23 commit 4106282ec41d92b98c29e25316d11d93600a8f23 Author: Alexander V. Chernikov AuthorDate: 2023-06-13 06:18:05 +0000 Commit: Alexander V. Chernikov CommitDate: 2023-06-13 06:18:10 +0000 ifconfig: remove global 'printifname' variable. This variable was used to print the created interface name in the atexit(3) handler. The interface name was calculated in the ifclonecreate() by matching old & new names. This change alter the implementation the following way: 1) the function responsible for the interface creation (ifcreate_ioctl) updates all necessary state internally. This removes the need for the name manipulation hack in wlan_create(). 2) As atexit(3) handler does not accept any parameters, explicitly store the name to print in the ifname_to_print variable read by the atexit(3) handler. Reviewed By: kp Differential Revision: https://reviews.freebsd.org/D40431 MFC after: 2 weeks --- sbin/ifconfig/ifclone.c | 9 --------- sbin/ifconfig/ifconfig.c | 26 +++++++++++++++++++++----- sbin/ifconfig/ifconfig.h | 9 +++++---- sbin/ifconfig/ifieee80211.c | 7 ------- 4 files changed, 26 insertions(+), 25 deletions(-) diff --git a/sbin/ifconfig/ifclone.c b/sbin/ifconfig/ifclone.c index 7939ff95a065..f09b91b4181b 100644 --- a/sbin/ifconfig/ifclone.c +++ b/sbin/ifconfig/ifclone.c @@ -148,15 +148,6 @@ ifclonecreate(if_ctx *ctx, void *arg __unused) } else { dcp->clone_cb(ctx, &ifr); } - - /* - * If we get a different name back than we put in, update record and - * indicate it should be printed later. - */ - if (strncmp(name, ifr.ifr_name, sizeof(name)) != 0) { - strlcpy(name, ifr.ifr_name, sizeof(name)); - printifname = 1; - } } static void diff --git a/sbin/ifconfig/ifconfig.c b/sbin/ifconfig/ifconfig.c index 869eb44289d7..28677e57065c 100644 --- a/sbin/ifconfig/ifconfig.c +++ b/sbin/ifconfig/ifconfig.c @@ -102,12 +102,13 @@ static int setmask; static int doalias; static int clearaddr; int newaddr = 1; -int printifname = 0; struct ifconfig_args global_args; int exit_code = 0; +static char ifname_to_print[IFNAMSIZ]; /* Helper for printifnamemaybe() */ + /* Formatter Strings */ char *f_inet, *f_inet6, *f_ether, *f_addr; @@ -198,9 +199,22 @@ usage(void) exit(1); } +static void +ifname_update(if_ctx *ctx, const char *name) +{ + strlcpy(ctx->_ifname_storage_ioctl, name, sizeof(ctx->_ifname_storage_ioctl)); + ctx->ifname = ctx->_ifname_storage_ioctl; + + strlcpy(ifname_to_print, name, sizeof(ifname_to_print)); +} + void ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr) { + char ifname_orig[IFNAMSIZ]; + + strlcpy(ifname_orig, ifr->ifr_name, sizeof(ifname_orig)); + if (ioctl(ctx->io_s, SIOCIFCREATE2, ifr) < 0) { switch (errno) { case EEXIST: @@ -209,6 +223,9 @@ ifcreate_ioctl(if_ctx *ctx, struct ifreq *ifr) err(1, "SIOCIFCREATE2 (%s)", ifr->ifr_name); } } + + if (strncmp(ifname_orig, ifr->ifr_name, sizeof(ifname_orig)) != 0) + ifname_update(ctx, ifr->ifr_name); } #ifdef WITHOUT_NETLINK @@ -402,8 +419,8 @@ sortifaddrs(struct ifaddrs *list, static void printifnamemaybe(void) { - if (printifname) - printf("%s\n", name); + if (ifname_to_print[0] != '\0') + printf("%s\n", ifname_to_print); } static void @@ -1520,8 +1537,7 @@ setifname(if_ctx *ctx, const char *val, int dummy __unused) free(newname); err(1, "ioctl SIOCSIFNAME (set name)"); } - printifname = 1; - strlcpy(name, newname, sizeof(name)); + ifname_update(ctx, newname); free(newname); } diff --git a/sbin/ifconfig/ifconfig.h b/sbin/ifconfig/ifconfig.h index 4910a816d3f1..7b9c64cdaef1 100644 --- a/sbin/ifconfig/ifconfig.h +++ b/sbin/ifconfig/ifconfig.h @@ -58,10 +58,12 @@ struct ifconfig_args; struct ifconfig_context { struct ifconfig_args *args; const struct afswtch *afp; - int io_s; /* fd to use for ioctl() */ - struct snl_state *io_ss; /* NETLINK_ROUTE socket */ + int io_s; /* fd to use for ioctl() */ + struct snl_state *io_ss; /* NETLINK_ROUTE socket */ + char *ifname; /* Current interface name */ + char _ifname_storage_ioctl[IFNAMSIZ]; }; -typedef const struct ifconfig_context if_ctx; +typedef struct ifconfig_context if_ctx; typedef void c_func(if_ctx *ctx, const char *cmd, int arg); typedef void c_func2(if_ctx *ctx, const char *arg1, const char *arg2); @@ -251,7 +253,6 @@ extern struct ifreq ifr; extern char name[IFNAMSIZ]; /* name of interface */ extern int allmedia; extern int newaddr; -extern int printifname; extern int exit_code; extern struct ifconfig_args global_args; extern char *f_inet, *f_inet6, *f_ether, *f_addr; diff --git a/sbin/ifconfig/ifieee80211.c b/sbin/ifconfig/ifieee80211.c index dfedb0b82a92..4f2af7148ece 100644 --- a/sbin/ifconfig/ifieee80211.c +++ b/sbin/ifconfig/ifieee80211.c @@ -5800,7 +5800,6 @@ static void wlan_create(if_ctx *ctx, struct ifreq *ifr) { static const uint8_t zerobssid[IEEE80211_ADDR_LEN]; - char orig_name[IFNAMSIZ]; if (params.icp_parent[0] == '\0') errx(1, "must specify a parent device (wlandev) when creating " @@ -5811,13 +5810,7 @@ wlan_create(if_ctx *ctx, struct ifreq *ifr) ifr->ifr_data = (caddr_t) ¶ms; ifcreate_ioctl(ctx, ifr); - /* XXX preserve original name for ifclonecreate(). */ - strlcpy(orig_name, name, sizeof(orig_name)); - strlcpy(name, ifr->ifr_name, sizeof(name)); - setdefregdomain(ctx); - - strlcpy(name, orig_name, sizeof(name)); } static void