0001
0002 #include <linux/kernel.h>
0003 #include <linux/module.h>
0004 #include <linux/device.h>
0005 #include <linux/netdevice.h>
0006
0007 #include <net/bonding.h>
0008 #include <net/bond_alb.h>
0009
0010 #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
0011
0012 #include <linux/debugfs.h>
0013 #include <linux/seq_file.h>
0014
0015 static struct dentry *bonding_debug_root;
0016
0017
0018 static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
0019 {
0020 struct bonding *bond = m->private;
0021 struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
0022 struct rlb_client_info *client_info;
0023 u32 hash_index;
0024
0025 if (BOND_MODE(bond) != BOND_MODE_ALB)
0026 return 0;
0027
0028 seq_printf(m, "SourceIP DestinationIP "
0029 "Destination MAC DEV\n");
0030
0031 spin_lock_bh(&bond->mode_lock);
0032
0033 hash_index = bond_info->rx_hashtbl_used_head;
0034 for (; hash_index != RLB_NULL_INDEX;
0035 hash_index = client_info->used_next) {
0036 client_info = &(bond_info->rx_hashtbl[hash_index]);
0037 seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
0038 &client_info->ip_src,
0039 &client_info->ip_dst,
0040 &client_info->mac_dst,
0041 client_info->slave->dev->name);
0042 }
0043
0044 spin_unlock_bh(&bond->mode_lock);
0045
0046 return 0;
0047 }
0048 DEFINE_SHOW_ATTRIBUTE(bond_debug_rlb_hash);
0049
0050 void bond_debug_register(struct bonding *bond)
0051 {
0052 if (!bonding_debug_root)
0053 return;
0054
0055 bond->debug_dir =
0056 debugfs_create_dir(bond->dev->name, bonding_debug_root);
0057
0058 debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
0059 bond, &bond_debug_rlb_hash_fops);
0060 }
0061
0062 void bond_debug_unregister(struct bonding *bond)
0063 {
0064 if (!bonding_debug_root)
0065 return;
0066
0067 debugfs_remove_recursive(bond->debug_dir);
0068 }
0069
0070 void bond_debug_reregister(struct bonding *bond)
0071 {
0072 struct dentry *d;
0073
0074 if (!bonding_debug_root)
0075 return;
0076
0077 d = debugfs_rename(bonding_debug_root, bond->debug_dir,
0078 bonding_debug_root, bond->dev->name);
0079 if (d) {
0080 bond->debug_dir = d;
0081 } else {
0082 netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
0083 bond_debug_unregister(bond);
0084 }
0085 }
0086
0087 void bond_create_debugfs(void)
0088 {
0089 bonding_debug_root = debugfs_create_dir("bonding", NULL);
0090
0091 if (!bonding_debug_root)
0092 pr_warn("Warning: Cannot create bonding directory in debugfs\n");
0093 }
0094
0095 void bond_destroy_debugfs(void)
0096 {
0097 debugfs_remove_recursive(bonding_debug_root);
0098 bonding_debug_root = NULL;
0099 }
0100
0101
0102 #else
0103
0104 void bond_debug_register(struct bonding *bond)
0105 {
0106 }
0107
0108 void bond_debug_unregister(struct bonding *bond)
0109 {
0110 }
0111
0112 void bond_debug_reregister(struct bonding *bond)
0113 {
0114 }
0115
0116 void bond_create_debugfs(void)
0117 {
0118 }
0119
0120 void bond_destroy_debugfs(void)
0121 {
0122 }
0123
0124 #endif