aboutsummaryrefslogtreecommitdiffstats
path: root/net/batman-adv/gateway_client.c
diff options
context:
space:
mode:
authorAntonio Quartulli <ordex@autistici.org>2011-04-26 15:31:45 -0400
committerSven Eckelmann <sven@narfation.org>2011-06-20 05:37:41 -0400
commit43676ab590c3f8686fd047d34c3e33803eef71f0 (patch)
tree056303a6b33a23a74610cceee11c946847b22c61 /net/batman-adv/gateway_client.c
parent19595e054d35820e026caac314414e435287e3ae (diff)
batman-adv: improved gateway tq-based selection
If a client issues a DHCPREQUEST for renewal, the packet is dropped if the old destination (the old gateway for the client) TQ is smaller than the current best gateway TQ less GW_THRESHOLD Signed-off-by: Antonio Quartulli <ordex@autistici.org> Signed-off-by: Marek Lindner <lindner_marek@yahoo.de> Signed-off-by: Sven Eckelmann <sven@narfation.org>
Diffstat (limited to 'net/batman-adv/gateway_client.c')
-rw-r--r--net/batman-adv/gateway_client.c94
1 files changed, 92 insertions, 2 deletions
diff --git a/net/batman-adv/gateway_client.c b/net/batman-adv/gateway_client.c
index 6381864c1ca4..8b25b52a4764 100644
--- a/net/batman-adv/gateway_client.c
+++ b/net/batman-adv/gateway_client.c
@@ -25,11 +25,17 @@
25#include "gateway_common.h" 25#include "gateway_common.h"
26#include "hard-interface.h" 26#include "hard-interface.h"
27#include "originator.h" 27#include "originator.h"
28#include "routing.h"
28#include <linux/ip.h> 29#include <linux/ip.h>
29#include <linux/ipv6.h> 30#include <linux/ipv6.h>
30#include <linux/udp.h> 31#include <linux/udp.h>
31#include <linux/if_vlan.h> 32#include <linux/if_vlan.h>
32 33
34/* This is the offset of the options field in a dhcp packet starting at
35 * the beginning of the dhcp header */
36#define DHCP_OPTIONS_OFFSET 240
37#define DHCP_REQUEST 3
38
33static void gw_node_free_ref(struct gw_node *gw_node) 39static void gw_node_free_ref(struct gw_node *gw_node)
34{ 40{
35 if (atomic_dec_and_test(&gw_node->refcount)) 41 if (atomic_dec_and_test(&gw_node->refcount))
@@ -509,14 +515,75 @@ out:
509 return ret; 515 return ret;
510} 516}
511 517
512int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb) 518static bool is_type_dhcprequest(struct sk_buff *skb, int header_len)
519{
520 int ret = false;
521 unsigned char *p;
522 int pkt_len;
523
524 if (skb_linearize(skb) < 0)
525 goto out;
526
527 pkt_len = skb_headlen(skb);
528
529 if (pkt_len < header_len + DHCP_OPTIONS_OFFSET + 1)
530 goto out;
531
532 p = skb->data + header_len + DHCP_OPTIONS_OFFSET;
533 pkt_len -= header_len + DHCP_OPTIONS_OFFSET + 1;
534
535 /* Access the dhcp option lists. Each entry is made up by:
536 * - octect 1: option type
537 * - octect 2: option data len (only if type != 255 and 0)
538 * - octect 3: option data */
539 while (*p != 255 && !ret) {
540 /* p now points to the first octect: option type */
541 if (*p == 53) {
542 /* type 53 is the message type option.
543 * Jump the len octect and go to the data octect */
544 if (pkt_len < 2)
545 goto out;
546 p += 2;
547
548 /* check if the message type is what we need */
549 if (*p == DHCP_REQUEST)
550 ret = true;
551 break;
552 } else if (*p == 0) {
553 /* option type 0 (padding), just go forward */
554 if (pkt_len < 1)
555 goto out;
556 pkt_len--;
557 p++;
558 } else {
559 /* This is any other option. So we get the length... */
560 if (pkt_len < 1)
561 goto out;
562 pkt_len--;
563 p++;
564
565 /* ...and then we jump over the data */
566 if (pkt_len < *p)
567 goto out;
568 pkt_len -= *p;
569 p += (*p);
570 }
571 }
572out:
573 return ret;
574}
575
576int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb,
577 struct orig_node *old_gw)
513{ 578{
514 struct ethhdr *ethhdr; 579 struct ethhdr *ethhdr;
515 struct iphdr *iphdr; 580 struct iphdr *iphdr;
516 struct ipv6hdr *ipv6hdr; 581 struct ipv6hdr *ipv6hdr;
517 struct udphdr *udphdr; 582 struct udphdr *udphdr;
518 struct gw_node *curr_gw; 583 struct gw_node *curr_gw;
584 struct neigh_node *neigh_curr = NULL, *neigh_old = NULL;
519 unsigned int header_len = 0; 585 unsigned int header_len = 0;
586 int ret = 1;
520 587
521 if (atomic_read(&bat_priv->gw_mode) == GW_MODE_OFF) 588 if (atomic_read(&bat_priv->gw_mode) == GW_MODE_OFF)
522 return 0; 589 return 0;
@@ -584,7 +651,30 @@ int gw_is_target(struct bat_priv *bat_priv, struct sk_buff *skb)
584 if (!curr_gw) 651 if (!curr_gw)
585 return 0; 652 return 0;
586 653
654 /* If old_gw != NULL then this packet is unicast.
655 * So, at this point we have to check the message type: if it is a
656 * DHCPREQUEST we have to decide whether to drop it or not */
657 if (old_gw && curr_gw->orig_node != old_gw) {
658 if (is_type_dhcprequest(skb, header_len)) {
659 /* If the dhcp packet has been sent to a different gw,
660 * we have to evaluate whether the old gw is still
661 * reliable enough */
662 neigh_curr = find_router(bat_priv, curr_gw->orig_node,
663 NULL);
664 neigh_old = find_router(bat_priv, old_gw, NULL);
665 if (!neigh_curr || !neigh_old)
666 goto free_neigh;
667 if (neigh_curr->tq_avg - neigh_old->tq_avg <
668 GW_THRESHOLD)
669 ret = -1;
670 }
671 }
672free_neigh:
673 if (neigh_old)
674 neigh_node_free_ref(neigh_old);
675 if (neigh_curr)
676 neigh_node_free_ref(neigh_curr);
587 if (curr_gw) 677 if (curr_gw)
588 gw_node_free_ref(curr_gw); 678 gw_node_free_ref(curr_gw);
589 return 1; 679 return ret;
590} 680}