Commit 436e5e53c97d8fb469306b18a0c31dc60f5e546c
1 parent
d6aa671f
Add 'set_link' monitor command (Mark McLoughlin)
Add a monitor command to setting a given network device's link status to 'up' or 'down'. Allows simulation of network cable disconnect. 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@6247 c046a42c-6fe2-441c-8c8c-71466251a162
Showing
3 changed files
with
33 additions
and
1 deletions
monitor.c
... | ... | @@ -1516,6 +1516,7 @@ static const term_cmd_t term_cmds[] = { |
1516 | 1516 | "value", "set maximum speed (in bytes) for migrations" }, |
1517 | 1517 | { "balloon", "i", do_balloon, |
1518 | 1518 | "target", "request VM to change it's memory allocation (in MB)" }, |
1519 | + { "set_link", "ss", do_set_link, "name [up|down]" }, | |
1519 | 1520 | { NULL, NULL, }, |
1520 | 1521 | }; |
1521 | 1522 | ... | ... |
net.c
... | ... | @@ -387,12 +387,15 @@ void qemu_send_packet(VLANClientState *vc1, const uint8_t *buf, int size) |
387 | 387 | VLANState *vlan = vc1->vlan; |
388 | 388 | VLANClientState *vc; |
389 | 389 | |
390 | + if (vc1->link_down) | |
391 | + return; | |
392 | + | |
390 | 393 | #ifdef DEBUG_NET |
391 | 394 | printf("vlan %d send:\n", vlan->id); |
392 | 395 | hex_dump(stdout, buf, size); |
393 | 396 | #endif |
394 | 397 | for(vc = vlan->first_client; vc != NULL; vc = vc->next) { |
395 | - if (vc != vc1) { | |
398 | + if (vc != vc1 && !vc->link_down) { | |
396 | 399 | vc->fd_read(vc->opaque, buf, size); |
397 | 400 | } |
398 | 401 | } |
... | ... | @@ -1692,6 +1695,32 @@ void do_info_network(void) |
1692 | 1695 | } |
1693 | 1696 | } |
1694 | 1697 | |
1698 | +int do_set_link(const char *name, const char *up_or_down) | |
1699 | +{ | |
1700 | + VLANState *vlan; | |
1701 | + VLANClientState *vc = NULL; | |
1702 | + | |
1703 | + for (vlan = first_vlan; vlan != NULL; vlan = vlan->next) | |
1704 | + for (vc = vlan->first_client; vc != NULL; vc = vc->next) | |
1705 | + if (strcmp(vc->name, name) == 0) | |
1706 | + break; | |
1707 | + | |
1708 | + if (!vc) { | |
1709 | + term_printf("could not find network device '%s'", name); | |
1710 | + return 0; | |
1711 | + } | |
1712 | + | |
1713 | + if (strcmp(up_or_down, "up") == 0) | |
1714 | + vc->link_down = 0; | |
1715 | + else if (strcmp(up_or_down, "down") == 0) | |
1716 | + vc->link_down = 1; | |
1717 | + else | |
1718 | + term_printf("invalid link status '%s'; only 'up' or 'down' valid\n", | |
1719 | + up_or_down); | |
1720 | + | |
1721 | + return 1; | |
1722 | +} | |
1723 | + | |
1695 | 1724 | void net_cleanup(void) |
1696 | 1725 | { |
1697 | 1726 | VLANState *vlan; | ... | ... |
net.h
... | ... | @@ -15,6 +15,7 @@ struct VLANClientState { |
15 | 15 | /* Packets may still be sent if this returns zero. It's used to |
16 | 16 | rate-limit the slirp code. */ |
17 | 17 | IOCanRWHandler *fd_can_read; |
18 | + int link_down; | |
18 | 19 | void *opaque; |
19 | 20 | struct VLANClientState *next; |
20 | 21 | struct VLANState *vlan; |
... | ... | @@ -46,6 +47,7 @@ void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
46 | 47 | void qemu_handler_true(void *opaque); |
47 | 48 | |
48 | 49 | void do_info_network(void); |
50 | +int do_set_link(const char *name, const char *up_or_down); | |
49 | 51 | |
50 | 52 | /* NIC info */ |
51 | 53 | ... | ... |