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