Skip to contentSkip to conversation

batman-adv: Use kernel version min macro

PATCH Applied Sven Eckelmann 3 participants 7 messages Nov 8, 2010 – Nov 17, 2010

lore
Share & tools
lore
#0 lore raw

PATCH 1/2 batman-adv: Use kernel version min macro

The kernel headers already provide different versions of a min/max macro which should be used by all modules according to Documentation/CodingStyle.

---
 batman-adv/hard-interface.c |    6 ++----
 1 files changed, 2 insertions(+), 4 deletions(-)
batman-adv/hard-interface.c +2 -4
index 5a1d631..e22f0dd 100644
@@ -31,8 +31,6 @@
 
 #include <linux/if_arp.h>
 
-#define MIN(x, y) ((x) < (y) ? (x) : (y))
-
 /* protect update critical side of if_list - but not the content */
 static DEFINE_SPINLOCK(if_list_lock);
 
@@ -220,8 +218,8 @@ int hardif_min_mtu(struct net_device *soft_iface)
 		if (batman_if->soft_iface != soft_iface)
 			continue;
 
-		min_mtu = MIN(batman_if->net_dev->mtu - BAT_HEADER_LEN,
-			      min_mtu);
+		min_mtu = min_t(int, batman_if->net_dev->mtu - BAT_HEADER_LEN,
+				min_mtu);
 	}
 	rcu_read_unlock();
 out:
Signature · 1 line
1.7.2.3
#1 lore raw

PATCH 2/2 batman-adv: Use kernel functions to identify broadcasts

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 can also be removed because is_multicast_ether_addr was only used together with is_broadcast_ether_addr and 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]

---
 batman-adv/main.c           |   10 ----------
 batman-adv/main.h           |    3 +--
 batman-adv/routing.c        |   16 ++++++++--------
 batman-adv/soft-interface.c |    2 +-
 batman-adv/unicast.c        |    2 +-
 batman-adv/vis.c            |    4 ++--
 6 files changed, 13 insertions(+), 24 deletions(-)
batman-adv/main.c +0 -10
index c91e635..b827f6a 100644
@@ -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);
 
batman-adv/main.h +1 -2
index 519d3b0..a362433 100644
@@ -112,6 +112,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 */
@@ -141,8 +142,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, ...);
batman-adv/routing.c +8 -8
index 9f31167..d8b0c5a 100644
@@ -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. */
@@ -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 */
@@ -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 */
@@ -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 */
batman-adv/soft-interface.c +1 -1
index 1e55bdb..405d96e 100644
@@ -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_broadcast_ether_addr(ethhdr->h_dest)) {
 		ret = gw_is_target(bat_priv, skb);
 
 		if (ret < 0)
batman-adv/unicast.c +1 -1
index 7b9385b..15d676f 100644
@@ -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_broadcast_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,
batman-adv/vis.c +2 -2
index 65676dc..957a086 100644
@@ -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? */
@@ -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);
Signature · 1 line
1.7.2.3
#2 lore raw

Re: [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: Use kernel functions to identify broadcasts

Quoted 6 lines

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]

[...]

batman-adv/soft-interface.c int interface_tx(struct sk_buff *skb, struct net_device *soft_iface) · line 382

Quoted 3 lines
batman-adv/soft-interface.c +1 -1
-	if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest)) {
+	if (is_broadcast_ether_addr(ethhdr->h_dest)) {
 		ret = gw_is_target(bat_priv, skb);

So, shouldn't that be the other way round?
is_multicast_ether_addr() instead?

Cheers,
Linus

#3 lore raw

Re: [B.A.T.M.A.N.] [PATCH 2/2] batman-adv: Use kernel functions to identify broadcasts

Quoted 9 lines · Linus Lüssing
Quoted 6 lines

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]

[...]

Quoted 7 lines

batman-adv/soft-interface.c int interface_tx(struct sk_buff *skb, struct net_device *soft_iface)

Quoted 4 lines
batman-adv/soft-interface.c +1 -1
-	if (is_bcast(ethhdr->h_dest) || is_mcast(ethhdr->h_dest)) {
+	if (is_broadcast_ether_addr(ethhdr->h_dest)) {
 
 		ret = gw_is_target(bat_priv, skb);

So, shouldn't that be the other way round?
is_multicast_ether_addr() instead?

Correct.

Best regards,
Sven

#4 lore raw

PATCH v2 2/2 batman-adv: Use kernel functions to identify broadcasts

In reply to Sven Eckelmann

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]

---
tklauser: Please tell us how you want to handle that patch. If you want resend yours or if it would be ok to use this patch - or maybe a third option.

 batman-adv/main.c           |   10 ----------
 batman-adv/main.h           |    3 +--
 batman-adv/routing.c        |   16 ++++++++--------
 batman-adv/soft-interface.c |    2 +-
 batman-adv/unicast.c        |    2 +-
 batman-adv/vis.c            |    4 ++--
 6 files changed, 13 insertions(+), 24 deletions(-)
batman-adv/main.c +0 -10
index c91e635..b827f6a 100644
@@ -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);
 
batman-adv/main.h +1 -2
index 519d3b0..a362433 100644
@@ -112,6 +112,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 */
@@ -141,8 +142,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, ...);
batman-adv/routing.c +8 -8
index 9f31167..d8b0c5a 100644
@@ -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. */
@@ -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 */
@@ -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 */
@@ -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 */
batman-adv/soft-interface.c +1 -1
index 1e55bdb..e93a99f 100644
@@ -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)
batman-adv/unicast.c +1 -1
index 7b9385b..dc2e28b 100644
@@ -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,
batman-adv/vis.c +2 -2
index 65676dc..957a086 100644
@@ -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? */
@@ -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);
Signature · 1 line
1.7.2.3
#5 lore raw

Re: [B.A.T.M.A.N.] [PATCHv2 2/2] batman-adv: Use kernel functions to identify broadcasts

Quoted 3 lines · On Tuesday 09 November 2010 10:27:28 Sven Eckelmann wrote:

linux/etherdevice.h already provides functions to classify different ethernet addresses. These inlineable functions should be used instead of custom functions.

Applied in revision 1873.

Thanks,
Marek

#6 lore raw
In reply to Sven Eckelmann
Quoted 3 lines · On Tuesday 09 November 2010 00:53:00 Sven Eckelmann wrote:

The kernel headers already provide different versions of a min/max macro which should be used by all modules according to Documentation/CodingStyle.

Applied in revision 1872.

Thanks,
Marek