Commit 7a9f6e4a8db958caf10332f160ed04f175932d55

Authored by aliguori
1 parent 96d5e201

Add a -net name=foo parameter (Mark McLoughlin)

Allow the user to supply a vlan client name on the command line.

This is probably only useful for management tools so that they can
use their own names rather than parsing the output of 'info network'.

Signed-off-by: Mark McLoughlin <markmc@redhat.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>



git-svn-id: svn://svn.savannah.nongnu.org/qemu/trunk@6220 c046a42c-6fe2-441c-8c8c-71466251a162
hw/e1000.c
... ... @@ -1071,7 +1071,7 @@ pci_e1000_init(PCIBus *bus, NICInfo *nd, int devfn)
1071 1071 d->rxbuf_min_shift = 1;
1072 1072 memset(&d->tx, 0, sizeof d->tx);
1073 1073  
1074   - d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  1074 + d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
1075 1075 e1000_receive, e1000_can_receive, d);
1076 1076  
1077 1077 qemu_format_nic_info_str(d->vc, d->nd->macaddr);
... ...
hw/eepro100.c
... ... @@ -1776,7 +1776,7 @@ static void nic_init(PCIBus * bus, NICInfo * nd,
1776 1776  
1777 1777 nic_reset(s);
1778 1778  
1779   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  1779 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
1780 1780 nic_receive, nic_can_receive, s);
1781 1781  
1782 1782 qemu_format_nic_info_str(s->vc, s->macaddr);
... ...
hw/etraxfs_eth.c
... ... @@ -572,7 +572,7 @@ void *etraxfs_eth_init(NICInfo *nd, CPUState *env,
572 572 eth->ethregs = cpu_register_io_memory(0, eth_read, eth_write, eth);
573 573 cpu_register_physical_memory (base, 0x5c, eth->ethregs);
574 574  
575   - eth->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  575 + eth->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
576 576 eth_receive, eth_can_receive, eth);
577 577  
578 578 return dma;
... ...
hw/mcf_fec.c
... ... @@ -452,7 +452,7 @@ void mcf_fec_init(NICInfo *nd, target_phys_addr_t base, qemu_irq *irq)
452 452 mcf_fec_writefn, s);
453 453 cpu_register_physical_memory(base, 0x400, iomemtype);
454 454  
455   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  455 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
456 456 mcf_fec_receive, mcf_fec_can_receive, s);
457 457 memcpy(s->macaddr, nd->macaddr, 6);
458 458 qemu_format_nic_info_str(n->vc, s->macaddr);
... ...
hw/mipsnet.c
... ... @@ -250,7 +250,7 @@ void mipsnet_init (int base, qemu_irq irq, NICInfo *nd)
250 250 s->irq = irq;
251 251 s->nd = nd;
252 252 if (nd && nd->vlan) {
253   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  253 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
254 254 mipsnet_receive, mipsnet_can_receive, s);
255 255 } else {
256 256 s->vc = NULL;
... ...
hw/musicpal.c
... ... @@ -718,7 +718,7 @@ static void mv88w8618_eth_init(NICInfo *nd, uint32_t base, qemu_irq irq)
718 718 if (!s)
719 719 return;
720 720 s->irq = irq;
721   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  721 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
722 722 eth_receive, eth_can_receive, s);
723 723 iomemtype = cpu_register_io_memory(0, mv88w8618_eth_readfn,
724 724 mv88w8618_eth_writefn, s);
... ...
hw/ne2000.c
... ... @@ -741,7 +741,7 @@ void isa_ne2000_init(int base, qemu_irq irq, NICInfo *nd)
741 741  
742 742 ne2000_reset(s);
743 743  
744   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  744 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
745 745 ne2000_receive, ne2000_can_receive, s);
746 746  
747 747 qemu_format_nic_info_str(s->vc, s->macaddr);
... ... @@ -804,7 +804,7 @@ void pci_ne2000_init(PCIBus *bus, NICInfo *nd, int devfn)
804 804 s->pci_dev = (PCIDevice *)d;
805 805 memcpy(s->macaddr, nd->macaddr, 6);
806 806 ne2000_reset(s);
807   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  807 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
808 808 ne2000_receive, ne2000_can_receive, s);
809 809  
810 810 qemu_format_nic_info_str(s->vc, s->macaddr);
... ...
hw/pcnet.c
... ... @@ -1936,7 +1936,7 @@ static void pcnet_common_init(PCNetState *d, NICInfo *nd, const char *info_str)
1936 1936 d->nd = nd;
1937 1937  
1938 1938 if (nd && nd->vlan) {
1939   - d->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  1939 + d->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
1940 1940 pcnet_receive, pcnet_can_receive, d);
1941 1941  
1942 1942 qemu_format_nic_info_str(d->vc, d->nd->macaddr);
... ...
hw/rtl8139.c
... ... @@ -3438,7 +3438,7 @@ void pci_rtl8139_init(PCIBus *bus, NICInfo *nd, int devfn)
3438 3438 s->pci_dev = (PCIDevice *)d;
3439 3439 memcpy(s->macaddr, nd->macaddr, 6);
3440 3440 rtl8139_reset(s);
3441   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  3441 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
3442 3442 rtl8139_receive, rtl8139_can_receive, s);
3443 3443  
3444 3444 qemu_format_nic_info_str(s->vc, s->macaddr);
... ...
hw/smc91c111.c
... ... @@ -704,7 +704,7 @@ void smc91c111_init(NICInfo *nd, uint32_t base, qemu_irq irq)
704 704  
705 705 smc91c111_reset(s);
706 706  
707   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  707 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
708 708 smc91c111_receive, smc91c111_can_receive, s);
709 709 qemu_format_nic_info_str(s->vc, s->macaddr);
710 710 /* ??? Save/restore. */
... ...
hw/stellaris_enet.c
... ... @@ -397,7 +397,7 @@ void stellaris_enet_init(NICInfo *nd, uint32_t base, qemu_irq irq)
397 397 memcpy(s->macaddr, nd->macaddr, 6);
398 398  
399 399 if (nd->vlan) {
400   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  400 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
401 401 stellaris_enet_receive, stellaris_enet_can_receive, s);
402 402 qemu_format_nic_info_str(s->vc, s->macaddr);
403 403 }
... ...
hw/usb-net.c
... ... @@ -1453,7 +1453,7 @@ USBDevice *usb_net_init(NICInfo *nd)
1453 1453  
1454 1454 pstrcpy(s->dev.devname, sizeof(s->dev.devname),
1455 1455 "QEMU USB Network Interface");
1456   - s->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  1456 + s->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
1457 1457 usbnet_receive, usbnet_can_receive, s);
1458 1458  
1459 1459 qemu_format_nic_info_str(s->vc, s->mac);
... ...
hw/virtio-net.c
... ... @@ -315,7 +315,7 @@ PCIDevice *virtio_net_init(PCIBus *bus, NICInfo *nd, int devfn)
315 315 n->rx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_rx);
316 316 n->tx_vq = virtio_add_queue(&n->vdev, 256, virtio_net_handle_tx);
317 317 memcpy(n->mac, nd->macaddr, 6);
318   - n->vc = qemu_new_vlan_client(nd->vlan, nd->model,
  318 + n->vc = qemu_new_vlan_client(nd->vlan, nd->model, nd->name,
319 319 virtio_net_receive, virtio_net_can_receive, n);
320 320  
321 321 qemu_format_nic_info_str(n->vc, n->mac);
... ...
... ... @@ -325,6 +325,7 @@ static char *assign_name(VLANClientState *vc1, const char *model)
325 325  
326 326 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
327 327 const char *model,
  328 + const char *name,
328 329 IOReadHandler *fd_read,
329 330 IOCanRWHandler *fd_can_read,
330 331 void *opaque)
... ... @@ -334,7 +335,10 @@ VLANClientState *qemu_new_vlan_client(VLANState *vlan,
334 335 if (!vc)
335 336 return NULL;
336 337 vc->model = strdup(model);
337   - vc->name = assign_name(vc, model);
  338 + if (name)
  339 + vc->name = strdup(name);
  340 + else
  341 + vc->name = assign_name(vc, model);
338 342 vc->fd_read = fd_read;
339 343 vc->fd_can_read = fd_can_read;
340 344 vc->opaque = opaque;
... ... @@ -474,13 +478,13 @@ static void slirp_receive(void *opaque, const uint8_t *buf, int size)
474 478 slirp_input(buf, size);
475 479 }
476 480  
477   -static int net_slirp_init(VLANState *vlan, const char *model)
  481 +static int net_slirp_init(VLANState *vlan, const char *model, const char *name)
