Skip to contentSkip to conversation

UML - Don't roll my own random MAC generator

PATCH In review Jeff Dike 3 participants 9 messages Sep 28, 2006 – Sep 30, 2006 User-mode Linux (UML)

lore
Share & tools
lore

Jeff Dike

author
#0 lore raw

PATCH 2/2 UML - Don't roll my own random MAC generator

Use the existing random_ether_addr() instead of cooking up my own version. Pointed out by Dave Hollis and Jason Lunz.

---

 arch/um/drivers/net_kern.c |    4 +---
 arch/um/drivers/net_user.c |   29 -----------------------------
 arch/um/include/net_user.h |    2 --
 3 files changed, 1 insertion(+), 34 deletions(-)
arch/um/drivers/net_kern.c +1 -3
Index: linux-2.6.18-mm/arch/um/drivers/net_kern.c
===================================================================
@@ -309,9 +309,7 @@ static void setup_etheraddr(char *str, u
 	return;
 
 random:
-	addr[0] = 0xfe;
-	addr[1] = 0xfd;
-	random_mac(addr);
+	random_ether_addr(addr)
 }
 
 static DEFINE_SPINLOCK(devices_lock);
arch/um/drivers/net_user.c +0 -29
Index: linux-2.6.18-mm/arch/um/drivers/net_user.c
===================================================================
@@ -259,32 +259,3 @@ char *split_if_spec(char *str, ...)
 	va_end(ap);
 	return str;
 }
-
-void random_mac(unsigned char *addr)
-{
-	struct timeval tv;
-	long n;
-	unsigned int seed;
-
-	gettimeofday(&tv, NULL);
-
-	/* Assume that 20 bits of microseconds and 12 bits of the pid are
-	 * reasonably unpredictable.
-	 */
-	seed = tv.tv_usec | (os_getpid() << 20);
-	srandom(seed);
-
-	/* Don't care about endianness here - switching endianness
-	 * just rearranges what are hopefully random numbers.
-	 *
-	 * Assume that RAND_MAX > 65536, so random is called twice and
-	 * we use 16 bits of the result.
-	 */
-	n = random();
-	addr[2] = (n >> 8) & 255;
-	addr[3] = n % 255;
-
-	n = random();
-	addr[4] = (n >> 8) & 255;
-	addr[5] = n % 255;
-}
arch/um/include/net_user.h +0 -2
Index: linux-2.6.18-mm/arch/um/include/net_user.h
===================================================================
@@ -50,6 +50,4 @@ extern char *split_if_spec(char *str, ..
 
 extern int dev_netmask(void *d, void *m);
 
-extern void random_mac(unsigned char *addr);
-
 #endif

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#1 lore raw

This patch as provided breaks my build due to a missing semicolon.

Patch attached.

Ollie

Quoted 76 lines · Jeff Dike

Use the existing random_ether_addr() instead of cooking up my own version. Pointed out by Dave Hollis and Jason Lunz.

---

 arch/um/drivers/net_kern.c |    4 +---
 arch/um/drivers/net_user.c |   29 -----------------------------
 arch/um/include/net_user.h |    2 --
 3 files changed, 1 insertion(+), 34 deletions(-)

Index: linux-2.6.18-mm/arch/um/drivers/net_kern.c
===================================================================

arch/um/drivers/net_kern.c 2006-09-28 13:00:58.000000000 -0400 renamed from arch/um/drivers/net_kern.c 2006-09-28 12:51:50.000000000 -0400 +1 -3
@@ -309,9 +309,7 @@ static void setup_etheraddr(char *str, u
        return;
 
 random:
-       addr[0] = 0xfe;
-       addr[1] = 0xfd;
-       random_mac(addr);
+       random_ether_addr(addr)
 }
 
 static DEFINE_SPINLOCK(devices_lock);

Index: linux-2.6.18-mm/arch/um/drivers/net_user.c
===================================================================

arch/um/drivers/net_user.c 2006-09-28 13:00:06.000000000 -0400 renamed from arch/um/drivers/net_user.c 2006-09-28 12:51:50.000000000 -0400 +0 -29
@@ -259,32 +259,3 @@ char *split_if_spec(char *str, ...)
        va_end(ap);
        return str;
 }
