From owner-svn-src-head@freebsd.org Mon Oct 21 18:07:25 2019 Return-Path: Delivered-To: svn-src-head@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 BC9DC15D57C; Mon, 21 Oct 2019 18:07:25 +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 46xl3K1KCmz4YrP; Mon, 21 Oct 2019 18:07:25 +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 D7ABF27B5C; Mon, 21 Oct 2019 18:07:24 +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 x9LI7OoE065569; Mon, 21 Oct 2019 18:07:24 GMT (envelope-from glebius@FreeBSD.org) Received: (from glebius@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id x9LI7OZu065568; Mon, 21 Oct 2019 18:07:24 GMT (envelope-from glebius@FreeBSD.org) Message-Id: <201910211807.x9LI7OZu065568@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 18:07:24 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r353821 - head/sys/dev/nfe X-SVN-Group: head X-SVN-Commit-Author: glebius X-SVN-Commit-Paths: head/sys/dev/nfe X-SVN-Commit-Revision: 353821 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 21 Oct 2019 18:07:25 -0000 Author: glebius Date: Mon Oct 21 18:07:24 2019 New Revision: 353821 URL: https://svnweb.freebsd.org/changeset/base/353821 Log: Convert to if_foreach_llmaddr() KPI. Modified: head/sys/dev/nfe/if_nfe.c Modified: head/sys/dev/nfe/if_nfe.c ============================================================================== --- head/sys/dev/nfe/if_nfe.c Mon Oct 21 18:07:19 2019 (r353820) +++ head/sys/dev/nfe/if_nfe.c Mon Oct 21 18:07:24 2019 (r353821) @@ -2557,75 +2557,67 @@ nfe_encap(struct nfe_softc *sc, struct mbuf **m_head) return (0); } +struct nfe_hash_maddr_ctx { + uint8_t addr[ETHER_ADDR_LEN]; + uint8_t mask[ETHER_ADDR_LEN]; +}; +static u_int +nfe_hash_maddr(void *arg, struct sockaddr_dl *sdl, u_int cnt) +{ + struct nfe_hash_maddr_ctx *ctx = arg; + uint8_t *addrp, mcaddr; + int j; + + addrp = LLADDR(sdl); + for (j = 0; j < ETHER_ADDR_LEN; j++) { + mcaddr = addrp[j]; + ctx->addr[j] &= mcaddr; + ctx->mask[j] &= ~mcaddr; + } + + return (1); +} + static void nfe_setmulti(struct nfe_softc *sc) { if_t ifp = sc->nfe_ifp; - int i, mc_count, mcnt; + struct nfe_hash_maddr_ctx ctx; uint32_t filter; - uint8_t addr[ETHER_ADDR_LEN], mask[ETHER_ADDR_LEN]; uint8_t etherbroadcastaddr[ETHER_ADDR_LEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff }; - uint8_t *mta; + int i; NFE_LOCK_ASSERT(sc); if ((if_getflags(ifp) & (IFF_ALLMULTI | IFF_PROMISC)) != 0) { - bzero(addr, ETHER_ADDR_LEN); - bzero(mask, ETHER_ADDR_LEN); + bzero(ctx.addr, ETHER_ADDR_LEN); + bzero(ctx.mask, ETHER_ADDR_LEN); goto done; } - bcopy(etherbroadcastaddr, addr, ETHER_ADDR_LEN); - bcopy(etherbroadcastaddr, mask, ETHER_ADDR_LEN); + bcopy(etherbroadcastaddr, ctx.addr, ETHER_ADDR_LEN); + bcopy(etherbroadcastaddr, ctx.mask, ETHER_ADDR_LEN); - mc_count = if_multiaddr_count(ifp, -1); - mta = malloc(sizeof(uint8_t) * ETHER_ADDR_LEN * mc_count, M_DEVBUF, - M_NOWAIT); + if_foreach_llmaddr(ifp, nfe_hash_maddr, &ctx); - /* Unable to get memory - process without filtering */ - if (mta == NULL) { - device_printf(sc->nfe_dev, "nfe_setmulti: failed to allocate" - "temp multicast buffer!\n"); - - bzero(addr, ETHER_ADDR_LEN); - bzero(mask, ETHER_ADDR_LEN); - goto done; - } - - if_multiaddr_array(ifp, mta, &mcnt, mc_count); - - for (i = 0; i < mcnt; i++) { - uint8_t *addrp; - int j; - - addrp = mta + (i * ETHER_ADDR_LEN); - for (j = 0; j < ETHER_ADDR_LEN; j++) { - u_int8_t mcaddr = addrp[j]; - addr[j] &= mcaddr; - mask[j] &= ~mcaddr; - } - } - - free(mta, M_DEVBUF); - for (i = 0; i < ETHER_ADDR_LEN; i++) { - mask[i] |= addr[i]; + ctx.mask[i] |= ctx.addr[i]; } done: - addr[0] |= 0x01; /* make sure multicast bit is set */ + ctx.addr[0] |= 0x01; /* make sure multicast bit is set */ - NFE_WRITE(sc, NFE_MULTIADDR_HI, - addr[3] << 24 | addr[2] << 16 | addr[1] << 8 | addr[0]); + NFE_WRITE(sc, NFE_MULTIADDR_HI, ctx.addr[3] << 24 | ctx.addr[2] << 16 | + ctx.addr[1] << 8 | ctx.addr[0]); NFE_WRITE(sc, NFE_MULTIADDR_LO, - addr[5] << 8 | addr[4]); - NFE_WRITE(sc, NFE_MULTIMASK_HI, - mask[3] << 24 | mask[2] << 16 | mask[1] << 8 | mask[0]); + ctx.addr[5] << 8 | ctx.addr[4]); + NFE_WRITE(sc, NFE_MULTIMASK_HI, ctx.mask[3] << 24 | ctx.mask[2] << 16 | + ctx.mask[1] << 8 | ctx.mask[0]); NFE_WRITE(sc, NFE_MULTIMASK_LO, - mask[5] << 8 | mask[4]); + ctx.mask[5] << 8 | ctx.mask[4]); filter = NFE_READ(sc, NFE_RXFILTER); filter &= NFE_PFF_RX_PAUSE;