Simon Wunderlich | e19f975 | 2014-01-04 18:04:25 +0100 | [diff] [blame] | 1 | /* Copyright (C) 2010-2014 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 |
Antonio Quartulli | ebf38fb | 2013-11-03 20:40:48 +0100 | [diff] [blame] | 15 | * along with this program; if not, see <http://www.gnu.org/licenses/>. |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include "main.h" |
| 19 | |
| 20 | #include <linux/debugfs.h> |
| 21 | |
Sven Eckelmann | b706b13 | 2012-06-10 23:58:51 +0200 | [diff] [blame] | 22 | #include "debugfs.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 23 | #include "translation-table.h" |
| 24 | #include "originator.h" |
| 25 | #include "hard-interface.h" |
| 26 | #include "gateway_common.h" |
| 27 | #include "gateway_client.h" |
| 28 | #include "soft-interface.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 29 | #include "icmp_socket.h" |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 30 | #include "bridge_loop_avoidance.h" |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 31 | #include "distributed-arp-table.h" |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 32 | #include "network-coding.h" |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 33 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 34 | static struct dentry *batadv_debugfs; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 35 | |
| 36 | #ifdef CONFIG_BATMAN_ADV_DEBUG |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 37 | #define BATADV_LOG_BUFF_MASK (batadv_log_buff_len - 1) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 38 | |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 39 | static const int batadv_log_buff_len = BATADV_LOG_BUF_LEN; |
| 40 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 41 | 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] | 42 | size_t idx) |
| 43 | { |
| 44 | return &debug_log->log_buff[idx & BATADV_LOG_BUFF_MASK]; |
| 45 | } |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 46 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 47 | static void batadv_emit_log_char(struct batadv_priv_debug_log *debug_log, |
| 48 | 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) |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 61 | static int batadv_fdebug_log(struct batadv_priv_debug_log *debug_log, |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 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 | { |
Sven Eckelmann | bd5b80d | 2012-08-20 23:37:26 +0200 | [diff] [blame] | 102 | if (!try_module_get(THIS_MODULE)) |
| 103 | return -EBUSY; |
| 104 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 105 | nonseekable_open(inode, file); |
| 106 | file->private_data = inode->i_private; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 107 | return 0; |
| 108 | } |
| 109 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 110 | static int batadv_log_release(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 111 | { |
Sven Eckelmann | bd5b80d | 2012-08-20 23:37:26 +0200 | [diff] [blame] | 112 | module_put(THIS_MODULE); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 113 | return 0; |
| 114 | } |
| 115 | |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 116 | static int batadv_log_empty(struct batadv_priv_debug_log *debug_log) |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 117 | { |
| 118 | return !(debug_log->log_start - debug_log->log_end); |
| 119 | } |
| 120 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 121 | static ssize_t batadv_log_read(struct file *file, char __user *buf, |
| 122 | size_t count, loff_t *ppos) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 123 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 124 | struct batadv_priv *bat_priv = file->private_data; |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 125 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 126 | int error, i = 0; |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 127 | char *char_addr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 128 | char c; |
| 129 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 130 | if ((file->f_flags & O_NONBLOCK) && batadv_log_empty(debug_log)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 131 | return -EAGAIN; |
| 132 | |
Sven Eckelmann | 16f14b4 | 2011-05-14 23:14:48 +0200 | [diff] [blame] | 133 | if (!buf) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 134 | return -EINVAL; |
| 135 | |
| 136 | if (count == 0) |
| 137 | return 0; |
| 138 | |
| 139 | if (!access_ok(VERIFY_WRITE, buf, count)) |
| 140 | return -EFAULT; |
| 141 | |
| 142 | error = wait_event_interruptible(debug_log->queue_wait, |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 143 | (!batadv_log_empty(debug_log))); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 144 | |
| 145 | if (error) |
| 146 | return error; |
| 147 | |
| 148 | spin_lock_bh(&debug_log->lock); |
| 149 | |
| 150 | while ((!error) && (i < count) && |
| 151 | (debug_log->log_start != debug_log->log_end)) { |
Sven Eckelmann | a8a0a62 | 2012-06-05 22:31:32 +0200 | [diff] [blame] | 152 | char_addr = batadv_log_char_addr(debug_log, |
| 153 | debug_log->log_start); |
| 154 | c = *char_addr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 155 | |
| 156 | debug_log->log_start++; |
| 157 | |
| 158 | spin_unlock_bh(&debug_log->lock); |
| 159 | |
| 160 | error = __put_user(c, buf); |
| 161 | |
| 162 | spin_lock_bh(&debug_log->lock); |
| 163 | |
| 164 | buf++; |
| 165 | i++; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 166 | } |
| 167 | |
| 168 | spin_unlock_bh(&debug_log->lock); |
| 169 | |
| 170 | if (!error) |
| 171 | return i; |
| 172 | |
| 173 | return error; |
| 174 | } |
| 175 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 176 | static unsigned int batadv_log_poll(struct file *file, poll_table *wait) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 177 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 178 | struct batadv_priv *bat_priv = file->private_data; |
Marek Lindner | 0abf5d8 | 2012-12-25 17:03:20 +0800 | [diff] [blame] | 179 | struct batadv_priv_debug_log *debug_log = bat_priv->debug_log; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 180 | |
| 181 | poll_wait(file, &debug_log->queue_wait, wait); |
| 182 | |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 183 | if (!batadv_log_empty(debug_log)) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 184 | return POLLIN | POLLRDNORM; |
| 185 | |
| 186 | return 0; |
| 187 | } |
| 188 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 189 | static const struct file_operations batadv_log_fops = { |
| 190 | .open = batadv_log_open, |
| 191 | .release = batadv_log_release, |
| 192 | .read = batadv_log_read, |
| 193 | .poll = batadv_log_poll, |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 194 | .llseek = no_llseek, |
| 195 | }; |
| 196 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 197 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 198 | { |
| 199 | struct dentry *d; |
| 200 | |
| 201 | if (!bat_priv->debug_dir) |
| 202 | goto err; |
| 203 | |
Sven Eckelmann | 704509b | 2011-05-14 23:14:54 +0200 | [diff] [blame] | 204 | bat_priv->debug_log = kzalloc(sizeof(*bat_priv->debug_log), GFP_ATOMIC); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 205 | if (!bat_priv->debug_log) |
| 206 | goto err; |
| 207 | |
| 208 | spin_lock_init(&bat_priv->debug_log->lock); |
| 209 | init_waitqueue_head(&bat_priv->debug_log->queue_wait); |
| 210 | |
| 211 | d = debugfs_create_file("log", S_IFREG | S_IRUSR, |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 212 | bat_priv->debug_dir, bat_priv, |
| 213 | &batadv_log_fops); |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 214 | if (!d) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 215 | goto err; |
| 216 | |
| 217 | return 0; |
| 218 | |
| 219 | err: |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 220 | return -ENOMEM; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 221 | } |
| 222 | |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 223 | static void batadv_debug_log_cleanup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 224 | { |
| 225 | kfree(bat_priv->debug_log); |
| 226 | bat_priv->debug_log = NULL; |
| 227 | } |
| 228 | #else /* CONFIG_BATMAN_ADV_DEBUG */ |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 229 | static int batadv_debug_log_setup(struct batadv_priv *bat_priv) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 230 | { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 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 | |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 251 | /** |
| 252 | * batadv_originators_hardif_open - handles debugfs output for the |
| 253 | * originator table of an hard interface |
| 254 | * @inode: inode pointer to debugfs file |
| 255 | * @file: pointer to the seq_file |
| 256 | */ |
| 257 | static int batadv_originators_hardif_open(struct inode *inode, |
| 258 | struct file *file) |
| 259 | { |
| 260 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 261 | return single_open(file, batadv_orig_hardif_seq_print_text, net_dev); |
| 262 | } |
| 263 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 264 | static int batadv_gateways_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 265 | { |
| 266 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 7cf06bc | 2012-05-12 02:09:29 +0200 | [diff] [blame] | 267 | return single_open(file, batadv_gw_client_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 268 | } |
| 269 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 270 | static int batadv_transtable_global_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 271 | { |
| 272 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 273 | return single_open(file, batadv_tt_global_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 274 | } |
| 275 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 276 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 277 | 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] | 278 | { |
| 279 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08adf15 | 2012-05-12 13:38:47 +0200 | [diff] [blame] | 280 | return single_open(file, batadv_bla_claim_table_seq_print_text, |
| 281 | net_dev); |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 282 | } |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 283 | |
| 284 | static int batadv_bla_backbone_table_open(struct inode *inode, |
| 285 | struct file *file) |
| 286 | { |
| 287 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 288 | return single_open(file, batadv_bla_backbone_table_seq_print_text, |
| 289 | net_dev); |
| 290 | } |
| 291 | |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 292 | #endif |
Simon Wunderlich | 9bf8e4d | 2012-01-22 20:00:21 +0100 | [diff] [blame] | 293 | |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 294 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 295 | /** |
| 296 | * batadv_dat_cache_open - Prepare file handler for reads from dat_chache |
| 297 | * @inode: inode which was opened |
| 298 | * @file: file handle to be initialized |
| 299 | */ |
| 300 | static int batadv_dat_cache_open(struct inode *inode, struct file *file) |
| 301 | { |
| 302 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 303 | return single_open(file, batadv_dat_cache_seq_print_text, net_dev); |
| 304 | } |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 305 | #endif |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 306 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 307 | static int batadv_transtable_local_open(struct inode *inode, struct file *file) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 308 | { |
| 309 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
Sven Eckelmann | 08c36d3 | 2012-05-12 02:09:39 +0200 | [diff] [blame] | 310 | return single_open(file, batadv_tt_local_seq_print_text, net_dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 311 | } |
| 312 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 313 | struct batadv_debuginfo { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 314 | struct attribute attr; |
| 315 | const struct file_operations fops; |
| 316 | }; |
| 317 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 318 | #ifdef CONFIG_BATMAN_ADV_NC |
| 319 | static int batadv_nc_nodes_open(struct inode *inode, struct file *file) |
| 320 | { |
| 321 | struct net_device *net_dev = (struct net_device *)inode->i_private; |
| 322 | return single_open(file, batadv_nc_nodes_seq_print_text, net_dev); |
| 323 | } |
| 324 | #endif |
| 325 | |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 326 | #define BATADV_DEBUGINFO(_name, _mode, _open) \ |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 327 | struct batadv_debuginfo batadv_debuginfo_##_name = { \ |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 328 | .attr = { .name = __stringify(_name), \ |
| 329 | .mode = _mode, }, \ |
| 330 | .fops = { .owner = THIS_MODULE, \ |
| 331 | .open = _open, \ |
| 332 | .read = seq_read, \ |
| 333 | .llseek = seq_lseek, \ |
| 334 | .release = single_release, \ |
| 335 | } \ |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 336 | }; |
| 337 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 338 | /* the following attributes are general and therefore they will be directly |
| 339 | * placed in the BATADV_DEBUGFS_SUBDIR subdirectory of debugfs |
| 340 | */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 341 | static BATADV_DEBUGINFO(routing_algos, S_IRUGO, batadv_algorithms_open); |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 342 | |
| 343 | static struct batadv_debuginfo *batadv_general_debuginfos[] = { |
| 344 | &batadv_debuginfo_routing_algos, |
| 345 | NULL, |
| 346 | }; |
| 347 | |
| 348 | /* The following attributes are per soft interface */ |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 349 | static BATADV_DEBUGINFO(originators, S_IRUGO, batadv_originators_open); |
| 350 | static BATADV_DEBUGINFO(gateways, S_IRUGO, batadv_gateways_open); |
| 351 | static BATADV_DEBUGINFO(transtable_global, S_IRUGO, |
| 352 | batadv_transtable_global_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 353 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 354 | 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] | 355 | static BATADV_DEBUGINFO(bla_backbone_table, S_IRUGO, |
| 356 | batadv_bla_backbone_table_open); |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 357 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 358 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 359 | static BATADV_DEBUGINFO(dat_cache, S_IRUGO, batadv_dat_cache_open); |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 360 | #endif |
Sven Eckelmann | 347c80f | 2012-06-03 22:19:07 +0200 | [diff] [blame] | 361 | static BATADV_DEBUGINFO(transtable_local, S_IRUGO, |
| 362 | batadv_transtable_local_open); |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 363 | #ifdef CONFIG_BATMAN_ADV_NC |
| 364 | static BATADV_DEBUGINFO(nc_nodes, S_IRUGO, batadv_nc_nodes_open); |
| 365 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 366 | |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 367 | static struct batadv_debuginfo *batadv_mesh_debuginfos[] = { |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 368 | &batadv_debuginfo_originators, |
| 369 | &batadv_debuginfo_gateways, |
| 370 | &batadv_debuginfo_transtable_global, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 371 | #ifdef CONFIG_BATMAN_ADV_BLA |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 372 | &batadv_debuginfo_bla_claim_table, |
Simon Wunderlich | 536a23f | 2012-06-18 18:39:26 +0200 | [diff] [blame] | 373 | &batadv_debuginfo_bla_backbone_table, |
Simon Wunderlich | 7a5cc24 | 2012-01-22 20:00:27 +0100 | [diff] [blame] | 374 | #endif |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 375 | #ifdef CONFIG_BATMAN_ADV_DAT |
Antonio Quartulli | 2f1dfbe | 2012-06-30 20:01:19 +0200 | [diff] [blame] | 376 | &batadv_debuginfo_dat_cache, |
Antonio Quartulli | 1722447 | 2011-11-06 12:23:55 +0100 | [diff] [blame] | 377 | #endif |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 378 | &batadv_debuginfo_transtable_local, |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 379 | #ifdef CONFIG_BATMAN_ADV_NC |
| 380 | &batadv_debuginfo_nc_nodes, |
| 381 | #endif |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 382 | NULL, |
| 383 | }; |
| 384 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 385 | #define BATADV_HARDIF_DEBUGINFO(_name, _mode, _open) \ |
| 386 | struct batadv_debuginfo batadv_hardif_debuginfo_##_name = { \ |
| 387 | .attr = { \ |
| 388 | .name = __stringify(_name), \ |
| 389 | .mode = _mode, \ |
| 390 | }, \ |
| 391 | .fops = { \ |
| 392 | .owner = THIS_MODULE, \ |
| 393 | .open = _open, \ |
| 394 | .read = seq_read, \ |
| 395 | .llseek = seq_lseek, \ |
| 396 | .release = single_release, \ |
| 397 | }, \ |
| 398 | }; |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 399 | static BATADV_HARDIF_DEBUGINFO(originators, S_IRUGO, |
| 400 | batadv_originators_hardif_open); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 401 | |
| 402 | static struct batadv_debuginfo *batadv_hardif_debuginfos[] = { |
Simon Wunderlich | cb1c92e | 2013-11-21 11:52:16 +0100 | [diff] [blame] | 403 | &batadv_hardif_debuginfo_originators, |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 404 | NULL, |
| 405 | }; |
| 406 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 407 | void batadv_debugfs_init(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 408 | { |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 409 | struct batadv_debuginfo **bat_debug; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 410 | struct dentry *file; |
| 411 | |
Sven Eckelmann | 54590e4 | 2012-06-03 22:19:08 +0200 | [diff] [blame] | 412 | batadv_debugfs = debugfs_create_dir(BATADV_DEBUGFS_SUBDIR, NULL); |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 413 | if (batadv_debugfs == ERR_PTR(-ENODEV)) |
| 414 | batadv_debugfs = NULL; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 415 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 416 | if (!batadv_debugfs) |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 417 | goto err; |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 418 | |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 419 | for (bat_debug = batadv_general_debuginfos; *bat_debug; ++bat_debug) { |
| 420 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 421 | S_IFREG | ((*bat_debug)->attr).mode, |
| 422 | batadv_debugfs, NULL, |
| 423 | &(*bat_debug)->fops); |
| 424 | if (!file) { |
| 425 | pr_err("Can't add general debugfs file: %s\n", |
| 426 | ((*bat_debug)->attr).name); |
| 427 | goto err; |
| 428 | } |
| 429 | } |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 430 | |
Marek Lindner | 1c28047 | 2011-11-28 17:40:17 +0800 | [diff] [blame] | 431 | return; |
Antonio Quartulli | 637fbd1 | 2012-10-16 10:04:39 +0200 | [diff] [blame] | 432 | err: |
| 433 | debugfs_remove_recursive(batadv_debugfs); |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 434 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 435 | } |
| 436 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 437 | void batadv_debugfs_destroy(void) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 438 | { |
Antonio Quartulli | 3f87c42 | 2012-11-29 01:03:31 +0100 | [diff] [blame] | 439 | debugfs_remove_recursive(batadv_debugfs); |
| 440 | batadv_debugfs = NULL; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 441 | } |
| 442 | |
Simon Wunderlich | 5bc7c1e | 2013-11-21 14:16:12 +0100 | [diff] [blame] | 443 | /** |
| 444 | * batadv_debugfs_add_hardif - creates the base directory for a hard interface |
| 445 | * in debugfs. |
| 446 | * @hard_iface: hard interface which should be added. |
| 447 | */ |
| 448 | int batadv_debugfs_add_hardif(struct batadv_hard_iface *hard_iface) |
| 449 | { |
| 450 | struct batadv_debuginfo **bat_debug; |
| 451 | struct dentry *file; |
| 452 | |
| 453 | if (!batadv_debugfs) |
| 454 | goto out; |
| 455 | |
| 456 | hard_iface->debug_dir = debugfs_create_dir(hard_iface->net_dev->name, |
| 457 | batadv_debugfs); |
| 458 | if (!hard_iface->debug_dir) |
| 459 | goto out; |
| 460 | |
| 461 | for (bat_debug = batadv_hardif_debuginfos; *bat_debug; ++bat_debug) { |
| 462 | file = debugfs_create_file(((*bat_debug)->attr).name, |
| 463 | S_IFREG | ((*bat_debug)->attr).mode, |
| 464 | hard_iface->debug_dir, |
| 465 | hard_iface->net_dev, |
| 466 | &(*bat_debug)->fops); |
| 467 | if (!file) |
| 468 | goto rem_attr; |
| 469 | } |
| 470 | |
| 471 | return 0; |
| 472 | rem_attr: |
| 473 | debugfs_remove_recursive(hard_iface->debug_dir); |
| 474 | hard_iface->debug_dir = NULL; |
| 475 | out: |
| 476 | #ifdef CONFIG_DEBUG_FS |
| 477 | return -ENOMEM; |
| 478 | #else |
| 479 | return 0; |
| 480 | #endif /* CONFIG_DEBUG_FS */ |
| 481 | } |
| 482 | |
| 483 | /** |
| 484 | * batadv_debugfs_del_hardif - delete the base directory for a hard interface |
| 485 | * in debugfs. |
| 486 | * @hard_iface: hard interface which is deleted. |
| 487 | */ |
| 488 | void batadv_debugfs_del_hardif(struct batadv_hard_iface *hard_iface) |
| 489 | { |
| 490 | if (batadv_debugfs) { |
| 491 | debugfs_remove_recursive(hard_iface->debug_dir); |
| 492 | hard_iface->debug_dir = NULL; |
| 493 | } |
| 494 | } |
| 495 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 496 | int batadv_debugfs_add_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 497 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 498 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | 7f223c0 | 2012-06-05 22:31:27 +0200 | [diff] [blame] | 499 | struct batadv_debuginfo **bat_debug; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 500 | struct dentry *file; |
| 501 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 502 | if (!batadv_debugfs) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 503 | goto out; |
| 504 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 505 | bat_priv->debug_dir = debugfs_create_dir(dev->name, batadv_debugfs); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 506 | if (!bat_priv->debug_dir) |
| 507 | goto out; |
| 508 | |
Sven Eckelmann | 9039dc7 | 2012-05-12 02:09:33 +0200 | [diff] [blame] | 509 | if (batadv_socket_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 510 | goto rem_attr; |
| 511 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 512 | if (batadv_debug_log_setup(bat_priv) < 0) |
Sven Eckelmann | 5346c35 | 2012-05-05 13:27:28 +0200 | [diff] [blame] | 513 | goto rem_attr; |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 514 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 515 | for (bat_debug = batadv_mesh_debuginfos; *bat_debug; ++bat_debug) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 516 | file = debugfs_create_file(((*bat_debug)->attr).name, |
Sven Eckelmann | 0aca236 | 2012-06-19 20:26:30 +0200 | [diff] [blame] | 517 | S_IFREG | ((*bat_debug)->attr).mode, |
| 518 | bat_priv->debug_dir, |
| 519 | dev, &(*bat_debug)->fops); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 520 | if (!file) { |
Sven Eckelmann | 3e34819 | 2012-05-16 20:23:22 +0200 | [diff] [blame] | 521 | batadv_err(dev, "Can't add debugfs file: %s/%s\n", |
| 522 | dev->name, ((*bat_debug)->attr).name); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 523 | goto rem_attr; |
| 524 | } |
| 525 | } |
| 526 | |
Martin Hundebøll | d56b170 | 2013-01-25 11:12:39 +0100 | [diff] [blame] | 527 | if (batadv_nc_init_debugfs(bat_priv) < 0) |
| 528 | goto rem_attr; |
| 529 | |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 530 | return 0; |
| 531 | rem_attr: |
| 532 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 533 | bat_priv->debug_dir = NULL; |
| 534 | out: |
| 535 | #ifdef CONFIG_DEBUG_FS |
| 536 | return -ENOMEM; |
| 537 | #else |
| 538 | return 0; |
| 539 | #endif /* CONFIG_DEBUG_FS */ |
| 540 | } |
| 541 | |
Sven Eckelmann | 40a072d | 2012-05-12 02:09:23 +0200 | [diff] [blame] | 542 | void batadv_debugfs_del_meshif(struct net_device *dev) |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 543 | { |
Sven Eckelmann | 56303d3 | 2012-06-05 22:31:31 +0200 | [diff] [blame] | 544 | struct batadv_priv *bat_priv = netdev_priv(dev); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 545 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 546 | batadv_debug_log_cleanup(bat_priv); |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 547 | |
Sven Eckelmann | 9e46625 | 2012-05-12 18:33:50 +0200 | [diff] [blame] | 548 | if (batadv_debugfs) { |
Sven Eckelmann | c6c8fea | 2010-12-13 11:19:28 +0000 | [diff] [blame] | 549 | debugfs_remove_recursive(bat_priv->debug_dir); |
| 550 | bat_priv->debug_dir = NULL; |
| 551 | } |
| 552 | } |