diff mbox series

net-procfs: show net devices bound packet types

Message ID 04a03a41-6d44-645e-4935-613de20afb2d@163.com (mailing list archive)
State Superseded
Delegated to: Netdev Maintainers
Headers show
Series net-procfs: show net devices bound packet types | expand

Checks

Context Check Description
netdev/tree_selection success Guessed tree name to be net-next
netdev/fixes_present success Fixes tag not required for -next series
netdev/subject_prefix warning Target tree name not specified in the subject
netdev/cover_letter success Single patches do not need cover letters
netdev/patch_count success Link
netdev/header_inline success No static functions without inline keyword in header files
netdev/build_32bit success Errors and warnings before: 2 this patch: 2
netdev/cc_maintainers warning 4 maintainers not CCed: yajun.deng@linux.dev davem@davemloft.net vladimir.oltean@nxp.com wujianguo@chinatelecom.cn
netdev/build_clang success Errors and warnings before: 22 this patch: 22
netdev/module_param success Was 0 now: 0
netdev/verify_signedoff success Signed-off-by tag matches author and committer
netdev/verify_fixes success No Fixes tag
netdev/build_allmodconfig_warn success Errors and warnings before: 7 this patch: 7
netdev/checkpatch warning WARNING: From:/Signed-off-by: email name mismatch: 'From: wujianguo <wujianguo@chinatelecom.cn>' != 'Signed-off-by: Jianguo Wu <wujianguo@chinatelecom.cn>' WARNING: line length of 82 exceeds 80 columns
netdev/kdoc success Errors and warnings before: 0 this patch: 0
netdev/source_inline success Was 0 now: 0

Commit Message

Jianguo Wu Jan. 20, 2022, 7:04 a.m. UTC
From: wujianguo <wujianguo@chinatelecom.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@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
  0800          ip_rcv
  0806          arp_rcv
  86dd          ipv6_rcv
  [root@localhost ~]# cat /proc/net/dev_ptype
  Type Device      Function
  ALL  ens192   tpacket_rcv

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

Comments

Stephen Hemminger Jan. 20, 2022, 3:58 p.m. UTC | #1
On Thu, 20 Jan 2022 15:04:58 +0800
Jianguo Wu <wujianguo106@163.com> wrote:

> From: wujianguo <wujianguo@chinatelecom.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.

That is an API regression, why not fix that rather than adding new /proc API?

/proc API's are legacy and it would be best not to add more there.
diff mbox series

Patch

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);