Revision bf38c1a0 net.c

b/net.c
297 297
#endif
298 298

  
299 299
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
300
                                      const char *model,
300 301
                                      IOReadHandler *fd_read,
301 302
                                      IOCanRWHandler *fd_can_read,
302 303
                                      void *opaque)
......
305 306
    vc = qemu_mallocz(sizeof(VLANClientState));
306 307
    if (!vc)
307 308
        return NULL;
309
    vc->model = strdup(model);
308 310
    vc->fd_read = fd_read;
309 311
    vc->fd_can_read = fd_can_read;
310 312
    vc->opaque = opaque;
......
325 327
    while (*pvc != NULL)
326 328
        if (*pvc == vc) {
327 329
            *pvc = vc->next;
330
            free(vc->model);
328 331
            free(vc);
329 332
            break;
330 333
        } else
......
442 445
    slirp_input(buf, size);
443 446
}
444 447

  
445
static int net_slirp_init(VLANState *vlan)
448
static int net_slirp_init(VLANState *vlan, const char *model)
446 449
{
447 450
    if (!slirp_inited) {
448 451
        slirp_inited = 1;
449 452
        slirp_init();
450 453
    }
451
    slirp_vc = qemu_new_vlan_client(vlan,
454
    slirp_vc = qemu_new_vlan_client(vlan, model,
452 455
                                    slirp_receive, NULL, NULL);
453 456
    snprintf(slirp_vc->info_str, sizeof(slirp_vc->info_str), "user redirector");
454 457
    return 0;
......
662 665

  
663 666
/* fd support */
664 667

  
665
static TAPState *net_tap_fd_init(VLANState *vlan, int fd)
668
static TAPState *net_tap_fd_init(VLANState *vlan, const char *model, int fd)
666 669
{
667 670
    TAPState *s;
668 671

  
......
670 673
    if (!s)
671 674
        return NULL;
672 675
    s->fd = fd;
673
    s->vc = qemu_new_vlan_client(vlan, tap_receive, NULL, s);
676
    s->vc = qemu_new_vlan_client(vlan, model, tap_receive, NULL, s);
674 677
#ifdef HAVE_IOVEC
675 678
    s->vc->fd_readv = tap_receive_iov;
676 679
#endif
......
905 908
    return 0;
906 909
}
907 910

  
908
static int net_tap_init(VLANState *vlan, const char *ifname1,
911
static int net_tap_init(VLANState *vlan, const char *model, const char *ifname1,
909 912
                        const char *setup_script, const char *down_script)
910 913
{
911 914
    TAPState *s;
......
926 929
	if (launch_script(setup_script, ifname, fd))
927 930
	    return -1;
928 931
    }
929
    s = net_tap_fd_init(vlan, fd);
932
    s = net_tap_fd_init(vlan, model, fd);
930 933
    if (!s)
931 934
        return -1;
932 935
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
......
969 972
    }
970 973
}
971 974

  
972
static int net_vde_init(VLANState *vlan, const char *sock, int port,
973
                        const char *group, int mode)
975
static int net_vde_init(VLANState *vlan, const char *model, const char *sock,
976
                        int port, const char *group, int mode)
974 977
{
975 978
    VDEState *s;
976 979
    char *init_group = strlen(group) ? (char *)group : NULL;
......
990 993
        free(s);
991 994
        return -1;
992 995
    }
993
    s->vc = qemu_new_vlan_client(vlan, vde_from_qemu, NULL, s);
996
    s->vc = qemu_new_vlan_client(vlan, model, vde_from_qemu, NULL, s);
994 997
    qemu_set_fd_handler(vde_datafd(s->vde), vde_to_qemu, NULL, s);
995 998
    snprintf(s->vc->info_str, sizeof(s->vc->info_str), "vde: sock=%s fd=%d",
996 999
             sock, vde_datafd(s->vde));
......
1011 1014

  
1012 1015
typedef struct NetSocketListenState {
1013 1016
    VLANState *vlan;
1017
    char *model;
1014 1018
    int fd;
1015 1019
} NetSocketListenState;
1016 1020

  
......
1164 1168
    return -1;
1165 1169
}
1166 1170

  
1167
static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, int fd,
1168
                                          int is_connected)
1171
static NetSocketState *net_socket_fd_init_dgram(VLANState *vlan, const char *model,
1172
                                                int fd, int is_connected)