478 482 {
479 483 if (!slirp_inited) {
480 484 slirp_inited = 1;
481 485 slirp_init();
482 486 }
483   - slirp_vc = qemu_new_vlan_client(vlan, model,
  487 + slirp_vc = qemu_new_vlan_client(vlan, model, name,
484 488 slirp_receive, NULL, NULL);
485 489 slirp_vc->info_str[0] = '\0';
486 490 return 0;
... ... @@ -694,7 +698,10 @@ static void tap_send(void *opaque)
694 698  
695 699 /* fd support */
696 700  
697   -static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
  701 +static TAPState *net_tap_fd_init(VLANState *vlan,
  702 + const char *model,
  703 + const char *name,
  704 + int fd)
698 705 {
699 706 TAPState *s;
700 707  
... ... @@ -702,7 +709,7 @@ static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
702 709 if (!s)
703 710 return NULL;
704 711 s->fd = fd;
705   - s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
  712 + s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
706 713 #ifdef HAVE_IOVEC
707 714 s->vc->fd_readv = tap_receive_iov;
708 715 #endif
... ... @@ -937,7 +944,8 @@ static int launch_script(const char *setup_script, const char *ifname, int fd)
937 944 return 0;
938 945 }
939 946  
940   -static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
  947 +static int net_tap_init(VLANState *vlan, const char *model,
  948 + const char *name, const char *ifname1,
941 949 const char *setup_script, const char *down_script)
942 950 {
943 951 TAPState *s;
... ... @@ -958,7 +966,7 @@ static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
958 966 if (launch_script(setup_script, ifname, fd))
959 967 return -1;
960 968 }
961   - s = net_tap_fd_init(vlan, model, fd);
  969 + s = net_tap_fd_init(vlan, model, name, fd);
962 970 if (!s)
963 971 return -1;
964 972 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
... ... @@ -1002,7 +1010,8 @@ static void vde_from_qemu(void *opaque, const uint8_t *buf, int size)
1002 1010 }
1003 1011 }
1004 1012  
1005   -static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
  1013 +static int net_vde_init(VLANState *vlan, const char *model,
  1014 + const char *name, const char *sock,
1006 1015 int port, const char *group, int mode)
1007 1016 {
1008 1017 VDEState *s;
... ... @@ -1023,7 +1032,7 @@ static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
1023 1032 free(s);
1024 1033 return -1;
1025 1034 }
1026   - s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
  1035 + s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s);
