|
6 | 6 |
|
7 | 7 | #include "dev.h"
|
8 | 8 |
|
9 |
| -#define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1) |
10 |
| - |
11 |
| -#define get_bucket(x) ((x) >> BUCKET_SPACE) |
12 |
| -#define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1)) |
13 |
| -#define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o)) |
14 |
| - |
15 |
| -static inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff_t *pos) |
| 9 | +static void *dev_seq_from_index(struct seq_file *seq, loff_t *pos) |
16 | 10 | {
|
17 |
| - struct net *net = seq_file_net(seq); |
| 11 | + unsigned long ifindex = *pos; |
18 | 12 | struct net_device *dev;
|
19 |
| - struct hlist_head *h; |
20 |
| - unsigned int count = 0, offset = get_offset(*pos); |
21 | 13 |
|
22 |
| - h = &net->dev_index_head[get_bucket(*pos)]; |
23 |
| - hlist_for_each_entry_rcu(dev, h, index_hlist) { |
24 |
| - if (++count == offset) |
25 |
| - return dev; |
| 14 | + for_each_netdev_dump(seq_file_net(seq), dev, ifindex) { |
| 15 | + *pos = dev->ifindex; |
| 16 | + return dev; |
26 | 17 | }
|
27 |
| - |
28 |
| - return NULL; |
29 |
| -} |
30 |
| - |
31 |
| -static inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *pos) |
32 |
| -{ |
33 |
| - struct net_device *dev; |
34 |
| - unsigned int bucket; |
35 |
| - |
36 |
| - do { |
37 |
| - dev = dev_from_same_bucket(seq, pos); |
38 |
| - if (dev) |
39 |
| - return dev; |
40 |
| - |
41 |
| - bucket = get_bucket(*pos) + 1; |
42 |
| - *pos = set_bucket_offset(bucket, 1); |
43 |
| - } while (bucket < NETDEV_HASHENTRIES); |
44 |
| - |
45 | 18 | return NULL;
|
46 | 19 | }
|
47 | 20 |
|
48 |
| -/* |
49 |
| - * This is invoked by the /proc filesystem handler to display a device |
50 |
| - * in detail. |
51 |
| - */ |
52 | 21 | static void *dev_seq_start(struct seq_file *seq, loff_t *pos)
|
53 | 22 | __acquires(RCU)
|
54 | 23 | {
|
55 | 24 | rcu_read_lock();
|
56 | 25 | if (!*pos)
|
57 | 26 | return SEQ_START_TOKEN;
|
58 | 27 |
|
59 |
| - if (get_bucket(*pos) >= NETDEV_HASHENTRIES) |
60 |
| - return NULL; |
61 |
| - |
62 |
| - return dev_from_bucket(seq, pos); |
| 28 | + return dev_seq_from_index(seq, pos); |
63 | 29 | }
|
64 | 30 |
|
65 | 31 | static void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos)
|
66 | 32 | {
|
67 | 33 | ++*pos;
|
68 |
| - return dev_from_bucket(seq, pos); |
| 34 | + return dev_seq_from_index(seq, pos); |
69 | 35 | }
|
70 | 36 |
|
71 | 37 | static void dev_seq_stop(struct seq_file *seq, void *v)
|
|
0 commit comments