diff options
author | Martin Hundebøll <martin@hundeboll.net> | 2013-01-13 18:20:32 -0500 |
---|---|---|
committer | Antonio Quartulli <ordex@autistici.org> | 2013-03-13 17:53:47 -0400 |
commit | f86ce0ad107bc0e33ead8ba2498fc22dfb747479 (patch) | |
tree | 097c1d92225b652860b6a5c3a4efbe06187bb8aa /net/batman-adv/routing.c | |
parent | 736292c2e89ff8ba266bdc08ca035f5a7afb68f6 (diff) |
batman-adv: Return reason for failure in batadv_check_unicast_packet()
batadv_check_unicast_packet() is changed to return a value based on the
reason to drop the packet, which will be useful information for
future users of batadv_check_unicast_packet().
Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
Acked-by: Antonio Quartulli <ordex@autistici.org>
Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
Diffstat (limited to 'net/batman-adv/routing.c')
-rw-r--r-- | net/batman-adv/routing.c | 18 |
1 files changed, 14 insertions, 4 deletions
diff --git a/net/batman-adv/routing.c b/net/batman-adv/routing.c index 5ee21cebbbb0..322c97ac10c7 100644 --- a/net/batman-adv/routing.c +++ b/net/batman-adv/routing.c | |||
@@ -548,27 +548,37 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig, | |||
548 | return router; | 548 | return router; |
549 | } | 549 | } |
550 | 550 | ||
551 | /** | ||
552 | * batadv_check_unicast_packet - Check for malformed unicast packets | ||
553 | * @skb: packet to check | ||
554 | * @hdr_size: size of header to pull | ||
555 | * | ||
556 | * Check for short header and bad addresses in given packet. Returns negative | ||
557 | * value when check fails and 0 otherwise. The negative value depends on the | ||
558 | * reason: -ENODATA for bad header, -EBADR for broadcast destination or source, | ||
559 | * and -EREMOTE for non-local (other host) destination. | ||
560 | */ | ||
551 | static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size) | 561 | static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size) |
552 | { | 562 | { |
553 | struct ethhdr *ethhdr; | 563 | struct ethhdr *ethhdr; |
554 | 564 | ||
555 | /* drop packet if it has not necessary minimum size */ | 565 | /* drop packet if it has not necessary minimum size */ |
556 | if (unlikely(!pskb_may_pull(skb, hdr_size))) | 566 | if (unlikely(!pskb_may_pull(skb, hdr_size))) |
557 | return -1; | 567 | return -ENODATA; |
558 | 568 | ||
559 | ethhdr = (struct ethhdr *)skb_mac_header(skb); | 569 | ethhdr = (struct ethhdr *)skb_mac_header(skb); |
560 | 570 | ||
561 | /* packet with unicast indication but broadcast recipient */ | 571 | /* packet with unicast indication but broadcast recipient */ |
562 | if (is_broadcast_ether_addr(ethhdr->h_dest)) | 572 | if (is_broadcast_ether_addr(ethhdr->h_dest)) |
563 | return -1; | 573 | return -EBADR; |
564 | 574 | ||
565 | /* packet with broadcast sender address */ | 575 | /* packet with broadcast sender address */ |
566 | if (is_broadcast_ether_addr(ethhdr->h_source)) | 576 | if (is_broadcast_ether_addr(ethhdr->h_source)) |
567 | return -1; | 577 | return -EBADR; |
568 | 578 | ||
569 | /* not for me */ | 579 | /* not for me */ |
570 | if (!batadv_is_my_mac(ethhdr->h_dest)) | 580 | if (!batadv_is_my_mac(ethhdr->h_dest)) |
571 | return -1; | 581 | return -EREMOTE; |
572 | 582 | ||
573 | return 0; | 583 | return 0; |
574 | } | 584 | } |