From patchwork Tue Dec 7 14:39:34 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?q?Linus_L=C3=BCssing?= X-Patchwork-Id: 664 Return-Path: Received: from ascomax.hasler.ascom.ch (ascomax.hasler.ascom.ch [139.79.135.1]) by open-mesh.org (Postfix) with ESMTPS id B756B15458A for ; Tue, 7 Dec 2010 15:39:32 +0100 (CET) Received: from eiger.ma.tech.ascom.ch (eiger.ma.tech.ascom.ch [139.79.100.1]) by ascomax.hasler.ascom.ch (8.14.4/8.14.4) with ESMTP id oB7EdVsV028377; Tue, 7 Dec 2010 15:39:31 +0100 (MET) Received: from [139.79.100.248] (helo=localhost) by eiger.ma.tech.ascom.ch with esmtp (Exim 3.16 #1) id 1PPyhV-0005uG-00; Tue, 07 Dec 2010 15:39:29 +0100 From: =?UTF-8?q?Linus=20L=C3=BCssing?= To: b.a.t.m.a.n@lists.open-mesh.org Date: Tue, 7 Dec 2010 15:39:34 +0100 Message-Id: <1291732778-27441-7-git-send-email-linus.luessing@ascom.ch> X-Mailer: git-send-email 1.7.1 In-Reply-To: <1291732778-27441-1-git-send-email-linus.luessing@ascom.ch> References: <1291732778-27441-1-git-send-email-linus.luessing@ascom.ch> Cc: =?UTF-8?q?Linus=20L=C3=BCssing?= Subject: [B.A.T.M.A.N.] [PATCH 06/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: Tue, 07 Dec 2010 14:39:33 -0000 If no new packet has been received from a neighbour for a while, then delete it from memory. --- ndp.c | 25 +++++++++++++++++++++++++ ndp.h | 1 + originator.c | 2 ++ 3 files changed, 28 insertions(+), 0 deletions(-) diff --git a/ndp.c b/ndp.c index 3442e17..c1cd016 100644 --- a/ndp.c +++ b/ndp.c @@ -189,6 +189,31 @@ 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, *neigh_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); + list_for_each_entry_safe(neigh_node, neigh_node_tmp, + &batman_if->neigh_list, list) { + if (time_before(jiffies, + neigh_node->last_valid + PURGE_TIMEOUT * HZ)) + continue; + + list_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 35146ce..5679f36 100644 --- a/ndp.h +++ b/ndp.h @@ -7,5 +7,6 @@ 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 89ec021..ad31bf7 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" @@ -307,6 +308,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); }