From: Pavel Vasilyev <pavel@pavlinux.ru>
To: qemu-devel@nongnu.org
Subject: [Qemu-devel] [PATCH] Random MAC address option
Date: Tue, 27 Jan 2009 03:13:18 +0300 [thread overview]
Message-ID: <200901270313.26331.pavel@pavlinux.ru> (raw)
[-- Attachment #1.1: Type: text/plain, Size: 3818 bytes --]
Index: Makefile.target
===================================================================
--- Makefile.target (revision 6463)
+++ Makefile.target (working copy)
@@ -580,7 +580,8 @@
OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
-CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
+CPPFLAGS +=
+#-DHAS_AUDIO -DHAS_AUDIO_CHOICE
endif
ifeq ($(TARGET_BASE_ARCH), ppc)
CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
Index: net.c
===================================================================
--- net.c (revision 6463)
+++ net.c (working copy)
@@ -122,6 +122,24 @@
static VLANState *first_vlan;
+unsigned long int random_mac_seed(void) {
+
+ unsigned long int seed = 0;
+ int fd;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1) {
+ perror("open");
+ return 0;
+ }
+ if (read(fd, &seed, sizeof (seed)) < 0) {
+ perror("read");
+ seed = 0;
+ }
+ if (close(fd))
+ perror("close");
+ return seed;
+}
/***********************************************************/
/* network device redirectors */
@@ -160,7 +178,7 @@
long int offset;
errno = 0;
- offset = strtol(p, &last_char, 0);
+ offset = strtol(p, &last_char, 0);
if (0 == errno && '\0' == *last_char &&
offset >= 0 && offset <= 0xFFFFFF) {
macaddr[3] = (offset & 0xFF0000) >> 16;
@@ -179,7 +197,7 @@
p++;
}
}
- return 0;
+ return 0;
}
return -1;
@@ -1576,15 +1594,27 @@
fprintf(stderr, "Too Many NICs\n");
return -1;
}
+
nd = &nd_table[nb_nics];
macaddr = nd->macaddr;
- macaddr[0] = 0x52;
- macaddr[1] = 0x54;
- macaddr[2] = 0x00;
- macaddr[3] = 0x12;
- macaddr[4] = 0x34;
- macaddr[5] = 0x56 + nb_nics;
+ if (strstr(p, "macrandom")) {
+ macaddr[0] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[1] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[2] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[3] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[4] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[5] = (uint8_t) (random_mac_seed() % 0x100);
+
+ } else {
+ macaddr[0] = 0x52;
+ macaddr[1] = 0x54;
+ macaddr[2] = 0x00;
+ macaddr[3] = 0x12;
+ macaddr[4] = 0x34;
+ macaddr[5] = 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];
-
+
p = str;
q = device;
while (*p != '\0' && *p != ',') {
Index: net.h
===================================================================
--- net.h (revision 6463)
+++ net.h (working copy)
@@ -52,6 +52,8 @@
const char *default_model);
void qemu_handler_true(void *opaque);
+unsigned long int random_mac_seed(void);
+
void do_info_network(void);
int do_set_link(const char *name, const char *up_or_down);
Index: qemu-malloc.c
===================================================================
--- qemu-malloc.c (revision 6463)
+++ qemu-malloc.c (working copy)
@@ -35,7 +35,7 @@
void *qemu_malloc(size_t size)
{
- return malloc(size);
+ return calloc(1, size);
}
void *qemu_realloc(void *ptr, size_t size)
[-- Attachment #1.2: macrandom.patch --]
[-- Type: text/x-diff, Size: 3818 bytes --]
Index: Makefile.target
===================================================================
--- Makefile.target (revision 6463)
+++ Makefile.target (working copy)
@@ -580,7 +580,8 @@
OBJS+= fdc.o mc146818rtc.o serial.o i8259.o i8254.o pcspk.o pc.o
OBJS+= cirrus_vga.o apic.o parallel.o acpi.o piix_pci.o
OBJS+= usb-uhci.o vmmouse.o vmport.o vmware_vga.o hpet.o
-CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
+CPPFLAGS +=
+#-DHAS_AUDIO -DHAS_AUDIO_CHOICE
endif
ifeq ($(TARGET_BASE_ARCH), ppc)
CPPFLAGS += -DHAS_AUDIO -DHAS_AUDIO_CHOICE
Index: net.c
===================================================================
--- net.c (revision 6463)
+++ net.c (working copy)
@@ -122,6 +122,24 @@
static VLANState *first_vlan;
+unsigned long int random_mac_seed(void) {
+
+ unsigned long int seed = 0;
+ int fd;
+
+ fd = open("/dev/urandom", O_RDONLY);
+ if (fd == -1) {
+ perror("open");
+ return 0;
+ }
+ if (read(fd, &seed, sizeof (seed)) < 0) {
+ perror("read");
+ seed = 0;
+ }
+ if (close(fd))
+ perror("close");
+ return seed;
+}
/***********************************************************/
/* network device redirectors */
@@ -160,7 +178,7 @@
long int offset;
errno = 0;
- offset = strtol(p, &last_char, 0);
+ offset = strtol(p, &last_char, 0);
if (0 == errno && '\0' == *last_char &&
offset >= 0 && offset <= 0xFFFFFF) {
macaddr[3] = (offset & 0xFF0000) >> 16;
@@ -179,7 +197,7 @@
p++;
}
}
- return 0;
+ return 0;
}
return -1;
@@ -1576,15 +1594,27 @@
fprintf(stderr, "Too Many NICs\n");
return -1;
}
+
nd = &nd_table[nb_nics];
macaddr = nd->macaddr;
- macaddr[0] = 0x52;
- macaddr[1] = 0x54;
- macaddr[2] = 0x00;
- macaddr[3] = 0x12;
- macaddr[4] = 0x34;
- macaddr[5] = 0x56 + nb_nics;
+ if (strstr(p, "macrandom")) {
+ macaddr[0] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[1] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[2] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[3] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[4] = (uint8_t) (random_mac_seed() % 0x100);
+ macaddr[5] = (uint8_t) (random_mac_seed() % 0x100);
+
+ } else {
+ macaddr[0] = 0x52;
+ macaddr[1] = 0x54;
+ macaddr[2] = 0x00;
+ macaddr[3] = 0x12;
+ macaddr[4] = 0x34;
+ macaddr[5] = 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];
-
+
p = str;
q = device;
while (*p != '\0' && *p != ',') {
Index: net.h
===================================================================
--- net.h (revision 6463)
+++ net.h (working copy)
@@ -52,6 +52,8 @@
const char *default_model);
void qemu_handler_true(void *opaque);
+unsigned long int random_mac_seed(void);
+
void do_info_network(void);
int do_set_link(const char *name, const char *up_or_down);
Index: qemu-malloc.c
===================================================================
--- qemu-malloc.c (revision 6463)
+++ qemu-malloc.c (working copy)
@@ -35,7 +35,7 @@
void *qemu_malloc(size_t size)
{
- return malloc(size);
+ return calloc(1, size);
}
void *qemu_realloc(void *ptr, size_t size)
[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 194 bytes --]
next reply other threads:[~2009-01-27 0:13 UTC|newest]
Thread overview: 13+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-01-27 0:13 Pavel Vasilyev [this message]
2009-01-27 0:34 ` [Qemu-devel] [PATCH] Replace strcmp() by strncmp() Pavel Vasilyev
2009-01-27 9:28 ` [Qemu-devel] " Jan Kiszka
2009-01-27 20:49 ` Pavel Vasilyev
2009-01-27 21:20 ` Pavel Vasilyev
2009-01-27 0:57 ` [Qemu-devel] [PATCH] Random MAC address option malc
2009-01-27 10:05 ` Kevin Wolf
2009-01-27 10:15 ` Riku Voipio
2009-01-27 10:25 ` Daniel P. Berrange
2009-01-27 14:28 ` Ian Jackson
2009-01-27 20:51 ` Pavel Vasilyev
2009-01-27 16:33 ` Paul Brook
2009-01-27 16:47 ` Anthony Liguori
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200901270313.26331.pavel@pavlinux.ru \
--to=pavel@pavlinux.ru \
--cc=qemu-devel@nongnu.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.