1
2#include <linux/kernel.h>
3#include <linux/module.h>
4#include <linux/device.h>
5#include <linux/netdevice.h>
6
7#include <net/bonding.h>
8#include <net/bond_alb.h>
9
10#if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
11
12#include <linux/debugfs.h>
13#include <linux/seq_file.h>
14
15static struct dentry *bonding_debug_root;
16
17
18static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
19{
20 struct bonding *bond = m->private;
21 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
22 struct rlb_client_info *client_info;
23 u32 hash_index;
24
25 if (BOND_MODE(bond) != BOND_MODE_ALB)
26 return 0;
27
28 seq_printf(m, "SourceIP DestinationIP "
29 "Destination MAC DEV\n");
30
31 spin_lock_bh(&bond->mode_lock);
32
33 hash_index = bond_info->rx_hashtbl_used_head;
34 for (; hash_index != RLB_NULL_INDEX;
35 hash_index = client_info->used_next) {
36 client_info = &(bond_info->rx_hashtbl[hash_index]);
37 seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
38 &client_info->ip_src,
39 &client_info->ip_dst,
40 &client_info->mac_dst,
41 client_info->slave->dev->name);
42 }
43
44 spin_unlock_bh(&bond->mode_lock);
45
46 return 0;
47}
48DEFINE_SHOW_ATTRIBUTE(bond_debug_rlb_hash);
49
50void bond_debug_register(struct bonding *bond)
51{
52 if (!bonding_debug_root)
53 return;
54
55 bond->debug_dir =
56 debugfs_create_dir(bond->dev->name, bonding_debug_root);
57
58 if (!bond->debug_dir) {
59 netdev_warn(bond->dev, "failed to register to debugfs\n");
60 return;
61 }
62
63 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
64 bond, &bond_debug_rlb_hash_fops);
65}
66
67void bond_debug_unregister(struct bonding *bond)
68{
69 if (!bonding_debug_root)
70 return;
71
72 debugfs_remove_recursive(bond->debug_dir);
73}
74
75void bond_debug_reregister(struct bonding *bond)
76{
77 struct dentry *d;
78
79 if (!bonding_debug_root)
80 return;
81
82 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
83 bonding_debug_root, bond->dev->name);
84 if (d) {
85 bond->debug_dir = d;
86 } else {
87 netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
88 bond_debug_unregister(bond);
89 }
90}
91
92void bond_create_debugfs(void)
93{
94 bonding_debug_root = debugfs_create_dir("bonding", NULL);
95
96 if (!bonding_debug_root) {
97 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
98 }
99}
100
101void bond_destroy_debugfs(void)
102{
103 debugfs_remove_recursive(bonding_debug_root);
104 bonding_debug_root = NULL;
105}
106
107
108#else
109
110void bond_debug_register(struct bonding *bond)
111{
112}
113
114void bond_debug_unregister(struct bonding *bond)
115{
116}
117
118void bond_debug_reregister(struct bonding *bond)
119{
120}
121
122void bond_create_debugfs(void)
123{
124}
125
126void bond_destroy_debugfs(void)
127{
128}
129
130#endif
131