1027 1036 qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
1028 1037 snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d",
1029 1038 sock, vde_datafd(s->vde));
... ... @@ -1045,6 +1054,7 @@ typedef struct NetSocketState {
1045 1054 typedef struct NetSocketListenState {
1046 1055 VLANState *vlan;
1047 1056 char *model;
  1057 + char *name;
1048 1058 int fd;
1049 1059 } NetSocketListenState;
1050 1060  
... ... @@ -1198,7 +1208,9 @@ fail:
1198 1208 return -1;
1199 1209 }
1200 1210  
1201   -static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
  1211 +static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan,
  1212 + const char *model,
  1213 + const char *name,
1202 1214 int fd, int is_connected)
1203 1215 {
1204 1216 struct sockaddr_in saddr;
... ... @@ -1242,7 +1254,7 @@ static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *mod
1242 1254 return NULL;
1243 1255 s->fd = fd;
1244 1256  
1245   - s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
  1257 + s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s);
1246 1258 qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
1247 1259  
1248 1260 /* mcast: save bound address as dst */
... ... @@ -1261,7 +1273,9 @@ static void net_socket_connect(void *opaque)
1261 1273 qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
1262 1274 }
1263 1275  
1264   -static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
  1276 +static NetSocketState *net_socket_fd_init_stream(VLANState *vlan,
  1277 + const char *model,
  1278 + const char *name,
1265 1279 int fd, int is_connected)
1266 1280 {
1267 1281 NetSocketState *s;
... ... @@ -1269,7 +1283,7 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
1269 1283 if (!s)
1270 1284 return NULL;
1271 1285 s->fd = fd;
1272   - s->vc = qemu_new_vlan_client(vlan, model,
  1286 + s->vc = qemu_new_vlan_client(vlan, model, name,
1273 1287 net_socket_receive, NULL, s);
1274 1288 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
1275 1289 "socket: fd=%d", fd);
... ... @@ -1281,7 +1295,8 @@ static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *mo
1281 1295 return s;
1282 1296 }
1283 1297  
1284   -static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
  1298 +static NetSocketState *net_socket_fd_init(VLANState *vlan,
  1299 + const char *model, const char *name,
1285 1300 int fd, int is_connected)
1286 1301 {
1287 1302 int so_type=-1, optlen=sizeof(so_type);
... ... @@ -1293,13 +1308,13 @@ static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
1293 1308 }
1294 1309 switch(so_type) {
1295 1310 case SOCK_DGRAM:
1296   - return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
  1311 + return net_socket_fd_init_dgram(vlan, model, name, fd, is_connected);
1297 1312 case SOCK_STREAM:
1298   - return net_socket_fd_init_stream(vlan, model, fd, is_connected);
  1313 + return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
1299 1314 default:
1300 1315 /* who knows ... this could be a eg. a pty, do warn and continue as stream */
1301 1316 fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
1302   - return net_socket_fd_init_stream(vlan, model, fd, is_connected);
  1317 + return net_socket_fd_init_stream(vlan, model, name, fd, is_connected);
1303 1318 }
1304 1319 return NULL;
1305 1320 }
... ... @@ -1321,7 +1336,7 @@ static void net_socket_accept(void *opaque)
1321 1336 break;
1322 1337 }
1323 1338 }
1324   - s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
  1339 + s1 = net_socket_fd_init(s->vlan, s->model, s->name, fd, 1);
