b.a.t.m.a.n.lists.open-mesh.org archive mirror
 help / color / mirror / Atom feed
* [B.A.T.M.A.N.] [PATCHv2] batman-adv: Return reason for failure in batadv_check_unicast_packet()
@ 2013-01-13 23:12 Martin Hundebøll
  2013-01-13 23:20 ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Hundebøll @ 2013-01-13 23:12 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

batadv_check_unicast_packet() is changed to return a value based on the
reason to drop the packet, which will be useful information for
future users of batadv_check_unicast_packet().

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
---
v2:
 * Changed return values to defined error codes.
 * Send as separate patch

 routing.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/routing.c b/routing.c
index 1aa1722..a3ee5be 100644
--- a/routing.c
+++ b/routing.c
@@ -552,27 +552,37 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,
 	return router;
 }
 
+/**
+ * batadv_check_unicast_packet - Check for malformed unicast packets
+ * @skb: packet to check
+ * @hdr_size: size of header to pull
+ *
+ * Check for short header and bad addresses in given packet. Returns negative
+ * value when check fails and 0 otherwise. The negative value depends on the
+ * reason: -ENODATA for bad header, -EBADR for broadcast destination or source
+ * source, and -EREMOTE for non-local (other host) destination.
+ */
 static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size)
 {
 	struct ethhdr *ethhdr;
 
 	/* drop packet if it has not necessary minimum size */
 	if (unlikely(!pskb_may_pull(skb, hdr_size)))
-		return -1;
+		return -ENODATA;
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 	/* packet with unicast indication but broadcast recipient */
 	if (is_broadcast_ether_addr(ethhdr->h_dest))
-		return -1;
+		return -EBADR;
 
 	/* packet with broadcast sender address */
 	if (is_broadcast_ether_addr(ethhdr->h_source))
-		return -1;
+		return -EBADR;
 
 	/* not for me */
 	if (!batadv_is_my_mac(ethhdr->h_dest))
-		return -1;
+		return -EREMOTE;
 
 	return 0;
 }
-- 
1.8.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* [B.A.T.M.A.N.] [PATCHv3] batman-adv: Return reason for failure in batadv_check_unicast_packet()
  2013-01-13 23:12 [B.A.T.M.A.N.] [PATCHv2] batman-adv: Return reason for failure in batadv_check_unicast_packet() Martin Hundebøll
@ 2013-01-13 23:20 ` Martin Hundebøll
  2013-01-16  6:01   ` Antonio Quartulli
  0 siblings, 1 reply; 4+ messages in thread
From: Martin Hundebøll @ 2013-01-13 23:20 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

batadv_check_unicast_packet() is changed to return a value based on the
reason to drop the packet, which will be useful information for
future users of batadv_check_unicast_packet().

---
v2:
 * Changed return values to defined error codes.
 * Send as separate patch

v3:
 * Fixed typo in kernel doc

Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
---
 routing.c | 18 ++++++++++++++----
 1 file changed, 14 insertions(+), 4 deletions(-)

diff --git a/routing.c b/routing.c
index 60ba03f..b070163 100644
--- a/routing.c
+++ b/routing.c
@@ -550,27 +550,37 @@ batadv_find_ifalter_router(struct batadv_orig_node *primary_orig,
 	return router;
 }
 
+/**
+ * batadv_check_unicast_packet - Check for malformed unicast packets
+ * @skb: packet to check
+ * @hdr_size: size of header to pull
+ *
+ * Check for short header and bad addresses in given packet. Returns negative
+ * value when check fails and 0 otherwise. The negative value depends on the
+ * reason: -ENODATA for bad header, -EBADR for broadcast destination or source,
+ * and -EREMOTE for non-local (other host) destination.
+ */
 static int batadv_check_unicast_packet(struct sk_buff *skb, int hdr_size)
 {
 	struct ethhdr *ethhdr;
 
 	/* drop packet if it has not necessary minimum size */
 	if (unlikely(!pskb_may_pull(skb, hdr_size)))
-		return -1;
+		return -ENODATA;
 
 	ethhdr = (struct ethhdr *)skb_mac_header(skb);
 
 	/* packet with unicast indication but broadcast recipient */
 	if (is_broadcast_ether_addr(ethhdr->h_dest))
-		return -1;
+		return -EBADR;
 
 	/* packet with broadcast sender address */
 	if (is_broadcast_ether_addr(ethhdr->h_source))
-		return -1;
+		return -EBADR;
 
 	/* not for me */
 	if (!batadv_is_my_mac(ethhdr->h_dest))
-		return -1;
+		return -EREMOTE;
 
 	return 0;
 }
