From nobody Fri Apr 14 11:20:46 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 4PyYsW24FZz4535q; Fri, 14 Apr 2023 11:20:47 +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 4PyYsW0Kvpz3vYq; Fri, 14 Apr 2023 11:20:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681471247; 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=BpLAbtZBwMoNz/0W10yfWx+klfozlopvZ1rRI4IM4S8=; b=GtowPeLjJE8MRNrqx/3XzcczcOm7efjxlaewQ4zyLFUPVyNZhrLJYW7hGJhNSVs/dx8R95 ckN/OTREImMfr4P4WBC8mjKkiJVQS74EJv1TuJbkpgJV33MA1NPw4B3WUkJs0EW2/MO38c Lq4rAtoOorDsCjVqLznIXVXio8oSLsjdhSbwBn0T3w0lJr7FTt6Qvrust84at2ewxe1lBW 5Bz3nXi0u6oDri6H53kVRpgJVwMTLwf/uT52tpzrWtv4WNogZiP3eghxEilootFbac4u/Q /9DE3pffuQ8FZK9ccaGBSrxEQ9oTcACDfupIDVt64lDF/5n1ICiJGofiK9Dteg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1681471247; 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=BpLAbtZBwMoNz/0W10yfWx+klfozlopvZ1rRI4IM4S8=; b=w8A20DqF/rhJUzsEspUsfqxMyY4Lr0VuI0Yz9rRlYEQP633kSGh/Cl5VuzIMOrKk+gXh4x yDk3iVdDm2d3doyPhQBjNZuDn7y0Ly91OAHxm6F2fNj7BouNZivnhrbtCLCELREU35eoDc ntNWE8NhWtfE0Q6aliqXW/dxMT2NT/Uc29YBNSBhLmM3hVFE55fXDiPewIJtsT/jBIvtNs dD//ErnpjVSZAFr8vZ4xqq+iQFKtUQxvbnZYaFB3yUY/TAB0pIjUQzAytXvDE5i/93m4eh tvBkpk0/tpiUvCNl5DRRsbWFKtqhgR5sFiCOUfM28T8u0sdnkblZKc8AUyenSw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1681471247; a=rsa-sha256; cv=none; b=YHjQifLQmPPHrCHl/VyhOjZdi2YSsP+HOfjuAWXyBSkA71QFyC/5fFHsWB2hovDY1UGtJc sSLBWpenXcPJCGHtjCauToa+WBF2R5SVoVPjjwc6GsrNyyNVLbEq769dpfz3BqcId0lml0 HNvRuZy843VsFHTq0HarZjhbKPiSdA9DP4RNi2yatSXEpcExHkhwodhYM8fJ6wxH9bCt/x zKBRjmU1q1vW++PkrzjAKFZiMJMVfhpuSXf53EWQkJN3RZ4WiELbsmo06kzdjCnAXhMhAr wHDYh2Ia5OffinbRY+iQbU+UK68M8xJ1SIIAhLaYJ76NzIGuSvojKz4YxXeaKA== 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 4PyYsV6JvTzMmY; Fri, 14 Apr 2023 11:20:46 +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 33EBKkJI022815; Fri, 14 Apr 2023 11:20:46 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33EBKkHI022814; Fri, 14 Apr 2023 11:20:46 GMT (envelope-from git) Date: Fri, 14 Apr 2023 11:20:46 GMT Message-Id: <202304141120.33EBKkHI022814@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Kristof Provost Subject: git: b0e38a1373c0 - main - bridge: distinguish no vlan and vlan 1 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: b0e38a1373c087e5a55eefcdee69ccfbf12f86ce Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=b0e38a1373c087e5a55eefcdee69ccfbf12f86ce commit b0e38a1373c087e5a55eefcdee69ccfbf12f86ce Author: Kristof Provost AuthorDate: 2023-04-07 16:00:08 +0000 Commit: Kristof Provost CommitDate: 2023-04-14 11:17:02 +0000 bridge: distinguish no vlan and vlan 1 The bridge treated no vlan tag as being equivalent to vlan ID 1, which causes confusion if the bridge sees both untagged and vlan 1 tagged traffic. Use DOT1Q_VID_NULL when there's no tag, and fix up the lookup code by using 'DOT1Q_VID_RSVD_IMPL' to mean 'any vlan', rather than vlan 0. Note that we have to account for userspace expecting to use 0 as meaning 'any vlan'. PR: 270559 Suggested by: Zhenlei Huang Reviewed by: philip, zlei Differential Revision: https://reviews.freebsd.org/D39478 --- sys/net/if_bridge.c | 24 ++++++++++++++---------- sys/net/if_vlan_var.h | 5 +++++ 2 files changed, 19 insertions(+), 10 deletions(-) diff --git a/sys/net/if_bridge.c b/sys/net/if_bridge.c index 44ee52e62b77..d78c647df0b4 100644 --- a/sys/net/if_bridge.c +++ b/sys/net/if_bridge.c @@ -389,9 +389,12 @@ static int bridge_fragment(struct ifnet *, struct mbuf **mp, static void bridge_linkstate(struct ifnet *ifp); static void bridge_linkcheck(struct bridge_softc *sc); -/* The default bridge vlan is 1 (IEEE 802.1Q-2003 Table 9-2) */ +/* + * Use the "null" value from IEEE 802.1Q-2014 Table 9-2 + * to indicate untagged frames. + */ #define VLANTAGOF(_m) \ - (_m->m_flags & M_VLANTAG) ? EVL_VLANOFTAG(_m->m_pkthdr.ether_vtag) : 1 + (_m->m_flags & M_VLANTAG) ? EVL_VLANOFTAG(_m->m_pkthdr.ether_vtag) : DOT1Q_VID_NULL static struct bstp_cb_ops bridge_ops = { .bcb_state = bridge_state_change, @@ -1639,8 +1642,13 @@ static int bridge_ioctl_daddr(struct bridge_softc *sc, void *arg) { struct ifbareq *req = arg; + int vlan = req->ifba_vlan; + + /* Userspace uses '0' to mean 'any vlan' */ + if (vlan == 0) + vlan = DOT1Q_VID_RSVD_IMPL; - return (bridge_rtdaddr(sc, req->ifba_dst, req->ifba_vlan)); + return (bridge_rtdaddr(sc, req->ifba_dst, vlan)); } static int @@ -2886,10 +2894,6 @@ bridge_rtupdate(struct bridge_softc *sc, const uint8_t *dst, uint16_t vlan, dst[3] == 0 && dst[4] == 0 && dst[5] == 0) != 0) return (EINVAL); - /* 802.1p frames map to vlan 1 */ - if (vlan == 0) - vlan = 1; - /* * A route for this destination might already exist. If so, * update it, otherwise create a new one. @@ -3100,8 +3104,8 @@ bridge_rtdaddr(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan) BRIDGE_RT_LOCK(sc); /* - * If vlan is zero then we want to delete for all vlans so the lookup - * may return more than one. + * If vlan is DOT1Q_VID_RSVD_IMPL then we want to delete for all vlans + * so the lookup may return more than one. */ while ((brt = bridge_rtnode_lookup(sc, addr, vlan)) != NULL) { bridge_rtnode_destroy(sc, brt); @@ -3232,7 +3236,7 @@ bridge_rtnode_lookup(struct bridge_softc *sc, const uint8_t *addr, uint16_t vlan hash = bridge_rthash(sc, addr); CK_LIST_FOREACH(brt, &sc->sc_rthash[hash], brt_hash) { dir = bridge_rtnode_addr_cmp(addr, brt->brt_addr); - if (dir == 0 && (brt->brt_vlan == vlan || vlan == 0)) + if (dir == 0 && (brt->brt_vlan == vlan || vlan == DOT1Q_VID_RSVD_IMPL)) return (brt); if (dir > 0) return (NULL); diff --git a/sys/net/if_vlan_var.h b/sys/net/if_vlan_var.h index fb05cddc03bd..faed461c97aa 100644 --- a/sys/net/if_vlan_var.h +++ b/sys/net/if_vlan_var.h @@ -128,6 +128,11 @@ struct vlanreq { #define VLAN_PCP_MAX 7 +#define DOT1Q_VID_NULL 0x0 +#define DOT1Q_VID_DEF_PVID 0x1 +#define DOT1Q_VID_DEF_SR_PVID 0x2 +#define DOT1Q_VID_RSVD_IMPL 0xfff + /* * 802.1q full tag. Proto and vid are stored in host byte order. */