From nobody Mon Feb 9 17:58:37 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id AEF3FEB64D9 for ; Wed, 14 Jun 2023 23:42:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235768AbjFNXmA (ORCPT ); Wed, 14 Jun 2023 19:42:00 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:35786 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230303AbjFNXlz (ORCPT ); Wed, 14 Jun 2023 19:41:55 -0400 Received: from mx0b-00069f02.pphosted.com (mx0b-00069f02.pphosted.com [205.220.177.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5F601FEB; Wed, 14 Jun 2023 16:41:49 -0700 (PDT) Received: from pps.filterd (m0246631.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 35EK6m77012638; Wed, 14 Jun 2023 23:41:34 GMT DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=oracle.com; h=from : to : cc : subject : date : message-id : in-reply-to : references : mime-version : content-transfer-encoding; s=corp-2023-03-30; bh=jH6Vx7IHa88iYD9ySv4iWWmDP+TOGUHn7olfX8Xe6UU=; b=yt8JY2AwLcrKRo2Gg9B4kpPfr6a2eTgRFJf9ivh1ROJXPgYQ19jND/3uyG0iUMWYJ4H3 bfW0q/h5qQyYd7b3z3i44lllNYErnSWkRNI4YjGEXsBKyI3Uyv5lk9WqXHQZ6EFX1xPT Gg5kUQjsUC5Iq2p/RUEjjpleqxLRd+rIqOebID7jxexWQj8ytJ1Qdr7O6WnDq1X1u+cY YJoyItYZPbEhpn6W0kz4PmjY0QmXxLqEUXm3Dqb4FUw8NQcaMX6WozgKjqy7vw4bS4Fg w+6SiLXz3z5vXGfkOfiSGtSDLszGwfZvG0WcUHLvqkDJE0tTNXI/rbE1qVzJpJX2TAMb rA== Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.appoci.oracle.com [138.1.114.2]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3r4fy3gse2-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Jun 2023 23:41:33 +0000 Received: from pps.filterd (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 35ELc04G017754; Wed, 14 Jun 2023 23:41:32 GMT Received: from pps.reinject (localhost [127.0.0.1]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTPS id 3r4fm5y0av-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Wed, 14 Jun 2023 23:41:32 +0000 Received: from phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 35ENfUeR023835; Wed, 14 Jun 2023 23:41:32 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by phxpaimrmta01.imrmtpd1.prodappphxaev1.oraclevcn.com (PPS) with ESMTP id 3r4fm5y09x-3; Wed, 14 Jun 2023 23:41:32 +0000 From: Anjali Kulkarni To: davem@davemloft.net Cc: david@fries.net, edumazet@google.com, kuba@kernel.org, pabeni@redhat.com, zbr@ioremap.net, brauner@kernel.org, johannes@sipsolutions.net, ecree.xilinx@gmail.com, leon@kernel.org, keescook@chromium.org, socketcan@hartkopp.net, petrm@nvidia.com, linux-kernel@vger.kernel.org, netdev@vger.kernel.org, Liam.Howlett@Oracle.com, akpm@linux-foundation.org, anjali.k.kulkarni@oracle.com Subject: [PATCH v6 2/6] netlink: Add new netlink_release function Date: Wed, 14 Jun 2023 16:41:24 -0700 Message-ID: <20230614234129.3264175-3-anjali.k.kulkarni@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230614234129.3264175-1-anjali.k.kulkarni@oracle.com> References: <20230614234129.3264175-1-anjali.k.kulkarni@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.957,Hydra:6.0.573,FMLib:17.11.176.26 definitions=2023-06-14_14,2023-06-14_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 malwarescore=0 suspectscore=0 mlxlogscore=999 mlxscore=0 phishscore=0 spamscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2306140207 X-Proofpoint-GUID: tMdY1ijFvFxCZ1YRhCjNCAfWqn_ALCb_ X-Proofpoint-ORIG-GUID: tMdY1ijFvFxCZ1YRhCjNCAfWqn_ALCb_ Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" A new function netlink_release is added in netlink_sock to store the protocol's release function. This is called when the socket is deleted. This can be supplied by the protocol via the release function in netlink_kernel_cfg. This is being added for the NETLINK_CONNECTOR protocol, so it can free it's data when socket is deleted. Signed-off-by: Anjali Kulkarni --- include/linux/netlink.h | 1 + net/netlink/af_netlink.c | 6 ++++++ net/netlink/af_netlink.h | 4 ++++ 3 files changed, 11 insertions(+) diff --git a/include/linux/netlink.h b/include/linux/netlink.h index d73cfe5b6bc2..0db4ffe6186b 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -50,6 +50,7 @@ struct netlink_kernel_cfg { struct mutex *cb_mutex; int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); + void (*release) (struct sock *sk, unsigned long *groups); }; =20 struct sock *__netlink_kernel_create(struct net *net, int unit, diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c index e75e5156e4ac..383c10c6e6e3 100644 --- a/net/netlink/af_netlink.c +++ b/net/netlink/af_netlink.c @@ -677,6 +677,7 @@ static int netlink_create(struct net *net, struct socke= t *sock, int protocol, struct netlink_sock *nlk; int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); + void (*release)(struct sock *sock, unsigned long *groups); int err =3D 0; =20 sock->state =3D SS_UNCONNECTED; @@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socke= t *sock, int protocol, cb_mutex =3D nl_table[protocol].cb_mutex; bind =3D nl_table[protocol].bind; unbind =3D nl_table[protocol].unbind; + release =3D nl_table[protocol].release; netlink_unlock_table(); =20 if (err < 0) @@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socke= t *sock, int protocol, nlk->module =3D module; nlk->netlink_bind =3D bind; nlk->netlink_unbind =3D unbind; + nlk->netlink_release =3D release; out: return err; =20 @@ -763,6 +766,8 @@ static int netlink_release(struct socket *sock) * OK. Socket is unlinked, any packets that arrive now * will be purged. */ + if (nlk->netlink_release) + nlk->netlink_release(sk, nlk->groups); =20 /* must not acquire netlink_table_lock in any way again before unbind * and notifying genetlink is done as otherwise it might deadlock @@ -2091,6 +2096,7 @@ __netlink_kernel_create(struct net *net, int unit, st= ruct module *module, if (cfg) { nl_table[unit].bind =3D cfg->bind; nl_table[unit].unbind =3D cfg->unbind; + nl_table[unit].release =3D cfg->release; nl_table[unit].flags =3D cfg->flags; } nl_table[unit].registered =3D 1; diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h index 90a3198a9b7f..cb2688aa347a 100644 --- a/net/netlink/af_netlink.h +++ b/net/netlink/af_netlink.h @@ -42,6 +42,8 @@ struct netlink_sock { void (*netlink_rcv)(struct sk_buff *skb); int (*netlink_bind)(struct net *net, int group); void (*netlink_unbind)(struct net *net, int group); + void (*netlink_release)(struct sock *sk, + unsigned long *groups); struct module *module; =20 struct rhash_head node; @@ -64,6 +66,8 @@ struct netlink_table { struct module *module; int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); + void (*release)(struct sock *sk,=20 + unsigned long *groups); int registered; }; =20 --=20 2.41.0