[v4,1/7] batman-adv: implement an helper function to forge unicast packets

Message ID 1322173279-18338-2-git-send-email-ordex@autistici.org (mailing list archive)
State Superseded, archived
Headers

Commit Message

Antonio Quartulli Nov. 24, 2011, 10:21 p.m. UTC
  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 |   36 ++++++++++++++++++++++++------------
 unicast.h |    1 +
 2 files changed, 25 insertions(+), 12 deletions(-)
  

Comments

Andrew Lunn Nov. 25, 2011, 8:18 a.m. UTC | #1
On Thu, Nov 24, 2011 at 11:21:13PM +0100, Antonio Quartulli wrote:
> 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 |   36 ++++++++++++++++++++++++------------
>  unicast.h |    1 +
>  2 files changed, 25 insertions(+), 12 deletions(-)
> 
> diff --git a/unicast.c b/unicast.c
> index 6f3c659..d49f2cc 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;

When Sven added this header structure, did he also add a function to
fill it in?

     Andrew
  
Sven Eckelmann Nov. 25, 2011, 8:54 a.m. UTC | #2
On Friday 25 November 2011 09:18:20 Andrew Lunn wrote:
[...]
> > +	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;
> 
> When Sven added this header structure, did he also add a function to
> fill it in?

No, I didn't. The header structure part was just the "keep it safe" thing. The 
fancy stuff can come later. And I am not sure whether such a function would be 
useful. More interesting would be the TTL cleanup that Linus proposed a long 
time ago.

Kind regards,
	Sven
  

Patch

diff --git a/unicast.c b/unicast.c
index 6f3c659..d49f2cc 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 8fd5535..63d0305 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)
 {