From patchwork Fri Dec 31 15:46:20 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Linus_L=C3=BCssing?= X-Patchwork-Id: 690 Return-Path: Received: from fmmailgate01.web.de (fmmailgate01.web.de [217.72.192.221]) by open-mesh.org (Postfix) with ESMTP id 570641542EB for ; Fri, 31 Dec 2010 17:47:51 +0100 (CET) Received: from smtp03.web.de ( [172.20.0.65]) by fmmailgate01.web.de (Postfix) with ESMTP id 23E8F184BBAC4; Fri, 31 Dec 2010 17:47:51 +0100 (CET) Received: from [87.170.35.198] (helo=localhost) by smtp03.web.de with asmtp (TLSv1:AES128-SHA:128) (WEB.DE 4.110 #4) id 1PYi8r-0006GX-00; Fri, 31 Dec 2010 17:47:50 +0100 From: =?UTF-8?q?Linus=20L=C3=BCssing?= To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 31 Dec 2010 16:46:20 +0100 Message-Id: <1293810385-31761-6-git-send-email-linus.luessing@ascom.ch> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1293810385-31761-1-git-send-email-linus.luessing@ascom.ch> References: <1293810385-31761-1-git-send-email-linus.luessing@ascom.ch> MIME-Version: 1.0 Sender: linus.luessing@web.de X-Sender: linus.luessing@web.de X-Provags-ID: V01U2FsdGVkX18KgPNC+H+DOy9SOKJVcbo30y0X7kxn0ujTKUrt RRGDosYA2JxsXxQ9YX3bh7ELk4/WvW7cfBMPo/pQMAuoC4OiQ5 1UjbCiuq8deIusT1LjSw== Cc: =?UTF-8?q?Linus=20L=C3=BCssing?= Subject: [B.A.T.M.A.N.] [PATCH 05/10] batman-adv: Purge outdated ndp neighbours X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.11 Precedence: list Reply-To: The list for a Better Approach To Mobile Ad-hoc Networking List-Id: The list for a Better Approach To Mobile Ad-hoc Networking List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 31 Dec 2010 16:47:51 -0000 If no new packet has been received from a neighbour for a while, then delete it from memory. Signed-off-by: Linus Lüssing --- ndp.c | 28 ++++++++++++++++++++++++++++ ndp.h | 1 + originator.c | 2 ++ 3 files changed, 31 insertions(+), 0 deletions(-) diff --git a/ndp.c b/ndp.c index 23e3bcd..dbb0e9e 100644 --- a/ndp.c +++ b/ndp.c @@ -22,6 +22,7 @@ #include "main.h" #include "send.h" #include "ndp.h" +#include "hard-interface.h" #include "originator.h" /* when do we schedule our own neighbor discovery packet to be sent */ @@ -210,6 +211,33 @@ static struct neigh_node *ndp_create_neighbor(uint8_t my_tq, uint32_t seqno, return neigh_node; } +void ndp_purge_neighbors(void) +{ + struct neigh_node *neigh_node; + struct hlist_node *node, *node_tmp; + struct batman_if *batman_if; + + rcu_read_lock(); + list_for_each_entry_rcu(batman_if, &if_list, list) { + if (batman_if->if_status != IF_ACTIVE) + continue; + + spin_lock_bh(&batman_if->neigh_list_lock); + hlist_for_each_entry_safe(neigh_node, node, node_tmp, + &batman_if->neigh_list, list) { + if (time_before(jiffies, neigh_node->last_valid + + msecs_to_jiffies(PURGE_TIMEOUT * + 1000))) + continue; + + hlist_del(&neigh_node->list); + kfree(neigh_node); + } + spin_unlock_bh(&batman_if->neigh_list_lock); + } + rcu_read_unlock(); +} + int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno, struct batman_if *batman_if, uint8_t *neigh_addr) { diff --git a/ndp.h b/ndp.h index 2496c3f..a828362 100644 --- a/ndp.h +++ b/ndp.h @@ -29,6 +29,7 @@ int ndp_init(struct batman_if *batman_if); void ndp_free(struct batman_if *batman_if); uint8_t ndp_fetch_tq(struct batman_packet_ndp *packet, uint8_t *my_if_addr); +void ndp_purge_neighbors(void); int ndp_update_neighbor(uint8_t my_tq, uint32_t seqno, struct batman_if *batman_if, uint8_t *neigh_addr); diff --git a/originator.c b/originator.c index c043bf8..e98add5 100644 --- a/originator.c +++ b/originator.c @@ -22,6 +22,7 @@ /* increase the reference counter for this originator */ #include "main.h" +#include "ndp.h" #include "originator.h" #include "hash.h" #include "translation-table.h" @@ -334,6 +335,7 @@ static void purge_orig(struct work_struct *work) container_of(delayed_work, struct bat_priv, orig_work); _purge_orig(bat_priv); + ndp_purge_neighbors(); start_purge_timer(bat_priv); }