-
-void random_mac(unsigned char *addr)
-{
-       struct timeval tv;
-       long n;
-       unsigned int seed;
-
-       gettimeofday(&tv, NULL);
-
-       /* Assume that 20 bits of microseconds and 12 bits of the pid are
-        * reasonably unpredictable.
-        */
-       seed = tv.tv_usec | (os_getpid() << 20);
-       srandom(seed);
-
-       /* Don't care about endianness here - switching endianness
-        * just rearranges what are hopefully random numbers.
-        *
-        * Assume that RAND_MAX > 65536, so random is called twice and
-        * we use 16 bits of the result.
-        */
-       n = random();
-       addr[2] = (n >> 8) & 255;
-       addr[3] = n % 255;
-
-       n = random();
-       addr[4] = (n >> 8) & 255;
-       addr[5] = n % 255;
-}

Index: linux-2.6.18-mm/arch/um/include/net_user.h
===================================================================

arch/um/include/net_user.h 2006-09-28 13:01:51.000000000 -0400 renamed from arch/um/include/net_user.h 2006-09-28 12:15:48.000000000 -0400 +0 -3
@@ -50,6 +50,4 @@ extern char *split_if_spec(char *str, ..
 
 extern int dev_netmask(void *d, void *m);
 
-extern void random_mac(unsigned char *addr);
-
 #endif
 
-
Quoted 5 lines

To unsubscribe from this list: send the line "unsubscribe linux-kernel" in the body of a message to [email protected]
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/

arch/um/drivers/net_kern.c +1 -1
index 16aa572..300a54a 100644
@@ -310,7 +310,7 @@ static void setup_etheraddr(char *str, u
 	return;
 
 random:
-	random_ether_addr(addr)
+	random_ether_addr(addr);
 }
 
 static DEFINE_SPINLOCK(devices_lock);

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV

_______________________________________________
User-mode-linux-devel mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#2 lore raw

arch/um/drivers/net_kern.c static void setup_etheraddr(char *str, u · line 313

Quoted 6 lines · On Fri, 29 Sep 2006 15:18:52 -0700 "Ollie Wild" <[email protected]> wrote:

This patch as provided breaks my build due to a missing semicolon.

..

arch/um/drivers/net_kern.c +1 -1
-	random_ether_addr(addr)
+	random_ether_addr(addr);

ahem. That must have had a lot of testing ;)

Jeff, could we pleeeeeze arrange for UML's `make allmodconfig' to work, and to continue to work?

Right now it goes splut with

arch/um/os-Linux/sys-x86_64/registers.c: In function 'get_thread_regs':
arch/um/os-Linux/sys-x86_64/registers.c:85: error: 'JB_PC' undeclared (first use in this function) arch/um/os-Linux/sys-x86_64/registers.c:85: error: (Each undeclared identifier is reported only once arch/um/os-Linux/sys-x86_64/registers.c:85: error: for each function it appears in.) arch/um/os-Linux/sys-x86_64/registers.c:86: error: 'JB_RSP' undeclared (first use in this function) arch/um/os-Linux/sys-x86_64/registers.c:87: error: 'JB_RBP' undeclared (first use in this function)

How does one build uml-for-i386 on an x86_64 host, btw?

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#3 lore raw

You can use "make ARCH=um SUBARCH=i386 .." to build for i386.

Ollie

Quoted 27 lines · Andrew Morton

arch/um/drivers/net_kern.c static void setup_etheraddr(char *str, u · line 313

Quoted 6 lines · On Fri, 29 Sep 2006 15:18:52 -0700 "Ollie Wild" <[email protected]> wrote:

This patch as provided breaks my build due to a missing semicolon.

..

arch/um/drivers/net_kern.c +1 -1
-     random_ether_addr(addr)
+     random_ether_addr(addr);

ahem. That must have had a lot of testing ;)

Jeff, could we pleeeeeze arrange for UML's `make allmodconfig' to work, and to continue to work?

Right now it goes splut with

arch/um/os-Linux/sys-x86_64/registers.c: In function 'get_thread_regs':
arch/um/os-Linux/sys-x86_64/registers.c:85: error: 'JB_PC' undeclared (first use in this function) arch/um/os-Linux/sys-x86_64/registers.c:85: error: (Each undeclared identifier is reported only once arch/um/os-Linux/sys-x86_64/registers.c:85: error: for each function it appears in.) arch/um/os-Linux/sys-x86_64/registers.c:86: error: 'JB_RSP' undeclared (first use in this function) arch/um/os-Linux/sys-x86_64/registers.c:87: error: 'JB_RBP' undeclared (first use in this function)

How does one build uml-for-i386 on an x86_64 host, btw?

#4 lore raw
Quoted 1 line · On Fri, 29 Sep 2006 15:48:04 -0700 "Ollie Wild" <[email protected]> wrote:

You can use "make ARCH=um SUBARCH=i386 .." to build for i386.

OIC, thanks.

I still get:

arch/um/os-Linux/sys-i386/registers.c: In function 'get_thread_regs':
arch/um/os-Linux/sys-i386/registers.c:137: error: 'JB_PC' undeclared (first use in this function) arch/um/os-Linux/sys-i386/registers.c:137: error: (Each undeclared identifier is reported only once arch/um/os-Linux/sys-i386/registers.c:137: error: for each function it appears in.) arch/um/os-Linux/sys-i386/registers.c:138: error: 'JB_SP' undeclared (first use in this function) arch/um/os-Linux/sys-i386/registers.c:139: error: 'JB_BP' undeclared (first use in this function)

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#5 lore raw
Quoted 6 lines · Andrew Morton

arch/um/os-Linux/sys-i386/registers.c: In function 'get_thread_regs':
arch/um/os-Linux/sys-i386/registers.c:137: error: 'JB_PC' undeclared (first use in this function) arch/um/os-Linux/sys-i386/registers.c:137: error: (Each undeclared identifier is reported only once arch/um/os-Linux/sys-i386/registers.c:137: error: for each function it appears in.) arch/um/os-Linux/sys-i386/registers.c:138: error: 'JB_SP' undeclared (first use in this function) arch/um/os-Linux/sys-i386/registers.c:139: error: 'JB_BP' undeclared (first use in this function)

Hmmm, I never tried a cross-build before, but I don't even get this far:

CC arch/um/sys-i386/user-offsets.s
In file included from /usr/include/features.h:352,

                 from /usr/include/stdio.h:28,
                 from /home/jdike/linux/2.6/linux-2.6.17/arch/um/sys-i386/user-\offsets.c:1:

/usr/include/gnu/stubs.h:7:27: error: gnu/stubs-32.h: No such file or directory m

I just flew into Ohio and am not in any shape to debug this atm. I'll have another look tomorrow.

Jeff

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#6 lore raw
In reply to Andrew Morton
Quoted 1 line · Andrew Morton

ahem. That must have had a lot of testing ;)

It did have some - just missed a patch refresh.

Quoted 2 lines

Jeff, could we pleeeeeze arrange for UML's `make allmodconfig' to work, and to continue to work?

It works for me - I haven't built -mm2 on x86_64 yet, but I'll check that.

Jeff

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

#7 lore raw
Quoted 4 lines · On Fri, 29 Sep 2006 23:52:34 -0400 Jeff Dike <[email protected]> wrote:
Quoted 2 lines

Jeff, could we pleeeeeze arrange for UML's `make allmodconfig' to work, and to continue to work?

It works for me - I haven't built -mm2 on x86_64 yet, but I'll check that.

that was mainline. Perhaps a toolchain thing?

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel

author
#8 lore raw
In reply to Ollie Wild
Quoted 3 lines · Ollie Wild

This patch as provided breaks my build due to a missing semicolon.

Patch attached.

Thanks - I fixed that, but forgot to refresh the patch.

Jeff

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
User-mode-linux-devel mailing list [email protected]
https://lists.sourceforge.net/lists/listinfo/user-mode-linux-devel