Merge branch 'master' of git://git2.kernel.org/pub/scm/linux/kernel/git/torvalds...
[linux-2.6/linux-2.6-openrd.git] / drivers / staging / batman-adv / proc.c
blobaac3df7f13fba6bc0e78d356440d663eba23d5c1
1 /*
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
18 * 02110-1301, USA
22 #include "main.h"
23 #include "proc.h"
24 #include "log.h"
25 #include "routing.h"
26 #include "translation-table.h"
27 #include "hard-interface.h"
28 #include "types.h"
29 #include "hash.h"
30 #include "vis.h"
31 #include "compat.h"
33 static uint8_t vis_format = DOT_DRAW;
35 static struct proc_dir_entry *proc_batman_dir, *proc_interface_file;
36 static struct proc_dir_entry *proc_orig_interval_file, *proc_originators_file;
37 static struct proc_dir_entry *proc_log_file, *proc_log_level_file;
38 static struct proc_dir_entry *proc_transt_local_file;
39 static struct proc_dir_entry *proc_transt_global_file;
40 static struct proc_dir_entry *proc_vis_file, *proc_vis_format_file;
41 static struct proc_dir_entry *proc_aggr_file;
43 static int proc_interfaces_read(struct seq_file *seq, void *offset)
45 struct batman_if *batman_if;
47 rcu_read_lock();
48 list_for_each_entry_rcu(batman_if, &if_list, list) {
49 seq_printf(seq, "[%8s] %s %s \n",
50 (batman_if->if_active == IF_ACTIVE ?
51 "active" : "inactive"),
52 batman_if->dev,
53 (batman_if->if_active == IF_ACTIVE ?
54 batman_if->addr_str : " "));
56 rcu_read_unlock();
58 return 0;
61 static int proc_interfaces_open(struct inode *inode, struct file *file)
63 return single_open(file, proc_interfaces_read, NULL);
66 static ssize_t proc_interfaces_write(struct file *instance,
67 const char __user *userbuffer,
68 size_t count, loff_t *data)
70 char *if_string, *colon_ptr = NULL, *cr_ptr = NULL;
71 int not_copied = 0, if_num = 0;
72 struct batman_if *batman_if = NULL;
74 if_string = kmalloc(count, GFP_KERNEL);
76 if (!if_string)
77 return -ENOMEM;
79 if (count > IFNAMSIZ - 1) {
80 debug_log(LOG_TYPE_WARN,
81 "Can't add interface: device name is too long\n");
82 goto end;
85 not_copied = copy_from_user(if_string, userbuffer, count);
86 if_string[count - not_copied - 1] = 0;
88 colon_ptr = strchr(if_string, ':');
89 if (colon_ptr)
90 *colon_ptr = 0;
92 if (!colon_ptr) {
93 cr_ptr = strchr(if_string, '\n');
94 if (cr_ptr)
95 *cr_ptr = 0;
98 if (strlen(if_string) == 0) {
99 shutdown_module();
100 num_ifs = 0;
101 goto end;
104 /* add interface */
105 rcu_read_lock();
106 list_for_each_entry_rcu(batman_if, &if_list, list) {
107 if (strncmp(batman_if->dev, if_string, count) == 0) {
108 debug_log(LOG_TYPE_WARN, "Given interface is already active: %s\n", if_string);
109 rcu_read_unlock();
110 goto end;
114 if_num++;
116 rcu_read_unlock();
118 hardif_add_interface(if_string, if_num);
120 if ((atomic_read(&module_state) == MODULE_INACTIVE) &&
121 (hardif_get_active_if_num() > 0))
122 activate_module();
124 rcu_read_lock();
125 if (list_empty(&if_list)) {
126 rcu_read_unlock();
127 goto end;
129 rcu_read_unlock();
131 num_ifs = if_num + 1;
132 return count;
134 end:
135 kfree(if_string);
136 return count;
139 static int proc_orig_interval_read(struct seq_file *seq, void *offset)
141 seq_printf(seq, "%i\n", atomic_read(&originator_interval));
143 return 0;
146 static ssize_t proc_orig_interval_write(struct file *file,
147 const char __user *buffer,
148 size_t count, loff_t *ppos)
150 char *interval_string;
151 int not_copied = 0;
152 unsigned long originator_interval_tmp;
153 int retval;
155 interval_string = kmalloc(count, GFP_KERNEL);
157 if (!interval_string)
158 return -ENOMEM;
160 not_copied = copy_from_user(interval_string, buffer, count);
161 interval_string[count - not_copied - 1] = 0;
163 retval = strict_strtoul(interval_string, 10, &originator_interval_tmp);
164 if (retval) {
165 debug_log(LOG_TYPE_WARN, "New originator interval invalid\n");
166 goto end;
169 if (originator_interval_tmp <= JITTER * 2) {
170 debug_log(LOG_TYPE_WARN,
171 "New originator interval too small: %i (min: %i)\n",
172 originator_interval_tmp, JITTER * 2);
173 goto end;
176 debug_log(LOG_TYPE_NOTICE,
177 "Changing originator interval from: %i to: %i\n",
178 atomic_read(&originator_interval), originator_interval_tmp);
180 atomic_set(&originator_interval, originator_interval_tmp);
182 end:
183 kfree(interval_string);
184 return count;
187 static int proc_orig_interval_open(struct inode *inode, struct file *file)
189 return single_open(file, proc_orig_interval_read, NULL);
192 static int proc_originators_read(struct seq_file *seq, void *offset)
194 struct hash_it_t *hashit = NULL;
195 struct orig_node *orig_node;
196 struct neigh_node *neigh_node;
197 int batman_count = 0;
198 char orig_str[ETH_STR_LEN], router_str[ETH_STR_LEN];
200 rcu_read_lock();
201 if (list_empty(&if_list)) {
202 rcu_read_unlock();
203 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
204 goto end;
207 if (((struct batman_if *)if_list.next)->if_active != IF_ACTIVE) {
208 rcu_read_unlock();
209 seq_printf(seq, "BATMAN disabled - primary interface not active \n");
210 goto end;
213 seq_printf(seq,
214 " %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s] \n",
215 "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
216 "Potential nexthops", SOURCE_VERSION, REVISION_VERSION_STR,
217 ((struct batman_if *)if_list.next)->dev,
218 ((struct batman_if *)if_list.next)->addr_str);
220 rcu_read_unlock();
221 spin_lock(&orig_hash_lock);
223 while (NULL != (hashit = hash_iterate(orig_hash, hashit))) {
225 orig_node = hashit->bucket->data;
227 if (!orig_node->router)
228 continue;
230 if (orig_node->router->tq_avg == 0)
231 continue;
233 batman_count++;
235 addr_to_string(orig_str, orig_node->orig);
236 addr_to_string(router_str, orig_node->router->addr);
238 seq_printf(seq, "%-17s (%3i) %17s [%10s]:",
239 orig_str, orig_node->router->tq_avg,
240 router_str, orig_node->router->if_incoming->dev);
242 list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
243 addr_to_string(orig_str, neigh_node->addr);
244 seq_printf(seq, " %17s (%3i)",
245 orig_str, neigh_node->tq_avg);
248 seq_printf(seq, "\n");
252 spin_unlock(&orig_hash_lock);
254 if (batman_count == 0)
255 seq_printf(seq, "No batman nodes in range ... \n");
257 end:
258 return 0;
261 static int proc_originators_open(struct inode *inode, struct file *file)
263 return single_open(file, proc_originators_read, NULL);
266 static int proc_log_level_read(struct seq_file *seq, void *offset)
269 seq_printf(seq, "[x] %s (%d)\n", LOG_TYPE_CRIT_NAME, LOG_TYPE_CRIT);
270 seq_printf(seq, "[%c] %s (%d)\n",
271 (LOG_TYPE_WARN & log_level) ? 'x' : ' ',
272 LOG_TYPE_WARN_NAME, LOG_TYPE_WARN);
273 seq_printf(seq, "[%c] %s (%d)\n",
274 (LOG_TYPE_NOTICE & log_level) ? 'x' : ' ',
275 LOG_TYPE_NOTICE_NAME, LOG_TYPE_NOTICE);
276 seq_printf(seq, "[%c] %s (%d)\n",
277 (LOG_TYPE_BATMAN & log_level) ? 'x' : ' ',
278 LOG_TYPE_BATMAN_NAME, LOG_TYPE_BATMAN);
279 seq_printf(seq, "[%c] %s (%d)\n",
280 (LOG_TYPE_ROUTES & log_level) ? 'x' : ' ',
281 LOG_TYPE_ROUTES_NAME, LOG_TYPE_ROUTES);
282 return 0;
285 static int proc_log_level_open(struct inode *inode, struct file *file)
287 return single_open(file, proc_log_level_read, NULL);
290 static ssize_t proc_log_level_write(struct file *instance,
291 const char __user *userbuffer,
292 size_t count, loff_t *data)
294 char *log_level_string, *tokptr, *cp;
295 int finished, not_copied = 0;
296 unsigned long log_level_tmp = 0;
298 log_level_string = kmalloc(count, GFP_KERNEL);
300 if (!log_level_string)
301 return -ENOMEM;
303 not_copied = copy_from_user(log_level_string, userbuffer, count);
304 log_level_string[count - not_copied - 1] = 0;
306 if (strict_strtoul(log_level_string, 10, &log_level_tmp) < 0) {
307 /* was not a number, doing textual parsing */
308 log_level_tmp = 0;
309 tokptr = log_level_string;
311 for (cp = log_level_string, finished = 0; !finished; cp++) {
312 switch (*cp) {
313 case 0:
314 finished = 1;
315 case ' ':
316 case '\n':
317 case '\t':
318 *cp = 0;
319 /* compare */
320 if (strcmp(tokptr, LOG_TYPE_WARN_NAME) == 0)
321 log_level_tmp |= LOG_TYPE_WARN;
322 if (strcmp(tokptr, LOG_TYPE_NOTICE_NAME) == 0)
323 log_level_tmp |= LOG_TYPE_NOTICE;
324 if (strcmp(tokptr, LOG_TYPE_BATMAN_NAME) == 0)
325 log_level_tmp |= LOG_TYPE_BATMAN;
326 if (strcmp(tokptr, LOG_TYPE_ROUTES_NAME) == 0)
327 log_level_tmp |= LOG_TYPE_ROUTES;
328 tokptr = cp + 1;
329 break;
330 default:
336 debug_log(LOG_TYPE_CRIT, "Changing log_level from: %i to: %i\n",
337 log_level, log_level_tmp);
338 log_level = log_level_tmp;
340 kfree(log_level_string);
341 return count;
344 static int proc_transt_local_read(struct seq_file *seq, void *offset)
346 char *buf;
348 buf = kmalloc(4096, GFP_KERNEL);
349 if (!buf)
350 return 0;
352 rcu_read_lock();
353 if (list_empty(&if_list)) {
354 rcu_read_unlock();
355 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
356 goto end;
359 rcu_read_unlock();
361 seq_printf(seq, "Locally retrieved addresses (from %s) announced via HNA:\n", soft_device->name);
363 hna_local_fill_buffer_text(buf, 4096);
364 seq_printf(seq, "%s", buf);
366 end:
367 kfree(buf);
368 return 0;
371 static int proc_transt_local_open(struct inode *inode, struct file *file)
373 return single_open(file, proc_transt_local_read, NULL);
376 static int proc_transt_global_read(struct seq_file *seq, void *offset)
378 char *buf;
380 buf = kmalloc(4096, GFP_KERNEL);
381 if (!buf)
382 return 0;
384 rcu_read_lock();
385 if (list_empty(&if_list)) {
386 rcu_read_unlock();
387 seq_printf(seq, "BATMAN disabled - please specify interfaces to enable it \n");
388 goto end;
390 rcu_read_unlock();
393 seq_printf(seq, "Globally announced HNAs received via the mesh (translation table):\n");
395 hna_global_fill_buffer_text(buf, 4096);
396 seq_printf(seq, "%s", buf);
398 end:
399 kfree(buf);
400 return 0;
403 static int proc_transt_global_open(struct inode *inode, struct file *file)
405 return single_open(file, proc_transt_global_read, NULL);
408 /* insert interface to the list of interfaces of one originator */
410 static void proc_vis_insert_interface(const uint8_t *interface,
411 struct vis_if_list **if_entry,
412 bool primary)
414 /* Did we get an empty list? (then insert imediately) */
415 if(*if_entry == NULL) {
416 *if_entry = kmalloc(sizeof(struct vis_if_list), GFP_KERNEL);
417 if (*if_entry == NULL)
418 return;
420 (*if_entry)->primary = primary;
421 (*if_entry)->next = NULL;
422 memcpy((*if_entry)->addr, interface, ETH_ALEN);
423 } else {
424 struct vis_if_list *head_if_entry = *if_entry;
425 /* Do we already have this interface in our list? */
426 while (!compare_orig((*if_entry)->addr, (void *)interface)) {
428 /* Or did we reach the end (then append the interface) */
429 if ((*if_entry)->next == NULL) {
430 (*if_entry)->next = kmalloc(sizeof(struct vis_if_list), GFP_KERNEL);
431 if ((*if_entry)->next == NULL)
432 return;
434 memcpy((*if_entry)->next->addr, interface, ETH_ALEN);
435 (*if_entry)->next->primary = primary;
436 (*if_entry)->next->next = NULL;
437 break;
439 *if_entry = (*if_entry)->next;
441 /* Rewind the list to its head */
442 *if_entry = head_if_entry;
445 /* read an entry */
447 static void proc_vis_read_entry(struct seq_file *seq,
448 struct vis_info_entry *entry,
449 struct vis_if_list **if_entry,
450 uint8_t *vis_orig,
451 uint8_t current_format,
452 uint8_t first_line)
454 char from[40];
455 char to[40];
456 int int_part, frac_part;
458 addr_to_string(to, entry->dest);
459 if (entry->quality == 0) {
460 #ifndef VIS_SUBCLUSTERS_DISABLED
461 proc_vis_insert_interface(vis_orig, if_entry, true);
462 #endif /* VIS_SUBCLUSTERS_DISABLED */
463 addr_to_string(from, vis_orig);
464 if (current_format == DOT_DRAW) {
465 seq_printf(seq, "\t\"%s\" -> \"%s\" [label=\"HNA\"]\n",
466 from, to);
467 } else {
468 seq_printf(seq,
469 "%s\t{ router : \"%s\", gateway : \"%s\", label : \"HNA\" }",
470 (first_line ? "" : ",\n"), from, to);
472 } else {
473 #ifndef VIS_SUBCLUSTERS_DISABLED
474 proc_vis_insert_interface(entry->src, if_entry, compare_orig(entry->src, vis_orig));
475 #endif /* VIS_SUBCLUSTERS_DISABLED */
476 addr_to_string(from, entry->src);
478 /* kernel has no printf-support for %f? it'd be better to return
479 * this in float. */
481 int_part = TQ_MAX_VALUE / entry->quality;
482 frac_part = 1000 * TQ_MAX_VALUE / entry->quality - int_part * 1000;
484 if (current_format == DOT_DRAW) {
485 seq_printf(seq,
486 "\t\"%s\" -> \"%s\" [label=\"%d.%d\"]\n",
487 from, to, int_part, frac_part);
488 } else {
489 seq_printf(seq,
490 "%s\t{ router : \"%s\", neighbour : \"%s\", label : %d.%d }",
491 (first_line ? "" : ",\n"), from, to, int_part, frac_part);
497 static int proc_vis_read(struct seq_file *seq, void *offset)
499 struct hash_it_t *hashit = NULL;
500 struct vis_info *info;
501 struct vis_info_entry *entries;
502 struct vis_if_list *if_entries = NULL;
503 int i;
504 uint8_t current_format, first_line = 1;
505 #ifndef VIS_SUBCLUSTERS_DISABLED
506 char tmp_addr_str[ETH_STR_LEN];
507 struct vis_if_list *tmp_if_next;
508 #endif /* VIS_SUBCLUSTERS_DISABLED */
510 current_format = vis_format;
512 rcu_read_lock();
513 if (list_empty(&if_list) || (!is_vis_server())) {
514 rcu_read_unlock();
515 if (current_format == DOT_DRAW)
516 seq_printf(seq, "digraph {\n}\n");
517 goto end;
520 rcu_read_unlock();
522 if (current_format == DOT_DRAW)
523 seq_printf(seq, "digraph {\n");
525 spin_lock(&vis_hash_lock);
526 while (NULL != (hashit = hash_iterate(vis_hash, hashit))) {
527 info = hashit->bucket->data;
528 entries = (struct vis_info_entry *)
529 ((char *)info + sizeof(struct vis_info));
531 for (i = 0; i < info->packet.entries; i++) {
532 proc_vis_read_entry(seq, &entries[i], &if_entries,
533 info->packet.vis_orig,
534 current_format, first_line);
535 if (first_line)
536 first_line = 0;
539 #ifndef VIS_SUBCLUSTERS_DISABLED
540 /* Generate subgraphs from the collected items */
541 if (current_format == DOT_DRAW) {
543 addr_to_string(tmp_addr_str, info->packet.vis_orig);
544 seq_printf(seq, "\tsubgraph \"cluster_%s\" {\n", tmp_addr_str);
545 while (if_entries != NULL) {
547 addr_to_string(tmp_addr_str, if_entries->addr);
548 if (if_entries->primary)
549 seq_printf(seq, "\t\t\"%s\" [peripheries=2]\n", tmp_addr_str);
550 else
551 seq_printf(seq, "\t\t\"%s\"\n", tmp_addr_str);
553 /* ... and empty the list while doing this */
554 tmp_if_next = if_entries->next;
555 kfree(if_entries);
556 if_entries = tmp_if_next;
558 seq_printf(seq, "\t}\n");
560 #endif /* VIS_SUBCLUSTERS_DISABLED */
562 spin_unlock(&vis_hash_lock);
564 if (current_format == DOT_DRAW)
565 seq_printf(seq, "}\n");
566 else
567 seq_printf(seq, "\n");
568 end:
569 return 0;
572 /* setting the mode of the vis server by the user */
573 static ssize_t proc_vis_write(struct file *file, const char __user * buffer,
574 size_t count, loff_t *ppos)
576 char *vis_mode_string;
577 int not_copied = 0;
579 vis_mode_string = kmalloc(count, GFP_KERNEL);
581 if (!vis_mode_string)
582 return -ENOMEM;
584 not_copied = copy_from_user(vis_mode_string, buffer, count);
585 vis_mode_string[count - not_copied - 1] = 0;
587 if (strcmp(vis_mode_string, "client") == 0) {
588 debug_log(LOG_TYPE_NOTICE, "Setting VIS mode to client\n");
589 vis_set_mode(VIS_TYPE_CLIENT_UPDATE);
590 } else if (strcmp(vis_mode_string, "server") == 0) {
591 debug_log(LOG_TYPE_NOTICE, "Setting VIS mode to server\n");
592 vis_set_mode(VIS_TYPE_SERVER_SYNC);
593 } else
594 debug_log(LOG_TYPE_WARN, "Unknown VIS mode: %s\n",
595 vis_mode_string);
597 kfree(vis_mode_string);
598 return count;
601 static int proc_vis_open(struct inode *inode, struct file *file)
603 return single_open(file, proc_vis_read, NULL);
606 static int proc_vis_format_read(struct seq_file *seq, void *offset)
608 uint8_t current_format = vis_format;
610 seq_printf(seq, "[%c] %s\n",
611 (current_format == DOT_DRAW) ? 'x' : ' ',
612 VIS_FORMAT_DD_NAME);
613 seq_printf(seq, "[%c] %s\n",
614 (current_format == JSON) ? 'x' : ' ',
615 VIS_FORMAT_JSON_NAME);
616 return 0;
619 static int proc_vis_format_open(struct inode *inode, struct file *file)
621 return single_open(file, proc_vis_format_read, NULL);
624 static ssize_t proc_vis_format_write(struct file *file,
625 const char __user *buffer,
626 size_t count, loff_t *ppos)
628 char *vis_format_string;
629 int not_copied = 0;
631 vis_format_string = kmalloc(count, GFP_KERNEL);
633 if (!vis_format_string)
634 return -ENOMEM;
636 not_copied = copy_from_user(vis_format_string, buffer, count);
637 vis_format_string[count - not_copied - 1] = 0;
639 if (strcmp(vis_format_string, VIS_FORMAT_DD_NAME) == 0) {
640 debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n",
641 VIS_FORMAT_DD_NAME);
642 vis_format = DOT_DRAW;
643 } else if (strcmp(vis_format_string, VIS_FORMAT_JSON_NAME) == 0) {
644 debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n",
645 VIS_FORMAT_JSON_NAME);
646 vis_format = JSON;
647 } else
648 debug_log(LOG_TYPE_WARN, "Unknown VIS output format: %s\n",
649 vis_format_string);
651 kfree(vis_format_string);
652 return count;
655 static int proc_aggr_read(struct seq_file *seq, void *offset)
657 seq_printf(seq, "%i\n", atomic_read(&aggregation_enabled));
659 return 0;
662 static ssize_t proc_aggr_write(struct file *file, const char __user *buffer,
663 size_t count, loff_t *ppos)
665 char *aggr_string;
666 int not_copied = 0;
667 unsigned long aggregation_enabled_tmp;
669 aggr_string = kmalloc(count, GFP_KERNEL);
671 if (!aggr_string)
672 return -ENOMEM;
674 not_copied = copy_from_user(aggr_string, buffer, count);
675 aggr_string[count - not_copied - 1] = 0;
677 strict_strtoul(aggr_string, 10, &aggregation_enabled_tmp);
679 if ((aggregation_enabled_tmp != 0) && (aggregation_enabled_tmp != 1)) {
680 debug_log(LOG_TYPE_WARN, "Aggregation can only be enabled (1) or disabled (0), given value: %li\n", aggregation_enabled_tmp);
681 goto end;
684 debug_log(LOG_TYPE_NOTICE, "Changing aggregation from: %s (%i) to: %s (%li)\n",
685 (atomic_read(&aggregation_enabled) == 1 ?
686 "enabled" : "disabled"),
687 atomic_read(&aggregation_enabled),
688 (aggregation_enabled_tmp == 1 ? "enabled" : "disabled"),
689 aggregation_enabled_tmp);
691 atomic_set(&aggregation_enabled, (unsigned)aggregation_enabled_tmp);
692 end:
693 kfree(aggr_string);
694 return count;
697 static int proc_aggr_open(struct inode *inode, struct file *file)
699 return single_open(file, proc_aggr_read, NULL);
702 /* satisfying different prototypes ... */
703 static ssize_t proc_dummy_write(struct file *file, const char __user *buffer,
704 size_t count, loff_t *ppos)
706 return count;
709 static const struct file_operations proc_aggr_fops = {
710 .owner = THIS_MODULE,
711 .open = proc_aggr_open,
712 .read = seq_read,
713 .write = proc_aggr_write,
714 .llseek = seq_lseek,
715 .release = single_release,
718 static const struct file_operations proc_vis_format_fops = {
719 .owner = THIS_MODULE,
720 .open = proc_vis_format_open,
721 .read = seq_read,
722 .write = proc_vis_format_write,
723 .llseek = seq_lseek,
724 .release = single_release,
727 static const struct file_operations proc_vis_fops = {
728 .owner = THIS_MODULE,
729 .open = proc_vis_open,
730 .read = seq_read,
731 .write = proc_vis_write,
732 .llseek = seq_lseek,
733 .release = single_release,
736 static const struct file_operations proc_originators_fops = {
737 .owner = THIS_MODULE,
738 .open = proc_originators_open,
739 .read = seq_read,
740 .write = proc_dummy_write,
741 .llseek = seq_lseek,
742 .release = single_release,
745 static const struct file_operations proc_transt_local_fops = {
746 .owner = THIS_MODULE,
747 .open = proc_transt_local_open,
748 .read = seq_read,
749 .write = proc_dummy_write,
750 .llseek = seq_lseek,
751 .release = single_release,
754 static const struct file_operations proc_transt_global_fops = {
755 .owner = THIS_MODULE,
756 .open = proc_transt_global_open,
757 .read = seq_read,
758 .write = proc_dummy_write,
759 .llseek = seq_lseek,
760 .release = single_release,
763 static const struct file_operations proc_log_level_fops = {
764 .owner = THIS_MODULE,
765 .open = proc_log_level_open,
766 .read = seq_read,
767 .write = proc_log_level_write,
768 .llseek = seq_lseek,
769 .release = single_release,
772 static const struct file_operations proc_interfaces_fops = {
773 .owner = THIS_MODULE,
774 .open = proc_interfaces_open,
775 .read = seq_read,
776 .write = proc_interfaces_write,
777 .llseek = seq_lseek,
778 .release = single_release,
781 static const struct file_operations proc_orig_interval_fops = {
782 .owner = THIS_MODULE,
783 .open = proc_orig_interval_open,
784 .read = seq_read,
785 .write = proc_orig_interval_write,
786 .llseek = seq_lseek,
787 .release = single_release,
790 void cleanup_procfs(void)
792 if (proc_transt_global_file)
793 remove_proc_entry(PROC_FILE_TRANST_GLOBAL, proc_batman_dir);
795 if (proc_transt_local_file)
796 remove_proc_entry(PROC_FILE_TRANST_LOCAL, proc_batman_dir);
798 if (proc_log_file)
799 remove_proc_entry(PROC_FILE_LOG, proc_batman_dir);
801 if (proc_log_level_file)
802 remove_proc_entry(PROC_FILE_LOG_LEVEL, proc_batman_dir);
804 if (proc_originators_file)
805 remove_proc_entry(PROC_FILE_ORIGINATORS, proc_batman_dir);
807 if (proc_orig_interval_file)
808 remove_proc_entry(PROC_FILE_ORIG_INTERVAL, proc_batman_dir);
810 if (proc_interface_file)
811 remove_proc_entry(PROC_FILE_INTERFACES, proc_batman_dir);
813 if (proc_vis_file)
814 remove_proc_entry(PROC_FILE_VIS, proc_batman_dir);
816 if (proc_vis_format_file)
817 remove_proc_entry(PROC_FILE_VIS_FORMAT, proc_batman_dir);
819 if (proc_aggr_file)
820 remove_proc_entry(PROC_FILE_AGGR, proc_batman_dir);
822 if (proc_batman_dir)
823 #ifdef __NET_NET_NAMESPACE_H
824 remove_proc_entry(PROC_ROOT_DIR, init_net.proc_net);
825 #else
826 remove_proc_entry(PROC_ROOT_DIR, proc_net);
827 #endif
830 int setup_procfs(void)
832 #ifdef __NET_NET_NAMESPACE_H
833 proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, init_net.proc_net);
834 #else
835 proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, proc_net);
836 #endif
838 if (!proc_batman_dir) {
839 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s' folder failed\n", PROC_ROOT_DIR);
840 return -EFAULT;
843 proc_interface_file = create_proc_entry(PROC_FILE_INTERFACES,
844 S_IWUSR | S_IRUGO,
845 proc_batman_dir);
846 if (proc_interface_file) {
847 proc_interface_file->proc_fops = &proc_interfaces_fops;
848 } else {
849 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_INTERFACES);
850 cleanup_procfs();
851 return -EFAULT;
854 proc_orig_interval_file = create_proc_entry(PROC_FILE_ORIG_INTERVAL,
855 S_IWUSR | S_IRUGO,
856 proc_batman_dir);
857 if (proc_orig_interval_file) {
858 proc_orig_interval_file->proc_fops = &proc_orig_interval_fops;
859 } else {
860 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIG_INTERVAL);
861 cleanup_procfs();
862 return -EFAULT;
865 proc_log_level_file = create_proc_entry(PROC_FILE_LOG_LEVEL,
866 S_IWUSR | S_IRUGO,
867 proc_batman_dir);
868 if (proc_log_level_file) {
869 proc_log_level_file->proc_fops = &proc_log_level_fops;
870 } else {
871 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_LOG_LEVEL);
872 cleanup_procfs();
873 return -EFAULT;
876 proc_originators_file = create_proc_entry(PROC_FILE_ORIGINATORS,
877 S_IRUGO, proc_batman_dir);
878 if (proc_originators_file) {
879 proc_originators_file->proc_fops = &proc_originators_fops;
880 } else {
881 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIGINATORS);
882 cleanup_procfs();
883 return -EFAULT;
886 proc_log_file = create_proc_entry(PROC_FILE_LOG,
887 S_IRUGO, proc_batman_dir);
888 if (proc_log_file) {
889 proc_log_file->proc_fops = &proc_log_operations;
890 } else {
891 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_FILE_LOG, PROC_FILE_GATEWAYS);
892 cleanup_procfs();
893 return -EFAULT;
896 proc_transt_local_file = create_proc_entry(PROC_FILE_TRANST_LOCAL,
897 S_IRUGO, proc_batman_dir);
898 if (proc_transt_local_file) {
899 proc_transt_local_file->proc_fops = &proc_transt_local_fops;
900 } else {
901 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_LOCAL);
902 cleanup_procfs();
903 return -EFAULT;
906 proc_transt_global_file = create_proc_entry(PROC_FILE_TRANST_GLOBAL,
907 S_IRUGO, proc_batman_dir);
908 if (proc_transt_global_file) {
909 proc_transt_global_file->proc_fops = &proc_transt_global_fops;
910 } else {
911 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_GLOBAL);
912 cleanup_procfs();
913 return -EFAULT;
916 proc_vis_file = create_proc_entry(PROC_FILE_VIS, S_IWUSR | S_IRUGO,
917 proc_batman_dir);
918 if (proc_vis_file) {
919 proc_vis_file->proc_fops = &proc_vis_fops;
920 } else {
921 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS);
922 cleanup_procfs();
923 return -EFAULT;
926 proc_vis_format_file = create_proc_entry(PROC_FILE_VIS_FORMAT,
927 S_IWUSR | S_IRUGO,
928 proc_batman_dir);
929 if (proc_vis_format_file) {
930 proc_vis_format_file->proc_fops = &proc_vis_format_fops;
931 } else {
932 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS_FORMAT);
933 cleanup_procfs();
934 return -EFAULT;
937 proc_aggr_file = create_proc_entry(PROC_FILE_AGGR, S_IWUSR | S_IRUGO,
938 proc_batman_dir);
939 if (proc_aggr_file) {
940 proc_aggr_file->proc_fops = &proc_aggr_fops;
941 } else {
942 printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_AGGR);
943 cleanup_procfs();
944 return -EFAULT;
947 return 0;