From nobody Fri Feb 03 14:45:17 2023 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 4P7djp2jwHz2pCXB; Fri, 3 Feb 2023 14:45:18 +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 4P7djp21tcz4MHM; Fri, 3 Feb 2023 14:45:18 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435518; 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=xuDfiYIIASi7tL9vxo6ECLqjFJLiY1evaIL1p0Cwyzk=; b=bZqMDr1MRKmSOxeYguiD435YOZkhNNGwSIkaD7uzX4vE0S5h+YztDsEsWYFsVAtLPOXdaH FPw4UDd2F2EKA10a21UiRaeO0GodzwWdxsfu03VZHBuWvPEcECUbo95XZh8rNgI7Y15qRs PhKNUiFpszYLbWd0f/bi42QHDqmEpKr8fvBHz3ab5ZdsMR48cZ50yNXyn7u6aQW1ODbVN4 MOhJbTtcATzNCTcwzlnD8GUy9YfgIMPml9N5oXvy8SIT3hebY786hgD48QHQlmhXRuoML0 vNEQenyyHFC9TSkTcix6ulPIf0a5aInQRjQt0MFVvOqDyZVpCcAk5f8eAtlIKQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1675435518; 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=xuDfiYIIASi7tL9vxo6ECLqjFJLiY1evaIL1p0Cwyzk=; b=jfTsQtvqTu+YTESljgsK0ZyvimhxA8l/sPkMrTPloK2fbZ9v1a8X525taPuijRe9BQukWe RpbQp1fs0Qk9FsYOA0tzMJvB+YMOC00TA/VGqom2qcc46+hCSPAMI8oHGS5B//fMTgVKCL Hg8MmNFhgzPoOSQtxkI/xobvA8EngEqZOodichckhZgGkoBh2VlA7h0dRBLwxxyB4g/X5j 7DWzIcAOyp82R7oMsO5VgBzVtjc9cHxC51ogboptlDEYKVuREICwJ0wcySr4f3+BU59zV/ goPzsy7k2xGWf/KSNP67nSF3NZDES4GEFi8dvZPA1Mbmo5jLpqzcrYD5InZDdg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1675435518; a=rsa-sha256; cv=none; b=uhOYTzrO9vJZi4EsCBhO/BFCEoqZBl1pfsfL1GHQWq6lncPp4ZWbDTV2lyLi0VPsKO8B5I Gkk6VUdx+d/HUCN48K44SnAPi3FQVH0ukrp7l8CbGsxNcW+nmJ788nx4Fzpt70LR4MwPzx o4D4QOCV6HLUYjAlQUy1VFK2wdzzAKoahAOU+kC5eRBbHETrgdeTIlKWoZoIooYBlnVt/y 91h0GFAJXxBonpyoJaavkBv3mmlp9CTbodZpB5MI2BqxWZqb0EBH7tzGrsdFqFj7/+TsDa nUIEI8dro26jgXrEzSJlH3z3nGRlpH7sBwzRn6VZtm/NeoRmCbsMrAg56WmiHA== 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 4P7djp0t5jzdnC; Fri, 3 Feb 2023 14:45:18 +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 313EjHcI027852; Fri, 3 Feb 2023 14:45:17 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 313EjHua027851; Fri, 3 Feb 2023 14:45:17 GMT (envelope-from git) Date: Fri, 3 Feb 2023 14:45:17 GMT Message-Id: <202302031445.313EjHua027851@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Justin Hibbits Subject: git: 2eeb808361e4 - main - IfAPI: Add iterator to loop over all interfaces 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: Sender: owner-dev-commits-src-all@freebsd.org X-BeenThere: dev-commits-src-all@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: jhibbits X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 2eeb808361e421f9a054820fa358e899383742de Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by jhibbits: URL: https://cgit.FreeBSD.org/src/commit/?id=2eeb808361e421f9a054820fa358e899383742de commit 2eeb808361e421f9a054820fa358e899383742de Author: Justin Hibbits AuthorDate: 2023-02-01 21:28:11 +0000 Commit: Justin Hibbits CommitDate: 2023-02-03 14:38:02 +0000 IfAPI: Add iterator to loop over all interfaces Summary: Sometimes it's useful to iterate over all interfaces in the current VNET, as the linuxulator does in several places. Unlike other iterators in the IfAPI this propagates any error received up to the caller, instead of returning a count. Sponsored by: Juniper Networks, Inc. Reviewed by: glebius, melifaro Differential Revision: https://reviews.freebsd.org/D38348 --- sys/net/if.c | 19 +++++++++++++++++++ sys/net/if_var.h | 3 +++ 2 files changed, 22 insertions(+) diff --git a/sys/net/if.c b/sys/net/if.c index 951349b97ffb..8bb5ed0043e5 100644 --- a/sys/net/if.c +++ b/sys/net/if.c @@ -4466,6 +4466,25 @@ if_lladdr_count(if_t ifp) return (count); } +int +if_foreach(if_foreach_cb_t cb, void *cb_arg) +{ + if_t ifp; + int error; + + NET_EPOCH_ASSERT(); + MPASS(cb); + + error = 0; + CK_STAILQ_FOREACH(ifp, &V_ifnet, if_link) { + error = cb(ifp, cb_arg); + if (error != 0) + break; + } + + return (error); +} + u_int if_foreach_lladdr(if_t ifp, iflladdr_cb_t cb, void *cb_arg) { diff --git a/sys/net/if_var.h b/sys/net/if_var.h index 4c3d4138f7ec..b4cdcf27253f 100644 --- a/sys/net/if_var.h +++ b/sys/net/if_var.h @@ -665,6 +665,9 @@ struct ifaddr * if_getifaddr(const if_t ifp); typedef u_int if_addr_cb_t(void *, struct ifaddr *, u_int); u_int if_foreach_addr_type(if_t ifp, int type, if_addr_cb_t cb, void *cb_arg); +typedef int (*if_foreach_cb_t)(if_t, void *); +int if_foreach(if_foreach_cb_t, void *); + /* Functions */ void if_setinitfn(if_t ifp, if_init_fn_t); void if_setinputfn(if_t ifp, if_input_fn_t);