From nobody Sun Apr 30 18:12:11 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 4Q8ZDq4kgDz486xQ; Sun, 30 Apr 2023 18:12:11 +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 4Q8ZDq4CB6z3ns1; Sun, 30 Apr 2023 18:12:11 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682878331; 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=Ah1nyT1baNYCNyDEjTPDf2IOsYlSGFxpl+HrHhpyqwA=; b=OhxcYEKg2bSHTLFJWBtdyoX4BpuCRHOUGOerI/4AXSnes0a3GwS+UIMT4L2V6WkgYle2Yz yO4X9NM4+tbR/xDy5zMO8tJ/KNnQpl/izq5OclEuv/NMOCH1p973oJM+dP2PqDkNtaRENX 3BXxo9pDhI0IbyxqAw7damXsB7iEoQGXGloXlXU2VyaJrBoTxgSwgP+feTduXDYyHvOm41 wukhyECRwKM+11Zp4xWc7/JB63JcAlhmZ0hrHn4M25t8betl5ywITew62mbcwda9BWCnZ/ D3YuMev02IdPzhEqDw8ovVSiBTYMP8G3+8EayJIeIpYNnQOo6TkqVnpZ5FVgbw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1682878331; 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=Ah1nyT1baNYCNyDEjTPDf2IOsYlSGFxpl+HrHhpyqwA=; b=wf5OzyPW1yWsPnVAWmAwYTKSqk9SyGRf/Ct3jRz/7s9uOl533MfZyT8rTtSUp+KUuCX1BP 4NZFcydCbTcSCv5LdKbg/UDKhxN91a5nlVYHPmAwfars7RxKml4ud7XQmq4BAaUenRudkY vyiCj4NrqMguNYyWguh+0EJTcD2jwOAD2ORn9Jfjx7ThdFrjqdyplHit9tLGNvcUsqCUI/ IFdICGSDX1QiBxJrqi6se5Ei9Rdsx2k/qNVtVapX+3XxR/3dq92kiCA0aXaXcS2mmaulKt Vmf7G9irqeSi7p4XrAz2/YUBzZPTE7aslkd3kEf9m+zKBYXaxTAefEhA1uMj8A== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1682878331; a=rsa-sha256; cv=none; b=hYR0XwS5/KG4wyDScBkP3liRKp0dV/ZZXnFQz6CC5NLvmMHcp8htY/FOBIs09iu3fsOlDj 14ZyB5y84gHHZ5Z6zkCyAskJJecEcIKaqYXJNkV80quk159HvD6Q6DJcrNt0FMcwDbnKgs 2lHgM8/+9MgvnIHRroxR2+kFB8iYMtHaa0X2u8aKllIE84Hhf6f1m5/svPxfNtIuenHMyi V3tiYNVjvS17p9UkAQ8+FtN/x0WFqdKLnzOprwiXw9X8qgFU7/moQJn6tZlFFvvj9Z/7Yk Px2EuJX0fwJApwU5AQmf/hKZLvFUWLgKobUT6ig/oafOS91k+v5dCi9K/gfJEg== 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 4Q8ZDq3FvrzYfy; Sun, 30 Apr 2023 18:12:11 +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 33UICB1v093314; Sun, 30 Apr 2023 18:12:11 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 33UICBUY093313; Sun, 30 Apr 2023 18:12:11 GMT (envelope-from git) Date: Sun, 30 Apr 2023 18:12:11 GMT Message-Id: <202304301812.33UICBUY093313@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: 6a23843a4a6f - main - libifconfig: fix carp key configuration 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: 6a23843a4a6f2dae95a2029358468b697072b8d2 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch main has been updated by kp: URL: https://cgit.FreeBSD.org/src/commit/?id=6a23843a4a6f2dae95a2029358468b697072b8d2 commit 6a23843a4a6f2dae95a2029358468b697072b8d2 Author: Kristof Provost AuthorDate: 2023-04-28 16:18:55 +0000 Commit: Kristof Provost CommitDate: 2023-04-30 18:11:54 +0000 libifconfig: fix carp key configuration There were two issues with the carp key configuration in the new netlink code. The first is that userspace failed to actually pass the CARP_NL_KEY attribute to the kernel, so a key was never set. The second issue is that snl_attr_get_string() returns a pointer to the string inside the netlink message. It does not copy the string to the target buffer. That's somewhat inconvenient to work with in libifconfig where we have a static buffer for the key. Introduce snl_attr_copy_string() which can copy a string to a target buffer and uses the 'arg' parameter to pass the buffer size, so it doesn't accidentally exceed the available space. Reviewed by: melifaro Sponsored by: Rubicon Communications, LLC ("Netgate") Differential Revision: https://reviews.freebsd.org/D39874 --- lib/libifconfig/libifconfig_carp.c | 3 ++- sys/netlink/netlink_snl.h | 20 +++++++++++++++++++- 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/lib/libifconfig/libifconfig_carp.c b/lib/libifconfig/libifconfig_carp.c index 2b612f0ba51b..cb1a998b3a0c 100644 --- a/lib/libifconfig/libifconfig_carp.c +++ b/lib/libifconfig/libifconfig_carp.c @@ -55,7 +55,7 @@ static struct snl_attr_parser ap_carp_get[] = { { .type = CARP_NL_STATE, .off = _OUT(carpr_state), .cb = snl_attr_get_uint32 }, { .type = CARP_NL_ADVBASE, .off = _OUT(carpr_advbase), .cb = snl_attr_get_int32 }, { .type = CARP_NL_ADVSKEW, .off = _OUT(carpr_advskew), .cb = snl_attr_get_int32 }, - { .type = CARP_NL_KEY, .off = _OUT(carpr_key), .cb = snl_attr_get_string }, + { .type = CARP_NL_KEY, .off = _OUT(carpr_key), .cb = snl_attr_copy_string, .arg_u32 = CARP_KEY_LEN }, { .type = CARP_NL_ADDR, .off = _OUT(carpr_addr), .cb = snl_attr_get_in_addr }, { .type = CARP_NL_ADDR6, .off = _OUT(carpr_addr6), .cb = snl_attr_get_in6_addr }, }; @@ -176,6 +176,7 @@ ifconfig_carp_set_info(ifconfig_handle_t *h, const char *name, &carpr->carpr_addr); snl_add_msg_attr(&nw, CARP_NL_ADDR6, sizeof(carpr->carpr_addr6), &carpr->carpr_addr6); + snl_add_msg_attr_string(&nw, CARP_NL_KEY, carpr->carpr_key); hdr = snl_finalize_msg(&nw); if (hdr == NULL) { diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 4cb1b3e13abc..822cec9b4dc4 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -138,7 +138,12 @@ struct snl_attr_parser { uint16_t type; /* Attribute type */ uint16_t off; /* field offset in the target structure */ snl_parse_attr_f *cb; /* parser function to call */ - const void *arg; /* Optional argument parser */ + + /* Optional parser argument */ + union { + const void *arg; + const uint32_t arg_u32; + }; }; struct snl_hdr_parser { @@ -588,6 +593,19 @@ snl_attr_get_stringn(struct snl_state *ss, struct nlattr *nla, return (true); } +static inline bool +snl_attr_copy_string(struct snl_state *ss, struct nlattr *nla, + const void *arg, void *target) +{ + char *tmp; + + if (snl_attr_get_string(ss, nla, NULL, &tmp)) { + strlcpy(target, tmp, (size_t)arg); + return (true); + } + return (false); +} + static inline bool snl_attr_get_nested(struct snl_state *ss, struct nlattr *nla, const void *arg, void *target) {