mirror of
https://github.com/xemu-project/xemu.git
synced 2024-11-27 05:20:50 +00:00
qapi: Change Netdev into a flat union
This is a mostly-mechanical conversion that creates a new flat union 'Netdev' QAPI type that covers all the branches of the former 'NetClientOptions' simple union, where the branches are now listed in a new 'NetClientDriver' enum rather than generated from the simple union. The existence of a flat union has no change to the command line syntax accepted for new code, and will make it possible for a future patch to switch the QMP command to parse a boxed union for no change to valid QMP; but it does have some ripple effect on the C code when dealing with the new types. While making the conversion, note that the 'NetLegacy' type remains unchanged: it applies only to legacy command line options, and will not be ported to QMP, so it should remain a wrapper around a simple union; to avoid confusion, the type named 'NetClientOptions' is now gone, and we introduce 'NetLegacyOptions' in its place. Then, in the C code, we convert from NetLegacy to Netdev as soon as possible, so that the bulk of the net stack only has to deal with one QAPI type, not two. Note that since the old legacy code always rejected 'hubport', we can just omit that branch from the new 'NetLegacyOptions' simple union. Based on an idea originally by Zoltán Kővágó <DirtY.iCE.hu@gmail.com>: Message-Id: <01a527fbf1a5de880091f98cf011616a78adeeee.1441627176.git.DirtY.iCE.hu@gmail.com> although the sed script in that patch no longer applies due to other changes in the tree since then, and I also did some manual cleanups (such as fixing whitespace to keep checkpatch happy). Signed-off-by: Eric Blake <eblake@redhat.com> Message-Id: <1468468228-27827-13-git-send-email-eblake@redhat.com> Reviewed-by: Markus Armbruster <armbru@redhat.com> [Fixup from Eric squashed in] Signed-off-by: Markus Armbruster <armbru@redhat.com>
This commit is contained in:
parent
faecd40a59
commit
f394b2e20d
@ -378,7 +378,7 @@ static void eth_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_mv88w8618_info = {
|
static NetClientInfo net_mv88w8618_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = eth_receive,
|
.receive = eth_receive,
|
||||||
.cleanup = eth_cleanup,
|
.cleanup = eth_cleanup,
|
||||||
|
@ -247,7 +247,7 @@ static void set_netdev(Object *obj, Visitor *v, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
queues = qemu_find_net_clients_except(str, peers,
|
queues = qemu_find_net_clients_except(str, peers,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
if (queues == 0) {
|
if (queues == 0) {
|
||||||
err = -ENOENT;
|
err = -ENOENT;
|
||||||
|
@ -424,7 +424,7 @@ static const MemoryRegionOps aw_emac_mem_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_aw_emac_info = {
|
static NetClientInfo net_aw_emac_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = aw_emac_can_receive,
|
.can_receive = aw_emac_can_receive,
|
||||||
.receive = aw_emac_receive,
|
.receive = aw_emac_receive,
|
||||||
|
@ -1207,7 +1207,7 @@ static void gem_set_link(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_gem_info = {
|
static NetClientInfo net_gem_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = gem_can_receive,
|
.can_receive = gem_can_receive,
|
||||||
.receive = gem_receive,
|
.receive = gem_receive,
|
||||||
|
@ -812,7 +812,7 @@ static void dp8393x_reset(DeviceState *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_dp83932_info = {
|
static NetClientInfo net_dp83932_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = dp8393x_can_receive,
|
.can_receive = dp8393x_can_receive,
|
||||||
.receive = dp8393x_receive,
|
.receive = dp8393x_receive,
|
||||||
|
@ -1563,7 +1563,7 @@ pci_e1000_uninit(PCIDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_e1000_info = {
|
static NetClientInfo net_e1000_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = e1000_can_receive,
|
.can_receive = e1000_can_receive,
|
||||||
.receive = e1000_receive,
|
.receive = e1000_receive,
|
||||||
|
@ -225,7 +225,7 @@ e1000e_set_link_status(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_e1000e_info = {
|
static NetClientInfo net_e1000e_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = e1000e_nc_can_receive,
|
.can_receive = e1000e_nc_can_receive,
|
||||||
.receive = e1000e_nc_receive,
|
.receive = e1000e_nc_receive,
|
||||||
|
@ -1848,7 +1848,7 @@ static void pci_nic_uninit(PCIDevice *pci_dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_eepro100_info = {
|
static NetClientInfo net_eepro100_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = nic_receive,
|
.receive = nic_receive,
|
||||||
};
|
};
|
||||||
|
@ -578,7 +578,7 @@ static const MemoryRegionOps eth_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_etraxfs_info = {
|
static NetClientInfo net_etraxfs_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = eth_receive,
|
.receive = eth_receive,
|
||||||
.link_status_changed = eth_set_link,
|
.link_status_changed = eth_set_link,
|
||||||
|
@ -371,7 +371,7 @@ static void etsec_set_link_status(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_etsec_info = {
|
static NetClientInfo net_etsec_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = etsec_receive,
|
.receive = etsec_receive,
|
||||||
.link_status_changed = etsec_set_link_status,
|
.link_status_changed = etsec_set_link_status,
|
||||||
|
@ -1147,7 +1147,7 @@ static void imx_eth_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo imx_eth_net_info = {
|
static NetClientInfo imx_eth_net_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = imx_eth_can_receive,
|
.can_receive = imx_eth_can_receive,
|
||||||
.receive = imx_eth_receive,
|
.receive = imx_eth_receive,
|
||||||
|
@ -1313,7 +1313,7 @@ static const MemoryRegionOps lan9118_16bit_mem_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_lan9118_info = {
|
static NetClientInfo net_lan9118_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = lan9118_receive,
|
.receive = lan9118_receive,
|
||||||
.link_status_changed = lan9118_set_link,
|
.link_status_changed = lan9118_set_link,
|
||||||
|
@ -93,7 +93,7 @@ static const MemoryRegionOps lance_mem_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_lance_info = {
|
static NetClientInfo net_lance_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = pcnet_receive,
|
.receive = pcnet_receive,
|
||||||
.link_status_changed = pcnet_set_link_status,
|
.link_status_changed = pcnet_set_link_status,
|
||||||
|
@ -507,7 +507,7 @@ static const MemoryRegionOps mcf_fec_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_mcf_fec_info = {
|
static NetClientInfo net_mcf_fec_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = mcf_fec_receive,
|
.receive = mcf_fec_receive,
|
||||||
};
|
};
|
||||||
|
@ -447,7 +447,7 @@ static void milkymist_minimac2_reset(DeviceState *d)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_milkymist_minimac2_info = {
|
static NetClientInfo net_milkymist_minimac2_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = minimac2_rx,
|
.receive = minimac2_rx,
|
||||||
};
|
};
|
||||||
|
@ -224,7 +224,7 @@ static const VMStateDescription vmstate_mipsnet = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_mipsnet_info = {
|
static NetClientInfo net_mipsnet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = mipsnet_receive,
|
.receive = mipsnet_receive,
|
||||||
};
|
};
|
||||||
|
@ -44,7 +44,7 @@ typedef struct ISANE2000State {
|
|||||||
} ISANE2000State;
|
} ISANE2000State;
|
||||||
|
|
||||||
static NetClientInfo net_ne2000_isa_info = {
|
static NetClientInfo net_ne2000_isa_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = ne2000_receive,
|
.receive = ne2000_receive,
|
||||||
};
|
};
|
||||||
|
@ -712,7 +712,7 @@ void ne2000_setup_io(NE2000State *s, DeviceState *dev, unsigned size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_ne2000_info = {
|
static NetClientInfo net_ne2000_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = ne2000_receive,
|
.receive = ne2000_receive,
|
||||||
};
|
};
|
||||||
|
@ -473,7 +473,7 @@ static ssize_t open_eth_receive(NetClientState *nc,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_open_eth_info = {
|
static NetClientInfo net_open_eth_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = open_eth_can_receive,
|
.can_receive = open_eth_can_receive,
|
||||||
.receive = open_eth_receive,
|
.receive = open_eth_receive,
|
||||||
|
@ -272,7 +272,7 @@ static void pci_pcnet_uninit(PCIDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_pci_pcnet_info = {
|
static NetClientInfo net_pci_pcnet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = pcnet_receive,
|
.receive = pcnet_receive,
|
||||||
.link_status_changed = pcnet_set_link_status,
|
.link_status_changed = pcnet_set_link_status,
|
||||||
|
@ -167,7 +167,7 @@ static void fp_port_set_link_status(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo fp_port_info = {
|
static NetClientInfo fp_port_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = fp_port_receive,
|
.receive = fp_port_receive,
|
||||||
.receive_iov = fp_port_receive_iov,
|
.receive_iov = fp_port_receive_iov,
|
||||||
|
@ -3393,7 +3393,7 @@ static void rtl8139_set_link_status(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_rtl8139_info = {
|
static NetClientInfo net_rtl8139_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = rtl8139_can_receive,
|
.can_receive = rtl8139_can_receive,
|
||||||
.receive = rtl8139_receive,
|
.receive = rtl8139_receive,
|
||||||
|
@ -755,7 +755,7 @@ static const MemoryRegionOps smc91c111_mem_ops = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
static NetClientInfo net_smc91c111_info = {
|
static NetClientInfo net_smc91c111_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = smc91c111_can_receive_nc,
|
.can_receive = smc91c111_can_receive_nc,
|
||||||
.receive = smc91c111_receive,
|
.receive = smc91c111_receive,
|
||||||
|
@ -278,7 +278,7 @@ static ssize_t spapr_vlan_receive(NetClientState *nc, const uint8_t *buf,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_spapr_vlan_info = {
|
static NetClientInfo net_spapr_vlan_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = spapr_vlan_can_receive,
|
.can_receive = spapr_vlan_can_receive,
|
||||||
.receive = spapr_vlan_receive,
|
.receive = spapr_vlan_receive,
|
||||||
|
@ -460,7 +460,7 @@ static void stellaris_enet_reset(stellaris_enet_state *s)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_stellaris_enet_info = {
|
static NetClientInfo net_stellaris_enet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = stellaris_enet_receive,
|
.receive = stellaris_enet_receive,
|
||||||
};
|
};
|
||||||
|
@ -88,10 +88,10 @@ static const int *vhost_net_get_feature_bits(struct vhost_net *net)
|
|||||||
const int *feature_bits = 0;
|
const int *feature_bits = 0;
|
||||||
|
|
||||||
switch (net->nc->info->type) {
|
switch (net->nc->info->type) {
|
||||||
case NET_CLIENT_OPTIONS_KIND_TAP:
|
case NET_CLIENT_DRIVER_TAP:
|
||||||
feature_bits = kernel_feature_bits;
|
feature_bits = kernel_feature_bits;
|
||||||
break;
|
break;
|
||||||
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
|
case NET_CLIENT_DRIVER_VHOST_USER:
|
||||||
feature_bits = user_feature_bits;
|
feature_bits = user_feature_bits;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
@ -128,7 +128,7 @@ uint64_t vhost_net_get_acked_features(VHostNetState *net)
|
|||||||
static int vhost_net_get_fd(NetClientState *backend)
|
static int vhost_net_get_fd(NetClientState *backend)
|
||||||
{
|
{
|
||||||
switch (backend->info->type) {
|
switch (backend->info->type) {
|
||||||
case NET_CLIENT_OPTIONS_KIND_TAP:
|
case NET_CLIENT_DRIVER_TAP:
|
||||||
return tap_get_fd(backend);
|
return tap_get_fd(backend);
|
||||||
default:
|
default:
|
||||||
fprintf(stderr, "vhost-net requires tap backend\n");
|
fprintf(stderr, "vhost-net requires tap backend\n");
|
||||||
@ -191,7 +191,7 @@ struct vhost_net *vhost_net_init(VhostNetOptions *options)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Set sane init value. Override when guest acks. */
|
/* Set sane init value. Override when guest acks. */
|
||||||
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
|
if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
|
||||||
features = vhost_user_get_acked_features(net->nc);
|
features = vhost_user_get_acked_features(net->nc);
|
||||||
if (~net->dev.features & features) {
|
if (~net->dev.features & features) {
|
||||||
fprintf(stderr, "vhost lacks feature mask %" PRIu64
|
fprintf(stderr, "vhost lacks feature mask %" PRIu64
|
||||||
@ -238,7 +238,7 @@ static int vhost_net_start_one(struct vhost_net *net,
|
|||||||
net->nc->info->poll(net->nc, false);
|
net->nc->info->poll(net->nc, false);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
|
||||||
qemu_set_fd_handler(net->backend, NULL, NULL, NULL);
|
qemu_set_fd_handler(net->backend, NULL, NULL, NULL);
|
||||||
file.fd = net->backend;
|
file.fd = net->backend;
|
||||||
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
|
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
|
||||||
@ -253,7 +253,7 @@ static int vhost_net_start_one(struct vhost_net *net,
|
|||||||
return 0;
|
return 0;
|
||||||
fail:
|
fail:
|
||||||
file.fd = -1;
|
file.fd = -1;
|
||||||
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
|
||||||
while (file.index-- > 0) {
|
while (file.index-- > 0) {
|
||||||
const VhostOps *vhost_ops = net->dev.vhost_ops;
|
const VhostOps *vhost_ops = net->dev.vhost_ops;
|
||||||
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
|
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
|
||||||
@ -275,7 +275,7 @@ static void vhost_net_stop_one(struct vhost_net *net,
|
|||||||
{
|
{
|
||||||
struct vhost_vring_file file = { .fd = -1 };
|
struct vhost_vring_file file = { .fd = -1 };
|
||||||
|
|
||||||
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (net->nc->info->type == NET_CLIENT_DRIVER_TAP) {
|
||||||
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
|
for (file.index = 0; file.index < net->dev.nvqs; ++file.index) {
|
||||||
const VhostOps *vhost_ops = net->dev.vhost_ops;
|
const VhostOps *vhost_ops = net->dev.vhost_ops;
|
||||||
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
|
int r = vhost_ops->vhost_net_set_backend(&net->dev, &file);
|
||||||
@ -312,7 +312,7 @@ int vhost_net_start(VirtIODevice *dev, NetClientState *ncs,
|
|||||||
* because vhost user doesn't interrupt masking/unmasking
|
* because vhost user doesn't interrupt masking/unmasking
|
||||||
* properly.
|
* properly.
|
||||||
*/
|
*/
|
||||||
if (net->nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
|
if (net->nc->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
|
||||||
dev->use_guest_notifier_mask = false;
|
dev->use_guest_notifier_mask = false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -413,10 +413,10 @@ VHostNetState *get_vhost_net(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (nc->info->type) {
|
switch (nc->info->type) {
|
||||||
case NET_CLIENT_OPTIONS_KIND_TAP:
|
case NET_CLIENT_DRIVER_TAP:
|
||||||
vhost_net = tap_get_vhost_net(nc);
|
vhost_net = tap_get_vhost_net(nc);
|
||||||
break;
|
break;
|
||||||
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
|
case NET_CLIENT_DRIVER_VHOST_USER:
|
||||||
vhost_net = vhost_user_get_vhost_net(nc);
|
vhost_net = vhost_user_get_vhost_net(nc);
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -468,11 +468,11 @@ static int peer_attach(VirtIONet *n, int index)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
|
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
|
||||||
vhost_set_vring_enable(nc->peer, 1);
|
vhost_set_vring_enable(nc->peer, 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -487,11 +487,11 @@ static int peer_detach(VirtIONet *n, int index)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER) {
|
if (nc->peer->info->type == NET_CLIENT_DRIVER_VHOST_USER) {
|
||||||
vhost_set_vring_enable(nc->peer, 0);
|
vhost_set_vring_enable(nc->peer, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (nc->peer->info->type != NET_CLIENT_OPTIONS_KIND_TAP) {
|
if (nc->peer->info->type != NET_CLIENT_DRIVER_TAP) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -1680,7 +1680,7 @@ static int virtio_net_load_device(VirtIODevice *vdev, QEMUFile *f,
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_virtio_info = {
|
static NetClientInfo net_virtio_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = virtio_net_can_receive,
|
.can_receive = virtio_net_can_receive,
|
||||||
.receive = virtio_net_receive,
|
.receive = virtio_net_receive,
|
||||||
|
@ -2087,7 +2087,7 @@ static void vmxnet3_set_link_status(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_vmxnet3_info = {
|
static NetClientInfo net_vmxnet3_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = vmxnet3_receive,
|
.receive = vmxnet3_receive,
|
||||||
.link_status_changed = vmxnet3_set_link_status,
|
.link_status_changed = vmxnet3_set_link_status,
|
||||||
|
@ -269,7 +269,7 @@ static ssize_t net_rx_packet(NetClientState *nc, const uint8_t *buf, size_t size
|
|||||||
/* ------------------------------------------------------------- */
|
/* ------------------------------------------------------------- */
|
||||||
|
|
||||||
static NetClientInfo net_xen_info = {
|
static NetClientInfo net_xen_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = net_rx_packet,
|
.receive = net_rx_packet,
|
||||||
};
|
};
|
||||||
|
@ -371,7 +371,7 @@ out:
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_xgmac_enet_info = {
|
static NetClientInfo net_xgmac_enet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = eth_rx,
|
.receive = eth_rx,
|
||||||
};
|
};
|
||||||
|
@ -935,7 +935,7 @@ xilinx_axienet_data_stream_push(StreamSlave *obj, uint8_t *buf, size_t size)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_xilinx_enet_info = {
|
static NetClientInfo net_xilinx_enet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = eth_rx,
|
.receive = eth_rx,
|
||||||
};
|
};
|
||||||
|
@ -217,7 +217,7 @@ static void xilinx_ethlite_reset(DeviceState *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_xilinx_ethlite_info = {
|
static NetClientInfo net_xilinx_ethlite_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.can_receive = eth_can_rx,
|
.can_receive = eth_can_rx,
|
||||||
.receive = eth_rx,
|
.receive = eth_rx,
|
||||||
|
@ -1334,7 +1334,7 @@ static void usb_net_handle_destroy(USBDevice *dev)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_usbnet_info = {
|
static NetClientInfo net_usbnet_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NIC,
|
.type = NET_CLIENT_DRIVER_NIC,
|
||||||
.size = sizeof(NICState),
|
.size = sizeof(NICState),
|
||||||
.receive = usbnet_receive,
|
.receive = usbnet_receive,
|
||||||
.cleanup = usbnet_cleanup,
|
.cleanup = usbnet_cleanup,
|
||||||
|
@ -66,7 +66,7 @@ typedef struct SocketReadState SocketReadState;
|
|||||||
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
|
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
|
||||||
|
|
||||||
typedef struct NetClientInfo {
|
typedef struct NetClientInfo {
|
||||||
NetClientOptionsKind type;
|
NetClientDriver type;
|
||||||
size_t size;
|
size_t size;
|
||||||
NetReceive *receive;
|
NetReceive *receive;
|
||||||
NetReceive *receive_raw;
|
NetReceive *receive_raw;
|
||||||
@ -122,7 +122,7 @@ int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size);
|
|||||||
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
||||||
NetClientState *qemu_find_netdev(const char *id);
|
NetClientState *qemu_find_netdev(const char *id);
|
||||||
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
||||||
NetClientOptionsKind type, int max);
|
NetClientDriver type, int max);
|
||||||
NetClientState *qemu_new_net_client(NetClientInfo *info,
|
NetClientState *qemu_new_net_client(NetClientInfo *info,
|
||||||
NetClientState *peer,
|
NetClientState *peer,
|
||||||
const char *model,
|
const char *model,
|
||||||
|
14
monitor.c
14
monitor.c
@ -3080,8 +3080,8 @@ void netdev_add_completion(ReadLineState *rs, int nb_args, const char *str)
|
|||||||
}
|
}
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
readline_set_completion_index(rs, len);
|
readline_set_completion_index(rs, len);
|
||||||
for (i = 0; NetClientOptionsKind_lookup[i]; i++) {
|
for (i = 0; NetClientDriver_lookup[i]; i++) {
|
||||||
add_completion_option(rs, str, NetClientOptionsKind_lookup[i]);
|
add_completion_option(rs, str, NetClientDriver_lookup[i]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -3281,7 +3281,7 @@ void set_link_completion(ReadLineState *rs, int nb_args, const char *str)
|
|||||||
NetClientState *ncs[MAX_QUEUE_NUM];
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
||||||
int count, i;
|
int count, i;
|
||||||
count = qemu_find_net_clients_except(NULL, ncs,
|
count = qemu_find_net_clients_except(NULL, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NONE,
|
NET_CLIENT_DRIVER_NONE,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
||||||
const char *name = ncs[i]->name;
|
const char *name = ncs[i]->name;
|
||||||
@ -3306,7 +3306,7 @@ void netdev_del_completion(ReadLineState *rs, int nb_args, const char *str)
|
|||||||
|
|
||||||
len = strlen(str);
|
len = strlen(str);
|
||||||
readline_set_completion_index(rs, len);
|
readline_set_completion_index(rs, len);
|
||||||
count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_OPTIONS_KIND_NIC,
|
count = qemu_find_net_clients_except(NULL, ncs, NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
||||||
QemuOpts *opts;
|
QemuOpts *opts;
|
||||||
@ -3435,7 +3435,7 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
|
|||||||
readline_set_completion_index(rs, len);
|
readline_set_completion_index(rs, len);
|
||||||
if (nb_args == 2) {
|
if (nb_args == 2) {
|
||||||
count = qemu_find_net_clients_except(NULL, ncs,
|
count = qemu_find_net_clients_except(NULL, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NONE,
|
NET_CLIENT_DRIVER_NONE,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
||||||
int id;
|
int id;
|
||||||
@ -3452,13 +3452,13 @@ void host_net_remove_completion(ReadLineState *rs, int nb_args, const char *str)
|
|||||||
return;
|
return;
|
||||||
} else if (nb_args == 3) {
|
} else if (nb_args == 3) {
|
||||||
count = qemu_find_net_clients_except(NULL, ncs,
|
count = qemu_find_net_clients_except(NULL, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
for (i = 0; i < MIN(count, MAX_QUEUE_NUM); i++) {
|
||||||
int id;
|
int id;
|
||||||
const char *name;
|
const char *name;
|
||||||
|
|
||||||
if (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT ||
|
if (ncs[i]->info->type == NET_CLIENT_DRIVER_HUBPORT ||
|
||||||
net_hub_id_for_client(ncs[i], &id)) {
|
net_hub_id_for_client(ncs[i], &id)) {
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
@ -172,7 +172,7 @@ static void dumpclient_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_dump_info = {
|
static NetClientInfo net_dump_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_DUMP,
|
.type = NET_CLIENT_DRIVER_DUMP,
|
||||||
.size = sizeof(DumpNetClient),
|
.size = sizeof(DumpNetClient),
|
||||||
.receive = dumpclient_receive,
|
.receive = dumpclient_receive,
|
||||||
.receive_iov = dumpclient_receive_iov,
|
.receive_iov = dumpclient_receive_iov,
|
||||||
@ -189,8 +189,8 @@ int net_init_dump(const Netdev *netdev, const char *name,
|
|||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
DumpNetClient *dnc;
|
DumpNetClient *dnc;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_DUMP);
|
assert(netdev->type == NET_CLIENT_DRIVER_DUMP);
|
||||||
dump = netdev->opts->u.dump.data;
|
dump = &netdev->u.dump;
|
||||||
|
|
||||||
assert(peer);
|
assert(peer);
|
||||||
|
|
||||||
|
@ -201,7 +201,7 @@ static void netfilter_complete(UserCreatable *uc, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
queues = qemu_find_net_clients_except(nf->netdev_id, ncs,
|
queues = qemu_find_net_clients_except(nf->netdev_id, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
if (queues < 1) {
|
if (queues < 1) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "netdev",
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "netdev",
|
||||||
|
22
net/hub.c
22
net/hub.c
@ -131,7 +131,7 @@ static void net_hub_port_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_hub_port_info = {
|
static NetClientInfo net_hub_port_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_HUBPORT,
|
.type = NET_CLIENT_DRIVER_HUBPORT,
|
||||||
.size = sizeof(NetHubPort),
|
.size = sizeof(NetHubPort),
|
||||||
.can_receive = net_hub_port_can_receive,
|
.can_receive = net_hub_port_can_receive,
|
||||||
.receive = net_hub_port_receive,
|
.receive = net_hub_port_receive,
|
||||||
@ -266,10 +266,10 @@ int net_hub_id_for_client(NetClientState *nc, int *id)
|
|||||||
{
|
{
|
||||||
NetHubPort *port;
|
NetHubPort *port;
|
||||||
|
|
||||||
if (nc->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
|
if (nc->info->type == NET_CLIENT_DRIVER_HUBPORT) {
|
||||||
port = DO_UPCAST(NetHubPort, nc, nc);
|
port = DO_UPCAST(NetHubPort, nc, nc);
|
||||||
} else if (nc->peer != NULL && nc->peer->info->type ==
|
} else if (nc->peer != NULL && nc->peer->info->type ==
|
||||||
NET_CLIENT_OPTIONS_KIND_HUBPORT) {
|
NET_CLIENT_DRIVER_HUBPORT) {
|
||||||
port = DO_UPCAST(NetHubPort, nc, nc->peer);
|
port = DO_UPCAST(NetHubPort, nc, nc->peer);
|
||||||
} else {
|
} else {
|
||||||
return -ENOENT;
|
return -ENOENT;
|
||||||
@ -286,9 +286,9 @@ int net_init_hubport(const Netdev *netdev, const char *name,
|
|||||||
{
|
{
|
||||||
const NetdevHubPortOptions *hubport;
|
const NetdevHubPortOptions *hubport;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT);
|
assert(netdev->type == NET_CLIENT_DRIVER_HUBPORT);
|
||||||
assert(!peer);
|
assert(!peer);
|
||||||
hubport = netdev->opts->u.hubport.data;
|
hubport = &netdev->u.hubport;
|
||||||
|
|
||||||
net_hub_add_port(hubport->hubid, name);
|
net_hub_add_port(hubport->hubid, name);
|
||||||
return 0;
|
return 0;
|
||||||
@ -315,14 +315,14 @@ void net_hub_check_clients(void)
|
|||||||
}
|
}
|
||||||
|
|
||||||
switch (peer->info->type) {
|
switch (peer->info->type) {
|
||||||
case NET_CLIENT_OPTIONS_KIND_NIC:
|
case NET_CLIENT_DRIVER_NIC:
|
||||||
has_nic = 1;
|
has_nic = 1;
|
||||||
break;
|
break;
|
||||||
case NET_CLIENT_OPTIONS_KIND_USER:
|
case NET_CLIENT_DRIVER_USER:
|
||||||
case NET_CLIENT_OPTIONS_KIND_TAP:
|
case NET_CLIENT_DRIVER_TAP:
|
||||||
case NET_CLIENT_OPTIONS_KIND_SOCKET:
|
case NET_CLIENT_DRIVER_SOCKET:
|
||||||
case NET_CLIENT_OPTIONS_KIND_VDE:
|
case NET_CLIENT_DRIVER_VDE:
|
||||||
case NET_CLIENT_OPTIONS_KIND_VHOST_USER:
|
case NET_CLIENT_DRIVER_VHOST_USER:
|
||||||
has_host_dev = 1;
|
has_host_dev = 1;
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
|
@ -516,7 +516,7 @@ static void net_l2tpv3_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_l2tpv3_info = {
|
static NetClientInfo net_l2tpv3_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_L2TPV3,
|
.type = NET_CLIENT_DRIVER_L2TPV3,
|
||||||
.size = sizeof(NetL2TPV3State),
|
.size = sizeof(NetL2TPV3State),
|
||||||
.receive = net_l2tpv3_receive_dgram,
|
.receive = net_l2tpv3_receive_dgram,
|
||||||
.receive_iov = net_l2tpv3_receive_dgram_iov,
|
.receive_iov = net_l2tpv3_receive_dgram_iov,
|
||||||
@ -545,8 +545,8 @@ int net_init_l2tpv3(const Netdev *netdev,
|
|||||||
s->queue_tail = 0;
|
s->queue_tail = 0;
|
||||||
s->header_mismatch = false;
|
s->header_mismatch = false;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_L2TPV3);
|
assert(netdev->type == NET_CLIENT_DRIVER_L2TPV3);
|
||||||
l2tpv3 = netdev->opts->u.l2tpv3.data;
|
l2tpv3 = &netdev->u.l2tpv3;
|
||||||
|
|
||||||
if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
|
if (l2tpv3->has_ipv6 && l2tpv3->ipv6) {
|
||||||
s->ipv6 = l2tpv3->ipv6;
|
s->ipv6 = l2tpv3->ipv6;
|
||||||
|
133
net/net.c
133
net/net.c
@ -289,7 +289,7 @@ NICState *qemu_new_nic(NetClientInfo *info,
|
|||||||
NICState *nic;
|
NICState *nic;
|
||||||
int i, queues = MAX(1, conf->peers.queues);
|
int i, queues = MAX(1, conf->peers.queues);
|
||||||
|
|
||||||
assert(info->type == NET_CLIENT_OPTIONS_KIND_NIC);
|
assert(info->type == NET_CLIENT_DRIVER_NIC);
|
||||||
assert(info->size >= sizeof(NICState));
|
assert(info->size >= sizeof(NICState));
|
||||||
|
|
||||||
nic = g_malloc0(info->size + sizeof(NetClientState) * queues);
|
nic = g_malloc0(info->size + sizeof(NetClientState) * queues);
|
||||||
@ -360,13 +360,13 @@ void qemu_del_net_client(NetClientState *nc)
|
|||||||
int queues, i;
|
int queues, i;
|
||||||
NetFilterState *nf, *next;
|
NetFilterState *nf, *next;
|
||||||
|
|
||||||
assert(nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC);
|
assert(nc->info->type != NET_CLIENT_DRIVER_NIC);
|
||||||
|
|
||||||
/* If the NetClientState belongs to a multiqueue backend, we will change all
|
/* If the NetClientState belongs to a multiqueue backend, we will change all
|
||||||
* other NetClientStates also.
|
* other NetClientStates also.
|
||||||
*/
|
*/
|
||||||
queues = qemu_find_net_clients_except(nc->name, ncs,
|
queues = qemu_find_net_clients_except(nc->name, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
assert(queues != 0);
|
assert(queues != 0);
|
||||||
|
|
||||||
@ -375,7 +375,7 @@ void qemu_del_net_client(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* If there is a peer NIC, delete and cleanup client, but do not free. */
|
/* If there is a peer NIC, delete and cleanup client, but do not free. */
|
||||||
if (nc->peer && nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_NIC) {
|
||||||
NICState *nic = qemu_get_nic(nc->peer);
|
NICState *nic = qemu_get_nic(nc->peer);
|
||||||
if (nic->peer_deleted) {
|
if (nic->peer_deleted) {
|
||||||
return;
|
return;
|
||||||
@ -431,7 +431,7 @@ void qemu_foreach_nic(qemu_nic_foreach func, void *opaque)
|
|||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
|
|
||||||
QTAILQ_FOREACH(nc, &net_clients, next) {
|
QTAILQ_FOREACH(nc, &net_clients, next) {
|
||||||
if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->info->type == NET_CLIENT_DRIVER_NIC) {
|
||||||
if (nc->queue_index == 0) {
|
if (nc->queue_index == 0) {
|
||||||
func(qemu_get_nic(nc), opaque);
|
func(qemu_get_nic(nc), opaque);
|
||||||
}
|
}
|
||||||
@ -603,7 +603,7 @@ void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge)
|
|||||||
{
|
{
|
||||||
nc->receive_disabled = 0;
|
nc->receive_disabled = 0;
|
||||||
|
|
||||||
if (nc->peer && nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
|
if (nc->peer && nc->peer->info->type == NET_CLIENT_DRIVER_HUBPORT) {
|
||||||
if (net_hub_flush(nc->peer)) {
|
if (net_hub_flush(nc->peer)) {
|
||||||
qemu_notify_event();
|
qemu_notify_event();
|
||||||
}
|
}
|
||||||
@ -777,7 +777,7 @@ NetClientState *qemu_find_netdev(const char *id)
|
|||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
|
|
||||||
QTAILQ_FOREACH(nc, &net_clients, next) {
|
QTAILQ_FOREACH(nc, &net_clients, next) {
|
||||||
if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC)
|
if (nc->info->type == NET_CLIENT_DRIVER_NIC)
|
||||||
continue;
|
continue;
|
||||||
if (!strcmp(nc->name, id)) {
|
if (!strcmp(nc->name, id)) {
|
||||||
return nc;
|
return nc;
|
||||||
@ -788,7 +788,7 @@ NetClientState *qemu_find_netdev(const char *id)
|
|||||||
}
|
}
|
||||||
|
|
||||||
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
||||||
NetClientOptionsKind type, int max)
|
NetClientDriver type, int max)
|
||||||
{
|
{
|
||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
int ret = 0;
|
int ret = 0;
|
||||||
@ -869,8 +869,8 @@ static int net_init_nic(const Netdev *netdev, const char *name,
|
|||||||
NICInfo *nd;
|
NICInfo *nd;
|
||||||
const NetLegacyNicOptions *nic;
|
const NetLegacyNicOptions *nic;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_NIC);
|
assert(netdev->type == NET_CLIENT_DRIVER_NIC);
|
||||||
nic = netdev->opts->u.nic.data;
|
nic = &netdev->u.nic;
|
||||||
|
|
||||||
idx = nic_get_free_idx();
|
idx = nic_get_free_idx();
|
||||||
if (idx == -1 || nb_nics >= MAX_NICS) {
|
if (idx == -1 || nb_nics >= MAX_NICS) {
|
||||||
@ -930,39 +930,38 @@ static int net_init_nic(const Netdev *netdev, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int (* const net_client_init_fun[NET_CLIENT_OPTIONS_KIND__MAX])(
|
static int (* const net_client_init_fun[NET_CLIENT_DRIVER__MAX])(
|
||||||
const Netdev *netdev,
|
const Netdev *netdev,
|
||||||
const char *name,
|
const char *name,
|
||||||
NetClientState *peer, Error **errp) = {
|
NetClientState *peer, Error **errp) = {
|
||||||
[NET_CLIENT_OPTIONS_KIND_NIC] = net_init_nic,
|
[NET_CLIENT_DRIVER_NIC] = net_init_nic,
|
||||||
#ifdef CONFIG_SLIRP
|
#ifdef CONFIG_SLIRP
|
||||||
[NET_CLIENT_OPTIONS_KIND_USER] = net_init_slirp,
|
[NET_CLIENT_DRIVER_USER] = net_init_slirp,
|
||||||
#endif
|
#endif
|
||||||
[NET_CLIENT_OPTIONS_KIND_TAP] = net_init_tap,
|
[NET_CLIENT_DRIVER_TAP] = net_init_tap,
|
||||||
[NET_CLIENT_OPTIONS_KIND_SOCKET] = net_init_socket,
|
[NET_CLIENT_DRIVER_SOCKET] = net_init_socket,
|
||||||
#ifdef CONFIG_VDE
|
#ifdef CONFIG_VDE
|
||||||
[NET_CLIENT_OPTIONS_KIND_VDE] = net_init_vde,
|
[NET_CLIENT_DRIVER_VDE] = net_init_vde,
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_NETMAP
|
#ifdef CONFIG_NETMAP
|
||||||
[NET_CLIENT_OPTIONS_KIND_NETMAP] = net_init_netmap,
|
[NET_CLIENT_DRIVER_NETMAP] = net_init_netmap,
|
||||||
#endif
|
#endif
|
||||||
[NET_CLIENT_OPTIONS_KIND_DUMP] = net_init_dump,
|
[NET_CLIENT_DRIVER_DUMP] = net_init_dump,
|
||||||
#ifdef CONFIG_NET_BRIDGE
|
#ifdef CONFIG_NET_BRIDGE
|
||||||
[NET_CLIENT_OPTIONS_KIND_BRIDGE] = net_init_bridge,
|
[NET_CLIENT_DRIVER_BRIDGE] = net_init_bridge,
|
||||||
#endif
|
#endif
|
||||||
[NET_CLIENT_OPTIONS_KIND_HUBPORT] = net_init_hubport,
|
[NET_CLIENT_DRIVER_HUBPORT] = net_init_hubport,
|
||||||
#ifdef CONFIG_VHOST_NET_USED
|
#ifdef CONFIG_VHOST_NET_USED
|
||||||
[NET_CLIENT_OPTIONS_KIND_VHOST_USER] = net_init_vhost_user,
|
[NET_CLIENT_DRIVER_VHOST_USER] = net_init_vhost_user,
|
||||||
#endif
|
#endif
|
||||||
#ifdef CONFIG_L2TPV3
|
#ifdef CONFIG_L2TPV3
|
||||||
[NET_CLIENT_OPTIONS_KIND_L2TPV3] = net_init_l2tpv3,
|
[NET_CLIENT_DRIVER_L2TPV3] = net_init_l2tpv3,
|
||||||
#endif
|
#endif
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
static int net_client_init1(const void *object, int is_netdev, Error **errp)
|
static int net_client_init1(const void *object, int is_netdev, Error **errp)
|
||||||
{
|
{
|
||||||
const NetClientOptions *opts;
|
|
||||||
Netdev legacy = {0};
|
Netdev legacy = {0};
|
||||||
const Netdev *netdev;
|
const Netdev *netdev;
|
||||||
const char *name;
|
const char *name;
|
||||||
@ -970,34 +969,72 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
|
|||||||
|
|
||||||
if (is_netdev) {
|
if (is_netdev) {
|
||||||
netdev = object;
|
netdev = object;
|
||||||
opts = netdev->opts;
|
|
||||||
name = netdev->id;
|
name = netdev->id;
|
||||||
|
|
||||||
if (opts->type == NET_CLIENT_OPTIONS_KIND_DUMP ||
|
if (netdev->type == NET_CLIENT_DRIVER_DUMP ||
|
||||||
opts->type == NET_CLIENT_OPTIONS_KIND_NIC ||
|
netdev->type == NET_CLIENT_DRIVER_NIC ||
|
||||||
!net_client_init_fun[opts->type]) {
|
!net_client_init_fun[netdev->type]) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
||||||
"a netdev backend type");
|
"a netdev backend type");
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
const NetLegacy *net = object;
|
const NetLegacy *net = object;
|
||||||
|
const NetLegacyOptions *opts = net->opts;
|
||||||
legacy.id = net->id;
|
legacy.id = net->id;
|
||||||
opts = legacy.opts = net->opts;
|
|
||||||
netdev = &legacy;
|
netdev = &legacy;
|
||||||
/* missing optional values have been initialized to "all bits zero" */
|
/* missing optional values have been initialized to "all bits zero" */
|
||||||
name = net->has_id ? net->id : net->name;
|
name = net->has_id ? net->id : net->name;
|
||||||
|
|
||||||
if (opts->type == NET_CLIENT_OPTIONS_KIND_NONE) {
|
/* Map the old options to the new flat type */
|
||||||
|
switch (opts->type) {
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_NONE:
|
||||||
return 0; /* nothing to do */
|
return 0; /* nothing to do */
|
||||||
}
|
case NET_LEGACY_OPTIONS_KIND_NIC:
|
||||||
if (opts->type == NET_CLIENT_OPTIONS_KIND_HUBPORT) {
|
legacy.type = NET_CLIENT_DRIVER_NIC;
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
legacy.u.nic = *opts->u.nic.data;
|
||||||
"a net type");
|
break;
|
||||||
return -1;
|
case NET_LEGACY_OPTIONS_KIND_USER:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_USER;
|
||||||
|
legacy.u.user = *opts->u.user.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_TAP:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_TAP;
|
||||||
|
legacy.u.tap = *opts->u.tap.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_L2TPV3:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_L2TPV3;
|
||||||
|
legacy.u.l2tpv3 = *opts->u.l2tpv3.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_SOCKET:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_SOCKET;
|
||||||
|
legacy.u.socket = *opts->u.socket.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_VDE:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_VDE;
|
||||||
|
legacy.u.vde = *opts->u.vde.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_DUMP:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_DUMP;
|
||||||
|
legacy.u.dump = *opts->u.dump.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_BRIDGE:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_BRIDGE;
|
||||||
|
legacy.u.bridge = *opts->u.bridge.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_NETMAP:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_NETMAP;
|
||||||
|
legacy.u.netmap = *opts->u.netmap.data;
|
||||||
|
break;
|
||||||
|
case NET_LEGACY_OPTIONS_KIND_VHOST_USER:
|
||||||
|
legacy.type = NET_CLIENT_DRIVER_VHOST_USER;
|
||||||
|
legacy.u.vhost_user = *opts->u.vhost_user.data;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
abort();
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!net_client_init_fun[opts->type]) {
|
if (!net_client_init_fun[netdev->type]) {
|
||||||
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
error_setg(errp, QERR_INVALID_PARAMETER_VALUE, "type",
|
||||||
"a net backend type (maybe it is not compiled "
|
"a net backend type (maybe it is not compiled "
|
||||||
"into this binary)");
|
"into this binary)");
|
||||||
@ -1005,17 +1042,17 @@ static int net_client_init1(const void *object, int is_netdev, Error **errp)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* Do not add to a vlan if it's a nic with a netdev= parameter. */
|
/* Do not add to a vlan if it's a nic with a netdev= parameter. */
|
||||||
if (opts->type != NET_CLIENT_OPTIONS_KIND_NIC ||
|
if (netdev->type != NET_CLIENT_DRIVER_NIC ||
|
||||||
!opts->u.nic.data->has_netdev) {
|
!opts->u.nic.data->has_netdev) {
|
||||||
peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
|
peer = net_hub_add_port(net->has_vlan ? net->vlan : 0, NULL);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (net_client_init_fun[opts->type](netdev, name, peer, errp) < 0) {
|
if (net_client_init_fun[netdev->type](netdev, name, peer, errp) < 0) {
|
||||||
/* FIXME drop when all init functions store an Error */
|
/* FIXME drop when all init functions store an Error */
|
||||||
if (errp && !*errp) {
|
if (errp && !*errp) {
|
||||||
error_setg(errp, QERR_DEVICE_INIT_FAILED,
|
error_setg(errp, QERR_DEVICE_INIT_FAILED,
|
||||||
NetClientOptionsKind_lookup[opts->type]);
|
NetClientDriver_lookup[netdev->type]);
|
||||||
}
|
}
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
@ -1135,7 +1172,7 @@ void hmp_host_net_remove(Monitor *mon, const QDict *qdict)
|
|||||||
device, vlan_id);
|
device, vlan_id);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->info->type == NET_CLIENT_DRIVER_NIC) {
|
||||||
error_report("invalid host network device '%s'", device);
|
error_report("invalid host network device '%s'", device);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
@ -1226,7 +1263,7 @@ void print_net_client(Monitor *mon, NetClientState *nc)
|
|||||||
|
|
||||||
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
|
monitor_printf(mon, "%s: index=%d,type=%s,%s\n", nc->name,
|
||||||
nc->queue_index,
|
nc->queue_index,
|
||||||
NetClientOptionsKind_lookup[nc->info->type],
|
NetClientDriver_lookup[nc->info->type],
|
||||||
nc->info_str);
|
nc->info_str);
|
||||||
if (!QTAILQ_EMPTY(&nc->filters)) {
|
if (!QTAILQ_EMPTY(&nc->filters)) {
|
||||||
monitor_printf(mon, "filters:\n");
|
monitor_printf(mon, "filters:\n");
|
||||||
@ -1256,7 +1293,7 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* only query rx-filter information of NIC */
|
/* only query rx-filter information of NIC */
|
||||||
if (nc->info->type != NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->info->type != NET_CLIENT_DRIVER_NIC) {
|
||||||
if (has_name) {
|
if (has_name) {
|
||||||
error_setg(errp, "net client(%s) isn't a NIC", name);
|
error_setg(errp, "net client(%s) isn't a NIC", name);
|
||||||
return NULL;
|
return NULL;
|
||||||
@ -1302,7 +1339,7 @@ RxFilterInfoList *qmp_query_rx_filter(bool has_name, const char *name,
|
|||||||
void hmp_info_network(Monitor *mon, const QDict *qdict)
|
void hmp_info_network(Monitor *mon, const QDict *qdict)
|
||||||
{
|
{
|
||||||
NetClientState *nc, *peer;
|
NetClientState *nc, *peer;
|
||||||
NetClientOptionsKind type;
|
NetClientDriver type;
|
||||||
|
|
||||||
net_hub_info(mon);
|
net_hub_info(mon);
|
||||||
|
|
||||||
@ -1315,10 +1352,10 @@ void hmp_info_network(Monitor *mon, const QDict *qdict)
|
|||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!peer || type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (!peer || type == NET_CLIENT_DRIVER_NIC) {
|
||||||
print_net_client(mon, nc);
|
print_net_client(mon, nc);
|
||||||
} /* else it's a netdev connected to a NIC, printed with the NIC */
|
} /* else it's a netdev connected to a NIC, printed with the NIC */
|
||||||
if (peer && type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (peer && type == NET_CLIENT_DRIVER_NIC) {
|
||||||
monitor_printf(mon, " \\ ");
|
monitor_printf(mon, " \\ ");
|
||||||
print_net_client(mon, peer);
|
print_net_client(mon, peer);
|
||||||
}
|
}
|
||||||
@ -1332,7 +1369,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
|
|||||||
int queues, i;
|
int queues, i;
|
||||||
|
|
||||||
queues = qemu_find_net_clients_except(name, ncs,
|
queues = qemu_find_net_clients_except(name, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND__MAX,
|
NET_CLIENT_DRIVER__MAX,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
|
|
||||||
if (queues == 0) {
|
if (queues == 0) {
|
||||||
@ -1359,7 +1396,7 @@ void qmp_set_link(const char *name, bool up, Error **errp)
|
|||||||
* multiple clients that can still communicate with each other in
|
* multiple clients that can still communicate with each other in
|
||||||
* disconnected mode. For now maintain this compatibility.
|
* disconnected mode. For now maintain this compatibility.
|
||||||
*/
|
*/
|
||||||
if (nc->peer->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->peer->info->type == NET_CLIENT_DRIVER_NIC) {
|
||||||
for (i = 0; i < queues; i++) {
|
for (i = 0; i < queues; i++) {
|
||||||
ncs[i]->peer->link_down = !up;
|
ncs[i]->peer->link_down = !up;
|
||||||
}
|
}
|
||||||
@ -1400,7 +1437,7 @@ void net_cleanup(void)
|
|||||||
*/
|
*/
|
||||||
while (!QTAILQ_EMPTY(&net_clients)) {
|
while (!QTAILQ_EMPTY(&net_clients)) {
|
||||||
nc = QTAILQ_FIRST(&net_clients);
|
nc = QTAILQ_FIRST(&net_clients);
|
||||||
if (nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC) {
|
if (nc->info->type == NET_CLIENT_DRIVER_NIC) {
|
||||||
qemu_del_nic(qemu_get_nic(nc));
|
qemu_del_nic(qemu_get_nic(nc));
|
||||||
} else {
|
} else {
|
||||||
qemu_del_net_client(nc);
|
qemu_del_net_client(nc);
|
||||||
@ -1420,7 +1457,7 @@ void net_check_clients(void)
|
|||||||
QTAILQ_FOREACH(nc, &net_clients, next) {
|
QTAILQ_FOREACH(nc, &net_clients, next) {
|
||||||
if (!nc->peer) {
|
if (!nc->peer) {
|
||||||
fprintf(stderr, "Warning: %s %s has no peer\n",
|
fprintf(stderr, "Warning: %s %s has no peer\n",
|
||||||
nc->info->type == NET_CLIENT_OPTIONS_KIND_NIC ?
|
nc->info->type == NET_CLIENT_DRIVER_NIC ?
|
||||||
"nic" : "netdev", nc->name);
|
"nic" : "netdev", nc->name);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -400,7 +400,7 @@ static void netmap_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
|
|||||||
|
|
||||||
/* NetClientInfo methods */
|
/* NetClientInfo methods */
|
||||||
static NetClientInfo net_netmap_info = {
|
static NetClientInfo net_netmap_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_NETMAP,
|
.type = NET_CLIENT_DRIVER_NETMAP,
|
||||||
.size = sizeof(NetmapState),
|
.size = sizeof(NetmapState),
|
||||||
.receive = netmap_receive,
|
.receive = netmap_receive,
|
||||||
.receive_iov = netmap_receive_iov,
|
.receive_iov = netmap_receive_iov,
|
||||||
@ -421,7 +421,7 @@ static NetClientInfo net_netmap_info = {
|
|||||||
int net_init_netmap(const Netdev *netdev,
|
int net_init_netmap(const Netdev *netdev,
|
||||||
const char *name, NetClientState *peer, Error **errp)
|
const char *name, NetClientState *peer, Error **errp)
|
||||||
{
|
{
|
||||||
const NetdevNetmapOptions *netmap_opts = netdev->opts->u.netmap.data;
|
const NetdevNetmapOptions *netmap_opts = &netdev->u.netmap;
|
||||||
struct nm_desc *nmd;
|
struct nm_desc *nmd;
|
||||||
NetClientState *nc;
|
NetClientState *nc;
|
||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
|
@ -137,7 +137,7 @@ static void net_slirp_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_slirp_info = {
|
static NetClientInfo net_slirp_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_USER,
|
.type = NET_CLIENT_DRIVER_USER,
|
||||||
.size = sizeof(SlirpState),
|
.size = sizeof(SlirpState),
|
||||||
.receive = net_slirp_receive,
|
.receive = net_slirp_receive,
|
||||||
.cleanup = net_slirp_cleanup,
|
.cleanup = net_slirp_cleanup,
|
||||||
@ -839,8 +839,8 @@ int net_init_slirp(const Netdev *netdev, const char *name,
|
|||||||
const char **dnssearch;
|
const char **dnssearch;
|
||||||
bool ipv4 = true, ipv6 = true;
|
bool ipv4 = true, ipv6 = true;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_USER);
|
assert(netdev->type == NET_CLIENT_DRIVER_USER);
|
||||||
user = netdev->opts->u.user.data;
|
user = &netdev->u.user;
|
||||||
|
|
||||||
if ((user->has_ipv6 && user->ipv6 && !user->has_ipv4) ||
|
if ((user->has_ipv6 && user->ipv6 && !user->has_ipv4) ||
|
||||||
(user->has_ipv4 && !user->ipv4)) {
|
(user->has_ipv4 && !user->ipv4)) {
|
||||||
|
@ -311,7 +311,7 @@ static void net_socket_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_dgram_socket_info = {
|
static NetClientInfo net_dgram_socket_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_SOCKET,
|
.type = NET_CLIENT_DRIVER_SOCKET,
|
||||||
.size = sizeof(NetSocketState),
|
.size = sizeof(NetSocketState),
|
||||||
.receive = net_socket_receive_dgram,
|
.receive = net_socket_receive_dgram,
|
||||||
.cleanup = net_socket_cleanup,
|
.cleanup = net_socket_cleanup,
|
||||||
@ -395,7 +395,7 @@ static void net_socket_connect(void *opaque)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_socket_info = {
|
static NetClientInfo net_socket_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_SOCKET,
|
.type = NET_CLIENT_DRIVER_SOCKET,
|
||||||
.size = sizeof(NetSocketState),
|
.size = sizeof(NetSocketState),
|
||||||
.receive = net_socket_receive,
|
.receive = net_socket_receive,
|
||||||
.cleanup = net_socket_cleanup,
|
.cleanup = net_socket_cleanup,
|
||||||
@ -670,8 +670,8 @@ int net_init_socket(const Netdev *netdev, const char *name,
|
|||||||
Error *err = NULL;
|
Error *err = NULL;
|
||||||
const NetdevSocketOptions *sock;
|
const NetdevSocketOptions *sock;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_SOCKET);
|
assert(netdev->type == NET_CLIENT_DRIVER_SOCKET);
|
||||||
sock = netdev->opts->u.socket.data;
|
sock = &netdev->u.socket;
|
||||||
|
|
||||||
if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
|
if (sock->has_fd + sock->has_listen + sock->has_connect + sock->has_mcast +
|
||||||
sock->has_udp != 1) {
|
sock->has_udp != 1) {
|
||||||
|
@ -750,7 +750,7 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_tap_win32_info = {
|
static NetClientInfo net_tap_win32_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_TAP,
|
.type = NET_CLIENT_DRIVER_TAP,
|
||||||
.size = sizeof(TAPState),
|
.size = sizeof(TAPState),
|
||||||
.receive = tap_receive,
|
.receive = tap_receive,
|
||||||
.cleanup = tap_cleanup,
|
.cleanup = tap_cleanup,
|
||||||
@ -794,8 +794,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
|||||||
/* FIXME error_setg(errp, ...) on failure */
|
/* FIXME error_setg(errp, ...) on failure */
|
||||||
const NetdevTapOptions *tap;
|
const NetdevTapOptions *tap;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
|
||||||
tap = netdev->opts->u.tap.data;
|
tap = &netdev->u.tap;
|
||||||
|
|
||||||
if (!tap->has_ifname) {
|
if (!tap->has_ifname) {
|
||||||
error_report("tap: no interface name");
|
error_report("tap: no interface name");
|
||||||
|
24
net/tap.c
24
net/tap.c
@ -223,7 +223,7 @@ static bool tap_has_ufo(NetClientState *nc)
|
|||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
|
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
|
|
||||||
return s->has_ufo;
|
return s->has_ufo;
|
||||||
}
|
}
|
||||||
@ -232,7 +232,7 @@ static bool tap_has_vnet_hdr(NetClientState *nc)
|
|||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
|
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
|
|
||||||
return !!s->host_vnet_hdr_len;
|
return !!s->host_vnet_hdr_len;
|
||||||
}
|
}
|
||||||
@ -241,7 +241,7 @@ static bool tap_has_vnet_hdr_len(NetClientState *nc, int len)
|
|||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
|
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
|
|
||||||
return !!tap_probe_vnet_hdr_len(s->fd, len);
|
return !!tap_probe_vnet_hdr_len(s->fd, len);
|
||||||
}
|
}
|
||||||
@ -250,7 +250,7 @@ static void tap_set_vnet_hdr_len(NetClientState *nc, int len)
|
|||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
|
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) ||
|
assert(len == sizeof(struct virtio_net_hdr_mrg_rxbuf) ||
|
||||||
len == sizeof(struct virtio_net_hdr));
|
len == sizeof(struct virtio_net_hdr));
|
||||||
|
|
||||||
@ -262,7 +262,7 @@ static void tap_using_vnet_hdr(NetClientState *nc, bool using_vnet_hdr)
|
|||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
|
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
assert(!!s->host_vnet_hdr_len == using_vnet_hdr);
|
assert(!!s->host_vnet_hdr_len == using_vnet_hdr);
|
||||||
|
|
||||||
s->using_vnet_hdr = using_vnet_hdr;
|
s->using_vnet_hdr = using_vnet_hdr;
|
||||||
@ -336,14 +336,14 @@ static void tap_poll(NetClientState *nc, bool enable)
|
|||||||
int tap_get_fd(NetClientState *nc)
|
int tap_get_fd(NetClientState *nc)
|
||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
return s->fd;
|
return s->fd;
|
||||||
}
|
}
|
||||||
|
|
||||||
/* fd support */
|
/* fd support */
|
||||||
|
|
||||||
static NetClientInfo net_tap_info = {
|
static NetClientInfo net_tap_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_TAP,
|
.type = NET_CLIENT_DRIVER_TAP,
|
||||||
.size = sizeof(TAPState),
|
.size = sizeof(TAPState),
|
||||||
.receive = tap_receive,
|
.receive = tap_receive,
|
||||||
.receive_raw = tap_receive_raw,
|
.receive_raw = tap_receive_raw,
|
||||||
@ -579,8 +579,8 @@ int net_init_bridge(const Netdev *netdev, const char *name,
|
|||||||
TAPState *s;
|
TAPState *s;
|
||||||
int fd, vnet_hdr;
|
int fd, vnet_hdr;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_BRIDGE);
|
assert(netdev->type == NET_CLIENT_DRIVER_BRIDGE);
|
||||||
bridge = netdev->opts->u.bridge.data;
|
bridge = &netdev->u.bridge;
|
||||||
|
|
||||||
helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
|
helper = bridge->has_helper ? bridge->helper : DEFAULT_BRIDGE_HELPER;
|
||||||
br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
|
br = bridge->has_br ? bridge->br : DEFAULT_BRIDGE_INTERFACE;
|
||||||
@ -747,8 +747,8 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
|||||||
const char *vhostfdname;
|
const char *vhostfdname;
|
||||||
char ifname[128];
|
char ifname[128];
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(netdev->type == NET_CLIENT_DRIVER_TAP);
|
||||||
tap = netdev->opts->u.tap.data;
|
tap = &netdev->u.tap;
|
||||||
queues = tap->has_queues ? tap->queues : 1;
|
queues = tap->has_queues ? tap->queues : 1;
|
||||||
vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
|
vhostfdname = tap->has_vhostfd ? tap->vhostfd : NULL;
|
||||||
|
|
||||||
@ -911,7 +911,7 @@ int net_init_tap(const Netdev *netdev, const char *name,
|
|||||||
VHostNetState *tap_get_vhost_net(NetClientState *nc)
|
VHostNetState *tap_get_vhost_net(NetClientState *nc)
|
||||||
{
|
{
|
||||||
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
TAPState *s = DO_UPCAST(TAPState, nc, nc);
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_TAP);
|
assert(nc->info->type == NET_CLIENT_DRIVER_TAP);
|
||||||
return s->vhost_net;
|
return s->vhost_net;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -68,7 +68,7 @@ static void vde_cleanup(NetClientState *nc)
|
|||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_vde_info = {
|
static NetClientInfo net_vde_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_VDE,
|
.type = NET_CLIENT_DRIVER_VDE,
|
||||||
.size = sizeof(VDEState),
|
.size = sizeof(VDEState),
|
||||||
.receive = vde_receive,
|
.receive = vde_receive,
|
||||||
.cleanup = vde_cleanup,
|
.cleanup = vde_cleanup,
|
||||||
@ -115,8 +115,8 @@ int net_init_vde(const Netdev *netdev, const char *name,
|
|||||||
/* FIXME error_setg(errp, ...) on failure */
|
/* FIXME error_setg(errp, ...) on failure */
|
||||||
const NetdevVdeOptions *vde;
|
const NetdevVdeOptions *vde;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VDE);
|
assert(netdev->type == NET_CLIENT_DRIVER_VDE);
|
||||||
vde = netdev->opts->u.vde.data;
|
vde = &netdev->u.vde;
|
||||||
|
|
||||||
/* missing optional values have been initialized to "all bits zero" */
|
/* missing optional values have been initialized to "all bits zero" */
|
||||||
if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
|
if (net_vde_init(peer, "vde", name, vde->sock, vde->port, vde->group,
|
||||||
|
@ -34,14 +34,14 @@ typedef struct VhostUserChardevProps {
|
|||||||
VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
|
VHostNetState *vhost_user_get_vhost_net(NetClientState *nc)
|
||||||
{
|
{
|
||||||
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
|
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
return s->vhost_net;
|
return s->vhost_net;
|
||||||
}
|
}
|
||||||
|
|
||||||
uint64_t vhost_user_get_acked_features(NetClientState *nc)
|
uint64_t vhost_user_get_acked_features(NetClientState *nc)
|
||||||
{
|
{
|
||||||
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
|
VhostUserState *s = DO_UPCAST(VhostUserState, nc, nc);
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
return s->acked_features;
|
return s->acked_features;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,7 +56,7 @@ static void vhost_user_stop(int queues, NetClientState *ncs[])
|
|||||||
int i;
|
int i;
|
||||||
|
|
||||||
for (i = 0; i < queues; i++) {
|
for (i = 0; i < queues; i++) {
|
||||||
assert (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
|
|
||||||
s = DO_UPCAST(VhostUserState, nc, ncs[i]);
|
s = DO_UPCAST(VhostUserState, nc, ncs[i]);
|
||||||
if (!vhost_user_running(s)) {
|
if (!vhost_user_running(s)) {
|
||||||
@ -82,7 +82,7 @@ static int vhost_user_start(int queues, NetClientState *ncs[])
|
|||||||
options.backend_type = VHOST_BACKEND_TYPE_USER;
|
options.backend_type = VHOST_BACKEND_TYPE_USER;
|
||||||
|
|
||||||
for (i = 0; i < queues; i++) {
|
for (i = 0; i < queues; i++) {
|
||||||
assert (ncs[i]->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(ncs[i]->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
|
|
||||||
s = DO_UPCAST(VhostUserState, nc, ncs[i]);
|
s = DO_UPCAST(VhostUserState, nc, ncs[i]);
|
||||||
if (vhost_user_running(s)) {
|
if (vhost_user_running(s)) {
|
||||||
@ -163,20 +163,20 @@ static void vhost_user_cleanup(NetClientState *nc)
|
|||||||
|
|
||||||
static bool vhost_user_has_vnet_hdr(NetClientState *nc)
|
static bool vhost_user_has_vnet_hdr(NetClientState *nc)
|
||||||
{
|
{
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static bool vhost_user_has_ufo(NetClientState *nc)
|
static bool vhost_user_has_ufo(NetClientState *nc)
|
||||||
{
|
{
|
||||||
assert(nc->info->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(nc->info->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
static NetClientInfo net_vhost_user_info = {
|
static NetClientInfo net_vhost_user_info = {
|
||||||
.type = NET_CLIENT_OPTIONS_KIND_VHOST_USER,
|
.type = NET_CLIENT_DRIVER_VHOST_USER,
|
||||||
.size = sizeof(VhostUserState),
|
.size = sizeof(VhostUserState),
|
||||||
.receive = vhost_user_receive,
|
.receive = vhost_user_receive,
|
||||||
.cleanup = vhost_user_cleanup,
|
.cleanup = vhost_user_cleanup,
|
||||||
@ -207,7 +207,7 @@ static void net_vhost_user_event(void *opaque, int event)
|
|||||||
int queues;
|
int queues;
|
||||||
|
|
||||||
queues = qemu_find_net_clients_except(name, ncs,
|
queues = qemu_find_net_clients_except(name, ncs,
|
||||||
NET_CLIENT_OPTIONS_KIND_NIC,
|
NET_CLIENT_DRIVER_NIC,
|
||||||
MAX_QUEUE_NUM);
|
MAX_QUEUE_NUM);
|
||||||
assert(queues < MAX_QUEUE_NUM);
|
assert(queues < MAX_QUEUE_NUM);
|
||||||
|
|
||||||
@ -341,8 +341,8 @@ int net_init_vhost_user(const Netdev *netdev, const char *name,
|
|||||||
const NetdevVhostUserOptions *vhost_user_opts;
|
const NetdevVhostUserOptions *vhost_user_opts;
|
||||||
CharDriverState *chr;
|
CharDriverState *chr;
|
||||||
|
|
||||||
assert(netdev->opts->type == NET_CLIENT_OPTIONS_KIND_VHOST_USER);
|
assert(netdev->type == NET_CLIENT_DRIVER_VHOST_USER);
|
||||||
vhost_user_opts = netdev->opts->u.vhost_user.data;
|
vhost_user_opts = &netdev->u.vhost_user;
|
||||||
|
|
||||||
chr = net_vhost_parse_chardev(vhost_user_opts, errp);
|
chr = net_vhost_parse_chardev(vhost_user_opts, errp);
|
||||||
if (!chr) {
|
if (!chr) {
|
||||||
|
@ -2809,16 +2809,32 @@
|
|||||||
'*queues': 'int' } }
|
'*queues': 'int' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @NetClientOptions
|
# @NetClientDriver
|
||||||
#
|
#
|
||||||
# A discriminated record of network device traits.
|
# Available netdev drivers.
|
||||||
|
#
|
||||||
|
# Since 2.7
|
||||||
|
##
|
||||||
|
{ 'enum': 'NetClientDriver',
|
||||||
|
'data': [ 'none', 'nic', 'user', 'tap', 'l2tpv3', 'socket', 'vde', 'dump',
|
||||||
|
'bridge', 'hubport', 'netmap', 'vhost-user' ] }
|
||||||
|
|
||||||
|
##
|
||||||
|
# @Netdev
|
||||||
|
#
|
||||||
|
# Captures the configuration of a network device.
|
||||||
|
#
|
||||||
|
# @id: identifier for monitor commands.
|
||||||
|
#
|
||||||
|
# @type: Specify the driver used for interpreting remaining arguments.
|
||||||
#
|
#
|
||||||
# Since 1.2
|
# Since 1.2
|
||||||
#
|
#
|
||||||
# 'l2tpv3' - since 2.1
|
# 'l2tpv3' - since 2.1
|
||||||
#
|
|
||||||
##
|
##
|
||||||
{ 'union': 'NetClientOptions',
|
{ 'union': 'Netdev',
|
||||||
|
'base': { 'id': 'str', 'type': 'NetClientDriver' },
|
||||||
|
'discriminator': 'type',
|
||||||
'data': {
|
'data': {
|
||||||
'none': 'NetdevNoneOptions',
|
'none': 'NetdevNoneOptions',
|
||||||
'nic': 'NetLegacyNicOptions',
|
'nic': 'NetLegacyNicOptions',
|
||||||
@ -2853,23 +2869,28 @@
|
|||||||
'*vlan': 'int32',
|
'*vlan': 'int32',
|
||||||
'*id': 'str',
|
'*id': 'str',
|
||||||
'*name': 'str',
|
'*name': 'str',
|
||||||
'opts': 'NetClientOptions' } }
|
'opts': 'NetLegacyOptions' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @Netdev
|
# @NetLegacyOptions
|
||||||
#
|
#
|
||||||
# Captures the configuration of a network device.
|
# Like Netdev, but for use only by the legacy command line options
|
||||||
#
|
|
||||||
# @id: identifier for monitor commands.
|
|
||||||
#
|
|
||||||
# @opts: device type specific properties
|
|
||||||
#
|
#
|
||||||
# Since 1.2
|
# Since 1.2
|
||||||
##
|
##
|
||||||
{ 'struct': 'Netdev',
|
{ 'union': 'NetLegacyOptions',
|
||||||
'data': {
|
'data': {
|
||||||
'id': 'str',
|
'none': 'NetdevNoneOptions',
|
||||||
'opts': 'NetClientOptions' } }
|
'nic': 'NetLegacyNicOptions',
|
||||||
|
'user': 'NetdevUserOptions',
|
||||||
|
'tap': 'NetdevTapOptions',
|
||||||
|
'l2tpv3': 'NetdevL2TPv3Options',
|
||||||
|
'socket': 'NetdevSocketOptions',
|
||||||
|
'vde': 'NetdevVdeOptions',
|
||||||
|
'dump': 'NetdevDumpOptions',
|
||||||
|
'bridge': 'NetdevBridgeOptions',
|
||||||
|
'netmap': 'NetdevNetmapOptions',
|
||||||
|
'vhost-user': 'NetdevVhostUserOptions' } }
|
||||||
|
|
||||||
##
|
##
|
||||||
# @NetFilterDirection
|
# @NetFilterDirection
|
||||||
|
Loading…
Reference in New Issue
Block a user