Received: by 2002:a05:6358:9144:b0:117:f937:c515 with SMTP id r4csp1338207rwr; Thu, 20 Apr 2023 13:29:28 -0700 (PDT) X-Google-Smtp-Source: AKy350Y2bip49CrGvydCIUGRaaIX5B9vuK+76PcEdaYlP7xXf6UhplmqlL1AHPRPnjc/SvrFNmTU X-Received: by 2002:a17:903:40cc:b0:1a0:6bd4:ea78 with SMTP id t12-20020a17090340cc00b001a06bd4ea78mr2574682pld.31.1682022568168; Thu, 20 Apr 2023 13:29:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1682022568; cv=none; d=google.com; s=arc-20160816; b=AQi7iGrTdVQyZkphH6nYOq8MYbOeXx72ujjt+IJ/SGqQS26uakGRV4Waq9VS3OsP3m i5SoxTPOqVkgbRf59DACzcVFTWLfXsHXULfPOS5t6A7YezZ9xjnk6kqFzj6hkutHO9b8 vRgzaDL1N0vfp1Fq710he+U6dCpn1b8jQv8nIdFvdiBgsIRKvMGfTBboSx2QJSA6cxN3 /NpNHYQYT1Fhj+T3iuLTd5lgtTuXbXYSzmBwHTbo3MhMEdvESbVynQKoVp5o+mf0Xbdb XGcAkzEMJ38iY0URZk2KHaSMvyeFt2tPs406D08SaXxk3yO+GhLsqt2uOLuCk/pZtHgC 91kg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=TszhWmDYp9cCLCMmtvEMQJZjTmyEI4o5qzJKzuAb25o=; b=B1KvNS67Js4sS8yN0Dr8nwZ9jyIu3mOz2AZ2jk+WbmhvvlMSwghpz8g60wmuKXsLo+ +BxuHp7GCVQfiZ1RD1PBGSXimquWgH0Bjj21zUGkLvAYqhNL07RfUA5tem31M6jTISH2 +mpVhyDp/NTXUIiCMkD9wjsOTAIAwM3cHnfRQJchWWwiV+LdLoIn+gafDhIa3oCicbfd TtfPZfNbowqkTiwIw9AC+eUUfn42f7lAYfE1XmMm62+hqtqsmuMRK63GvroQ5aDW8DS8 Btk8fUNBc7O7TZq86v5nUrPvtwDXQ8ONDgFO1L2Hq//rr/0HbVPZTlOeIvMzj8Xft1A6 33cA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=JsPRUhsN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id km3-20020a17090327c300b001a6dc4a98f7si2233980plb.365.2023.04.20.13.29.15; Thu, 20 Apr 2023 13:29:28 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=JsPRUhsN; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=oracle.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232473AbjDTU20 (ORCPT + 99 others); Thu, 20 Apr 2023 16:28:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232386AbjDTU1q (ORCPT ); Thu, 20 Apr 2023 16:27:46 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 42BB93C22; Thu, 20 Apr 2023 13:27:38 -0700 (PDT) Received: from pps.filterd (m0333521.ppops.net [127.0.0.1]) by mx0b-00069f02.pphosted.com (8.17.1.19/8.17.1.19) with ESMTP id 33KK2BjO013174; Thu, 20 Apr 2023 20:27:19 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=TszhWmDYp9cCLCMmtvEMQJZjTmyEI4o5qzJKzuAb25o=; b=JsPRUhsNRjvdDoz8rdHr6+EoascaoYy40LQ7z+Z+vXLXuZcMtP6SleEe3Vxw6VqisvON F7ldsAb2jYqL1f2ct/8KqUb7hgHh5ryV0iqhNapw0ekk1/kdwB3KG6G86UDJA9yYlQb3 q4JKl0GbHKg2O6LYOZ5Uuf89Nbj3FWF48MMqOche68vs/z5ZJRhLqalmoJR7qJRQzvG6 zh/NqkN+g6Gi4f3BJHcR0sAwFhOIcFKt93tiG/XcOhfdkiaJUjQ1+juyS24ruzAYJURf 9WLo+GhQKVDr4BZ0vnrVIbz7ICj1ivKEeUgd46S2uxmmdCYK0k76e0PE/hWcsdAlBnoc kA== Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.appoci.oracle.com [130.35.103.27]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3pyjucc02c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Apr 2023 20:27:18 +0000 Received: from pps.filterd (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 33KKDsOV026370; Thu, 20 Apr 2023 20:27:17 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3pyjcf2e82-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 20 Apr 2023 20:27:16 +0000 Received: from iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 33KKRCYa027077; Thu, 20 Apr 2023 20:27:16 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta03.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3pyjcf2e4y-3; Thu, 20 Apr 2023 20:27:15 +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, anjali.k.kulkarni@oracle.com Subject: [PATCH v5 2/6] netlink: Add new netlink_release function Date: Thu, 20 Apr 2023 13:27:05 -0700 Message-Id: <20230420202709.3207243-3-anjali.k.kulkarni@oracle.com> X-Mailer: git-send-email 2.40.0 In-Reply-To: <20230420202709.3207243-1-anjali.k.kulkarni@oracle.com> References: <20230420202709.3207243-1-anjali.k.kulkarni@oracle.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Proofpoint-Virus-Version: vendor=baseguard engine=ICAP:2.0.254,Aquarius:18.0.942,Hydra:6.0.573,FMLib:17.11.170.22 definitions=2023-04-20_15,2023-04-20_01,2023-02-09_01 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 mlxlogscore=999 mlxscore=0 adultscore=0 suspectscore=0 phishscore=0 spamscore=0 malwarescore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2303200000 definitions=main-2304200171 X-Proofpoint-GUID: YNahw9NRMwl4kwvDZvhIM68FbAMCU04- X-Proofpoint-ORIG-GUID: YNahw9NRMwl4kwvDZvhIM68FbAMCU04- X-Spam-Status: No, score=-2.8 required=5.0 tests=BAYES_00,DKIMWL_WL_MED, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 866bbc5a4c8d..05a316aa93b4 100644 --- a/include/linux/netlink.h +++ b/include/linux/netlink.h @@ -51,6 +51,7 @@ struct netlink_kernel_cfg { int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); bool (*compare)(struct net *net, struct sock *sk); + void (*release) (struct sock *sk, unsigned long *groups); }; 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 003c7e6ec9be..dc7880055705 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 socket *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 = 0; sock->state = SS_UNCONNECTED; @@ -704,6 +705,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, cb_mutex = nl_table[protocol].cb_mutex; bind = nl_table[protocol].bind; unbind = nl_table[protocol].unbind; + release = nl_table[protocol].release; netlink_unlock_table(); if (err < 0) @@ -719,6 +721,7 @@ static int netlink_create(struct net *net, struct socket *sock, int protocol, nlk->module = module; nlk->netlink_bind = bind; nlk->netlink_unbind = unbind; + nlk->netlink_release = release; out: return err; @@ -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); /* must not acquire netlink_table_lock in any way again before unbind * and notifying genetlink is done as otherwise it might deadlock @@ -2117,6 +2122,7 @@ __netlink_kernel_create(struct net *net, int unit, struct module *module, if (cfg) { nl_table[unit].bind = cfg->bind; nl_table[unit].unbind = cfg->unbind; + nl_table[unit].release = cfg->release; nl_table[unit].flags = cfg->flags; if (cfg->compare) nl_table[unit].compare = cfg->compare; diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h index 5f454c8de6a4..054335a34804 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; struct rhash_head node; @@ -65,6 +67,8 @@ struct netlink_table { int (*bind)(struct net *net, int group); void (*unbind)(struct net *net, int group); bool (*compare)(struct net *net, struct sock *sock); + void (*release)(struct sock *sk, + unsigned long *groups); int registered; }; -- 2.40.0