Skip to content

Commit

Permalink
Staging: batman-adv: Use kernel functions to identify broadcasts
Browse files Browse the repository at this point in the history
linux/etherdevice.h already provides functions to classify different
ethernet addresses. These inlineable functions should be used instead of
custom functions.

The check for multicast together with multicast can also be replaced
with a single test for multicast because for every ethernet address x
following is always true:

is_broadcast_ether_addr(x) => is_multicast_ether_addr(x)

or when looking more at the implementation:

(FF:FF:FF:FF:FF:FF == x) => [(01:00:00:00:00:00 & x) != 00:00:00:00:00:00]

Reported-by: Tobias Klauser <tklauser@distanz.ch>
Signed-off-by: Sven Eckelmann <sven.eckelmann@gmx.de>
Signed-off-by: Greg Kroah-Hartman <gregkh@suse.de>
  • Loading branch information
Sven Eckelmann authored and Greg Kroah-Hartman committed Nov 29, 2010
1 parent 8cab2fb commit 951c44e
Show file tree
Hide file tree
Showing 6 changed files with 13 additions and 24 deletions.
10 changes: 0 additions & 10 deletions drivers/staging/batman-adv/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -172,16 +172,6 @@ int is_my_mac(uint8_t *addr)

}

int is_bcast(uint8_t *addr)
{
return (addr[0] == (uint8_t)0xff) && (addr[1] == (uint8_t)0xff);
}

int is_mcast(uint8_t *addr)
{
return *addr & 0x01;
}

module_init(batman_init);
module_exit(batman_exit);

Expand Down
3 changes: 1 addition & 2 deletions drivers/staging/batman-adv/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@
#include <linux/mutex.h> /* mutex */
#include <linux/module.h> /* needed by all modules */
#include <linux/netdevice.h> /* netdevice */
#include <linux/etherdevice.h> /* ethernet address classifaction */
#include <linux/if_ether.h> /* ethernet header */
#include <linux/poll.h> /* poll_table */
#include <linux/kthread.h> /* kernel threads */
Expand Down Expand Up @@ -136,8 +137,6 @@ void mesh_free(struct net_device *soft_iface);
void inc_module_count(void);
void dec_module_count(void);
int is_my_mac(uint8_t *addr);
int is_bcast(uint8_t *addr);
int is_mcast(uint8_t *addr);

#ifdef CONFIG_BATMAN_ADV_DEBUG
int debug_log(struct bat_priv *bat_priv, char *fmt, ...);
Expand Down
16 changes: 8 additions & 8 deletions drivers/staging/batman-adv/routing.c
Original file line number Diff line number Diff line change
Expand Up @@ -770,11 +770,11 @@ int recv_bat_packet(struct sk_buff *skb, struct batman_if *batman_if)
ethhdr = (struct ethhdr *)skb_mac_header(skb);

/* packet with broadcast indication but unicast recipient */
if (!is_bcast(ethhdr->h_dest))
if (!is_broadcast_ether_addr(ethhdr->h_dest))
return NET_RX_DROP;

/* packet with broadcast sender address */
if (is_bcast(ethhdr->h_source))
if (is_broadcast_ether_addr(ethhdr->h_source))
return NET_RX_DROP;

/* create a copy of the skb, if needed, to modify it. */
Expand Down Expand Up @@ -946,11 +946,11 @@ int recv_icmp_packet(struct sk_buff *skb, struct batman_if *recv_if)
ethhdr = (struct ethhdr *)skb_mac_header(skb);

/* packet with unicast indication but broadcast recipient */
if (is_bcast(ethhdr->h_dest))
if (is_broadcast_ether_addr(ethhdr->h_dest))
return NET_RX_DROP;

/* packet with broadcast sender address */
if (is_bcast(ethhdr->h_source))
if (is_broadcast_ether_addr(ethhdr->h_source))
return NET_RX_DROP;

/* not for me */
Expand Down Expand Up @@ -1118,11 +1118,11 @@ static int check_unicast_packet(struct sk_buff *skb, int hdr_size)
ethhdr = (struct ethhdr *)skb_mac_header(skb);

/* packet with unicast indication but broadcast recipient */
if (is_bcast(ethhdr->h_dest))
if (is_broadcast_ether_addr(ethhdr->h_dest))
return -1;

/* packet with broadcast sender address */
if (is_bcast(ethhdr->h_source))
if (is_broadcast_ether_addr(ethhdr->h_source))
return -1;

/* not for me */
Expand Down Expand Up @@ -1282,11 +1282,11 @@ int recv_bcast_packet(struct sk_buff *skb, struct batman_if *recv_if)
ethhdr = (struct ethhdr *)skb_mac_header(skb);

/* packet with broadcast indication but unicast recipient */
if (!is_bcast(ethhdr->h_dest))
if (!is_broadcast_ether_addr(ethhdr->h_dest))
return NET_RX_DROP;

/* packet with broadcast sender address */
if (is_bcast(ethhdr->h_source))
if (is_broadcast_ether_addr(ethhdr->h_source))
return NET_RX_DROP;

/* ignore broadcasts sent by myself */
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/batman-adv/soft-interface.c
Original file line number Diff line number Diff line change
Expand Up @@ -378,7 +378,7 @@ int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)
/* TODO: check this for locks */
hna_local_add(soft_iface, ethhdr->h_source);

if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest)) {
if (is_multicast_ether_addr(ethhdr->h_dest)) {
ret = gw_is_target(bat_priv, skb);

if (ret < 0)
Expand Down
2 changes: 1 addition & 1 deletion drivers/staging/batman-adv/unicast.c
Original file line number Diff line number Diff line change
Expand Up @@ -283,7 +283,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
spin_lock_bh(&bat_priv->orig_hash_lock);

/* get routing information */
if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest))
if (is_multicast_ether_addr(ethhdr->h_dest))
orig_node = (struct orig_node *)gw_get_selected(bat_priv);
else
orig_node = ((struct orig_node *)hash_find(bat_priv->orig_hash,
Expand Down
4 changes: 2 additions & 2 deletions drivers/staging/batman-adv/vis.c
Original file line number Diff line number Diff line change
Expand Up @@ -472,7 +472,7 @@ void receive_client_update_packet(struct bat_priv *bat_priv,
int are_target = 0;

/* clients shall not broadcast. */
if (is_bcast(vis_packet->target_orig))
if (is_broadcast_ether_addr(vis_packet->target_orig))
return;

/* Are we the target for this VIS packet? */
Expand Down Expand Up @@ -755,7 +755,7 @@ static void send_vis_packet(struct bat_priv *bat_priv, struct vis_info *info)
ETH_ALEN);
packet->ttl--;

if (is_bcast(packet->target_orig))
if (is_broadcast_ether_addr(packet->target_orig))
broadcast_vis_packet(bat_priv, info);
else
unicast_vis_packet(bat_priv, info);
Expand Down

0 comments on commit 951c44e

Please sign in to comment.