Skip to content

Commit

Permalink
Staging: batman-adv: replace internal logging mechanism.
Browse files Browse the repository at this point in the history
batman-adv used its own logging infrastructure. Replace this with
standard kernel logging, printk(), with compile time and runtime
options to enable/disable different debug levels.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Andrew Lunn authored and Greg Kroah-Hartman committed Mar 4, 2010
1 parent e89230e commit bad2239
Show file tree
Hide file tree
Showing 15 changed files with 242 additions and 520 deletions.
2 changes: 1 addition & 1 deletion drivers/staging/batman-adv/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,4 +19,4 @@
#

obj-m += batman-adv.o
batman-adv-objs := main.o proc.o send.o routing.o soft-interface.o device.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o log.o
batman-adv-objs := main.o proc.o send.o routing.o soft-interface.o device.o translation-table.o bitarray.o hash.o ring_buffer.o vis.o hard-interface.o aggregation.o
50 changes: 49 additions & 1 deletion drivers/staging/batman-adv/README
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
[state: 07-11-2009]
[state: 13-11-2009]

BATMAN-ADV
----------
Expand Down Expand Up @@ -96,6 +96,54 @@ To deactivate batman, do:

# echo "" > /proc/net/batman-adv/interfaces

LOGGING/DEBUGGING
-----------------

All error messages, warnings and information messages are sent to the
kernel log. Depending on your operating system distribution this can be
read in one of a number of ways. Try using the commands: dmesg,
logread, or looking in the files /var/log/kern.log or
/var/log/syslog. All batman-adv messages are prefixed with
"batman-adv:" So to see just these messages try

dmesg | grep batman-adv

When investigating problems with your mesh network it is sometimes
necessary to see more detail debug messages. This must be enabled when
compiling the batman-adv module. When building batman-adv as part of
kernel, use "make menuconfig" and enable the option
"B.A.T.M.A.N. debugging". When compiling outside of the kernel tree it
is necessary to edit the file Makefile.kbuild and uncomment the line

#EXTRA_CFLAGS += -DCONFIG_BATMAN_DEBUG

The additional debug output is by default disabled. It can be enabled
either at kernel modules load time or during run time. To enable debug
output at module load time, add the module parameter debug=<value>.
<value> can take one of four values.

0 - All debug output disabled
1 - Enable messages related to routing / flooding / broadcasting
2 - Enable route or hna added / changed / deleted
3 - Enable all messages

e.g.

modprobe batman-adv debug=2

will load the module and enable debug messages for when routes or HNAs
change.

The debug output can also be changed at runtime using the file
/sys/module/batman-adv/parameters/debug. e.g.

echo 2 > /sys/module/batman-adv/parameters/debug

enables debug messages for when routes or HNAs

The debug output is sent to the kernel logs. So try dmesg, logread etc
to see the debug messages.

BATCTL
------

Expand Down
15 changes: 7 additions & 8 deletions drivers/staging/batman-adv/bitarray.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "main.h"
#include "bitarray.h"
#include "log.h"

