blob: e52e25a977fa203d82d4d35260584c1b1ef644a9 [file] [log] [blame]
Taku Izumif073c7c2010-12-09 15:17:13 +00001#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/device.h>
4#include <linux/netdevice.h>
5
David S. Miller1ef80192014-11-10 13:27:49 -05006#include <net/bonding.h>
7#include <net/bond_alb.h>
Taku Izumif073c7c2010-12-09 15:17:13 +00008
Eric W. Biederman96ca7ff2012-07-09 10:52:43 +00009#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
Taku Izumif073c7c2010-12-09 15:17:13 +000010
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13
14static struct dentry *bonding_debug_root;
15
Nikolay Aleksandrov547942c2014-09-15 17:19:34 +020016/* Show RLB hash table */
Taku Izumicaafa842010-12-12 19:04:43 +000017static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
18{
19 struct bonding *bond = m->private;
20 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
21 struct rlb_client_info *client_info;
22 u32 hash_index;
23
Veaceslav Falico01844092014-05-15 21:39:55 +020024 if (BOND_MODE(bond) != BOND_MODE_ALB)
Taku Izumicaafa842010-12-12 19:04:43 +000025 return 0;
26
27 seq_printf(m, "SourceIP DestinationIP "
28 "Destination MAC DEV\n");
29
Nikolay Aleksandrov4bab16d2014-09-11 22:49:26 +020030 spin_lock_bh(&bond->mode_lock);
Taku Izumicaafa842010-12-12 19:04:43 +000031
Jiri Bohace53665c2012-11-28 04:42:14 +000032 hash_index = bond_info->rx_hashtbl_used_head;
33 for (; hash_index != RLB_NULL_INDEX;
34 hash_index = client_info->used_next) {
Taku Izumicaafa842010-12-12 19:04:43 +000035 client_info = &(bond_info->rx_hashtbl[hash_index]);
36 seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
37 &client_info->ip_src,
38 &client_info->ip_dst,
39 &client_info->mac_dst,
40 client_info->slave->dev->name);
41 }
42
Nikolay Aleksandrov4bab16d2014-09-11 22:49:26 +020043 spin_unlock_bh(&bond->mode_lock);
Taku Izumicaafa842010-12-12 19:04:43 +000044
45 return 0;
46}
47
48static int bond_debug_rlb_hash_open(struct inode *inode, struct file *file)
49{
50 return single_open(file, bond_debug_rlb_hash_show, inode->i_private);
51}
52
53static const struct file_operations bond_debug_rlb_hash_fops = {
54 .owner = THIS_MODULE,
55 .open = bond_debug_rlb_hash_open,
56 .read = seq_read,
57 .llseek = seq_lseek,
58 .release = single_release,
59};
60
Taku Izumif073c7c2010-12-09 15:17:13 +000061void bond_debug_register(struct bonding *bond)
62{
63 if (!bonding_debug_root)
64 return;
65
66 bond->debug_dir =
67 debugfs_create_dir(bond->dev->name, bonding_debug_root);
68
69 if (!bond->debug_dir) {
Veaceslav Falico9ef1cf12014-07-15 19:36:04 +020070 netdev_warn(bond->dev, "failed to register to debugfs\n");
Taku Izumif073c7c2010-12-09 15:17:13 +000071 return;
72 }
Taku Izumicaafa842010-12-12 19:04:43 +000073
74 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
75 bond, &bond_debug_rlb_hash_fops);
Taku Izumif073c7c2010-12-09 15:17:13 +000076}
77
78void bond_debug_unregister(struct bonding *bond)
79{
80 if (!bonding_debug_root)
81 return;
82
83 debugfs_remove_recursive(bond->debug_dir);
84}
85
86void bond_debug_reregister(struct bonding *bond)
87{
88 struct dentry *d;
89
90 if (!bonding_debug_root)
91 return;
92
93 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
94 bonding_debug_root, bond->dev->name);
95 if (d) {
96 bond->debug_dir = d;
97 } else {
Veaceslav Falico9ef1cf12014-07-15 19:36:04 +020098 netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
Taku Izumif073c7c2010-12-09 15:17:13 +000099 bond_debug_unregister(bond);
100 }
101}
102
103void bond_create_debugfs(void)
104{
105 bonding_debug_root = debugfs_create_dir("bonding", NULL);
106
107 if (!bonding_debug_root) {
Joe Perches91565eb2014-02-15 15:57:04 -0800108 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
Taku Izumif073c7c2010-12-09 15:17:13 +0000109 }
110}
111
112void bond_destroy_debugfs(void)
113{
114 debugfs_remove_recursive(bonding_debug_root);
115 bonding_debug_root = NULL;
116}
117
118
119#else /* !CONFIG_DEBUG_FS */
120
121void bond_debug_register(struct bonding *bond)
122{
123}
124
125void bond_debug_unregister(struct bonding *bond)
126{
127}
128
129void bond_debug_reregister(struct bonding *bond)
130{
131}
132
133void bond_create_debugfs(void)
134{
135}
136
137void bond_destroy_debugfs(void)
138{
139}
140
141#endif /* CONFIG_DEBUG_FS */