diff options
author | Antonio Quartulli <ordex@autistici.org> | 2013-05-12 15:51:15 -0400 |
---|---|---|
committer | Antonio Quartulli <antonio@meshcoding.com> | 2013-10-12 05:58:30 -0400 |
commit | f7f8ed5695ef441495cfab5287951927d9d5f12e (patch) | |
tree | bce239bcd43bdb8e61c7162d1f314adb32b1e7d2 /net/batman-adv | |
parent | 210260594782ba9bc52732d84880573466c13441 (diff) |
batman-adv: h_vlan_encapsulated_proto access refactoring
In case of a VLAN tagged frame the ethhdr pointer is
moved forward by 4 bytes so that the offset of h_proto
in struct ethhdr matches the real
h_vlan_encapsulated_proto address in the skb. While this
trickery is correct it makes the code harder to understand
and may lead to bugs in case of re-use of ethhdr for other
purposes.
This patch introduces a proto variable to make things
cleaner and easier to understand.
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Diffstat (limited to 'net/batman-adv')
-rw-r--r-- | net/batman-adv/gateway_client.c | 19 |
1 files changed, 12 insertions, 7 deletions
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c index 1bce63aa5f5f..ac97ca7f4ad0 100644 --- a/net/batman-adv/gateway_client.c +++ b/net/batman-adv/gateway_client.c | |||
@@ -655,24 +655,29 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) | |||
655 | struct iphdr *iphdr; | 655 | struct iphdr *iphdr; |
656 | struct ipv6hdr *ipv6hdr; | 656 | struct ipv6hdr *ipv6hdr; |
657 | struct udphdr *udphdr; | 657 | struct udphdr *udphdr; |
658 | struct vlan_ethhdr *vhdr; | ||
659 | __be16 proto; | ||
658 | 660 | ||
659 | /* check for ethernet header */ | 661 | /* check for ethernet header */ |
660 | if (!pskb_may_pull(skb, *header_len + ETH_HLEN)) | 662 | if (!pskb_may_pull(skb, *header_len + ETH_HLEN)) |
661 | return false; | 663 | return false; |
662 | ethhdr = (struct ethhdr *)skb->data; | 664 | ethhdr = (struct ethhdr *)skb->data; |
665 | proto = ethhdr->h_proto; | ||
663 | *header_len += ETH_HLEN; | 666 | *header_len += ETH_HLEN; |
664 | 667 | ||
665 | /* check for initial vlan header */ | 668 | /* check for initial vlan header */ |
666 | if (ntohs(ethhdr->h_proto) == ETH_P_8021Q) { | 669 | if (proto == htons(ETH_P_8021Q)) { |
667 | if (!pskb_may_pull(skb, *header_len + VLAN_HLEN)) | 670 | if (!pskb_may_pull(skb, *header_len + VLAN_HLEN)) |
668 | return false; | 671 | return false; |
669 | ethhdr = (struct ethhdr *)(skb->data + VLAN_HLEN); | 672 | |
673 | vhdr = (struct vlan_ethhdr *)skb->data; | ||
674 | proto = vhdr->h_vlan_encapsulated_proto; | ||
670 | *header_len += VLAN_HLEN; | 675 | *header_len += VLAN_HLEN; |
671 | } | 676 | } |
672 | 677 | ||
673 | /* check for ip header */ | 678 | /* check for ip header */ |
674 | switch (ntohs(ethhdr->h_proto)) { | 679 | switch (proto) { |
675 | case ETH_P_IP: | 680 | case htons(ETH_P_IP): |
676 | if (!pskb_may_pull(skb, *header_len + sizeof(*iphdr))) | 681 | if (!pskb_may_pull(skb, *header_len + sizeof(*iphdr))) |
677 | return false; | 682 | return false; |
678 | iphdr = (struct iphdr *)(skb->data + *header_len); | 683 | iphdr = (struct iphdr *)(skb->data + *header_len); |
@@ -683,7 +688,7 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) | |||
683 | return false; | 688 | return false; |
684 | 689 | ||
685 | break; | 690 | break; |
686 | case ETH_P_IPV6: | 691 | case htons(ETH_P_IPV6): |
687 | if (!pskb_may_pull(skb, *header_len + sizeof(*ipv6hdr))) | 692 | if (!pskb_may_pull(skb, *header_len + sizeof(*ipv6hdr))) |
688 | return false; | 693 | return false; |
689 | ipv6hdr = (struct ipv6hdr *)(skb->data + *header_len); | 694 | ipv6hdr = (struct ipv6hdr *)(skb->data + *header_len); |
@@ -710,11 +715,11 @@ bool batadv_gw_is_dhcp_target(struct sk_buff *skb, unsigned int *header_len) | |||
710 | *header_len += sizeof(*udphdr); | 715 | *header_len += sizeof(*udphdr); |
711 | 716 | ||
712 | /* check for bootp port */ | 717 | /* check for bootp port */ |
713 | if ((ntohs(ethhdr->h_proto) == ETH_P_IP) && | 718 | if ((proto == htons(ETH_P_IP)) && |
714 | (ntohs(udphdr->dest) != 67)) | 719 | (ntohs(udphdr->dest) != 67)) |
715 | return false; | 720 | return false; |
716 | 721 | ||
717 | if ((ntohs(ethhdr->h_proto) == ETH_P_IPV6) && | 722 | if ((proto == htons(ETH_P_IPV6)) && |
718 | (ntohs(udphdr->dest) != 547)) | 723 | (ntohs(udphdr->dest) != 547)) |
719 | return false; | 724 | return false; |
720 | 725 | ||