Loading...
1#include <linux/kernel.h>
2#include <linux/module.h>
3#include <linux/device.h>
4#include <linux/netdevice.h>
5
6#include "bonding.h"
7#include "bond_alb.h"
8
9#ifdef CONFIG_DEBUG_FS
10
11#include <linux/debugfs.h>
12#include <linux/seq_file.h>
13
14static struct dentry *bonding_debug_root;
15
16/*
17 * Show RLB hash table
18 */
19static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
20{
21 struct bonding *bond = m->private;
22 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
23 struct rlb_client_info *client_info;
24 u32 hash_index;
25
26 if (bond->params.mode != BOND_MODE_ALB)
27 return 0;
28
29 seq_printf(m, "SourceIP DestinationIP "
30 "Destination MAC DEV\n");
31
32 spin_lock_bh(&(BOND_ALB_INFO(bond).rx_hashtbl_lock));
33
34 hash_index = bond_info->rx_hashtbl_head;
35 for (; hash_index != RLB_NULL_INDEX; hash_index = client_info->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_ALB_INFO(bond).rx_hashtbl_lock));
45
46 return 0;
47}
48
49static int bond_debug_rlb_hash_open(struct inode *inode, struct file *file)
50{
51 return single_open(file, bond_debug_rlb_hash_show, inode->i_private);
52}
53
54static const struct file_operations bond_debug_rlb_hash_fops = {
55 .owner = THIS_MODULE,
56 .open = bond_debug_rlb_hash_open,
57 .read = seq_read,
58 .llseek = seq_lseek,
59 .release = single_release,
60};
61
62void bond_debug_register(struct bonding *bond)
63{
64 if (!bonding_debug_root)
65 return;
66
67 bond->debug_dir =
68 debugfs_create_dir(bond->dev->name, bonding_debug_root);
69
70 if (!bond->debug_dir) {
71 pr_warning("%s: Warning: failed to register to debugfs\n",
72 bond->dev->name);
73 return;
74 }
75
76 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
77 bond, &bond_debug_rlb_hash_fops);
78}
79
80void bond_debug_unregister(struct bonding *bond)
81{
82 if (!bonding_debug_root)
83 return;
84
85 debugfs_remove_recursive(bond->debug_dir);
86}
87
88void bond_debug_reregister(struct bonding *bond)
89{
90 struct dentry *d;
91
92 if (!bonding_debug_root)
93 return;
94
95 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
96 bonding_debug_root, bond->dev->name);
97 if (d) {
98 bond->debug_dir = d;
99 } else {
100 pr_warning("%s: Warning: failed to reregister, "
101 "so just unregister old one\n",
102 bond->dev->name);
103 bond_debug_unregister(bond);
104 }
105}
106
107void bond_create_debugfs(void)
108{
109 bonding_debug_root = debugfs_create_dir("bonding", NULL);
110
111 if (!bonding_debug_root) {
112 pr_warning("Warning: Cannot create bonding directory"
113 " in debugfs\n");
114 }
115}
116
117void bond_destroy_debugfs(void)
118{
119 debugfs_remove_recursive(bonding_debug_root);
120 bonding_debug_root = NULL;
121}
122
123
124#else /* !CONFIG_DEBUG_FS */
125
126void bond_debug_register(struct bonding *bond)
127{
128}
129
130void bond_debug_unregister(struct bonding *bond)
131{
132}
133
134void bond_debug_reregister(struct bonding *bond)
135{
136}
137
138void bond_create_debugfs(void)
139{
140}
141
142void bond_destroy_debugfs(void)
143{
144}
145
146#endif /* CONFIG_DEBUG_FS */
1// SPDX-License-Identifier: GPL-2.0
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/* Show RLB hash table */
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 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
59 bond, &bond_debug_rlb_hash_fops);
60}
61
62void bond_debug_unregister(struct bonding *bond)
63{
64 if (!bonding_debug_root)
65 return;
66
67 debugfs_remove_recursive(bond->debug_dir);
68}
69
70void 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);
79 if (d) {
80 bond->debug_dir = d;
81 } else {
82 netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
83 bond_debug_unregister(bond);
84 }
85}
86
87void bond_create_debugfs(void)
88{
89 bonding_debug_root = debugfs_create_dir("bonding", NULL);
90
91 if (!bonding_debug_root) {
92 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
93 }
94}
95
96void bond_destroy_debugfs(void)
97{
98 debugfs_remove_recursive(bonding_debug_root);
99 bonding_debug_root = NULL;
100}
101
102
103#else /* !CONFIG_DEBUG_FS */
104
105void bond_debug_register(struct bonding *bond)
106{
107}
108
109void bond_debug_unregister(struct bonding *bond)
110{
111}
112
113void bond_debug_reregister(struct bonding *bond)
114{
115}
116
117void bond_create_debugfs(void)
118{
119}
120
121void bond_destroy_debugfs(void)
122{
123}
124
125#endif /* CONFIG_DEBUG_FS */