blob: 0adbcee80d24e403db23c6401e3e8d1b8268ecbf [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
Antonio Quartulliebf38fb2013-11-03 20:40:48 +010015 * along with this program; if not, see <http://www.gnu.org/licenses/>.
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000016 */
17
18#include "main.h"
19
20#include <linux/debugfs.h>
21
Sven Eckelmannb706b132012-06-10 23:58:51 +020022#include "debugfs.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000023#include "translation-table.h"
24#include "originator.h"
25#include "hard-interface.h"
26#include "gateway_common.h"
27#include "gateway_client.h"
28#include "soft-interface.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000029#include "icmp_socket.h"
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +010030#include "bridge_loop_avoidance.h"
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +020031#include "distributed-arp-table.h"
Martin Hundebølld56b1702013-01-25 11:12:39 +010032#include "network-coding.h"
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000033
Sven Eckelmann9e466252012-05-12 18:33:50 +020034static struct dentry *batadv_debugfs;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000035
36#ifdef CONFIG_BATMAN_ADV_DEBUG
Sven Eckelmann347c80f2012-06-03 22:19:07 +020037#define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000038
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020039static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN;
40
Marek Lindner0abf5d82012-12-25 17:03:20 +080041static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log,
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020042 size_t idx)
43{
44 return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
45}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000046
Marek Lindner0abf5d82012-12-25 17:03:20 +080047static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log,
48 char c)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000049{
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020050 char *char_addr;
51
52 char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
53 *char_addr = c;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000054 debug_log->log_end++;
55
Sven Eckelmann9e466252012-05-12 18:33:50 +020056 if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
57 debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000058}
59
Sven Eckelmannd3a547b2011-05-14 23:14:46 +020060__printf(2, 3)
Marek Lindner0abf5d82012-12-25 17:03:20 +080061static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log,
Sven Eckelmann56303d32012-06-05 22:31:31 +020062 const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000063{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000064 va_list args;
65 static char debug_log_buf[256];
66 char *p;
67
68 if (!debug_log)
69 return 0;
70
71 spin_lock_bh(&debug_log->lock);
72 va_start(args, fmt);
Sven Eckelmann1299bda2011-01-27 13:48:54 +010073 vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000074 va_end(args);
75
76 for (p = debug_log_buf; *p != 0; p++)
Sven Eckelmann9e466252012-05-12 18:33:50 +020077 batadv_emit_log_char(debug_log, *p);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000078
79 spin_unlock_bh(&debug_log->lock);
80
81 wake_up(&debug_log->queue_wait);
82
83 return 0;
84}
85
Sven Eckelmann56303d32012-06-05 22:31:31 +020086int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000087{
88 va_list args;
89 char tmp_log_buf[256];
90
91 va_start(args, fmt);
92 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
Sven Eckelmann9e466252012-05-12 18:33:50 +020093 batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
94 jiffies_to_msecs(jiffies), tmp_log_buf);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000095 va_end(args);
96
97 return 0;
98}
99
Sven Eckelmann9e466252012-05-12 18:33:50 +0200100static int batadv_log_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000101{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200102 if (!try_module_get(THIS_MODULE))
103 return -EBUSY;
104
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000105 nonseekable_open(inode, file);
106 file->private_data = inode->i_private;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000107 return 0;
108}
109
Sven Eckelmann9e466252012-05-12 18:33:50 +0200110static int batadv_log_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000111{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200112 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000113 return 0;
114}
115
Marek Lindner0abf5d82012-12-25 17:03:20 +0800116static int batadv_log_empty(struct batadv_priv_debug_log *debug_log)
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200117{
118 return !(debug_log->log_start - debug_log->log_end);
119}
120
Sven Eckelmann9e466252012-05-12 18:33:50 +0200121static ssize_t batadv_log_read(struct file *file, char __user *buf,
122 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000123{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200124 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800125 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000126 int error, i = 0;
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200127 char *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000128 char c;
129
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200130 if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000131 return -EAGAIN;
132
Sven Eckelmann16f14b42011-05-14 23:14:48 +0200133 if (!buf)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000134 return -EINVAL;
135
136 if (count == 0)
137 return 0;
138
139 if (!access_ok(VERIFY_WRITE, buf, count))
140 return -EFAULT;
141
142 error = wait_event_interruptible(debug_log->queue_wait,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200143 (!batadv_log_empty(debug_log)));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000144
145 if (error)
146 return error;
147
148 spin_lock_bh(&debug_log->lock);
149
150 while ((!error) && (i < count) &&
151 (debug_log->log_start != debug_log->log_end)) {
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200152 char_addr = batadv_log_char_addr(debug_log,
153 debug_log->log_start);
154 c = *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000155
156 debug_log->log_start++;
157
158 spin_unlock_bh(&debug_log->lock);
159
160 error = __put_user(c, buf);
161
162 spin_lock_bh(&debug_log->lock);
163
164 buf++;
165 i++;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000166 }
167
168 spin_unlock_bh(&debug_log->lock);
169
170 if (!error)
171 return i;
172
173 return error;
174}
175
Sven Eckelmann9e466252012-05-12 18:33:50 +0200176static unsigned int batadv_log_poll(struct file *file, poll_table *wait)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000177{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200178 struct batadv_priv *bat_priv = file->private_data;
Marek Lindner0abf5d82012-12-25 17:03:20 +0800179 struct batadv_priv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000180
181 poll_wait(file, &debug_log->queue_wait, wait);
182
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200183 if (!batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000184 return POLLIN | POLLRDNORM;
185
186 return 0;
187}
188
Sven Eckelmann9e466252012-05-12 18:33:50 +0200189static const struct file_operations batadv_log_fops = {
190 .open = batadv_log_open,
191 .release = batadv_log_release,
192 .read = batadv_log_read,
193 .poll = batadv_log_poll,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000194 .llseek = no_llseek,
195};
196
Sven Eckelmann56303d32012-06-05 22:31:31 +0200197static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000198{
199 struct dentry *d;
200
201 if (!bat_priv->debug_dir)
202 goto err;
203
Sven Eckelmann704509b2011-05-14 23:14:54 +0200204 bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000205 if (!bat_priv->debug_log)
206 goto err;
207
208 spin_lock_init(&bat_priv->debug_log->lock);
209 init_waitqueue_head(&bat_priv->debug_log->queue_wait);
210
211 d = debugfs_create_file("log", S_IFREG | S_IRUSR,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200212 bat_priv->debug_dir, bat_priv,
213 &batadv_log_fops);
Sven Eckelmann5346c352012-05-05 13:27:28 +0200214 if (!d)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000215 goto err;
216
217 return 0;
218
219err:
Sven Eckelmann5346c352012-05-05 13:27:28 +0200220 return -ENOMEM;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000221}
222
Sven Eckelmann56303d32012-06-05 22:31:31 +0200223static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000224{
225 kfree(bat_priv->debug_log);
226 bat_priv->debug_log = NULL;
227}
228#else /* CONFIG_BATMAN_ADV_DEBUG */
Sven Eckelmann56303d32012-06-05 22:31:31 +0200229static int batadv_debug_log_setup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000230{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000231 return 0;
232}
233
Sven Eckelmann56303d32012-06-05 22:31:31 +0200234static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000235{
236 return;
237}
238#endif
239
Sven Eckelmann9e466252012-05-12 18:33:50 +0200240static int batadv_algorithms_open(struct inode *inode, struct file *file)
Marek Lindner1c280472011-11-28 17:40:17 +0800241{
Sven Eckelmann3193e8f2012-05-12 02:09:42 +0200242 return single_open(file, batadv_algo_seq_print_text, NULL);
Marek Lindner1c280472011-11-28 17:40:17 +0800243}
244
Sven Eckelmann9e466252012-05-12 18:33:50 +0200245static int batadv_originators_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000246{
247 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7d211ef2012-05-12 02:09:34 +0200248 return single_open(file, batadv_orig_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000249}
250
Sven Eckelmann9e466252012-05-12 18:33:50 +0200251static int batadv_gateways_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000252{
253 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann7cf06bc2012-05-12 02:09:29 +0200254 return single_open(file, batadv_gw_client_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000255}
256
Sven Eckelmann9e466252012-05-12 18:33:50 +0200257static int batadv_transtable_global_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000258{
259 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200260 return single_open(file, batadv_tt_global_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000261}
262
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100263#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200264static int batadv_bla_claim_table_open(struct inode *inode, struct file *file)
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100265{
266 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08adf152012-05-12 13:38:47 +0200267 return single_open(file, batadv_bla_claim_table_seq_print_text,
268 net_dev);
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100269}
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200270
271static int batadv_bla_backbone_table_open(struct inode *inode,
272 struct file *file)
273{
274 struct net_device *net_dev = (struct net_device *)inode->i_private;
275 return single_open(file, batadv_bla_backbone_table_seq_print_text,
276 net_dev);
277}
278
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100279#endif
Simon Wunderlich9bf8e4d2012-01-22 20:00:21 +0100280
Antonio Quartulli17224472011-11-06 12:23:55 +0100281#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200282/**
283 * batadv_dat_cache_open - Prepare file handler for reads from dat_chache
284 * @inode: inode which was opened
285 * @file: file handle to be initialized
286 */
287static int batadv_dat_cache_open(struct inode *inode, struct file *file)
288{
289 struct net_device *net_dev = (struct net_device *)inode->i_private;
290 return single_open(file, batadv_dat_cache_seq_print_text, net_dev);
291}
Antonio Quartulli17224472011-11-06 12:23:55 +0100292#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200293
Sven Eckelmann9e466252012-05-12 18:33:50 +0200294static int batadv_transtable_local_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000295{
296 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmann08c36d32012-05-12 02:09:39 +0200297 return single_open(file, batadv_tt_local_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000298}
299
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200300struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000301 struct attribute attr;
302 const struct file_operations fops;
303};
304
Martin Hundebølld56b1702013-01-25 11:12:39 +0100305#ifdef CONFIG_BATMAN_ADV_NC
306static int batadv_nc_nodes_open(struct inode *inode, struct file *file)
307{
308 struct net_device *net_dev = (struct net_device *)inode->i_private;
309 return single_open(file, batadv_nc_nodes_seq_print_text, net_dev);
310}
311#endif
312
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200313#define BATADV_DEBUGINFO(_name, _mode, _open) \
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200314struct batadv_debuginfo batadv_debuginfo_##_name = { \
Sven Eckelmann9e466252012-05-12 18:33:50 +0200315 .attr = { .name = __stringify(_name), \
316 .mode = _mode, }, \
317 .fops = { .owner = THIS_MODULE, \
318 .open = _open, \
319 .read = seq_read, \
320 .llseek = seq_lseek, \
321 .release = single_release, \
322 } \
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000323};
324
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200325/* the following attributes are general and therefore they will be directly
326 * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs
327 */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200328static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200329
330static struct batadv_debuginfo *batadv_general_debuginfos[] = {
331 &batadv_debuginfo_routing_algos,
332 NULL,
333};
334
335/* The following attributes are per soft interface */
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200336static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
337static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
338static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
339 batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100340#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200341static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open);
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200342static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO,
343 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100344#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100345#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200346static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open);
Antonio Quartulli17224472011-11-06 12:23:55 +0100347#endif
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200348static BATADV_DEBUGINFO(transtable_local, S_IRUGO,
349 batadv_transtable_local_open);
Martin Hundebølld56b1702013-01-25 11:12:39 +0100350#ifdef CONFIG_BATMAN_ADV_NC
351static BATADV_DEBUGINFO(nc_nodes, S_IRUGO, batadv_nc_nodes_open);
352#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000353
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200354static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Sven Eckelmann9e466252012-05-12 18:33:50 +0200355 &batadv_debuginfo_originators,
356 &batadv_debuginfo_gateways,
357 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100358#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200359 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200360 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100361#endif
Antonio Quartulli17224472011-11-06 12:23:55 +0100362#ifdef CONFIG_BATMAN_ADV_DAT
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200363 &batadv_debuginfo_dat_cache,
Antonio Quartulli17224472011-11-06 12:23:55 +0100364#endif
Sven Eckelmann9e466252012-05-12 18:33:50 +0200365 &batadv_debuginfo_transtable_local,
Martin Hundebølld56b1702013-01-25 11:12:39 +0100366#ifdef CONFIG_BATMAN_ADV_NC
367 &batadv_debuginfo_nc_nodes,
368#endif
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000369 NULL,
370};
371
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200372void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000373{
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200374 struct batadv_debuginfo **bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800375 struct dentry *file;
376
Sven Eckelmann54590e42012-06-03 22:19:08 +0200377 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200378 if (batadv_debugfs == ERR_PTR(-ENODEV))
379 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800380
Sven Eckelmann9e466252012-05-12 18:33:50 +0200381 if (!batadv_debugfs)
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200382 goto err;
Marek Lindner1c280472011-11-28 17:40:17 +0800383
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200384 for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) {
385 file = debugfs_create_file(((*bat_debug)->attr).name,
386 S_IFREG | ((*bat_debug)->attr).mode,
387 batadv_debugfs, NULL,
388 &(*bat_debug)->fops);
389 if (!file) {
390 pr_err("Can't add general debugfs file: %s\n",
391 ((*bat_debug)->attr).name);
392 goto err;
393 }
394 }
Marek Lindner1c280472011-11-28 17:40:17 +0800395
Marek Lindner1c280472011-11-28 17:40:17 +0800396 return;
Antonio Quartulli637fbd12012-10-16 10:04:39 +0200397err:
398 debugfs_remove_recursive(batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000399}
400
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200401void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000402{
Antonio Quartulli3f87c422012-11-29 01:03:31 +0100403 debugfs_remove_recursive(batadv_debugfs);
404 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000405}
406
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200407int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000408{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200409 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200410 struct batadv_debuginfo **bat_debug;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000411 struct dentry *file;
412
Sven Eckelmann9e466252012-05-12 18:33:50 +0200413 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000414 goto out;
415
Sven Eckelmann9e466252012-05-12 18:33:50 +0200416 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000417 if (!bat_priv->debug_dir)
418 goto out;
419
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200420 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200421 goto rem_attr;
422
Sven Eckelmann9e466252012-05-12 18:33:50 +0200423 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200424 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000425
Sven Eckelmann9e466252012-05-12 18:33:50 +0200426 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000427 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200428 S_IFREG | ((*bat_debug)->attr).mode,
429 bat_priv->debug_dir,
430 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000431 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200432 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
433 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000434 goto rem_attr;
435 }
436 }
437
Martin Hundebølld56b1702013-01-25 11:12:39 +0100438 if (batadv_nc_init_debugfs(bat_priv) < 0)
439 goto rem_attr;
440
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000441 return 0;
442rem_attr:
443 debugfs_remove_recursive(bat_priv->debug_dir);
444 bat_priv->debug_dir = NULL;
445out:
446#ifdef CONFIG_DEBUG_FS
447 return -ENOMEM;
448#else
449 return 0;
450#endif /* CONFIG_DEBUG_FS */
451}
452
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200453void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000454{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200455 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000456
Sven Eckelmann9e466252012-05-12 18:33:50 +0200457 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000458
Sven Eckelmann9e466252012-05-12 18:33:50 +0200459 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000460 debugfs_remove_recursive(bat_priv->debug_dir);
461 bat_priv->debug_dir = NULL;
462 }
463}