--- qemu-0.6.1/vl.c 2004-11-14 15:51:33.000000000 -0500 +++ qemu-0.6.1-mod/vl.c 2005-04-23 18:33:03.000000000 -0500 @@ -1622,10 +1622,10 @@ qemu_add_fd_read_handler(nd->fd, fd_can_read, fd_read, opaque); } -static int net_tun_init(NetDriverState *nd) +static int net_tun_init(NetDriverState *nd, int *IDs,char *IP) { int pid, status; - char *args[3]; + char *args[6]; char **parg; nd->fd = tun_open(nd->ifname, sizeof(nd->ifname)); @@ -1636,9 +1636,16 @@ pid = fork(); if (pid >= 0) { if (pid == 0) { + char a[5],b[5]; parg = args; *parg++ = network_script; *parg++ = nd->ifname; + sprintf(a, "%d", *IDs); + *parg++ = a; + IDs++; + sprintf(b, "%d", *IDs); + *parg++ = b; + *parg++ = IP; *parg++ = NULL; execv(network_script, args); exit(1); @@ -2512,6 +2519,14 @@ "Network options:\n" "-nics n simulate 'n' network cards [default=1]\n" "-macaddr addr set the mac address of the first interface\n" + "-macaddr0 addr set the mac address of the first interface\n" + "-macaddr1 addr set the mac address of the second interface\n" + "-macaddr2 addr set the mac address of the third interface\n" + "-macaddr3 addr set the mac address of the fourth interface\n" + "-macaddr4 addr set the mac address of the fifth interface\n" + "-macaddr5 addr set the mac address of the sixth interface\n" + "-ID1 identifier extra ID passed to host script\n" + "-ID2 identifier extra ID passed to host script\n" "-n script set tap/tun network init script [default=%s]\n" "-tun-fd fd use this fd as already opened tap/tun interface\n" #ifdef CONFIG_SLIRP @@ -2593,7 +2608,15 @@ QEMU_OPTION_enable_audio, QEMU_OPTION_nics, + QEMU_OPTION_ID1, + QEMU_OPTION_ID2, QEMU_OPTION_macaddr, + QEMU_OPTION_macaddr0, + QEMU_OPTION_macaddr1, + QEMU_OPTION_macaddr2, + QEMU_OPTION_macaddr3, + QEMU_OPTION_macaddr4, + QEMU_OPTION_macaddr5, QEMU_OPTION_n, QEMU_OPTION_tun_fd, QEMU_OPTION_user_net, @@ -2649,7 +2672,15 @@ { "enable-audio", 0, QEMU_OPTION_enable_audio }, { "nics", HAS_ARG, QEMU_OPTION_nics}, + { "ID1", HAS_ARG, QEMU_OPTION_ID1}, + { "ID2", HAS_ARG, QEMU_OPTION_ID2}, { "macaddr", HAS_ARG, QEMU_OPTION_macaddr}, + { "macaddr0", HAS_ARG, QEMU_OPTION_macaddr0}, + { "macaddr1", HAS_ARG, QEMU_OPTION_macaddr1}, + { "macaddr2", HAS_ARG, QEMU_OPTION_macaddr2}, + { "macaddr3", HAS_ARG, QEMU_OPTION_macaddr3}, + { "macaddr4", HAS_ARG, QEMU_OPTION_macaddr4}, + { "macaddr5", HAS_ARG, QEMU_OPTION_macaddr4}, { "n", HAS_ARG, QEMU_OPTION_n }, { "tun-fd", HAS_ARG, QEMU_OPTION_tun_fd }, #ifdef CONFIG_SLIRP @@ -2747,6 +2778,7 @@ int use_gdbstub, gdbstub_port; #endif int i, has_cdrom; + int IDs[2]; int snapshot, linux_boot; CPUState *env; const char *initrd_filename; @@ -2756,6 +2788,7 @@ int cyls, heads, secs; int start_emulation = 1; uint8_t macaddr[6]; + uint8_t macaddrs[6][6]; int net_if_type, nb_tun_fds, tun_fds[MAX_NICS]; int optind; const char *r, *optarg; @@ -2805,6 +2838,15 @@ macaddr[3] = 0x12; macaddr[4] = 0x34; macaddr[5] = 0x56; + /* default IDs are 0 */ + IDs[0]=IDs[1]=0; + + for (i = 0; i < 6; i++) { + int j; + for (j = 0; j < 6; j++) { + macaddrs[i][j] = 0xFF; + } + } optind = 1; for(;;) { @@ -2932,6 +2974,16 @@ exit(1); } break; + case QEMU_OPTION_ID1: + { + IDs[0]=atoi(optarg); + } + break; + case QEMU_OPTION_ID2: + { + IDs[1]=atoi(optarg); + } + break; case QEMU_OPTION_macaddr: { const char *p; @@ -2953,6 +3005,126 @@ } } break; + case QEMU_OPTION_macaddr0: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[0][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; + case QEMU_OPTION_macaddr1: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[1][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; + case QEMU_OPTION_macaddr2: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[2][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; + case QEMU_OPTION_macaddr3: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[3][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; + case QEMU_OPTION_macaddr4: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[4][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; + case QEMU_OPTION_macaddr5: + { + const char *p; + int i; + p = optarg; + for(i = 0; i < 6; i++) { + macaddrs[5][i] = strtol(p, (char **)&p, 16); + if (i == 5) { + if (*p != '\0') + goto macaddr_error; + } else { + if (*p != ':') { + fprintf(stderr, "qemu: invalid syntax for ethernet address\n"); + exit(1); + } + p++; + } + } + } + break; #ifdef CONFIG_SLIRP case QEMU_OPTION_tftp: tftp_prefix = optarg; @@ -3132,13 +3304,25 @@ for(i = 0; i < nb_nics; i++) { NetDriverState *nd = &nd_table[i]; nd->index = i; + char IP[256]; + memset(IP,0,256); /* init virtual mac address */ - nd->macaddr[0] = macaddr[0]; - nd->macaddr[1] = macaddr[1]; - nd->macaddr[2] = macaddr[2]; - nd->macaddr[3] = macaddr[3]; - nd->macaddr[4] = macaddr[4]; - nd->macaddr[5] = macaddr[5] + i; + if (macaddrs[i][0] == 0xFF) { + nd->macaddr[0] = macaddr[0]; + nd->macaddr[1] = macaddr[1]; + nd->macaddr[2] = macaddr[2]; + nd->macaddr[3] = macaddr[3]; + nd->macaddr[4] = macaddr[4]; + nd->macaddr[5] = macaddr[5] + i; + } else { + nd->macaddr[0] = macaddrs[i][0]; + nd->macaddr[1] = macaddrs[i][1]; + nd->macaddr[2] = macaddrs[i][2]; + nd->macaddr[3] = macaddrs[i][3]; + nd->macaddr[4] = macaddrs[i][4]; + nd->macaddr[5] = macaddrs[i][5]; + sprintf(IP, "%d.%d.%d.%d", nd->macaddr[2],nd->macaddr[3],nd->macaddr[4],nd->macaddr[5]); + } switch(net_if_type) { #if defined(CONFIG_SLIRP) case NET_IF_USER: @@ -3150,7 +3334,7 @@ if (i < nb_tun_fds) { net_fd_init(nd, tun_fds[i]); } else { - if (net_tun_init(nd) < 0) + if (net_tun_init(nd, IDs,IP) < 0) net_dummy_init(nd); } break;