a256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737407747; 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=3SHm6WJ+QYPQPjcNDA9P1t8xo5THeQ5YUp+k/gilES8=; b=r5tzZXGtzhJXCw/l+6Q8JElTLGeKwVSvMpwZG9/xSGZVtZrdRwpP59/itl2LL8GAtVKEZo 4XgZX/lEo3ZDtl15NUgYfBMNRO2Iyi9MvWlWeu3L1q6wRE0aF2n/nmXvzrg1ClfBpPyz/e Eyr+/UcTDaiH+dltijbV+wqVpolumWDGJ2xLyQfqzcGKQGmBV0uLGhT5uiPc5UPrODdynp SbzWzDczPwOlYz9Kze6mGp/qqFeCCuiqdj0Fb4+GQEyXq5n5r+wZ0SK7ynJAqUfvFvHlIi NMRSRD5+Z8EBvtMQOqseaOM21jeym1D8+QRFBz00K+0Kk6f0nWkHwLrXR7nyXg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1737407747; 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=3SHm6WJ+QYPQPjcNDA9P1t8xo5THeQ5YUp+k/gilES8=; b=HpYqHvvOpi7wZwhVUGxcR4eM4rkySOAhakWaTNMe17nyaeoV0D5eVEUbFQdGMDIb1xP9OL JfxDObYdUd/BK/DrFg7UrdnbOeJD4xjkbSALdWtvyi85BCTQAcsjvH2Ge/pDcdXZhSlJDW lNmb05hHucguMr5xT1GBwGI394JB32lbfUGOzNYeDhN9f6/OW56AZVxxurEdCWAxrV6g6l M3fjqfBAKzNRtbcsYcYLZgjO8dzL7wQSMBP5vJiSg/3ny+L1/nBvIwfOLnloxUuYTeqyqz GrZKwE38XiTFJvWQLRNSsQf7Z8a3estEQVC06CdRVZr+ZBnEV4qd9UynLj2MJw== ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1737407747; a=rsa-sha256; cv=none; b=WKQgsRnm41XFxnBQG9y0gxHWCgV26VDc1V1y4g2gzAsbP87vwI7gNusCT27KC7j06MVNN9 S7R7Zx54vX98xRajvU0TfEugqIrQzEuQL06ujzV+oHi7coSm4iPfdpu2b6MoGLRhK+s49l zl4tDK0IBeW2I0YRE0BqKdmJKmB4yccT7ppzoKRGp8Rq9iHf1asiL3ffUd8Cq/pF22butf vJZqFFB1Mfeb7Yc6R3wzv4SEQ8h8XZKnv+DrCB2vuspNhpyOUTq/R8kWsXC6R0envbeYiZ Kl5IN+FleC3D+X9rPt5S6eZp9k2migQnipdtQ9l4qf8HABTIhwbIBpj0scVqgQ== ARC-Authentication-Results: i=1; mx1.freebsd.org; none 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 4YcNRR2S1szdMg; Mon, 20 Jan 2025 21:15:47 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 50KLFl1X057493; Mon, 20 Jan 2025 21:15:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 50KLFlcd057490; Mon, 20 Jan 2025 21:15:47 GMT (envelope-from git) Date: Mon, 20 Jan 2025 21:15:47 GMT Message-Id: <202501202115.50KLFlcd057490@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Gleb Smirnoff Subject: git: ddc7fd6641c3 - main - netlink: provide snl_clone() to create a secondary snl state List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: glebius X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ddc7fd6641c38a00d8d299d69ba57f0657f5eaac Auto-Submitted: auto-generated The branch main has been updated by glebius: URL: https://cgit.FreeBSD.org/src/commit/?id=ddc7fd6641c38a00d8d299d69ba57f0657f5eaac commit ddc7fd6641c38a00d8d299d69ba57f0657f5eaac Author: Gleb Smirnoff AuthorDate: 2025-01-20 21:15:39 +0000 Commit: Gleb Smirnoff CommitDate: 2025-01-20 21:15:39 +0000 netlink: provide snl_clone() to create a secondary snl state The function will clone an existing snl_state(). The clone points at the same socket, but has a separate allocator. Closing a clone frees the memory, but doesn't close the socket. Such clones are handy in a multithreaded process that has a single socket with multiple writers and a serialized reader. It can be easily extended to support multiple readers, too, but now there is no use. Reviewed by: melifaro Differential Revision: https://reviews.freebsd.org/D48568 --- sys/netlink/netlink_snl.h | 23 ++++++++++++++++------- 1 file changed, 16 insertions(+), 7 deletions(-) diff --git a/sys/netlink/netlink_snl.h b/sys/netlink/netlink_snl.h index 44967b6f444a..faaeebe52eac 100644 --- a/sys/netlink/netlink_snl.h +++ b/sys/netlink/netlink_snl.h @@ -240,14 +240,13 @@ snl_clear_lb(struct snl_state *ss) static void snl_free(struct snl_state *ss) { - if (ss->init_done) { + if (ss->init_done) close(ss->fd); - if (ss->buf != NULL) - free(ss->buf); - if (ss->lb != NULL) { - snl_clear_lb(ss); - lb_free(ss->lb); - } + if (ss->buf != NULL) + free(ss->buf); + if (ss->lb != NULL) { + snl_clear_lb(ss); + lb_free(ss->lb); } } @@ -290,6 +289,16 @@ snl_init(struct snl_state *ss, int netlink_family) return (true); } +static inline bool +snl_clone(struct snl_state *ss, const struct snl_state *orig) +{ + *ss = (struct snl_state){ + .fd = orig->fd, + .init_done = false, + }; + return ((ss->lb = lb_init(SCRATCH_BUFFER_SIZE)) != NULL); +} + static inline bool snl_send(struct snl_state *ss, void *data, int sz) {