1 #include <linux/kernel.h>
2 #include <linux/module.h>
3 #include <linux/device.h>
4 #include <linux/netdevice.h>
6 #include <net/bonding.h>
7 #include <net/bond_alb.h>
9 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
11 #include <linux/debugfs.h>
12 #include <linux/seq_file.h>
14 static struct dentry
*bonding_debug_root
;
16 /* Show RLB hash table */
17 static int bond_debug_rlb_hash_show(struct seq_file
*m
, void *v
)
19 struct bonding
*bond
= m
->private;
20 struct alb_bond_info
*bond_info
= &(BOND_ALB_INFO(bond
));
21 struct rlb_client_info
*client_info
;
24 if (BOND_MODE(bond
) != BOND_MODE_ALB
)
27 seq_printf(m
, "SourceIP DestinationIP "
28 "Destination MAC DEV\n");
30 spin_lock_bh(&bond
->mode_lock
);
32 hash_index
= bond_info
->rx_hashtbl_used_head
;
33 for (; hash_index
!= RLB_NULL_INDEX
;
34 hash_index
= client_info
->used_next
) {
35 client_info
= &(bond_info
->rx_hashtbl
[hash_index
]);
36 seq_printf(m
, "%-15pI4 %-15pI4 %-17pM %s\n",
39 &client_info
->mac_dst
,
40 client_info
->slave
->dev
->name
);
43 spin_unlock_bh(&bond
->mode_lock
);
48 static int bond_debug_rlb_hash_open(struct inode
*inode
, struct file
*file
)
50 return single_open(file
, bond_debug_rlb_hash_show
, inode
->i_private
);
53 static const struct file_operations bond_debug_rlb_hash_fops
= {
55 .open
= bond_debug_rlb_hash_open
,
58 .release
= single_release
,
61 void bond_debug_register(struct bonding
*bond
)
63 if (!bonding_debug_root
)
67 debugfs_create_dir(bond
->dev
->name
, bonding_debug_root
);
69 if (!bond
->debug_dir
) {
70 netdev_warn(bond
->dev
, "failed to register to debugfs\n");
74 debugfs_create_file("rlb_hash_table", 0400, bond
->debug_dir
,
75 bond
, &bond_debug_rlb_hash_fops
);
78 void bond_debug_unregister(struct bonding
*bond
)
80 if (!bonding_debug_root
)
83 debugfs_remove_recursive(bond
->debug_dir
);
86 void bond_debug_reregister(struct bonding
*bond
)
90 if (!bonding_debug_root
)
93 d
= debugfs_rename(bonding_debug_root
, bond
->debug_dir
,
94 bonding_debug_root
, bond
->dev
->name
);
98 netdev_warn(bond
->dev
, "failed to reregister, so just unregister old one\n");
99 bond_debug_unregister(bond
);
103 void bond_create_debugfs(void)
105 bonding_debug_root
= debugfs_create_dir("bonding", NULL
);
107 if (!bonding_debug_root
) {
108 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
112 void bond_destroy_debugfs(void)
114 debugfs_remove_recursive(bonding_debug_root
);
115 bonding_debug_root
= NULL
;
119 #else /* !CONFIG_DEBUG_FS */
121 void bond_debug_register(struct bonding
*bond
)
125 void bond_debug_unregister(struct bonding
*bond
)
129 void bond_debug_reregister(struct bonding
*bond
)
133 void bond_create_debugfs(void)
137 void bond_destroy_debugfs(void)
141 #endif /* CONFIG_DEBUG_FS */