Revision b946a153 net.c
b/net.c | ||
---|---|---|
333 | 333 |
const char *name, |
334 | 334 |
IOReadHandler *fd_read, |
335 | 335 |
IOCanRWHandler *fd_can_read, |
336 |
NetCleanup *cleanup, |
|
336 | 337 |
void *opaque) |
337 | 338 |
{ |
338 | 339 |
VLANClientState *vc, **pvc; |
... | ... | |
344 | 345 |
vc->name = assign_name(vc, model); |
345 | 346 |
vc->fd_read = fd_read; |
346 | 347 |
vc->fd_can_read = fd_can_read; |
348 |
vc->cleanup = cleanup; |
|
347 | 349 |
vc->opaque = opaque; |
348 | 350 |
vc->vlan = vlan; |
349 | 351 |
|
... | ... | |
362 | 364 |
while (*pvc != NULL) |
363 | 365 |
if (*pvc == vc) { |
364 | 366 |
*pvc = vc->next; |
367 |
if (vc->cleanup) { |
|
368 |
vc->cleanup(vc); |
|
369 |
} |
|
365 | 370 |
free(vc->name); |
366 | 371 |
free(vc->model); |
367 | 372 |
free(vc); |
... | ... | |
521 | 526 |
slirp_init(slirp_restrict, slirp_ip); |
522 | 527 |
} |
523 | 528 |
slirp_vc = qemu_new_vlan_client(vlan, model, name, |
524 |
slirp_receive, NULL, NULL); |
|
529 |
slirp_receive, NULL, NULL, NULL);
|
|
525 | 530 |
slirp_vc->info_str[0] = '\0'; |
526 | 531 |
return 0; |
527 | 532 |
} |
... | ... | |
702 | 707 |
char down_script_arg[128]; |
703 | 708 |
} TAPState; |
704 | 709 |
|
710 |
static int launch_script(const char *setup_script, const char *ifname, int fd); |
|
711 |
|
|
705 | 712 |
static ssize_t tap_receive_iov(void *opaque, const struct iovec *iov, |
706 | 713 |
int iovcnt) |
707 | 714 |
{ |
... | ... | |
748 | 755 |
} |
749 | 756 |
} |
750 | 757 |
|
758 |
static void tap_cleanup(VLANClientState *vc) |
|
759 |
{ |
|
760 |
TAPState *s = vc->opaque; |
|
761 |
|
|
762 |
if (s->down_script[0]) |
|
763 |
launch_script(s->down_script, s->down_script_arg, s->fd); |
|
764 |
|
|
765 |
qemu_set_fd_handler(s->fd, NULL, NULL, NULL); |
|
766 |
close(s->fd); |
|
767 |
qemu_free(s); |
|
768 |
} |
|
769 |
|
|
751 | 770 |
/* fd support */ |
752 | 771 |
|
753 | 772 |
static TAPState *net_tap_fd_init(VLANState *vlan, |
... | ... | |
759 | 778 |
|
760 | 779 |
s = qemu_mallocz(sizeof(TAPState)); |
761 | 780 |
s->fd = fd; |
762 |
s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, NULL, s); |
|
781 |
s->vc = qemu_new_vlan_client(vlan, model, name, tap_receive, |
|
782 |
NULL, tap_cleanup, s); |
|
763 | 783 |
s->vc->fd_readv = tap_receive_iov; |
764 | 784 |
qemu_set_fd_handler(s->fd, tap_send, NULL, s); |
765 | 785 |
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "fd=%d", fd); |
... | ... | |
1058 | 1078 |
} |
1059 | 1079 |
} |
1060 | 1080 |
|
1081 |
static void vde_cleanup(VLANClientState *vc) |
|
1082 |
{ |
|
1083 |
VDEState *s = vc->opaque; |
|
1084 |
qemu_set_fd_handler(vde_datafd(s->vde), NULL, NULL, NULL); |
|
1085 |
vde_close(s->vde); |
|
1086 |
qemu_free(s); |
|
1087 |
} |
|
1088 |
|
|
1061 | 1089 |
static int net_vde_init(VLANState *vlan, const char *model, |
1062 | 1090 |
const char *name, const char *sock, |
1063 | 1091 |
int port, const char *group, int mode) |
... | ... | |
1078 | 1106 |
free(s); |
1079 | 1107 |
return -1; |
1080 | 1108 |
} |
1081 |
s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, NULL, s); |
|
1109 |
s->vc = qemu_new_vlan_client(vlan, model, name, vde_from_qemu, |
|
1110 |
NULL, vde_cleanup, s); |
|
1082 | 1111 |
qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s); |
1083 | 1112 |
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "sock=%s,fd=%d", |
1084 | 1113 |
sock, vde_datafd(s->vde)); |
... | ... | |
1263 | 1292 |
return -1; |
1264 | 1293 |
} |
1265 | 1294 |
|
1295 |
static void net_socket_cleanup(VLANClientState *vc) |
|
1296 |
{ |
|
1297 |
NetSocketState *s = vc->opaque; |
|
1298 |
qemu_set_fd_handler(s->fd, NULL, NULL, NULL); |
|
1299 |
close(s->fd); |
|
1300 |
qemu_free(s); |
|
1301 |
} |
|
1302 |
|
|
1266 | 1303 |
static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, |
1267 | 1304 |
const char *model, |
1268 | 1305 |
const char *name, |
... | ... | |
1307 | 1344 |
s = qemu_mallocz(sizeof(NetSocketState)); |
1308 | 1345 |
s->fd = fd; |
1309 | 1346 |
|
1310 |
s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, NULL, s); |
|
1347 |
s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive_dgram, |
|
1348 |
NULL, net_socket_cleanup, s); |
|
1311 | 1349 |
qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s); |
1312 | 1350 |
|
1313 | 1351 |
/* mcast: save bound address as dst */ |
... | ... | |
1334 | 1372 |
NetSocketState *s; |
1335 | 1373 |
s = qemu_mallocz(sizeof(NetSocketState)); |
1336 | 1374 |
s->fd = fd; |
1337 |
s->vc = qemu_new_vlan_client(vlan, model, name, |
|
1338 |
net_socket_receive, NULL, s);
|
|
1375 |
s->vc = qemu_new_vlan_client(vlan, model, name, net_socket_receive,
|
|
1376 |
NULL, net_socket_cleanup, s);
|
|
1339 | 1377 |
snprintf(s->vc->info_str, sizeof(s->vc->info_str), |
1340 | 1378 |
"socket: fd=%d", fd); |
1341 | 1379 |
if (is_connected) { |
... | ... | |
1895 | 1933 |
|
1896 | 1934 |
void net_cleanup(void) |
1897 | 1935 |
{ |
1898 |
#if !defined(_WIN32) |
|
1899 | 1936 |
VLANState *vlan; |
1900 | 1937 |
|
1901 | 1938 |
/* close network clients */ |
1902 | 1939 |
for(vlan = first_vlan; vlan != NULL; vlan = vlan->next) { |
1903 |
VLANClientState *vc; |
|
1940 |
VLANClientState *vc = vlan->first_client;
|
|
1904 | 1941 |
|
1905 |
for(vc = vlan->first_client; vc != NULL; vc = vc->next) { |
|
1906 |
if (vc->fd_read == tap_receive) { |
|
1907 |
TAPState *s = vc->opaque; |
|
1942 |
while (vc) { |
|
1943 |
VLANClientState *next = vc->next; |
|
1908 | 1944 |
|
1909 |
if (s->down_script[0]) |
|
1910 |
launch_script(s->down_script, s->down_script_arg, s->fd); |
|
1911 |
} |
|
1912 |
#if defined(CONFIG_VDE) |
|
1913 |
if (vc->fd_read == vde_from_qemu) { |
|
1914 |
VDEState *s = vc->opaque; |
|
1915 |
vde_close(s->vde); |
|
1916 |
} |
|
1917 |
#endif |
|
1945 |
qemu_del_vlan_client(vc); |
|
1946 |
|
|
1947 |
vc = next; |
|
1918 | 1948 |
} |
1919 | 1949 |
} |
1920 |
#endif |
|
1921 | 1950 |
} |
1922 | 1951 |
|
1923 | 1952 |
void net_client_check(void) |
Also available in: Unified diff