diff mbox

[03/11] batman-adv: randomize initial seqno to avoid collision

Message ID 1334663907-22725-4-git-send-email-ordex@autistici.org
State Changes Requested, archived
Delegated to: David Miller
Headers show

Commit Message

Antonio Quartulli April 17, 2012, 11:58 a.m. UTC
From: Marek Lindner <lindner_marek@yahoo.de>

Signed-off-by: Marek Lindner <lindner_marek@yahoo.de>
Signed-off-by: Antonio Quartulli <ordex@autistici.org>
---
 net/batman-adv/bat_iv_ogm.c |    5 +++++
 1 file changed, 5 insertions(+)

Comments

David Miller April 18, 2012, 2:45 a.m. UTC | #1
From: Antonio Quartulli <ordex@autistici.org>
Date: Tue, 17 Apr 2012 13:58:19 +0200

> @@ -33,6 +33,11 @@
>  static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
>  {
>  	struct batman_ogm_packet *batman_ogm_packet;
> +	unsigned long random_seqno;
> +
> +	/* randomize initial seqno to avoid collision */
> +	get_random_bytes(&random_seqno, sizeof(unsigned long));
> +	atomic_set(&hard_iface->seqno, (uint32_t)random_seqno);

This is silly.

Just use "uint32_t" for the type of random_seqno and the sizeof passed
to get_random_bytes.

And here comes the magic part.

Amazing, no ugly and pointless casts needed!
--
To unsubscribe from this list: send the line "unsubscribe netdev" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Antonio Quartulli April 18, 2012, 6:42 a.m. UTC | #2
On Tue, Apr 17, 2012 at 10:45:27 -0400, David Miller wrote:
> From: Antonio Quartulli <ordex@autistici.org>
> Date: Tue, 17 Apr 2012 13:58:19 +0200
> 
> > @@ -33,6 +33,11 @@
> >  static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
> >  {
> >  	struct batman_ogm_packet *batman_ogm_packet;
> > +	unsigned long random_seqno;
> > +
> > +	/* randomize initial seqno to avoid collision */
> > +	get_random_bytes(&random_seqno, sizeof(unsigned long));
> > +	atomic_set(&hard_iface->seqno, (uint32_t)random_seqno);
> 
> This is silly.
> 
> Just use "uint32_t" for the type of random_seqno and the sizeof passed
> to get_random_bytes.
> 
> And here comes the magic part.
> 
> Amazing, no ugly and pointless casts needed!

I agree :-)
Thank you for the suggestion.

Cheers,
diff mbox

Patch

diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
index 117b831..4661bd4 100644
--- a/net/batman-adv/bat_iv_ogm.c
+++ b/net/batman-adv/bat_iv_ogm.c
@@ -33,6 +33,11 @@ 
 static void bat_iv_ogm_iface_enable(struct hard_iface *hard_iface)
 {
 	struct batman_ogm_packet *batman_ogm_packet;
+	unsigned long random_seqno;
+
+	/* randomize initial seqno to avoid collision */
+	get_random_bytes(&random_seqno, sizeof(unsigned long));
+	atomic_set(&hard_iface->seqno, (uint32_t)random_seqno);
 
 	hard_iface->packet_len = BATMAN_OGM_LEN;
 	hard_iface->packet_buff = kmalloc(hard_iface->packet_len, GFP_ATOMIC);