blob: ebc5f4d1f53c9be0227270248918dc0e9c15a3a9 [file] [log] [blame]
Sven Eckelmann9cfc7bd2012-05-12 02:09:43 +02001/* Copyright (C) 2010-2012 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"
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
43static char *batadv_log_char_addr(struct batadv_debug_log *debug_log,
44 size_t idx)
45{
46 return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK];
47}
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000048
Sven Eckelmann56303d32012-06-05 22:31:31 +020049static void batadv_emit_log_char(struct batadv_debug_log *debug_log, char c)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000050{
Sven Eckelmanna8a0a622012-06-05 22:31:32 +020051 char *char_addr;
52
53 char_addr = batadv_log_char_addr(debug_log, debug_log->log_end);
54 *char_addr = c;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000055 debug_log->log_end++;
56
Sven Eckelmann9e466252012-05-12 18:33:50 +020057 if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len)
58 debug_log->log_start = debug_log->log_end - batadv_log_buff_len;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000059}
60
Sven Eckelmannd3a547b2011-05-14 23:14:46 +020061__printf(2, 3)
Sven Eckelmann56303d32012-06-05 22:31:31 +020062static int batadv_fdebug_log(struct batadv_debug_log *debug_log,
63 const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000064{
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000065 va_list args;
66 static char debug_log_buf[256];
67 char *p;
68
69 if (!debug_log)
70 return 0;
71
72 spin_lock_bh(&debug_log->lock);
73 va_start(args, fmt);
Sven Eckelmann1299bda2011-01-27 13:48:54 +010074 vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000075 va_end(args);
76
77 for (p = debug_log_buf; *p != 0; p++)
Sven Eckelmann9e466252012-05-12 18:33:50 +020078 batadv_emit_log_char(debug_log, *p);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000079
80 spin_unlock_bh(&debug_log->lock);
81
82 wake_up(&debug_log->queue_wait);
83
84 return 0;
85}
86
Sven Eckelmann56303d32012-06-05 22:31:31 +020087int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000088{
89 va_list args;
90 char tmp_log_buf[256];
91
92 va_start(args, fmt);
93 vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args);
Sven Eckelmann9e466252012-05-12 18:33:50 +020094 batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s",
95 jiffies_to_msecs(jiffies), tmp_log_buf);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +000096 va_end(args);
97
98 return 0;
99}
100
Sven Eckelmann9e466252012-05-12 18:33:50 +0200101static int batadv_log_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000102{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200103 if (!try_module_get(THIS_MODULE))
104 return -EBUSY;
105
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000106 nonseekable_open(inode, file);
107 file->private_data = inode->i_private;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000108 return 0;
109}
110
Sven Eckelmann9e466252012-05-12 18:33:50 +0200111static int batadv_log_release(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000112{
Sven Eckelmannbd5b80d2012-08-20 23:37:26 +0200113 module_put(THIS_MODULE);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000114 return 0;
115}
116
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200117static int batadv_log_empty(struct batadv_debug_log *debug_log)
118{
119 return !(debug_log->log_start - debug_log->log_end);
120}
121
Sven Eckelmann9e466252012-05-12 18:33:50 +0200122static ssize_t batadv_log_read(struct file *file, char __user *buf,
123 size_t count, loff_t *ppos)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000124{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200125 struct batadv_priv *bat_priv = file->private_data;
126 struct batadv_debug_log *debug_log = bat_priv->debug_log;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000127 int error, i = 0;
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200128 char *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000129 char c;
130
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200131 if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log))
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000132 return -EAGAIN;
133
Sven Eckelmann16f14b42011-05-14 23:14:48 +0200134 if (!buf)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000135 return -EINVAL;
136
137 if (count == 0)
138 return 0;
139
140 if (!access_ok(VERIFY_WRITE, buf, count))
141 return -EFAULT;
142
143 error = wait_event_interruptible(debug_log->queue_wait,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200144 (!batadv_log_empty(debug_log)));
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000145
146 if (error)
147 return error;
148
149 spin_lock_bh(&debug_log->lock);
150
151 while ((!error) && (i < count) &&
152 (debug_log->log_start != debug_log->log_end)) {
Sven Eckelmanna8a0a622012-06-05 22:31:32 +0200153 char_addr = batadv_log_char_addr(debug_log,
154 debug_log->log_start);
155 c = *char_addr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000156
157 debug_log->log_start++;
158
159 spin_unlock_bh(&debug_log->lock);
160
161 error = __put_user(c, buf);
162
163 spin_lock_bh(&debug_log->lock);
164
165 buf++;
166 i++;
167
168 }
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;
181 struct batadv_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{
233 bat_priv->debug_log = NULL;
234 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 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}
294
295
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 Eckelmann9e466252012-05-12 18:33:50 +0200302static int batadv_vis_data_open(struct inode *inode, struct file *file)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000303{
304 struct net_device *net_dev = (struct net_device *)inode->i_private;
Sven Eckelmannd0f714f2012-05-12 02:09:41 +0200305 return single_open(file, batadv_vis_seq_print_text, net_dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000306}
307
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200308struct batadv_debuginfo {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000309 struct attribute attr;
310 const struct file_operations fops;
311};
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
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200325static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open);
326static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open);
327static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open);
328static BATADV_DEBUGINFO(transtable_global, S_IRUGO,
329 batadv_transtable_global_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100330#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200331static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open);
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200332static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO,
333 batadv_bla_backbone_table_open);
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100334#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200335static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open);
Sven Eckelmann347c80f2012-06-03 22:19:07 +0200336static BATADV_DEBUGINFO(transtable_local, S_IRUGO,
337 batadv_transtable_local_open);
338static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000339
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200340static struct batadv_debuginfo *batadv_mesh_debuginfos[] = {
Sven Eckelmann9e466252012-05-12 18:33:50 +0200341 &batadv_debuginfo_originators,
342 &batadv_debuginfo_gateways,
343 &batadv_debuginfo_transtable_global,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100344#ifdef CONFIG_BATMAN_ADV_BLA
Sven Eckelmann9e466252012-05-12 18:33:50 +0200345 &batadv_debuginfo_bla_claim_table,
Simon Wunderlich536a23f2012-06-18 18:39:26 +0200346 &batadv_debuginfo_bla_backbone_table,
Simon Wunderlich7a5cc242012-01-22 20:00:27 +0100347#endif
Antonio Quartulli2f1dfbe2012-06-30 20:01:19 +0200348 &batadv_debuginfo_dat_cache,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200349 &batadv_debuginfo_transtable_local,
350 &batadv_debuginfo_vis_data,
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000351 NULL,
352};
353
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200354void batadv_debugfs_init(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000355{
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200356 struct batadv_debuginfo *bat_debug;
Marek Lindner1c280472011-11-28 17:40:17 +0800357 struct dentry *file;
358
Sven Eckelmann54590e42012-06-03 22:19:08 +0200359 batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL);
Sven Eckelmann9e466252012-05-12 18:33:50 +0200360 if (batadv_debugfs == ERR_PTR(-ENODEV))
361 batadv_debugfs = NULL;
Marek Lindner1c280472011-11-28 17:40:17 +0800362
Sven Eckelmann9e466252012-05-12 18:33:50 +0200363 if (!batadv_debugfs)
Marek Lindner1c280472011-11-28 17:40:17 +0800364 goto out;
365
Sven Eckelmann9e466252012-05-12 18:33:50 +0200366 bat_debug = &batadv_debuginfo_routing_algos;
Marek Lindner1c280472011-11-28 17:40:17 +0800367 file = debugfs_create_file(bat_debug->attr.name,
368 S_IFREG | bat_debug->attr.mode,
Sven Eckelmann9e466252012-05-12 18:33:50 +0200369 batadv_debugfs, NULL, &bat_debug->fops);
Marek Lindner1c280472011-11-28 17:40:17 +0800370 if (!file)
371 pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name);
372
373out:
374 return;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000375}
376
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200377void batadv_debugfs_destroy(void)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000378{
Sven Eckelmann9e466252012-05-12 18:33:50 +0200379 if (batadv_debugfs) {
380 debugfs_remove_recursive(batadv_debugfs);
381 batadv_debugfs = NULL;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000382 }
383}
384
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200385int batadv_debugfs_add_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000386{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200387 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmann7f223c02012-06-05 22:31:27 +0200388 struct batadv_debuginfo **bat_debug;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000389 struct dentry *file;
390
Sven Eckelmann9e466252012-05-12 18:33:50 +0200391 if (!batadv_debugfs)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000392 goto out;
393
Sven Eckelmann9e466252012-05-12 18:33:50 +0200394 bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000395 if (!bat_priv->debug_dir)
396 goto out;
397
Sven Eckelmann9039dc72012-05-12 02:09:33 +0200398 if (batadv_socket_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200399 goto rem_attr;
400
Sven Eckelmann9e466252012-05-12 18:33:50 +0200401 if (batadv_debug_log_setup(bat_priv) < 0)
Sven Eckelmann5346c352012-05-05 13:27:28 +0200402 goto rem_attr;
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000403
Sven Eckelmann9e466252012-05-12 18:33:50 +0200404 for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000405 file = debugfs_create_file(((*bat_debug)->attr).name,
Sven Eckelmann0aca2362012-06-19 20:26:30 +0200406 S_IFREG | ((*bat_debug)->attr).mode,
407 bat_priv->debug_dir,
408 dev, &(*bat_debug)->fops);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000409 if (!file) {
Sven Eckelmann3e348192012-05-16 20:23:22 +0200410 batadv_err(dev, "Can't add debugfs file: %s/%s\n",
411 dev->name, ((*bat_debug)->attr).name);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000412 goto rem_attr;
413 }
414 }
415
416 return 0;
417rem_attr:
418 debugfs_remove_recursive(bat_priv->debug_dir);
419 bat_priv->debug_dir = NULL;
420out:
421#ifdef CONFIG_DEBUG_FS
422 return -ENOMEM;
423#else
424 return 0;
425#endif /* CONFIG_DEBUG_FS */
426}
427
Sven Eckelmann40a072d2012-05-12 02:09:23 +0200428void batadv_debugfs_del_meshif(struct net_device *dev)
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000429{
Sven Eckelmann56303d32012-06-05 22:31:31 +0200430 struct batadv_priv *bat_priv = netdev_priv(dev);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000431
Sven Eckelmann9e466252012-05-12 18:33:50 +0200432 batadv_debug_log_cleanup(bat_priv);
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000433
Sven Eckelmann9e466252012-05-12 18:33:50 +0200434 if (batadv_debugfs) {
Sven Eckelmannc6c8fea2010-12-13 11:19:28 +0000435 debugfs_remove_recursive(bat_priv->debug_dir);
436 bat_priv->debug_dir = NULL;
437 }
438}