Commit | Line | Data |
---|---|---|
b2441318 | 1 | // SPDX-License-Identifier: GPL-2.0 |
f073c7ca TI |
2 | #include <linux/kernel.h> |
3 | #include <linux/module.h> | |
4 | #include <linux/device.h> | |
5 | #include <linux/netdevice.h> | |
6 | ||
1ef8019b DM |
7 | #include <net/bonding.h> |
8 | #include <net/bond_alb.h> | |
f073c7ca | 9 | |
96ca7ffe | 10 | #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS) |
f073c7ca TI |
11 | |
12 | #include <linux/debugfs.h> | |
13 | #include <linux/seq_file.h> | |
14 | ||
15 | static struct dentry *bonding_debug_root; | |
16 | ||
547942ca | 17 | /* Show RLB hash table */ |
caafa842 TI |
18 | static 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 | ||
01844098 | 25 | if (BOND_MODE(bond) != BOND_MODE_ALB) |
caafa842 TI |
26 | return 0; |
27 | ||
28 | seq_printf(m, "SourceIP DestinationIP " | |
29 | "Destination MAC DEV\n"); | |
30 | ||
4bab16d7 | 31 | spin_lock_bh(&bond->mode_lock); |
caafa842 | 32 | |
e53665c6 JB |
33 | hash_index = bond_info->rx_hashtbl_used_head; |
34 | for (; hash_index != RLB_NULL_INDEX; | |
35 | hash_index = client_info->used_next) { | |
caafa842 TI |
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 | ||
4bab16d7 | 44 | spin_unlock_bh(&bond->mode_lock); |
caafa842 TI |
45 | |
46 | return 0; | |
47 | } | |
4e6feb7a | 48 | DEFINE_SHOW_ATTRIBUTE(bond_debug_rlb_hash); |
caafa842 | 49 | |
f073c7ca TI |
50 | void 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 | ||
caafa842 TI |
58 | debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir, |
59 | bond, &bond_debug_rlb_hash_fops); | |
f073c7ca TI |
60 | } |
61 | ||
62 | void bond_debug_unregister(struct bonding *bond) | |
63 | { | |
64 | if (!bonding_debug_root) | |
65 | return; | |
66 | ||
67 | debugfs_remove_recursive(bond->debug_dir); | |
68 | } | |
69 | ||
70 | void bond_debug_reregister(struct bonding *bond) | |
71 | { | |
72 | struct dentry *d; | |
73 | ||
74 | if (!bonding_debug_root) | |
75 | return; | |
76 | ||
77 | d = debugfs_rename(bonding_debug_root, bond->debug_dir, | |
78 | bonding_debug_root, bond->dev->name); | |
cbe83191 | 79 | if (!IS_ERR(d)) { |
f073c7ca TI |
80 | bond->debug_dir = d; |
81 | } else { | |
9ef1cf16 | 82 | netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n"); |
f073c7ca TI |
83 | bond_debug_unregister(bond); |
84 | } | |
85 | } | |
86 | ||
87 | void bond_create_debugfs(void) | |
88 | { | |
89 | bonding_debug_root = debugfs_create_dir("bonding", NULL); | |
90 | ||
52333512 | 91 | if (!bonding_debug_root) |
91565ebb | 92 | pr_warn("Warning: Cannot create bonding directory in debugfs\n"); |
f073c7ca TI |
93 | } |
94 | ||
95 | void bond_destroy_debugfs(void) | |
96 | { | |
97 | debugfs_remove_recursive(bonding_debug_root); | |
98 | bonding_debug_root = NULL; | |
99 | } | |
100 | ||
101 | ||
102 | #else /* !CONFIG_DEBUG_FS */ | |
103 | ||
104 | void bond_debug_register(struct bonding *bond) | |
105 | { | |
106 | } | |
107 | ||
108 | void bond_debug_unregister(struct bonding *bond) | |
109 | { | |
110 | } | |
111 | ||
112 | void bond_debug_reregister(struct bonding *bond) | |
113 | { | |
114 | } | |
115 | ||
116 | void bond_create_debugfs(void) | |
117 | { | |
118 | } | |
119 | ||
120 | void bond_destroy_debugfs(void) | |
121 | { | |
122 | } | |
123 | ||
124 | #endif /* CONFIG_DEBUG_FS */ |