[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
[Qemu-devel] [PATCH] Random MAC address option
From: |
Pavel Vasilyev |
Subject: |
[Qemu-devel] [PATCH] Random MAC address option |
Date: |
Tue, 27 Jan 2009 03:13:18 +0300 |
User-agent: |
KMail/1.9.10 |
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)
macrandom.patch
Description: Text Data
signature.asc
Description: This is a digitally signed message part.
- [Qemu-devel] [PATCH] Random MAC address option,
Pavel Vasilyev <=