1169 1173
{
1170 1174
    struct sockaddr_in saddr;
1171 1175
    int newfd;
......
1208 1212
        return NULL;
1209 1213
    s->fd = fd;
1210 1214

  
1211
    s->vc = qemu_new_vlan_client(vlan, net_socket_receive_dgram, NULL, s);
1215
    s->vc = qemu_new_vlan_client(vlan, model, net_socket_receive_dgram, NULL, s);
1212 1216
    qemu_set_fd_handler(s->fd, net_socket_send_dgram, NULL, s);
1213 1217

  
1214 1218
    /* mcast: save bound address as dst */
......
1227 1231
    qemu_set_fd_handler(s->fd, net_socket_send, NULL, s);
1228 1232
}
1229 1233

  
1230
static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, int fd,
1231
                                          int is_connected)
1234
static NetSocketState *net_socket_fd_init_stream(VLANState *vlan, const char *model,
1235
                                                 int fd, int is_connected)
1232 1236
{
1233 1237
    NetSocketState *s;
1234 1238
    s = qemu_mallocz(sizeof(NetSocketState));
1235 1239
    if (!s)
1236 1240
        return NULL;
1237 1241
    s->fd = fd;
1238
    s->vc = qemu_new_vlan_client(vlan,
1242
    s->vc = qemu_new_vlan_client(vlan, model,
1239 1243
                                 net_socket_receive, NULL, s);
1240 1244
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
1241 1245
             "socket: fd=%d", fd);
......
1247 1251
    return s;
1248 1252
}
1249 1253

  
1250
static NetSocketState *net_socket_fd_init(VLANState *vlan, int fd,
1251
                                          int is_connected)
1254
static NetSocketState *net_socket_fd_init(VLANState *vlan, const char *model,
1255
                                          int fd, int is_connected)
1252 1256
{
1253 1257
    int so_type=-1, optlen=sizeof(so_type);
1254 1258

  
......
1259 1263
    }
1260 1264
    switch(so_type) {
1261 1265
    case SOCK_DGRAM:
1262
        return net_socket_fd_init_dgram(vlan, fd, is_connected);
1266
        return net_socket_fd_init_dgram(vlan, model, fd, is_connected);
1263 1267
    case SOCK_STREAM:
1264
        return net_socket_fd_init_stream(vlan, fd, is_connected);
1268
        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
1265 1269
    default:
1266 1270
        /* who knows ... this could be a eg. a pty, do warn and continue as stream */
1267 1271
        fprintf(stderr, "qemu: warning: socket type=%d for fd=%d is not SOCK_DGRAM or SOCK_STREAM\n", so_type, fd);
1268
        return net_socket_fd_init_stream(vlan, fd, is_connected);
1272
        return net_socket_fd_init_stream(vlan, model, fd, is_connected);
1269 1273
    }
1270 1274
    return NULL;
1271 1275
}
......
1287 1291
            break;
1288 1292
        }
1289 1293
    }
1290
    s1 = net_socket_fd_init(s->vlan, fd, 1);
1294
    s1 = net_socket_fd_init(s->vlan, s->model, fd, 1);
1291 1295
    if (!s1) {
1292 1296
        closesocket(fd);
1293 1297
    } else {
......
1297 1301
    }
1298 1302
}
1299 1303

  
1300
static int net_socket_listen_init(VLANState *vlan, const char *host_str)
1304
static int net_socket_listen_init(VLANState *vlan, const char *model,
1305
                                  const char *host_str)
1301 1306
{
1302 1307
    NetSocketListenState *s;
1303 1308
    int fd, val, ret;
......
1332 1337
        return -1;
1333 1338
    }
1334 1339
    s->vlan = vlan;
1340
    s->model = strdup(model);
1335 1341
    s->fd = fd;
1336 1342
    qemu_set_fd_handler(fd, net_socket_accept, NULL, s);
1337 1343
    return 0;
1338 1344
}
1339 1345

  
1340
static int net_socket_connect_init(VLANState *vlan, const char *host_str)
1346
static int net_socket_connect_init(VLANState *vlan, const char *model,
1347
                                   const char *host_str)
1341 1348
{
1342 1349
    NetSocketState *s;
1343 1350
    int fd, connected, ret, err;
......
1375 1382
            break;
1376 1383
        }
