From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1LRba9-0004xn-2o for qemu-devel@nongnu.org; Mon, 26 Jan 2009 19:13:33 -0500 Received: from [199.232.76.173] (port=46577 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1LRba7-0004xf-Q9 for qemu-devel@nongnu.org; Mon, 26 Jan 2009 19:13:31 -0500 Received: from imp01.mtu.ru ([62.5.255.10]:53380) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1LRba7-0004v2-1R for qemu-devel@nongnu.org; Mon, 26 Jan 2009 19:13:31 -0500 Received: from ss27-so04.mtu.ru (localhost [127.0.0.1]) by ss27-so04.mtu.ru (Postfix) with ESMTP id 12AAA39E26D for ; Tue, 27 Jan 2009 03:13:27 +0300 (MSK) Received: from imp01.mtu.ru (alt-proxy-1.mtu.ru [62.5.255.74]) by ss27-so04.mtu.ru (Postfix) with ESMTP id E2B6939E261 for ; Tue, 27 Jan 2009 03:13:26 +0300 (MSK) From: Pavel Vasilyev Date: Tue, 27 Jan 2009 03:13:18 +0300 MIME-Version: 1.0 Content-Type: multipart/signed; boundary="nextPart1531275.n0mC2sJ2MN"; protocol="application/pgp-signature"; micalg=pgp-sha1 Content-Transfer-Encoding: 7bit Message-Id: <200901270313.26331.pavel@pavlinux.ru> Subject: [Qemu-devel] [PATCH] Random MAC address option Reply-To: pavel@pavlinux.ru, qemu-devel@nongnu.org List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: qemu-devel@nongnu.org --nextPart1531275.n0mC2sJ2MN Content-Type: multipart/mixed; boundary="Boundary-01=_eGlfJjqtVoVpgDK" Content-Transfer-Encoding: 7bit Content-Disposition: inline --Boundary-01=_eGlfJjqtVoVpgDK Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Index: Makefile.target =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- Makefile.target (revision 6463) +++ Makefile.target (working copy) @@ -580,7 +580,8 @@ OBJS+=3D fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o OBJS+=3D cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o OBJS+=3D usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o =2DCPPFLAGS +=3D -DHAS_AUDIO -DHAS_AUDIO_CHOICE +CPPFLAGS +=3D=20 +#-DHAS_AUDIO -DHAS_AUDIO_CHOICE endif ifeq ($(TARGET_BASE_ARCH), ppc) CPPFLAGS +=3D -DHAS_AUDIO -DHAS_AUDIO_CHOICE Index: net.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- net.c (revision 6463) +++ net.c (working copy) @@ -122,6 +122,24 @@ =20 static VLANState *first_vlan; =20 +unsigned long int random_mac_seed(void) { + + unsigned long int seed =3D 0; + int fd; + + fd =3D open("/dev/urandom", O_RDONLY); + if (fd =3D=3D -1) { + perror("open"); + return 0; + } + if (read(fd, &seed, sizeof (seed)) < 0) { + perror("read"); + seed =3D 0; + } + if (close(fd)) + perror("close"); + return seed; +} /***********************************************************/ /* network device redirectors */ =20 @@ -160,7 +178,7 @@ long int offset; =20 errno =3D 0; =2D offset =3D strtol(p, &last_char, 0); =20 + offset =3D strtol(p, &last_char, 0); if (0 =3D=3D errno && '\0' =3D=3D *last_char && offset >=3D 0 && offset <=3D 0xFFFFFF) { macaddr[3] =3D (offset & 0xFF0000) >> 16; @@ -179,7 +197,7 @@ p++; } } =2D return 0; =20 + return 0; } =20 return -1; @@ -1576,15 +1594,27 @@ fprintf(stderr, "Too Many NICs\n"); return -1; } + nd =3D &nd_table[nb_nics]; macaddr =3D nd->macaddr; =2D macaddr[0] =3D 0x52; =2D macaddr[1] =3D 0x54; =2D macaddr[2] =3D 0x00; =2D macaddr[3] =3D 0x12; =2D macaddr[4] =3D 0x34; =2D macaddr[5] =3D 0x56 + nb_nics; =20 + if (strstr(p, "macrandom")) { + macaddr[0] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[1] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[2] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[3] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[4] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[5] =3D (uint8_t) (random_mac_seed() % 0x100); + + } else { + macaddr[0] =3D 0x52; + macaddr[1] =3D 0x54; + macaddr[2] =3D 0x00; + macaddr[3] =3D 0x12; + macaddr[4] =3D 0x34; + macaddr[5] =3D 0x56 + nb_nics; + } + if (get_param_value(buf, sizeof(buf), "macaddr", p)) { if (parse_macaddr(macaddr, buf) < 0) { fprintf(stderr, "invalid syntax for ethernet address\n"); @@ -1720,7 +1750,7 @@ const char *p; char *q; char device[64]; =2D + =20 p =3D str; q =3D device; while (*p !=3D '\0' && *p !=3D ',') { Index: net.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- net.h (revision 6463) +++ net.h (working copy) @@ -52,6 +52,8 @@ const char *default_model); void qemu_handler_true(void *opaque); =20 +unsigned long int random_mac_seed(void); + void do_info_network(void); int do_set_link(const char *name, const char *up_or_down); =20 Index: qemu-malloc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- qemu-malloc.c (revision 6463) +++ qemu-malloc.c (working copy) @@ -35,7 +35,7 @@ =20 void *qemu_malloc(size_t size) { =2D return malloc(size); + return calloc(1, size); } =20 void *qemu_realloc(void *ptr, size_t size) --Boundary-01=_eGlfJjqtVoVpgDK Content-Type: text/x-diff; charset="iso 8859-1"; name="macrandom.patch" Content-Transfer-Encoding: quoted-printable Content-Disposition: attachment; filename="macrandom.patch" Index: Makefile.target =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- Makefile.target (revision 6463) +++ Makefile.target (working copy) @@ -580,7 +580,8 @@ OBJS+=3D fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o OBJS+=3D cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o OBJS+=3D usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o =2DCPPFLAGS +=3D -DHAS_AUDIO -DHAS_AUDIO_CHOICE +CPPFLAGS +=3D=20 +#-DHAS_AUDIO -DHAS_AUDIO_CHOICE endif ifeq ($(TARGET_BASE_ARCH), ppc) CPPFLAGS +=3D -DHAS_AUDIO -DHAS_AUDIO_CHOICE Index: net.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- net.c (revision 6463) +++ net.c (working copy) @@ -122,6 +122,24 @@ =20 static VLANState *first_vlan; =20 +unsigned long int random_mac_seed(void) { + + unsigned long int seed =3D 0; + int fd; + + fd =3D open("/dev/urandom", O_RDONLY); + if (fd =3D=3D -1) { + perror("open"); + return 0; + } + if (read(fd, &seed, sizeof (seed)) < 0) { + perror("read"); + seed =3D 0; + } + if (close(fd)) + perror("close"); + return seed; +} /***********************************************************/ /* network device redirectors */ =20 @@ -160,7 +178,7 @@ long int offset; =20 errno =3D 0; =2D offset =3D strtol(p, &last_char, 0); =20 + offset =3D strtol(p, &last_char, 0); if (0 =3D=3D errno && '\0' =3D=3D *last_char && offset >=3D 0 && offset <=3D 0xFFFFFF) { macaddr[3] =3D (offset & 0xFF0000) >> 16; @@ -179,7 +197,7 @@ p++; } } =2D return 0; =20 + return 0; } =20 return -1; @@ -1576,15 +1594,27 @@ fprintf(stderr, "Too Many NICs\n"); return -1; } + nd =3D &nd_table[nb_nics]; macaddr =3D nd->macaddr; =2D macaddr[0] =3D 0x52; =2D macaddr[1] =3D 0x54; =2D macaddr[2] =3D 0x00; =2D macaddr[3] =3D 0x12; =2D macaddr[4] =3D 0x34; =2D macaddr[5] =3D 0x56 + nb_nics; =20 + if (strstr(p, "macrandom")) { + macaddr[0] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[1] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[2] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[3] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[4] =3D (uint8_t) (random_mac_seed() % 0x100); + macaddr[5] =3D (uint8_t) (random_mac_seed() % 0x100); + + } else { + macaddr[0] =3D 0x52; + macaddr[1] =3D 0x54; + macaddr[2] =3D 0x00; + macaddr[3] =3D 0x12; + macaddr[4] =3D 0x34; + macaddr[5] =3D 0x56 + nb_nics; + } + if (get_param_value(buf, sizeof(buf), "macaddr", p)) { if (parse_macaddr(macaddr, buf) < 0) { fprintf(stderr, "invalid syntax for ethernet address\n"); @@ -1720,7 +1750,7 @@ const char *p; char *q; char device[64]; =2D + =20 p =3D str; q =3D device; while (*p !=3D '\0' && *p !=3D ',') { Index: net.h =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- net.h (revision 6463) +++ net.h (working copy) @@ -52,6 +52,8 @@ const char *default_model); void qemu_handler_true(void *opaque); =20 +unsigned long int random_mac_seed(void); + void do_info_network(void); int do_set_link(const char *name, const char *up_or_down); =20 Index: qemu-malloc.c =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D= =3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D=3D =2D-- qemu-malloc.c (revision 6463) +++ qemu-malloc.c (working copy) @@ -35,7 +35,7 @@ =20 void *qemu_malloc(size_t size) { =2D return malloc(size); + return calloc(1, size); } =20 void *qemu_realloc(void *ptr, size_t size) --Boundary-01=_eGlfJjqtVoVpgDK-- --nextPart1531275.n0mC2sJ2MN Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.4-svn0 (GNU/Linux) iD8DBQBJflGmMFsE+gWr1VkRAn9uAJ49oOYRsZfG9rCTGXrUr7dAaHFSoQCfbu1n 4zcCIh94qRL7uMQ5PVAYIoE= =nleu -----END PGP SIGNATURE----- --nextPart1531275.n0mC2sJ2MN--