Received: by 2002:a05:6358:3188:b0:123:57c1:9b43 with SMTP id q8csp32691902rwd; Fri, 7 Jul 2023 19:40:52 -0700 (PDT) X-Google-Smtp-Source: APBJJlFAiLxDQntcBmouulPGhXAeoS3DWbYg29Xnlx1rXnkLB/L93JLja/CX8ltNeib1gXZk54+s X-Received: by 2002:a17:906:10d0:b0:993:e752:1a6d with SMTP id v16-20020a17090610d000b00993e7521a6dmr719934ejv.18.1688784051798; Fri, 07 Jul 2023 19:40:51 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1688784051; cv=none; d=google.com; s=arc-20160816; b=OQCCF00KriM3WeVKcpOsuSRvz9Kn6Mr+wxF5mFjy696Bm+BSlLNK+tTGAUK2ei6vbG Rj+c0I5mZS7EsXJElbwWZqN/qgVEDLtogi38JXFRkJXe0xw4Op7ASlY24JJHC/qWgSO3 8N138nrfsLfIYpbROgRpDgfibk1BVGIn2c+UiWICyEbM1qb+1yvWlFFSadUL6BXjYieP z6qJugqZ5X1vRkhmkfQn0wJF78n2+gOAGlt+lahr9GDoXN7Yao3mxOD6Hwz8G8qg9YgO 8E2QvI9lYvzHk/8WMdpMi7LHif8tHrJV52OW6OlFWb0PVhGLMw8W5+cvSYCGohMXb+ry uogA== 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=h6DAPzFvYzPXIAaThIGiAO2Aq5ra0GTsF/O8HUcoK6s=; fh=L25bI22Y4h2nlxYi3SiuGrikSvp5JITVFvWG3qKhvOg=; b=o59TMg12JsS9PLoFUf06/DDJ26tNyWL5LuWuCMv9C3xmqenDETFUI1+F3i5IPkAwEP 0TKCOVW3BkcceHCT5KuT2C2skjwrGoqQcLOFCgluNAXU+jzjjGN+uMFsyeZ9EGb4ijzd 9ZzLAL7nzHLQRYaRIzuSPO49zbaIwuVBwNuTh+0bo0p+WfiLG78Sv6UYInNsJHOpGcBe Spra0I4ji5Gk6s7RpbbV9r65BerlTHR273k0kqPmo7SbLGhr1k52ttY6bFDwA1sjRln6 IV89yCfBngVpO1A7IXTCLdGKZx/EMPhRHxdbCXXCOHzlu/awe8FOXk4XQf2TFDDEcwsx Q4bw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@oracle.com header.s=corp-2023-03-30 header.b=ZMaSs4rc; 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 i16-20020a1709063c5000b00992437c5881si2759048ejg.198.2023.07.07.19.40.28; Fri, 07 Jul 2023 19:40:51 -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=ZMaSs4rc; 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 S229751AbjGHCT0 (ORCPT + 99 others); Fri, 7 Jul 2023 22:19:26 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46264 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229631AbjGHCTZ (ORCPT ); Fri, 7 Jul 2023 22:19:25 -0400 Received: from mx0a-00069f02.pphosted.com (mx0a-00069f02.pphosted.com [205.220.165.32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4A541113; Fri, 7 Jul 2023 19:19:24 -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 368270gb019292; Sat, 8 Jul 2023 02:19:02 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=h6DAPzFvYzPXIAaThIGiAO2Aq5ra0GTsF/O8HUcoK6s=; b=ZMaSs4rclTS0orpTYnFUnPtrbZ8NkLMt//SZ+ssf/w5+YXQmL4ak5W4qMSCqu+Dvjnr8 2Kv7e+XQ4Mhac5eUqhGs365L9NpKMFd9JmvRKPk6inRzLGnceQHtvDCWxzUMPon54BUY 7l2hzVhwZCQBpda+ExK1o6j8uLz3KvMFq0U/LesZxQwA+YvQG5Mr+1NkHMjLLdiMNIdw tcGCaaTzdGdOYkA/L83VDFMJuHZAiRI/kysWGDGgQpHrSKRkKaDSnNaWgx44REcGL2oG XxLm5eGOI1YFv1ws376QkOf5RzX+8XlU5k/2vSFdCIXbqmcBUENGqFdfY+3+O+cZkqDs kA== Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.appoci.oracle.com [130.35.100.223]) by mx0b-00069f02.pphosted.com (PPS) with ESMTPS id 3rpxqb00a4-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 08 Jul 2023 02:19:01 +0000 Received: from pps.filterd (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (8.17.1.19/8.17.1.19) with ESMTP id 3681XmFQ006498; Sat, 8 Jul 2023 02:15:19 GMT Received: from pps.reinject (localhost [127.0.0.1]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTPS id 3rpx87rm1c-1 (version=TLSv1.2 cipher=ECDHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Sat, 08 Jul 2023 02:15:19 +0000 Received: from iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com [127.0.0.1]) by pps.reinject (8.17.1.5/8.17.1.5) with ESMTP id 3682FEKk002005; Sat, 8 Jul 2023 02:15:19 GMT Received: from ca-dev112.us.oracle.com (ca-dev112.us.oracle.com [10.129.136.47]) by iadpaimrmta01.imrmtpd1.prodappiadaev1.oraclevcn.com (PPS) with ESMTP id 3rpx87rkuh-3; Sat, 08 Jul 2023 02:15:18 +0000 From: Anjali Kulkarni To: davem@davemloft.net Cc: Liam.Howlett@Oracle.com, akpm@linux-foundation.org, 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 v8 2/6] netlink: Add new netlink_release function Date: Fri, 7 Jul 2023 19:15:08 -0700 Message-ID: <20230708021512.3929237-3-anjali.k.kulkarni@oracle.com> X-Mailer: git-send-email 2.41.0 In-Reply-To: <20230708021512.3929237-1-anjali.k.kulkarni@oracle.com> References: <20230708021512.3929237-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.957,Hydra:6.0.591,FMLib:17.11.176.26 definitions=2023-07-07_16,2023-07-06_02,2023-05-22_02 X-Proofpoint-Spam-Details: rule=notspam policy=default score=0 bulkscore=0 spamscore=0 mlxlogscore=999 adultscore=0 suspectscore=0 mlxscore=0 malwarescore=0 phishscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.12.0-2305260000 definitions=main-2307080019 X-Proofpoint-ORIG-GUID: SeqdTCg7MRluD27__kQCnXN_pFKB31_- X-Proofpoint-GUID: SeqdTCg7MRluD27__kQCnXN_pFKB31_- 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_H5,RCVD_IN_MSPIKE_WL,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 Reviewed-by: Liam R. Howlett Acked-by: Jakub Kicinski --- 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); }; 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 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 @@ -2091,6 +2096,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; } nl_table[unit].registered = 1; diff --git a/net/netlink/af_netlink.h b/net/netlink/af_netlink.h index 90a3198a9b7f..fd424cd63f31 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; @@ -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, + unsigned long *groups); int registered; }; -- 2.41.0