Received: by 2002:a05:6a10:1a4d:0:0:0:0 with SMTP id nk13csp858717pxb; Tue, 1 Feb 2022 11:54:46 -0800 (PST) X-Google-Smtp-Source: ABdhPJx5SiiesO4oFGigrP3UOU6vojVSWVWpvXDCiAXOVMwGyHm7whsBa9MROXt9ueYdZ8mLp1Za X-Received: by 2002:a50:eb46:: with SMTP id z6mr26640756edp.229.1643745286263; Tue, 01 Feb 2022 11:54:46 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643745286; cv=none; d=google.com; s=arc-20160816; b=fuuiY0c3tKLXqd+7aWW+lka8utCU8F4ILEmHNQqO14SpMHwe3fLxd41nN+skK1zt4B UzTfq7Z/5i2zHlAreXjBuyuFbyKgyrIhs3ZOqwiwlJtfz5AzaSJDRMw7CoMAqneFh/ST DetFuPjIbMoyfpo0TSky2AMV3SfwVwNutBOhF9oRQInhG8JFhsB3SuDGluUUpoD2SRRD P9L1WWFFMSCfitNAtHCwubb6C5W2TCma+PNkYFnlhUsqgnL/0CXGSYA67dw17BX88pj8 k5hWjNuQ0BDQgndOhuGAOg3pgPviasggZ+N0OzfbmwnV2wFO8mHfyju5kHgSaAUBAsFl 1Iug== 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 :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=jF3kd2VS3N1nJS6wgZgcdHE0UsazwlHIizIX00PooD4=; b=wl65+2M4+D8dqo5Z8O0PdpucwF9qV7Q8t0QHxg5CRM7IkyjKPenm1EvluTlc8LTLga HiodVvPqlaNn9TVlXkRH6dN5+H6dwWIu/Drjv1Yz39CJqoMt2nwLNeyvyZK6em7DSAGY wp+1zusj3GMdJ6h/bz5c8BupwbeF5xEWKwCqKwd2ky9JrykhQ/HPuypQ/rTbQepSmMeR ck53PSLZwnj95IT1SEx3GET+Db8ZmGi3K9OqvnpzEyTkGm+QAw+EAEhX4M5a+rWm8yWU R/6t9QW9R7Xv7QnlAS2vP5NPPmeeBOCYyAiyq4iLOW/Dg5FS6lnebRVR6yz0KrqMCDZj dw5A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jBFsRpDn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id hv16si4970097ejc.163.2022.02.01.11.54.21; Tue, 01 Feb 2022 11:54:46 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=jBFsRpDn; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1359174AbiAaLEg (ORCPT + 99 others); Mon, 31 Jan 2022 06:04:36 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43312 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1359118AbiAaLC7 (ORCPT ); Mon, 31 Jan 2022 06:02:59 -0500 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3F3B8C0613E9; Mon, 31 Jan 2022 03:01:21 -0800 (PST) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id D11E260BA2; Mon, 31 Jan 2022 11:01:20 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id BAC6DC340E8; Mon, 31 Jan 2022 11:01:19 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1643626880; bh=eqaDUaWKBeWkcDFPzgRykjEQnCAlLdBYpvHrHiPgvio=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=jBFsRpDn/rSx54J91L+wCaODl84GYP5b+mPYyy/5mBpjZ17fTmXtO9wFaHjhzWn2A SfzHwPrwqnGt6jEPaym5MquyapsOKuexQIWhmLR2XO25nnXhoYdJ448V4jdhB0nkKW ZJ8QzDrKBDcveVi0AyVBq11GwYVTLBt5GAJNZtnQ= From: Greg Kroah-Hartman To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Jianguo Wu , "David S. Miller" Subject: [PATCH 5.4 42/64] net-procfs: show net devices bound packet types Date: Mon, 31 Jan 2022 11:56:27 +0100 Message-Id: <20220131105217.100841787@linuxfoundation.org> X-Mailer: git-send-email 2.35.1 In-Reply-To: <20220131105215.644174521@linuxfoundation.org> References: <20220131105215.644174521@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Jianguo Wu commit 1d10f8a1f40b965d449e8f2d5ed7b96a7c138b77 upstream. After commit:7866a621043f ("dev: add per net_device packet type chains"), we can not get packet types that are bound to a specified net device by /proc/net/ptype, this patch fix the regression. Run "tcpdump -i ens192 udp -nns0" Before and after apply this patch: Before: [root@localhost ~]# cat /proc/net/ptype Type Device Function 0800 ip_rcv 0806 arp_rcv 86dd ipv6_rcv After: [root@localhost ~]# cat /proc/net/ptype Type Device Function ALL ens192 tpacket_rcv 0800 ip_rcv 0806 arp_rcv 86dd ipv6_rcv v1 -> v2: - fix the regression rather than adding new /proc API as suggested by Stephen Hemminger. Fixes: 7866a621043f ("dev: add per net_device packet type chains") Signed-off-by: Jianguo Wu Signed-off-by: David S. Miller Signed-off-by: Greg Kroah-Hartman --- net/core/net-procfs.c | 35 ++++++++++++++++++++++++++++++++--- 1 file changed, 32 insertions(+), 3 deletions(-) --- a/net/core/net-procfs.c +++ b/net/core/net-procfs.c @@ -182,12 +182,23 @@ static const struct seq_operations softn .show = softnet_seq_show, }; -static void *ptype_get_idx(loff_t pos) +static void *ptype_get_idx(struct seq_file *seq, loff_t pos) { + struct list_head *ptype_list = NULL; struct packet_type *pt = NULL; + struct net_device *dev; loff_t i = 0; int t; + for_each_netdev_rcu(seq_file_net(seq), dev) { + ptype_list = &dev->ptype_all; + list_for_each_entry_rcu(pt, ptype_list, list) { + if (i == pos) + return pt; + ++i; + } + } + list_for_each_entry_rcu(pt, &ptype_all, list) { if (i == pos) return pt; @@ -208,22 +219,40 @@ static void *ptype_seq_start(struct seq_ __acquires(RCU) { rcu_read_lock(); - return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN; + return *pos ? ptype_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; } static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos) { + struct net_device *dev; struct packet_type *pt; struct list_head *nxt; int hash; ++*pos; if (v == SEQ_START_TOKEN) - return ptype_get_idx(0); + return ptype_get_idx(seq, 0); pt = v; nxt = pt->list.next; + if (pt->dev) { + if (nxt != &pt->dev->ptype_all) + goto found; + + dev = pt->dev; + for_each_netdev_continue_rcu(seq_file_net(seq), dev) { + if (!list_empty(&dev->ptype_all)) { + nxt = dev->ptype_all.next; + goto found; + } + } + + nxt = ptype_all.next; + goto ptype_all; + } + if (pt->type == htons(ETH_P_ALL)) { +ptype_all: if (nxt != &ptype_all) goto found; hash = 0;