Skip to content

Commit

Permalink
Staging: batman-adv: Use printk(%pM) for MAC addresses
Browse files Browse the repository at this point in the history
printk() since kernel version 2.6.29 has supported printing MAC
addresses directly, as an extension to the %p processing. This patch
makes use of this for printk() and bat_dbg(). This will remove the
overhead of using addr_to_string() which is normally never actually
output.

Fixed a typo found by Gus Wirth.

Signed-off-by: Andrew Lunn <andrew@lunn.ch>
Signed-off-by: Simon Wunderlich <siwu@hrz.tu-chemnitz.de>
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 a9c2910 commit b9b27e4
Show file tree
Hide file tree
Showing 9 changed files with 111 additions and 121 deletions.
4 changes: 0 additions & 4 deletions drivers/staging/batman-adv/TODO
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,6 @@
-> transtable_global (read-only) [outputs the global translation table]
-> transtable_local (read-only) [outputs the local translation table]

=> logging
* make use of printk %pM support instead of converting mac addresses
* manually

=> strip out all backward compatibility support to older kernels
(only found in compat.h)

Expand Down
82 changes: 64 additions & 18 deletions drivers/staging/batman-adv/compat.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,41 +35,87 @@
#define list_first_entry(ptr, type, member) \
list_entry((ptr)->next, type, member)

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 22) */
#define skb_mac_header(_skb) \
((_skb)->mac.raw)

#define skb_network_header(_skb) \
((_skb)->nh.raw)

#define skb_mac_header(_skb) \
((_skb)->mac.raw)

#endif /* < KERNEL_VERSION(2,6,22) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)

static inline int skb_clone_writable(struct sk_buff *skb, unsigned int len)
{
/* skb->hdr_len not available, just "not writable" to enforce a copy */
return 0;
}

#define cancel_delayed_work_sync(wq) cancel_rearming_delayed_work(wq)

#endif /* < KERNEL_VERSION(2, 6, 23) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)

#define strict_strtoul(cp, base, res) \
({ \
int ret = 0; \
char *endp; \
*res = simple_strtoul(cp, &endp, base); \
if (cp == endp) \
ret = -EINVAL; \
ret; \
})

#endif /* < KERNEL_VERSION(2, 6, 25) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26)

static const char hex_asc[] = "0123456789abcdef";
#define hex_asc_lo(x) hex_asc[((x) & 0x0f)]
#define hex_asc_hi(x) hex_asc[((x) & 0xf0) >> 4]
static inline char *pack_hex_byte(char *buf, u8 byte)
{
*buf++ = hex_asc_hi(byte);
*buf++ = hex_asc_lo(byte);
return buf;
}

#define device_create(_cls, _parent, _devt, _device, _fmt) \
class_device_create(_cls, _parent, _devt, _device, _fmt)

#define device_destroy(_cls, _device) \
class_device_destroy(_cls, _device)

#else
#endif /* < KERNEL_VERSION(2, 6, 26) */

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27)

#ifndef dereference_function_descriptor
#define dereference_function_descriptor(p) (p)
#endif

#ifndef device_create
#define device_create(_cls, _parent, _devt, _device, _fmt) \
device_create_drvdata(_cls, _parent, _devt, _device, _fmt)
#endif

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 27) */
#endif /* < KERNEL_VERSION(2, 6, 27) */

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 26) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 29)

#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23)
asmlinkage int bat_printk(const char *fmt, ...);
#define printk bat_printk

#define cancel_delayed_work_sync(wq) cancel_rearming_delayed_work(wq)
static inline struct net_device_stats *dev_get_stats(struct net_device *dev)
{
if (dev->get_stats)
return dev->get_stats(dev);
else
return NULL;
}

#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 23) */
#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25)
#define strict_strtoul(cp, base, res) \
({ \
int ret = 0; \
char *endp; \
*res = simple_strtoul(cp, &endp, base); \
if (cp == endp) \
ret = -EINVAL; \
ret; \
})
#endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 25) */
#endif /* < KERNEL_VERSION(2, 6, 29) */
1 change: 1 addition & 0 deletions drivers/staging/batman-adv/device.c
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
*
*/

