blob: d4a7702e48d8eddc76684a62c858acde0a8a480b [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001// SPDX-License-Identifier: GPL-2.0
Sven Eckelmann6b1aea82018-01-01 00:00:00 +01002/* Copyright (C) 2010-2018 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner
5 *
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
Antonio Quartulliebf38fb2013-11-03 20:40:48 +010016 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000017 */
18
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020019#include "debugfs.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000020#include "main.h"
21
Sven Eckelmanna5dac4d2018-10-21 11:30:29 +020022#include <asm/current.h>
Sven Eckelmann36dc6212018-06-01 19:24:23 +020023#include <linux/dcache.h>
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000024#include <linux/debugfs.h>
Sven Eckelmann3e7514a2017-01-28 10:23:30 +010025#include <linux/err.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020026#include <linux/errno.h>
27#include <linux/export.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020028#include <linux/fs.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020029#include <linux/netdevice.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020030#include <linux/printk.h>
Sven Eckelmanna5dac4d2018-10-21 11:30:29 +020031#include <linux/sched.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020032#include <linux/seq_file.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020033#include <linux/stat.h>
34#include <linux/stddef.h>
35#include <linux/stringify.h>
36#include <linux/sysfs.h>
Andrew Lunn94969202016-07-03 13:31:34 +020037#include <net/net_namespace.h>
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000038
Sven Eckelmann01d350d2016-05-15 11:07:44 +020039#include "bat_algo.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010040#include "bridge_loop_avoidance.h"
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020041#include "distributed-arp-table.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020042#include "gateway_client.h"
43#include "icmp_socket.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020044#include "log.h"
Linus Lüssing4e3e8232016-05-10 18:41:27 +020045#include "multicast.h"
Martin Hundebølld56b1702013-01-25 11:12:39 +010046#include "network-coding.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020047#include "originator.h"
48#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049
Sven Eckelmann9e466252012-05-12 18:33:50 +020050static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000051
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020052/**
53 * batadv_debugfs_deprecated() - Log use of deprecated batadv debugfs access
54 * @file: file which was accessed
55 * @alt: explanation what can be used as alternative
56 */
57void batadv_debugfs_deprecated(struct file *file, const char *alt)
58{
59 struct dentry *dentry = file_dentry(file);
60 const char *name = dentry->d_name.name;
61
62 pr_warn_ratelimited(DEPRECATED "%s (pid %d) Use of debugfs file \"%s\".\n%s",
63 current->comm, task_pid_nr(current), name, alt);
64}
65
Sven Eckelmann9e466252012-05-12 18:33:50 +020066static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +080067{
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020068 batadv_debugfs_deprecated(file,
69 "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n");
Sven Eckelmann3193e8f2012-05-12 02:09:42 +020070 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +080071}
72
Marek Lindner75874052015-08-04 21:09:57 +080073static int neighbors_open(struct inode *inode, struct file *file)
74{
75 struct net_device *net_dev = (struct net_device *)inode->i_private;
76
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020077 batadv_debugfs_deprecated(file,
78 "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n");
Marek Lindner75874052015-08-04 21:09:57 +080079 return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev);
80}
81
Sven Eckelmann9e466252012-05-12 18:33:50 +020082static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000083{
84 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +020085
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020086 batadv_debugfs_deprecated(file,
87 "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n");
Sven Eckelmann7d211ef2012-05-12 02:09:34 +020088 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000089}
90
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010091/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010092 * batadv_originators_hardif_open() - handles debugfs output for the originator
93 * table of an hard interface
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010094 * @inode: inode pointer to debugfs file
95 * @file: pointer to the seq_file
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +010096 *
97 * Return: 0 on success or negative error number in case of failure
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010098 */
99static int batadv_originators_hardif_open(struct inode *inode,
100 struct file *file)
101{
102 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200103
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200104 batadv_debugfs_deprecated(file,
105 "Use genl command BATADV_CMD_GET_HARDIFS instead\n");
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +0100106 return single_open(file, batadv_orig_hardif_seq_print_text, net_dev);
107}
108
Sven Eckelmann9e466252012-05-12 18:33:50 +0200109static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000110{
111 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200112
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200113 batadv_debugfs_deprecated(file,
114 "Use genl command BATADV_CMD_GET_GATEWAYS instead\n");
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200115 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000116}
117
Sven Eckelmann9e466252012-05-12 18:33:50 +0200118static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000119{
120 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200121
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200122 batadv_debugfs_deprecated(file,
123 "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n");
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200124 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000125}
126
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100127#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200128static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100129{
130 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200131
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200132 batadv_debugfs_deprecated(file,
133 "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n");
Sven Eckelmann08adf152012-05-12 13:38:47 +0200134 return single_open(file, batadv_bla_claim_table_seq_print_text,
135 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100136}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200137
138static int batadv_bla_backbone_table_open(struct inode *inode,
139 struct file *file)
140{
141 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200142
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200143 batadv_debugfs_deprecated(file,
144 "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n");
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200145 return single_open(file, batadv_bla_backbone_table_seq_print_text,
146 net_dev);
147}
148
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100149#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100150
Antonio Quartulli17224472011-11-06 12:23:55 +0100151#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200152/**
Sven Eckelmannbe01dc32018-07-05 14:42:49 +0200153 * batadv_dat_cache_open() - Prepare file handler for reads from dat_cache
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200154 * @inode: inode which was opened
155 * @file: file handle to be initialized
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +0100156 *
157 * Return: 0 on success or negative error number in case of failure
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200158 */
159static int batadv_dat_cache_open(struct inode *inode, struct file *file)
160{
161 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200162
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200163 batadv_debugfs_deprecated(file,
164 "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n");
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200165 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
166}
Antonio Quartulli17224472011-11-06 12:23:55 +0100167#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200168
Sven Eckelmann9e466252012-05-12 18:33:50 +0200169static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000170{
171 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200172
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200173 batadv_debugfs_deprecated(file,
174 "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n");
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200175 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000176}
177
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200178struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000179 struct attribute attr;
180 const struct file_operations fops;
181};
182
Martin Hundebølld56b1702013-01-25 11:12:39 +0100183#ifdef CONFIG_BATMAN_ADV_NC
184static int batadv_nc_nodes_open(struct inode *inode, struct file *file)
185{
186 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200187
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200188 batadv_debugfs_deprecated(file, "");
Martin Hundebølld56b1702013-01-25 11:12:39 +0100189 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
190}
191#endif
192
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200193#ifdef CONFIG_BATMAN_ADV_MCAST
194/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100195 * batadv_mcast_flags_open() - prepare file handler for reads from mcast_flags
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200196 * @inode: inode which was opened
197 * @file: file handle to be initialized
198 *
199 * Return: 0 on success or negative error number in case of failure
200 */
201static int batadv_mcast_flags_open(struct inode *inode, struct file *file)
202{
203 struct net_device *net_dev = (struct net_device *)inode->i_private;
204
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200205 batadv_debugfs_deprecated(file,
206 "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n");
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200207 return single_open(file, batadv_mcast_flags_seq_print_text, net_dev);
208}
209#endif
210
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200211#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200212struct batadv_debuginfo batadv_debuginfo_##_name = { \
Simon Wunderlich121bdca2016-03-11 14:01:11 +0100213 .attr = { \
214 .name = __stringify(_name), \
215 .mode = _mode, \
216 }, \
217 .fops = { \
218 .owner = THIS_MODULE, \
219 .open = _open, \
220 .read = seq_read, \
221 .llseek = seq_lseek, \
222 .release = single_release, \
223 }, \
Antonio Quartulli2b64df22014-05-15 11:24:26 +0200224}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000225
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200226/* the following attributes are general and therefore they will be directly
227 * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
228 */
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200229static BATADV_DEBUGINFO(routing_algos, 0444, batadv_algorithms_open);
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200230
231static struct batadv_debuginfo *batadv_general_debuginfos[] = {
232 &batadv_debuginfo_routing_algos,
233 NULL,
234};
235
236/* The following attributes are per soft interface */
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200237static BATADV_DEBUGINFO(neighbors, 0444, neighbors_open);
238static BATADV_DEBUGINFO(originators, 0444, batadv_originators_open);
239static BATADV_DEBUGINFO(gateways, 0444, batadv_gateways_open);
240static BATADV_DEBUGINFO(transtable_global, 0444, batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100241#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200242static BATADV_DEBUGINFO(bla_claim_table, 0444, batadv_bla_claim_table_open);
243static BATADV_DEBUGINFO(bla_backbone_table, 0444,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200244 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100245#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100246#ifdef CONFIG_BATMAN_ADV_DAT
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200247static BATADV_DEBUGINFO(dat_cache, 0444, batadv_dat_cache_open);
Antonio Quartulli17224472011-11-06 12:23:55 +0100248#endif
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200249static BATADV_DEBUGINFO(transtable_local, 0444, batadv_transtable_local_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100250#ifdef CONFIG_BATMAN_ADV_NC
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200251static BATADV_DEBUGINFO(nc_nodes, 0444, batadv_nc_nodes_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100252#endif
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200253#ifdef CONFIG_BATMAN_ADV_MCAST
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200254static BATADV_DEBUGINFO(mcast_flags, 0444, batadv_mcast_flags_open);
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200255#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000256
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200257static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Marek Lindner75874052015-08-04 21:09:57 +0800258 &batadv_debuginfo_neighbors,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200259 &batadv_debuginfo_originators,
260 &batadv_debuginfo_gateways,
261 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100262#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200263 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200264 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100265#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100266#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200267 &batadv_debuginfo_dat_cache,
Antonio Quartulli17224472011-11-06 12:23:55 +0100268#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200269 &batadv_debuginfo_transtable_local,
Martin Hundebølld56b1702013-01-25 11:12:39 +0100270#ifdef CONFIG_BATMAN_ADV_NC
271 &batadv_debuginfo_nc_nodes,
272#endif
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200273#ifdef CONFIG_BATMAN_ADV_MCAST
274 &batadv_debuginfo_mcast_flags,
275#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000276 NULL,
277};
278
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100279#define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open) \
280struct batadv_debuginfo batadv_hardif_debuginfo_##_name = { \
281 .attr = { \
282 .name = __stringify(_name), \
283 .mode = _mode, \
284 }, \
285 .fops = { \
286 .owner = THIS_MODULE, \
287 .open = _open, \
288 .read = seq_read, \
289 .llseek = seq_lseek, \
290 .release = single_release, \
291 }, \
Antonio Quartulli2b64df22014-05-15 11:24:26 +0200292}
Antonio Quartulliaa143d22014-09-01 14:37:27 +0200293
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200294static BATADV_HARDIF_DEBUGINFO(originators, 0444,
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +0100295 batadv_originators_hardif_open);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100296
297static struct batadv_debuginfo *batadv_hardif_debuginfos[] = {
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +0100298 &batadv_hardif_debuginfo_originators,
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100299 NULL,
300};
301
Sven Eckelmannff15c272017-12-02 19:51:53 +0100302/**
303 * batadv_debugfs_init() - Initialize soft interface independent debugfs entries
304 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200305void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000306{
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200307 struct batadv_debuginfo **bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800308 struct dentry *file;
309
Sven Eckelmann54590e42012-06-03 22:19:08 +0200310 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200311 if (batadv_debugfs == ERR_PTR(-ENODEV))
312 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800313
Sven Eckelmann9e466252012-05-12 18:33:50 +0200314 if (!batadv_debugfs)
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200315 goto err;
Marek Lindner1c280472011-11-28 17:40:17 +0800316
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200317 for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
318 file = debugfs_create_file(((*bat_debug)->attr).name,
319 S_IFREG | ((*bat_debug)->attr).mode,
320 batadv_debugfs, NULL,
321 &(*bat_debug)->fops);
322 if (!file) {
323 pr_err("Can't add general debugfs file: %s\n",
324 ((*bat_debug)->attr).name);
325 goto err;
326 }
327 }
Marek Lindner1c280472011-11-28 17:40:17 +0800328
Marek Lindner1c280472011-11-28 17:40:17 +0800329 return;
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200330err:
331 debugfs_remove_recursive(batadv_debugfs);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100332 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000333}
334
Sven Eckelmannff15c272017-12-02 19:51:53 +0100335/**
336 * batadv_debugfs_destroy() - Remove all debugfs entries
337 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200338void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000339{
Antonio Quartulli3f87c422012-11-29 01:03:31 +0100340 debugfs_remove_recursive(batadv_debugfs);
341 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000342}
343
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100344/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100345 * batadv_debugfs_add_hardif() - creates the base directory for a hard interface
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100346 * in debugfs.
347 * @hard_iface: hard interface which should be added.
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +0100348 *
349 * Return: 0 on success or negative error number in case of failure
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100350 */
351int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
352{
Andrew Lunn94969202016-07-03 13:31:34 +0200353 struct net *net = dev_net(hard_iface->net_dev);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100354 struct batadv_debuginfo **bat_debug;
355 struct dentry *file;
356
357 if (!batadv_debugfs)
358 goto out;
359
Andrew Lunn94969202016-07-03 13:31:34 +0200360 if (net != &init_net)
361 return 0;
362
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100363 hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name,
364 batadv_debugfs);
365 if (!hard_iface->debug_dir)
366 goto out;
367
368 for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) {
369 file = debugfs_create_file(((*bat_debug)->attr).name,
370 S_IFREG | ((*bat_debug)->attr).mode,
371 hard_iface->debug_dir,
372 hard_iface->net_dev,
373 &(*bat_debug)->fops);
374 if (!file)
375 goto rem_attr;
376 }
377
378 return 0;
379rem_attr:
380 debugfs_remove_recursive(hard_iface->debug_dir);
381 hard_iface->debug_dir = NULL;
382out:
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100383 return -ENOMEM;
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100384}
385
386/**
Sven Eckelmann36dc6212018-06-01 19:24:23 +0200387 * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif
388 * @hard_iface: hard interface which was renamed
389 */
390void batadv_debugfs_rename_hardif(struct batadv_hard_iface *hard_iface)
391{
392 const char *name = hard_iface->net_dev->name;
393 struct dentry *dir;
394 struct dentry *d;
395
396 dir = hard_iface->debug_dir;
397 if (!dir)
398 return;
399
400 d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
401 if (!d)
402 pr_err("Can't rename debugfs dir to %s\n", name);
403}
404
405/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100406 * batadv_debugfs_del_hardif() - delete the base directory for a hard interface
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100407 * in debugfs.
408 * @hard_iface: hard interface which is deleted.
409 */
410void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
411{
Andrew Lunn94969202016-07-03 13:31:34 +0200412 struct net *net = dev_net(hard_iface->net_dev);
413
414 if (net != &init_net)
415 return;
416
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100417 if (batadv_debugfs) {
418 debugfs_remove_recursive(hard_iface->debug_dir);
419 hard_iface->debug_dir = NULL;
420 }
421}
422
Sven Eckelmannff15c272017-12-02 19:51:53 +0100423/**
424 * batadv_debugfs_add_meshif() - Initialize interface dependent debugfs entries
425 * @dev: netdev struct of the soft interface
426 *
427 * Return: 0 on success or negative error number in case of failure
428 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200429int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000430{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200431 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200432 struct batadv_debuginfo **bat_debug;
Andrew Lunn94969202016-07-03 13:31:34 +0200433 struct net *net = dev_net(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000434 struct dentry *file;
435
Sven Eckelmann9e466252012-05-12 18:33:50 +0200436 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000437 goto out;
438
Andrew Lunn94969202016-07-03 13:31:34 +0200439 if (net != &init_net)
440 return 0;
441
Sven Eckelmann9e466252012-05-12 18:33:50 +0200442 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000443 if (!bat_priv->debug_dir)
444 goto out;
445
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200446 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200447 goto rem_attr;
448
Sven Eckelmann9e466252012-05-12 18:33:50 +0200449 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200450 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000451
Sven Eckelmann9e466252012-05-12 18:33:50 +0200452 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000453 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200454 S_IFREG | ((*bat_debug)->attr).mode,
455 bat_priv->debug_dir,
456 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000457 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200458 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
459 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000460 goto rem_attr;
461 }
462 }
463
Martin Hundebølld56b1702013-01-25 11:12:39 +0100464 if (batadv_nc_init_debugfs(bat_priv) < 0)
465 goto rem_attr;
466
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467 return 0;
468rem_attr:
469 debugfs_remove_recursive(bat_priv->debug_dir);
470 bat_priv->debug_dir = NULL;
471out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000472 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000473}
474
Sven Eckelmannff15c272017-12-02 19:51:53 +0100475/**
Sven Eckelmann6da7be72018-06-01 19:24:24 +0200476 * batadv_debugfs_rename_meshif() - Fix debugfs path for renamed softif
477 * @dev: net_device which was renamed
478 */
479void batadv_debugfs_rename_meshif(struct net_device *dev)
480{
481 struct batadv_priv *bat_priv = netdev_priv(dev);
482 const char *name = dev->name;
483 struct dentry *dir;
484 struct dentry *d;
485
486 dir = bat_priv->debug_dir;
487 if (!dir)
488 return;
489
490 d = debugfs_rename(dir->d_parent, dir, dir->d_parent, name);
491 if (!d)
492 pr_err("Can't rename debugfs dir to %s\n", name);
493}
494
495/**
Sven Eckelmannff15c272017-12-02 19:51:53 +0100496 * batadv_debugfs_del_meshif() - Remove interface dependent debugfs entries
497 * @dev: netdev struct of the soft interface
498 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200499void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000500{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200501 struct batadv_priv *bat_priv = netdev_priv(dev);
Andrew Lunn94969202016-07-03 13:31:34 +0200502 struct net *net = dev_net(dev);
503
504 if (net != &init_net)
505 return;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000506
Sven Eckelmann9e466252012-05-12 18:33:50 +0200507 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000508
Sven Eckelmann9e466252012-05-12 18:33:50 +0200509 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000510 debugfs_remove_recursive(bat_priv->debug_dir);
511 bat_priv->debug_dir = NULL;
512 }
513}