1325 1340 if (!s1) {
1326 1341 closesocket(fd);
1327 1342 } else {
... ... @@ -1331,7 +1346,9 @@ static void net_socket_accept(void *opaque)
1331 1346 }
1332 1347 }
1333 1348  
1334   -static int net_socket_listen_init(VLANState *vlan, const char *model,
  1349 +static int net_socket_listen_init(VLANState *vlan,
  1350 + const char *model,
  1351 + const char *name,
1335 1352 const char *host_str)
1336 1353 {
1337 1354 NetSocketListenState *s;
... ... @@ -1368,12 +1385,15 @@ static int net_socket_listen_init(VLANState *vlan, const char *model,
1368 1385 }
1369 1386 s->vlan = vlan;
1370 1387 s->model = strdup(model);
  1388 + s->name = strdup(name);
1371 1389 s->fd = fd;
1372 1390 qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
1373 1391 return 0;
1374 1392 }
1375 1393  
1376   -static int net_socket_connect_init(VLANState *vlan, const char *model,
  1394 +static int net_socket_connect_init(VLANState *vlan,
  1395 + const char *model,
  1396 + const char *name,
1377 1397 const char *host_str)
1378 1398 {
1379 1399 NetSocketState *s;
... ... @@ -1412,7 +1432,7 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
1412 1432 break;
1413 1433 }
1414 1434 }
1415   - s = net_socket_fd_init(vlan, model, fd, connected);
  1435 + s = net_socket_fd_init(vlan, model, name, fd, connected);
1416 1436 if (!s)
1417 1437 return -1;
1418 1438 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
... ... @@ -1421,7 +1441,9 @@ static int net_socket_connect_init(VLANState *vlan, const char *model,
1421 1441 return 0;
1422 1442 }
1423 1443  
1424   -static int net_socket_mcast_init(VLANState *vlan, const char *model,
  1444 +static int net_socket_mcast_init(VLANState *vlan,
  1445 + const char *model,
  1446 + const char *name,
1425 1447 const char *host_str)
1426 1448 {
1427 1449 NetSocketState *s;
... ... @@ -1436,7 +1458,7 @@ static int net_socket_mcast_init(VLANState *vlan, const char *model,
1436 1458 if (fd < 0)
1437 1459 return -1;
1438 1460  
1439   - s = net_socket_fd_init(vlan, model, fd, 0);
  1461 + s = net_socket_fd_init(vlan, model, name, fd, 0);
1440 1462 if (!s)
1441 1463 return -1;
1442 1464  
... ... @@ -1474,6 +1496,7 @@ int net_client_init(const char *device, const char *p)
1474 1496 char buf[1024];
1475 1497 int vlan_id, ret;
1476 1498 VLANState *vlan;
  1499 + char *name = NULL;
1477 1500  
1478 1501 vlan_id = 0;
1479 1502 if (get_param_value(buf, sizeof(buf), "vlan", p)) {
... ... @@ -1484,6 +1507,9 @@ int net_client_init(const char *device, const char *p)
1484 1507 fprintf(stderr, "Could not create vlan %d\n", vlan_id);
1485 1508 return -1;
1486 1509 }
  1510 + if (get_param_value(buf, sizeof(buf), "name", p)) {
  1511 + name = strdup(buf);
  1512 + }
1487 1513 if (!strcmp(device, "nic")) {
1488 1514 NICInfo *nd;
1489 1515 uint8_t *macaddr;
... ... @@ -1511,6 +1537,8 @@ int net_client_init(const char *device, const char *p)
1511 1537 nd->model = strdup(buf);
1512 1538 }
1513 1539 nd->vlan = vlan;
  1540 + nd->name = name;
  1541 + name = NULL;
1514 1542 nb_nics++;
1515 1543 vlan->nb_guest_devs++;
1516 1544 ret = 0;
... ... @@ -1526,7 +1554,7 @@ int net_client_init(const char *device, const char *p)
1526 1554 pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
1527 1555 }
1528 1556 vlan->nb_host_devs++;
1529   - ret = net_slirp_init(vlan, device);
  1557 + ret = net_slirp_init(vlan, device, name);
1530 1558 } else
1531 1559 #endif
1532 1560 #ifdef _WIN32
... ... @@ -1537,7 +1565,7 @@ int net_client_init(const char *device, const char *p)
1537 1565 return -1;
1538 1566 }
1539 1567 vlan->nb_host_devs++;
1540   - ret = tap_win32_init(vlan, device, ifname);
  1568 + ret = tap_win32_init(vlan, device, name, ifname);
1541 1569 } else
1542 1570 #elif defined (_AIX)
1543 1571 #else
... ... @@ -1550,7 +1578,7 @@ int net_client_init(const char *device, const char *p)
1550 1578 fd = strtol(buf, NULL, 0);
1551 1579 fcntl(fd, F_SETFL, O_NONBLOCK);
1552 1580 ret = -1;
1553   - if (net_tap_fd_init(vlan, device, fd))
  1581 + if (net_tap_fd_init(vlan, device, name, fd))
