blob: 049a7a2ac5b69b83422a3292ee7ebb2183e36114 [file] [log] [blame]
Antonio Quartulli0b873932013-01-04 03:05:31 +01001/* Copyright (C) 2010-2013 B.A.T.M.A.N. contributors:
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +00002 *
3 * Marek Lindner
4 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of version 2 of the GNU General Public
7 * License as published by the Free Software Foundation.
8 *
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
17 * 02110-1301, USA
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000018 */
19
20#include "main.h"
21
22#include <linux/debugfs.h>
23
Sven Eckelmannb706b132012-06-10 23:58:51 +020024#include "debugfs.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000025#include "translation-table.h"
26#include "originator.h"
27#include "hard-interface.h"
28#include "gateway_common.h"
29#include "gateway_client.h"
30#include "soft-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000031#include "icmp_socket.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010032#include "bridge_loop_avoidance.h"
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020033#include "distributed-arp-table.h"
Martin Hundebølld56b1702013-01-25 11:12:39 +010034#include "network-coding.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000035
Sven Eckelmann9e466252012-05-12 18:33:50 +020036static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000037
38#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann347c80f2012-06-03 22:19:07 +020039#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000040
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020041static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
42
Marek Lindner0abf5d82012-12-25 17:03:20 +080043static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log,
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020044 size_t idx)
45{
46 return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
47}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000048
Marek Lindner0abf5d82012-12-25 17:03:20 +080049static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log,
50 char c)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000051{
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020052 char *char_addr;
53
54 char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
55 *char_addr = c;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000056 debug_log->log_end++;
57
Sven Eckelmann9e466252012-05-12 18:33:50 +020058 if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
59 debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000060}
61
Sven Eckelmannd3a547b2011-05-14 23:14:46 +020062__printf(2, 3)
Marek Lindner0abf5d82012-12-25 17:03:20 +080063static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
Sven Eckelmann56303d32012-06-05 22:31:31 +020064 const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000066 va_list args;
67 static char debug_log_buf[256];
68 char *p;
69
70 if (!debug_log)
71 return 0;
72
73 spin_lock_bh(&debug_log->lock);
74 va_start(args, fmt);
Sven Eckelmann1299bda2011-01-27 13:48:54 +010075 vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000076 va_end(args);
77
78 for (p = debug_log_buf; *p != 0; p++)
Sven Eckelmann9e466252012-05-12 18:33:50 +020079 batadv_emit_log_char(debug_log, *p);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000080
81 spin_unlock_bh(&debug_log->lock);
82
83 wake_up(&debug_log->queue_wait);
84
85 return 0;
86}
87
Sven Eckelmann56303d32012-06-05 22:31:31 +020088int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000089{
90 va_list args;
91 char tmp_log_buf[256];
92
93 va_start(args, fmt);
94 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
Sven Eckelmann9e466252012-05-12 18:33:50 +020095 batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
96 jiffies_to_msecs(jiffies), tmp_log_buf);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000097 va_end(args);
98
99 return 0;
100}
101
Sven Eckelmann9e466252012-05-12 18:33:50 +0200102static int batadv_log_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000103{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200104 if (!try_module_get(THIS_MODULE))
105 return -EBUSY;
106
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000107 nonseekable_open(inode, file);
108 file->private_data = inode->i_private;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000109 return 0;
110}
111
Sven Eckelmann9e466252012-05-12 18:33:50 +0200112static int batadv_log_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200114 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000115 return 0;
116}
117
Marek Lindner0abf5d82012-12-25 17:03:20 +0800118static int batadv_log_empty(struct batadv_priv_debug_log *debug_log)
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200119{
120 return !(debug_log->log_start - debug_log->log_end);
121}
122
Sven Eckelmann9e466252012-05-12 18:33:50 +0200123static ssize_t batadv_log_read(struct file *file, char __user *buf,
124 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000125{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200126 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800127 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000128 int error, i = 0;
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200129 char *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000130 char c;
131
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200132 if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000133 return -EAGAIN;
134
Sven Eckelmann16f14b42011-05-14 23:14:48 +0200135 if (!buf)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000136 return -EINVAL;
137
138 if (count == 0)
139 return 0;
140
141 if (!access_ok(VERIFY_WRITE, buf, count))
142 return -EFAULT;
143
144 error = wait_event_interruptible(debug_log->queue_wait,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200145 (!batadv_log_empty(debug_log)));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000146
147 if (error)
148 return error;
149
150 spin_lock_bh(&debug_log->lock);
151
152 while ((!error) && (i < count) &&
153 (debug_log->log_start != debug_log->log_end)) {
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200154 char_addr = batadv_log_char_addr(debug_log,
155 debug_log->log_start);
156 c = *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000157
158 debug_log->log_start++;
159
160 spin_unlock_bh(&debug_log->lock);
161
162 error = __put_user(c, buf);
163
164 spin_lock_bh(&debug_log->lock);
165
166 buf++;
167 i++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000168 }
169
170 spin_unlock_bh(&debug_log->lock);
171
172 if (!error)
173 return i;
174
175 return error;
176}
177
Sven Eckelmann9e466252012-05-12 18:33:50 +0200178static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000179{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200180 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800181 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000182
183 poll_wait(file, &debug_log->queue_wait, wait);
184
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200185 if (!batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000186 return POLLIN | POLLRDNORM;
187
188 return 0;
189}
190
Sven Eckelmann9e466252012-05-12 18:33:50 +0200191static const struct file_operations batadv_log_fops = {
192 .open = batadv_log_open,
193 .release = batadv_log_release,
194 .read = batadv_log_read,
195 .poll = batadv_log_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000196 .llseek = no_llseek,
197};
198
Sven Eckelmann56303d32012-06-05 22:31:31 +0200199static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000200{
201 struct dentry *d;
202
203 if (!bat_priv->debug_dir)
204 goto err;
205
Sven Eckelmann704509b2011-05-14 23:14:54 +0200206 bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000207 if (!bat_priv->debug_log)
208 goto err;
209
210 spin_lock_init(&bat_priv->debug_log->lock);
211 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
212
213 d = debugfs_create_file("log", S_IFREG | S_IRUSR,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200214 bat_priv->debug_dir, bat_priv,
215 &batadv_log_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200216 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000217 goto err;
218
219 return 0;
220
221err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200222 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000223}
224
Sven Eckelmann56303d32012-06-05 22:31:31 +0200225static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000226{
227 kfree(bat_priv->debug_log);
228 bat_priv->debug_log = NULL;
229}
230#else /* CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200231static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000232{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000233 return 0;
234}
235
Sven Eckelmann56303d32012-06-05 22:31:31 +0200236static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000237{
238 return;
239}
240#endif
241
Sven Eckelmann9e466252012-05-12 18:33:50 +0200242static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +0800243{
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200244 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +0800245}
246
Sven Eckelmann9e466252012-05-12 18:33:50 +0200247static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000248{
249 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200250 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000251}
252
Sven Eckelmann9e466252012-05-12 18:33:50 +0200253static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000254{
255 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200256 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000257}
258
Sven Eckelmann9e466252012-05-12 18:33:50 +0200259static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000260{
261 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200262 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000263}
264
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100265#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200266static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100267{
268 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08adf152012-05-12 13:38:47 +0200269 return single_open(file, batadv_bla_claim_table_seq_print_text,
270 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100271}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200272
273static int batadv_bla_backbone_table_open(struct inode *inode,
274 struct file *file)
275{
276 struct net_device *net_dev = (struct net_device *)inode->i_private;
277 return single_open(file, batadv_bla_backbone_table_seq_print_text,
278 net_dev);
279}
280
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100281#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100282
Antonio Quartulli17224472011-11-06 12:23:55 +0100283#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200284/**
285 * batadv_dat_cache_open - Prepare file handler for reads from dat_chache
286 * @inode: inode which was opened
287 * @file: file handle to be initialized
288 */
289static int batadv_dat_cache_open(struct inode *inode, struct file *file)
290{
291 struct net_device *net_dev = (struct net_device *)inode->i_private;
292 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
293}
Antonio Quartulli17224472011-11-06 12:23:55 +0100294#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200295
Sven Eckelmann9e466252012-05-12 18:33:50 +0200296static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000297{
298 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200299 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000300}
301
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200302struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000303 struct attribute attr;
304 const struct file_operations fops;
305};
306
Martin Hundebølld56b1702013-01-25 11:12:39 +0100307#ifdef CONFIG_BATMAN_ADV_NC
308static int batadv_nc_nodes_open(struct inode *inode, struct file *file)
309{
310 struct net_device *net_dev = (struct net_device *)inode->i_private;
311 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
312}
313#endif
314
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200315#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200316struct batadv_debuginfo batadv_debuginfo_##_name = { \
Sven Eckelmann9e466252012-05-12 18:33:50 +0200317 .attr = { .name = __stringify(_name), \
318 .mode = _mode, }, \
319 .fops = { .owner = THIS_MODULE, \
320 .open = _open, \
321 .read = seq_read, \
322 .llseek = seq_lseek, \
323 .release = single_release, \
324 } \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000325};
326
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200327/* the following attributes are general and therefore they will be directly
328 * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
329 */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200330static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200331
332static struct batadv_debuginfo *batadv_general_debuginfos[] = {
333 &batadv_debuginfo_routing_algos,
334 NULL,
335};
336
337/* The following attributes are per soft interface */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200338static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
339static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
340static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
341 batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100342#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200343static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open);
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200344static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO,
345 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100346#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100347#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200348static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open);
Antonio Quartulli17224472011-11-06 12:23:55 +0100349#endif
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200350static BATADV_DEBUGINFO(transtable_local, S_IRUGO,
351 batadv_transtable_local_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100352#ifdef CONFIG_BATMAN_ADV_NC
353static BATADV_DEBUGINFO(nc_nodes, S_IRUGO, batadv_nc_nodes_open);
354#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000355
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200356static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Sven Eckelmann9e466252012-05-12 18:33:50 +0200357 &batadv_debuginfo_originators,
358 &batadv_debuginfo_gateways,
359 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100360#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200361 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200362 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100363#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100364#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200365 &batadv_debuginfo_dat_cache,
Antonio Quartulli17224472011-11-06 12:23:55 +0100366#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200367 &batadv_debuginfo_transtable_local,
Martin Hundebølld56b1702013-01-25 11:12:39 +0100368#ifdef CONFIG_BATMAN_ADV_NC
369 &batadv_debuginfo_nc_nodes,
370#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000371 NULL,
372};
373
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200374void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000375{
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200376 struct batadv_debuginfo **bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800377 struct dentry *file;
378
Sven Eckelmann54590e42012-06-03 22:19:08 +0200379 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200380 if (batadv_debugfs == ERR_PTR(-ENODEV))
381 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800382
Sven Eckelmann9e466252012-05-12 18:33:50 +0200383 if (!batadv_debugfs)
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200384 goto err;
Marek Lindner1c280472011-11-28 17:40:17 +0800385
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200386 for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
387 file = debugfs_create_file(((*bat_debug)->attr).name,
388 S_IFREG | ((*bat_debug)->attr).mode,
389 batadv_debugfs, NULL,
390 &(*bat_debug)->fops);
391 if (!file) {
392 pr_err("Can't add general debugfs file: %s\n",
393 ((*bat_debug)->attr).name);
394 goto err;
395 }
396 }
Marek Lindner1c280472011-11-28 17:40:17 +0800397
Marek Lindner1c280472011-11-28 17:40:17 +0800398 return;
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200399err:
400 debugfs_remove_recursive(batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000401}
402
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200403void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000404{
Antonio Quartulli3f87c422012-11-29 01:03:31 +0100405 debugfs_remove_recursive(batadv_debugfs);
406 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000407}
408
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200409int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000410{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200411 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200412 struct batadv_debuginfo **bat_debug;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000413 struct dentry *file;
414
Sven Eckelmann9e466252012-05-12 18:33:50 +0200415 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000416 goto out;
417
Sven Eckelmann9e466252012-05-12 18:33:50 +0200418 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000419 if (!bat_priv->debug_dir)
420 goto out;
421
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200422 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200423 goto rem_attr;
424
Sven Eckelmann9e466252012-05-12 18:33:50 +0200425 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200426 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000427
Sven Eckelmann9e466252012-05-12 18:33:50 +0200428 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000429 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200430 S_IFREG | ((*bat_debug)->attr).mode,
431 bat_priv->debug_dir,
432 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000433 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200434 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
435 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000436 goto rem_attr;
437 }
438 }
439
Martin Hundebølld56b1702013-01-25 11:12:39 +0100440 if (batadv_nc_init_debugfs(bat_priv) < 0)
441 goto rem_attr;
442
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000443 return 0;
444rem_attr:
445 debugfs_remove_recursive(bat_priv->debug_dir);
446 bat_priv->debug_dir = NULL;
447out:
448#ifdef CONFIG_DEBUG_FS
449 return -ENOMEM;
450#else
451 return 0;
452#endif /* CONFIG_DEBUG_FS */
453}
454
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200455void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000456{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200457 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000458
Sven Eckelmann9e466252012-05-12 18:33:50 +0200459 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000460
Sven Eckelmann9e466252012-05-12 18:33:50 +0200461 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000462 debugfs_remove_recursive(bat_priv->debug_dir);
463 bat_priv->debug_dir = NULL;
464 }
465}