Skip to content

Commit 1d10f8a

Browse files
Jianguo Wudavem330
authored andcommitted
net-procfs: show net devices bound packet types
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: 7866a62 ("dev: add per net_device packet type chains") Signed-off-by: Jianguo Wu <[email protected]> Signed-off-by: David S. Miller <[email protected]>
1 parent aa60346 commit 1d10f8a

File tree

1 file changed

+32
-3
lines changed

1 file changed

+32
-3
lines changed

net/core/net-procfs.c

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -190,12 +190,23 @@ static const struct seq_operations softnet_seq_ops = {
190190
.show = softnet_seq_show,
191191
};
192192

193-
static void *ptype_get_idx(loff_t pos)
193+
static void *ptype_get_idx(struct seq_file *seq, loff_t pos)
194194
{
195+
struct list_head *ptype_list = NULL;
195196
struct packet_type *pt = NULL;
197+
struct net_device *dev;
196198
loff_t i = 0;
197199
int t;
198200

201+
for_each_netdev_rcu(seq_file_net(seq), dev) {
202+
ptype_list = &dev->ptype_all;
203+
list_for_each_entry_rcu(pt, ptype_list, list) {
204+
if (i == pos)
205+
return pt;
206+
++i;
207+
}
208+
}
209+
199210
list_for_each_entry_rcu(pt, &ptype_all, list) {
200211
if (i == pos)
201212
return pt;
@@ -216,22 +227,40 @@ static void *ptype_seq_start(struct seq_file *seq, loff_t *pos)
216227
__acquires(RCU)
217228
{
218229
rcu_read_lock();
219-
return *pos ? ptype_get_idx(*pos - 1) : SEQ_START_TOKEN;
230+
return *pos ? ptype_get_idx(seq, *pos - 1) : SEQ_START_TOKEN;
220231
}
221232

222233
static void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos)
223234
{
235+
struct net_device *dev;
224236
struct packet_type *pt;
225237
struct list_head *nxt;
226238
int hash;
227239

228240
++*pos;
229241
if (v == SEQ_START_TOKEN)
230-
return ptype_get_idx(0);
242+
return ptype_get_idx(seq, 0);
231243

232244
pt = v;
233245
nxt = pt->list.next;
246+
if (pt->dev) {
247+
if (nxt != &pt->dev->ptype_all)
248+
goto found;
249+
250+
dev = pt->dev;
251+
for_each_netdev_continue_rcu(seq_file_net(seq), dev) {
252+
if (!list_empty(&dev->ptype_all)) {
253+
nxt = dev->ptype_all.next;
254+
goto found;
255+
}
256+
}
257+
258+
nxt = ptype_all.next;
259+
goto ptype_all;
260+
}
261+
234262
if (pt->type == htons(ETH_P_ALL)) {
263+
ptype_all:
235264
if (nxt != &ptype_all)
236265
goto found;
237266
hash = 0;

0 commit comments

Comments
 (0)