From nobody Fri May 24 16:05:01 2024 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 4Vm8y54vfsz5LKgC; Fri, 24 May 2024 16:05: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 4Vm8y546jJz41yn; Fri, 24 May 2024 16:05:01 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716566701; 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=Lcz39PcmFqbunav+06idOalJGwc1ITGRdlMLMI5cYhI=; b=cG8LkDhB5gblUAbqx1ReP6PUPBOsPkMdvPNV9OwQsIKtdT9xdoA5eXZiM5+5RwCuH/MLuH AUopPkBTO8NiSF/Gp9SK5m+oaDt3IzGm3angpI1dNLkeqN3XWnYY+15LfvliBDMzPHscYm FOc7egiqwVr7gCui5t3pZbSJcYkoZLyjdQVm1nX+XGfjy3szV7aG21szuwA+5p5KJ8itof f7Gy+/bX7K/Peam9MHoE64W/BgGICJvZkXzoABq5L2h3lXV9KPxIpTe/fTbsfOrc0RPIzQ fm8S8V/6cIkrwLSV1DunEH+RomoT72xjaFX6+VIz6CknN7qIqzMUC6ASQVKTag== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1716566701; a=rsa-sha256; cv=none; b=mGkOVw+B4vc0YtQdTf0/d1GbAxONrcfGE2oZq1js2+qyTFHMlpoCMD83yxLF8qnnQeU9tm vhvTy2GbHiyszeDfpfs1td6gvKCHFpKkB9EHG2L8YMb4tNmH3hSRmwKUPuIjyCVJx0s5sK /uqHr4UsiUw/iMxFwIUAiGnONzCIM66MM2WZvedK3Zv32xxl3OYjRQLgHh/69i3ySNMgjR HK4T5tuOfKFWGJgPEfoCX/2AqMg3ft7kwAZtggFN5DXipPoBKttjjTfzmNqFtpTzb2fpty Pd3V/seiJ2SgH1xjDmEl2uBITazWis5MM32E9lplGFqx49vz8yIntpGIoiv5YQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1716566701; 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=Lcz39PcmFqbunav+06idOalJGwc1ITGRdlMLMI5cYhI=; b=oRGegyelBfDhwZxAkFCASl9rsoPpr161LxZXcsXsy3+MijGRlKcNYxt2l1aQlbjKzzV0YD nD4IODVNXBnf1owuxwUW3xjXV7Bginl/ZcroblI6AR3frJvk5y2jT/AG7RG1QC/Md8mif2 PVrpFjl9AwrtTNcF81UIGSzJOOXiwTHYnzJLBGKakQTcxQlDEIyRfEVXnUxriTm4idmBTn oCnZW+gEUOcq+Q73pF+ltLn5BuWaduxceRz1u8AFH10nGVYEIWmgyAasIIPNCAcKOJMCTR hHongn/RtkSrsSij5GIPKVkHLdDW7PmwEnqisj9QUIv4080tvLkfzFBy2mtYIQ== 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 4Vm8y53c8Fzfts; Fri, 24 May 2024 16:05:01 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.17.1/8.17.1) with ESMTP id 44OG51b1056210; Fri, 24 May 2024 16:05:01 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.17.1/8.17.1/Submit) id 44OG51PA056207; Fri, 24 May 2024 16:05:01 GMT (envelope-from git) Date: Fri, 24 May 2024 16:05:01 GMT Message-Id: <202405241605.44OG51PA056207@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Zhenlei Huang Subject: git: c9188db6f956 - stable/14 - ifconfig: Redo fix vlan/vlanproto reconfiguration 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: X-BeenThere: dev-commits-src-all@freebsd.org Sender: owner-dev-commits-src-all@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: zlei X-Git-Repository: src X-Git-Refname: refs/heads/stable/14 X-Git-Reftype: branch X-Git-Commit: c9188db6f956b30344bc99a13baf57727d4ac97a Auto-Submitted: auto-generated The branch stable/14 has been updated by zlei: URL: https://cgit.FreeBSD.org/src/commit/?id=c9188db6f956b30344bc99a13baf57727d4ac97a commit c9188db6f956b30344bc99a13baf57727d4ac97a Author: Zhenlei Huang AuthorDate: 2024-05-21 16:35:01 +0000 Commit: Zhenlei Huang CommitDate: 2024-05-24 16:03:02 +0000 ifconfig: Redo fix vlan/vlanproto reconfiguration When the if_vlan(4) interface has not been fully configured, i.e., a bare interface without a physical interface associated with it, retrieving the current settings of it and unconditionally overwriting `params` will result in losing vlandev settings in `params`. That will lead to failing to associate the if_vlan(4) interface with the requested physical interface and the false report 'both vlan and vlandev must be specified'. Fix that by checking if the vlan interface has been fully configured. The basic VLAN test is slightly modified to cover this case. PR: 279181 Reviewed by: kp Tested by: Mike Tancsa Fixes: b82b8055ad44 ifconfig: fix vlan/vlanproto reconfiguration MFC after: 3 days Differential Revision: https://reviews.freebsd.org/D45283 (cherry picked from commit 76df3c57a0abfd24652bfa33982ba136d9d0575b) --- sbin/ifconfig/ifvlan.c | 31 ++++++++++++++++++++++++++----- tests/sys/net/if_vlan.sh | 10 +++++++--- 2 files changed, 33 insertions(+), 8 deletions(-) diff --git a/sbin/ifconfig/ifvlan.c b/sbin/ifconfig/ifvlan.c index a79ea35bc14b..0a2603f1736f 100644 --- a/sbin/ifconfig/ifvlan.c +++ b/sbin/ifconfig/ifvlan.c @@ -60,6 +60,7 @@ #include "ifconfig.h" #define NOTAG ((u_short) -1) +#define NOPROTO ((u_short) -1) static const char proto_8021Q[] = "802.1q"; static const char proto_8021ad[] = "802.1ad"; @@ -67,7 +68,7 @@ static const char proto_qinq[] = "qinq"; static struct vlanreq params = { .vlr_tag = NOTAG, - .vlr_proto = ETHERTYPE_VLAN, + .vlr_proto = NOPROTO, }; static void @@ -157,6 +158,8 @@ vlan_create(if_ctx *ctx, struct ifreq *ifr) errx(1, "must specify a tag for vlan create"); if (params.vlr_parent[0] == '\0') errx(1, "must specify a parent device for vlan create"); + if (params.vlr_proto == NOPROTO) + params.vlr_proto = ETHERTYPE_VLAN; ifr->ifr_data = (caddr_t) ¶ms; } ifcreate_ioctl(ctx, ifr); @@ -173,6 +176,8 @@ static void vlan_set(int s, struct ifreq *ifr) { if (params.vlr_tag != NOTAG && params.vlr_parent[0] != '\0') { + if (params.vlr_proto == NOPROTO) + params.vlr_proto = ETHERTYPE_VLAN; ifr->ifr_data = (caddr_t) ¶ms; if (ioctl(s, SIOCSETVLAN, (caddr_t)ifr) == -1) err(1, "SIOCSETVLAN"); @@ -196,8 +201,16 @@ setvlantag(if_ctx *ctx, const char *val, int dummy __unused) errx(1, "value for vlan out of range"); if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) { - vreq.vlr_tag = params.vlr_tag; - memcpy(¶ms, &vreq, sizeof(params)); + /* + * Retrieve the current settings if the interface has already + * been configured. + */ + if (vreq.vlr_parent[0] != '\0') { + if (params.vlr_parent[0] == '\0') + strlcpy(params.vlr_parent, vreq.vlr_parent, IFNAMSIZ); + if (params.vlr_proto == NOPROTO) + params.vlr_proto = vreq.vlr_proto; + } vlan_set(ctx->io_s, &ifr); } } @@ -230,8 +243,16 @@ setvlanproto(if_ctx *ctx, const char *val, int dummy __unused) errx(1, "invalid value for vlanproto"); if (ioctl_ctx_ifr(ctx, SIOCGETVLAN, &ifr) != -1) { - vreq.vlr_proto = params.vlr_proto; - memcpy(¶ms, &vreq, sizeof(params)); + /* + * Retrieve the current settings if the interface has already + * been configured. + */ + if (vreq.vlr_parent[0] != '\0') { + if (params.vlr_parent[0] == '\0') + strlcpy(params.vlr_parent, vreq.vlr_parent, IFNAMSIZ); + if (params.vlr_tag == NOTAG) + params.vlr_tag = vreq.vlr_tag; + } vlan_set(ctx->io_s, &ifr); } } diff --git a/tests/sys/net/if_vlan.sh b/tests/sys/net/if_vlan.sh index 675ed0090e8c..458e3cc36bc6 100755 --- a/tests/sys/net/if_vlan.sh +++ b/tests/sys/net/if_vlan.sh @@ -22,8 +22,12 @@ basic_body() jexec alcatraz ifconfig ${epair_vlan}a up jexec alcatraz ifconfig ${vlan0} 10.0.0.1/24 up - vlan1=$(jexec singsing ifconfig vlan create vlandev ${epair_vlan}b \ - vlan 42) + vlan1=$(jexec singsing ifconfig vlan create) + + # Test associating the physical interface + atf_check -s exit:0 \ + jexec singsing ifconfig ${vlan1} vlandev ${epair_vlan}b vlan 42 + jexec singsing ifconfig ${epair_vlan}b up jexec singsing ifconfig ${vlan1} 10.0.0.2/24 up @@ -37,7 +41,7 @@ basic_body() # And change back # Test changing the vlan ID atf_check -s exit:0 \ - jexec singsing ifconfig ${vlan1} vlandev ${epair_vlan}b vlan 42 + jexec singsing ifconfig ${vlan1} vlan 42 vlandev ${epair_vlan}b atf_check -s exit:0 -o ignore jexec singsing ping -c 1 10.0.0.1 }