From patchwork Wed Aug 3 07:53:01 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Lindner X-Patchwork-Id: 1212 Return-Path: Received: from nm17-vm0.bullet.mail.ukl.yahoo.com (nm17-vm0.bullet.mail.ukl.yahoo.com [217.146.183.93]) by open-mesh.org (Postfix) with SMTP id EA64C600846 for ; Wed, 3 Aug 2011 09:53:27 +0200 (CEST) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@yahoo.de; dkim-adsp=none Received: from [217.146.183.216] by nm17.bullet.mail.ukl.yahoo.com with NNFMP; 03 Aug 2011 07:53:27 -0000 Received: from [77.238.184.69] by tm9.bullet.mail.ukl.yahoo.com with NNFMP; 03 Aug 2011 07:53:27 -0000 Received: from [127.0.0.1] by smtp138.mail.ukl.yahoo.com with NNFMP; 03 Aug 2011 07:53:27 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=yahoo.de; s=s1024; t=1312358007; bh=PQkKau8dD0tcJclGnqaDuxMfqgchR4d6kRlGReo4Ly4=; 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=Nr1JNY/5d1duOpUK9czBAZvBJXHgOFYRyd8RK+TvpD9p4H8DAf638Da5K+wGxoCvnsLGi+H2Yrl06J3u0e/WkfTBJzs9iJsbLTxTwGeTfo3w11DazAkR88IBLBxLxDuapSpFzH78tiaVqooHY2S4+I8GU9/2gc/umUMv2d5yPNA= X-Yahoo-Newman-Id: 439246.54019.bm@smtp138.mail.ukl.yahoo.com X-Yahoo-Newman-Property: ymail-3 X-YMail-OSG: Wb3L5M8VM1ltPQOaLGUYpFsNNxo9PWcjgFBEjnARYj_U1.m OJm8GRuOrd0oM9xGRyvWwe2vJubUA.IgEg7fFAsP5xU6JjzXLGcWiREvl89q ao3jtLxkxs62V1B1W.2MHQi8tjMv9V.16JeAhFGXrZpmeVKF.jLwH1Swk8uS hGkC5a2ipAWAjtMAlgBRqbiKZK0apbjreikyLXYELHZHjf1wnxqyWZBe28RO zZjDGdP0WtwpKRLZuBtoKSRScmr3FTrj0GBgOZry1QAp0WMCVqOLmuRik6Zs AY8ATm0AP_bo6MTC3YQIqohKSBxX7H5fWhSDK27lzBX62K7F_SckcLg-- X-Yahoo-SMTP: tW.h3tiswBBMXO2coYcbPigGD5Lt6zY_.Zc- Received: from localhost (lindner_marek@114.45.174.211 with plain) by smtp138.mail.ukl.yahoo.com with SMTP; 03 Aug 2011 07:53:26 +0000 GMT From: Marek Lindner To: b.a.t.m.a.n@lists.open-mesh.org Date: Wed, 3 Aug 2011 09:53:01 +0200 Message-Id: <1312357982-4610-3-git-send-email-lindner_marek@yahoo.de> X-Mailer: git-send-email 1.7.5.3 In-Reply-To: <1312357982-4610-1-git-send-email-lindner_marek@yahoo.de> References: <201108030952.35467.lindner_marek@yahoo.de> <1312357982-4610-1-git-send-email-lindner_marek@yahoo.de> Cc: Marek Lindner Subject: [B.A.T.M.A.N.] [PATCH 3/4] batman-adv: move routing packet initialization into corresponding file 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: Wed, 03 Aug 2011 07:53:28 -0000 Signed-off-by: Marek Lindner --- bat_iv_ogm.c | 37 +++++++++++++++++++++++++++++++++++++ bat_ogm.h | 3 +++ hard-interface.c | 38 ++++++-------------------------------- 3 files changed, 46 insertions(+), 32 deletions(-) diff --git a/bat_iv_ogm.c b/bat_iv_ogm.c index 6fa2d46..468bd5e 100644 --- a/bat_iv_ogm.c +++ b/bat_iv_ogm.c @@ -30,6 +30,43 @@ #include "hard-interface.h" #include "send.h" +void bat_ogm_init(struct hard_iface *hard_iface) +{ + struct batman_ogm_packet *batman_ogm_packet; + + hard_iface->packet_len = BATMAN_OGM_LEN; + hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); + + batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; + batman_ogm_packet->packet_type = BAT_OGM; + batman_ogm_packet->version = COMPAT_VERSION; + batman_ogm_packet->flags = NO_FLAGS; + batman_ogm_packet->ttl = 2; + batman_ogm_packet->tq = TQ_MAX_VALUE; + batman_ogm_packet->tt_num_changes = 0; + batman_ogm_packet->ttvn = 0; +} + +void bat_ogm_init_primary(struct hard_iface *hard_iface) +{ + struct batman_ogm_packet *batman_ogm_packet; + + batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; + batman_ogm_packet->flags = PRIMARIES_FIRST_HOP; + batman_ogm_packet->ttl = TTL; +} + +void bat_ogm_update_mac(struct hard_iface *hard_iface) +{ + struct batman_ogm_packet *batman_ogm_packet; + + batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; + memcpy(batman_ogm_packet->orig, + hard_iface->net_dev->dev_addr, ETH_ALEN); + memcpy(batman_ogm_packet->prev_sender, + hard_iface->net_dev->dev_addr, ETH_ALEN); +} + /* is there another aggregated packet here? */ static int bat_ogm_aggr_packet(int buff_pos, int packet_len, int tt_num_changes) diff --git a/bat_ogm.h b/bat_ogm.h index bdd3d1e..7809b92 100644 --- a/bat_ogm.h +++ b/bat_ogm.h @@ -24,6 +24,9 @@ #include "main.h" +void bat_ogm_init(struct hard_iface *hard_iface); +void bat_ogm_init_primary(struct hard_iface *hard_iface); +void bat_ogm_update_mac(struct hard_iface *hard_iface); void bat_ogm_receive(const struct ethhdr *ethhdr, unsigned char *packet_buff, int packet_len, struct hard_iface *if_incoming); diff --git a/hard-interface.c b/hard-interface.c index cfee017..2a15582 100644 --- a/hard-interface.c +++ b/hard-interface.c @@ -28,6 +28,7 @@ #include "bat_sysfs.h" #include "originator.h" #include "hash.h" +#include "bat_ogm.h" #include @@ -131,7 +132,6 @@ static void primary_if_select(struct bat_priv *bat_priv, struct hard_iface *new_hard_iface) { struct hard_iface *curr_hard_iface; - struct batman_ogm_packet *batman_ogm_packet; ASSERT_RTNL(); @@ -147,11 +147,7 @@ static void primary_if_select(struct bat_priv *bat_priv, if (!new_hard_iface) return; - batman_ogm_packet = (struct batman_ogm_packet *) - (new_hard_iface->packet_buff); - batman_ogm_packet->flags = PRIMARIES_FIRST_HOP; - batman_ogm_packet->ttl = TTL; - + bat_ogm_init_primary(new_hard_iface); primary_if_update_addr(bat_priv); } @@ -163,17 +159,6 @@ static bool hardif_is_iface_up(const struct hard_iface *hard_iface) return false; } -static void update_mac_addresses(struct hard_iface *hard_iface) -{ - struct batman_ogm_packet *batman_ogm_packet; - - batman_ogm_packet = (struct batman_ogm_packet *)hard_iface->packet_buff; - memcpy(batman_ogm_packet->orig, - hard_iface->net_dev->dev_addr, ETH_ALEN); - memcpy(batman_ogm_packet->prev_sender, - hard_iface->net_dev->dev_addr, ETH_ALEN); -} - static void check_known_mac_addr(const struct net_device *net_dev) { const struct hard_iface *hard_iface; @@ -248,7 +233,7 @@ static void hardif_activate_interface(struct hard_iface *hard_iface) bat_priv = netdev_priv(hard_iface->soft_iface); - update_mac_addresses(hard_iface); + bat_ogm_update_mac(hard_iface); hard_iface->if_status = IF_TO_BE_ACTIVATED; /** @@ -287,7 +272,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface, const char *iface_name) { struct bat_priv *bat_priv; - struct batman_ogm_packet *batman_ogm_packet; struct net_device *soft_iface; int ret; @@ -322,8 +306,8 @@ int hardif_enable_interface(struct hard_iface *hard_iface, hard_iface->soft_iface = soft_iface; bat_priv = netdev_priv(hard_iface->soft_iface); - hard_iface->packet_len = BATMAN_OGM_LEN; - hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC); + + bat_ogm_init(hard_iface); if (!hard_iface->packet_buff) { bat_err(hard_iface->soft_iface, "Can't add interface packet " @@ -332,16 +316,6 @@ int hardif_enable_interface(struct hard_iface *hard_iface, goto err; } - batman_ogm_packet = (struct batman_ogm_packet *) - (hard_iface->packet_buff); - batman_ogm_packet->packet_type = BAT_OGM; - batman_ogm_packet->version = COMPAT_VERSION; - batman_ogm_packet->flags = NO_FLAGS; - batman_ogm_packet->ttl = 2; - batman_ogm_packet->tq = TQ_MAX_VALUE; - batman_ogm_packet->tt_num_changes = 0; - batman_ogm_packet->ttvn = 0; - hard_iface->if_num = bat_priv->num_ifaces; bat_priv->num_ifaces++; hard_iface->if_status = IF_INACTIVE; @@ -556,7 +530,7 @@ static int hard_if_event(struct notifier_block *this, goto hardif_put; check_known_mac_addr(hard_iface->net_dev); - update_mac_addresses(hard_iface); + bat_ogm_update_mac(hard_iface); bat_priv = netdev_priv(hard_iface->soft_iface); primary_if = primary_if_get_selected(bat_priv);