From patchwork Thu Feb 9 23:41:34 2012 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Antonio Quartulli X-Patchwork-Id: 1505 Return-Path: Received: from latitanza.investici.org (latitanza.investici.org [82.94.249.234]) by open-mesh.org (Postfix) with ESMTPS id 181F16008A2 for ; Fri, 10 Feb 2012 00:42:50 +0100 (CET) Authentication-Results: open-mesh.org; dkim=pass (1024-bit key) header.i=@autistici.org; dkim-adsp=pass Received: from [82.94.249.234] (latitanza [82.94.249.234]) (Authenticated sender: ordex@autistici.org) by localhost (Postfix) with ESMTPSA id 67BBD98087; Thu, 9 Feb 2012 23:42:49 +0000 (UTC) X-DKIM: Sendmail DKIM Filter v2.8.2 latitanza.investici.org 67BBD98087 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=autistici.org; s=stigmate; t=1328830969; bh=FKbb6S/V0OP5/4TqMALW2+krxuXwf6cJpttztddzXvk=; h=From:To:Cc:Subject:Date:Message-Id:In-Reply-To:References; b=dM18BkeBJBq2eC/0CAwv5kPlItH8hWQUKODtmkg4Aksx59zr1ytQOeU8Vdl33yH6l GNiMeLY24Cy4RKkaP0EcFG7mZ9YEKW6Bex4Dx2CaTARwVkNHT99EYXe8MIddOXlIkw 2/8rGIremtJ1T4uLae6zV59eORXUEcyd0RFbcxjM= From: Antonio Quartulli To: b.a.t.m.a.n@lists.open-mesh.org Date: Fri, 10 Feb 2012 00:41:34 +0100 Message-Id: <1328830902-11574-2-git-send-email-ordex@autistici.org> X-Mailer: git-send-email 1.7.3.4 In-Reply-To: <1328830902-11574-1-git-send-email-ordex@autistici.org> References: <1328830902-11574-1-git-send-email-ordex@autistici.org> Subject: [B.A.T.M.A.N.] [PATCHv5 1/9] batman-adv: implement an helper function to forge unicast packets 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, 09 Feb 2012 23:42:50 -0000 A new function named prepare_unicast_packet() has been implemented so that it can do all the needed operations to set up a skb for unicast sending. It is general enough to be used in every context. Helpful for later developments Signed-off-by: Antonio Quartulli --- unicast.c | 36 ++++++++++++++++++++++++------------ unicast.h | 1 + 2 files changed, 25 insertions(+), 12 deletions(-) diff --git a/unicast.c b/unicast.c index 0897dfa..887342b 100644 --- a/unicast.c +++ b/unicast.c @@ -283,6 +283,29 @@ out: return ret; } +bool prepare_unicast_packet(struct sk_buff *skb, struct orig_node *orig_node) +{ + struct unicast_packet *unicast_packet; + + if (my_skb_head_push(skb, sizeof(*unicast_packet)) < 0) + return false; + + unicast_packet = (struct unicast_packet *)skb->data; + + unicast_packet->header.version = COMPAT_VERSION; + /* batman packet type: unicast */ + unicast_packet->header.packet_type = BAT_UNICAST; + /* set unicast ttl */ + unicast_packet->header.ttl = TTL; + /* copy the destination for faster routing */ + memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); + /* set the destination tt version number */ + unicast_packet->ttvn = + (uint8_t)atomic_read(&orig_node->last_ttvn); + + return true; +} + int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) { struct ethhdr *ethhdr = (struct ethhdr *)skb->data; @@ -315,22 +338,11 @@ find_router: if (!neigh_node) goto out; - if (my_skb_head_push(skb, sizeof(*unicast_packet)) < 0) + if (!prepare_unicast_packet(skb, orig_node)) goto out; unicast_packet = (struct unicast_packet *)skb->data; - unicast_packet->header.version = COMPAT_VERSION; - /* batman packet type: unicast */ - unicast_packet->header.packet_type = BAT_UNICAST; - /* set unicast ttl */ - unicast_packet->header.ttl = TTL; - /* copy the destination for faster routing */ - memcpy(unicast_packet->dest, orig_node->orig, ETH_ALEN); - /* set the destination tt version number */ - unicast_packet->ttvn = - (uint8_t)atomic_read(&orig_node->last_ttvn); - if (atomic_read(&bat_priv->fragmentation) && data_len + sizeof(*unicast_packet) > neigh_node->if_incoming->net_dev->mtu) { diff --git a/unicast.h b/unicast.h index a9faf6b..c51ad3d 100644 --- a/unicast.h +++ b/unicast.h @@ -33,6 +33,7 @@ void frag_list_free(struct list_head *head); int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv); int frag_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv, struct hard_iface *hard_iface, const uint8_t dstaddr[]); +bool prepare_unicast_packet(struct sk_buff *skb, struct orig_node *orig_node); static inline int frag_can_reassemble(const struct sk_buff *skb, int mtu) {