From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: From: Antonio Quartulli Date: Mon, 21 Nov 2011 23:53:07 +0100 Message-Id: <1321915993-29312-2-git-send-email-ordex@autistici.org> In-Reply-To: <1321915993-29312-1-git-send-email-ordex@autistici.org> References: <1321915993-29312-1-git-send-email-ordex@autistici.org> Subject: [B.A.T.M.A.N.] [PATCHv3 1/7] batman-adv: implement an helper function to forge unicast packets 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: , To: b.a.t.m.a.n@lists.open-mesh.org 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 Reviewed-by: Simon Wunderlich --- unicast.c | 43 ++++++++++++++++++++++++++++++------------- unicast.h | 2 ++ 2 files changed, 32 insertions(+), 13 deletions(-) diff --git a/unicast.c b/unicast.c index 07d1c1d..cbadc21 100644 --- a/unicast.c +++ b/unicast.c @@ -283,6 +283,33 @@ out: return ret; } +struct sk_buff *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) + goto out; + + unicast_packet = (struct unicast_packet *)skb->data; + + unicast_packet->version = COMPAT_VERSION; + /* batman packet type: unicast */ + unicast_packet->packet_type = BAT_UNICAST; + /* set unicast ttl */ + unicast_packet->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 skb; +out: + kfree(skb); + return NULL; +} + int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv) { struct ethhdr *ethhdr = (struct ethhdr *)skb->data; @@ -315,22 +342,12 @@ find_router: if (!neigh_node) goto out; - if (my_skb_head_push(skb, sizeof(*unicast_packet)) < 0) + skb = prepare_unicast_packet(skb, orig_node); + if (!skb) goto out; unicast_packet = (struct unicast_packet *)skb->data; - unicast_packet->version = COMPAT_VERSION; - /* batman packet type: unicast */ - unicast_packet->packet_type = BAT_UNICAST; - /* set unicast ttl */ - unicast_packet->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) { @@ -350,7 +367,7 @@ out: neigh_node_free_ref(neigh_node); if (orig_node) orig_node_free_ref(orig_node); - if (ret == 1) + if (ret == 1 && skb) kfree_skb(skb); return ret; } diff --git a/unicast.h b/unicast.h index 8fd5535..f53a735 100644 --- a/unicast.h +++ b/unicast.h @@ -33,6 +33,8 @@ 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[]); +struct sk_buff *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) { -- 1.7.3.4