b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
From: Antonio Quartulli <ordex@autistici.org>
To: b.a.t.m.a.n@lists.open-mesh.org
Subject: [B.A.T.M.A.N.] [PATCH 1/6] batman-adv: implement an helper function to forge unicast packets
Date: Sun, 30 Oct 2011 09:55:57 +0100	[thread overview]
Message-ID: <1319964962-5092-2-git-send-email-ordex@autistici.org> (raw)
In-Reply-To: <1319964962-5092-1-git-send-email-ordex@autistici.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 <ordex@autistici.org>
---
 unicast.c |   48 ++++++++++++++++++++++++++++++++----------------
 unicast.h |    2 ++
 2 files changed, 34 insertions(+), 16 deletions(-)

diff --git a/unicast.c b/unicast.c
index 07d1c1d..ee7bceb 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;
@@ -296,7 +323,7 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 	if (is_multicast_ether_addr(ethhdr->h_dest)) {
 		orig_node = gw_get_selected_orig(bat_priv);
 		if (orig_node)
-			goto find_router;
+			goto prepare_packet;
 	}
 
 	/* check for tt host - increases orig_node refcount.
@@ -304,33 +331,22 @@ int unicast_send_skb(struct sk_buff *skb, struct bat_priv *bat_priv)
 	orig_node = transtable_search(bat_priv, ethhdr->h_source,
 				      ethhdr->h_dest);
 
-find_router:
+prepare_packet:
 	/**
 	 * find_router():
 	 *  - if orig_node is NULL it returns NULL
 	 *  - increases neigh_nodes refcount if found.
 	 */
 	neigh_node = find_router(bat_priv, orig_node, NULL);
-
 	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 +366,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


  reply	other threads:[~2011-10-30  8:55 UTC|newest]

Thread overview: 24+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-30  8:55 [B.A.T.M.A.N.] [PATCH 0/6] DAT: Distributed ARP Table Antonio Quartulli
2011-10-30  8:55 ` Antonio Quartulli [this message]
2011-10-31  0:05   ` [B.A.T.M.A.N.] [PATCH 1/6] batman-adv: implement an helper function to forge unicast packets Simon Wunderlich
2011-11-01  9:12     ` Antonio Quartulli
2011-10-30  8:55 ` [B.A.T.M.A.N.] [PATCH 2/6] batman-adv: add a new log level for DAT-ARP debugging Antonio Quartulli
2011-10-30  8:55 ` [B.A.T.M.A.N.] [PATCH 3/6] batman-adv: Distributed ARP Table - create the DHT helper functions Antonio Quartulli
2011-10-31  0:08   ` Simon Wunderlich
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 4/6] batman-adv: Distributed ARP Table - add ARP parsing functions Antonio Quartulli
2011-10-31  0:10   ` Simon Wunderlich
2011-11-01  9:14     ` Antonio Quartulli
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 5/6] batman-adv: Distributed ARP Table - add snooping functions for ARP messages Antonio Quartulli
2011-10-30  9:18   ` Sven Eckelmann
2011-10-30  9:29     ` Antonio Quartulli
2011-10-31  0:12   ` Simon Wunderlich
2011-11-01  9:16     ` Antonio Quartulli
2011-10-30  8:56 ` [B.A.T.M.A.N.] [PATCH 6/6] batman-adv: Distributed ARP Table - increase default soft_iface ARP table timeout Antonio Quartulli
2011-10-31  0:03 ` [B.A.T.M.A.N.] [PATCH 0/6] DAT: Distributed ARP Table Simon Wunderlich
2011-10-31  9:26   ` Martin Hundebøll
2011-10-31  9:42     ` Marek Lindner
2011-10-31  9:48       ` Simon Wunderlich
2011-11-01  9:16         ` Antonio Quartulli
2011-10-31 18:53 ` Gus Wirth
2011-10-31 23:11   ` Simon Wunderlich
2011-11-01  9:10   ` Antonio Quartulli

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1319964962-5092-2-git-send-email-ordex@autistici.org \
    --to=ordex@autistici.org \
    --cc=b.a.t.m.a.n@lists.open-mesh.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).