1377 1384
    }
1378
    s = net_socket_fd_init(vlan, fd, connected);
1385
    s = net_socket_fd_init(vlan, model, fd, connected);
1379 1386
    if (!s)
1380 1387
        return -1;
1381 1388
    snprintf(s->vc->info_str, sizeof(s->vc->info_str),
......
1384 1391
    return 0;
1385 1392
}
1386 1393

  
1387
static int net_socket_mcast_init(VLANState *vlan, const char *host_str)
1394
static int net_socket_mcast_init(VLANState *vlan, const char *model,
1395
                                 const char *host_str)
1388 1396
{
1389 1397
    NetSocketState *s;
1390 1398
    int fd;
......
1398 1406
    if (fd < 0)
1399 1407
	return -1;
1400 1408

  
1401
    s = net_socket_fd_init(vlan, fd, 0);
1409
    s = net_socket_fd_init(vlan, model, fd, 0);
1402 1410
    if (!s)
1403 1411
        return -1;
1404 1412

  
......
1488 1496
            pstrcpy(slirp_hostname, sizeof(slirp_hostname), buf);
1489 1497
        }
1490 1498
        vlan->nb_host_devs++;
1491
        ret = net_slirp_init(vlan);
1499
        ret = net_slirp_init(vlan, device);
1492 1500
    } else
1493 1501
#endif
1494 1502
#ifdef _WIN32
......
1499 1507
            return -1;
1500 1508
        }
1501 1509
        vlan->nb_host_devs++;
1502
        ret = tap_win32_init(vlan, ifname);
1510
        ret = tap_win32_init(vlan, device, ifname);
1503 1511
    } else
1504 1512
#elif defined (_AIX)
1505 1513
#else
......
1512 1520
            fd = strtol(buf, NULL, 0);
1513 1521
            fcntl(fd, F_SETFL, O_NONBLOCK);
1514 1522
            ret = -1;
1515
            if (net_tap_fd_init(vlan, fd))
1523
            if (net_tap_fd_init(vlan, device, fd))
1516 1524
                ret = 0;
1517 1525
        } else {
1518 1526
            if (get_param_value(ifname, sizeof(ifname), "ifname", p) <= 0) {
......
1524 1532
            if (get_param_value(down_script, sizeof(down_script), "downscript", p) == 0) {
1525 1533
                pstrcpy(down_script, sizeof(down_script), DEFAULT_NETWORK_DOWN_SCRIPT);
1526 1534
            }
1527
            ret = net_tap_init(vlan, ifname, setup_script, down_script);
1535
            ret = net_tap_init(vlan, device, ifname, setup_script, down_script);
1528 1536
        }
1529 1537
    } else
1530 1538
#endif
......
1533 1541
            int fd;
1534 1542
            fd = strtol(buf, NULL, 0);
1535 1543
            ret = -1;
1536
            if (net_socket_fd_init(vlan, fd, 1))
1544
            if (net_socket_fd_init(vlan, device, fd, 1))
1537 1545
                ret = 0;
1538 1546
        } else if (get_param_value(buf, sizeof(buf), "listen", p) > 0) {
1539
            ret = net_socket_listen_init(vlan, buf);
1547
            ret = net_socket_listen_init(vlan, device, buf);
1540 1548
        } else if (get_param_value(buf, sizeof(buf), "connect", p) > 0) {
1541
            ret = net_socket_connect_init(vlan, buf);
1549
            ret = net_socket_connect_init(vlan, device, buf);
1542 1550
        } else if (get_param_value(buf, sizeof(buf), "mcast", p) > 0) {
1543
            ret = net_socket_mcast_init(vlan, buf);
1551
            ret = net_socket_mcast_init(vlan, device, buf);
1544 1552
        } else {
1545 1553
            fprintf(stderr, "Unknown socket options: %s\n", p);
1546 1554
            return -1;
......
1568 1576
	} else {
1569 1577
	    vde_mode = 0700;
1570 1578
	}
1571
	ret = net_vde_init(vlan, vde_sock, vde_port, vde_group, vde_mode);
1579
	ret = net_vde_init(vlan, device, vde_sock, vde_port, vde_group, vde_mode);
1572 1580
    } else
1573 1581
#endif
1574 1582
    {

Also available in: Unified diff