#include <linux/device.h>
#include "main.h"
#include "device.h"
#include "send.h"
Expand Down
14 changes: 7 additions & 7 deletions drivers/staging/batman-adv/hard-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,6 @@ int hardif_min_mtu(void)
static void check_known_mac_addr(uint8_t *addr)
{
struct batman_if *batman_if;
char mac_string[ETH_STR_LEN];

rcu_read_lock();
list_for_each_entry_rcu(batman_if, &if_list, list) {
Expand All @@ -85,9 +84,8 @@ static void check_known_mac_addr(uint8_t *addr)
if (!compare_orig(batman_if->net_dev->dev_addr, addr))
continue;

addr_to_string(mac_string, addr);
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:The newly added mac address (%pM) already exists on: %s\n",
addr, 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 @@ -447,9 +445,11 @@ int batman_skb_recv(struct sk_buff *skb, struct net_device *dev,
if (!batman_if)
goto err_free;

stats = &skb->dev->stats;
stats->rx_packets++;
stats->rx_bytes += skb->len;
stats = (struct net_device_stats *) dev_get_stats(skb->dev);
if (stats) {
stats->rx_packets++;
stats->rx_bytes += skb->len;
}

batman_packet = (struct batman_packet *)skb->data;

Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ unsigned char broadcastAddr[] = {0xff, 0xff, 0xff, 0xff, 0xff, 0xff};
atomic_t module_state;

static struct packet_type batman_adv_packet_type __read_mostly = {
.type = cpu_to_be16(ETH_P_BATMAN),
.type = __constant_htons(ETH_P_BATMAN),
.func = batman_skb_recv,
};

Expand Down
17 changes: 5 additions & 12 deletions drivers/staging/batman-adv/originator.c
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@
#include "hash.h"
#include "translation-table.h"
#include "routing.h"
#include "compat.h"


static DECLARE_DELAYED_WORK(purge_orig_wq, purge_orig);
Expand Down Expand Up @@ -121,16 +122,14 @@ struct orig_node *get_orig_node(uint8_t *addr)
{
struct orig_node *orig_node;
struct hashtable_t *swaphash;
char orig_str[ETH_STR_LEN];
int size;

orig_node = ((struct orig_node *)hash_find(orig_hash, addr));

if (orig_node != NULL)
return orig_node;

addr_to_string(orig_str, addr);
bat_dbg(DBG_BATMAN, "Creating new originator: %s \n", orig_str);
bat_dbg(DBG_BATMAN, "Creating new originator: %pM \n", addr);

orig_node = kmalloc(sizeof(struct orig_node), GFP_ATOMIC);
if (!orig_node)
Expand Down Expand Up @@ -186,7 +185,6 @@ static bool purge_orig_neighbors(struct orig_node *orig_node,
struct neigh_node **best_neigh_node)
{
struct list_head *list_pos, *list_pos_tmp;
char neigh_str[ETH_STR_LEN], orig_str[ETH_STR_LEN];
struct neigh_node *neigh_node;
bool neigh_purged = false;

Expand All @@ -201,9 +199,7 @@ static bool purge_orig_neighbors(struct orig_node *orig_node,
(neigh_node->last_valid +
((PURGE_TIMEOUT * HZ) / 1000)))) {

addr_to_string(neigh_str, neigh_node->addr);
addr_to_string(orig_str, orig_node->orig);
bat_dbg(DBG_BATMAN, "neighbor timeout: originator %s, neighbor: %s, last_valid %lu\n", orig_str, neigh_str, (neigh_node->last_valid / HZ));
bat_dbg(DBG_BATMAN, "neighbor timeout: originator %pM, neighbor: %pM, last_valid %lu\n", orig_node->orig, neigh_node->addr, (neigh_node->last_valid / HZ));

neigh_purged = true;
list_del(list_pos);
Expand All @@ -221,17 +217,14 @@ static bool purge_orig_neighbors(struct orig_node *orig_node,
static bool purge_orig_node(struct orig_node *orig_node)
{
struct neigh_node *best_neigh_node;
char orig_str[ETH_STR_LEN];

addr_to_string(orig_str, orig_node->orig);

if (time_after(jiffies,
(orig_node->last_valid +
((2 * PURGE_TIMEOUT * HZ) / 1000)))) {

bat_dbg(DBG_BATMAN,
"Originator timeout: originator %s, last_valid %lu\n",
orig_str, (orig_node->last_valid / HZ));
"Originator timeout: originator %pM, last_valid %lu\n",
orig_node->orig, (orig_node->last_valid / HZ));
return true;
} else {
if (purge_orig_neighbors(orig_node, &best_neigh_node))
Expand Down
Loading

0 comments on commit b9b27e4

Please sign in to comment.