lists.openwall.net   lists  /  announce  owl-users  owl-dev  john-users  john-dev  passwdqc-users  yescrypt  popa3d-users  /  oss-security  kernel-hardening  musl  sabotage  tlsify  passwords  /  crypt-dev  xvendor  /  Bugtraq  Full-Disclosure  linux-kernel  linux-netdev  linux-ext4  linux-hardening  linux-cve-announce  PHC 
Open Source and information security mailing list archives
 
Hash Suite: Windows password security audit tool. GUI, reports in PDF.
[<prev] [next>] [thread-next>] [day] [month] [year] [list]
Message-ID: <04a03a41-6d44-645e-4935-613de20afb2d@163.com>
Date:   Thu, 20 Jan 2022 15:04:58 +0800
From:   Jianguo Wu <wujianguo106@....com>
To:     netdev@...r.kernel.org
Cc:     shemminger@...ux-foundation.org, noureddine@...sta.com,
        Jakub Kicinski <kuba@...nel.org>
Subject: [PATCH] net-procfs: show net devices bound packet types

From: wujianguo <wujianguo@...natelecom.cn>

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.

So and a new net procfs(/proc/net/dev_ptype) to show packet types
that are bound to a specified net device.

Run "tcpdump -i ens192 udp -nns0" Before and after apply this patch:

Before:
  [root@...alhost ~]# cat /proc/net/ptype
  Type Device      Function
  0800          ip_rcv
  0806          arp_rcv
  86dd          ipv6_rcv

After:
  [root@...alhost ~]# cat /proc/net/ptype
  Type Device      Function
  0800          ip_rcv
  0806          arp_rcv
  86dd          ipv6_rcv
  [root@...alhost ~]# cat /proc/net/dev_ptype
  Type Device      Function
  ALL  ens192   tpacket_rcv

Signed-off-by: Jianguo Wu <wujianguo@...natelecom.cn>
---
 net/core/net-procfs.c | 40 +++++++++++++++++++++++++++++++++++++++-
 1 file changed, 39 insertions(+), 1 deletion(-)

diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
index d8b9dbabd4a4..9589e4faa51c 100644
--- a/net/core/net-procfs.c
+++ b/net/core/net-procfs.c
@@ -280,6 +280,37 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
 	.show  = ptype_seq_show,
 };

+static int dev_ptype_seq_show(struct seq_file *seq, void *v)
+{
+	struct net_device *dev = v;
+	struct packet_type *pt = NULL;
+	struct list_head *ptype_list = NULL;
+
+	if (v == SEQ_START_TOKEN) {
+		seq_puts(seq, "Type Device      Function\n");
+	} else {
+		ptype_list = &dev->ptype_all;
+		list_for_each_entry_rcu(pt, ptype_list, list) {
+			if (pt->type == htons(ETH_P_ALL))
+				seq_puts(seq, "ALL ");
+			else
+				seq_printf(seq, "%04x", ntohs(pt->type));
+
+			seq_printf(seq, " %-8s %ps\n",
+				   pt->dev ? pt->dev->name : "", pt->func);
+		}
+	}
+
+	return 0;
+}
+
+static const struct seq_operations dev_ptype_seq_ops = {
+	.start = dev_seq_start,
+	.next  = dev_seq_next,
+	.stop  = dev_seq_stop,
+	.show  = dev_ptype_seq_show,
+};
+
 static int __net_init dev_proc_net_init(struct net *net)
 {
 	int rc = -ENOMEM;
@@ -294,11 +325,17 @@ static int __net_init dev_proc_net_init(struct net *net)
 			sizeof(struct seq_net_private)))
 		goto out_softnet;

-	if (wext_proc_init(net))
+	if (!proc_create_net("dev_ptype", 0444, net->proc_net, &dev_ptype_seq_ops,
+			     sizeof(struct seq_net_private)))
 		goto out_ptype;
+
+	if (wext_proc_init(net))
+		goto out_dev_ptype;
 	rc = 0;
 out:
 	return rc;
+out_dev_ptype:
+	remove_proc_entry("dev_ptype", net->proc_net);
 out_ptype:
 	remove_proc_entry("ptype", net->proc_net);
 out_softnet:
@@ -312,6 +349,7 @@ static void __net_exit dev_proc_net_exit(struct net *net)
 {
 	wext_proc_exit(net);

+	remove_proc_entry("dev_ptype", net->proc_net);
 	remove_proc_entry("ptype", net->proc_net);
 	remove_proc_entry("softnet_stat", net->proc_net);
 	remove_proc_entry("dev", net->proc_net);
-- 
1.8.3.1

Powered by blists - more mailing lists

Powered by Openwall GNU/*/Linux Powered by OpenVZ