Commit 7ed4be95 authored by Antonio Quartulli's avatar Antonio Quartulli

batman-adv: use eth_hdr() when it makes sense

Instead of casting the result of skb_mac_header() to
"struct ethhdr *" every time, the eth_hdr inline function
can be use to beautify the code and improve its readability.
Signed-off-by: default avatarAntonio Quartulli <ordex@autistici.org>
Signed-off-by: default avatarMarek Lindner <lindner_marek@yahoo.de>
parent 7db3fc29
...@@ -1268,7 +1268,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb, ...@@ -1268,7 +1268,7 @@ static int batadv_iv_ogm_receive(struct sk_buff *skb,
skb->len + ETH_HLEN); skb->len + ETH_HLEN);
packet_len = skb_headlen(skb); packet_len = skb_headlen(skb);
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
packet_buff = skb->data; packet_buff = skb->data;
batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff; batadv_ogm_packet = (struct batadv_ogm_packet *)packet_buff;
......
...@@ -864,7 +864,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ...@@ -864,7 +864,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
short vid = -1; short vid = -1;
int ret; int ret;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) { if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) {
vhdr = (struct vlan_ethhdr *)ethhdr; vhdr = (struct vlan_ethhdr *)ethhdr;
...@@ -885,7 +885,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv, ...@@ -885,7 +885,7 @@ static int batadv_bla_process_claim(struct batadv_priv *bat_priv,
return 0; return 0;
/* pskb_may_pull() may have modified the pointers, get ethhdr again */ /* pskb_may_pull() may have modified the pointers, get ethhdr again */
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
arphdr = (struct arphdr *)((uint8_t *)ethhdr + headlen); arphdr = (struct arphdr *)((uint8_t *)ethhdr + headlen);
/* Check whether the ARP frame carries a valid /* Check whether the ARP frame carries a valid
...@@ -1432,7 +1432,7 @@ int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid, ...@@ -1432,7 +1432,7 @@ int batadv_bla_rx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid,
struct batadv_hard_iface *primary_if; struct batadv_hard_iface *primary_if;
int ret; int ret;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
primary_if = batadv_primary_if_get_selected(bat_priv); primary_if = batadv_primary_if_get_selected(bat_priv);
if (!primary_if) if (!primary_if)
...@@ -1539,7 +1539,7 @@ int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid) ...@@ -1539,7 +1539,7 @@ int batadv_bla_tx(struct batadv_priv *bat_priv, struct sk_buff *skb, short vid)
if (batadv_bla_process_claim(bat_priv, primary_if, skb)) if (batadv_bla_process_claim(bat_priv, primary_if, skb))
goto handled; goto handled;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
if (unlikely(atomic_read(&bat_priv->bla.num_requests))) if (unlikely(atomic_read(&bat_priv->bla.num_requests)))
/* don't allow broadcasts while requests are in flight */ /* don't allow broadcasts while requests are in flight */
......
...@@ -1245,7 +1245,7 @@ static void batadv_nc_skb_store_before_coding(struct batadv_priv *bat_priv, ...@@ -1245,7 +1245,7 @@ static void batadv_nc_skb_store_before_coding(struct batadv_priv *bat_priv,
return; return;
/* Set the mac header as if we actually sent the packet uncoded */ /* Set the mac header as if we actually sent the packet uncoded */
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
memcpy(ethhdr->h_source, ethhdr->h_dest, ETH_ALEN); memcpy(ethhdr->h_source, ethhdr->h_dest, ETH_ALEN);
memcpy(ethhdr->h_dest, eth_dst_new, ETH_ALEN); memcpy(ethhdr->h_dest, eth_dst_new, ETH_ALEN);
...@@ -1423,7 +1423,7 @@ void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv, ...@@ -1423,7 +1423,7 @@ void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv,
{ {
struct batadv_unicast_packet *packet; struct batadv_unicast_packet *packet;
struct batadv_nc_path *nc_path; struct batadv_nc_path *nc_path;
struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); struct ethhdr *ethhdr = eth_hdr(skb);
__be32 packet_id; __be32 packet_id;
u8 *payload; u8 *payload;
...@@ -1482,7 +1482,7 @@ void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv, ...@@ -1482,7 +1482,7 @@ void batadv_nc_skb_store_for_decoding(struct batadv_priv *bat_priv,
void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv, void batadv_nc_skb_store_sniffed_unicast(struct batadv_priv *bat_priv,
struct sk_buff *skb) struct sk_buff *skb)
{ {
struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); struct ethhdr *ethhdr = eth_hdr(skb);
if (batadv_is_my_mac(bat_priv, ethhdr->h_dest)) if (batadv_is_my_mac(bat_priv, ethhdr->h_dest))
return; return;
...@@ -1533,7 +1533,7 @@ batadv_nc_skb_decode_packet(struct batadv_priv *bat_priv, struct sk_buff *skb, ...@@ -1533,7 +1533,7 @@ batadv_nc_skb_decode_packet(struct batadv_priv *bat_priv, struct sk_buff *skb,
skb_reset_network_header(skb); skb_reset_network_header(skb);
/* Reconstruct original mac header */ /* Reconstruct original mac header */
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
memcpy(ethhdr, &ethhdr_tmp, sizeof(*ethhdr)); memcpy(ethhdr, &ethhdr_tmp, sizeof(*ethhdr));
/* Select the correct unicast header information based on the location /* Select the correct unicast header information based on the location
...@@ -1677,7 +1677,7 @@ static int batadv_nc_recv_coded_packet(struct sk_buff *skb, ...@@ -1677,7 +1677,7 @@ static int batadv_nc_recv_coded_packet(struct sk_buff *skb,
return NET_RX_DROP; return NET_RX_DROP;
coded_packet = (struct batadv_coded_packet *)skb->data; coded_packet = (struct batadv_coded_packet *)skb->data;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* Verify frame is destined for us */ /* Verify frame is destined for us */
if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest) && if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest) &&
......
...@@ -256,7 +256,7 @@ bool batadv_check_management_packet(struct sk_buff *skb, ...@@ -256,7 +256,7 @@ bool batadv_check_management_packet(struct sk_buff *skb,
if (unlikely(!pskb_may_pull(skb, header_len))) if (unlikely(!pskb_may_pull(skb, header_len)))
return false; return false;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* packet with broadcast indication but unicast recipient */ /* packet with broadcast indication but unicast recipient */
if (!is_broadcast_ether_addr(ethhdr->h_dest)) if (!is_broadcast_ether_addr(ethhdr->h_dest))
...@@ -392,7 +392,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb, ...@@ -392,7 +392,7 @@ int batadv_recv_icmp_packet(struct sk_buff *skb,
if (unlikely(!pskb_may_pull(skb, hdr_size))) if (unlikely(!pskb_may_pull(skb, hdr_size)))
goto out; goto out;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* packet with unicast indication but broadcast recipient */ /* packet with unicast indication but broadcast recipient */
if (is_broadcast_ether_addr(ethhdr->h_dest)) if (is_broadcast_ether_addr(ethhdr->h_dest))
...@@ -569,7 +569,7 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv, ...@@ -569,7 +569,7 @@ static int batadv_check_unicast_packet(struct batadv_priv *bat_priv,
if (unlikely(!pskb_may_pull(skb, hdr_size))) if (unlikely(!pskb_may_pull(skb, hdr_size)))
return -ENODATA; return -ENODATA;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* packet with unicast indication but broadcast recipient */ /* packet with unicast indication but broadcast recipient */
if (is_broadcast_ether_addr(ethhdr->h_dest)) if (is_broadcast_ether_addr(ethhdr->h_dest))
...@@ -803,7 +803,7 @@ static int batadv_route_unicast_packet(struct sk_buff *skb, ...@@ -803,7 +803,7 @@ static int batadv_route_unicast_packet(struct sk_buff *skb,
struct batadv_orig_node *orig_node = NULL; struct batadv_orig_node *orig_node = NULL;
struct batadv_neigh_node *neigh_node = NULL; struct batadv_neigh_node *neigh_node = NULL;
struct batadv_unicast_packet *unicast_packet; struct batadv_unicast_packet *unicast_packet;
struct ethhdr *ethhdr = (struct ethhdr *)skb_mac_header(skb); struct ethhdr *ethhdr = eth_hdr(skb);
int ret = NET_RX_DROP; int ret = NET_RX_DROP;
struct sk_buff *new_skb; struct sk_buff *new_skb;
...@@ -1165,7 +1165,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb, ...@@ -1165,7 +1165,7 @@ int batadv_recv_bcast_packet(struct sk_buff *skb,
if (unlikely(!pskb_may_pull(skb, hdr_size))) if (unlikely(!pskb_may_pull(skb, hdr_size)))
goto out; goto out;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* packet with broadcast indication but unicast recipient */ /* packet with broadcast indication but unicast recipient */
if (!is_broadcast_ether_addr(ethhdr->h_dest)) if (!is_broadcast_ether_addr(ethhdr->h_dest))
...@@ -1265,7 +1265,7 @@ int batadv_recv_vis_packet(struct sk_buff *skb, ...@@ -1265,7 +1265,7 @@ int batadv_recv_vis_packet(struct sk_buff *skb,
return NET_RX_DROP; return NET_RX_DROP;
vis_packet = (struct batadv_vis_packet *)skb->data; vis_packet = (struct batadv_vis_packet *)skb->data;
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
/* not for me */ /* not for me */
if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest)) if (!batadv_is_my_mac(bat_priv, ethhdr->h_dest))
......
...@@ -61,7 +61,7 @@ int batadv_send_skb_packet(struct sk_buff *skb, ...@@ -61,7 +61,7 @@ int batadv_send_skb_packet(struct sk_buff *skb,
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
memcpy(ethhdr->h_source, hard_iface->net_dev->dev_addr, ETH_ALEN); memcpy(ethhdr->h_source, hard_iface->net_dev->dev_addr, ETH_ALEN);
memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN); memcpy(ethhdr->h_dest, dst_addr, ETH_ALEN);
ethhdr->h_proto = __constant_htons(ETH_P_BATMAN); ethhdr->h_proto = __constant_htons(ETH_P_BATMAN);
......
...@@ -316,7 +316,7 @@ void batadv_interface_rx(struct net_device *soft_iface, ...@@ -316,7 +316,7 @@ void batadv_interface_rx(struct net_device *soft_iface,
skb_pull_rcsum(skb, hdr_size); skb_pull_rcsum(skb, hdr_size);
skb_reset_mac_header(skb); skb_reset_mac_header(skb);
ethhdr = (struct ethhdr *)skb_mac_header(skb); ethhdr = eth_hdr(skb);
switch (ntohs(ethhdr->h_proto)) { switch (ntohs(ethhdr->h_proto)) {
case ETH_P_8021Q: case ETH_P_8021Q:
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment