[B.A.T.M.A.N.] batman goes looping...
by Andrew Lunn
Hi Marek
I finally had time to dig into our problems with loops in our chain.
Some background for the list. Yang and I have been using User Mode
Linux (UML) to build a test network for batman advanced. We connect a
number of uml machines together using a modified version of
uml_switch. The modifications allow us to change the packet drop
probability between any two nodes. We have been testing using simple
chains as shown in the attached gif. The black lines show the
currently used links. The red lines are other links which are
currently not used by batman. The black links have a packet drop
probablilty of 0% and the red of 20%.
Our test was to remove uml5 from the network and see how long
batman-adv took to re-route around it. We ping from uml4 to uml6 and
from uml1 to uml9.
We found that uml4->uml6 would recover in around 14 seconds. However
uml1->uml9 took much longer, 65 seconds.
Looking at the routing, we found it went into loops. When sending from
uml1 to uml9, uml1 routes to uml2, uml2 routes back to uml1.
Here are the logs from uml2. I've cut out most of the packets, just
showing OGMs from uml9. There is a simple relationship between the MAC
address and the uml number:
fe:fe:00:00:01:01 - uml1
fe:fe:00:00:02:01 - uml2
fe:fe:00:00:03:01 - uml3
etc...
[ 42949558] Received BATMAN packet via NB: fe:fe:00:00:03:01, IF: eth1 [fe:fe:00:00:02:01] (from OG: fe:fe:00:00:09:01, via old OG: fe:fe:00:00:04:01, seqno 146, tq 218, TTL 44, V 7, IDF 0)
[ 42949558] bidirectional: orig = fe:fe:00:00:09:01 neigh = fe:fe:00:00:03:01 => own_bcast = 64, real recv = 64, local tq: 255, asym_penalty: 255, total tq: 218
[ 42949558] update_originator(): Searching and updating originator entry of received packet
[ 42949558] Updating existing last-hop neighbour of originator
[ 42949558] Drop packet: duplicate packet received
This has been received from uml3 origionally from uml4. The TQ is 218
to uml9 via uml3.
[ 42949559] Received BATMAN packet via NB: fe:fe:00:00:01:01, IF: eth1 [fe:fe:00:00:02:01] (from OG: fe:fe:00:00:09:01, via old OG: fe:fe:00:00:03:01, seqno 146, tq 209, TTL 42, V 7, IDF 0)
[ 42949559] bidirectional: orig = fe:fe:00:00:09:01 neigh = fe:fe:00:00:01:01 => own_bcast = 64, real recv = 64, local tq: 255, asym_penalty: 255, total tq: 209
[ 42949559] update_originator(): Searching and updating originator entry of received packet
[ 42949559] Updating existing last-hop neighbour of originator
[ 42949559] Drop packet: duplicate packet received
This is where is starts to get interesting. This is from uml1,
origionally from uml3. So it has jumped uml2, it used the 20% packet
drop link which exists between uml1 and uml3. Because this is not an
echo, uml2 processes it, and now knows that with a TQ of 209 it can
get to uml9 via uml1.
[ 42949559] Sending own packet (originator fe:fe:00:00:02:01, seqno 155, TQ 255, TTL 50, IDF off) on interface eth1 [fe:fe:00:00:02:01]
[ 42949559] Forwarding aggregated packet (originator fe:fe:00:00:06:01, seqno 152, TQ 232, TTL 46, IDF off) on interface eth1 [fe:fe:00:00:02:01]
[ 42949559] Forwarding aggregated packet (originator fe:fe:00:00:09:01, seqno 146, TQ 215, TTL 43, IDF off) on interface eth1 [fe:fe:00:00:02:01]
[ 42949559] Forwarding packet (originator fe:fe:00:00:01:01, seqno 156, TQ 250, TTL 49, IDF on) on interface eth1 [fe:fe:00:00:02:01]
[ 42949560] Received BATMAN packet via NB: fe:fe:00:00:03:01, IF: eth1 [fe:fe:00:00:02:01] (from OG: fe:fe:00:00:09:01, via old OG: fe:fe:00:00:04:01, seqno 148, tq 150, TTL 45, V 7, IDF 0)
[ 42949560] updating last_seqno: old 146, new 148
[ 42949560] bidirectional: orig = fe:fe:00:00:09:01 neigh = fe:fe:00:00:03:01 => own_bcast = 64, real recv = 64, local tq: 255, asym_penalty: 255, total tq: 150
[ 42949560] update_originator(): Searching and updating originator entry of received packet
[ 42949560] Updating existing last-hop neighbour of originator
[ 42949560] Changing route towards: fe:fe:00:00:09:01 (now via fe:fe:00:00:01:01 - was via fe:fe:00:00:03:01)
[ 42949560] Forwarding packet: rebroadcast originator packet
[ 42949560] Forwarding packet: tq_orig: 150, tq_avg: 209, tq_forw: 204, ttl_orig: 44, ttl_forw: 255
Now things go none optimal :-(
This is from uml3, origionally from uml4. The TQ value has dropped to
150. This will be when we have removed uml5, so the TQ naturally does
drop.
The TQ value via uml3 is now less than the TQ value via uml1. So it
changes its route to go via uml1.
Looking at the logs of uml1, uml1 is always routing to uml9 via uml2.
The problem here i think is to do with the asymetric links algorithms.
When sending out an OGM, the node uses the TQ for its best link to the
originator, not the link the OGM came in on. If the OGM from uml1
origionally from UML3 reported the TQ via that route, the TQ would
very likely be lower. uml2 would then not of choosen to swap to
uml1. However, uml1 reports its best route, which is via uml2. uml2
does not know this, decides to use uml1, and we have a loop.
Does this all hang together correctly? I'm i interpreting this all
right...
How would you suggest fix this?
Thanks
Andrew
13 years, 5 months
[B.A.T.M.A.N.] [batman-adv] Cleanup proc.[ch]
by Andrew Lunn
Make proc.[ch] clean with respect to the 2.6.29 checkpatch
script. Exceptions are long lines with printk/seq_print.
Signed-off-by: Andrew Lunn <andrew.lunn(a)ascom.ch>
Index: batman-adv-kernelland/proc.c
===================================================================
--- batman-adv-kernelland/proc.c (revision 1351)
+++ batman-adv-kernelland/proc.c (working copy)
@@ -17,282 +17,52 @@
*
*/
-
-
-
-
#include "main.h"
#include "proc.h"
#include "log.h"
#include "routing.h"
#include "translation-table.h"
#include "hard-interface.h"
-#include "vis.h"
#include "types.h"
#include "hash.h"
+#include "vis.h"
-static uint8_t vis_format = DOT_DRAW;
+uint8_t vis_format = DOT_DRAW;
+static struct proc_dir_entry *proc_batman_dir, *proc_interface_file;
+static struct proc_dir_entry *proc_orig_interval_file, *proc_originators_file;
+static struct proc_dir_entry *proc_log_file, *proc_log_level_file;
+static struct proc_dir_entry *proc_transt_local_file;
+static struct proc_dir_entry *proc_transt_global_file;
+static struct proc_dir_entry *proc_vis_file, *proc_vis_format_file;
+static struct proc_dir_entry *proc_aggr_file;
-static struct proc_dir_entry *proc_batman_dir = NULL, *proc_interface_file = NULL, *proc_orig_interval_file = NULL, *proc_originators_file = NULL;
-static struct proc_dir_entry *proc_log_file = NULL, *proc_log_level_file = NULL, *proc_transtable_local_file = NULL, *proc_transtable_global_file = NULL;
-static struct proc_dir_entry *proc_vis_file = NULL, *proc_vis_format_file = NULL, *proc_aggr_file = NULL;
-
-static const struct file_operations proc_aggr_fops = {
- .owner = THIS_MODULE,
- .open = proc_aggr_open,
- .read = seq_read,
- .write = proc_aggr_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-static const struct file_operations proc_vis_format_fops = {
- .owner = THIS_MODULE,
- .open = proc_vis_format_open,
- .read = seq_read,
- .write = proc_vis_format_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-static const struct file_operations proc_vis_fops = {
- .owner = THIS_MODULE,
- .open = proc_vis_open,
- .read = seq_read,
- .write = proc_vis_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-static const struct file_operations proc_originators_fops = {
- .owner = THIS_MODULE,
- .open = proc_originators_open,
- .read = seq_read,
- .write = proc_dummy_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-static const struct file_operations proc_transtable_local_fops = {
- .owner = THIS_MODULE,
- .open = proc_transtable_local_open,
- .read = seq_read,
- .write = proc_dummy_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-static const struct file_operations proc_transtable_global_fops = {
- .owner = THIS_MODULE,
- .open = proc_transtable_global_open,
- .read = seq_read,
- .write = proc_dummy_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-static const struct file_operations proc_log_level_fops = {
- .owner = THIS_MODULE,
- .open = proc_log_level_open,
- .read = seq_read,
- .write = proc_log_level_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-static const struct file_operations proc_interfaces_fops = {
- .owner = THIS_MODULE,
- .open = proc_interfaces_open,
- .read = seq_read,
- .write = proc_interfaces_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-static const struct file_operations proc_orig_interval_fops = {
- .owner = THIS_MODULE,
- .open = proc_orig_interval_open,
- .read = seq_read,
- .write = proc_orig_interval_write,
- .llseek = seq_lseek,
- .release = single_release,
-};
-
-
-
-void cleanup_procfs(void)
+static int proc_interfaces_read(struct seq_file *seq, void *offset)
{
- if (proc_transtable_global_file)
- remove_proc_entry(PROC_FILE_TRANSTABLE_GLOBAL, proc_batman_dir);
-
- if (proc_transtable_local_file)
- remove_proc_entry(PROC_FILE_TRANSTABLE_LOCAL, proc_batman_dir);
-
- if (proc_log_file)
- remove_proc_entry(PROC_FILE_LOG, proc_batman_dir);
-
- if (proc_log_level_file)
- remove_proc_entry(PROC_FILE_LOG_LEVEL, proc_batman_dir);
-
- if (proc_originators_file)
- remove_proc_entry(PROC_FILE_ORIGINATORS, proc_batman_dir);
-
- if (proc_orig_interval_file)
- remove_proc_entry(PROC_FILE_ORIG_INTERVAL, proc_batman_dir);
-
- if (proc_interface_file)
- remove_proc_entry(PROC_FILE_INTERFACES, proc_batman_dir);
-
- if (proc_vis_file)
- remove_proc_entry(PROC_FILE_VIS, proc_batman_dir);
-
- if (proc_vis_format_file)
- remove_proc_entry(PROC_FILE_VIS_FORMAT, proc_batman_dir);
-
- if (proc_aggr_file)
- remove_proc_entry(PROC_FILE_AGGR, proc_batman_dir);
-
- if (proc_batman_dir)
-#ifdef __NET_NET_NAMESPACE_H
- remove_proc_entry(PROC_ROOT_DIR, init_net.proc_net);
-#else
- remove_proc_entry(PROC_ROOT_DIR, proc_net);
-#endif
-}
-
-int setup_procfs(void)
-{
-#ifdef __NET_NET_NAMESPACE_H
- proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, init_net.proc_net);
-#else
- proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, proc_net);
-#endif
-
- if (!proc_batman_dir) {
- printk("batman-adv: Registering the '/proc/net/%s' folder failed\n", PROC_ROOT_DIR);
- return -EFAULT;
- }
-
- proc_interface_file = create_proc_entry(PROC_FILE_INTERFACES, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_interface_file) {
- proc_interface_file->proc_fops = &proc_interfaces_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_INTERFACES);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_orig_interval_file = create_proc_entry(PROC_FILE_ORIG_INTERVAL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_orig_interval_file) {
- proc_orig_interval_file->proc_fops = &proc_orig_interval_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIG_INTERVAL);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_log_level_file = create_proc_entry(PROC_FILE_LOG_LEVEL, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_log_level_file) {
-
- proc_log_level_file->proc_fops = &proc_log_level_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_LOG_LEVEL);
- cleanup_procfs();
- return -EFAULT;
- }
-
-
- proc_originators_file = create_proc_entry(PROC_FILE_ORIGINATORS, S_IRUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_originators_file) {
- proc_originators_file->proc_fops = &proc_originators_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIGINATORS);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_log_file = create_proc_entry(PROC_FILE_LOG, S_IRUSR | S_IRGRP | S_IROTH, proc_batman_dir);
- if (proc_log_file) {
- proc_log_file->proc_fops = &proc_log_operations;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_FILE_LOG, PROC_FILE_GATEWAYS);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_transtable_local_file = create_proc_entry(PROC_FILE_TRANSTABLE_LOCAL, S_IRUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_transtable_local_file) {
- proc_transtable_local_file->proc_fops = &proc_transtable_local_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANSTABLE_LOCAL);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_transtable_global_file = create_proc_entry(PROC_FILE_TRANSTABLE_GLOBAL, S_IRUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_transtable_global_file) {
- proc_transtable_global_file->proc_fops = &proc_transtable_global_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANSTABLE_GLOBAL);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_vis_file = create_proc_entry(PROC_FILE_VIS, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_vis_file) {
- proc_vis_file->proc_fops = &proc_vis_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_vis_format_file = create_proc_entry(PROC_FILE_VIS_FORMAT, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_vis_format_file) {
- proc_vis_format_file->proc_fops = &proc_vis_format_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS_FORMAT);
- cleanup_procfs();
- return -EFAULT;
- }
-
- proc_aggr_file = create_proc_entry(PROC_FILE_AGGR, S_IRUSR | S_IWUSR | S_IRGRP | S_IROTH, proc_batman_dir);
-
- if (proc_aggr_file) {
- proc_aggr_file->proc_fops = &proc_aggr_fops;
- } else {
- printk("batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_AGGR);
- cleanup_procfs();
- return -EFAULT;
- }
-
- return 0;
-}
-
-int proc_interfaces_read(struct seq_file *seq, void *offset)
-{
struct batman_if *batman_if;
rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) {
- seq_printf(seq, "[%8s] %s %s \n", (batman_if->if_active == IF_ACTIVE ? "active" : "inactive"),
- batman_if->dev, (batman_if->if_active == IF_ACTIVE ? batman_if->addr_str : " "));
+ seq_printf(seq, "[%8s] %s %s \n",
+ (batman_if->if_active == IF_ACTIVE ?
+ "active" : "inactive"),
+ batman_if->dev,
+ (batman_if->if_active == IF_ACTIVE ?
+ batman_if->addr_str : " "));
}
rcu_read_unlock();
return 0;
}
-int proc_interfaces_open(struct inode *inode, struct file *file)
+static int proc_interfaces_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_interfaces_read, NULL);
}
-ssize_t proc_interfaces_write(struct file *instance, const char __user *userbuffer, size_t count, loff_t *data)
+static ssize_t proc_interfaces_write(struct file *instance,
+ const char __user *userbuffer,
+ size_t count, loff_t *data)
{
char *if_string, *colon_ptr = NULL, *cr_ptr = NULL;
int not_copied = 0, if_num = 0;
@@ -304,20 +74,22 @@
return -ENOMEM;
if (count > IFNAMSIZ - 1) {
- debug_log(LOG_TYPE_WARN, "Can't add interface: device name is too long\n");
+ debug_log(LOG_TYPE_WARN,
+ "Can't add interface: device name is too long\n");
goto end;
}
not_copied = copy_from_user(if_string, userbuffer, count);
if_string[count - not_copied - 1] = 0;
-
- if ((colon_ptr = strchr(if_string, ':')) != NULL)
+ colon_ptr = strchr(if_string, ':');
+ if (colon_ptr != NULL)
*colon_ptr = 0;
- else if ((cr_ptr = strchr(if_string, '\n')) != NULL)
- *cr_ptr = 0;
-
+ else {
+ cr_ptr = strchr(if_string, '\n');
+ if (cr_ptr != NULL)
+ *cr_ptr = 0;
+ }
if (strlen(if_string) == 0) {
-
shutdown_module();
spin_lock(&orig_hash_lock);
@@ -327,13 +99,10 @@
num_ifs = 0;
goto end;
-
} else {
-
/* add interface */
rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) {
-
if (strncmp(batman_if->dev, if_string, count) == 0) {
debug_log(LOG_TYPE_WARN, "Given interface is already active: %s\n", if_string);
rcu_read_unlock();
@@ -374,18 +143,21 @@
return count;
}
-int proc_orig_interval_read(struct seq_file *seq, void *offset)
+static int proc_orig_interval_read(struct seq_file *seq, void *offset)
{
seq_printf(seq, "%i\n", atomic_read(&originator_interval));
return 0;
}
-ssize_t proc_orig_interval_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos)
+static ssize_t proc_orig_interval_write(struct file *file,
+ const char __user *buffer,
+ size_t count, loff_t *ppos)
{
char *interval_string;
int not_copied = 0;
- int16_t originator_interval_tmp;
+ long originator_interval_tmp;
+ int retval;
interval_string = kmalloc(count, GFP_KERNEL);
@@ -395,14 +167,22 @@
not_copied = copy_from_user(interval_string, buffer, count);
interval_string[count - not_copied - 1] = 0;
- originator_interval_tmp = simple_strtol(interval_string, NULL, 10);
+ retval = strict_strtol(interval_string, 10, &originator_interval_tmp);
+ if (retval) {
+ debug_log(LOG_TYPE_WARN, "New originator interval invalid\n");
+ goto end;
+ }
if (originator_interval_tmp <= JITTER * 2) {
- debug_log(LOG_TYPE_WARN, "New originator interval too small: %i (min: %i)\n", originator_interval_tmp, JITTER * 2);
+ debug_log(LOG_TYPE_WARN,
+ "New originator interval too small: %i (min: %i)\n",
+ originator_interval_tmp, JITTER * 2);
goto end;
}
- debug_log(LOG_TYPE_NOTICE, "Changing originator interval from: %i to: %i\n", atomic_read(&originator_interval), originator_interval_tmp);
+ debug_log(LOG_TYPE_NOTICE,
+ "Changing originator interval from: %i to: %i\n",
+ atomic_read(&originator_interval), originator_interval_tmp);
atomic_set(&originator_interval, originator_interval_tmp);
@@ -411,12 +191,12 @@
return count;
}
-int proc_orig_interval_open(struct inode *inode, struct file *file)
+static int proc_orig_interval_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_orig_interval_read, NULL);
}
-int proc_originators_read(struct seq_file *seq, void *offset)
+static int proc_originators_read(struct seq_file *seq, void *offset)
{
struct hash_it_t *hashit = NULL;
struct orig_node *orig_node;
@@ -437,12 +217,18 @@
goto end;
}
- seq_printf(seq, " %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s] \n", "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF", "Potential nexthops", SOURCE_VERSION, (strlen(REVISION_VERSION) > 3 ? REVISION_VERSION : ""), ((struct batman_if *)if_list.next)->dev, ((struct batman_if *)if_list.next)->addr_str);
+ seq_printf(seq,
+ " %-14s (%s/%i) %17s [%10s]: %20s ... [B.A.T.M.A.N. adv %s%s, MainIF/MAC: %s/%s] \n",
+ "Originator", "#", TQ_MAX_VALUE, "Nexthop", "outgoingIF",
+ "Potential nexthops", SOURCE_VERSION,
+ (strlen(REVISION_VERSION) > 3 ? REVISION_VERSION : ""),
+ ((struct batman_if *)if_list.next)->dev,
+ ((struct batman_if *)if_list.next)->addr_str);
rcu_read_unlock();
spin_lock(&orig_hash_lock);
- while (NULL != (hashit = hash_iterate( orig_hash, hashit))) {
+ while (NULL != (hashit = hash_iterate(orig_hash, hashit))) {
orig_node = hashit->bucket->data;
@@ -457,11 +243,14 @@
addr_to_string(orig_str, orig_node->orig);
addr_to_string(router_str, orig_node->router->addr);
- seq_printf(seq, "%-17s (%3i) %17s [%10s]:", orig_str, orig_node->router->tq_avg, router_str, orig_node->router->if_incoming->dev);
+ seq_printf(seq, "%-17s (%3i) %17s [%10s]:",
+ orig_str, orig_node->router->tq_avg,
+ router_str, orig_node->router->if_incoming->dev);
list_for_each_entry(neigh_node, &orig_node->neigh_list, list) {
addr_to_string(orig_str, neigh_node->addr);
- seq_printf(seq, " %17s (%3i)", orig_str, neigh_node->tq_avg);
+ seq_printf(seq, " %17s (%3i)",
+ orig_str, neigh_node->tq_avg);
}
seq_printf(seq, "\n");
@@ -477,29 +266,38 @@
return 0;
}
-int proc_originators_open(struct inode *inode, struct file *file)
+static int proc_originators_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_originators_read, NULL);
}
-int proc_log_level_read(struct seq_file *seq, void *offset)
+static int proc_log_level_read(struct seq_file *seq, void *offset)
{
seq_printf(seq, "[x] %s (%d)\n", LOG_TYPE_CRIT_NAME, LOG_TYPE_CRIT);
- seq_printf(seq, "[%c] %s (%d)\n", (LOG_TYPE_WARN & log_level) ? 'x' : ' ', LOG_TYPE_WARN_NAME, LOG_TYPE_WARN);
- seq_printf(seq, "[%c] %s (%d)\n", (LOG_TYPE_NOTICE & log_level) ? 'x' : ' ', LOG_TYPE_NOTICE_NAME, LOG_TYPE_NOTICE);
- seq_printf(seq, "[%c] %s (%d)\n", (LOG_TYPE_BATMAN & log_level) ? 'x' : ' ', LOG_TYPE_BATMAN_NAME, LOG_TYPE_BATMAN);
- seq_printf(seq, "[%c] %s (%d)\n", (LOG_TYPE_ROUTES & log_level) ? 'x' : ' ', LOG_TYPE_ROUTES_NAME, LOG_TYPE_ROUTES);
-
+ seq_printf(seq, "[%c] %s (%d)\n",
+ (LOG_TYPE_WARN & log_level) ? 'x' : ' ',
+ LOG_TYPE_WARN_NAME, LOG_TYPE_WARN);
+ seq_printf(seq, "[%c] %s (%d)\n",
+ (LOG_TYPE_NOTICE & log_level) ? 'x' : ' ',
+ LOG_TYPE_NOTICE_NAME, LOG_TYPE_NOTICE);
+ seq_printf(seq, "[%c] %s (%d)\n",
+ (LOG_TYPE_BATMAN & log_level) ? 'x' : ' ',
+ LOG_TYPE_BATMAN_NAME, LOG_TYPE_BATMAN);
+ seq_printf(seq, "[%c] %s (%d)\n",
+ (LOG_TYPE_ROUTES & log_level) ? 'x' : ' ',
+ LOG_TYPE_ROUTES_NAME, LOG_TYPE_ROUTES);
return 0;
}
-int proc_log_level_open(struct inode *inode, struct file *file)
+static int proc_log_level_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_log_level_read, NULL);
}
-ssize_t proc_log_level_write(struct file *instance, const char __user *userbuffer, size_t count, loff_t *data)
+static ssize_t proc_log_level_write(struct file *instance,
+ const char __user *userbuffer,
+ size_t count, loff_t *data)
{
char *log_level_string, *tokptr, *cp;
int finished, not_copied = 0;
@@ -545,14 +343,15 @@
}
}
- debug_log(LOG_TYPE_CRIT, "Changing log_level from: %i to: %i\n", log_level, log_level_tmp);
+ debug_log(LOG_TYPE_CRIT, "Changing log_level from: %i to: %i\n",
+ log_level, log_level_tmp);
log_level = log_level_tmp;
kfree(log_level_string);
return count;
}
-int proc_transtable_local_read(struct seq_file *seq, void *offset)
+static int proc_transt_local_read(struct seq_file *seq, void *offset)
{
char *buf;
@@ -579,12 +378,12 @@
return 0;
}
-int proc_transtable_local_open(struct inode *inode, struct file *file)
+static int proc_transt_local_open(struct inode *inode, struct file *file)
{
- return single_open(file, proc_transtable_local_read, NULL);
+ return single_open(file, proc_transt_local_read, NULL);
}
-int proc_transtable_global_read(struct seq_file *seq, void *offset)
+static int proc_transt_global_read(struct seq_file *seq, void *offset)
{
char *buf;
@@ -611,63 +410,80 @@
return 0;
}
-int proc_transtable_global_open(struct inode *inode, struct file *file)
+static int proc_transt_global_open(struct inode *inode, struct file *file)
{
- return single_open(file, proc_transtable_global_read, NULL);
+ return single_open(file, proc_transt_global_read, NULL);
}
-int proc_vis_read(struct seq_file *seq, void *offset)
+static void proc_vis_read_entry(struct seq_file *seq,
+ struct vis_info_entry *entry,
+ char *from,
+ uint8_t current_format,
+ uint8_t first_line)
{
+ char to[40];
+
+ addr_to_string(to, entry->dest);
+ if (entry->quality == 0) {
+ if (current_format == DOT_DRAW) {
+ seq_printf(seq, "\t\"%s\" -> \"%s\" [label=\"HNA\"]\n",
+ from, to);
+ } else {
+ seq_printf(seq,
+ "%s\t{ router : \"%s\", gateway : \"%s\", label : \"HNA\" }",
+ (first_line ? "" : ",\n"), from, to);
+ }
+ } else {
+ /* kernel has no printf-support for %f? it'd be better to return
+ * this in float. */
+ if (current_format == DOT_DRAW) {
+ seq_printf(seq,
+ "\t\"%s\" -> \"%s\" [label=\"%d\"]\n",
+ from, to, entry->quality);
+ } else {
+ seq_printf(seq,
+ "%s\t{ router : \"%s\", neighbour : \"%s\", label : %d }",
+ (first_line ? "" : ",\n"), from, to,
+ entry->quality);
+ }
+ }
+}
+
+static int proc_vis_read(struct seq_file *seq, void *offset)
+{
struct hash_it_t *hashit = NULL;
struct vis_info *info;
struct vis_info_entry *entries;
- char from[40], to[40];
- int i, int_part, frac_part;
+ char from[40];
+ int i;
uint8_t current_format, first_line = 1;
-
current_format = vis_format;
rcu_read_lock();
if (list_empty(&if_list) || (!is_vis_server())) {
rcu_read_unlock();
if (current_format == DOT_DRAW)
- seq_printf(seq, "digraph {\n}\n" );
+ seq_printf(seq, "digraph {\n}\n");
goto end;
}
rcu_read_unlock();
if (current_format == DOT_DRAW)
- seq_printf(seq, "digraph {\n" );
+ seq_printf(seq, "digraph {\n");
spin_lock(&vis_hash_lock);
while (NULL != (hashit = hash_iterate(vis_hash, hashit))) {
info = hashit->bucket->data;
- entries = (struct vis_info_entry *)((char *)info + sizeof(struct vis_info));
+ entries = (struct vis_info_entry *)
+ ((char *)info + sizeof(struct vis_info));
addr_to_string(from, info->packet.vis_orig);
for (i = 0; i < info->packet.entries; i++) {
- addr_to_string(to, entries[i].dest);
- if (entries[i].quality == 0) {
- if (current_format == DOT_DRAW) {
- seq_printf(seq, "\t\"%s\" -> \"%s\" [label=\"HNA\"]\n", from, to);
- } else {
- seq_printf(seq, "%s\t{ router : \"%s\", gateway : \"%s\", label : \"HNA\" }",
- (first_line ? "" : ",\n"), from, to);
- first_line = 0;
- }
- } else {
- /* kernel has no printf-support for %f? it'd be better to return this in float. */
- int_part = 255/entries[i].quality;
- frac_part = 1000 * 255/entries[i].quality - int_part * 1000;
- if (current_format == DOT_DRAW) {
- seq_printf(seq, "\t\"%s\" -> \"%s\" [label=\"%d.%d\"]\n", from, to, int_part, frac_part);
- } else {
- seq_printf(seq, "%s\t{ router : \"%s\", neighbour : \"%s\", label : %d.%d }",
- (first_line ? "" : ",\n"), from, to, int_part, frac_part);
- first_line = 0;
- }
- }
+ proc_vis_read_entry(seq, &entries[i], from,
+ current_format, first_line);
+ if (first_line)
+ first_line = 0;
}
}
@@ -681,7 +497,8 @@
}
/* setting the mode of the vis server by the user */
-ssize_t proc_vis_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos)
+static ssize_t proc_vis_write(struct file *file, const char __user * buffer,
+ size_t count, loff_t *ppos)
{
char *vis_mode_string;
int not_copied = 0;
@@ -701,33 +518,39 @@
debug_log(LOG_TYPE_NOTICE, "Setting VIS mode to server\n");
vis_set_mode(VIS_TYPE_SERVER_SYNC);
} else
- debug_log(LOG_TYPE_WARN, "Unknown VIS mode: %s\n", vis_mode_string);
+ debug_log(LOG_TYPE_WARN, "Unknown VIS mode: %s\n",
+ vis_mode_string);
kfree(vis_mode_string);
return count;
}
-int proc_vis_open(struct inode *inode, struct file *file)
+static int proc_vis_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_vis_read, NULL);
}
-int proc_vis_format_read(struct seq_file *seq, void *offset)
+static int proc_vis_format_read(struct seq_file *seq, void *offset)
{
uint8_t current_format = vis_format;
- seq_printf(seq, "[%c] %s\n", (current_format == DOT_DRAW) ? 'x' : ' ', VIS_FORMAT_DD_NAME);
- seq_printf(seq, "[%c] %s\n", (current_format == JSON) ? 'x' : ' ', VIS_FORMAT_JSON_NAME);
-
+ seq_printf(seq, "[%c] %s\n",
+ (current_format == DOT_DRAW) ? 'x' : ' ',
+ VIS_FORMAT_DD_NAME);
+ seq_printf(seq, "[%c] %s\n",
+ (current_format == JSON) ? 'x' : ' ',
+ VIS_FORMAT_JSON_NAME);
return 0;
}
-int proc_vis_format_open(struct inode *inode, struct file *file)
+static int proc_vis_format_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_vis_format_read, NULL);
}
-ssize_t proc_vis_format_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos)
+static ssize_t proc_vis_format_write(struct file *file,
+ const char __user *buffer,
+ size_t count, loff_t *ppos)
{
char *vis_format_string;
int not_copied = 0;
@@ -741,26 +564,30 @@
vis_format_string[count - not_copied - 1] = 0;
if (strcmp(vis_format_string, VIS_FORMAT_DD_NAME) == 0) {
- debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n", VIS_FORMAT_DD_NAME);
+ debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n",
+ VIS_FORMAT_DD_NAME);
vis_format = DOT_DRAW;
} else if (strcmp(vis_format_string, VIS_FORMAT_JSON_NAME) == 0) {
- debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n", VIS_FORMAT_JSON_NAME);
+ debug_log(LOG_TYPE_NOTICE, "Setting VIS output format to: %s\n",
+ VIS_FORMAT_JSON_NAME);
vis_format = JSON;
} else
- debug_log(LOG_TYPE_WARN, "Unknown VIS output format: %s\n", vis_format_string);
+ debug_log(LOG_TYPE_WARN, "Unknown VIS output format: %s\n",
+ vis_format_string);
kfree(vis_format_string);
return count;
}
-int proc_aggr_read(struct seq_file *seq, void *offset)
+static int proc_aggr_read(struct seq_file *seq, void *offset)
{
seq_printf(seq, "%i\n", atomic_read(&aggregation_enabled));
return 0;
}
-ssize_t proc_aggr_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos)
+static ssize_t proc_aggr_write(struct file *file, const char __user *buffer,
+ size_t count, loff_t *ppos)
{
char *aggr_string;
int not_copied = 0;
@@ -781,23 +608,280 @@
goto end;
}
- debug_log(LOG_TYPE_NOTICE, "Changing aggregation from: %s (%i) to: %s (%i)\n", (atomic_read(&aggregation_enabled) == 1 ? "enabled" : "disabled"), atomic_read(&aggregation_enabled), (aggregation_enabled_tmp == 1 ? "enabled" : "disabled"), aggregation_enabled_tmp);
+ debug_log(LOG_TYPE_NOTICE, "Changing aggregation from: %s (%i) to: %s (%i)\n",
+ (atomic_read(&aggregation_enabled) == 1 ?
+ "enabled" : "disabled"),
+ atomic_read(&aggregation_enabled),
+ (aggregation_enabled_tmp == 1 ? "enabled" : "disabled"),
+ aggregation_enabled_tmp);
atomic_set(&aggregation_enabled, aggregation_enabled_tmp);
-
end:
kfree(aggr_string);
return count;
}
-int proc_aggr_open(struct inode *inode, struct file *file)
+static int proc_aggr_open(struct inode *inode, struct file *file)
{
return single_open(file, proc_aggr_read, NULL);
}
/* satisfying different prototypes ... */
-ssize_t proc_dummy_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos)
+static ssize_t proc_dummy_write(struct file *file, const char __user *buffer,
+ size_t count, loff_t *ppos)
{
return count;
}
+static const struct file_operations proc_aggr_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_aggr_open,
+ .read = seq_read,
+ .write = proc_aggr_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_vis_format_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_vis_format_open,
+ .read = seq_read,
+ .write = proc_vis_format_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_vis_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_vis_open,
+ .read = seq_read,
+ .write = proc_vis_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_originators_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_originators_open,
+ .read = seq_read,
+ .write = proc_dummy_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_transt_local_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_transt_local_open,
+ .read = seq_read,
+ .write = proc_dummy_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_transt_global_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_transt_global_open,
+ .read = seq_read,
+ .write = proc_dummy_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_log_level_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_log_level_open,
+ .read = seq_read,
+ .write = proc_log_level_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_interfaces_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_interfaces_open,
+ .read = seq_read,
+ .write = proc_interfaces_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+static const struct file_operations proc_orig_interval_fops = {
+ .owner = THIS_MODULE,
+ .open = proc_orig_interval_open,
+ .read = seq_read,
+ .write = proc_orig_interval_write,
+ .llseek = seq_lseek,
+ .release = single_release,
+};
+
+void cleanup_procfs(void)
+{
+ if (proc_transt_global_file)
+ remove_proc_entry(PROC_FILE_TRANST_GLOBAL, proc_batman_dir);
+
+ if (proc_transt_local_file)
+ remove_proc_entry(PROC_FILE_TRANST_LOCAL, proc_batman_dir);
+
+ if (proc_log_file)
+ remove_proc_entry(PROC_FILE_LOG, proc_batman_dir);
+
+ if (proc_log_level_file)
+ remove_proc_entry(PROC_FILE_LOG_LEVEL, proc_batman_dir);
+
+ if (proc_originators_file)
+ remove_proc_entry(PROC_FILE_ORIGINATORS, proc_batman_dir);
+
+ if (proc_orig_interval_file)
+ remove_proc_entry(PROC_FILE_ORIG_INTERVAL, proc_batman_dir);
+
+ if (proc_interface_file)
+ remove_proc_entry(PROC_FILE_INTERFACES, proc_batman_dir);
+
+ if (proc_vis_file)
+ remove_proc_entry(PROC_FILE_VIS, proc_batman_dir);
+
+ if (proc_vis_format_file)
+ remove_proc_entry(PROC_FILE_VIS_FORMAT, proc_batman_dir);
+
+ if (proc_aggr_file)
+ remove_proc_entry(PROC_FILE_AGGR, proc_batman_dir);
+
+ if (proc_batman_dir)
+#ifdef __NET_NET_NAMESPACE_H
+ remove_proc_entry(PROC_ROOT_DIR, init_net.proc_net);
+#else
+ remove_proc_entry(PROC_ROOT_DIR, proc_net);
+#endif
+}
+
+int setup_procfs(void)
+{
+#ifdef __NET_NET_NAMESPACE_H
+ proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, init_net.proc_net);
+#else
+ proc_batman_dir = proc_mkdir(PROC_ROOT_DIR, proc_net);
+#endif
+
+ if (!proc_batman_dir) {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s' folder failed\n", PROC_ROOT_DIR);
+ return -EFAULT;
+ }
+
+ proc_interface_file = create_proc_entry(PROC_FILE_INTERFACES,
+ S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_interface_file) {
+ proc_interface_file->proc_fops = &proc_interfaces_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_INTERFACES);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_orig_interval_file = create_proc_entry(PROC_FILE_ORIG_INTERVAL,
+ S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_orig_interval_file) {
+ proc_orig_interval_file->proc_fops = &proc_orig_interval_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIG_INTERVAL);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_log_level_file = create_proc_entry(PROC_FILE_LOG_LEVEL,
+ S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_log_level_file) {
+
+ proc_log_level_file->proc_fops = &proc_log_level_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_LOG_LEVEL);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_originators_file = create_proc_entry(PROC_FILE_ORIGINATORS,
+ S_IRUGO, proc_batman_dir);
+
+ if (proc_originators_file) {
+ proc_originators_file->proc_fops = &proc_originators_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_ORIGINATORS);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_log_file = create_proc_entry(PROC_FILE_LOG,
+ S_IRUGO, proc_batman_dir);
+ if (proc_log_file) {
+ proc_log_file->proc_fops = &proc_log_operations;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_FILE_LOG, PROC_FILE_GATEWAYS);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_transt_local_file = create_proc_entry(PROC_FILE_TRANST_LOCAL,
+ S_IRUGO, proc_batman_dir);
+
+ if (proc_transt_local_file) {
+ proc_transt_local_file->proc_fops = &proc_transt_local_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_LOCAL);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_transt_global_file = create_proc_entry(PROC_FILE_TRANST_GLOBAL,
+ S_IRUGO, proc_batman_dir);
+
+ if (proc_transt_global_file) {
+ proc_transt_global_file->proc_fops = &proc_transt_global_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_TRANST_GLOBAL);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_vis_file = create_proc_entry(PROC_FILE_VIS, S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_vis_file) {
+ proc_vis_file->proc_fops = &proc_vis_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_vis_format_file = create_proc_entry(PROC_FILE_VIS_FORMAT,
+ S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_vis_format_file) {
+ proc_vis_format_file->proc_fops = &proc_vis_format_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_VIS_FORMAT);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ proc_aggr_file = create_proc_entry(PROC_FILE_AGGR, S_IWUSR | S_IRUGO,
+ proc_batman_dir);
+
+ if (proc_aggr_file) {
+ proc_aggr_file->proc_fops = &proc_aggr_fops;
+ } else {
+ printk(KERN_ERR "batman-adv: Registering the '/proc/net/%s/%s' file failed\n", PROC_ROOT_DIR, PROC_FILE_AGGR);
+ cleanup_procfs();
+ return -EFAULT;
+ }
+
+ return 0;
+}
+
+
Index: batman-adv-kernelland/proc.h
===================================================================
--- batman-adv-kernelland/proc.h (revision 1351)
+++ batman-adv-kernelland/proc.h (working copy)
@@ -17,10 +17,6 @@
*
*/
-
-
-
-
#include <linux/proc_fs.h>
#include <linux/seq_file.h>
@@ -31,37 +27,11 @@
#define PROC_FILE_GATEWAYS "gateways"
#define PROC_FILE_LOG "log"
#define PROC_FILE_LOG_LEVEL "log_level"
-#define PROC_FILE_TRANSTABLE_LOCAL "transtable_local"
-#define PROC_FILE_TRANSTABLE_GLOBAL "transtable_global"
+#define PROC_FILE_TRANST_LOCAL "transtable_local"
+#define PROC_FILE_TRANST_GLOBAL "transtable_global"
#define PROC_FILE_VIS "vis"
#define PROC_FILE_VIS_FORMAT "vis_format"
#define PROC_FILE_AGGR "aggregate_ogm"
-
-
void cleanup_procfs(void);
int setup_procfs(void);
-int proc_interfaces_open(struct inode *inode, struct file *file);
-int proc_interfaces_read(struct seq_file *seq, void *offset);
-ssize_t proc_interfaces_write(struct file *instance, const char __user *userbuffer, size_t count, loff_t *data);
-int proc_orig_interval_open(struct inode *inode, struct file *file);
-int proc_orig_interval_read(struct seq_file *seq, void *offset);
-ssize_t proc_orig_interval_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos);
-int proc_originators_open(struct inode *inode, struct file *file);
-int proc_originators_read(struct seq_file *seq, void *offset);
-int proc_log_level_open(struct inode *inode, struct file *file);
-int proc_log_level_read(struct seq_file *seq, void *offset);
-ssize_t proc_log_level_write(struct file *instance, const char __user *userbuffer, size_t count, loff_t *data);
-int proc_transtable_local_open(struct inode *inode, struct file *file);
-int proc_transtable_local_read(struct seq_file *seq, void *offset);
-int proc_transtable_global_open(struct inode *inode, struct file *file);
-int proc_transtable_global_read(struct seq_file *seq, void *offset);
-int proc_vis_open(struct inode *inode, struct file *file);
-int proc_vis_read(struct seq_file *seq, void *offset);
-int proc_vis_format_open(struct inode *inode, struct file *file);
-int proc_aggr_open(struct inode *inode, struct file *file);
-int proc_aggr_read(struct seq_file *seq, void *offset);
-ssize_t proc_vis_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos);
-ssize_t proc_vis_format_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos);
-ssize_t proc_aggr_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos);
-ssize_t proc_dummy_write(struct file *file, const char __user * buffer, size_t count, loff_t * ppos);
13 years, 6 months
[B.A.T.M.A.N.] [batman-advanced]beginner questions
by Sophana K
Hi
I've read the readme on how to setup batman advanced and also the openwrt
howto.
It looks great, and it looks like the way to go as roaming seem to be
handled correctly.
I have some questions before I try to setup it.
Could it work on "standard" broadcom hardware like WRT54gl?
Do I need multi ssid hardware? only atheros?
What about the ahdemo mode? is it like adhoc?
If I want standard AP mode, must I create several ssid (1 ahdemo + 1 AP)
then bridge bat0 to the AP ssid?
If I want to setup coova-chilli to drive the mesh (hotspot mesh), how could
I ssh to the repeaters? Is some sort of VLAN supported? there would be 2
separate networks in the mesh, one for gateway to repeater communication,
the other for the hotspot mesh.
Or maybe would it be possible that repeaters use a specific dhcp server (not
chilli) to get their ip addresses?
It looks that we can get the mac addresses of all repeaters. Can I use arp
to get their IP?
You would say "why ssh to the repeaters?", I don't know... Maybe for
configuration/ monitoring...
Thanks
13 years, 6 months
[B.A.T.M.A.N.] [PATCH] Cleanup smaller style problems
by Sven Eckelmann
Make some files clean with respect to the 2.6.29 checkpatch
script. Exceptions are long lines with printk/seq_print.
Signed-off-by: Sven Eckelmann <sven.eckelmann(a)gmx.de>
---
batman-adv-kernelland/compat.h | 2 +-
batman-adv-kernelland/proc.c | 10 +++++-----
batman-adv-kernelland/routing.c | 8 ++++----
batman-adv-kernelland/types.h | 27 +++++++++------------------
4 files changed, 19 insertions(+), 28 deletions(-)
diff --git a/batman-adv-kernelland/compat.h b/batman-adv-kernelland/compat.h
index af0cc96..2f0877c 100644
--- a/batman-adv-kernelland/compat.h
+++ b/batman-adv-kernelland/compat.h
@@ -57,6 +57,6 @@
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
-#define cancel_delayed_work_sync(wq) cancel_rearming_delayed_work(wq)
+#define cancel_delayed_work_sync(wq) cancel_rearming_delayed_work(wq)
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) */
diff --git a/batman-adv-kernelland/proc.c b/batman-adv-kernelland/proc.c
index 0105c3e..dd109a5 100644
--- a/batman-adv-kernelland/proc.c
+++ b/batman-adv-kernelland/proc.c
@@ -597,7 +597,7 @@ static ssize_t proc_aggr_write(struct file *file, const char __user *buffer,
{
char *aggr_string;
int not_copied = 0;
- int16_t aggregation_enabled_tmp;
+ long aggregation_enabled_tmp;
aggr_string = kmalloc(count, GFP_KERNEL);
@@ -607,21 +607,21 @@ static ssize_t proc_aggr_write(struct file *file, const char __user *buffer,
not_copied = copy_from_user(aggr_string, buffer, count);
aggr_string[count - not_copied - 1] = 0;
- aggregation_enabled_tmp = simple_strtol(aggr_string, NULL, 10);
+ strict_strtol(aggr_string, 10, &aggregation_enabled_tmp);
if ((aggregation_enabled_tmp != 0) && (aggregation_enabled_tmp != 1)) {
- debug_log(LOG_TYPE_WARN, "Aggregation can only be enabled (1) or disabled (0), given value: %i\n", aggregation_enabled_tmp);
+ debug_log(LOG_TYPE_WARN, "Aggregation can only be enabled (1) or disabled (0), given value: %li\n", aggregation_enabled_tmp);
goto end;
}
- debug_log(LOG_TYPE_NOTICE, "Changing aggregation from: %s (%i) to: %s (%i)\n",
+ debug_log(LOG_TYPE_NOTICE, "Changing aggregation from: %s (%i) to: %s (%li)\n",
(atomic_read(&aggregation_enabled) == 1 ?
"enabled" : "disabled"),
atomic_read(&aggregation_enabled),
(aggregation_enabled_tmp == 1 ? "enabled" : "disabled"),
aggregation_enabled_tmp);
- atomic_set(&aggregation_enabled, aggregation_enabled_tmp);
+ atomic_set(&aggregation_enabled, (unsigned)aggregation_enabled_tmp);
end:
kfree(aggr_string);
return count;
diff --git a/batman-adv-kernelland/routing.c b/batman-adv-kernelland/routing.c
index 269c932..b576f8c 100644
--- a/batman-adv-kernelland/routing.c
+++ b/batman-adv-kernelland/routing.c
@@ -186,7 +186,7 @@ static void update_routes(struct orig_node *orig_node, struct neigh_node *neigh_
/* may be just HNA changed */
} else {
- if ((hna_buff_len != orig_node->hna_buff_len) || ((hna_buff_len > 0 ) && (orig_node->hna_buff_len > 0) && (memcmp(orig_node->hna_buff, hna_buff, hna_buff_len) != 0))) {
+ if ((hna_buff_len != orig_node->hna_buff_len) || ((hna_buff_len > 0) && (orig_node->hna_buff_len > 0) && (memcmp(orig_node->hna_buff, hna_buff, hna_buff_len) != 0))) {
if (orig_node->hna_buff_len > 0)
hna_global_del_orig(orig_node, "originator changed hna");
@@ -227,7 +227,7 @@ static int isBidirectionalNeigh(struct orig_node *orig_node, struct orig_node *o
neigh_node = tmp_neigh_node;
}
- if ( neigh_node == NULL )
+ if (neigh_node == NULL)
neigh_node = create_neighbor(orig_neigh_node, orig_neigh_node, orig_neigh_node->orig, if_incoming);
}
@@ -612,8 +612,8 @@ int packet_recv_thread(void *data)
result = 0;
break;
}
-
- if ((result = receive_raw_packet(batman_if->raw_sock, packet_buff, PACKBUFF_SIZE)) <= 0)
+ result = receive_raw_packet(batman_if->raw_sock, packet_buff, PACKBUFF_SIZE);
+ if (result <= 0)
break;
if (result < sizeof(struct ethhdr) + 2)
diff --git a/batman-adv-kernelland/types.h b/batman-adv-kernelland/types.h
index 4001b59..0c31b4d 100644
--- a/batman-adv-kernelland/types.h
+++ b/batman-adv-kernelland/types.h
@@ -30,8 +30,7 @@
#define BAT_HEADER_LEN (sizeof(struct ethhdr) + ((sizeof(struct unicast_packet) > sizeof(struct bcast_packet) ? sizeof(struct unicast_packet) : sizeof(struct bcast_packet))))
-struct batman_if
-{
+struct batman_if {
struct list_head list;
int16_t if_num;
char *dev;
@@ -46,8 +45,7 @@ struct batman_if
};
-struct orig_node /* structure for orig_list maintaining nodes of mesh */
-{
+struct orig_node { /* structure for orig_list maintaining nodes of mesh */
uint8_t orig[ETH_ALEN];
struct neigh_node *router;
struct batman_if *batman_if;
@@ -67,8 +65,7 @@ struct orig_node /* structure for orig_list maintaining nodes of
struct list_head neigh_list;
};
-struct neigh_node
-{
+struct neigh_node {
struct list_head list;
uint8_t addr[ETH_ALEN];
uint8_t real_packet_count;
@@ -82,13 +79,11 @@ struct neigh_node
struct batman_if *if_incoming;
};
-struct bat_priv
-{
+struct bat_priv {
struct net_device_stats stats;
};
-struct device_client
-{
+struct device_client {
struct list_head queue_list;
unsigned int queue_len;
unsigned char index;
@@ -96,27 +91,23 @@ struct device_client
wait_queue_head_t queue_wait;
};
-struct device_packet
-{
+struct device_packet {
struct list_head list;
struct icmp_packet icmp_packet;
};
-struct hna_local_entry
-{
+struct hna_local_entry {
uint8_t addr[ETH_ALEN];
unsigned long last_seen;
char never_purge;
};
-struct hna_global_entry
-{
+struct hna_global_entry {
uint8_t addr[ETH_ALEN];
struct orig_node *orig_node;
};
-struct forw_packet /* structure for forw_list maintaining packets to be send/forwarded */
-{
+struct forw_packet { /* structure for forw_list maintaining packets to be send/forwarded */
struct hlist_node list;
unsigned long send_time;
uint8_t own;
--
1.6.3.3
13 years, 6 months
[B.A.T.M.A.N.] [batman-adv] cleanup send.[ch]
by Andrew Lunn
Make send.[ch] clean with respect to the 2.6.29
checkpatch script. Exceptions are long lines with debug_log.
Signed-off-by: Andrew Lunn <andrew.lunn(a)ascom.ch>
Index: batman-adv-kernelland/send.c
===================================================================
--- batman-adv-kernelland/send.c (revision 1351)
+++ batman-adv-kernelland/send.c (working copy)
@@ -17,9 +17,6 @@
*
*/
-
-
-
#include "main.h"
#include "send.h"
#include "log.h"
@@ -32,10 +29,44 @@
#include "compat.h"
+/* apply the hop penalty for a wireless link */
+static uint8_t wireless_hop_penalty(const uint8_t tq)
+{
+ return (tq * (TQ_MAX_VALUE - (2 * TQ_HOP_PENALTY))) / (TQ_MAX_VALUE);
+}
+/* apply hop penalty for a normal link */
+static uint8_t hop_penalty(const uint8_t tq)
+{
+ return (tq * (TQ_MAX_VALUE - TQ_HOP_PENALTY)) / (TQ_MAX_VALUE);
+}
+/* when do we schedule our own packet to be sent */
+static unsigned long own_send_time(void)
+{
+ return jiffies +
+ (((atomic_read(&originator_interval) - JITTER +
+ (random32() % 2*JITTER)) * HZ) / 1000);
+}
+
+/* when do we schedule a forwarded packet to be sent */
+static unsigned long forward_send_time(void)
+{
+ unsigned long send_time = jiffies; /* Starting now plus... */
+
+ if (atomic_read(&aggregation_enabled))
+ send_time += (((MAX_AGGREGATION_MS - (JITTER/2) +
+ (random32() % JITTER)) * HZ) / 1000);
+ else
+ send_time += (((random32() % (JITTER/2)) * HZ) / 1000);
+
+ return send_time;
+}
+
/* sends a raw packet. */
-void send_raw_packet(unsigned char *pack_buff, int pack_buff_len, uint8_t *src_addr, uint8_t *dst_addr, struct batman_if *batman_if)
+void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
+ uint8_t *src_addr, uint8_t *dst_addr,
+ struct batman_if *batman_if)
{
struct ethhdr *ethhdr;
struct sk_buff *skb;
@@ -46,7 +77,8 @@
return;
if (!(batman_if->net_dev->flags & IFF_UP)) {
- debug_log(LOG_TYPE_WARN, "Interface %s is not up - can't send packet via that interface !\n", batman_if->dev);
+ debug_log(LOG_TYPE_WARN,
+ "Interface %s is not up - can't send packet via that interface !\n", batman_if->dev);
batman_if->if_active = IF_TO_BE_DEACTIVATED;
return;
}
@@ -69,29 +101,103 @@
skb->protocol = __constant_htons(ETH_P_BATMAN);
skb->dev = batman_if->net_dev;
- /* dev_queue_xmit() returns a negative result on error.
- * However on congestion and traffic shaping, it drops and returns
- * NET_XMIT_DROP (which is > 0). This will not be treated as an error. */
+ /* dev_queue_xmit() returns a negative result on error. However on
+ * congestion and traffic shaping, it drops and returns NET_XMIT_DROP
+ * (which is > 0). This will not be treated as an error. */
retval = dev_queue_xmit(skb);
if (retval < 0) {
- debug_log(LOG_TYPE_CRIT, "Can't write to raw socket: %i\n", retval);
+ debug_log(LOG_TYPE_CRIT, "Can't write to raw socket: %i\n",
+ retval);
batman_if->if_active = IF_TO_BE_DEACTIVATED;
}
}
+/* Send a packet to a given interface */
+static void send_packet_to_if(struct forw_packet *forw_packet,
+ struct batman_if *batman_if)
+{
+ char *fwd_str;
+ uint8_t packet_num;
+ int16_t buff_pos;
+ struct batman_packet *batman_packet =
+ (struct batman_packet *)(forw_packet->packet_buff);
+ char orig_str[ETH_STR_LEN];
+
+ if (batman_if->if_active != IF_ACTIVE)
+ return;
+
+ packet_num = buff_pos = 0;
+ batman_packet = (struct batman_packet *)
+ (forw_packet->packet_buff);
+
+ /* adjust all flags and log packets */
+ while (aggregated_packet(buff_pos,
+ forw_packet->packet_len,
+ batman_packet->num_hna)) {
+
+ /* we might have aggregated direct link packets with an
+ * ordinary base packet */
+ if ((forw_packet->direct_link_flags & (1 << packet_num)) &&
+ (forw_packet->if_incoming == batman_if))
+ batman_packet->flags |= DIRECTLINK;
+ else
+ batman_packet->flags &= ~DIRECTLINK;
+
+ /* for later logging */
+ if (packet_num > 0)
+ addr_to_string(orig_str, batman_packet->orig);
+
+ /**
+ * if the outgoing interface is a wifi interface and
+ * equal to the incoming interface add extra penalty
+ * (own packets are to be ignored)
+ */
+ if ((batman_if->net_dev->wireless_handlers) &&
+ (!forw_packet->own) &&
+ (forw_packet->if_incoming == batman_if))
+ batman_packet->tq =
+ wireless_hop_penalty(batman_packet->tq);
+
+ fwd_str = (packet_num > 0 ? "Forwarding" : (forw_packet->own ?
+ "Sending own" :
+ "Forwarding"));
+ debug_log(LOG_TYPE_BATMAN,
+ "%s %s packet (originator %s, seqno %d, TQ %d, TTL %d, IDF %s) on interface %s [%s]\n",
+ fwd_str,
+ (packet_num > 0 ? "aggregated " : ""),
+ orig_str, ntohs(batman_packet->seqno),
+ batman_packet->tq, batman_packet->ttl,
+ (batman_packet->flags & DIRECTLINK ?
+ "on" : "off"),
+ batman_if->dev, batman_if->addr_str);
+
+ buff_pos += sizeof(struct batman_packet) +
+ (batman_packet->num_hna * ETH_ALEN);
+ packet_num++;
+ batman_packet = (struct batman_packet *)
+ (forw_packet->packet_buff + buff_pos);
+ }
+
+ send_raw_packet(forw_packet->packet_buff,
+ forw_packet->packet_len,
+ batman_if->net_dev->dev_addr,
+ broadcastAddr, batman_if);
+}
+
/* send a batman packet */
static void send_packet(struct forw_packet *forw_packet)
{
struct batman_if *batman_if;
- struct batman_packet *batman_packet = (struct batman_packet *)(forw_packet->packet_buff);
+ struct batman_packet *batman_packet =
+ (struct batman_packet *)(forw_packet->packet_buff);
char orig_str[ETH_STR_LEN];
unsigned char directlink = (batman_packet->flags & DIRECTLINK ? 1 : 0);
- uint8_t packet_num;
- int16_t buff_pos;
- /* according to calltree the incoming iface should always be specified. */
+ /* according to calltree the incoming iface should always be
+ * specified. */
if (forw_packet->if_incoming == NULL) {
- debug_log(LOG_TYPE_CRIT, "Error - can't forward packet: incoming iface not specified\n");
+ debug_log(LOG_TYPE_CRIT,
+ "Error - can't forward packet: incoming iface not specified\n");
return;
}
@@ -103,94 +209,66 @@
/* multihomed peer assumed */
/* non-primary OGMs are only broadcasted on their interface */
if ((directlink && (batman_packet->ttl == 1)) ||
- (forw_packet->own && (forw_packet->if_incoming->if_num > 0))) {
+ (forw_packet->own && (forw_packet->if_incoming->if_num > 0))) {
/* FIXME: what about aggregated packets ? */
- debug_log(LOG_TYPE_BATMAN, "%s packet (originator %s, seqno %d, TTL %d) on interface %s [%s]\n", (forw_packet->own ? "Sending own" : "Forwarding"), orig_str, ntohs(batman_packet->seqno), batman_packet->ttl, forw_packet->if_incoming->dev, forw_packet->if_incoming->addr_str);
+ debug_log(LOG_TYPE_BATMAN,
+ "%s packet (originator %s, seqno %d, TTL %d) on interface %s [%s]\n",
+ (forw_packet->own ? "Sending own" : "Forwarding"),
+ orig_str, ntohs(batman_packet->seqno),
+ batman_packet->ttl, forw_packet->if_incoming->dev,
+ forw_packet->if_incoming->addr_str);
- send_raw_packet(forw_packet->packet_buff, forw_packet->packet_len, forw_packet->if_incoming->net_dev->dev_addr, broadcastAddr, forw_packet->if_incoming);
+ send_raw_packet(forw_packet->packet_buff,
+ forw_packet->packet_len,
+ forw_packet->if_incoming->net_dev->dev_addr,
+ broadcastAddr, forw_packet->if_incoming);
return;
}
/* broadcast on every interface */
rcu_read_lock();
- list_for_each_entry_rcu(batman_if, &if_list, list) {
- if (batman_if->if_active != IF_ACTIVE)
- continue;
+ list_for_each_entry_rcu(batman_if, &if_list, list)
+ send_packet_to_if(forw_packet, batman_if);
+ rcu_read_unlock();
+}
- packet_num = buff_pos = 0;
- batman_packet = (struct batman_packet *)(forw_packet->packet_buff);
+static void rebuild_batman_packet(struct batman_if *batman_if)
+{
+ int new_len;
+ unsigned char *new_buff;
+ struct batman_packet *batman_packet;
- /* adjust all flags and log packets */
- while (aggregated_packet(buff_pos, forw_packet->packet_len, batman_packet->num_hna)) {
+ new_len = sizeof(struct batman_packet) + (num_hna * ETH_ALEN);
+ new_buff = kmalloc(new_len, GFP_ATOMIC);
- /* we might have aggregated direct link packets with an ordinary base packet */
- if ((forw_packet->direct_link_flags & (1 << packet_num)) && (forw_packet->if_incoming == batman_if))
- batman_packet->flags |= DIRECTLINK;
- else
- batman_packet->flags &= ~DIRECTLINK;
+ /* keep old buffer if kmalloc should fail */
+ if (new_buff) {
+ memcpy(new_buff, batman_if->packet_buff,
+ sizeof(struct batman_packet));
+ batman_packet = (struct batman_packet *)new_buff;
- /* for later logging */
- if (packet_num > 0)
- addr_to_string(orig_str, batman_packet->orig);
+ batman_packet->num_hna = hna_local_fill_buffer(
+ new_buff + sizeof(struct batman_packet),
+ new_len - sizeof(struct batman_packet));
- /**
- * if the outgoing interface is a wifi interface and equal to the incoming interface
- * add extra penalty (own packets are to be ignored)
- */
- if ((batman_if->net_dev->wireless_handlers) && (!forw_packet->own) &&
- (forw_packet->if_incoming == batman_if))
- batman_packet->tq = (batman_packet->tq * (TQ_MAX_VALUE - (2 * TQ_HOP_PENALTY))) / (TQ_MAX_VALUE);
-
- debug_log(LOG_TYPE_BATMAN,
- "%s %s packet (originator %s, seqno %d, TQ %d, TTL %d, IDF %s) on interface %s [%s]\n",
- (packet_num > 0 ? "Forwarding" : (forw_packet->own ? "Sending own" : "Forwarding")),
- (packet_num > 0 ? "aggregated " : ""), orig_str, ntohs(batman_packet->seqno),
- batman_packet->tq, batman_packet->ttl,
- (batman_packet->flags & DIRECTLINK ? "on" : "off"),
- batman_if->dev, batman_if->addr_str);
-
- buff_pos += sizeof(struct batman_packet) + (batman_packet->num_hna * ETH_ALEN);
- packet_num++;
- batman_packet = (struct batman_packet *)(forw_packet->packet_buff + buff_pos);
- }
-
- send_raw_packet(forw_packet->packet_buff, forw_packet->packet_len, batman_if->net_dev->dev_addr, broadcastAddr, batman_if);
+ kfree(batman_if->packet_buff);
+ batman_if->packet_buff = new_buff;
+ batman_if->packet_len = new_len;
}
- rcu_read_unlock();
}
void schedule_own_packet(struct batman_if *batman_if)
{
- unsigned char *new_buff;
unsigned long send_time;
struct batman_packet *batman_packet;
- int new_len;
batman_packet = (struct batman_packet *)batman_if->packet_buff;
/* if local hna has changed and interface is a primary interface */
- if ((hna_local_changed) && (batman_if->if_num == 0)) {
+ if ((hna_local_changed) && (batman_if->if_num == 0))
+ rebuild_batman_packet(batman_if);
- new_len = sizeof(struct batman_packet) + (num_hna * ETH_ALEN);
- new_buff = kmalloc(new_len, GFP_ATOMIC);
-
- /* keep old buffer if kmalloc should fail */
- if (new_buff) {
- memcpy(new_buff, batman_if->packet_buff, sizeof(struct batman_packet));
- batman_packet = (struct batman_packet *)new_buff;
-
- batman_packet->num_hna = hna_local_fill_buffer(
- new_buff + sizeof(struct batman_packet),
- new_len - sizeof(struct batman_packet));
-
- kfree(batman_if->packet_buff);
- batman_if->packet_buff = new_buff;
- batman_if->packet_len = new_len;
- }
-
- }
-
/* change sequence number to network order */
batman_packet->seqno = htons((uint16_t)atomic_read(&batman_if->seqno));
@@ -203,11 +281,16 @@
atomic_inc(&batman_if->seqno);
slide_own_bcast_window(batman_if);
- send_time = jiffies + (((atomic_read(&originator_interval) - JITTER + (random32() % 2*JITTER)) * HZ) / 1000);
- add_bat_packet_to_list(batman_if->packet_buff, batman_if->packet_len, batman_if, 1, send_time);
+ send_time = own_send_time();
+ add_bat_packet_to_list(batman_if->packet_buff,
+ batman_if->packet_len, batman_if, 1, send_time);
}
-void schedule_forward_packet(struct orig_node *orig_node, struct ethhdr *ethhdr, struct batman_packet *batman_packet, uint8_t directlink, int hna_buff_len, struct batman_if *if_incoming)
+void schedule_forward_packet(struct orig_node *orig_node,
+ struct ethhdr *ethhdr,
+ struct batman_packet *batman_packet,
+ uint8_t directlink, int hna_buff_len,
+ struct batman_if *if_incoming)
{
unsigned char in_tq, in_ttl, tq_avg = 0;
unsigned long send_time;
@@ -223,7 +306,8 @@
batman_packet->ttl--;
memcpy(batman_packet->old_orig, ethhdr->h_source, ETH_ALEN);
- /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast of our best tq value */
+ /* rebroadcast tq of our best ranking neighbor to ensure the rebroadcast
+ * of our best tq value */
if ((orig_node->router != NULL) && (orig_node->router->tq_avg != 0)) {
/* rebroadcast ogm of best ranking neighbor as is */
@@ -231,17 +315,17 @@
batman_packet->tq = orig_node->router->tq_avg;
batman_packet->ttl = orig_node->router->last_ttl - 1;
-
}
tq_avg = orig_node->router->tq_avg;
-
}
/* apply hop penalty */
- batman_packet->tq = (batman_packet->tq * (TQ_MAX_VALUE - TQ_HOP_PENALTY)) / (TQ_MAX_VALUE);
+ batman_packet->tq = hop_penalty(batman_packet->tq);
- debug_log(LOG_TYPE_BATMAN, "Forwarding packet: tq_orig: %i, tq_avg: %i, tq_forw: %i, ttl_orig: %i, ttl_forw: %i \n", in_tq, tq_avg, batman_packet->tq, in_ttl - 1, batman_packet->ttl);
+ debug_log(LOG_TYPE_BATMAN, "Forwarding packet: tq_orig: %i, tq_avg: %i, tq_forw: %i, ttl_orig: %i, ttl_forw: %i \n",
+ in_tq, tq_avg, batman_packet->tq, in_ttl - 1,
+ batman_packet->ttl);
batman_packet->seqno = htons(batman_packet->seqno);
@@ -250,12 +334,10 @@
else
batman_packet->flags &= ~DIRECTLINK;
- if (atomic_read(&aggregation_enabled))
- send_time = jiffies + (((MAX_AGGREGATION_MS - (JITTER/2) + (random32() % JITTER)) * HZ) / 1000);
- else
- send_time = jiffies + (((random32() % (JITTER/2)) * HZ) / 1000);
-
- add_bat_packet_to_list((unsigned char *)batman_packet, sizeof(struct batman_packet) + hna_buff_len, if_incoming, 0, send_time);
+ send_time = forward_send_time();
+ add_bat_packet_to_list((unsigned char *)batman_packet,
+ sizeof(struct batman_packet) + hna_buff_len,
+ if_incoming, 0, send_time);
}
static void forw_packet_free(struct forw_packet *forw_packet)
@@ -264,7 +346,8 @@
kfree(forw_packet);
}
-static void _add_bcast_packet_to_list(struct forw_packet *forw_packet, unsigned long send_time)
+static void _add_bcast_packet_to_list(struct forw_packet *forw_packet,
+ unsigned long send_time)
{
INIT_HLIST_NODE(&forw_packet->list);
@@ -274,8 +357,10 @@
spin_unlock(&forw_bcast_list_lock);
/* start timer for this packet */
- INIT_DELAYED_WORK(&forw_packet->delayed_work, send_outstanding_bcast_packet);
- queue_delayed_work(bat_event_workqueue, &forw_packet->delayed_work, send_time);
+ INIT_DELAYED_WORK(&forw_packet->delayed_work,
+ send_outstanding_bcast_packet);
+ queue_delayed_work(bat_event_workqueue, &forw_packet->delayed_work,
+ send_time);
}
void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len)
@@ -297,8 +382,10 @@
void send_outstanding_bcast_packet(struct work_struct *work)
{
struct batman_if *batman_if;
- struct delayed_work *delayed_work = container_of(work, struct delayed_work, work);
- struct forw_packet *forw_packet = container_of(delayed_work, struct forw_packet, delayed_work);
+ struct delayed_work *delayed_work =
+ container_of(work, struct delayed_work, work);
+ struct forw_packet *forw_packet =
+ container_of(delayed_work, struct forw_packet, delayed_work);
spin_lock(&forw_bcast_list_lock);
hlist_del(&forw_packet->list);
@@ -307,15 +394,19 @@
/* rebroadcast packet */
rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) {
- send_raw_packet(forw_packet->packet_buff, forw_packet->packet_len,
- batman_if->net_dev->dev_addr, broadcastAddr, batman_if);
+ send_raw_packet(forw_packet->packet_buff,
+ forw_packet->packet_len,
+ batman_if->net_dev->dev_addr,
+ broadcastAddr, batman_if);
}
rcu_read_unlock();
forw_packet->num_packets++;
- /* if we still have some more bcasts to send and we are not shutting down */
- if ((forw_packet->num_packets < 3) && (module_state != MODULE_INACTIVE))
+ /* if we still have some more bcasts to send and we are not shutting
+ * down */
+ if ((forw_packet->num_packets < 3) &&
+ (module_state != MODULE_INACTIVE))
_add_bcast_packet_to_list(forw_packet, ((5 * HZ) / 1000));
else
forw_packet_free(forw_packet);
@@ -323,8 +414,10 @@
void send_outstanding_bat_packet(struct work_struct *work)
{
- struct delayed_work *delayed_work = container_of(work, struct delayed_work, work);
- struct forw_packet *forw_packet = container_of(delayed_work, struct forw_packet, delayed_work);
+ struct delayed_work *delayed_work =
+ container_of(work, struct delayed_work, work);
+ struct forw_packet *forw_packet =
+ container_of(delayed_work, struct forw_packet, delayed_work);
spin_lock(&forw_bat_list_lock);
hlist_del(&forw_packet->list);
@@ -352,7 +445,8 @@
/* free bcast list */
spin_lock(&forw_bcast_list_lock);
- hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node, &forw_bcast_list, list) {
+ hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
+ &forw_bcast_list, list) {
spin_unlock(&forw_bcast_list_lock);
@@ -367,7 +461,8 @@
/* free batman packet list */
spin_lock(&forw_bat_list_lock);
- hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node, &forw_bat_list, list) {
+ hlist_for_each_entry_safe(forw_packet, tmp_node, safe_tmp_node,
+ &forw_bat_list, list) {
spin_unlock(&forw_bat_list_lock);
Index: batman-adv-kernelland/send.h
===================================================================
--- batman-adv-kernelland/send.h (revision 1351)
+++ batman-adv-kernelland/send.h (working copy)
@@ -17,18 +17,18 @@
*
*/
-
-
-
-
#include "types.h"
-
-
void send_own_packet_work(struct work_struct *work);
-void send_raw_packet(unsigned char *pack_buff, int pack_buff_len, uint8_t *src_addr, uint8_t *dst_addr, struct batman_if *batman_if);
+void send_raw_packet(unsigned char *pack_buff, int pack_buff_len,
+ uint8_t *src_addr, uint8_t *dst_addr,
+ struct batman_if *batman_if);
void schedule_own_packet(struct batman_if *batman_if);
-void schedule_forward_packet(struct orig_node *orig_node, struct ethhdr *ethhdr, struct batman_packet *batman_packet, uint8_t directlink, int hna_buff_len, struct batman_if *if_outgoing);
+void schedule_forward_packet(struct orig_node *orig_node,
+ struct ethhdr *ethhdr,
+ struct batman_packet *batman_packet,
+ uint8_t directlink, int hna_buff_len,
+ struct batman_if *if_outgoing);
void add_bcast_packet_to_list(unsigned char *packet_buff, int packet_len);
void send_outstanding_bcast_packet(struct work_struct *work);
void send_outstanding_bat_packet(struct work_struct *work);
13 years, 6 months
[B.A.T.M.A.N.] Bit of clarification - interfaces wrt54
by nick farrow
Hi,
I have installed kamikaze, xwrt, webif, batman webif - all ok.
I'm having difficulty in understanding how I 'link' batman to the wireless interface. I have removed all the virtual lan stuff as I think this is the first step.
If I ssh in and ifconfig I can see eth0.0 (lan ports) eth0.1 (seems to be the internet wan port) and also wl0 with the config I set for it via the webif.
If I go to the webif/mesh tab all I can select as interfaces are the listed are the eth0.0 and eth0.1 no mention of the wireless interface ?
Second point the Mesh tab indicates that no batmand is running, presumably it will auto start (from this page) when I have the interface set properly.
Sorry for the basic questions, I have read the basic howto's but am not really sure how the command line relates to the batman webif.
Thanks very much
nick
_________________________________________________________________
Windows Live Messenger: Celebrate 10 amazing years with free winks and emoticons.
http://clk.atdmt.com/UKM/go/157562755/direct/01/
13 years, 6 months
[B.A.T.M.A.N.] [batman-adv] Cleanup aggregation.[ch]
by Andrew Lunn
Make aggregation.[ch] clean with respect to the 2.6.29 checkpatch script.
Signed-off-by: Andrew Lunn <andrew.lunn(a)ascom.ch>
Index: batman-adv-kernelland/aggregation.c
===================================================================
--- batman-adv-kernelland/aggregation.c (revision 1351)
+++ batman-adv-kernelland/aggregation.c (working copy)
@@ -17,146 +17,212 @@
*
*/
-
-
-
#include "main.h"
#include "aggregation.h"
#include "send.h"
#include "routing.h"
+/* calculate the size of the hna information for a given packet */
+static int hna_len(struct batman_packet *batman_packet)
+{
+ return batman_packet->num_hna * ETH_ALEN;
+}
+/* return true if new_packet can be aggregated with forw_packet */
+static bool can_aggregate_with(struct batman_packet *new_packet,
+ int packet_len,
+ unsigned long send_time,
+ bool directlink,
+ struct batman_if *if_incoming,
+ struct forw_packet *forw_packet_pos)
+{
-void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len, struct batman_if *if_incoming, char own_packet, unsigned long send_time)
-{
+ struct batman_packet *forw_packet =
+ (struct batman_packet *)forw_packet_pos->packet_buff;
+ int aggregated_bytes = forw_packet_pos->packet_len + packet_len;
+
/**
- * _aggr -> pointer to the packet we want to aggregate with
- * _pos -> pointer to the position in the queue
+ * we can aggregate the current packet to this aggregated packet
+ * if:
+ *
+ * - the send time is within our MAX_AGGREGATION_MS time
+ * - the resulting packet wont be bigger than
+ * MAX_AGGREGATION_BYTES
*/
- struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
- struct hlist_node *tmp_node;
- struct batman_packet *batman_packet;
- unsigned char directlink = (((struct batman_packet *)packet_buff)->flags & DIRECTLINK ? 1 : 0);
- /* find position for the packet in the forward queue */
- spin_lock(&forw_bat_list_lock);
- hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list, list) {
+ if (time_before(send_time, forw_packet_pos->send_time) &&
+ (aggregated_bytes <= MAX_AGGREGATION_BYTES)) {
- /* own packets are not to be aggregated */
- if ((atomic_read(&aggregation_enabled)) && (!own_packet)) {
+ /**
+ * check aggregation compatibility
+ * -> direct link packets are broadcasted on
+ * their interface only
+ * -> aggregate packet if the current packet is
+ * a "global" packet as well as the base
+ * packet
+ */
- /* don't save aggregation position if aggregation is disabled */
- forw_packet_aggr = forw_packet_pos;
+ /* packets without direct link flag and high TTL
+ * are flooded through the net */
+ if ((!directlink) &&
+ (!(forw_packet->flags & DIRECTLINK)) &&
+ (forw_packet->ttl != 1) &&
- /**
- * we can aggregate the current packet to this packet if:
- * - the send time is within our MAX_AGGREGATION_MS time
- * - the resulting packet wont be bigger than MAX_AGGREGATION_BYTES
- */
- if ((time_before(send_time, forw_packet_pos->send_time)) &&
- (forw_packet_pos->packet_len + packet_len <= MAX_AGGREGATION_BYTES)) {
+ /* own packets originating non-primary
+ * interfaces leave only that interface */
+ ((!forw_packet_pos->own) ||
+ (forw_packet_pos->if_incoming->if_num == 0)))
+ return true;
- batman_packet = (struct batman_packet *)forw_packet_pos->packet_buff;
+ /* if the incoming packet is sent via this one
+ * interface only - we still can aggregate */
+ if ((directlink) &&
+ (new_packet->ttl == 1) &&
+ (forw_packet_pos->if_incoming == if_incoming))
+ return true;
- /**
- * check aggregation compatibility
- * -> direct link packets are broadcasted on their interface only
- * -> aggregate packet if the current packet is a "global" packet
- * as well as the base packet
- */
+ }
+ return false;
+}
- /* packets without direct link flag and high TTL are flooded through the net */
- if ((!directlink) && (!(batman_packet->flags & DIRECTLINK)) && (batman_packet->ttl != 1) &&
+/* create a new aggregated packet and add this packet to it */
+void new_aggregated_packet(unsigned char *packet_buff, int packet_len,
+ unsigned long send_time,
+ bool direct_link,
+ struct batman_if *if_incoming,
+ int own_packet)
+{
+ struct forw_packet *forw_packet_aggr;
- /* own packets originating non-primary interfaces leave only that interface */
- ((!forw_packet_pos->own) || (forw_packet_pos->if_incoming->if_num == 0)))
- break;
+ forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
+ if (!forw_packet_aggr)
+ return;
- batman_packet = (struct batman_packet *)packet_buff;
+ forw_packet_aggr->packet_buff = kmalloc(MAX_AGGREGATION_BYTES,
+ GFP_ATOMIC);
+ if (!forw_packet_aggr->packet_buff) {
+ kfree(forw_packet_aggr);
+ return;
+ }
- /* if the incoming packet is sent via this one interface only - we still can aggregate */
- if ((directlink) && (batman_packet->ttl == 1) && (forw_packet_pos->if_incoming == if_incoming))
- break;
+ INIT_HLIST_NODE(&forw_packet_aggr->list);
- }
+ forw_packet_aggr->packet_len = packet_len;
+ memcpy(forw_packet_aggr->packet_buff,
+ packet_buff,
+ forw_packet_aggr->packet_len);
- /* could not find packet to aggregate with */
- forw_packet_aggr = NULL;
+ forw_packet_aggr->own = own_packet;
+ forw_packet_aggr->if_incoming = if_incoming;
+ forw_packet_aggr->num_packets = 0;
+ forw_packet_aggr->direct_link_flags = 0;
+ forw_packet_aggr->send_time = send_time;
- }
+ /* save packet direct link flag status */
+ if (direct_link)
+ forw_packet_aggr->direct_link_flags |= 1;
- }
+ /* add new packet to packet list */
+ spin_lock(&forw_bat_list_lock);
+ hlist_add_head(&forw_packet_aggr->list, &forw_bat_list);
+ spin_unlock(&forw_bat_list_lock);
- /* nothing to aggregate with - either aggregation disabled or no suitable aggregation packet found */
- if (forw_packet_aggr == NULL) {
+ /* start timer for this packet */
+ INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work,
+ send_outstanding_bat_packet);
+ queue_delayed_work(bat_event_workqueue,
+ &forw_packet_aggr->delayed_work,
+ send_time - jiffies);
+}
- /* the following section can run without the lock */
- spin_unlock(&forw_bat_list_lock);
+/* aggregate a new packet into the existing aggregation */
+static void aggregate(struct forw_packet *forw_packet_aggr,
+ unsigned char *packet_buff, int packet_len,
+ bool direct_link)
+{
+ memcpy((forw_packet_aggr->packet_buff + forw_packet_aggr->packet_len),
+ packet_buff, packet_len);
+ forw_packet_aggr->packet_len += packet_len;
+ forw_packet_aggr->num_packets++;
- forw_packet_aggr = kmalloc(sizeof(struct forw_packet), GFP_ATOMIC);
- forw_packet_aggr->packet_buff = kmalloc(MAX_AGGREGATION_BYTES, GFP_ATOMIC);
+ /* save packet direct link flag status */
+ if (direct_link)
+ forw_packet_aggr->direct_link_flags |=
+ (1 << forw_packet_aggr->num_packets);
+}
- INIT_HLIST_NODE(&forw_packet_aggr->list);
+void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
+ struct batman_if *if_incoming, char own_packet,
+ unsigned long send_time)
+{
+ /**
+ * _aggr -> pointer to the packet we want to aggregate with
+ * _pos -> pointer to the position in the queue
+ */
+ struct forw_packet *forw_packet_aggr = NULL, *forw_packet_pos = NULL;
+ struct hlist_node *tmp_node;
+ struct batman_packet *batman_packet =
+ (struct batman_packet *)packet_buff;
+ bool direct_link = batman_packet->flags & DIRECTLINK ? 1 : 0;
- forw_packet_aggr->packet_len = packet_len;
- memcpy(forw_packet_aggr->packet_buff, packet_buff, forw_packet_aggr->packet_len);
+ /* find position for the packet in the forward queue */
+ spin_lock(&forw_bat_list_lock);
+ /* own packets are not to be aggregated */
+ if ((atomic_read(&aggregation_enabled)) && (!own_packet)) {
+ hlist_for_each_entry(forw_packet_pos, tmp_node, &forw_bat_list,
+ list) {
+ if (can_aggregate_with(batman_packet,
+ packet_len,
+ send_time,
+ direct_link,
+ if_incoming,
+ forw_packet_pos)) {
+ forw_packet_aggr = forw_packet_pos;
+ break;
+ }
+ }
+ }
- forw_packet_aggr->own = own_packet;
- forw_packet_aggr->if_incoming = if_incoming;
- forw_packet_aggr->num_packets = 0;
- forw_packet_aggr->direct_link_flags = 0;
-
- forw_packet_aggr->send_time = send_time;
-
- batman_packet = (struct batman_packet *)packet_buff;
-
- /* save packet direct link flag status */
- if (batman_packet->flags & DIRECTLINK)
- forw_packet_aggr->direct_link_flags = forw_packet_aggr->direct_link_flags | (1 << forw_packet_aggr->num_packets);
-
- /* add new packet to packet list */
- spin_lock(&forw_bat_list_lock);
- hlist_add_head(&forw_packet_aggr->list, &forw_bat_list);
+ /* nothing to aggregate with - either aggregation disabled or no
+ * suitable aggregation packet found */
+ if (forw_packet_aggr == NULL) {
+ /* the following section can run without the lock */
spin_unlock(&forw_bat_list_lock);
-
- /* start timer for this packet */
- INIT_DELAYED_WORK(&forw_packet_aggr->delayed_work, send_outstanding_bat_packet);
- queue_delayed_work(bat_event_workqueue, &forw_packet_aggr->delayed_work, send_time - jiffies);
-
+ new_aggregated_packet(packet_buff, packet_len,
+ send_time, direct_link,
+ if_incoming, own_packet);
} else {
-
- batman_packet = (struct batman_packet *)packet_buff;
-
- memcpy(forw_packet_aggr->packet_buff + forw_packet_aggr->packet_len, packet_buff, packet_len);
- forw_packet_aggr->packet_len += packet_len;
-
- forw_packet_aggr->num_packets++;
-
- /* save packet direct link flag status */
- if (batman_packet->flags & DIRECTLINK)
- forw_packet_aggr->direct_link_flags = forw_packet_aggr->direct_link_flags | (1 << forw_packet_aggr->num_packets);
-
+ aggregate(forw_packet_aggr,
+ packet_buff, packet_len,
+ direct_link);
spin_unlock(&forw_bat_list_lock);
-
}
}
-void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff, int packet_len, struct batman_if *if_incoming)
+/* unpack the aggregated packets and process them one by one */
+void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
+ int packet_len, struct batman_if *if_incoming)
{
struct batman_packet *batman_packet;
- int16_t buff_pos = 0;
+ int buff_pos = 0;
+ unsigned char *hna_buff;
batman_packet = (struct batman_packet *)packet_buff;
- /* unpack the aggregated packets and process them one by one */
- while (aggregated_packet(buff_pos, packet_len, batman_packet->num_hna)) {
+ while (aggregated_packet(buff_pos, packet_len,
+ batman_packet->num_hna)) {
- /* network to host order for our 16bit seqno. */
+ /* network to host order for our 16bit seqno, and the
+ orig_interval. */
batman_packet->seqno = ntohs(batman_packet->seqno);
- receive_bat_packet(ethhdr, batman_packet, packet_buff + buff_pos + sizeof(struct batman_packet), batman_packet->num_hna * ETH_ALEN, if_incoming);
+ hna_buff = packet_buff + buff_pos + BAT_PACKET_LEN;
+ receive_bat_packet(ethhdr, batman_packet,
+ hna_buff, hna_len(batman_packet),
+ if_incoming);
- buff_pos += sizeof(struct batman_packet) + batman_packet->num_hna * ETH_ALEN;
- batman_packet = (struct batman_packet *)(packet_buff + buff_pos);
+ buff_pos += BAT_PACKET_LEN + hna_len(batman_packet);
+ batman_packet = (struct batman_packet *)
+ (packet_buff + buff_pos);
}
}
Index: batman-adv-kernelland/aggregation.h
===================================================================
--- batman-adv-kernelland/aggregation.h (revision 1351)
+++ batman-adv-kernelland/aggregation.h (working copy)
@@ -17,15 +17,19 @@
*
*/
-
-
-
#include "main.h"
-#define aggregated_packet(buff_pos, packet_len, num_hna) \
- buff_pos + sizeof(struct batman_packet) + (num_hna * ETH_ALEN) <= packet_len && \
- buff_pos + sizeof(struct batman_packet) + (num_hna * ETH_ALEN) <= MAX_AGGREGATION_BYTES
+/* is there another aggregated packet here? */
+static inline int aggregated_packet(int buff_pos, int packet_len, int num_hna)
+{
+ int next_buff_pos = buff_pos + BAT_PACKET_LEN + (num_hna * ETH_ALEN);
+ return (next_buff_pos <= packet_len) &&
+ (next_buff_pos <= MAX_AGGREGATION_BYTES);
+}
-void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len, struct batman_if *if_outgoing, char own_packet, unsigned long send_time);
-void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff, int packet_len, struct batman_if *if_incoming);
+void add_bat_packet_to_list(unsigned char *packet_buff, int packet_len,
+ struct batman_if *if_outgoing, char own_packet,
+ unsigned long send_time);
+void receive_aggr_bat_packet(struct ethhdr *ethhdr, unsigned char *packet_buff,
+ int packet_len, struct batman_if *if_incoming);
13 years, 6 months
[B.A.T.M.A.N.] Batman gateway lock ups
by Outback Dingo
see pastebin
http://www.pastebin.ca/1194874
pertinent info
dmesg | grep 'batgat loaded'
batgat: [init_module:96] batgat loaded rv1025
uname -a
Linux nightwing 2.6.23.16 #16 Tue Apr 22 20:00:17 ART 2008 mips unknown
root@nightwing:~# batmand -v
WARNING: You are using the unstable batman branch. If you are interested in
*using* batman get the latest stable release !
B.A.T.M.A.N. 0.3-beta (compatibility version 5)
lsmod
Module Size Used by Tainted:
P
sch_htb 14048
2
ath_ahb 103616
0
wlan_xauth 480
0
wlan_wep 4000
0
wlan_tkip 9856
0
wlan_ccmp 5440
2
wlan_acl 1920 0
ath_rate_minstrel 8352 1
ath_hal 136832 3 ath_ahb,ath_rate_minstrel
wlan_scan_sta 8768 1
wlan_scan_ap 6656 0
wlan 152464 10
ath_ahb,wlan_xauth,wlan_wep,wlan_tkip,wlan_ccmp,wlan_acl,ath_rate_minstrel,wlan_scan_sta,wlan_scan_ap
batgat 10944 1
ipt_iprange 672 0
ipt_TOS 832 0
ipt_TTL 928 0
xt_MARK 960 3
ipt_ECN 1472 0
xt_CLASSIFY 640 0
ipt_ttl 704 0
ipt_tos 544 0
ipt_time 1568 0
xt_tcpmss 1088 0
xt_statistic 832 0
xt_mark 672 7
xt_mac 736 3
xt_length 736 0
ipt_ecn 1024 0
xt_DSCP 1056 0
xt_dscp 832 0
imq 2096 0
ipt_IMQ 672 2
xt_string 896 0
xt_layer7 9840 0
ipt_ipp2p 6784 0
ipt_LOG 4640 0
xt_CHAOS 1792 0
xt_DELUDE 2624 1
xt_TARPIT 2816 1
xt_quota 800 0
xt_portscan 2016 0
xt_pkttype 704 0
xt_physdev 1488 0
ipt_owner 800 0
iptable_raw 832 0
xt_NOTRACK 832 0
xt_CONNMARK 1088 0
ipt_recent 4992 0
xt_helper 992 0
xt_conntrack 1312 0
xt_connmark 832 0
xt_connbytes 1312 0
tun 6592 0
13 years, 6 months
[B.A.T.M.A.N.] VIS labels
by Gustavo Lindberg
Hi
I would like to know where I can find information about the data that
the VIS Server gives. More precisely the label on each link and its
relation with the link quality that B.A.T.M.A.N. gives.
Also, which is the general criteria to know from which number, that
the output shows, is considered a good, regular, bad or "imposible to
use" link?
An example:
digraph topology
{
"5.174.37.225" -> "5.224.160.202"[label="2.13"]
"5.174.117.226" -> "5.174.37.225"[label="5.00"]
"5.174.117.226" -> "0.0.0.0/0.0.0.0"[label="HNA"]
"5.224.160.202" -> "5.174.37.225"[label="1.28"]
"5.224.160.202" -> "0.0.0.0/0.0.0.0"[label="HNA"]
}
Thanks in advance.
13 years, 6 months
[B.A.T.M.A.N.] [batman-adv] Cleanup translation-table.[ch]
by Andrew Lunn
Make translation-table.[ch] clean with respect to the 2.6.29
checkpatch script. Exceptions are long lines with debug_log.
Signed-off-by: Andrew Lunn <andrew.lunn(a)ascom.ch>
Index: batman-adv-kernelland/translation-table.c
===================================================================
--- batman-adv-kernelland/translation-table.c (revision 1351)
+++ batman-adv-kernelland/translation-table.c (working copy)
@@ -17,10 +17,6 @@
*
*/
-
-
-
-
#include "main.h"
#include "translation-table.h"
#include "log.h"
@@ -29,17 +25,14 @@
#include "hash.h"
#include "compat.h"
+struct hashtable_t *hna_local_hash;
+static struct hashtable_t *hna_global_hash;
-
-struct hashtable_t *hna_local_hash = NULL;
-static struct hashtable_t *hna_global_hash = NULL;
-
DEFINE_SPINLOCK(hna_local_hash_lock);
DEFINE_SPINLOCK(hna_global_hash_lock);
static DECLARE_DELAYED_WORK(hna_local_purge_wq, hna_local_purge);
-
static void hna_local_start_timer(void)
{
queue_delayed_work(bat_event_workqueue, &hna_local_purge_wq, 10 * HZ);
@@ -66,7 +59,8 @@
unsigned long flags;
spin_lock_irqsave(&hna_local_hash_lock, flags);
- hna_local_entry = ((struct hna_local_entry *)hash_find(hna_local_hash, addr));
+ hna_local_entry =
+ ((struct hna_local_entry *)hash_find(hna_local_hash, addr));
spin_unlock_irqrestore(&hna_local_hash_lock, flags);
if (hna_local_entry != NULL) {
@@ -76,17 +70,19 @@
addr_to_string(hna_str, addr);
- /* only announce as many hosts as possible in the batman-packet and space in batman_packet->num_hna
- That also should give a limit to MAC-flooding. */
- if ((num_hna + 1 > (1500 - sizeof(struct batman_packet)) / 6) || (num_hna + 1 > 255)) {
+ /* only announce as many hosts as possible in the batman-packet and
+ space in batman_packet->num_hna That also should give a limit to
+ MAC-flooding. */
+ if ((num_hna + 1 > (1500 - sizeof(struct batman_packet)) / 6) ||
+ (num_hna + 1 > 255)) {
debug_log(LOG_TYPE_ROUTES, "Can't add new local hna entry (%s): number of local hna entries exceeds packet size \n", hna_str);
return;
}
- debug_log(LOG_TYPE_ROUTES, "Creating new local hna entry: %s \n", hna_str);
+ debug_log(LOG_TYPE_ROUTES, "Creating new local hna entry: %s \n",
+ hna_str);
hna_local_entry = kmalloc(sizeof(struct hna_local_entry), GFP_KERNEL);
-
if (!hna_local_entry)
return;
@@ -106,7 +102,8 @@
hna_local_changed = 1;
if (hna_local_hash->elements * 4 > hna_local_hash->size) {
- swaphash = hash_resize(hna_local_hash, hna_local_hash->size * 2);
+ swaphash = hash_resize(hna_local_hash,
+ hna_local_hash->size * 2);
if (swaphash == NULL)
debug_log(LOG_TYPE_CRIT, "Couldn't resize local hna hash table \n");
@@ -119,7 +116,8 @@
/* remove address from global hash if present */
spin_lock_irqsave(&hna_global_hash_lock, flags);
- hna_global_entry = ((struct hna_global_entry *)hash_find(hna_global_hash, addr));
+ hna_global_entry =
+ ((struct hna_global_entry *)hash_find(hna_global_hash, addr));
if (hna_global_entry != NULL)
_hna_global_del_orig(hna_global_entry, "local hna received");
@@ -172,9 +170,14 @@
hna_local_entry = hashit->bucket->data;
- bytes_written += snprintf(buff + bytes_written, ETH_STR_LEN + 4, " * %02x:%02x:%02x:%02x:%02x:%02x\n",
- hna_local_entry->addr[0], hna_local_entry->addr[1], hna_local_entry->addr[2],
- hna_local_entry->addr[3], hna_local_entry->addr[4], hna_local_entry->addr[5]);
+ bytes_written += snprintf(buff + bytes_written, ETH_STR_LEN + 4,
+ " * %02x:%02x:%02x:%02x:%02x:%02x\n",
+ hna_local_entry->addr[0],
+ hna_local_entry->addr[1],
+ hna_local_entry->addr[2],
+ hna_local_entry->addr[3],
+ hna_local_entry->addr[4],
+ hna_local_entry->addr[5]);
}
spin_unlock_irqrestore(&hna_local_hash_lock, flags);
@@ -189,12 +192,14 @@
hna_local_changed = 1;
}
-static void hna_local_del(struct hna_local_entry *hna_local_entry, char *message)
+static void hna_local_del(struct hna_local_entry *hna_local_entry,
+ char *message)
{
char hna_str[ETH_STR_LEN];
addr_to_string(hna_str, hna_local_entry->addr);
- debug_log(LOG_TYPE_ROUTES, "Deleting local hna entry (%s): %s \n", hna_str, message);
+ debug_log(LOG_TYPE_ROUTES, "Deleting local hna entry (%s): %s \n",
+ hna_str, message);
hash_remove(hna_local_hash, hna_local_entry->addr);
_hna_local_del(hna_local_entry);
@@ -205,15 +210,18 @@
struct hna_local_entry *hna_local_entry;
struct hash_it_t *hashit = NULL;
unsigned long flags;
+ unsigned long timeout;
spin_lock_irqsave(&hna_local_hash_lock, flags);
while (NULL != (hashit = hash_iterate(hna_local_hash, hashit))) {
-
hna_local_entry = hashit->bucket->data;
- if ((!hna_local_entry->never_purge) && (time_after(jiffies, hna_local_entry->last_seen + (LOCAL_HNA_TIMEOUT /1000) * HZ)))
- hna_local_del(hna_local_entry, "address timeouted");
+ timeout = hna_local_entry->last_seen +
+ ((LOCAL_HNA_TIMEOUT / 1000) * HZ);
+ if ((!hna_local_entry->never_purge) &&
+ time_after(jiffies, timeout))
+ hna_local_del(hna_local_entry, "address timed out");
}
spin_unlock_irqrestore(&hna_local_hash_lock, flags);
@@ -223,7 +231,6 @@
void hna_local_free(void)
{
if (hna_local_hash != NULL) {
-
cancel_delayed_work_sync(&hna_local_purge_wq);
hash_delete(hna_local_hash, _hna_local_del);
}
@@ -239,7 +246,8 @@
return 1;
}
-void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff, int hna_buff_len)
+void hna_global_add_orig(struct orig_node *orig_node,
+ unsigned char *hna_buff, int hna_buff_len)
{
struct hna_global_entry *hna_global_entry;
struct hna_local_entry *hna_local_entry;
@@ -247,25 +255,28 @@
char hna_str[ETH_STR_LEN], orig_str[ETH_STR_LEN];
int hna_buff_count = 0;
unsigned long flags;
+ unsigned char *hna_ptr;
addr_to_string(orig_str, orig_node->orig);
while ((hna_buff_count + 1) * ETH_ALEN <= hna_buff_len) {
-
spin_lock_irqsave(&hna_global_hash_lock, flags);
- hna_global_entry = ((struct hna_global_entry *)hash_find(hna_global_hash, hna_buff + (hna_buff_count * ETH_ALEN)));
+ hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
+ hna_global_entry = (struct hna_global_entry *)
+ hash_find(hna_global_hash, hna_ptr);
if (hna_global_entry == NULL) {
-
spin_unlock_irqrestore(&hna_global_hash_lock, flags);
- hna_global_entry = kmalloc(sizeof(struct hna_global_entry), GFP_KERNEL);
+ hna_global_entry =
+ kmalloc(sizeof(struct hna_global_entry),
+ GFP_KERNEL);
if (!hna_global_entry)
break;
- memcpy(hna_global_entry->addr, hna_buff + (hna_buff_count * ETH_ALEN), ETH_ALEN);
+ memcpy(hna_global_entry->addr, hna_ptr, ETH_ALEN);
addr_to_string(hna_str, hna_global_entry->addr);
debug_log(LOG_TYPE_ROUTES, "Creating new global hna entry: %s (via %s)\n", hna_str, orig_str);
@@ -281,7 +292,9 @@
/* remove address from local hash if present */
spin_lock_irqsave(&hna_local_hash_lock, flags);
- hna_local_entry = ((struct hna_local_entry *)hash_find(hna_local_hash, hna_buff + (hna_buff_count * ETH_ALEN)));
+ hna_ptr = hna_buff + (hna_buff_count * ETH_ALEN);
+ hna_local_entry = (struct hna_local_entry *)
+ hash_find(hna_local_hash, hna_ptr);
if (hna_local_entry != NULL)
hna_local_del(hna_local_entry, "global hna received");
@@ -294,7 +307,8 @@
orig_node->hna_buff_len = hna_buff_len;
if (orig_node->hna_buff_len > 0) {
- orig_node->hna_buff = kmalloc(orig_node->hna_buff_len, GFP_KERNEL);
+ orig_node->hna_buff = kmalloc(orig_node->hna_buff_len,
+ GFP_KERNEL);
memcpy(orig_node->hna_buff, hna_buff, orig_node->hna_buff_len);
} else {
orig_node->hna_buff = NULL;
@@ -303,7 +317,8 @@
spin_lock_irqsave(&hna_global_hash_lock, flags);
if (hna_global_hash->elements * 4 > hna_global_hash->size) {
- swaphash = hash_resize(hna_global_hash, hna_global_hash->size * 2);
+ swaphash = hash_resize(hna_global_hash,
+ hna_global_hash->size * 2);
if (swaphash == NULL)
debug_log(LOG_TYPE_CRIT, "Couldn't resize global hna hash table \n");
@@ -324,19 +339,26 @@
spin_lock_irqsave(&hna_global_hash_lock, flags);
while (NULL != (hashit = hash_iterate(hna_global_hash, hashit))) {
-
if (buff_len < bytes_written + (2 * ETH_STR_LEN) + 10)
break;
hna_global_entry = hashit->bucket->data;
- bytes_written += snprintf(buff + bytes_written, (2 * ETH_STR_LEN) + 10,
- " * %02x:%02x:%02x:%02x:%02x:%02x via %02x:%02x:%02x:%02x:%02x:%02x \n",
- hna_global_entry->addr[0], hna_global_entry->addr[1], hna_global_entry->addr[2],
- hna_global_entry->addr[3], hna_global_entry->addr[4], hna_global_entry->addr[5],
- hna_global_entry->orig_node->orig[0], hna_global_entry->orig_node->orig[1],
- hna_global_entry->orig_node->orig[2], hna_global_entry->orig_node->orig[3],
- hna_global_entry->orig_node->orig[4], hna_global_entry->orig_node->orig[5]);
+ bytes_written += snprintf(buff + bytes_written,
+ (2 * ETH_STR_LEN) + 10,
+ " * %02x:%02x:%02x:%02x:%02x:%02x via %02x:%02x:%02x:%02x:%02x:%02x \n",
+ hna_global_entry->addr[0],
+ hna_global_entry->addr[1],
+ hna_global_entry->addr[2],
+ hna_global_entry->addr[3],
+ hna_global_entry->addr[4],
+ hna_global_entry->addr[5],
+ hna_global_entry->orig_node->orig[0],
+ hna_global_entry->orig_node->orig[1],
+ hna_global_entry->orig_node->orig[2],
+ hna_global_entry->orig_node->orig[3],
+ hna_global_entry->orig_node->orig[4],
+ hna_global_entry->orig_node->orig[5]);
}
spin_unlock_irqrestore(&hna_global_hash_lock, flags);
@@ -344,7 +366,8 @@
return bytes_written;
}
-void _hna_global_del_orig(struct hna_global_entry *hna_global_entry, char *message)
+void _hna_global_del_orig(struct hna_global_entry *hna_global_entry,
+ char *message)
{
char hna_str[ETH_STR_LEN], orig_str[ETH_STR_LEN];
@@ -362,6 +385,7 @@
struct hna_global_entry *hna_global_entry;
int hna_buff_count = 0;
unsigned long flags;
+ unsigned char *hna_ptr;
if (orig_node->hna_buff_len == 0)
return;
@@ -369,10 +393,12 @@
spin_lock_irqsave(&hna_global_hash_lock, flags);
while ((hna_buff_count + 1) * ETH_ALEN <= orig_node->hna_buff_len) {
+ hna_ptr = orig_node->hna_buff + (hna_buff_count * ETH_ALEN);
+ hna_global_entry = (struct hna_global_entry *)
+ hash_find(hna_global_hash, hna_ptr);
- hna_global_entry = ((struct hna_global_entry *)hash_find(hna_global_hash, orig_node->hna_buff + (hna_buff_count * ETH_ALEN)));
-
- if ((hna_global_entry != NULL) && (hna_global_entry->orig_node == orig_node))
+ if ((hna_global_entry != NULL) &&
+ (hna_global_entry->orig_node == orig_node))
_hna_global_del_orig(hna_global_entry, message);
hna_buff_count++;
@@ -402,7 +428,8 @@
unsigned long flags;
spin_lock_irqsave(&hna_global_hash_lock, flags);
- hna_global_entry = ((struct hna_global_entry *)hash_find(hna_global_hash, addr));
+ hna_global_entry = (struct hna_global_entry *)
+ hash_find(hna_global_hash, addr);
spin_unlock_irqrestore(&hna_global_hash_lock, flags);
if (hna_global_entry == NULL)
@@ -410,4 +437,3 @@
return hna_global_entry->orig_node;
}
-
Index: batman-adv-kernelland/translation-table.h
===================================================================
--- batman-adv-kernelland/translation-table.h (revision 1351)
+++ batman-adv-kernelland/translation-table.h (working copy)
@@ -17,14 +17,8 @@
*
*/
-
-
-
-
#include "types.h"
-
-
int hna_local_init(void);
void hna_local_add(uint8_t *addr);
int hna_local_fill_buffer(unsigned char *buff, int buff_len);
@@ -32,9 +26,11 @@
void hna_local_purge(struct work_struct *work);
void hna_local_free(void);
int hna_global_init(void);
-void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff, int hna_buff_len);
+void hna_global_add_orig(struct orig_node *orig_node, unsigned char *hna_buff,
+ int hna_buff_len);
int hna_global_fill_buffer_text(unsigned char *buff, int buff_len);
-void _hna_global_del_orig(struct hna_global_entry *hna_global_entry, char *orig_str);
+void _hna_global_del_orig(struct hna_global_entry *hna_global_entry,
+ char *orig_str);
void hna_global_del_orig(struct orig_node *orig_node, char *message);
void hna_global_free(void);
struct orig_node *transtable_search(uint8_t *addr);
13 years, 6 months