Antonio Quartulli | 0b87393 | 2013-01-04 03:05:31 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2010-2013 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" |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 34 | #include "distributed-arp-table.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 35 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 36 | static struct dentry *batadv_debugfs; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 37 | |
| 38 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 39 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 40 | |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 41 | static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN; |
| 42 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 43 | static char *batadv_log_char_addr(struct batadv_priv_debug_log *debug_log, |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 44 | size_t idx) |
| 45 | { |
| 46 | return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK]; |
| 47 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 48 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 49 | static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log, |
| 50 | char c) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 51 | { |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 52 | char *char_addr; |
| 53 | |
| 54 | char_addr = batadv_log_char_addr(debug_log, debug_log->log_end); |
| 55 | *char_addr = c; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 56 | debug_log->log_end++; |
| 57 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 58 | if (debug_log->log_end - debug_log->log_start > batadv_log_buff_len) |
| 59 | debug_log->log_start = debug_log->log_end - batadv_log_buff_len; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 60 | } |
| 61 | |
Sven Eckelmann | d3a547b | 2011-05-14 23:14:46 +0200 | [diff] [blame] | 62 | __printf(2, 3) |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 63 | static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 64 | const char *fmt, ...) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 65 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 66 | va_list args; |
| 67 | static char debug_log_buf[256]; |
| 68 | char *p; |
| 69 | |
| 70 | if (!debug_log) |
| 71 | return 0; |
| 72 | |
| 73 | spin_lock_bh(&debug_log->lock); |
| 74 | va_start(args, fmt); |
Sven Eckelmann | 1299bda | 2011-01-27 13:48:54 +0100 | [diff] [blame] | 75 | vscnprintf(debug_log_buf, sizeof(debug_log_buf), fmt, args); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 76 | va_end(args); |
| 77 | |
| 78 | for (p = debug_log_buf; *p != 0; p++) |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 79 | batadv_emit_log_char(debug_log, *p); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 80 | |
| 81 | spin_unlock_bh(&debug_log->lock); |
| 82 | |
| 83 | wake_up(&debug_log->queue_wait); |
| 84 | |
| 85 | return 0; |
| 86 | } |
| 87 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 88 | int batadv_debug_log(struct batadv_priv *bat_priv, const char *fmt, ...) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 89 | { |
| 90 | va_list args; |
| 91 | char tmp_log_buf[256]; |
| 92 | |
| 93 | va_start(args, fmt); |
| 94 | vscnprintf(tmp_log_buf, sizeof(tmp_log_buf), fmt, args); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 95 | batadv_fdebug_log(bat_priv->debug_log, "[%10u] %s", |
| 96 | jiffies_to_msecs(jiffies), tmp_log_buf); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 97 | va_end(args); |
| 98 | |
| 99 | return 0; |
| 100 | } |
| 101 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 102 | static int batadv_log_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 103 | { |
Sven Eckelmann | bd5b80d | 2012-08-20 23:37:26 +0200 | [diff] [blame] | 104 | if (!try_module_get(THIS_MODULE)) |
| 105 | return -EBUSY; |
| 106 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 107 | nonseekable_open(inode, file); |
| 108 | file->private_data = inode->i_private; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 109 | return 0; |
| 110 | } |
| 111 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 112 | static int batadv_log_release(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 113 | { |
Sven Eckelmann | bd5b80d | 2012-08-20 23:37:26 +0200 | [diff] [blame] | 114 | module_put(THIS_MODULE); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 115 | return 0; |
| 116 | } |
| 117 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 118 | static int batadv_log_empty(struct batadv_priv_debug_log *debug_log) |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 119 | { |
| 120 | return !(debug_log->log_start - debug_log->log_end); |
| 121 | } |
| 122 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 123 | static ssize_t batadv_log_read(struct file *file, char __user *buf, |
| 124 | size_t count, loff_t *ppos) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 125 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 126 | struct batadv_priv *bat_priv = file->private_data; |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 127 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 128 | int error, i = 0; |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 129 | char *char_addr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 130 | char c; |
| 131 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 132 | if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 133 | return -EAGAIN; |
| 134 | |
Sven Eckelmann | 16f14b4 | 2011-05-14 23:14:48 +0200 | [diff] [blame] | 135 | if (!buf) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 136 | return -EINVAL; |
| 137 | |
| 138 | if (count == 0) |
| 139 | return 0; |
| 140 | |
| 141 | if (!access_ok(VERIFY_WRITE, buf, count)) |
| 142 | return -EFAULT; |
| 143 | |
| 144 | error = wait_event_interruptible(debug_log->queue_wait, |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 145 | (!batadv_log_empty(debug_log))); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 146 | |
| 147 | if (error) |
| 148 | return error; |
| 149 | |
| 150 | spin_lock_bh(&debug_log->lock); |
| 151 | |
| 152 | while ((!error) && (i < count) && |
| 153 | (debug_log->log_start != debug_log->log_end)) { |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 154 | char_addr = batadv_log_char_addr(debug_log, |
| 155 | debug_log->log_start); |
| 156 | c = *char_addr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 157 | |
| 158 | debug_log->log_start++; |
| 159 | |
| 160 | spin_unlock_bh(&debug_log->lock); |
| 161 | |
| 162 | error = __put_user(c, buf); |
| 163 | |
| 164 | spin_lock_bh(&debug_log->lock); |
| 165 | |
| 166 | buf++; |
| 167 | i++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 168 | } |
| 169 | |
| 170 | spin_unlock_bh(&debug_log->lock); |
| 171 | |
| 172 | if (!error) |
| 173 | return i; |
| 174 | |
| 175 | return error; |
| 176 | } |
| 177 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 178 | static unsigned int batadv_log_poll(struct file *file, poll_table *wait) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 179 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 180 | struct batadv_priv *bat_priv = file->private_data; |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 181 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 182 | |
| 183 | poll_wait(file, &debug_log->queue_wait, wait); |
| 184 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 185 | if (!batadv_log_empty(debug_log)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 186 | return POLLIN | POLLRDNORM; |
| 187 | |
| 188 | return 0; |
| 189 | } |
| 190 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 191 | static 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 Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 196 | .llseek = no_llseek, |
| 197 | }; |
| 198 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 199 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 200 | { |
| 201 | struct dentry *d; |
| 202 | |
| 203 | if (!bat_priv->debug_dir) |
| 204 | goto err; |
| 205 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 206 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 207 | 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 Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 214 | bat_priv->debug_dir, bat_priv, |
| 215 | &batadv_log_fops); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 216 | if (!d) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 217 | goto err; |
| 218 | |
| 219 | return 0; |
| 220 | |
| 221 | err: |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 222 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 223 | } |
| 224 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 225 | static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 226 | { |
| 227 | kfree(bat_priv->debug_log); |
| 228 | bat_priv->debug_log = NULL; |
| 229 | } |
| 230 | #else /* CONFIG_BATMAN_ADV_DEBUG */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 231 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 232 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 233 | return 0; |
| 234 | } |
| 235 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 236 | static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 237 | { |
| 238 | return; |
| 239 | } |
| 240 | #endif |
| 241 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 242 | static int batadv_algorithms_open(struct inode *inode, struct file *file) |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 243 | { |
Sven Eckelmann | 3193e8f | 2012-05-12 02:09:42 +0200 | [diff] [blame] | 244 | return single_open(file, batadv_algo_seq_print_text, NULL); |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 245 | } |
| 246 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 247 | static int batadv_originators_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 248 | { |
| 249 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 7d211ef | 2012-05-12 02:09:34 +0200 | [diff] [blame] | 250 | return single_open(file, batadv_orig_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 251 | } |
| 252 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 253 | static int batadv_gateways_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 254 | { |
| 255 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 256 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 257 | } |
| 258 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 259 | static int batadv_transtable_global_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 260 | { |
| 261 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 262 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 263 | } |
| 264 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 265 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 266 | 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] | 267 | { |
| 268 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 269 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
| 270 | net_dev); |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 271 | } |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 272 | |
| 273 | static int batadv_bla_backbone_table_open(struct inode *inode, |
| 274 | struct file *file) |
| 275 | { |
| 276 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 277 | return single_open(file, batadv_bla_backbone_table_seq_print_text, |
| 278 | net_dev); |
| 279 | } |
| 280 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 281 | #endif |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 282 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 283 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 284 | /** |
| 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 | */ |
| 289 | static 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 | } |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 294 | #endif |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 295 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 296 | static int batadv_transtable_local_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 297 | { |
| 298 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 299 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 300 | } |
| 301 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 302 | static int batadv_vis_data_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 303 | { |
| 304 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | d0f714f | 2012-05-12 02:09:41 +0200 | [diff] [blame] | 305 | return single_open(file, batadv_vis_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 306 | } |
| 307 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 308 | struct batadv_debuginfo { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 309 | struct attribute attr; |
| 310 | const struct file_operations fops; |
| 311 | }; |
| 312 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 313 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 314 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 315 | .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 Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 323 | }; |
| 324 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 325 | /* the following attributes are general and therefore they will be directly |
| 326 | * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs |
| 327 | */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 328 | static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open); |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 329 | |
| 330 | static struct batadv_debuginfo *batadv_general_debuginfos[] = { |
| 331 | &batadv_debuginfo_routing_algos, |
| 332 | NULL, |
| 333 | }; |
| 334 | |
| 335 | /* The following attributes are per soft interface */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 336 | static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open); |
| 337 | static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open); |
| 338 | static BATADV_DEBUGINFO(transtable_global, S_IRUGO, |
| 339 | batadv_transtable_global_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 340 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 341 | static BATADV_DEBUGINFO(bla_claim_table, S_IRUGO, batadv_bla_claim_table_open); |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 342 | static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO, |
| 343 | batadv_bla_backbone_table_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 344 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 345 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 346 | static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open); |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 347 | #endif |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 348 | static BATADV_DEBUGINFO(transtable_local, S_IRUGO, |
| 349 | batadv_transtable_local_open); |
| 350 | static BATADV_DEBUGINFO(vis_data, S_IRUGO, batadv_vis_data_open); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 351 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 352 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 353 | &batadv_debuginfo_originators, |
| 354 | &batadv_debuginfo_gateways, |
| 355 | &batadv_debuginfo_transtable_global, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 356 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 357 | &batadv_debuginfo_bla_claim_table, |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 358 | &batadv_debuginfo_bla_backbone_table, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 359 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 360 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 361 | &batadv_debuginfo_dat_cache, |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 362 | #endif |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 363 | &batadv_debuginfo_transtable_local, |
| 364 | &batadv_debuginfo_vis_data, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 365 | NULL, |
| 366 | }; |
| 367 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 368 | void batadv_debugfs_init(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 369 | { |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 370 | struct batadv_debuginfo **bat_debug; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 371 | struct dentry *file; |
| 372 | |
Sven Eckelmann | 54590e4 | 2012-06-03 22:19:08 +0200 | [diff] [blame] | 373 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 374 | if (batadv_debugfs == ERR_PTR(-ENODEV)) |
| 375 | batadv_debugfs = NULL; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 376 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 377 | if (!batadv_debugfs) |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 378 | goto err; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 379 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 380 | for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) { |
| 381 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 382 | S_IFREG | ((*bat_debug)->attr).mode, |
| 383 | batadv_debugfs, NULL, |
| 384 | &(*bat_debug)->fops); |
| 385 | if (!file) { |
| 386 | pr_err("Can't add general debugfs file: %s\n", |
| 387 | ((*bat_debug)->attr).name); |
| 388 | goto err; |
| 389 | } |
| 390 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 391 | |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 392 | return; |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 393 | err: |
| 394 | debugfs_remove_recursive(batadv_debugfs); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 395 | } |
| 396 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 397 | void batadv_debugfs_destroy(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 398 | { |
Antonio Quartulli | 3f87c42 | 2012-11-29 01:03:31 +0100 | [diff] [blame] | 399 | debugfs_remove_recursive(batadv_debugfs); |
| 400 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 401 | } |
| 402 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 403 | int batadv_debugfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 404 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 405 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 406 | struct batadv_debuginfo **bat_debug; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 407 | struct dentry *file; |
| 408 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 409 | if (!batadv_debugfs) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 410 | goto out; |
| 411 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 412 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 413 | if (!bat_priv->debug_dir) |
| 414 | goto out; |
| 415 | |
Sven Eckelmann | 9039dc7 | 2012-05-12 02:09:33 +0200 | [diff] [blame] | 416 | if (batadv_socket_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 417 | goto rem_attr; |
| 418 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 419 | if (batadv_debug_log_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 420 | goto rem_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 421 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 422 | for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 423 | file = debugfs_create_file(((*bat_debug)->attr).name, |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 424 | S_IFREG | ((*bat_debug)->attr).mode, |
| 425 | bat_priv->debug_dir, |
| 426 | dev, &(*bat_debug)->fops); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 427 | if (!file) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 428 | batadv_err(dev, "Can't add debugfs file: %s/%s\n", |
| 429 | dev->name, ((*bat_debug)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 430 | goto rem_attr; |
| 431 | } |
| 432 | } |
| 433 | |
| 434 | return 0; |
| 435 | rem_attr: |
| 436 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 437 | bat_priv->debug_dir = NULL; |
| 438 | out: |
| 439 | #ifdef CONFIG_DEBUG_FS |
| 440 | return -ENOMEM; |
| 441 | #else |
| 442 | return 0; |
| 443 | #endif /* CONFIG_DEBUG_FS */ |
| 444 | } |
| 445 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 446 | void batadv_debugfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 447 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 448 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 449 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 450 | batadv_debug_log_cleanup(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 451 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 452 | if (batadv_debugfs) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 453 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 454 | bat_priv->debug_dir = NULL; |
| 455 | } |
| 456 | } |