From nobody Fri Mar 31 11:36:42 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 4PnytM0D9Yz42Mjx; Fri, 31 Mar 2023 11:36:43 +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 4PnytL6sv1z3jC1; Fri, 31 Mar 2023 11:36:42 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680262603; 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=HOnVrUEwn3TenTQmTGioc4scLbnC7VB3DMPkfwGYxhY=; b=BlVBKP1YUlXR6rZ2zkyT2ts2QtqczG2NhEVlbm3t/6J6MTyPzTDpivrs3cBlLo5Wzdq6Ct h/OQt+Tx/KU19a5xQNYCQ/MnjCbJFRcgxr9onhvg5gPZWvRCUb8Fs3V/ouCGOzpcu9PGrC 9B2bCDCN5xLIWn2n3LH3nTlz9fW7VXCLmRxJpg3v6D/A4kBRVIuXWISPxwghoDjK08mRJi YBg3ZeBTyhMvCqgktH8loVNfyKBF7I7PNiJr/wPkWLe0bOvriJ6rDlOKEFyEYi+Eo/KIfl NBiJll8Ch5IjIezW7Ww3g1T703ePwmLOsCURAKAr1CBSTEOdCDpfD4SgNCWJTA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1680262603; 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=HOnVrUEwn3TenTQmTGioc4scLbnC7VB3DMPkfwGYxhY=; b=HmCjMfSQGjyEtQWiI66ruGJJn97tRmQ0+r5WFmCcnwrAgKwjBHS+a+EyxJg8+1oqYIFi+1 XORmerFT7JlEs27l3E2DhNI6ONiLhUU61tCeLP9XvKkGMVvBezkt1lV3k8YydX9irfl86T ZbFLlvCi2g8mXRbKQ0L9Qhc1/+DH41c6j6oJTUPoIdjGc4fWFl5QaiuQZasUXovaX2NJ1a 4mIWXr4V4QTjKVHBF/1lUDokGqR3RXMmcejnZHozwL7UqRF+/YZcjBE1c9qR/ij7K4Vd+U biE/B1NhdgGigsPPOTMD8JPm5eGVorRb8/XGDHp6KyIvuU1p4rGESuI2wZHumw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1680262603; a=rsa-sha256; cv=none; b=EXukbOAhki6XR1foO/FfTkEMqHQK2/V4OYAut4NCm4QgyWfH3O3ipZDKugmtYdzdXkfyTJ yd4iXPBDSiUiFp1fh4GpE5LsG6aqMjVoJhDenN4edXKEAontEQhXmA375ioRCfPwjR+5Bh IR37FTGfbxltH9544PT0ZlujDgVAEmWG/3H7y4Fclysa4vkhnEI+WTlbhHNpwQgy1vMoOf 6jTMjeLFX8Ltr66movFY5k2ljcN1neAJfNbWoq8p/gqW2kvPtoWcxlWs/hOYvKITMxRd7o 7XMx0XWcoERaZL2kc51v6UINqwmShrIE2LKTcEi4Q6415WQv2t5bVIKWyfXD7w== 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 4PnytL5xJyzsMY; Fri, 31 Mar 2023 11:36:42 +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 32VBag9F054267; Fri, 31 Mar 2023 11:36:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 32VBagJl054266; Fri, 31 Mar 2023 11:36:42 GMT (envelope-from git) Date: Fri, 31 Mar 2023 11:36:42 GMT Message-Id: <202303311136.32VBagJl054266@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: 28921c4f7de6 - main - carp: allow commands to use interface name rather than index 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: kp X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: 28921c4f7de6d8641b4deaa8942526309018668a Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=28921c4f7de6d8641b4deaa8942526309018668a commit 28921c4f7de6d8641b4deaa8942526309018668a Author: Kristof Provost AuthorDate: 2023-03-30 23:34:03 +0000 Commit: Kristof Provost CommitDate: 2023-03-31 09:29:58 +0000 carp: allow commands to use interface name rather than index Get/set commands can now choose to provide the interface name rather than the interface index. This allows userspace to avoid a call to if_nametoindex(). Suggested by: melifaro Reviewed by: melifaro Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D39359 --- lib/libifconfig/libifconfig_carp.c | 18 ++---------------- sys/netinet/ip_carp.c | 16 ++++++++++++---- sys/netinet/ip_carp_nl.h | 1 + 3 files changed, 15 insertions(+), 20 deletions(-) diff --git a/lib/libifconfig/libifconfig_carp.c b/lib/libifconfig/libifconfig_carp.c index 5729362ffef9..501ca81782eb 100644 --- a/lib/libifconfig/libifconfig_carp.c +++ b/lib/libifconfig/libifconfig_carp.c @@ -73,17 +73,10 @@ _ifconfig_carp_get(ifconfig_handle_t *h, const char *name, struct nlmsghdr *hdr; size_t i = 0; uint32_t seq_id; - unsigned int ifindex; int family_id; ifconfig_error_clear(h); - ifindex = if_nametoindex(name); - if (ifindex == 0) { - ifconfig_error(h, NETLINK, ENOENT); - return (-1); - } - if (! snl_init(&ss, NETLINK_GENERIC)) { ifconfig_error(h, NETLINK, ENOTSUP); return (-1); @@ -100,7 +93,7 @@ _ifconfig_carp_get(ifconfig_handle_t *h, const char *name, hdr = snl_create_genl_msg_request(&nw, family_id, CARP_NL_CMD_GET); hdr->nlmsg_flags |= NLM_F_DUMP; - snl_add_msg_attr_u32(&nw, CARP_NL_IFINDEX, ifindex); + snl_add_msg_attr_string(&nw, CARP_NL_IFNAME, name); if (vhid != 0) snl_add_msg_attr_u32(&nw, CARP_NL_VHID, vhid); @@ -153,18 +146,11 @@ ifconfig_carp_set_info(ifconfig_handle_t *h, const char *name, struct snl_state ss = {}; struct snl_writer nw; struct nlmsghdr *hdr; - unsigned int ifindex; int family_id; uint32_t seq_id; ifconfig_error_clear(h); - ifindex = if_nametoindex(name); - if (ifindex == 0) { - ifconfig_error(h, NETLINK, ENOENT); - return (-1); - } - if (! snl_init(&ss, NETLINK_GENERIC)) { ifconfig_error(h, NETLINK, ENOTSUP); return (-1); @@ -183,7 +169,7 @@ ifconfig_carp_set_info(ifconfig_handle_t *h, const char *name, snl_add_msg_attr_u32(&nw, CARP_NL_STATE, carpr->carpr_state); snl_add_msg_attr_s32(&nw, CARP_NL_ADVBASE, carpr->carpr_advbase); snl_add_msg_attr_s32(&nw, CARP_NL_ADVSKEW, carpr->carpr_advskew); - snl_add_msg_attr_u32(&nw, CARP_NL_IFINDEX, ifindex); + snl_add_msg_attr_string(&nw, CARP_NL_IFNAME, name); snl_add_msg_attr(&nw, CARP_NL_ADDR, sizeof(carpr->carpr_addr), &carpr->carpr_addr); snl_add_msg_attr(&nw, CARP_NL_ADDR6, sizeof(carpr->carpr_addr6), diff --git a/sys/netinet/ip_carp.c b/sys/netinet/ip_carp.c index 2e1c8e084b4b..a6a89d0f87d8 100644 --- a/sys/netinet/ip_carp.c +++ b/sys/netinet/ip_carp.c @@ -2301,6 +2301,7 @@ carp_nl_send(void *arg, struct carp_softc *sc, int priv) struct nl_carp_parsed { unsigned int ifindex; + char *ifname; uint32_t state; uint32_t vhid; int32_t advbase; @@ -2322,6 +2323,7 @@ static const struct nlattr_parser nla_p_set[] = { { .type = CARP_NL_IFINDEX, .off = _OUT(ifindex), .cb = nlattr_get_uint32 }, { .type = CARP_NL_ADDR, .off = _OUT(addr), .cb = nlattr_get_in_addr }, { .type = CARP_NL_ADDR6, .off = _OUT(addr6), .cb = nlattr_get_in6_addr }, + { .type = CARP_NL_IFNAME, .off = _OUT(ifname), .cb = nlattr_get_string }, }; static const struct nlfield_parser nlf_p_set[] = { }; @@ -2337,7 +2339,7 @@ carp_nl_get(struct nlmsghdr *hdr, struct nl_pstate *npt) struct carp_nl_send_args args; struct carpreq carpr = { }; struct epoch_tracker et; - if_t ifp; + if_t ifp = NULL; int error; error = nl_parse_nlmsg(hdr, &carp_parser, npt, &attrs); @@ -2345,7 +2347,10 @@ carp_nl_get(struct nlmsghdr *hdr, struct nl_pstate *npt) return (error); NET_EPOCH_ENTER(et); - ifp = ifnet_byindex_ref(attrs.ifindex); + if (attrs.ifname != NULL) + ifp = ifunit_ref(attrs.ifname); + else if (attrs.ifindex != 0) + ifp = ifnet_byindex_ref(attrs.ifindex); NET_EPOCH_EXIT(et); if ((error = carp_is_supported_if(ifp)) != 0) @@ -2379,7 +2384,7 @@ carp_nl_set(struct nlmsghdr *hdr, struct nl_pstate *npt) struct nl_carp_parsed attrs = { }; struct carpkreq carpr; struct epoch_tracker et; - if_t ifp; + if_t ifp = NULL; int error; error = nl_parse_nlmsg(hdr, &carp_parser, npt, &attrs); @@ -2398,7 +2403,10 @@ carp_nl_set(struct nlmsghdr *hdr, struct nl_pstate *npt) return (EINVAL); NET_EPOCH_ENTER(et); - ifp = ifnet_byindex_ref(attrs.ifindex); + if (attrs.ifname != NULL) + ifp = ifunit_ref(attrs.ifname); + else if (attrs.ifindex != 0) + ifp = ifnet_byindex_ref(attrs.ifindex); NET_EPOCH_EXIT(et); if ((error = carp_is_supported_if(ifp)) != 0) diff --git a/sys/netinet/ip_carp_nl.h b/sys/netinet/ip_carp_nl.h index 60e8c569a05d..89720af3e0dc 100644 --- a/sys/netinet/ip_carp_nl.h +++ b/sys/netinet/ip_carp_nl.h @@ -31,6 +31,7 @@ enum carp_nl_type_t { CARP_NL_IFINDEX = 6, /* u32 */ CARP_NL_ADDR = 7, /* in_addr_t */ CARP_NL_ADDR6 = 8, /* in6_addr_t */ + CARP_NL_IFNAME = 9, /* string */ }; #endif