Skip to contentSkip to conversation

eth_hdr/skb_reset_mac_header changes

B.A.T.M.A.N. Superseded Linus Lüssing 2 participants 4 messages Jan 18, 2014 – Jan 19, 2014

v5 of 6 Superseded Latest is v6 →

lore
Share & tools
lore
#0 lore raw

Changes v5:

Added Antonio's simpler compat code suggestion (thanks!)

#1 lore raw

PATCH v5 1/2 batman-adv: use eth_hdr() instead of skb->data in interface_tx path

Our .ndo_start_xmit handler (batadv_interface_tx()) can rely on having the skb ether header pointer set correctly since the following commit present in kernels >= 3.9:

"net: reset mac header in dev_start_xmit()" (6d1ccff627)

Therefore we can safely use eth_hdr() instead of skb->data now, which spares us some ugly type casts.

---
 compat.h         |   11 +++++++++++
 soft-interface.c |    6 +++---
 2 files changed, 14 insertions(+), 3 deletions(-)
compat.h +11 -0
index 57c9d96..9692ed2 100644
@@ -302,6 +302,17 @@ static int batadv_interface_set_mac_addr(struct net_device *dev, void *p) \
 }\
 static int __batadv_interface_set_mac_addr(x, y)
 
+#define batadv_interface_tx(x, y) \
+__batadv_interface_tx(struct sk_buff *skb, struct net_device *soft_iface); \
+static int batadv_interface_tx(struct sk_buff *skb, \
+			       struct net_device *soft_iface) \
+{ \
+	skb_reset_mac_header(skb); \
+	return __batadv_interface_tx(skb, soft_iface); \
+} \
+static int __batadv_interface_tx(struct sk_buff *skb, \
+				 struct net_device *soft_iface)
+
 #define netdev_master_upper_dev_link netdev_set_master
 #define netdev_upper_dev_unlink(slave, master) netdev_set_master(slave, NULL)
 #define netdev_master_upper_dev_get(dev) \
soft-interface.c +3 -3
index f82c267..66903a1 100644
@@ -176,7 +176,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
 
 	soft_iface->trans_start = jiffies;
 	vid = batadv_get_vid(skb, 0);
-	ethhdr = (struct ethhdr *)skb->data;
+	ethhdr = eth_hdr(skb);
 
 	switch (ntohs(ethhdr->h_proto)) {
 	case ETH_P_8021Q:
@@ -194,7 +194,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
 		goto dropped;
 
 	/* skb->data might have been reallocated by batadv_bla_tx() */
-	ethhdr = (struct ethhdr *)skb->data;
+	ethhdr = eth_hdr(skb);
 
 	/* Register the client MAC in the transtable */
 	if (!is_multicast_ether_addr(ethhdr->h_source)) {
@@ -230,7 +230,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
 		/* skb->data may have been modified by
 		 * batadv_gw_dhcp_recipient_get()
 		 */
-		ethhdr = (struct ethhdr *)skb->data;
+		ethhdr = eth_hdr(skb);
 		/* if gw_mode is on, broadcast any non-DHCP message.
 		 * All the DHCP packets are going to be sent as unicast
 		 */
Signature · 1 line
1.7.10.4
#3 lore raw

PATCH v5 2/2 batman-adv: remove obsolete skb_reset_mac_header() in batadv_bla_tx()

In reply to Linus Lüssing

Our .ndo_start_xmit handler (batadv_interface_tx()) can rely on having the skb ether header pointer set correctly since the following commit present in kernels >= 3.9:

"net: reset mac header in dev_start_xmit()" (6d1ccff627)

Therefore this commit removes the according, now redundant, skb_reset_mac_header() call in batadv_bla_tx().

---
 bridge_loop_avoidance.c |    3 ---
 1 file changed, 3 deletions(-)
bridge_loop_avoidance.c +0 -3
index 5c0eda4..26ec489 100644
@@ -1535,9 +1535,6 @@ int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb,
 	if (!atomic_read(&bat_priv->bridge_loop_avoidance))
 		goto allow;
 
-	/* in VLAN case, the mac header might not be set. */
-	skb_reset_mac_header(skb);
-
 	if (batadv_bla_process_claim(bat_priv, primary_if, skb))
 		goto handled;
 
Signature · 1 line
1.7.10.4
#2 lore raw

Re: [B.A.T.M.A.N.] [PATCHv5 1/2] batman-adv: use eth_hdr() instead of skb->data in interface_tx path

In reply to Linus Lüssing
Quoted 10 lines · Linus Lüssing

Our .ndo_start_xmit handler (batadv_interface_tx()) can rely on having the skb ether header pointer set correctly since the following commit present in kernels >= 3.9:

"net: reset mac header in dev_start_xmit()" (6d1ccff627)

Therefore we can safely use eth_hdr() instead of skb->data now, which spares us some ugly type casts.

Linus,

in interface_tx() we also have an assignment for vlan_hdr getting the value of skb->data as well.

Would you mind switching it to vlan_eth_hdr() ?

Maybe you can have a quick look whether there are other occurrences to change within interface_tx()?

Cheers,

Signature · 1 line
Antonio Quartulli