/* returns true if the corresponding bit in the given seq_bits indicates true
* and curr_seqno is within range of last_seqno */
Expand Down Expand Up @@ -80,8 +79,8 @@ void bit_shift(TYPE_OF_WORD *seq_bits, int32_t n)
* from.
*
* left is high, right is low: FEDC BA98 7654 3210
* ^^ ^^
* vvvv
* ^^ ^^
* vvvv
* ^^^^ = from, vvvvv =to, we'd have word_num==1 and
* word_offset==WORD_BIT_SIZE/2 ????? in this example.
* (=24 bits)
Expand Down Expand Up @@ -133,13 +132,13 @@ char bit_get_packet(TYPE_OF_WORD *seq_bits, int16_t seq_num_diff,
(seq_num_diff < -TQ_LOCAL_WINDOW_SIZE)) {

if (seq_num_diff > TQ_LOCAL_WINDOW_SIZE)
debug_log(LOG_TYPE_BATMAN,
"We missed a lot of packets (%i) !\n",
seq_num_diff-1);
bat_dbg(DBG_BATMAN,
"We missed a lot of packets (%i) !\n",
seq_num_diff-1);

if (-seq_num_diff > TQ_LOCAL_WINDOW_SIZE)
debug_log(LOG_TYPE_BATMAN,
"Other host probably restarted !\n");
bat_dbg(DBG_BATMAN,
"Other host probably restarted !\n");

for (i = 0; i < NUM_WORDS; i++)
seq_bits[i] = 0;
Expand Down
13 changes: 6 additions & 7 deletions drivers/staging/batman-adv/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "main.h"
#include "device.h"
#include "log.h"
#include "send.h"
#include "types.h"
#include "hash.h"
Expand Down Expand Up @@ -60,15 +59,15 @@ int bat_device_setup(void)
/* register our device - kernel assigns a free major number */
tmp_major = register_chrdev(0, DRIVER_DEVICE, &fops);
if (tmp_major < 0) {
debug_log(LOG_TYPE_WARN, "Registering the character device failed with %d\n",
printk(KERN_ERR "batman-adv:Registering the character device failed with %d\n",
tmp_major);
return 0;
}

batman_class = class_create(THIS_MODULE, "batman-adv");

if (IS_ERR(batman_class)) {
debug_log(LOG_TYPE_WARN, "Could not register class 'batman-adv' \n");
printk(KERN_ERR "batman-adv:Could not register class 'batman-adv' \n");
return 0;
}

Expand Down Expand Up @@ -111,7 +110,7 @@ int bat_device_open(struct inode *inode, struct file *file)
}

if (device_client_hash[i] != device_client) {
debug_log(LOG_TYPE_WARN, "Error - can't add another packet client: maximum number of clients reached \n");
printk(KERN_ERR "batman-adv:Error - can't add another packet client: maximum number of clients reached \n");
kfree(device_client);
return -EXFULL;
}
Expand Down Expand Up @@ -208,7 +207,7 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,
struct batman_if *batman_if;

if (len < sizeof(struct icmp_packet)) {
debug_log(LOG_TYPE_NOTICE, "Error - can't send packet from char device: invalid packet size\n");
printk(KERN_DEBUG "batman-adv:Error - can't send packet from char device: invalid packet size\n");
return -EINVAL;
}

Expand All @@ -219,12 +218,12 @@ ssize_t bat_device_write(struct file *file, const char __user *buff,
return -EFAULT;

if (icmp_packet.packet_type != BAT_ICMP) {
debug_log(LOG_TYPE_NOTICE, "Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
printk(KERN_DEBUG "batman-adv:Error - can't send packet from char device: got bogus packet type (expected: BAT_ICMP)\n");
return -EINVAL;
}

if (icmp_packet.msg_type != ECHO_REQUEST) {
debug_log(LOG_TYPE_NOTICE, "Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n");
printk(KERN_DEBUG "batman-adv:Error - can't send packet from char device: got bogus message type (expected: ECHO_REQUEST)\n");
return -EINVAL;
}

Expand Down
36 changes: 17 additions & 19 deletions drivers/staging/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@

#include "main.h"
#include "hard-interface.h"
#include "log.h"
#include "soft-interface.h"
#include "send.h"
#include "translation-table.h"
Expand Down Expand Up @@ -87,9 +86,9 @@ static void check_known_mac_addr(uint8_t *addr)
continue;

addr_to_string(mac_string, addr);
debug_log(LOG_TYPE_WARN, "The newly added mac address (%s) already exists on: %s\n",
mac_string, batman_if->dev);
debug_log(LOG_TYPE_WARN, "It is strongly recommended to keep mac addresses unique to avoid problems!\n");
printk(KERN_WARNING "batman-adv:The newly added mac address (%s) already exists on: %s\n",
mac_string, batman_if->dev);
printk(KERN_WARNING "batman-adv:It is strongly recommended to keep mac addresses unique to avoid problems!\n");
}
rcu_read_unlock();
}
Expand Down Expand Up @@ -171,8 +170,8 @@ void hardif_deactivate_interface(struct batman_if *batman_if)
batman_if->if_active = IF_INACTIVE;
active_ifs--;

debug_log(LOG_TYPE_NOTICE, "Interface deactivated: %s\n",
batman_if->dev);
printk(KERN_INFO "batman-adv:Interface deactivated: %s\n",
batman_if->dev);
}

/* (re)activate given interface. */
Expand All @@ -197,7 +196,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
&batman_if->raw_sock);

if (retval < 0) {
debug_log(LOG_TYPE_WARN, "Can't create raw socket: %i\n",
printk(KERN_ERR "batman-adv:Can't create raw socket: %i\n",
retval);
goto sock_err;
}
Expand All @@ -210,7 +209,7 @@ static void hardif_activate_interface(struct batman_if *batman_if)
(struct sockaddr *)&bind_addr, sizeof(bind_addr));

