* [PATCH] net-procfs: show net devices bound packet types
@ 2022-01-20 7:04 Jianguo Wu
2022-01-20 15:58 ` Stephen Hemminger
0 siblings, 1 reply; 2+ messages in thread
From: Jianguo Wu @ 2022-01-20 7:04 UTC (permalink / raw)
To: netdev; +Cc: shemminger, noureddine, Jakub Kicinski
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(-)
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
^ permalink raw reply related [flat|nested] 2+ messages in thread
* Re: [PATCH] net-procfs: show net devices bound packet types
2022-01-20 7:04 [PATCH] net-procfs: show net devices bound packet types Jianguo Wu
@ 2022-01-20 15:58 ` Stephen Hemminger
0 siblings, 0 replies; 2+ messages in thread
From: Stephen Hemminger @ 2022-01-20 15:58 UTC (permalink / raw)
To: Jianguo Wu; +Cc: netdev, shemminger, noureddine, Jakub Kicinski
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.
^ permalink raw reply [flat|nested] 2+ messages in thread
end of thread, other threads:[~2022-01-20 15:58 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-20 7:04 [PATCH] net-procfs: show net devices bound packet types Jianguo Wu
2022-01-20 15:58 ` Stephen Hemminger
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).