From owner-svn-src-all@freebsd.org Mon Oct 21 17:59:02 2019 Return-Path: Delivered-To: svn-src-all@mailman.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.nyi.freebsd.org (Postfix) with ESMTP id F18E415CC5A; Mon, 21 Oct 2019 17:59:02 +0000 (UTC) (envelope-from glebius@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) server-signature RSA-PSS (4096 bits) client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 46xksf5zhSz4W9s; Mon, 21 Oct 2019 17:59:02 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id ACC9F2798F; Mon, 21 Oct 2019 17:59:02 +0000 (UTC) (envelope-from glebius@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id x9LHx2wl058665; Mon, 21 Oct 2019 17:59:02 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9LHx2Fx058664; Mon, 21 Oct 2019 17:59:02 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201910211759.x9LHx2Fx058664@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: glebius set sender to glebius@FreeBSD.org using -f From: Gleb Smirnoff Date: Mon, 21 Oct 2019 17:59:02 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353802 - head/sys/dev/virtio/network X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/sys/dev/virtio/network X-SVN-Commit-Revision: 353802 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-all@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "SVN commit messages for the entire src tree \(except for " user" and " projects" \)" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2019 17:59:03 -0000 Author: glebius Date: Mon Oct 21 17:59:02 2019 New Revision: 353802 URL: https://svnweb.freebsd.org/changeset/base/353802 Log: Convert to if_foreach_llmaddr() KPI. Modified: head/sys/dev/virtio/network/if_vtnet.c Modified: head/sys/dev/virtio/network/if_vtnet.c ============================================================================== --- head/sys/dev/virtio/network/if_vtnet.c Mon Oct 21 17:54:53 2019 (r353801) +++ head/sys/dev/virtio/network/if_vtnet.c Mon Oct 21 17:59:02 2019 (r353802) @@ -3285,6 +3285,34 @@ vtnet_rx_filter(struct vtnet_softc *sc) ifp->if_flags & IFF_ALLMULTI ? "enable" : "disable"); } +static u_int +vtnet_copy_ifaddr(void *arg, struct sockaddr_dl *sdl, u_int ucnt) +{ + struct vtnet_softc *sc = arg; + + if (memcmp(LLADDR(sdl), sc->vtnet_hwaddr, ETHER_ADDR_LEN) == 0) + return (0); + + if (ucnt < VTNET_MAX_MAC_ENTRIES) + bcopy(LLADDR(sdl), + &sc->vtnet_mac_filter->vmf_unicast.macs[ucnt], + ETHER_ADDR_LEN); + + return (1); +} + +static u_int +vtnet_copy_maddr(void *arg, struct sockaddr_dl *sdl, u_int mcnt) +{ + struct vtnet_mac_filter *filter = arg; + + if (mcnt < VTNET_MAX_MAC_ENTRIES) + bcopy(LLADDR(sdl), &filter->vmf_multicast.macs[mcnt], + ETHER_ADDR_LEN); + + return (1); +} + static void vtnet_rx_filter_mac(struct vtnet_softc *sc) { @@ -3293,42 +3321,23 @@ vtnet_rx_filter_mac(struct vtnet_softc *sc) struct sglist_seg segs[4]; struct sglist sg; struct ifnet *ifp; - struct ifaddr *ifa; - struct ifmultiaddr *ifma; - int ucnt, mcnt, promisc, allmulti, error; + bool promisc, allmulti; + u_int ucnt, mcnt; + int error; uint8_t ack; ifp = sc->vtnet_ifp; filter = sc->vtnet_mac_filter; - ucnt = 0; - mcnt = 0; - promisc = 0; - allmulti = 0; VTNET_CORE_LOCK_ASSERT(sc); KASSERT(sc->vtnet_flags & VTNET_FLAG_CTRL_RX, ("%s: CTRL_RX feature not negotiated", __func__)); /* Unicast MAC addresses: */ - if_addr_rlock(ifp); - CK_STAILQ_FOREACH(ifa, &ifp->if_addrhead, ifa_link) { - if (ifa->ifa_addr->sa_family != AF_LINK) - continue; - else if (memcmp(LLADDR((struct sockaddr_dl *)ifa->ifa_addr), - sc->vtnet_hwaddr, ETHER_ADDR_LEN) == 0) - continue; - else if (ucnt == VTNET_MAX_MAC_ENTRIES) { - promisc = 1; - break; - } + ucnt = if_foreach_lladdr(ifp, vtnet_copy_ifaddr, sc); + promisc = (ucnt > VTNET_MAX_MAC_ENTRIES); - bcopy(LLADDR((struct sockaddr_dl *)ifa->ifa_addr), - &filter->vmf_unicast.macs[ucnt], ETHER_ADDR_LEN); - ucnt++; - } - if_addr_runlock(ifp); - - if (promisc != 0) { + if (promisc) { filter->vmf_unicast.nentries = 0; if_printf(ifp, "more than %d MAC addresses assigned, " "falling back to promiscuous mode\n", @@ -3337,22 +3346,10 @@ vtnet_rx_filter_mac(struct vtnet_softc *sc) filter->vmf_unicast.nentries = ucnt; /* Multicast MAC addresses: */ - if_maddr_rlock(ifp); - CK_STAILQ_FOREACH(ifma, &ifp->if_multiaddrs, ifma_link) { - if (ifma->ifma_addr->sa_family != AF_LINK) - continue; - else if (mcnt == VTNET_MAX_MAC_ENTRIES) { - allmulti = 1; - break; - } + mcnt = if_foreach_llmaddr(ifp, vtnet_copy_maddr, filter); + allmulti = (mcnt > VTNET_MAX_MAC_ENTRIES); - bcopy(LLADDR((struct sockaddr_dl *)ifma->ifma_addr), - &filter->vmf_multicast.macs[mcnt], ETHER_ADDR_LEN); - mcnt++; - } - if_maddr_runlock(ifp); - - if (allmulti != 0) { + if (allmulti) { filter->vmf_multicast.nentries = 0; if_printf(ifp, "more than %d multicast MAC addresses " "assigned, falling back to all-multicast mode\n", @@ -3360,7 +3357,7 @@ vtnet_rx_filter_mac(struct vtnet_softc *sc) } else filter->vmf_multicast.nentries = mcnt; - if (promisc != 0 && allmulti != 0) + if (promisc && allmulti) goto out; hdr.class = VIRTIO_NET_CTRL_MAC;