Sven Eckelmann | 7db7d9f | 2017-11-19 15:05:11 +0100 | [diff] [blame] | 1 | // SPDX-License-Identifier: GPL-2.0 |
Sven Eckelmann | 7a79d71 | 2018-12-31 23:59:59 +0100 | [diff] [blame] | 2 | /* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 3 | * |
| 4 | * Marek Lindner |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 5 | */ |
| 6 | |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 7 | #include "debugfs.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 8 | #include "main.h" |
| 9 | |
Sven Eckelmann | a5dac4d | 2018-10-21 11:30:29 +0200 | [diff] [blame] | 10 | #include <asm/current.h> |
Sven Eckelmann | 36dc621 | 2018-06-01 19:24:23 +0200 | [diff] [blame] | 11 | #include <linux/dcache.h> |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 12 | #include <linux/debugfs.h> |
Sven Eckelmann | 3e7514a | 2017-01-28 10:23:30 +0100 | [diff] [blame] | 13 | #include <linux/err.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 14 | #include <linux/errno.h> |
| 15 | #include <linux/export.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 16 | #include <linux/fs.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 17 | #include <linux/netdevice.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 18 | #include <linux/printk.h> |
Sven Eckelmann | a5dac4d | 2018-10-21 11:30:29 +0200 | [diff] [blame] | 19 | #include <linux/sched.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 20 | #include <linux/seq_file.h> |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 21 | #include <linux/stat.h> |
| 22 | #include <linux/stddef.h> |
| 23 | #include <linux/stringify.h> |
| 24 | #include <linux/sysfs.h> |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 25 | #include <net/net_namespace.h> |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 26 | |
Sven Eckelmann | 01d350d | 2016-05-15 11:07:44 +0200 | [diff] [blame] | 27 | #include "bat_algo.h" |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 28 | #include "bridge_loop_avoidance.h" |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 29 | #include "distributed-arp-table.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 30 | #include "gateway_client.h" |
| 31 | #include "icmp_socket.h" |
Sven Eckelmann | ba41208 | 2016-05-15 23:48:31 +0200 | [diff] [blame] | 32 | #include "log.h" |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 33 | #include "multicast.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 34 | #include "network-coding.h" |
Sven Eckelmann | 1e2c2a4 | 2015-04-17 19:40:28 +0200 | [diff] [blame] | 35 | #include "originator.h" |
| 36 | #include "translation-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 37 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 38 | static struct dentry *batadv_debugfs; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 39 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 40 | /** |
| 41 | * batadv_debugfs_deprecated() - Log use of deprecated batadv debugfs access |
| 42 | * @file: file which was accessed |
| 43 | * @alt: explanation what can be used as alternative |
| 44 | */ |
| 45 | void batadv_debugfs_deprecated(struct file *file, const char *alt) |
| 46 | { |
| 47 | struct dentry *dentry = file_dentry(file); |
| 48 | const char *name = dentry->d_name.name; |
| 49 | |
| 50 | pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of debugfs file \"%s\".\n%s", |
| 51 | current->comm, task_pid_nr(current), name, alt); |
| 52 | } |
| 53 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 54 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 55 | { |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 56 | batadv_debugfs_deprecated(file, |
| 57 | "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n"); |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 58 | return single_open(file, batadv_algo_seq_print_text, NULL); |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 59 | } |
| 60 | |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 61 | static int neighbors_open(struct inode *inode, struct file *file) |
| 62 | { |
| 63 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 64 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 65 | batadv_debugfs_deprecated(file, |
| 66 | "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n"); |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 67 | return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev); |
| 68 | } |
| 69 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 70 | static int batadv_originators_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 71 | { |
| 72 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 73 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 74 | batadv_debugfs_deprecated(file, |
| 75 | "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n"); |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 76 | return single_open(file, batadv_orig_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 79 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 80 | * batadv_originators_hardif_open() - handles debugfs output for the originator |
| 81 | * table of an hard interface |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 82 | * @inode: inode pointer to debugfs file |
| 83 | * @file: pointer to the seq_file |
Sven Eckelmann | 7afcbbe | 2015-10-31 12:29:29 +0100 | [diff] [blame] | 84 | * |
| 85 | * Return: 0 on success or negative error number in case of failure |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 86 | */ |
| 87 | static int batadv_originators_hardif_open(struct inode *inode, |
| 88 | struct file *file) |
| 89 | { |
| 90 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 91 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 92 | batadv_debugfs_deprecated(file, |
| 93 | "Use genl command BATADV_CMD_GET_HARDIFS instead\n"); |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 94 | return single_open(file, batadv_orig_hardif_seq_print_text, net_dev); |
| 95 | } |
| 96 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 97 | static int batadv_gateways_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 98 | { |
| 99 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 100 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 101 | batadv_debugfs_deprecated(file, |
| 102 | "Use genl command BATADV_CMD_GET_GATEWAYS instead\n"); |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 103 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 104 | } |
| 105 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 106 | static int batadv_transtable_global_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 107 | { |
| 108 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 109 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 110 | batadv_debugfs_deprecated(file, |
| 111 | "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n"); |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 112 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 113 | } |
| 114 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 115 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 116 | static int batadv_bla_claim_table_open(struct inode *inode, struct file *file) |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 117 | { |
| 118 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 119 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 120 | batadv_debugfs_deprecated(file, |
| 121 | "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n"); |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 122 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
| 123 | net_dev); |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 124 | } |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 125 | |
| 126 | static int batadv_bla_backbone_table_open(struct inode *inode, |
| 127 | struct file *file) |
| 128 | { |
| 129 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 130 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 131 | batadv_debugfs_deprecated(file, |
| 132 | "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n"); |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 133 | return single_open(file, batadv_bla_backbone_table_seq_print_text, |
| 134 | net_dev); |
| 135 | } |
| 136 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 137 | #endif |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 138 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 139 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 140 | /** |
Sven Eckelmann | be01dc3 | 2018-07-05 14:42:49 +0200 | [diff] [blame] | 141 | * batadv_dat_cache_open() - Prepare file handler for reads from dat_cache |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 142 | * @inode: inode which was opened |
| 143 | * @file: file handle to be initialized |
Sven Eckelmann | 7afcbbe | 2015-10-31 12:29:29 +0100 | [diff] [blame] | 144 | * |
| 145 | * Return: 0 on success or negative error number in case of failure |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 146 | */ |
| 147 | static int batadv_dat_cache_open(struct inode *inode, struct file *file) |
| 148 | { |
| 149 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 150 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 151 | batadv_debugfs_deprecated(file, |
| 152 | "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n"); |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 153 | return single_open(file, batadv_dat_cache_seq_print_text, net_dev); |
| 154 | } |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 155 | #endif |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 156 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 157 | static int batadv_transtable_local_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 158 | { |
| 159 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 160 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 161 | batadv_debugfs_deprecated(file, |
| 162 | "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n"); |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 163 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 164 | } |
| 165 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 166 | struct batadv_debuginfo { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 167 | struct attribute attr; |
| 168 | const struct file_operations fops; |
| 169 | }; |
| 170 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 171 | #ifdef CONFIG_BATMAN_ADV_NC |
| 172 | static int batadv_nc_nodes_open(struct inode *inode, struct file *file) |
| 173 | { |
| 174 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Antonio Quartulli | f138694 | 2014-05-10 18:56:37 +0200 | [diff] [blame] | 175 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 176 | batadv_debugfs_deprecated(file, ""); |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 177 | return single_open(file, batadv_nc_nodes_seq_print_text, net_dev); |
| 178 | } |
| 179 | #endif |
| 180 | |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 181 | #ifdef CONFIG_BATMAN_ADV_MCAST |
| 182 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 183 | * batadv_mcast_flags_open() - prepare file handler for reads from mcast_flags |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 184 | * @inode: inode which was opened |
| 185 | * @file: file handle to be initialized |
| 186 | * |
| 187 | * Return: 0 on success or negative error number in case of failure |
| 188 | */ |
| 189 | static int batadv_mcast_flags_open(struct inode *inode, struct file *file) |
| 190 | { |
| 191 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 192 | |
Sven Eckelmann | 00caf6a | 2018-08-10 23:36:15 +0200 | [diff] [blame] | 193 | batadv_debugfs_deprecated(file, |
| 194 | "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n"); |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 195 | return single_open(file, batadv_mcast_flags_seq_print_text, net_dev); |
| 196 | } |
| 197 | #endif |
| 198 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 199 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 200 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
Simon Wunderlich | 121bdca | 2016-03-11 14:01:11 +0100 | [diff] [blame] | 201 | .attr = { \ |
| 202 | .name = __stringify(_name), \ |
| 203 | .mode = _mode, \ |
| 204 | }, \ |
| 205 | .fops = { \ |
| 206 | .owner = THIS_MODULE, \ |
| 207 | .open = _open, \ |
| 208 | .read = seq_read, \ |
| 209 | .llseek = seq_lseek, \ |
| 210 | .release = single_release, \ |
| 211 | }, \ |
Antonio Quartulli | 2b64df2 | 2014-05-15 11:24:26 +0200 | [diff] [blame] | 212 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 213 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 214 | /* the following attributes are general and therefore they will be directly |
| 215 | * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs |
| 216 | */ |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 217 | static BATADV_DEBUGINFO(routing_algos, 0444, batadv_algorithms_open); |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 218 | |
| 219 | static struct batadv_debuginfo *batadv_general_debuginfos[] = { |
| 220 | &batadv_debuginfo_routing_algos, |
| 221 | NULL, |
| 222 | }; |
| 223 | |
| 224 | /* The following attributes are per soft interface */ |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 225 | static BATADV_DEBUGINFO(neighbors, 0444, neighbors_open); |
| 226 | static BATADV_DEBUGINFO(originators, 0444, batadv_originators_open); |
| 227 | static BATADV_DEBUGINFO(gateways, 0444, batadv_gateways_open); |
| 228 | static BATADV_DEBUGINFO(transtable_global, 0444, batadv_transtable_global_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 229 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 230 | static BATADV_DEBUGINFO(bla_claim_table, 0444, batadv_bla_claim_table_open); |
| 231 | static BATADV_DEBUGINFO(bla_backbone_table, 0444, |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 232 | batadv_bla_backbone_table_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 233 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 234 | #ifdef CONFIG_BATMAN_ADV_DAT |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 235 | static BATADV_DEBUGINFO(dat_cache, 0444, batadv_dat_cache_open); |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 236 | #endif |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 237 | static BATADV_DEBUGINFO(transtable_local, 0444, batadv_transtable_local_open); |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 238 | #ifdef CONFIG_BATMAN_ADV_NC |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 239 | static BATADV_DEBUGINFO(nc_nodes, 0444, batadv_nc_nodes_open); |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 240 | #endif |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 241 | #ifdef CONFIG_BATMAN_ADV_MCAST |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 242 | static BATADV_DEBUGINFO(mcast_flags, 0444, batadv_mcast_flags_open); |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 243 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 244 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 245 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
Marek Lindner | 7587405 | 2015-08-04 21:09:57 +0800 | [diff] [blame] | 246 | &batadv_debuginfo_neighbors, |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 247 | &batadv_debuginfo_originators, |
| 248 | &batadv_debuginfo_gateways, |
| 249 | &batadv_debuginfo_transtable_global, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 250 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 251 | &batadv_debuginfo_bla_claim_table, |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 252 | &batadv_debuginfo_bla_backbone_table, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 253 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 254 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 255 | &batadv_debuginfo_dat_cache, |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 256 | #endif |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 257 | &batadv_debuginfo_transtable_local, |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 258 | #ifdef CONFIG_BATMAN_ADV_NC |
| 259 | &batadv_debuginfo_nc_nodes, |
| 260 | #endif |
Linus Lüssing | 4e3e823 | 2016-05-10 18:41:27 +0200 | [diff] [blame] | 261 | #ifdef CONFIG_BATMAN_ADV_MCAST |
| 262 | &batadv_debuginfo_mcast_flags, |
| 263 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 264 | NULL, |
| 265 | }; |
| 266 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 267 | #define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open) \ |
| 268 | struct batadv_debuginfo batadv_hardif_debuginfo_##_name = { \ |
| 269 | .attr = { \ |
| 270 | .name = __stringify(_name), \ |
| 271 | .mode = _mode, \ |
| 272 | }, \ |
| 273 | .fops = { \ |
| 274 | .owner = THIS_MODULE, \ |
| 275 | .open = _open, \ |
| 276 | .read = seq_read, \ |
| 277 | .llseek = seq_lseek, \ |
| 278 | .release = single_release, \ |
| 279 | }, \ |
Antonio Quartulli | 2b64df2 | 2014-05-15 11:24:26 +0200 | [diff] [blame] | 280 | } |
Antonio Quartulli | aa143d2 | 2014-09-01 14:37:27 +0200 | [diff] [blame] | 281 | |
Sven Eckelmann | 507b37c | 2016-09-01 10:25:12 +0200 | [diff] [blame] | 282 | static BATADV_HARDIF_DEBUGINFO(originators, 0444, |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 283 | batadv_originators_hardif_open); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 284 | |
| 285 | static struct batadv_debuginfo *batadv_hardif_debuginfos[] = { |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 286 | &batadv_hardif_debuginfo_originators, |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 287 | NULL, |
| 288 | }; |
| 289 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 290 | /** |
| 291 | * batadv_debugfs_init() - Initialize soft interface independent debugfs entries |
| 292 | */ |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 293 | void batadv_debugfs_init(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 294 | { |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 295 | struct batadv_debuginfo **bat_debug; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 296 | struct dentry *file; |
| 297 | |
Sven Eckelmann | 54590e4 | 2012-06-03 22:19:08 +0200 | [diff] [blame] | 298 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 299 | if (batadv_debugfs == ERR_PTR(-ENODEV)) |
| 300 | batadv_debugfs = NULL; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 301 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 302 | if (!batadv_debugfs) |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 303 | goto err; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 304 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 305 | for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) { |
| 306 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 307 | S_IFREG | ((*bat_debug)->attr).mode, |
| 308 | batadv_debugfs, NULL, |
| 309 | &(*bat_debug)->fops); |
| 310 | if (!file) { |
| 311 | pr_err("Can't add general debugfs file: %s\n", |
| 312 | ((*bat_debug)->attr).name); |
| 313 | goto err; |
| 314 | } |
| 315 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 316 | |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 317 | return; |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 318 | err: |
| 319 | debugfs_remove_recursive(batadv_debugfs); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 320 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 321 | } |
| 322 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 323 | /** |
| 324 | * batadv_debugfs_destroy() - Remove all debugfs entries |
| 325 | */ |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 326 | void batadv_debugfs_destroy(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 327 | { |
Antonio Quartulli | 3f87c42 | 2012-11-29 01:03:31 +0100 | [diff] [blame] | 328 | debugfs_remove_recursive(batadv_debugfs); |
| 329 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 332 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 333 | * batadv_debugfs_add_hardif() - creates the base directory for a hard interface |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 334 | * in debugfs. |
| 335 | * @hard_iface: hard interface which should be added. |
Sven Eckelmann | 7afcbbe | 2015-10-31 12:29:29 +0100 | [diff] [blame] | 336 | * |
| 337 | * Return: 0 on success or negative error number in case of failure |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 338 | */ |
| 339 | int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) |
| 340 | { |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 341 | struct net *net = dev_net(hard_iface->net_dev); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 342 | struct batadv_debuginfo **bat_debug; |
| 343 | struct dentry *file; |
| 344 | |
| 345 | if (!batadv_debugfs) |
| 346 | goto out; |
| 347 | |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 348 | if (net != &init_net) |
| 349 | return 0; |
| 350 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 351 | hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, |
| 352 | batadv_debugfs); |
| 353 | if (!hard_iface->debug_dir) |
| 354 | goto out; |
| 355 | |
| 356 | for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) { |
| 357 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 358 | S_IFREG | ((*bat_debug)->attr).mode, |
| 359 | hard_iface->debug_dir, |
| 360 | hard_iface->net_dev, |
| 361 | &(*bat_debug)->fops); |
| 362 | if (!file) |
| 363 | goto rem_attr; |
| 364 | } |
| 365 | |
| 366 | return 0; |
| 367 | rem_attr: |
| 368 | debugfs_remove_recursive(hard_iface->debug_dir); |
| 369 | hard_iface->debug_dir = NULL; |
| 370 | out: |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 371 | return -ENOMEM; |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 372 | } |
| 373 | |
| 374 | /** |
Sven Eckelmann | 36dc621 | 2018-06-01 19:24:23 +0200 | [diff] [blame] | 375 | * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif |
| 376 | * @hard_iface: hard interface which was renamed |
| 377 | */ |
| 378 | void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface) |
| 379 | { |
| 380 | const char *name = hard_iface->net_dev->name; |
| 381 | struct dentry *dir; |
| 382 | struct dentry *d; |
| 383 | |
| 384 | dir = hard_iface->debug_dir; |
| 385 | if (!dir) |
| 386 | return; |
| 387 | |
| 388 | d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name); |
| 389 | if (!d) |
| 390 | pr_err("Can't rename debugfs dir to %s\n", name); |
| 391 | } |
| 392 | |
| 393 | /** |
Sven Eckelmann | 7e9a8c2 | 2017-12-02 19:51:47 +0100 | [diff] [blame] | 394 | * batadv_debugfs_del_hardif() - delete the base directory for a hard interface |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 395 | * in debugfs. |
| 396 | * @hard_iface: hard interface which is deleted. |
| 397 | */ |
| 398 | void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) |
| 399 | { |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 400 | struct net *net = dev_net(hard_iface->net_dev); |
| 401 | |
| 402 | if (net != &init_net) |
| 403 | return; |
| 404 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 405 | if (batadv_debugfs) { |
| 406 | debugfs_remove_recursive(hard_iface->debug_dir); |
| 407 | hard_iface->debug_dir = NULL; |
| 408 | } |
| 409 | } |
| 410 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 411 | /** |
| 412 | * batadv_debugfs_add_meshif() - Initialize interface dependent debugfs entries |
| 413 | * @dev: netdev struct of the soft interface |
| 414 | * |
| 415 | * Return: 0 on success or negative error number in case of failure |
| 416 | */ |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 417 | int batadv_debugfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 418 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 419 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 420 | struct batadv_debuginfo **bat_debug; |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 421 | struct net *net = dev_net(dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 422 | struct dentry *file; |
| 423 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 424 | if (!batadv_debugfs) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 425 | goto out; |
| 426 | |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 427 | if (net != &init_net) |
| 428 | return 0; |
| 429 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 430 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 431 | if (!bat_priv->debug_dir) |
| 432 | goto out; |
| 433 | |
Sven Eckelmann | 9039dc7 | 2012-05-12 02:09:33 +0200 | [diff] [blame] | 434 | if (batadv_socket_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 435 | goto rem_attr; |
| 436 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 437 | if (batadv_debug_log_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 438 | goto rem_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 439 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 440 | for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 441 | file = debugfs_create_file(((*bat_debug)->attr).name, |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 442 | S_IFREG | ((*bat_debug)->attr).mode, |
| 443 | bat_priv->debug_dir, |
| 444 | dev, &(*bat_debug)->fops); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 445 | if (!file) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 446 | batadv_err(dev, "Can't add debugfs file: %s/%s\n", |
| 447 | dev->name, ((*bat_debug)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 448 | goto rem_attr; |
| 449 | } |
| 450 | } |
| 451 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 452 | if (batadv_nc_init_debugfs(bat_priv) < 0) |
| 453 | goto rem_attr; |
| 454 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 455 | return 0; |
| 456 | rem_attr: |
| 457 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 458 | bat_priv->debug_dir = NULL; |
| 459 | out: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 460 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 461 | } |
| 462 | |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 463 | /** |
Sven Eckelmann | 6da7be7 | 2018-06-01 19:24:24 +0200 | [diff] [blame] | 464 | * batadv_debugfs_rename_meshif() - Fix debugfs path for renamed softif |
| 465 | * @dev: net_device which was renamed |
| 466 | */ |
| 467 | void batadv_debugfs_rename_meshif(struct net_device *dev) |
| 468 | { |
| 469 | struct batadv_priv *bat_priv = netdev_priv(dev); |
| 470 | const char *name = dev->name; |
| 471 | struct dentry *dir; |
| 472 | struct dentry *d; |
| 473 | |
| 474 | dir = bat_priv->debug_dir; |
| 475 | if (!dir) |
| 476 | return; |
| 477 | |
| 478 | d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name); |
| 479 | if (!d) |
| 480 | pr_err("Can't rename debugfs dir to %s\n", name); |
| 481 | } |
| 482 | |
| 483 | /** |
Sven Eckelmann | ff15c27 | 2017-12-02 19:51:53 +0100 | [diff] [blame] | 484 | * batadv_debugfs_del_meshif() - Remove interface dependent debugfs entries |
| 485 | * @dev: netdev struct of the soft interface |
| 486 | */ |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 487 | void batadv_debugfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 488 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 489 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Andrew Lunn | 9496920 | 2016-07-03 13:31:34 +0200 | [diff] [blame] | 490 | struct net *net = dev_net(dev); |
| 491 | |
| 492 | if (net != &init_net) |
| 493 | return; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 494 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 495 | batadv_debug_log_cleanup(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 496 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 497 | if (batadv_debugfs) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 498 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 499 | bat_priv->debug_dir = NULL; |
| 500 | } |
| 501 | } |