bond_debugfs.c 2.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  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. #include <net/bonding.h>
  7. #include <net/bond_alb.h>
  8. #if defined(CONFIG_DEBUG_FS) && !defined(CONFIG_NET_NS)
  9. #include <linux/debugfs.h>
  10. #include <linux/seq_file.h>
  11. static struct dentry *bonding_debug_root;
  12. /* Show RLB hash table */
  13. static int bond_debug_rlb_hash_show(struct seq_file *m, void *v)
  14. {
  15. struct bonding *bond = m->private;
  16. struct alb_bond_info *bond_info = &(BOND_ALB_INFO(bond));
  17. struct rlb_client_info *client_info;
  18. u32 hash_index;
  19. if (BOND_MODE(bond) != BOND_MODE_ALB)
  20. return 0;
  21. seq_printf(m, "SourceIP DestinationIP "
  22. "Destination MAC DEV\n");
  23. spin_lock_bh(&bond->mode_lock);
  24. hash_index = bond_info->rx_hashtbl_used_head;
  25. for (; hash_index != RLB_NULL_INDEX;
  26. hash_index = client_info->used_next) {
  27. client_info = &(bond_info->rx_hashtbl[hash_index]);
  28. seq_printf(m, "%-15pI4 %-15pI4 %-17pM %s\n",
  29. &client_info->ip_src,
  30. &client_info->ip_dst,
  31. &client_info->mac_dst,
  32. client_info->slave->dev->name);
  33. }
  34. spin_unlock_bh(&bond->mode_lock);
  35. return 0;
  36. }
  37. DEFINE_SHOW_ATTRIBUTE(bond_debug_rlb_hash);
  38. void bond_debug_register(struct bonding *bond)
  39. {
  40. if (!bonding_debug_root)
  41. return;
  42. bond->debug_dir =
  43. debugfs_create_dir(bond->dev->name, bonding_debug_root);
  44. debugfs_create_file("rlb_hash_table", 0400, bond->debug_dir,
  45. bond, &bond_debug_rlb_hash_fops);
  46. }
  47. void bond_debug_unregister(struct bonding *bond)
  48. {
  49. if (!bonding_debug_root)
  50. return;
  51. debugfs_remove_recursive(bond->debug_dir);
  52. }
  53. void bond_debug_reregister(struct bonding *bond)
  54. {
  55. struct dentry *d;
  56. if (!bonding_debug_root)
  57. return;
  58. d = debugfs_rename(bonding_debug_root, bond->debug_dir,
  59. bonding_debug_root, bond->dev->name);
  60. if (!IS_ERR(d)) {
  61. bond->debug_dir = d;
  62. } else {
  63. netdev_warn(bond->dev, "failed to reregister, so just unregister old one\n");
  64. bond_debug_unregister(bond);
  65. }
  66. }
  67. void bond_create_debugfs(void)
  68. {
  69. bonding_debug_root = debugfs_create_dir("bonding", NULL);
  70. if (!bonding_debug_root)
  71. pr_warn("Warning: Cannot create bonding directory in debugfs\n");
  72. }
  73. void bond_destroy_debugfs(void)
  74. {
  75. debugfs_remove_recursive(bonding_debug_root);
  76. bonding_debug_root = NULL;
  77. }
  78. #else /* !CONFIG_DEBUG_FS */
  79. void bond_debug_register(struct bonding *bond)
  80. {
  81. }
  82. void bond_debug_unregister(struct bonding *bond)
  83. {
  84. }
  85. void bond_debug_reregister(struct bonding *bond)
  86. {
  87. }
  88. void bond_create_debugfs(void)
  89. {
  90. }
  91. void bond_destroy_debugfs(void)
  92. {
  93. }
  94. #endif /* CONFIG_DEBUG_FS */