1554 1582 ret = 0;
1555 1583 } else {
1556 1584 if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
... ... @@ -1562,7 +1590,7 @@ int net_client_init(const char *device, const char *p)
1562 1590 if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
1563 1591 pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
1564 1592 }
1565   - ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
  1593 + ret = net_tap_init(vlan, device, name, ifname, setup_script, down_script);
1566 1594 }
1567 1595 } else
1568 1596 #endif
... ... @@ -1571,14 +1599,14 @@ int net_client_init(const char *device, const char *p)
1571 1599 int fd;
1572 1600 fd = strtol(buf, NULL, 0);
1573 1601 ret = -1;
1574   - if (net_socket_fd_init(vlan, device, fd, 1))
  1602 + if (net_socket_fd_init(vlan, device, name, fd, 1))
1575 1603 ret = 0;
1576 1604 } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
1577   - ret = net_socket_listen_init(vlan, device, buf);
  1605 + ret = net_socket_listen_init(vlan, device, name, buf);
1578 1606 } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
1579   - ret = net_socket_connect_init(vlan, device, buf);
  1607 + ret = net_socket_connect_init(vlan, device, name, buf);
1580 1608 } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
1581   - ret = net_socket_mcast_init(vlan, device, buf);
  1609 + ret = net_socket_mcast_init(vlan, device, name, buf);
1582 1610 } else {
1583 1611 fprintf(stderr, "Unknown socket options: %s\n", p);
1584 1612 return -1;
... ... @@ -1606,17 +1634,20 @@ int net_client_init(const char *device, const char *p)
1606 1634 } else {
1607 1635 vde_mode = 0700;
1608 1636 }
1609   - ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
  1637 + ret = net_vde_init(vlan, device, name, vde_sock, vde_port, vde_group, vde_mode);
