From patchwork Wed Nov 17 01:26:27 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 568 Return-Path: Received: from nm5.bullet.mail.ukl.yahoo.com (nm5.bullet.mail.ukl.yahoo.com [217.146.182.226]) by open-mesh.org (Postfix) with SMTP id 1650C1542F8 for ; Wed, 17 Nov 2010 02:28:53 +0100 (CET) Received: from [217.146.183.216] by nm5.bullet.mail.ukl.yahoo.com with NNFMP; 17 Nov 2010 01:28:52 -0000 Received: from [217.146.183.168] by tm9.bullet.mail.ukl.yahoo.com with NNFMP; 17 Nov 2010 01:28:52 -0000 Received: from [127.0.0.1] by omp1009.mail.ukl.yahoo.com with NNFMP; 17 Nov 2010 01:28:52 -0000 X-Yahoo-Newman-Id: 645138.73529.bm@omp1009.mail.ukl.yahoo.com Received: (qmail 60592 invoked from network); 17 Nov 2010 01:28:52 -0000 DomainKey-Signature: a=rsa-sha1; q=dns; c=nofws; s=s1024; d=yahoo.de; h=DKIM-Signature:Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=2KW0cgrc/6Xlcvss8mEgLJwfNDztOw6vqK5C9rOdwPyHEpdqkILuNZE5FctrvGwOioEATBrYAKxcfe/DUogSh4xTlhX9gRrkNBXyhXo4jn/uOfaz93Y/CkeshfHGX8YOCds1voSwoFwYqabR6xu5zz9gSeSjJK4GVuILu9g7pzc= ; DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1289957332; bh=xH7BpI5VecmCTjn5g+pZ0gQRfux0aUQzQCgFmQFHmYU=; h=Received:X-Yahoo-SMTP:X-YMail-OSG:X-Yahoo-Newman-Property:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=va6/4rCcWM0PaCDflCEDIiXF6xSuqkNhTojIKUeLp51cy2G6KFfcyZkrDAcIwZbpd/QoPFwlJtTPsAIPtd0IxC5EaT334HrpcfWFpfihAiZHhqiOdpoztzOUZ5bOiBNTarJUjK8LHkncXMIo7mOyJ9nraGpWLIljfqLddDheb2o= Received: from localhost (lindner_marek@81.57.254.118 with plain) by smtp124.mail.ukl.yahoo.com with SMTP; 16 Nov 2010 17:28:48 -0800 PST X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- X-YMail-OSG: TAm0fYkVM1nNBbvLo6_MnKSSRhui1XW9KuHvVwjDEfFBw4G q1N1R9uIT7C3Jq0EXBSj6Nxm.bQuesAE_mG2wIJ.5SU3XSb4OhPNxixnH1jH eH7Hl0i_mvxzzIzyyHTnQYTwjgV8MlDoYjg4BmhlZcjOTWh19.5phm3WN694 MNKU_..jxLFK2evuKNsykq.q0Dl7JNa8OShSyvsh5UzuFxXtdLlsk.uDISps 4PTJF5uBey2KzCyb8sodjsbJ.eREdYtGw3.q154n.LyoK0fxF8XDLswfU3Zj IQpC_..5DUoV_F5Xk6CNxjeg2VA-- X-Yahoo-Newman-Property: ymail-3 From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 17 Nov 2010 02:26:27 +0100 Message-Id: <1289957194-5455-1-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.2.3 In-Reply-To: <201011170226.09739.lindner_marek@yahoo.de> References: <201011170226.09739.lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 1/8] batman-adv: protect neighbor nodes with reference counters 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: Wed, 17 Nov 2010 01:28:53 -0000 Signed-off-by: Marek Lindner --- batman-adv/originator.c | 20 +++++++++++++++----- batman-adv/originator.h | 8 +++++--- batman-adv/routing.c | 7 +++++++ batman-adv/types.h | 1 + 4 files changed, 28 insertions(+), 8 deletions(-) diff --git a/batman-adv/originator.c b/batman-adv/originator.c index 89ec021..9aff835 100644 --- a/batman-adv/originator.c +++ b/batman-adv/originator.c @@ -59,9 +59,18 @@ err: return 0; } -struct neigh_node * -create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, - uint8_t *neigh, struct batman_if *if_incoming) +void neigh_node_free_ref(struct kref *refcount) +{ + struct neigh_node *neigh_node; + + neigh_node = container_of(refcount, struct neigh_node, refcount); + kfree(neigh_node); +} + +struct neigh_node *create_neighbor(struct orig_node *orig_node, + struct orig_node *orig_neigh_node, + uint8_t *neigh, + struct batman_if *if_incoming) { struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); struct neigh_node *neigh_node; @@ -78,6 +87,7 @@ create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, memcpy(neigh_node->addr, neigh, ETH_ALEN); neigh_node->orig_node = orig_neigh_node; neigh_node->if_incoming = if_incoming; + kref_init(&neigh_node->refcount); list_add_tail(&neigh_node->list, &orig_node->neigh_list); return neigh_node; @@ -95,7 +105,7 @@ static void free_orig_node(void *data, void *arg) neigh_node = list_entry(list_pos, struct neigh_node, list); list_del(list_pos); - kfree(neigh_node); + kref_put(&neigh_node->refcount, neigh_node_free_ref); } frag_list_free(&orig_node->frag_list); @@ -228,7 +238,7 @@ static bool purge_orig_neighbors(struct bat_priv *bat_priv, neigh_purged = true; list_del(list_pos); - kfree(neigh_node); + kref_put(&neigh_node->refcount, neigh_node_free_ref); } else { if ((*best_neigh_node == NULL) || (neigh_node->tq_avg > (*best_neigh_node)->tq_avg)) diff --git a/batman-adv/originator.h b/batman-adv/originator.h index d474ceb..f3676fa 100644 --- a/batman-adv/originator.h +++ b/batman-adv/originator.h @@ -26,9 +26,11 @@ int originator_init(struct bat_priv *bat_priv); void originator_free(struct bat_priv *bat_priv); void purge_orig_ref(struct bat_priv *bat_priv); struct orig_node *get_orig_node(struct bat_priv *bat_priv, uint8_t *addr); -struct neigh_node * -create_neighbor(struct orig_node *orig_node, struct orig_node *orig_neigh_node, - uint8_t *neigh, struct batman_if *if_incoming); +struct neigh_node *create_neighbor(struct orig_node *orig_node, + struct orig_node *orig_neigh_node, + uint8_t *neigh, + struct batman_if *if_incoming); +void neigh_node_free_ref(struct kref *refcount); int orig_seq_print_text(struct seq_file *seq, void *offset); int orig_hash_add_if(struct batman_if *batman_if, int max_if_num); int orig_hash_del_if(struct batman_if *batman_if, int max_if_num); diff --git a/batman-adv/routing.c b/batman-adv/routing.c index 9f31167..881e444 100644 --- a/batman-adv/routing.c +++ b/batman-adv/routing.c @@ -82,6 +82,8 @@ static void update_route(struct bat_priv *bat_priv, struct neigh_node *neigh_node, unsigned char *hna_buff, int hna_buff_len) { + struct neigh_node *neigh_node_tmp; + /* route deleted */ if ((orig_node->router != NULL) && (neigh_node == NULL)) { @@ -108,7 +110,12 @@ static void update_route(struct bat_priv *bat_priv, orig_node->router->addr); } + neigh_node_tmp = orig_node->router; orig_node->router = neigh_node; + if (orig_node->router) + kref_get(&orig_node->router->refcount); + if (neigh_node_tmp) + kref_put(&neigh_node->refcount, neigh_node_free_ref); } diff --git a/batman-adv/types.h b/batman-adv/types.h index 1d00849..c1accbf 100644 --- a/batman-adv/types.h +++ b/batman-adv/types.h @@ -115,6 +115,7 @@ struct neigh_node { struct neigh_node *next_bond_candidate; unsigned long last_valid; TYPE_OF_WORD real_bits[NUM_WORDS]; + struct kref refcount; struct orig_node *orig_node; struct batman_if *if_incoming; };