#endif
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
+ const char *model,
IOReadHandler *fd_read,
IOCanRWHandler *fd_can_read,
void *opaque)
vc = qemu_mallocz(sizeof(VLANClientState));
if (!vc)
return NULL;
+ vc->model = strdup(model);
vc->fd_read = fd_read;
vc->fd_can_read = fd_can_read;
vc->opaque = opaque;
while (*pvc != NULL)
if (*pvc == vc) {
*pvc = vc->next;
+ free(vc->model);
free(vc);
break;
} else
slirp_input(buf, size);
}
-static int net_slirp_init(VLANState *vlan)
+static int net_slirp_init(VLANState *vlan, const char *model)
{
if (!slirp_inited) {
slirp_inited = 1;
slirp_init();
}
- slirp_vc = qemu_new_vlan_client(vlan,
+ slirp_vc = qemu_new_vlan_client(vlan, model,
slirp_receive, NULL, NULL);
snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
return 0;
/* fd support */
-static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
+static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
{
TAPState *s;
if (!s)
return NULL;
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
+ s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
#ifdef HAVE_IOVEC
s->vc->fd_readv = tap_receive_iov;
#endif
return 0;
}
-static int net_tap_init(VLANState *vlan, const char *ifname1,
+static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
const char *setup_script, const char *down_script)
{
TAPState *s;
if (launch_script(setup_script, ifname, fd))
return -1;
}
- s = net_tap_fd_init(vlan, fd);
+ s = net_tap_fd_init(vlan, model, fd);
if (!s)
return -1;
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
}
}
-static int net_vde_init(VLANState *vlan, const char *sock, int port,
- const char *group, int mode)
+static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
+ int port, const char *group, int mode)
{
VDEState *s;
char *init_group = strlen(group) ? (char *)group : NULL;
free(s);
return -1;
}
- s->vc = qemu_new_vlan_client(vlan, vde_from_qemu, NULL, s);
+ s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
sock, vde_datafd(s->vde));
typedef struct NetSocketListenState {
VLANState *vlan;
+ char *model;
int fd;
} NetSocketListenState;
return -1;
}
-static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
- int is_connected)
+static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
+ int fd, int is_connected)
{
struct sockaddr_in saddr;
int newfd;
return NULL;
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, NULL, s);
+ s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
/* mcast: save bound address as dst */
qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
}
-static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
- int is_connected)
+static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
+ int fd, int is_connected)
{
NetSocketState *s;
s = qemu_mallocz(sizeof(NetSocketState));
if (!s)
return NULL;
s->fd = fd;
- s->vc = qemu_new_vlan_client(vlan,
+ s->vc = qemu_new_vlan_client(vlan, model,
net_socket_receive, NULL, s);
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
"socket: fd=%d", fd);
return s;
}
-static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
- int is_connected)
+static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
+ int fd, int is_connected)
{
int so_type=-1, optlen=sizeof(so_type);
}
switch(so_type) {
case SOCK_DGRAM:
- return net_socket_fd_init_dgram(vlan, fd, is_connected);
+ return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
case SOCK_STREAM:
- return net_socket_fd_init_stream(vlan, fd, is_connected);
+ return net_socket_fd_init_stream(vlan, model, fd, is_connected);
default:
/* who knows ... this could be a eg. a pty, do warn and continue as stream */
fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
- return net_socket_fd_init_stream(vlan, fd, is_connected);
+ return net_socket_fd_init_stream(vlan, model, fd, is_connected);
}
return NULL;
}
break;
}
}
- s1 = net_socket_fd_init(s->vlan, fd, 1);
+ s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
if (!s1) {
closesocket(fd);
} else {
}
}
-static int net_socket_listen_init(VLANState *vlan, const char *host_str)
+static int net_socket_listen_init(VLANState *vlan, const char *model,
+ const char *host_str)
{
NetSocketListenState *s;
int fd, val, ret;
return -1;
}
s->vlan = vlan;
+ s->model = strdup(model);
s->fd = fd;
qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
return 0;
}
-static int net_socket_connect_init(VLANState *vlan, const char *host_str)
+static int net_socket_connect_init(VLANState *vlan, const char *model,
+ const char *host_str)
{
NetSocketState *s;
int fd, connected, ret, err;
break;
}
}
- s = net_socket_fd_init(vlan, fd, connected);
+ s = net_socket_fd_init(vlan, model, fd, connected);
if (!s)
return -1;
snprintf(s->vc->info_str, sizeof(s->vc->info_str),
return 0;
}
-static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
+static int net_socket_mcast_init(VLANState *vlan, const char *model,
+ const char *host_str)
{
NetSocketState *s;
int fd;
if (fd < 0)
return -1;
- s = net_socket_fd_init(vlan, fd, 0);
+ s = net_socket_fd_init(vlan, model, fd, 0);
if (!s)
return -1;
pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
}
vlan->nb_host_devs++;
- ret = net_slirp_init(vlan);
+ ret = net_slirp_init(vlan, device);
} else
#endif
#ifdef _WIN32
return -1;
}
vlan->nb_host_devs++;
- ret = tap_win32_init(vlan, ifname);
+ ret = tap_win32_init(vlan, device, ifname);
} else
#elif defined (_AIX)
#else
fd = strtol(buf, NULL, 0);
fcntl(fd, F_SETFL, O_NONBLOCK);
ret = -1;
- if (net_tap_fd_init(vlan, fd))
+ if (net_tap_fd_init(vlan, device, fd))
ret = 0;
} else {
if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
}
- ret = net_tap_init(vlan, ifname, setup_script, down_script);
+ ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
}
} else
#endif
int fd;
fd = strtol(buf, NULL, 0);
ret = -1;
- if (net_socket_fd_init(vlan, fd, 1))
+ if (net_socket_fd_init(vlan, device, fd, 1))
ret = 0;
} else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
- ret = net_socket_listen_init(vlan, buf);
+ ret = net_socket_listen_init(vlan, device, buf);
} else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
- ret = net_socket_connect_init(vlan, buf);
+ ret = net_socket_connect_init(vlan, device, buf);
} else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
- ret = net_socket_mcast_init(vlan, buf);
+ ret = net_socket_mcast_init(vlan, device, buf);
} else {
fprintf(stderr, "Unknown socket options: %s\n", p);
return -1;
} else {
vde_mode = 0700;
}
- ret = net_vde_init(vlan, vde_sock, vde_port, vde_group, vde_mode);
+ ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
} else
#endif
{