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