1610 1638 } else
1611 1639 #endif
1612 1640 {
1613 1641 fprintf(stderr, "Unknown network device: %s\n", device);
  1642 + if (name)
  1643 + free(name);
1614 1644 return -1;
1615 1645 }
1616 1646 if (ret < 0) {
1617 1647 fprintf(stderr, "Could not initialize device '%s'\n", device);
1618 1648 }
1619   -
  1649 + if (name)
  1650 + free(name);
1620 1651 return ret;
1621 1652 }
1622 1653  
... ...
... ... @@ -33,6 +33,7 @@ struct VLANState {
33 33 VLANState *qemu_find_vlan(int id);
34 34 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
35 35 const char *model,
  36 + const char *name,
36 37 IOReadHandler *fd_read,
37 38 IOCanRWHandler *fd_can_read,
38 39 void *opaque);
... ... @@ -53,6 +54,7 @@ void do_info_network(void);
53 54 struct NICInfo {
54 55 uint8_t macaddr[6];
55 56 const char *model;
  57 + const char *name;
56 58 VLANState *vlan;
57 59 };
58 60  
... ...
qemu-doc.texi
... ... @@ -608,10 +608,11 @@ Network options:
608 608  
609 609 @table @option
610 610  
611   -@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}]
  611 +@item -net nic[,vlan=@var{n}][,macaddr=@var{addr}][,model=@var{type}][,name=@var{name}]
612 612 Create a new Network Interface Card and connect it to VLAN @var{n} (@var{n}
613 613 = 0 is the default). The NIC is an ne2k_pci by default on the PC
614   -target. Optionally, the MAC address can be changed. If no
  614 +target. Optionally, the MAC address can be changed to @var{addr}
  615 +and a @var{name} can be assigned for use in monitor commands. If no
615 616 @option{-net} option is specified, a single NIC is created.
616 617 Qemu can emulate several different models of network card.
617 618 Valid values for @var{type} are
... ... @@ -621,12 +622,12 @@ Valid values for @var{type} are
621 622 Not all devices are supported on all targets. Use -net nic,model=?
622 623 for a list of available devices for your target.
623 624  
624   -@item -net user[,vlan=@var{n}][,hostname=@var{name}]
  625 +@item -net user[,vlan=@var{n}][,hostname=@var{name}][,name=@var{name}]
625 626 Use the user mode network stack which requires no administrator
626 627 privilege to run. @option{hostname=name} can be used to specify the client
627 628 hostname reported by the builtin DHCP server.
628 629  
629   -@item -net tap[,vlan=@var{n}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
  630 +@item -net tap[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,ifname=@var{name}][,script=@var{file}][,downscript=@var{dfile}]
630 631 Connect the host TAP network interface @var{name} to VLAN @var{n}, use
631 632 the network script @var{file} to configure it and the network script
632 633 @var{dfile} to deconfigure it. If @var{name} is not provided, the OS
... ... @@ -647,7 +648,7 @@ qemu linux.img -net nic,vlan=0 -net tap,vlan=0,ifname=tap0 \
647 648 @end example
648 649  
649 650  
650   -@item -net socket[,vlan=@var{n}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
  651 +@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,listen=[@var{host}]:@var{port}][,connect=@var{host}:@var{port}]
651 652  
652 653 Connect the VLAN @var{n} to a remote VLAN in another QEMU virtual
653 654 machine using a TCP socket connection. If @option{listen} is
... ... @@ -667,7 +668,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:57 \
667 668 -net socket,connect=127.0.0.1:1234
668 669 @end example
669 670  
670   -@item -net socket[,vlan=@var{n}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
  671 +@item -net socket[,vlan=@var{n}][,name=@var{name}][,fd=@var{h}][,mcast=@var{maddr}:@var{port}]
671 672  
672 673 Create a VLAN @var{n} shared with another QEMU virtual
673 674 machines using a UDP multicast socket, effectively making a bus for
... ... @@ -707,7 +708,7 @@ qemu linux.img -net nic,macaddr=52:54:00:12:34:56 \
707 708 /path/to/linux ubd0=/path/to/root_fs eth0=mcast
708 709 @end example
709 710  
710   -@item -net vde[,vlan=@var{n}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
  711 +@item -net vde[,vlan=@var{n}][,name=@var{name}][,sock=@var{socketpath}][,port=@var{n}][,group=@var{groupname}][,mode=@var{octalmode}]
711 712 Connect VLAN @var{n} to PORT @var{n} of a vde switch running on host and
712 713 listening for incoming connections on @var{socketpath}. Use GROUP @var{groupname}
713 714 and MODE @var{octalmode} to change default ownership and permissions for
... ...
sysemu.h
... ... @@ -75,7 +75,8 @@ void qemu_del_wait_object(HANDLE handle, WaitObjectFunc *func, void *opaque);
75 75 #endif
76 76  
77 77 /* TAP win32 */
78   -int tap_win32_init(VLANState *vlan, const char *model, const char *ifname);
  78 +int tap_win32_init(VLANState *vlan, const char *model,
  79 + const char *name, const char *ifname);
79 80  
80 81 /* SLIRP */
81 82 void do_info_slirp(void);
... ...
tap-win32.c
... ... @@ -660,7 +660,8 @@ static void tap_win32_send(void *opaque)
660 660 }
661 661 }
662 662  
663   -int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
  663 +int tap_win32_init(VLANState *vlan, const char *model,
  664 + const char *name, const char *ifname)
664 665 {
665 666 TAPState *s;
666 667  
... ... @@ -672,7 +673,7 @@ int tap_win32_init(VLANState *vlan, const char *model, const char *ifname)
672 673 return -1;
673 674 }
674 675  
675   - s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
  676 + s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s);
