2 * Copyright (C) 2007-2009 B.A.T.M.A.N. contributors:
4 * Marek Lindner, Simon Wunderlich
6 * This program is free software; you can redistribute it and/or
7 * modify it under the terms of version 2 of the GNU General Public
8 * License as published by the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
25 #include "translation-table.h"
26 #include "hard-interface.h"
31 static struct proc_dir_entry *proc_batman_dir, *proc_interface_file;
32 static struct proc_dir_entry *proc_orig_interval_file, *proc_originators_file;
33 static struct proc_dir_entry *proc_transt_local_file;
34 static struct proc_dir_entry *proc_transt_global_file;
35 static struct proc_dir_entry *proc_vis_srv_file, *proc_vis_data_file;
36 static struct proc_dir_entry *proc_aggr_file;
38 static int proc_interfaces_read(struct seq_file *seq, void *offset)
40 struct batman_if *batman_if;
43 list_for_each_entry_rcu(batman_if, &if_list, list) {
44 seq_printf(seq, "[%8s] %s %s \n",
45 (batman_if->if_active == IF_ACTIVE ?
46 "active" : "inactive"),
48 (batman_if->if_active == IF_ACTIVE ?
49 batman_if->addr_str : " "));
56 static int proc_interfaces_open(struct inode *inode, struct file *file)
58 return single_open(file, proc_interfaces_read, NULL);
61 static ssize_t proc_interfaces_write(struct file *instance,
62 const char __user *userbuffer,
63 size_t count, loff_t *data)
65 char *if_string, *colon_ptr = NULL, *cr_ptr = NULL;
66 int not_copied = 0, if_num = 0, add_success;
67 struct batman_if *batman_if = NULL;
69 if_string = kmalloc(count, GFP_KERNEL);
74 if (count > IFNAMSIZ - 1) {
75 printk(KERN_WARNING "batman-adv:Can't add interface: device name is too long\n");
79 not_copied = copy_from_user(if_string, userbuffer, count);
80 if_string[count - not_copied - 1] = 0;
82 colon_ptr = strchr(if_string, ':');
87 cr_ptr = strchr(if_string, '\n');
92 if (strlen(if_string) == 0) {
100 list_for_each_entry_rcu(batman_if, &if_list, list) {
101 if (strncmp(batman_if->dev, if_string, count) == 0) {
102 printk(KERN_ERR "batman-adv:Given interface is already active: %s\n", if_string);
112 add_success = hardif_add_interface(if_string, if_num);
116 num_ifs = if_num + 1;
118 if ((atomic_read(&module_state) == MODULE_INACTIVE) &&
119 (hardif_get_active_if_num() > 0))
128 static int proc_orig_interval_read(struct seq_file *seq, void *offset)
130 seq_printf(seq, "%i\n", atomic_read(&originator_interval));
135 static ssize_t proc_orig_interval_write(struct file *file,
136 const char __user *buffer,
137 size_t count, loff_t *ppos)
139 char *interval_string;
141 unsigned long originator_interval_tmp;
144 interval_string = kmalloc(count, GFP_KERNEL);
146 if (!interval_string)
149 not_copied = copy_from_user(interval_string, buffer, count);
150 interval_string[count - not_copied - 1] = 0;
152 retval = strict_strtoul(interval_string, 10, &originator_interval_tmp);
154 printk(KERN_ERR "batman-adv:New originator interval invalid\n");
158 if (originator_interval_tmp <= JITTER * 2) {
159 printk(KERN_WARNING "batman-adv:New originator interval too small: %li (min: %i)\n",
160 originator_interval_tmp, JITTER * 2);
164 printk(KERN_INFO "batman-adv:Changing originator interval from: %i to: %li\n",
165 atomic_read(&originator_interval), originator_interval_tmp);
167 atomic_set(&originator_interval, originator_interval_tmp);
170 kfree(interval_string);
174 static int proc_orig_interval_open(struct inode *inode, struct file *file)
176 return single_open(file, proc_orig_interval_read, NULL);
179 static int proc_originators_read(struct seq_file *seq, void *offset)
182 struct orig_node *orig_node;
183 struct neigh_node *neigh_node;
184 int batman_count = 0;
185 char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
189 if (list_empty(&if_list)) {
191 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
195 if (((struct batman_if *)if_list.next)->if_active != IF_ACTIVE) {
197 seq_printf(seq, "BATMAN disabled - primary interface not active \n");
202 " %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s] \n",
203 "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
204 "Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR,
205 ((struct batman_if *)if_list.next)->dev,
206 ((struct batman_if *)if_list.next)->addr_str);
209 spin_lock_irqsave(&orig_hash_lock, flags);
211 while (hash_iterate(orig_hash, &hashit)) {
213 orig_node = hashit.bucket->data;
215 if (!orig_node->router)
218 if (orig_node->router->tq_avg == 0)
223 addr_to_string(orig_str, orig_node->orig);
224 addr_to_string(router_str, orig_node->router->addr);
226 seq_printf(seq, "%-17s (%3i) %17s [%10s]:",
227 orig_str, orig_node->router->tq_avg,
228 router_str, orig_node->router->if_incoming->dev);
230 list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
231 addr_to_string(orig_str, neigh_node->addr);
232 seq_printf(seq, " %17s (%3i)",
233 orig_str, neigh_node->tq_avg);
236 seq_printf(seq, "\n");
240 spin_unlock_irqrestore(&orig_hash_lock, flags);
242 if (batman_count == 0)
243 seq_printf(seq, "No batman nodes in range ... \n");
249 static int proc_originators_open(struct inode *inode, struct file *file)
251 return single_open(file, proc_originators_read, NULL);
254 static int proc_transt_local_read(struct seq_file *seq, void *offset)
258 buf = kmalloc(4096, GFP_KERNEL);
263 if (list_empty(&if_list)) {
265 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
271 seq_printf(seq, "Locally retrieved addresses (from %s) announced via HNA:\n", soft_device->name);
273 hna_local_fill_buffer_text(buf, 4096);
274 seq_printf(seq, "%s", buf);
281 static int proc_transt_local_open(struct inode *inode, struct file *file)
283 return single_open(file, proc_transt_local_read, NULL);
286 static int proc_transt_global_read(struct seq_file *seq, void *offset)
290 buf = kmalloc(4096, GFP_KERNEL);
295 if (list_empty(&if_list)) {
297 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
303 seq_printf(seq, "Globally announced HNAs received via the mesh (translation table):\n");
305 hna_global_fill_buffer_text(buf, 4096);
306 seq_printf(seq, "%s", buf);
313 static int proc_transt_global_open(struct inode *inode, struct file *file)
315 return single_open(file, proc_transt_global_read, NULL);
318 /* setting the mode of the vis server by the user */
319 static ssize_t proc_vis_srv_write(struct file *file, const char __user * buffer,
320 size_t count, loff_t *ppos)
322 char *vis_mode_string;
325 vis_mode_string = kmalloc(count, GFP_KERNEL);
327 if (!vis_mode_string)
330 not_copied = copy_from_user(vis_mode_string, buffer, count);
331 vis_mode_string[count - not_copied - 1] = 0;
333 if ((strcmp(vis_mode_string, "client") == 0) ||
334 (strcmp(vis_mode_string, "disabled") == 0)) {
335 printk(KERN_INFO "batman-adv:Setting VIS mode to client (disabling vis server)\n");
336 atomic_set(&vis_mode, VIS_TYPE_CLIENT_UPDATE);
337 } else if ((strcmp(vis_mode_string, "server") == 0) ||
338 (strcmp(vis_mode_string, "enabled") == 0)) {
339 printk(KERN_INFO "batman-adv:Setting VIS mode to server (enabling vis server)\n");
340 atomic_set(&vis_mode, VIS_TYPE_SERVER_SYNC);
342 printk(KERN_ERR "batman-adv:Unknown VIS mode: %s\n",
345 kfree(vis_mode_string);
349 static int proc_vis_srv_read(struct seq_file *seq, void *offset)
351 int vis_server = atomic_read(&vis_mode);
353 seq_printf(seq, "[%c] client mode (server disabled) \n",
354 (vis_server == VIS_TYPE_CLIENT_UPDATE) ? 'x' : ' ');
355 seq_printf(seq, "[%c] server mode (server enabled) \n",
356 (vis_server == VIS_TYPE_SERVER_SYNC) ? 'x' : ' ');
361 static int proc_vis_srv_open(struct inode *inode, struct file *file)
363 return single_open(file, proc_vis_srv_read, NULL);
366 static int proc_vis_data_read(struct seq_file *seq, void *offset)
369 struct vis_info *info;
370 struct vis_info_entry *entries;
371 HLIST_HEAD(vis_if_list);
373 char tmp_addr_str[ETH_STR_LEN];
375 int vis_server = atomic_read(&vis_mode);
378 if (list_empty(&if_list) || (vis_server == VIS_TYPE_CLIENT_UPDATE)) {
385 spin_lock_irqsave(&vis_hash_lock, flags);
386 while (hash_iterate(vis_hash, &hashit)) {
387 info = hashit.bucket->data;
388 entries = (struct vis_info_entry *)
389 ((char *)info + sizeof(struct vis_info));
390 addr_to_string(tmp_addr_str, info->packet.vis_orig);
391 seq_printf(seq, "%s,", tmp_addr_str);
393 for (i = 0; i < info->packet.entries; i++) {
394 proc_vis_read_entry(seq, &entries[i], &vis_if_list,
395 info->packet.vis_orig);
398 /* add primary/secondary records */
399 proc_vis_read_prim_sec(seq, &vis_if_list);
400 seq_printf(seq, "\n");
402 spin_unlock_irqrestore(&vis_hash_lock, flags);
408 static int proc_vis_data_open(struct inode *inode, struct file *file)
410 return single_open(file, proc_vis_data_read, NULL);
413 static int proc_aggr_read(struct seq_file *seq, void *offset)
415 seq_printf(seq, "%i\n", atomic_read(&aggregation_enabled));
420 static ssize_t proc_aggr_write(struct file *file, const char __user *buffer,
421 size_t count, loff_t *ppos)
425 unsigned long aggregation_enabled_tmp;
428 aggr_string = kmalloc(count, GFP_KERNEL);
433 not_copied = copy_from_user(aggr_string, buffer, count);
434 aggr_string[count - not_copied - 1] = 0;
436 retval = strict_strtoul(aggr_string, 10, &aggregation_enabled_tmp);
438 if (retval || aggregation_enabled_tmp > 1) {
439 printk(KERN_ERR "batman-adv:Aggregation can only be enabled (1) or disabled (0), given value: %li\n", aggregation_enabled_tmp);
441 printk(KERN_INFO "batman-adv:Changing aggregation from: %s (%i) to: %s (%li)\n",
442 (atomic_read(&aggregation_enabled) == 1 ?
443 "enabled" : "disabled"),
444 atomic_read(&aggregation_enabled),
445 (aggregation_enabled_tmp == 1 ? "enabled" : "disabled"),
446 aggregation_enabled_tmp);
447 atomic_set(&aggregation_enabled,
448 (unsigned)aggregation_enabled_tmp);
455 static int proc_aggr_open(struct inode *inode, struct file *file)
457 return single_open(file, proc_aggr_read, NULL);
460 /* satisfying different prototypes ... */
461 static ssize_t proc_dummy_write(struct file *file, const char __user *buffer,
462 size_t count, loff_t *ppos)
467 static const struct file_operations proc_aggr_fops = {
468 .owner = THIS_MODULE,
469 .open = proc_aggr_open,
471 .write = proc_aggr_write,
473 .release = single_release,
476 static const struct file_operations proc_vis_srv_fops = {
477 .owner = THIS_MODULE,
478 .open = proc_vis_srv_open,
480 .write = proc_vis_srv_write,
482 .release = single_release,
485 static const struct file_operations proc_vis_data_fops = {
486 .owner = THIS_MODULE,
487 .open = proc_vis_data_open,
489 .write = proc_dummy_write,
491 .release = single_release,
494 static const struct file_operations proc_originators_fops = {
495 .owner = THIS_MODULE,
496 .open = proc_originators_open,
498 .write = proc_dummy_write,
500 .release = single_release,
503 static const struct file_operations proc_transt_local_fops = {
504 .owner = THIS_MODULE,
505 .open = proc_transt_local_open,
507 .write = proc_dummy_write,
509 .release = single_release,
512 static const struct file_operations proc_transt_global_fops = {
513 .owner = THIS_MODULE,
514 .open = proc_transt_global_open,
516 .write = proc_dummy_write,
518 .release = single_release,
521 static const struct file_operations proc_interfaces_fops = {
522 .owner = THIS_MODULE,
523 .open = proc_interfaces_open,
525 .write = proc_interfaces_write,
527 .release = single_release,
530 static const struct file_operations proc_orig_interval_fops = {
531 .owner = THIS_MODULE,
532 .open = proc_orig_interval_open,
534 .write = proc_orig_interval_write,
536 .release = single_release,
539 void cleanup_procfs(void)
541 if (proc_transt_global_file)
542 remove_proc_entry(PROC_FILE_TRANST_GLOBAL, proc_batman_dir);
544 if (proc_transt_local_file)
545 remove_proc_entry(PROC_FILE_TRANST_LOCAL, proc_batman_dir);
547 if (proc_originators_file)
548 remove_proc_entry(PROC_FILE_ORIGINATORS, proc_batman_dir);
550 if (proc_orig_interval_file)
551 remove_proc_entry(PROC_FILE_ORIG_INTERVAL, proc_batman_dir);
553 if (proc_interface_file)
554 remove_proc_entry(PROC_FILE_INTERFACES, proc_batman_dir);
556 if (proc_vis_data_file)
557 remove_proc_entry(PROC_FILE_VIS_DATA, proc_batman_dir);
559 if (proc_vis_srv_file)
560 remove_proc_entry(PROC_FILE_VIS_SRV, proc_batman_dir);
563 remove_proc_entry(PROC_FILE_AGGR, proc_batman_dir);
566 #ifdef __NET_NET_NAMESPACE_H
567 remove_proc_entry(PROC_ROOT_DIR, init_net.proc_net);
569 remove_proc_entry(PROC_ROOT_DIR, proc_net);
573 int setup_procfs(void)
575 #ifdef __NET_NET_NAMESPACE_H
576 proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, init_net.proc_net);
578 proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, proc_net);
581 if (!proc_batman_dir) {
582 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s' folder failed\n", PROC_ROOT_DIR);
586 proc_interface_file = create_proc_entry(PROC_FILE_INTERFACES,
589 if (proc_interface_file) {
590 proc_interface_file->proc_fops = &proc_interfaces_fops;
592 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_INTERFACES);
597 proc_orig_interval_file = create_proc_entry(PROC_FILE_ORIG_INTERVAL,
600 if (proc_orig_interval_file) {
601 proc_orig_interval_file->proc_fops = &proc_orig_interval_fops;
603 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIG_INTERVAL);
608 proc_originators_file = create_proc_entry(PROC_FILE_ORIGINATORS,
609 S_IRUGO, proc_batman_dir);
610 if (proc_originators_file) {
611 proc_originators_file->proc_fops = &proc_originators_fops;
613 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIGINATORS);
618 proc_transt_local_file = create_proc_entry(PROC_FILE_TRANST_LOCAL,
619 S_IRUGO, proc_batman_dir);
620 if (proc_transt_local_file) {
621 proc_transt_local_file->proc_fops = &proc_transt_local_fops;
623 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_LOCAL);
628 proc_transt_global_file = create_proc_entry(PROC_FILE_TRANST_GLOBAL,
629 S_IRUGO, proc_batman_dir);
630 if (proc_transt_global_file) {
631 proc_transt_global_file->proc_fops = &proc_transt_global_fops;
633 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_GLOBAL);
638 proc_vis_srv_file = create_proc_entry(PROC_FILE_VIS_SRV,
641 if (proc_vis_srv_file) {
642 proc_vis_srv_file->proc_fops = &proc_vis_srv_fops;
644 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS_SRV);
649 proc_vis_data_file = create_proc_entry(PROC_FILE_VIS_DATA, S_IRUGO,
651 if (proc_vis_data_file) {
652 proc_vis_data_file->proc_fops = &proc_vis_data_fops;
654 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS_DATA);
659 proc_aggr_file = create_proc_entry(PROC_FILE_AGGR, S_IWUSR | S_IRUGO,
661 if (proc_aggr_file) {
662 proc_aggr_file->proc_fops = &proc_aggr_fops;
664 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_AGGR);