Sven Eckelmann | 9cfc7bd | 2012-05-12 02:09:43 +0200 | [diff] [blame] | 1 | /* Copyright (C) 2010-2012 B.A.T.M.A.N. contributors: |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 2 | * |
| 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 Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include "main.h" |
| 21 | |
| 22 | #include <linux/debugfs.h> |
| 23 | |
| 24 | #include "bat_debugfs.h" |
| 25 | #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 Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 33 | #include "bridge_loop_avoidance.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 34 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 35 | static struct dentry *batadv_debugfs; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 36 | |
| 37 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 38 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) |
| 39 | #define BATADV_LOG_BUFF(idx) (debug_log->log_buff[(idx) & BATADV_LOG_BUFF_MASK]) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 40 | |
Sven Eckelmann | 42d0b04 | 2012-06-03 22:19:17 +0200 | [diff] [blame] | 41 | static int batadv_log_buff_len = BATADV_LOG_BUF_LEN; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 42 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 43 | static void batadv_emit_log_char(struct debug_log *debug_log, char c) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 44 | { |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 45 | BATADV_LOG_BUFF(debug_log->log_end) = c; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 46 | debug_log->log_end++; |
| 47 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 48 | if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len) |
| 49 | debug_log->log_start = debug_log->log_end - batadv_log_buff_len; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 50 | } |
| 51 | |
Sven Eckelmann | d3a547b | 2011-05-14 23:14:46 +0200 | [diff] [blame] | 52 | __printf(2, 3) |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 53 | static int batadv_fdebug_log(struct debug_log *debug_log, const char *fmt, ...) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 54 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 55 | va_list args; |
| 56 | static char debug_log_buf[256]; |
| 57 | char *p; |
| 58 | |
| 59 | if (!debug_log) |
| 60 | return 0; |
| 61 | |
| 62 | spin_lock_bh(&debug_log->lock); |
| 63 | va_start(args, fmt); |
Sven Eckelmann | 1299bda | 2011-01-27 13:48:54 +0100 | [diff] [blame] | 64 | vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 65 | va_end(args); |
| 66 | |
| 67 | for (p = debug_log_buf; *p != 0; p++) |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 68 | batadv_emit_log_char(debug_log, *p); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 69 | |
| 70 | spin_unlock_bh(&debug_log->lock); |
| 71 | |
| 72 | wake_up(&debug_log->queue_wait); |
| 73 | |
| 74 | return 0; |
| 75 | } |
| 76 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 77 | int batadv_debug_log(struct bat_priv *bat_priv, const char *fmt, ...) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 78 | { |
| 79 | va_list args; |
| 80 | char tmp_log_buf[256]; |
| 81 | |
| 82 | va_start(args, fmt); |
| 83 | vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 84 | batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s", |
| 85 | jiffies_to_msecs(jiffies), tmp_log_buf); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 86 | va_end(args); |
| 87 | |
| 88 | return 0; |
| 89 | } |
| 90 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 91 | static int batadv_log_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 92 | { |
| 93 | nonseekable_open(inode, file); |
| 94 | file->private_data = inode->i_private; |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 95 | batadv_inc_module_count(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 96 | return 0; |
| 97 | } |
| 98 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 99 | static int batadv_log_release(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 100 | { |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 101 | batadv_dec_module_count(); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 102 | return 0; |
| 103 | } |
| 104 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 105 | static ssize_t batadv_log_read(struct file *file, char __user *buf, |
| 106 | size_t count, loff_t *ppos) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 107 | { |
| 108 | struct bat_priv *bat_priv = file->private_data; |
| 109 | struct debug_log *debug_log = bat_priv->debug_log; |
| 110 | int error, i = 0; |
| 111 | char c; |
| 112 | |
| 113 | if ((file->f_flags & O_NONBLOCK) && |
| 114 | !(debug_log->log_end - debug_log->log_start)) |
| 115 | return -EAGAIN; |
| 116 | |
Sven Eckelmann | 16f14b4 | 2011-05-14 23:14:48 +0200 | [diff] [blame] | 117 | if (!buf) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 118 | return -EINVAL; |
| 119 | |
| 120 | if (count == 0) |
| 121 | return 0; |
| 122 | |
| 123 | if (!access_ok(VERIFY_WRITE, buf, count)) |
| 124 | return -EFAULT; |
| 125 | |
| 126 | error = wait_event_interruptible(debug_log->queue_wait, |
| 127 | (debug_log->log_start - debug_log->log_end)); |
| 128 | |
| 129 | if (error) |
| 130 | return error; |
| 131 | |
| 132 | spin_lock_bh(&debug_log->lock); |
| 133 | |
| 134 | while ((!error) && (i < count) && |
| 135 | (debug_log->log_start != debug_log->log_end)) { |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 136 | c = BATADV_LOG_BUFF(debug_log->log_start); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 137 | |
| 138 | debug_log->log_start++; |
| 139 | |
| 140 | spin_unlock_bh(&debug_log->lock); |
| 141 | |
| 142 | error = __put_user(c, buf); |
| 143 | |
| 144 | spin_lock_bh(&debug_log->lock); |
| 145 | |
| 146 | buf++; |
| 147 | i++; |
| 148 | |
| 149 | } |
| 150 | |
| 151 | spin_unlock_bh(&debug_log->lock); |
| 152 | |
| 153 | if (!error) |
| 154 | return i; |
| 155 | |
| 156 | return error; |
| 157 | } |
| 158 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 159 | static unsigned int batadv_log_poll(struct file *file, poll_table *wait) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 160 | { |
| 161 | struct bat_priv *bat_priv = file->private_data; |
| 162 | struct debug_log *debug_log = bat_priv->debug_log; |
| 163 | |
| 164 | poll_wait(file, &debug_log->queue_wait, wait); |
| 165 | |
| 166 | if (debug_log->log_end - debug_log->log_start) |
| 167 | return POLLIN | POLLRDNORM; |
| 168 | |
| 169 | return 0; |
| 170 | } |
| 171 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 172 | static const struct file_operations batadv_log_fops = { |
| 173 | .open = batadv_log_open, |
| 174 | .release = batadv_log_release, |
| 175 | .read = batadv_log_read, |
| 176 | .poll = batadv_log_poll, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 177 | .llseek = no_llseek, |
| 178 | }; |
| 179 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 180 | static int batadv_debug_log_setup(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 181 | { |
| 182 | struct dentry *d; |
| 183 | |
| 184 | if (!bat_priv->debug_dir) |
| 185 | goto err; |
| 186 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 187 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 188 | if (!bat_priv->debug_log) |
| 189 | goto err; |
| 190 | |
| 191 | spin_lock_init(&bat_priv->debug_log->lock); |
| 192 | init_waitqueue_head(&bat_priv->debug_log->queue_wait); |
| 193 | |
| 194 | d = debugfs_create_file("log", S_IFREG | S_IRUSR, |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 195 | bat_priv->debug_dir, bat_priv, |
| 196 | &batadv_log_fops); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 197 | if (!d) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 198 | goto err; |
| 199 | |
| 200 | return 0; |
| 201 | |
| 202 | err: |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 203 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 204 | } |
| 205 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 206 | static void batadv_debug_log_cleanup(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 207 | { |
| 208 | kfree(bat_priv->debug_log); |
| 209 | bat_priv->debug_log = NULL; |
| 210 | } |
| 211 | #else /* CONFIG_BATMAN_ADV_DEBUG */ |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 212 | static int batadv_debug_log_setup(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 213 | { |
| 214 | bat_priv->debug_log = NULL; |
| 215 | return 0; |
| 216 | } |
| 217 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 218 | static void batadv_debug_log_cleanup(struct bat_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 219 | { |
| 220 | return; |
| 221 | } |
| 222 | #endif |
| 223 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 224 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 225 | { |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 226 | return single_open(file, batadv_algo_seq_print_text, NULL); |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 227 | } |
| 228 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 229 | static int batadv_originators_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 230 | { |
| 231 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 232 | return single_open(file, batadv_orig_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 235 | static int batadv_gateways_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 236 | { |
| 237 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 238 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 239 | } |
| 240 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 241 | static int batadv_transtable_global_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 242 | { |
| 243 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 244 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 245 | } |
| 246 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 247 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 248 | static int batadv_bla_claim_table_open(struct inode *inode, struct file *file) |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 249 | { |
| 250 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 251 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
| 252 | net_dev); |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 253 | } |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 254 | #endif |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 255 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 256 | static int batadv_transtable_local_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 257 | { |
| 258 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 259 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 260 | } |
| 261 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 262 | static int batadv_vis_data_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 263 | { |
| 264 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 265 | return single_open(file, batadv_vis_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 266 | } |
| 267 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame^] | 268 | struct batadv_debuginfo { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 269 | struct attribute attr; |
| 270 | const struct file_operations fops; |
| 271 | }; |
| 272 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 273 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame^] | 274 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 275 | .attr = { .name = __stringify(_name), \ |
| 276 | .mode = _mode, }, \ |
| 277 | .fops = { .owner = THIS_MODULE, \ |
| 278 | .open = _open, \ |
| 279 | .read = seq_read, \ |
| 280 | .llseek = seq_lseek, \ |
| 281 | .release = single_release, \ |
| 282 | } \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 283 | }; |
| 284 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 285 | static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open); |
| 286 | static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open); |
| 287 | static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open); |
| 288 | static BATADV_DEBUGINFO(transtable_global, S_IRUGO, |
| 289 | batadv_transtable_global_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 290 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 291 | static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 292 | #endif |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 293 | static BATADV_DEBUGINFO(transtable_local, S_IRUGO, |
| 294 | batadv_transtable_local_open); |
| 295 | static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 296 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame^] | 297 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 298 | &batadv_debuginfo_originators, |
| 299 | &batadv_debuginfo_gateways, |
| 300 | &batadv_debuginfo_transtable_global, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 301 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 302 | &batadv_debuginfo_bla_claim_table, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 303 | #endif |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 304 | &batadv_debuginfo_transtable_local, |
| 305 | &batadv_debuginfo_vis_data, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 306 | NULL, |
| 307 | }; |
| 308 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 309 | void batadv_debugfs_init(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 310 | { |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame^] | 311 | struct batadv_debuginfo *bat_debug; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 312 | struct dentry *file; |
| 313 | |
Sven Eckelmann | 54590e4 | 2012-06-03 22:19:08 +0200 | [diff] [blame] | 314 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 315 | if (batadv_debugfs == ERR_PTR(-ENODEV)) |
| 316 | batadv_debugfs = NULL; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 317 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 318 | if (!batadv_debugfs) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 319 | goto out; |
| 320 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 321 | bat_debug = &batadv_debuginfo_routing_algos; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 322 | file = debugfs_create_file(bat_debug->attr.name, |
| 323 | S_IFREG | bat_debug->attr.mode, |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 324 | batadv_debugfs, NULL, &bat_debug->fops); |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 325 | if (!file) |
| 326 | pr_err("Can't add debugfs file: %s\n", bat_debug->attr.name); |
| 327 | |
| 328 | out: |
| 329 | return; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 330 | } |
| 331 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 332 | void batadv_debugfs_destroy(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 333 | { |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 334 | if (batadv_debugfs) { |
| 335 | debugfs_remove_recursive(batadv_debugfs); |
| 336 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 337 | } |
| 338 | } |
| 339 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 340 | int batadv_debugfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 341 | { |
| 342 | struct bat_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame^] | 343 | struct batadv_debuginfo **bat_debug; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 344 | struct dentry *file; |
| 345 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 346 | if (!batadv_debugfs) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 347 | goto out; |
| 348 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 349 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 350 | if (!bat_priv->debug_dir) |
| 351 | goto out; |
| 352 | |
Sven Eckelmann | 9039dc7 | 2012-05-12 02:09:33 +0200 | [diff] [blame] | 353 | if (batadv_socket_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 354 | goto rem_attr; |
| 355 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 356 | if (batadv_debug_log_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 357 | goto rem_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 358 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 359 | for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 360 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 361 | S_IFREG | ((*bat_debug)->attr).mode, |
| 362 | bat_priv->debug_dir, |
| 363 | dev, &(*bat_debug)->fops); |
| 364 | if (!file) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 365 | batadv_err(dev, "Can't add debugfs file: %s/%s\n", |
| 366 | dev->name, ((*bat_debug)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 367 | goto rem_attr; |
| 368 | } |
| 369 | } |
| 370 | |
| 371 | return 0; |
| 372 | rem_attr: |
| 373 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 374 | bat_priv->debug_dir = NULL; |
| 375 | out: |
| 376 | #ifdef CONFIG_DEBUG_FS |
| 377 | return -ENOMEM; |
| 378 | #else |
| 379 | return 0; |
| 380 | #endif /* CONFIG_DEBUG_FS */ |
| 381 | } |
| 382 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 383 | void batadv_debugfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 384 | { |
| 385 | struct bat_priv *bat_priv = netdev_priv(dev); |
| 386 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 387 | batadv_debug_log_cleanup(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 388 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 389 | if (batadv_debugfs) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 390 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 391 | bat_priv->debug_dir = NULL; |
| 392 | } |
| 393 | } |