-- 
1.8.1


^ permalink raw reply related	[flat|nested] 4+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: Return reason for failure in batadv_check_unicast_packet()
  2013-01-13 23:20 ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
@ 2013-01-16  6:01   ` Antonio Quartulli
  2013-01-27  5:26     ` Marek Lindner
  0 siblings, 1 reply; 4+ messages in thread
From: Antonio Quartulli @ 2013-01-16  6:01 UTC (permalink / raw)
  To: The list for a Better Approach To Mobile Ad-hoc Networking
  Cc: Martin Hundebøll

[-- Attachment #1: Type: text/plain, Size: 697 bytes --]

On Mon, Jan 14, 2013 at 12:20:32AM +0100, Martin Hundebøll wrote:
> batadv_check_unicast_packet() is changed to return a value based on the
> reason to drop the packet, which will be useful information for
> future users of batadv_check_unicast_packet().
> 
> ---
> v2:
>  * Changed return values to defined error codes.
>  * Send as separate patch
> 
> v3:
>  * Fixed typo in kernel doc
> 
> Signed-off-by: Martin Hundebøll <martin@hundeboll.net>

uhm...This signed-off should be part of the commit message.
But other than this this:

Acked-by: Antonio Quartulli <ordex@autistici.org>

-- 
Antonio Quartulli

..each of us alone is worth nothing..
Ernesto "Che" Guevara

[-- Attachment #2: Type: application/pgp-signature, Size: 836 bytes --]

^ permalink raw reply	[flat|nested] 4+ messages in thread

* Re: [B.A.T.M.A.N.] [PATCHv3] batman-adv: Return reason for failure in batadv_check_unicast_packet()
  2013-01-16  6:01   ` Antonio Quartulli
@ 2013-01-27  5:26     ` Marek Lindner
  0 siblings, 0 replies; 4+ messages in thread
From: Marek Lindner @ 2013-01-27  5:26 UTC (permalink / raw)
  To: b.a.t.m.a.n; +Cc: Martin Hundebøll

On Wednesday, January 16, 2013 14:01:07 Antonio Quartulli wrote:
>   On Mon, Jan 14, 2013 at 12:20:32AM +0100, Martin Hundebøll wrote:
> > batadv_check_unicast_packet() is changed to return a value based on the
> > reason to drop the packet, which will be useful information for
> > future users of batadv_check_unicast_packet().
> >
> > ---
> >
> > v2:
> >  * Changed return values to defined error codes.
> >  * Send as separate patch
> > 
> >
> > v3:
> >  * Fixed typo in kernel doc
> > 
> >
> > Signed-off-by: Martin Hundebøll <martin@hundeboll.net>
> 
> uhm...This signed-off should be part of the commit message.
> But other than this this:
> 
> Acked-by: Antonio Quartulli <ordex@autistici.org>

Applied in revision ff41008.

Thanks,
Marek

^ permalink raw reply	[flat|nested] 4+ messages in thread

end of thread, other threads:[~2013-01-27  5:26 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2013-01-13 23:12 [B.A.T.M.A.N.] [PATCHv2] batman-adv: Return reason for failure in batadv_check_unicast_packet() Martin Hundebøll
2013-01-13 23:20 ` [B.A.T.M.A.N.] [PATCHv3] " Martin Hundebøll
2013-01-16  6:01   ` Antonio Quartulli
2013-01-27  5:26     ` Marek Lindner

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).