676 677  
677 678 snprintf(s->vc->info_str, sizeof(s->vc->info_str),
678 679 "tap: ifname=%s", ifname);
... ...
... ... @@ -3887,30 +3887,30 @@ static void help(int exitcode)
3887 3887 "-uuid %%08x-%%04x-%%04x-%%04x-%%012x specify machine UUID\n"
3888 3888 "\n"
3889 3889 "Network options:\n"
3890   - "-net nic[,vlan=n][,macaddr=addr][,model=type]\n"
  3890 + "-net nic[,vlan=n][,macaddr=addr][,model=type][,name=str]\n"
3891 3891 " create a new Network Interface Card and connect it to VLAN 'n'\n"
3892 3892 #ifdef CONFIG_SLIRP
3893   - "-net user[,vlan=n][,hostname=host]\n"
  3893 + "-net user[,vlan=n][,name=str][,hostname=host]\n"
3894 3894 " connect the user mode network stack to VLAN 'n' and send\n"
3895 3895 " hostname 'host' to DHCP clients\n"
3896 3896 #endif
3897 3897 #ifdef _WIN32
3898   - "-net tap[,vlan=n],ifname=name\n"
  3898 + "-net tap[,vlan=n][,name=str],ifname=name\n"
3899 3899 " connect the host TAP network interface to VLAN 'n'\n"
3900 3900 #else
3901   - "-net tap[,vlan=n][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
  3901 + "-net tap[,vlan=n][,name=str][,fd=h][,ifname=name][,script=file][,downscript=dfile]\n"
3902 3902 " connect the host TAP network interface to VLAN 'n' and use the\n"
3903 3903 " network scripts 'file' (default=%s)\n"
3904 3904 " and 'dfile' (default=%s);\n"
3905 3905 " use '[down]script=no' to disable script execution;\n"
3906 3906 " use 'fd=h' to connect to an already opened TAP interface\n"
3907 3907 #endif
3908   - "-net socket[,vlan=n][,fd=h][,listen=[host]:port][,connect=host:port]\n"
  3908 + "-net socket[,vlan=n][,name=str][,fd=h][,listen=[host]:port][,connect=host:port]\n"
3909 3909 " connect the vlan 'n' to another VLAN using a socket connection\n"
3910   - "-net socket[,vlan=n][,fd=h][,mcast=maddr:port]\n"
  3910 + "-net socket[,vlan=n][,name=str][,fd=h][,mcast=maddr:port]\n"
3911 3911 " connect the vlan 'n' to multicast maddr and port\n"
3912 3912 #ifdef CONFIG_VDE
3913   - "-net vde[,vlan=n][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
  3913 + "-net vde[,vlan=n][,name=str][,sock=socketpath][,port=n][,group=groupname][,mode=octalmode]\n"
3914 3914 " connect the vlan 'n' to port 'n' of a vde switch running\n"
3915 3915 " on host and listening for incoming connections on 'socketpath'.\n"
3916 3916 " Use group 'groupname' and mode 'octalmode' to change default\n"
... ...