blob: f186a55b23c3fbd1eda3a2d5877b5b781fd647eb [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"
31#include "vis.h"
32#include "icmp_socket.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010033#include "bridge_loop_avoidance.h"
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020034#include "distributed-arp-table.h"
Martin Hundebølld56b1702013-01-25 11:12:39 +010035#include "network-coding.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000036
Sven Eckelmann9e466252012-05-12 18:33:50 +020037static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000038
39#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann347c80f2012-06-03 22:19:07 +020040#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000041
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020042static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
43
Marek Lindner0abf5d82012-12-25 17:03:20 +080044static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log,
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020045 size_t idx)
46{
47 return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
48}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049
Marek Lindner0abf5d82012-12-25 17:03:20 +080050static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log,
51 char c)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000052{
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020053 char *char_addr;
54
55 char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
56 *char_addr = c;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000057 debug_log->log_end++;
58
Sven Eckelmann9e466252012-05-12 18:33:50 +020059 if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
60 debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000061}
62
Sven Eckelmannd3a547b2011-05-14 23:14:46 +020063__printf(2, 3)
Marek Lindner0abf5d82012-12-25 17:03:20 +080064static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
Sven Eckelmann56303d32012-06-05 22:31:31 +020065 const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000066{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000067 va_list args;
68 static char debug_log_buf[256];
69 char *p;
70
71 if (!debug_log)
72 return 0;
73
74 spin_lock_bh(&debug_log->lock);
75 va_start(args, fmt);
Sven Eckelmann1299bda2011-01-27 13:48:54 +010076 vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000077 va_end(args);
78
79 for (p = debug_log_buf; *p != 0; p++)
Sven Eckelmann9e466252012-05-12 18:33:50 +020080 batadv_emit_log_char(debug_log, *p);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000081
82 spin_unlock_bh(&debug_log->lock);
83
84 wake_up(&debug_log->queue_wait);
85
86 return 0;
87}
88
Sven Eckelmann56303d32012-06-05 22:31:31 +020089int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000090{
91 va_list args;
92 char tmp_log_buf[256];
93
94 va_start(args, fmt);
95 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
Sven Eckelmann9e466252012-05-12 18:33:50 +020096 batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
97 jiffies_to_msecs(jiffies), tmp_log_buf);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000098 va_end(args);
99
100 return 0;
101}
102
Sven Eckelmann9e466252012-05-12 18:33:50 +0200103static int batadv_log_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000104{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200105 if (!try_module_get(THIS_MODULE))
106 return -EBUSY;
107
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000108 nonseekable_open(inode, file);
109 file->private_data = inode->i_private;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000110 return 0;
111}
112
Sven Eckelmann9e466252012-05-12 18:33:50 +0200113static int batadv_log_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000114{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200115 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000116 return 0;
117}
118
Marek Lindner0abf5d82012-12-25 17:03:20 +0800119static int batadv_log_empty(struct batadv_priv_debug_log *debug_log)
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200120{
121 return !(debug_log->log_start - debug_log->log_end);
122}
123
Sven Eckelmann9e466252012-05-12 18:33:50 +0200124static ssize_t batadv_log_read(struct file *file, char __user *buf,
125 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000126{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200127 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800128 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000129 int error, i = 0;
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200130 char *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000131 char c;
132
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200133 if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134 return -EAGAIN;
135
Sven Eckelmann16f14b42011-05-14 23:14:48 +0200136 if (!buf)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000137 return -EINVAL;
138
139 if (count == 0)
140 return 0;
141
142 if (!access_ok(VERIFY_WRITE, buf, count))
143 return -EFAULT;
144
145 error = wait_event_interruptible(debug_log->queue_wait,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200146 (!batadv_log_empty(debug_log)));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000147
148 if (error)
149 return error;
150
151 spin_lock_bh(&debug_log->lock);
152
153 while ((!error) && (i < count) &&
154 (debug_log->log_start != debug_log->log_end)) {
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200155 char_addr = batadv_log_char_addr(debug_log,
156 debug_log->log_start);
157 c = *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000158
159 debug_log->log_start++;
160
161 spin_unlock_bh(&debug_log->lock);
162
163 error = __put_user(c, buf);
164
165 spin_lock_bh(&debug_log->lock);
166
167 buf++;
168 i++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000169 }
170
171 spin_unlock_bh(&debug_log->lock);
172
173 if (!error)
174 return i;
175
176 return error;
177}
178
Sven Eckelmann9e466252012-05-12 18:33:50 +0200179static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000180{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200181 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800182 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000183
184 poll_wait(file, &debug_log->queue_wait, wait);
185
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200186 if (!batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000187 return POLLIN | POLLRDNORM;
188
189 return 0;
190}
191
Sven Eckelmann9e466252012-05-12 18:33:50 +0200192static const struct file_operations batadv_log_fops = {
193 .open = batadv_log_open,
194 .release = batadv_log_release,
195 .read = batadv_log_read,
196 .poll = batadv_log_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000197 .llseek = no_llseek,
198};
199
Sven Eckelmann56303d32012-06-05 22:31:31 +0200200static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000201{
202 struct dentry *d;
203
204 if (!bat_priv->debug_dir)
205 goto err;
206
Sven Eckelmann704509b2011-05-14 23:14:54 +0200207 bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000208 if (!bat_priv->debug_log)
209 goto err;
210
211 spin_lock_init(&bat_priv->debug_log->lock);
212 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
213
214 d = debugfs_create_file("log", S_IFREG | S_IRUSR,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200215 bat_priv->debug_dir, bat_priv,
216 &batadv_log_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200217 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000218 goto err;
219
220 return 0;
221
222err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200223 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000224}
225
Sven Eckelmann56303d32012-06-05 22:31:31 +0200226static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000227{
228 kfree(bat_priv->debug_log);
229 bat_priv->debug_log = NULL;
230}
231#else /* CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200232static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000233{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000234 return 0;
235}
236
Sven Eckelmann56303d32012-06-05 22:31:31 +0200237static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000238{
239 return;
240}
241#endif
242
Sven Eckelmann9e466252012-05-12 18:33:50 +0200243static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +0800244{
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200245 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +0800246}
247
Sven Eckelmann9e466252012-05-12 18:33:50 +0200248static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000249{
250 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200251 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000252}
253
Sven Eckelmann9e466252012-05-12 18:33:50 +0200254static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000255{
256 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200257 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000258}
259
Sven Eckelmann9e466252012-05-12 18:33:50 +0200260static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000261{
262 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200263 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000264}
265
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100266#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200267static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100268{
269 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08adf152012-05-12 13:38:47 +0200270 return single_open(file, batadv_bla_claim_table_seq_print_text,
271 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100272}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200273
274static int batadv_bla_backbone_table_open(struct inode *inode,
275 struct file *file)
276{
277 struct net_device *net_dev = (struct net_device *)inode->i_private;
278 return single_open(file, batadv_bla_backbone_table_seq_print_text,
279 net_dev);
280}
281
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100282#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100283
Antonio Quartulli17224472011-11-06 12:23:55 +0100284#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200285/**
286 * batadv_dat_cache_open - Prepare file handler for reads from dat_chache
287 * @inode: inode which was opened
288 * @file: file handle to be initialized
289 */
290static int batadv_dat_cache_open(struct inode *inode, struct file *file)
291{
292 struct net_device *net_dev = (struct net_device *)inode->i_private;
293 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
294}
Antonio Quartulli17224472011-11-06 12:23:55 +0100295#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200296
Sven Eckelmann9e466252012-05-12 18:33:50 +0200297static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000298{
299 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200300 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000301}
302
Sven Eckelmann9e466252012-05-12 18:33:50 +0200303static int batadv_vis_data_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000304{
305 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmannd0f714f2012-05-12 02:09:41 +0200306 return single_open(file, batadv_vis_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000307}
308
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200309struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000310 struct attribute attr;
311 const struct file_operations fops;
312};
313
Martin Hundebølld56b1702013-01-25 11:12:39 +0100314#ifdef CONFIG_BATMAN_ADV_NC
315static int batadv_nc_nodes_open(struct inode *inode, struct file *file)
316{
317 struct net_device *net_dev = (struct net_device *)inode->i_private;
318 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
319}
320#endif
321
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200322#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200323struct batadv_debuginfo batadv_debuginfo_##_name = { \
Sven Eckelmann9e466252012-05-12 18:33:50 +0200324 .attr = { .name = __stringify(_name), \
325 .mode = _mode, }, \
326 .fops = { .owner = THIS_MODULE, \
327 .open = _open, \
328 .read = seq_read, \
329 .llseek = seq_lseek, \
330 .release = single_release, \
331 } \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000332};
333
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200334/* the following attributes are general and therefore they will be directly
335 * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
336 */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200337static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200338
339static struct batadv_debuginfo *batadv_general_debuginfos[] = {
340 &batadv_debuginfo_routing_algos,
341 NULL,
342};
343
344/* The following attributes are per soft interface */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200345static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
346static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
347static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
348 batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100349#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200350static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open);
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200351static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO,
352 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100353#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100354#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200355static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open);
Antonio Quartulli17224472011-11-06 12:23:55 +0100356#endif
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200357static BATADV_DEBUGINFO(transtable_local, S_IRUGO,
358 batadv_transtable_local_open);
359static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100360#ifdef CONFIG_BATMAN_ADV_NC
361static BATADV_DEBUGINFO(nc_nodes, S_IRUGO, batadv_nc_nodes_open);
362#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000363
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200364static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Sven Eckelmann9e466252012-05-12 18:33:50 +0200365 &batadv_debuginfo_originators,
366 &batadv_debuginfo_gateways,
367 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100368#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200369 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200370 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100371#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100372#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200373 &batadv_debuginfo_dat_cache,
Antonio Quartulli17224472011-11-06 12:23:55 +0100374#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200375 &batadv_debuginfo_transtable_local,
376 &batadv_debuginfo_vis_data,
Martin Hundebølld56b1702013-01-25 11:12:39 +0100377#ifdef CONFIG_BATMAN_ADV_NC
378 &batadv_debuginfo_nc_nodes,
379#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000380 NULL,
381};
382
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200383void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000384{
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200385 struct batadv_debuginfo **bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800386 struct dentry *file;
387
Sven Eckelmann54590e42012-06-03 22:19:08 +0200388 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200389 if (batadv_debugfs == ERR_PTR(-ENODEV))
390 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800391
Sven Eckelmann9e466252012-05-12 18:33:50 +0200392 if (!batadv_debugfs)
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200393 goto err;
Marek Lindner1c280472011-11-28 17:40:17 +0800394
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200395 for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
396 file = debugfs_create_file(((*bat_debug)->attr).name,
397 S_IFREG | ((*bat_debug)->attr).mode,
398 batadv_debugfs, NULL,
399 &(*bat_debug)->fops);
400 if (!file) {
401 pr_err("Can't add general debugfs file: %s\n",
402 ((*bat_debug)->attr).name);
403 goto err;
404 }
405 }
Marek Lindner1c280472011-11-28 17:40:17 +0800406
Marek Lindner1c280472011-11-28 17:40:17 +0800407 return;
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200408err:
409 debugfs_remove_recursive(batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000410}
411
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200412void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000413{
Antonio Quartulli3f87c422012-11-29 01:03:31 +0100414 debugfs_remove_recursive(batadv_debugfs);
415 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000416}
417
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200418int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000419{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200420 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200421 struct batadv_debuginfo **bat_debug;
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
Sven Eckelmann9e466252012-05-12 18:33:50 +0200427 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000428 if (!bat_priv->debug_dir)
429 goto out;
430
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200431 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200432 goto rem_attr;
433
Sven Eckelmann9e466252012-05-12 18:33:50 +0200434 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200435 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000436
Sven Eckelmann9e466252012-05-12 18:33:50 +0200437 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000438 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200439 S_IFREG | ((*bat_debug)->attr).mode,
440 bat_priv->debug_dir,
441 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000442 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200443 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
444 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000445 goto rem_attr;
446 }
447 }
448
Martin Hundebølld56b1702013-01-25 11:12:39 +0100449 if (batadv_nc_init_debugfs(bat_priv) < 0)
450 goto rem_attr;
451
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000452 return 0;
453rem_attr:
454 debugfs_remove_recursive(bat_priv->debug_dir);
455 bat_priv->debug_dir = NULL;
456out:
457#ifdef CONFIG_DEBUG_FS
458 return -ENOMEM;
459#else
460 return 0;
461#endif /* CONFIG_DEBUG_FS */
462}
463
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200464void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000465{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200466 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000467
Sven Eckelmann9e466252012-05-12 18:33:50 +0200468 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000469
Sven Eckelmann9e466252012-05-12 18:33:50 +0200470 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000471 debugfs_remove_recursive(bat_priv->debug_dir);
472 bat_priv->debug_dir = NULL;
473 }
474}