if (retval < 0) {
debug_log(LOG_TYPE_WARN, "Can't create bind raw socket: %i\n",
printk(KERN_ERR "batman-adv:Can't create bind raw socket: %i\n",
retval);
goto bind_err;
}
Expand All @@ -235,8 +234,8 @@ static void hardif_activate_interface(struct batman_if *batman_if)
if (batman_if->if_num == 0)
set_main_if_addr(batman_if->net_dev->dev_addr);

debug_log(LOG_TYPE_NOTICE, "Interface activated: %s\n",
batman_if->dev);
printk(KERN_INFO "batman-adv:Interface activated: %s\n",
batman_if->dev);

return;

Expand Down Expand Up @@ -290,7 +289,7 @@ static int resize_orig(struct orig_node *orig_node, int if_num)
data_ptr = kmalloc((if_num + 1) * sizeof(TYPE_OF_WORD) * NUM_WORDS,
GFP_ATOMIC);
if (!data_ptr) {
debug_log(LOG_TYPE_WARN, "Can't resize orig: out of memory\n");
printk(KERN_ERR "batman-adv:Can't resize orig: out of memory\n");
return -1;
}

Expand All @@ -301,7 +300,7 @@ static int resize_orig(struct orig_node *orig_node, int if_num)

data_ptr = kmalloc((if_num + 1) * sizeof(uint8_t), GFP_ATOMIC);
if (!data_ptr) {
debug_log(LOG_TYPE_WARN, "Can't resize orig: out of memory\n");
printk(KERN_ERR "batman-adv:Can't resize orig: out of memory\n");
return -1;
}

Expand All @@ -324,7 +323,7 @@ int hardif_add_interface(char *dev, int if_num)
batman_if = kmalloc(sizeof(struct batman_if), GFP_KERNEL);

if (!batman_if) {
debug_log(LOG_TYPE_WARN, "Can't add interface (%s): out of memory\n", dev);
printk(KERN_ERR "batman-adv:Can't add interface (%s): out of memory\n", dev);
return -1;
}

Expand All @@ -339,7 +338,7 @@ int hardif_add_interface(char *dev, int if_num)
batman_if->packet_buff = kmalloc(batman_if->packet_len, GFP_KERNEL);

if (!batman_if->packet_buff) {
debug_log(LOG_TYPE_WARN, "Can't add interface packet (%s): out of memory\n", dev);
printk(KERN_ERR "batman-adv:Can't add interface packet (%s): out of memory\n", dev);
goto out;
}

Expand All @@ -348,7 +347,7 @@ int hardif_add_interface(char *dev, int if_num)
batman_if->if_active = IF_INACTIVE;
INIT_RCU_HEAD(&batman_if->rcu);

debug_log(LOG_TYPE_NOTICE, "Adding interface: %s\n", dev);
printk(KERN_INFO "batman-adv:Adding interface: %s\n", dev);
avail_ifs++;

INIT_LIST_HEAD(&batman_if->list);
Expand Down Expand Up @@ -389,7 +388,7 @@ int hardif_add_interface(char *dev, int if_num)
spin_unlock(&orig_hash_lock);

if (!hardif_is_interface_up(batman_if->dev))
debug_log(LOG_TYPE_WARN, "Not using interface %s (retrying later): interface not active\n", batman_if->dev);
printk(KERN_ERR "batman-adv:Not using interface %s (retrying later): interface not active\n", batman_if->dev);
else
hardif_activate_interface(batman_if);

Expand All @@ -413,7 +412,7 @@ char hardif_get_active_if_num(void)
}

static int hard_if_event(struct notifier_block *this,
unsigned long event, void *ptr)
unsigned long event, void *ptr)
{
struct net_device *dev = (struct net_device *)ptr;
struct batman_if *batman_if = get_batman_if_by_name(dev->name);
Expand All @@ -436,7 +435,6 @@ static int hard_if_event(struct notifier_block *this,
break;
/* NETDEV_CHANGEADDR - mac address change - what are we doing here ? */
default:
/* debug_log(LOG_TYPE_CRIT, "hard_if_event: %s %i\n", dev->name, event); */
break;
};

Expand All @@ -447,5 +445,5 @@ static int hard_if_event(struct notifier_block *this,
}

struct notifier_block hard_if_notifier = {
.notifier_call = hard_if_event,
.notifier_call = hard_if_event,
};
Loading

0 comments on commit bad2239

Please sign in to comment.