From patchwork Thu Mar 1 07:35:21 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1588 Return-Path: Received: from nm4-vm0.bullet.mail.ukl.yahoo.com (nm4-vm0.bullet.mail.ukl.yahoo.com [217.146.183.230]) by open-mesh.org (Postfix) with SMTP id BC67C6008EE for ; Thu, 1 Mar 2012 08:36:51 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.211] by nm4.bullet.mail.ukl.yahoo.com with NNFMP; 01 Mar 2012 07:36:51 -0000 Received: from [217.146.183.123] by tm4.bullet.mail.ukl.yahoo.com with NNFMP; 01 Mar 2012 07:36:51 -0000 Received: from [127.0.0.1] by smtp112.mail.ukl.yahoo.com with NNFMP; 01 Mar 2012 07:36:51 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1330587411; bh=P+fDRTvkZAIGjmfGwfltdnbrnI+9Csr+X7AaCBSVDAs=; h=X-Yahoo-Newman-Id:X-Yahoo-Newman-Property:X-YMail-OSG:X-Yahoo-SMTP:Received:From:To:Cc:Subject:Date:Message-Id:X-Mailer:In-Reply-To:References; b=LnhNUF3VTZInIA9BJAQ+3fSTMMHGvomIhy8cTKoainlbs9lz//TeIdP1B44pdF8Itwn6nG6n+5pSDM1NZtl2BOwWf+XbPR4KOl5lqrT6CFyTb9eRWUSrT6AsDidrohP+e/4ETX043cl57LqxfFe0JUSa/fqNnLUh4YLHKp4kwVA= X-Yahoo-Newman-Id: 322887.24879.bm@smtp112.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: SyoaRskVM1k3kKWXx28w3dzpKOP_LX4n6s_B9OSoLhA8jie 59eFglNsJDW7QsWj3KLNDl7yYQE3Q1Fz2POjaVsuvbB8qyN3pgatnqdJohVZ 1wHTmH6G1S92PPeEqy83j4rnUfemO8BBbSj6zLbM4kwnendolyTkFfn2VoCX d2htUgH9EiRVAZ7crkSiZKfXNy_2SVyMsYhzYFAt8oohM7smNst3ChnEwfQj et7vUtvooccBUdyYvgB_RWcLjbQfCHtPgOlZ5YcwPgO.zqol83TRRX2imCl_ d2wjJ1rkTt3naFMPSvnBNOt8_2.8lqA5T4.SLCGLMMjmfiYBNqvrkENH3rT1 i9ES4RhtgsaF_W1mhCWJiap_U1d1wtJtYnxt4kQ88MohaQS.G22P6i1LJ0h_ 5eS7E X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@119.236.110.45 with plain) by smtp112.mail.ukl.yahoo.com with SMTP; 29 Feb 2012 23:36:49 -0800 PST From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Thu, 1 Mar 2012 15:35:21 +0800 Message-Id: <1330587321-12177-6-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.9 In-Reply-To: <1330587321-12177-1-git-send-email-lindner_marek@yahoo.de> References: <1330587321-12177-1-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 6/6] batman-adv: split neigh_new function into generic and batman iv specific parts X-BeenThere: b.a.t.m.a.n@lists.open-mesh.org X-Mailman-Version: 2.1.13 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: Thu, 01 Mar 2012 07:36:52 -0000 Signed-off-by: Marek Lindner --- bat_iv_ogm.c | 40 ++++++++++++++++++++++++++++++++++------ originator.c | 27 ++++++++++----------------- originator.h | 6 ++---- 3 files changed, 46 insertions(+), 27 deletions(-) diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c index 209722f..2d2cc73 100644 --- a/bat_iv_ogm.c +++ b/bat_iv_ogm.c @@ -30,6 +30,32 @@ #include "send.h" #include "bat_algo.h" +static struct neigh_node *bat_iv_ogm_neigh_new(struct hard_iface *hard_iface, + const uint8_t *neigh_addr, + struct orig_node *orig_node, + struct orig_node *orig_neigh, + uint32_t seqno) +{ + struct neigh_node *neigh_node; + + neigh_node = neigh_node_new(hard_iface, neigh_addr, seqno); + if (!neigh_node) + goto out; + + INIT_LIST_HEAD(&neigh_node->bonding_list); + spin_lock_init(&neigh_node->tq_lock); + + neigh_node->orig_node = orig_neigh; + neigh_node->if_incoming = hard_iface; + + spin_lock_bh(&orig_node->neigh_list_lock); + hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); + spin_unlock_bh(&orig_node->neigh_list_lock); + +out: + return neigh_node; +} + static int bat_iv_ogm_iface_enable(struct hard_iface *hard_iface) { struct batman_ogm_packet *batman_ogm_packet; @@ -642,8 +668,9 @@ static void bat_iv_ogm_orig_update(struct bat_priv *bat_priv, if (!orig_tmp) goto unlock; - neigh_node = create_neighbor(orig_node, orig_tmp, - ethhdr->h_source, if_incoming); + neigh_node = bat_iv_ogm_neigh_new(if_incoming, ethhdr->h_source, + orig_node, orig_tmp, + batman_ogm_packet->seqno); orig_node_free_ref(orig_tmp); if (!neigh_node) @@ -768,10 +795,11 @@ static int bat_iv_ogm_calc_tq(struct orig_node *orig_node, rcu_read_unlock(); if (!neigh_node) - neigh_node = create_neighbor(orig_neigh_node, - orig_neigh_node, - orig_neigh_node->orig, - if_incoming); + neigh_node = bat_iv_ogm_neigh_new(if_incoming, + orig_neigh_node->orig, + orig_neigh_node, + orig_neigh_node, + batman_ogm_packet->seqno); if (!neigh_node) goto out; diff --git a/originator.c b/originator.c index 183a1fe..9f32aa0 100644 --- a/originator.c +++ b/originator.c @@ -86,35 +86,28 @@ struct neigh_node *orig_node_get_router(struct orig_node *orig_node) return router; } -struct neigh_node *create_neighbor(struct orig_node *orig_node, - struct orig_node *orig_neigh_node, - const uint8_t *neigh, - struct hard_iface *if_incoming) +struct neigh_node *neigh_node_new(struct hard_iface *hard_iface, + const uint8_t *neigh_addr, uint32_t seqno) { - struct bat_priv *bat_priv = netdev_priv(if_incoming->soft_iface); + struct bat_priv *bat_priv = netdev_priv(hard_iface->soft_iface); struct neigh_node *neigh_node; - bat_dbg(DBG_BATMAN, bat_priv, - "Creating new last-hop neighbor of originator\n"); - neigh_node = kzalloc(sizeof(*neigh_node), GFP_ATOMIC); if (!neigh_node) - return NULL; + goto out; INIT_HLIST_NODE(&neigh_node->list); - INIT_LIST_HEAD(&neigh_node->bonding_list); - spin_lock_init(&neigh_node->tq_lock); - memcpy(neigh_node->addr, neigh, ETH_ALEN); - neigh_node->orig_node = orig_neigh_node; - neigh_node->if_incoming = if_incoming; + memcpy(neigh_node->addr, neigh_addr, ETH_ALEN); /* extra reference for return */ atomic_set(&neigh_node->refcount, 2); - spin_lock_bh(&orig_node->neigh_list_lock); - hlist_add_head_rcu(&neigh_node->list, &orig_node->neigh_list); - spin_unlock_bh(&orig_node->neigh_list_lock); + bat_dbg(DBG_BATMAN, bat_priv, + "Creating new neighbor %pM, initial seqno %d\n", + neigh_addr, seqno); + +out: return neigh_node; } diff --git a/originator.h b/originator.h index 3fe2eda..64c5d94 100644 --- a/originator.h +++ b/originator.h @@ -29,10 +29,8 @@ void originator_free(struct bat_priv *bat_priv); void purge_orig_ref(struct bat_priv *bat_priv); void orig_node_free_ref(struct orig_node *orig_node); struct orig_node *get_orig_node(struct bat_priv *bat_priv, const uint8_t *addr); -struct neigh_node *create_neighbor(struct orig_node *orig_node, - struct orig_node *orig_neigh_node, - const uint8_t *neigh, - struct hard_iface *if_incoming); +struct neigh_node *neigh_node_new(struct hard_iface *hard_iface, + const uint8_t *neigh_addr, uint32_t seqno); void neigh_node_free_ref(struct neigh_node *neigh_node); struct neigh_node *orig_node_get_router(struct orig_node *orig_node); int orig_seq_print_text(struct seq_file *seq, void *offset);