18c2ecf20Sopenharmony_ci// SPDX-License-Identifier: GPL-2.0 28c2ecf20Sopenharmony_ci#include <linux/netdevice.h> 38c2ecf20Sopenharmony_ci#include <linux/proc_fs.h> 48c2ecf20Sopenharmony_ci#include <linux/seq_file.h> 58c2ecf20Sopenharmony_ci#include <net/wext.h> 68c2ecf20Sopenharmony_ci 78c2ecf20Sopenharmony_ci#define BUCKET_SPACE (32 - NETDEV_HASHBITS - 1) 88c2ecf20Sopenharmony_ci 98c2ecf20Sopenharmony_ci#define get_bucket(x) ((x) >> BUCKET_SPACE) 108c2ecf20Sopenharmony_ci#define get_offset(x) ((x) & ((1 << BUCKET_SPACE) - 1)) 118c2ecf20Sopenharmony_ci#define set_bucket_offset(b, o) ((b) << BUCKET_SPACE | (o)) 128c2ecf20Sopenharmony_ci 138c2ecf20Sopenharmony_ciextern struct list_head ptype_all __read_mostly; 148c2ecf20Sopenharmony_ciextern struct list_head ptype_base[PTYPE_HASH_SIZE] __read_mostly; 158c2ecf20Sopenharmony_ci 168c2ecf20Sopenharmony_cistatic inline struct net_device *dev_from_same_bucket(struct seq_file *seq, loff_t *pos) 178c2ecf20Sopenharmony_ci{ 188c2ecf20Sopenharmony_ci struct net *net = seq_file_net(seq); 198c2ecf20Sopenharmony_ci struct net_device *dev; 208c2ecf20Sopenharmony_ci struct hlist_head *h; 218c2ecf20Sopenharmony_ci unsigned int count = 0, offset = get_offset(*pos); 228c2ecf20Sopenharmony_ci 238c2ecf20Sopenharmony_ci h = &net->dev_index_head[get_bucket(*pos)]; 248c2ecf20Sopenharmony_ci hlist_for_each_entry_rcu(dev, h, index_hlist) { 258c2ecf20Sopenharmony_ci if (++count == offset) 268c2ecf20Sopenharmony_ci return dev; 278c2ecf20Sopenharmony_ci } 288c2ecf20Sopenharmony_ci 298c2ecf20Sopenharmony_ci return NULL; 308c2ecf20Sopenharmony_ci} 318c2ecf20Sopenharmony_ci 328c2ecf20Sopenharmony_cistatic inline struct net_device *dev_from_bucket(struct seq_file *seq, loff_t *pos) 338c2ecf20Sopenharmony_ci{ 348c2ecf20Sopenharmony_ci struct net_device *dev; 358c2ecf20Sopenharmony_ci unsigned int bucket; 368c2ecf20Sopenharmony_ci 378c2ecf20Sopenharmony_ci do { 388c2ecf20Sopenharmony_ci dev = dev_from_same_bucket(seq, pos); 398c2ecf20Sopenharmony_ci if (dev) 408c2ecf20Sopenharmony_ci return dev; 418c2ecf20Sopenharmony_ci 428c2ecf20Sopenharmony_ci bucket = get_bucket(*pos) + 1; 438c2ecf20Sopenharmony_ci *pos = set_bucket_offset(bucket, 1); 448c2ecf20Sopenharmony_ci } while (bucket < NETDEV_HASHENTRIES); 458c2ecf20Sopenharmony_ci 468c2ecf20Sopenharmony_ci return NULL; 478c2ecf20Sopenharmony_ci} 488c2ecf20Sopenharmony_ci 498c2ecf20Sopenharmony_ci/* 508c2ecf20Sopenharmony_ci * This is invoked by the /proc filesystem handler to display a device 518c2ecf20Sopenharmony_ci * in detail. 528c2ecf20Sopenharmony_ci */ 538c2ecf20Sopenharmony_cistatic void *dev_seq_start(struct seq_file *seq, loff_t *pos) 548c2ecf20Sopenharmony_ci __acquires(RCU) 558c2ecf20Sopenharmony_ci{ 568c2ecf20Sopenharmony_ci rcu_read_lock(); 578c2ecf20Sopenharmony_ci if (!*pos) 588c2ecf20Sopenharmony_ci return SEQ_START_TOKEN; 598c2ecf20Sopenharmony_ci 608c2ecf20Sopenharmony_ci if (get_bucket(*pos) >= NETDEV_HASHENTRIES) 618c2ecf20Sopenharmony_ci return NULL; 628c2ecf20Sopenharmony_ci 638c2ecf20Sopenharmony_ci return dev_from_bucket(seq, pos); 648c2ecf20Sopenharmony_ci} 658c2ecf20Sopenharmony_ci 668c2ecf20Sopenharmony_cistatic void *dev_seq_next(struct seq_file *seq, void *v, loff_t *pos) 678c2ecf20Sopenharmony_ci{ 688c2ecf20Sopenharmony_ci ++*pos; 698c2ecf20Sopenharmony_ci return dev_from_bucket(seq, pos); 708c2ecf20Sopenharmony_ci} 718c2ecf20Sopenharmony_ci 728c2ecf20Sopenharmony_cistatic void dev_seq_stop(struct seq_file *seq, void *v) 738c2ecf20Sopenharmony_ci __releases(RCU) 748c2ecf20Sopenharmony_ci{ 758c2ecf20Sopenharmony_ci rcu_read_unlock(); 768c2ecf20Sopenharmony_ci} 778c2ecf20Sopenharmony_ci 788c2ecf20Sopenharmony_cistatic void dev_seq_printf_stats(struct seq_file *seq, struct net_device *dev) 798c2ecf20Sopenharmony_ci{ 808c2ecf20Sopenharmony_ci struct rtnl_link_stats64 temp; 818c2ecf20Sopenharmony_ci const struct rtnl_link_stats64 *stats = dev_get_stats(dev, &temp); 828c2ecf20Sopenharmony_ci 838c2ecf20Sopenharmony_ci seq_printf(seq, "%6s: %7llu %7llu %4llu %4llu %4llu %5llu %10llu %9llu " 848c2ecf20Sopenharmony_ci "%8llu %7llu %4llu %4llu %4llu %5llu %7llu %10llu\n", 858c2ecf20Sopenharmony_ci dev->name, stats->rx_bytes, stats->rx_packets, 868c2ecf20Sopenharmony_ci stats->rx_errors, 878c2ecf20Sopenharmony_ci stats->rx_dropped + stats->rx_missed_errors, 888c2ecf20Sopenharmony_ci stats->rx_fifo_errors, 898c2ecf20Sopenharmony_ci stats->rx_length_errors + stats->rx_over_errors + 908c2ecf20Sopenharmony_ci stats->rx_crc_errors + stats->rx_frame_errors, 918c2ecf20Sopenharmony_ci stats->rx_compressed, stats->multicast, 928c2ecf20Sopenharmony_ci stats->tx_bytes, stats->tx_packets, 938c2ecf20Sopenharmony_ci stats->tx_errors, stats->tx_dropped, 948c2ecf20Sopenharmony_ci stats->tx_fifo_errors, stats->collisions, 958c2ecf20Sopenharmony_ci stats->tx_carrier_errors + 968c2ecf20Sopenharmony_ci stats->tx_aborted_errors + 978c2ecf20Sopenharmony_ci stats->tx_window_errors + 988c2ecf20Sopenharmony_ci stats->tx_heartbeat_errors, 998c2ecf20Sopenharmony_ci stats->tx_compressed); 1008c2ecf20Sopenharmony_ci} 1018c2ecf20Sopenharmony_ci 1028c2ecf20Sopenharmony_ci/* 1038c2ecf20Sopenharmony_ci * Called from the PROCfs module. This now uses the new arbitrary sized 1048c2ecf20Sopenharmony_ci * /proc/net interface to create /proc/net/dev 1058c2ecf20Sopenharmony_ci */ 1068c2ecf20Sopenharmony_cistatic int dev_seq_show(struct seq_file *seq, void *v) 1078c2ecf20Sopenharmony_ci{ 1088c2ecf20Sopenharmony_ci if (v == SEQ_START_TOKEN) 1098c2ecf20Sopenharmony_ci seq_puts(seq, "Inter-| Receive " 1108c2ecf20Sopenharmony_ci " | Transmit\n" 1118c2ecf20Sopenharmony_ci " face |bytes packets errs drop fifo frame " 1128c2ecf20Sopenharmony_ci "compressed multicast|bytes packets errs " 1138c2ecf20Sopenharmony_ci "drop fifo colls carrier compressed\n"); 1148c2ecf20Sopenharmony_ci else 1158c2ecf20Sopenharmony_ci dev_seq_printf_stats(seq, v); 1168c2ecf20Sopenharmony_ci return 0; 1178c2ecf20Sopenharmony_ci} 1188c2ecf20Sopenharmony_ci 1198c2ecf20Sopenharmony_cistatic u32 softnet_backlog_len(struct softnet_data *sd) 1208c2ecf20Sopenharmony_ci{ 1218c2ecf20Sopenharmony_ci return skb_queue_len_lockless(&sd->input_pkt_queue) + 1228c2ecf20Sopenharmony_ci skb_queue_len_lockless(&sd->process_queue); 1238c2ecf20Sopenharmony_ci} 1248c2ecf20Sopenharmony_ci 1258c2ecf20Sopenharmony_cistatic struct softnet_data *softnet_get_online(loff_t *pos) 1268c2ecf20Sopenharmony_ci{ 1278c2ecf20Sopenharmony_ci struct softnet_data *sd = NULL; 1288c2ecf20Sopenharmony_ci 1298c2ecf20Sopenharmony_ci while (*pos < nr_cpu_ids) 1308c2ecf20Sopenharmony_ci if (cpu_online(*pos)) { 1318c2ecf20Sopenharmony_ci sd = &per_cpu(softnet_data, *pos); 1328c2ecf20Sopenharmony_ci break; 1338c2ecf20Sopenharmony_ci } else 1348c2ecf20Sopenharmony_ci ++*pos; 1358c2ecf20Sopenharmony_ci return sd; 1368c2ecf20Sopenharmony_ci} 1378c2ecf20Sopenharmony_ci 1388c2ecf20Sopenharmony_cistatic void *softnet_seq_start(struct seq_file *seq, loff_t *pos) 1398c2ecf20Sopenharmony_ci{ 1408c2ecf20Sopenharmony_ci return softnet_get_online(pos); 1418c2ecf20Sopenharmony_ci} 1428c2ecf20Sopenharmony_ci 1438c2ecf20Sopenharmony_cistatic void *softnet_seq_next(struct seq_file *seq, void *v, loff_t *pos) 1448c2ecf20Sopenharmony_ci{ 1458c2ecf20Sopenharmony_ci ++*pos; 1468c2ecf20Sopenharmony_ci return softnet_get_online(pos); 1478c2ecf20Sopenharmony_ci} 1488c2ecf20Sopenharmony_ci 1498c2ecf20Sopenharmony_cistatic void softnet_seq_stop(struct seq_file *seq, void *v) 1508c2ecf20Sopenharmony_ci{ 1518c2ecf20Sopenharmony_ci} 1528c2ecf20Sopenharmony_ci 1538c2ecf20Sopenharmony_cistatic int softnet_seq_show(struct seq_file *seq, void *v) 1548c2ecf20Sopenharmony_ci{ 1558c2ecf20Sopenharmony_ci struct softnet_data *sd = v; 1568c2ecf20Sopenharmony_ci unsigned int flow_limit_count = 0; 1578c2ecf20Sopenharmony_ci 1588c2ecf20Sopenharmony_ci#ifdef CONFIG_NET_FLOW_LIMIT 1598c2ecf20Sopenharmony_ci struct sd_flow_limit *fl; 1608c2ecf20Sopenharmony_ci 1618c2ecf20Sopenharmony_ci rcu_read_lock(); 1628c2ecf20Sopenharmony_ci fl = rcu_dereference(sd->flow_limit); 1638c2ecf20Sopenharmony_ci if (fl) 1648c2ecf20Sopenharmony_ci flow_limit_count = fl->count; 1658c2ecf20Sopenharmony_ci rcu_read_unlock(); 1668c2ecf20Sopenharmony_ci#endif 1678c2ecf20Sopenharmony_ci 1688c2ecf20Sopenharmony_ci /* the index is the CPU id owing this sd. Since offline CPUs are not 1698c2ecf20Sopenharmony_ci * displayed, it would be othrwise not trivial for the user-space 1708c2ecf20Sopenharmony_ci * mapping the data a specific CPU 1718c2ecf20Sopenharmony_ci */ 1728c2ecf20Sopenharmony_ci seq_printf(seq, 1738c2ecf20Sopenharmony_ci "%08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x %08x\n", 1748c2ecf20Sopenharmony_ci sd->processed, sd->dropped, sd->time_squeeze, 0, 1758c2ecf20Sopenharmony_ci 0, 0, 0, 0, /* was fastroute */ 1768c2ecf20Sopenharmony_ci 0, /* was cpu_collision */ 1778c2ecf20Sopenharmony_ci sd->received_rps, flow_limit_count, 1788c2ecf20Sopenharmony_ci softnet_backlog_len(sd), (int)seq->index); 1798c2ecf20Sopenharmony_ci return 0; 1808c2ecf20Sopenharmony_ci} 1818c2ecf20Sopenharmony_ci 1828c2ecf20Sopenharmony_cistatic const struct seq_operations dev_seq_ops = { 1838c2ecf20Sopenharmony_ci .start = dev_seq_start, 1848c2ecf20Sopenharmony_ci .next = dev_seq_next, 1858c2ecf20Sopenharmony_ci .stop = dev_seq_stop, 1868c2ecf20Sopenharmony_ci .show = dev_seq_show, 1878c2ecf20Sopenharmony_ci}; 1888c2ecf20Sopenharmony_ci 1898c2ecf20Sopenharmony_cistatic const struct seq_operations softnet_seq_ops = { 1908c2ecf20Sopenharmony_ci .start = softnet_seq_start, 1918c2ecf20Sopenharmony_ci .next = softnet_seq_next, 1928c2ecf20Sopenharmony_ci .stop = softnet_seq_stop, 1938c2ecf20Sopenharmony_ci .show = softnet_seq_show, 1948c2ecf20Sopenharmony_ci}; 1958c2ecf20Sopenharmony_ci 1968c2ecf20Sopenharmony_cistatic void *ptype_get_idx(struct seq_file *seq, loff_t pos) 1978c2ecf20Sopenharmony_ci{ 1988c2ecf20Sopenharmony_ci struct list_head *ptype_list = NULL; 1998c2ecf20Sopenharmony_ci struct packet_type *pt = NULL; 2008c2ecf20Sopenharmony_ci struct net_device *dev; 2018c2ecf20Sopenharmony_ci loff_t i = 0; 2028c2ecf20Sopenharmony_ci int t; 2038c2ecf20Sopenharmony_ci 2048c2ecf20Sopenharmony_ci for_each_netdev_rcu(seq_file_net(seq), dev) { 2058c2ecf20Sopenharmony_ci ptype_list = &dev->ptype_all; 2068c2ecf20Sopenharmony_ci list_for_each_entry_rcu(pt, ptype_list, list) { 2078c2ecf20Sopenharmony_ci if (i == pos) 2088c2ecf20Sopenharmony_ci return pt; 2098c2ecf20Sopenharmony_ci ++i; 2108c2ecf20Sopenharmony_ci } 2118c2ecf20Sopenharmony_ci } 2128c2ecf20Sopenharmony_ci 2138c2ecf20Sopenharmony_ci list_for_each_entry_rcu(pt, &ptype_all, list) { 2148c2ecf20Sopenharmony_ci if (i == pos) 2158c2ecf20Sopenharmony_ci return pt; 2168c2ecf20Sopenharmony_ci ++i; 2178c2ecf20Sopenharmony_ci } 2188c2ecf20Sopenharmony_ci 2198c2ecf20Sopenharmony_ci for (t = 0; t < PTYPE_HASH_SIZE; t++) { 2208c2ecf20Sopenharmony_ci list_for_each_entry_rcu(pt, &ptype_base[t], list) { 2218c2ecf20Sopenharmony_ci if (i == pos) 2228c2ecf20Sopenharmony_ci return pt; 2238c2ecf20Sopenharmony_ci ++i; 2248c2ecf20Sopenharmony_ci } 2258c2ecf20Sopenharmony_ci } 2268c2ecf20Sopenharmony_ci return NULL; 2278c2ecf20Sopenharmony_ci} 2288c2ecf20Sopenharmony_ci 2298c2ecf20Sopenharmony_cistatic void *ptype_seq_start(struct seq_file *seq, loff_t *pos) 2308c2ecf20Sopenharmony_ci __acquires(RCU) 2318c2ecf20Sopenharmony_ci{ 2328c2ecf20Sopenharmony_ci rcu_read_lock(); 2338c2ecf20Sopenharmony_ci return *pos ? ptype_get_idx(seq, *pos - 1) : SEQ_START_TOKEN; 2348c2ecf20Sopenharmony_ci} 2358c2ecf20Sopenharmony_ci 2368c2ecf20Sopenharmony_cistatic void *ptype_seq_next(struct seq_file *seq, void *v, loff_t *pos) 2378c2ecf20Sopenharmony_ci{ 2388c2ecf20Sopenharmony_ci struct net_device *dev; 2398c2ecf20Sopenharmony_ci struct packet_type *pt; 2408c2ecf20Sopenharmony_ci struct list_head *nxt; 2418c2ecf20Sopenharmony_ci int hash; 2428c2ecf20Sopenharmony_ci 2438c2ecf20Sopenharmony_ci ++*pos; 2448c2ecf20Sopenharmony_ci if (v == SEQ_START_TOKEN) 2458c2ecf20Sopenharmony_ci return ptype_get_idx(seq, 0); 2468c2ecf20Sopenharmony_ci 2478c2ecf20Sopenharmony_ci pt = v; 2488c2ecf20Sopenharmony_ci nxt = pt->list.next; 2498c2ecf20Sopenharmony_ci if (pt->dev) { 2508c2ecf20Sopenharmony_ci if (nxt != &pt->dev->ptype_all) 2518c2ecf20Sopenharmony_ci goto found; 2528c2ecf20Sopenharmony_ci 2538c2ecf20Sopenharmony_ci dev = pt->dev; 2548c2ecf20Sopenharmony_ci for_each_netdev_continue_rcu(seq_file_net(seq), dev) { 2558c2ecf20Sopenharmony_ci if (!list_empty(&dev->ptype_all)) { 2568c2ecf20Sopenharmony_ci nxt = dev->ptype_all.next; 2578c2ecf20Sopenharmony_ci goto found; 2588c2ecf20Sopenharmony_ci } 2598c2ecf20Sopenharmony_ci } 2608c2ecf20Sopenharmony_ci 2618c2ecf20Sopenharmony_ci nxt = ptype_all.next; 2628c2ecf20Sopenharmony_ci goto ptype_all; 2638c2ecf20Sopenharmony_ci } 2648c2ecf20Sopenharmony_ci 2658c2ecf20Sopenharmony_ci if (pt->type == htons(ETH_P_ALL)) { 2668c2ecf20Sopenharmony_ciptype_all: 2678c2ecf20Sopenharmony_ci if (nxt != &ptype_all) 2688c2ecf20Sopenharmony_ci goto found; 2698c2ecf20Sopenharmony_ci hash = 0; 2708c2ecf20Sopenharmony_ci nxt = ptype_base[0].next; 2718c2ecf20Sopenharmony_ci } else 2728c2ecf20Sopenharmony_ci hash = ntohs(pt->type) & PTYPE_HASH_MASK; 2738c2ecf20Sopenharmony_ci 2748c2ecf20Sopenharmony_ci while (nxt == &ptype_base[hash]) { 2758c2ecf20Sopenharmony_ci if (++hash >= PTYPE_HASH_SIZE) 2768c2ecf20Sopenharmony_ci return NULL; 2778c2ecf20Sopenharmony_ci nxt = ptype_base[hash].next; 2788c2ecf20Sopenharmony_ci } 2798c2ecf20Sopenharmony_cifound: 2808c2ecf20Sopenharmony_ci return list_entry(nxt, struct packet_type, list); 2818c2ecf20Sopenharmony_ci} 2828c2ecf20Sopenharmony_ci 2838c2ecf20Sopenharmony_cistatic void ptype_seq_stop(struct seq_file *seq, void *v) 2848c2ecf20Sopenharmony_ci __releases(RCU) 2858c2ecf20Sopenharmony_ci{ 2868c2ecf20Sopenharmony_ci rcu_read_unlock(); 2878c2ecf20Sopenharmony_ci} 2888c2ecf20Sopenharmony_ci 2898c2ecf20Sopenharmony_cistatic int ptype_seq_show(struct seq_file *seq, void *v) 2908c2ecf20Sopenharmony_ci{ 2918c2ecf20Sopenharmony_ci struct packet_type *pt = v; 2928c2ecf20Sopenharmony_ci 2938c2ecf20Sopenharmony_ci if (v == SEQ_START_TOKEN) 2948c2ecf20Sopenharmony_ci seq_puts(seq, "Type Device Function\n"); 2958c2ecf20Sopenharmony_ci else if ((!pt->af_packet_net || net_eq(pt->af_packet_net, seq_file_net(seq))) && 2968c2ecf20Sopenharmony_ci (!pt->dev || net_eq(dev_net(pt->dev), seq_file_net(seq)))) { 2978c2ecf20Sopenharmony_ci if (pt->type == htons(ETH_P_ALL)) 2988c2ecf20Sopenharmony_ci seq_puts(seq, "ALL "); 2998c2ecf20Sopenharmony_ci else 3008c2ecf20Sopenharmony_ci seq_printf(seq, "%04x", ntohs(pt->type)); 3018c2ecf20Sopenharmony_ci 3028c2ecf20Sopenharmony_ci seq_printf(seq, " %-8s %ps\n", 3038c2ecf20Sopenharmony_ci pt->dev ? pt->dev->name : "", pt->func); 3048c2ecf20Sopenharmony_ci } 3058c2ecf20Sopenharmony_ci 3068c2ecf20Sopenharmony_ci return 0; 3078c2ecf20Sopenharmony_ci} 3088c2ecf20Sopenharmony_ci 3098c2ecf20Sopenharmony_cistatic const struct seq_operations ptype_seq_ops = { 3108c2ecf20Sopenharmony_ci .start = ptype_seq_start, 3118c2ecf20Sopenharmony_ci .next = ptype_seq_next, 3128c2ecf20Sopenharmony_ci .stop = ptype_seq_stop, 3138c2ecf20Sopenharmony_ci .show = ptype_seq_show, 3148c2ecf20Sopenharmony_ci}; 3158c2ecf20Sopenharmony_ci 3168c2ecf20Sopenharmony_cistatic int __net_init dev_proc_net_init(struct net *net) 3178c2ecf20Sopenharmony_ci{ 3188c2ecf20Sopenharmony_ci int rc = -ENOMEM; 3198c2ecf20Sopenharmony_ci 3208c2ecf20Sopenharmony_ci if (!proc_create_net("dev", 0444, net->proc_net, &dev_seq_ops, 3218c2ecf20Sopenharmony_ci sizeof(struct seq_net_private))) 3228c2ecf20Sopenharmony_ci goto out; 3238c2ecf20Sopenharmony_ci if (!proc_create_seq("softnet_stat", 0444, net->proc_net, 3248c2ecf20Sopenharmony_ci &softnet_seq_ops)) 3258c2ecf20Sopenharmony_ci goto out_dev; 3268c2ecf20Sopenharmony_ci if (!proc_create_net("ptype", 0444, net->proc_net, &ptype_seq_ops, 3278c2ecf20Sopenharmony_ci sizeof(struct seq_net_private))) 3288c2ecf20Sopenharmony_ci goto out_softnet; 3298c2ecf20Sopenharmony_ci 3308c2ecf20Sopenharmony_ci if (wext_proc_init(net)) 3318c2ecf20Sopenharmony_ci goto out_ptype; 3328c2ecf20Sopenharmony_ci rc = 0; 3338c2ecf20Sopenharmony_ciout: 3348c2ecf20Sopenharmony_ci return rc; 3358c2ecf20Sopenharmony_ciout_ptype: 3368c2ecf20Sopenharmony_ci remove_proc_entry("ptype", net->proc_net); 3378c2ecf20Sopenharmony_ciout_softnet: 3388c2ecf20Sopenharmony_ci remove_proc_entry("softnet_stat", net->proc_net); 3398c2ecf20Sopenharmony_ciout_dev: 3408c2ecf20Sopenharmony_ci remove_proc_entry("dev", net->proc_net); 3418c2ecf20Sopenharmony_ci goto out; 3428c2ecf20Sopenharmony_ci} 3438c2ecf20Sopenharmony_ci 3448c2ecf20Sopenharmony_cistatic void __net_exit dev_proc_net_exit(struct net *net) 3458c2ecf20Sopenharmony_ci{ 3468c2ecf20Sopenharmony_ci wext_proc_exit(net); 3478c2ecf20Sopenharmony_ci 3488c2ecf20Sopenharmony_ci remove_proc_entry("ptype", net->proc_net); 3498c2ecf20Sopenharmony_ci remove_proc_entry("softnet_stat", net->proc_net); 3508c2ecf20Sopenharmony_ci remove_proc_entry("dev", net->proc_net); 3518c2ecf20Sopenharmony_ci} 3528c2ecf20Sopenharmony_ci 3538c2ecf20Sopenharmony_cistatic struct pernet_operations __net_initdata dev_proc_ops = { 3548c2ecf20Sopenharmony_ci .init = dev_proc_net_init, 3558c2ecf20Sopenharmony_ci .exit = dev_proc_net_exit, 3568c2ecf20Sopenharmony_ci}; 3578c2ecf20Sopenharmony_ci 3588c2ecf20Sopenharmony_cistatic int dev_mc_seq_show(struct seq_file *seq, void *v) 3598c2ecf20Sopenharmony_ci{ 3608c2ecf20Sopenharmony_ci struct netdev_hw_addr *ha; 3618c2ecf20Sopenharmony_ci struct net_device *dev = v; 3628c2ecf20Sopenharmony_ci 3638c2ecf20Sopenharmony_ci if (v == SEQ_START_TOKEN) 3648c2ecf20Sopenharmony_ci return 0; 3658c2ecf20Sopenharmony_ci 3668c2ecf20Sopenharmony_ci netif_addr_lock_bh(dev); 3678c2ecf20Sopenharmony_ci netdev_for_each_mc_addr(ha, dev) { 3688c2ecf20Sopenharmony_ci seq_printf(seq, "%-4d %-15s %-5d %-5d %*phN\n", 3698c2ecf20Sopenharmony_ci dev->ifindex, dev->name, 3708c2ecf20Sopenharmony_ci ha->refcount, ha->global_use, 3718c2ecf20Sopenharmony_ci (int)dev->addr_len, ha->addr); 3728c2ecf20Sopenharmony_ci } 3738c2ecf20Sopenharmony_ci netif_addr_unlock_bh(dev); 3748c2ecf20Sopenharmony_ci return 0; 3758c2ecf20Sopenharmony_ci} 3768c2ecf20Sopenharmony_ci 3778c2ecf20Sopenharmony_cistatic const struct seq_operations dev_mc_seq_ops = { 3788c2ecf20Sopenharmony_ci .start = dev_seq_start, 3798c2ecf20Sopenharmony_ci .next = dev_seq_next, 3808c2ecf20Sopenharmony_ci .stop = dev_seq_stop, 3818c2ecf20Sopenharmony_ci .show = dev_mc_seq_show, 3828c2ecf20Sopenharmony_ci}; 3838c2ecf20Sopenharmony_ci 3848c2ecf20Sopenharmony_cistatic int __net_init dev_mc_net_init(struct net *net) 3858c2ecf20Sopenharmony_ci{ 3868c2ecf20Sopenharmony_ci if (!proc_create_net("dev_mcast", 0, net->proc_net, &dev_mc_seq_ops, 3878c2ecf20Sopenharmony_ci sizeof(struct seq_net_private))) 3888c2ecf20Sopenharmony_ci return -ENOMEM; 3898c2ecf20Sopenharmony_ci return 0; 3908c2ecf20Sopenharmony_ci} 3918c2ecf20Sopenharmony_ci 3928c2ecf20Sopenharmony_cistatic void __net_exit dev_mc_net_exit(struct net *net) 3938c2ecf20Sopenharmony_ci{ 3948c2ecf20Sopenharmony_ci remove_proc_entry("dev_mcast", net->proc_net); 3958c2ecf20Sopenharmony_ci} 3968c2ecf20Sopenharmony_ci 3978c2ecf20Sopenharmony_cistatic struct pernet_operations __net_initdata dev_mc_net_ops = { 3988c2ecf20Sopenharmony_ci .init = dev_mc_net_init, 3998c2ecf20Sopenharmony_ci .exit = dev_mc_net_exit, 4008c2ecf20Sopenharmony_ci}; 4018c2ecf20Sopenharmony_ci 4028c2ecf20Sopenharmony_ciint __init dev_proc_init(void) 4038c2ecf20Sopenharmony_ci{ 4048c2ecf20Sopenharmony_ci int ret = register_pernet_subsys(&dev_proc_ops); 4058c2ecf20Sopenharmony_ci if (!ret) 4068c2ecf20Sopenharmony_ci return register_pernet_subsys(&dev_mc_net_ops); 4078c2ecf20Sopenharmony_ci return ret; 4088c2ecf20Sopenharmony_ci} 409