blob: d38d70ccdd5ae8aab3afa87b38c7f498a9d5f826 [file] [log] [blame]
Sven Eckelmann7db7d9f2017-11-19 15:05:11 +01001// SPDX-License-Identifier: GPL-2.0
Sven Eckelmann7a79d712018-12-31 23:59:59 +01002/* Copyright (C) 2010-2019 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00003 *
4 * Marek Lindner
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00005 */
6
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +02007#include "debugfs.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00008#include "main.h"
9
Sven Eckelmanna5dac4d2018-10-21 11:30:29 +020010#include <asm/current.h>
Sven Eckelmann36dc6212018-06-01 19:24:23 +020011#include <linux/dcache.h>
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000012#include <linux/debugfs.h>
Sven Eckelmann3e7514a2017-01-28 10:23:30 +010013#include <linux/err.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020014#include <linux/errno.h>
15#include <linux/export.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020016#include <linux/fs.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020017#include <linux/netdevice.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020018#include <linux/printk.h>
Sven Eckelmanna5dac4d2018-10-21 11:30:29 +020019#include <linux/sched.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020020#include <linux/seq_file.h>
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020021#include <linux/stat.h>
22#include <linux/stddef.h>
23#include <linux/stringify.h>
24#include <linux/sysfs.h>
Andrew Lunn94969202016-07-03 13:31:34 +020025#include <net/net_namespace.h>
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000026
Sven Eckelmann01d350d2016-05-15 11:07:44 +020027#include "bat_algo.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010028#include "bridge_loop_avoidance.h"
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020029#include "distributed-arp-table.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020030#include "gateway_client.h"
31#include "icmp_socket.h"
Sven Eckelmannba412082016-05-15 23:48:31 +020032#include "log.h"
Linus Lüssing4e3e8232016-05-10 18:41:27 +020033#include "multicast.h"
Martin Hundebølld56b1702013-01-25 11:12:39 +010034#include "network-coding.h"
Sven Eckelmann1e2c2a42015-04-17 19:40:28 +020035#include "originator.h"
36#include "translation-table.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000037
Sven Eckelmann9e466252012-05-12 18:33:50 +020038static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000039
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020040/**
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 */
45void 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 Eckelmann9e466252012-05-12 18:33:50 +020054static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +080055{
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020056 batadv_debugfs_deprecated(file,
57 "Use genl command BATADV_CMD_GET_ROUTING_ALGOS instead\n");
Sven Eckelmann3193e8f2012-05-12 02:09:42 +020058 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +080059}
60
Marek Lindner75874052015-08-04 21:09:57 +080061static int neighbors_open(struct inode *inode, struct file *file)
62{
63 struct net_device *net_dev = (struct net_device *)inode->i_private;
64
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020065 batadv_debugfs_deprecated(file,
66 "Use genl command BATADV_CMD_GET_NEIGHBORS instead\n");
Marek Lindner75874052015-08-04 21:09:57 +080067 return single_open(file, batadv_hardif_neigh_seq_print_text, net_dev);
68}
69
Sven Eckelmann9e466252012-05-12 18:33:50 +020070static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000071{
72 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +020073
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020074 batadv_debugfs_deprecated(file,
75 "Use genl command BATADV_CMD_GET_ORIGINATORS instead\n");
Sven Eckelmann7d211ef2012-05-12 02:09:34 +020076 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077}
78
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010079/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +010080 * batadv_originators_hardif_open() - handles debugfs output for the originator
81 * table of an hard interface
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010082 * @inode: inode pointer to debugfs file
83 * @file: pointer to the seq_file
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +010084 *
85 * Return: 0 on success or negative error number in case of failure
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010086 */
87static 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 Quartullif1386942014-05-10 18:56:37 +020091
Sven Eckelmann00caf6a2018-08-10 23:36:15 +020092 batadv_debugfs_deprecated(file,
93 "Use genl command BATADV_CMD_GET_HARDIFS instead\n");
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +010094 return single_open(file, batadv_orig_hardif_seq_print_text, net_dev);
95}
96
Sven Eckelmann9e466252012-05-12 18:33:50 +020097static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000098{
99 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200100
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200101 batadv_debugfs_deprecated(file,
102 "Use genl command BATADV_CMD_GET_GATEWAYS instead\n");
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200103 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000104}
105
Sven Eckelmann9e466252012-05-12 18:33:50 +0200106static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000107{
108 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200109
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200110 batadv_debugfs_deprecated(file,
111 "Use genl command BATADV_CMD_GET_TRANSTABLE_GLOBAL instead\n");
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200112 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113}
114
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100115#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200116static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100117{
118 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200119
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200120 batadv_debugfs_deprecated(file,
121 "Use genl command BATADV_CMD_GET_BLA_CLAIM instead\n");
Sven Eckelmann08adf152012-05-12 13:38:47 +0200122 return single_open(file, batadv_bla_claim_table_seq_print_text,
123 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100124}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200125
126static 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 Quartullif1386942014-05-10 18:56:37 +0200130
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200131 batadv_debugfs_deprecated(file,
132 "Use genl command BATADV_CMD_GET_BLA_BACKBONE instead\n");
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200133 return single_open(file, batadv_bla_backbone_table_seq_print_text,
134 net_dev);
135}
136
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100137#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100138
Antonio Quartulli17224472011-11-06 12:23:55 +0100139#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200140/**
Sven Eckelmannbe01dc32018-07-05 14:42:49 +0200141 * batadv_dat_cache_open() - Prepare file handler for reads from dat_cache
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200142 * @inode: inode which was opened
143 * @file: file handle to be initialized
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +0100144 *
145 * Return: 0 on success or negative error number in case of failure
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200146 */
147static 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 Quartullif1386942014-05-10 18:56:37 +0200150
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200151 batadv_debugfs_deprecated(file,
152 "Use genl command BATADV_CMD_GET_DAT_CACHE instead\n");
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200153 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
154}
Antonio Quartulli17224472011-11-06 12:23:55 +0100155#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200156
Sven Eckelmann9e466252012-05-12 18:33:50 +0200157static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000158{
159 struct net_device *net_dev = (struct net_device *)inode->i_private;
Antonio Quartullif1386942014-05-10 18:56:37 +0200160
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200161 batadv_debugfs_deprecated(file,
162 "Use genl command BATADV_CMD_GET_TRANSTABLE_LOCAL instead\n");
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200163 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000164}
165
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200166struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000167 struct attribute attr;
168 const struct file_operations fops;
169};
170
Martin Hundebølld56b1702013-01-25 11:12:39 +0100171#ifdef CONFIG_BATMAN_ADV_NC
172static 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 Quartullif1386942014-05-10 18:56:37 +0200175
Sven Eckelmann00caf6a2018-08-10 23:36:15 +0200176 batadv_debugfs_deprecated(file, "");
Martin Hundebølld56b1702013-01-25 11:12:39 +0100177 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
178}
179#endif
180
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200181#ifdef CONFIG_BATMAN_ADV_MCAST
182/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100183 * batadv_mcast_flags_open() - prepare file handler for reads from mcast_flags
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200184 * @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 */
189static 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 Eckelmann00caf6a2018-08-10 23:36:15 +0200193 batadv_debugfs_deprecated(file,
194 "Use genl command BATADV_CMD_GET_MCAST_FLAGS instead\n");
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200195 return single_open(file, batadv_mcast_flags_seq_print_text, net_dev);
196}
197#endif
198
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200199#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200200struct batadv_debuginfo batadv_debuginfo_##_name = { \
Simon Wunderlich121bdca2016-03-11 14:01:11 +0100201 .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 Quartulli2b64df22014-05-15 11:24:26 +0200212}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000213
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200214/* the following attributes are general and therefore they will be directly
215 * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
216 */
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200217static BATADV_DEBUGINFO(routing_algos, 0444, batadv_algorithms_open);
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200218
219static struct batadv_debuginfo *batadv_general_debuginfos[] = {
220 &batadv_debuginfo_routing_algos,
221 NULL,
222};
223
224/* The following attributes are per soft interface */
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200225static BATADV_DEBUGINFO(neighbors, 0444, neighbors_open);
226static BATADV_DEBUGINFO(originators, 0444, batadv_originators_open);
227static BATADV_DEBUGINFO(gateways, 0444, batadv_gateways_open);
228static BATADV_DEBUGINFO(transtable_global, 0444, batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100229#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200230static BATADV_DEBUGINFO(bla_claim_table, 0444, batadv_bla_claim_table_open);
231static BATADV_DEBUGINFO(bla_backbone_table, 0444,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200232 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100233#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100234#ifdef CONFIG_BATMAN_ADV_DAT
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200235static BATADV_DEBUGINFO(dat_cache, 0444, batadv_dat_cache_open);
Antonio Quartulli17224472011-11-06 12:23:55 +0100236#endif
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200237static BATADV_DEBUGINFO(transtable_local, 0444, batadv_transtable_local_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100238#ifdef CONFIG_BATMAN_ADV_NC
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200239static BATADV_DEBUGINFO(nc_nodes, 0444, batadv_nc_nodes_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100240#endif
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200241#ifdef CONFIG_BATMAN_ADV_MCAST
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200242static BATADV_DEBUGINFO(mcast_flags, 0444, batadv_mcast_flags_open);
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200243#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000244
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200245static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Marek Lindner75874052015-08-04 21:09:57 +0800246 &batadv_debuginfo_neighbors,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200247 &batadv_debuginfo_originators,
248 &batadv_debuginfo_gateways,
249 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100250#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200251 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200252 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100253#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100254#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200255 &batadv_debuginfo_dat_cache,
Antonio Quartulli17224472011-11-06 12:23:55 +0100256#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200257 &batadv_debuginfo_transtable_local,
Martin Hundebølld56b1702013-01-25 11:12:39 +0100258#ifdef CONFIG_BATMAN_ADV_NC
259 &batadv_debuginfo_nc_nodes,
260#endif
Linus Lüssing4e3e8232016-05-10 18:41:27 +0200261#ifdef CONFIG_BATMAN_ADV_MCAST
262 &batadv_debuginfo_mcast_flags,
263#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000264 NULL,
265};
266
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100267#define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open) \
268struct 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 Quartulli2b64df22014-05-15 11:24:26 +0200280}
Antonio Quartulliaa143d22014-09-01 14:37:27 +0200281
Sven Eckelmann507b37c2016-09-01 10:25:12 +0200282static BATADV_HARDIF_DEBUGINFO(originators, 0444,
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +0100283 batadv_originators_hardif_open);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100284
285static struct batadv_debuginfo *batadv_hardif_debuginfos[] = {
Simon Wunderlichcb1c92e2013-11-21 11:52:16 +0100286 &batadv_hardif_debuginfo_originators,
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100287 NULL,
288};
289
Sven Eckelmannff15c272017-12-02 19:51:53 +0100290/**
291 * batadv_debugfs_init() - Initialize soft interface independent debugfs entries
292 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200293void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000294{
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200295 struct batadv_debuginfo **bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800296 struct dentry *file;
297
Sven Eckelmann54590e42012-06-03 22:19:08 +0200298 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200299 if (batadv_debugfs == ERR_PTR(-ENODEV))
300 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800301
Sven Eckelmann9e466252012-05-12 18:33:50 +0200302 if (!batadv_debugfs)
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200303 goto err;
Marek Lindner1c280472011-11-28 17:40:17 +0800304
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200305 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 Lindner1c280472011-11-28 17:40:17 +0800316
Marek Lindner1c280472011-11-28 17:40:17 +0800317 return;
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200318err:
319 debugfs_remove_recursive(batadv_debugfs);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100320 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000321}
322
Sven Eckelmannff15c272017-12-02 19:51:53 +0100323/**
324 * batadv_debugfs_destroy() - Remove all debugfs entries
325 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200326void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000327{
Antonio Quartulli3f87c422012-11-29 01:03:31 +0100328 debugfs_remove_recursive(batadv_debugfs);
329 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000330}
331
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100332/**
Sven Eckelmann7e9a8c22017-12-02 19:51:47 +0100333 * batadv_debugfs_add_hardif() - creates the base directory for a hard interface
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100334 * in debugfs.
335 * @hard_iface: hard interface which should be added.
Sven Eckelmann7afcbbe2015-10-31 12:29:29 +0100336 *
337 * Return: 0 on success or negative error number in case of failure
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100338 */
339int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface)
340{
Andrew Lunn94969202016-07-03 13:31:34 +0200341 struct net *net = dev_net(hard_iface->net_dev);
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100342 struct batadv_debuginfo **bat_debug;
343 struct dentry *file;
344
345 if (!batadv_debugfs)
346 goto out;
347
Andrew Lunn94969202016-07-03 13:31:34 +0200348 if (net != &init_net)
349 return 0;
350
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100351 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;
367rem_attr:
368 debugfs_remove_recursive(hard_iface->debug_dir);
369 hard_iface->debug_dir = NULL;
370out:
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100371 return -ENOMEM;
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100372}
373
374/**
Sven Eckelmann36dc6212018-06-01 19:24:23 +0200375 * batadv_debugfs_rename_hardif() - Fix debugfs path for renamed hardif
376 * @hard_iface: hard interface which was renamed
377 */
378void 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 Eckelmann7e9a8c22017-12-02 19:51:47 +0100394 * batadv_debugfs_del_hardif() - delete the base directory for a hard interface
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100395 * in debugfs.
396 * @hard_iface: hard interface which is deleted.
397 */
398void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface)
399{
Andrew Lunn94969202016-07-03 13:31:34 +0200400 struct net *net = dev_net(hard_iface->net_dev);
401
402 if (net != &init_net)
403 return;
404
Simon Wunderlich5bc7c1e2013-11-21 14:16:12 +0100405 if (batadv_debugfs) {
406 debugfs_remove_recursive(hard_iface->debug_dir);
407 hard_iface->debug_dir = NULL;
408 }
409}
410
Sven Eckelmannff15c272017-12-02 19:51:53 +0100411/**
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 Eckelmann40a072d2012-05-12 02:09:23 +0200417int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000418{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200419 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200420 struct batadv_debuginfo **bat_debug;
Andrew Lunn94969202016-07-03 13:31:34 +0200421 struct net *net = dev_net(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000422 struct dentry *file;
423
Sven Eckelmann9e466252012-05-12 18:33:50 +0200424 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000425 goto out;
426
Andrew Lunn94969202016-07-03 13:31:34 +0200427 if (net != &init_net)
428 return 0;
429
Sven Eckelmann9e466252012-05-12 18:33:50 +0200430 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000431 if (!bat_priv->debug_dir)
432 goto out;
433
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200434 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200435 goto rem_attr;
436
Sven Eckelmann9e466252012-05-12 18:33:50 +0200437 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200438 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000439
Sven Eckelmann9e466252012-05-12 18:33:50 +0200440 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000441 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200442 S_IFREG | ((*bat_debug)->attr).mode,
443 bat_priv->debug_dir,
444 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000445 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200446 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
447 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000448 goto rem_attr;
449 }
450 }
451
Martin Hundebølld56b1702013-01-25 11:12:39 +0100452 if (batadv_nc_init_debugfs(bat_priv) < 0)
453 goto rem_attr;
454
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000455 return 0;
456rem_attr:
457 debugfs_remove_recursive(bat_priv->debug_dir);
458 bat_priv->debug_dir = NULL;
459out:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000460 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000461}
462
Sven Eckelmannff15c272017-12-02 19:51:53 +0100463/**
Sven Eckelmann6da7be72018-06-01 19:24:24 +0200464 * batadv_debugfs_rename_meshif() - Fix debugfs path for renamed softif
465 * @dev: net_device which was renamed
466 */
467void 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 Eckelmannff15c272017-12-02 19:51:53 +0100484 * batadv_debugfs_del_meshif() - Remove interface dependent debugfs entries
485 * @dev: netdev struct of the soft interface
486 */
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200487void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000488{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200489 struct batadv_priv *bat_priv = netdev_priv(dev);
Andrew Lunn94969202016-07-03 13:31:34 +0200490 struct net *net = dev_net(dev);
491
492 if (net != &init_net)
493 return;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000494
Sven Eckelmann9e466252012-05-12 18:33:50 +0200495 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000496
Sven Eckelmann9e466252012-05-12 18:33:50 +0200497 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000498 debugfs_remove_recursive(bat_priv->debug_dir);
499 bat_priv->debug_dir = NULL;
500 }
501}