2007-11-18 01:14:51 +08:00
|
|
|
#ifndef QEMU_NET_H
|
|
|
|
#define QEMU_NET_H
|
|
|
|
|
2012-12-18 01:20:00 +08:00
|
|
|
#include "qemu/queue.h"
|
2018-02-11 17:36:01 +08:00
|
|
|
#include "qapi/qapi-types-net.h"
|
2009-10-24 00:52:16 +08:00
|
|
|
#include "net/queue.h"
|
2008-12-18 03:13:11 +08:00
|
|
|
|
2016-06-01 16:23:37 +08:00
|
|
|
#define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
|
|
|
|
#define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
|
|
|
|
((uint8_t *)(x))[2], ((uint8_t *)(x))[3], \
|
|
|
|
((uint8_t *)(x))[4], ((uint8_t *)(x))[5]
|
|
|
|
|
2013-01-30 19:12:28 +08:00
|
|
|
#define MAX_QUEUE_NUM 1024
|
|
|
|
|
2013-03-19 02:43:44 +08:00
|
|
|
/* Maximum GSO packet size (64k) plus plenty of room for
|
|
|
|
* the ethernet and virtio_net headers
|
|
|
|
*/
|
|
|
|
#define NET_BUFSIZE (4096 + 65536)
|
|
|
|
|
2009-10-21 21:25:22 +08:00
|
|
|
struct MACAddr {
|
|
|
|
uint8_t a[6];
|
|
|
|
};
|
|
|
|
|
2009-10-21 21:25:26 +08:00
|
|
|
/* qdev nic properties */
|
|
|
|
|
2013-01-30 19:12:28 +08:00
|
|
|
typedef struct NICPeers {
|
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
2014-05-26 18:04:08 +08:00
|
|
|
int32_t queues;
|
2013-01-30 19:12:28 +08:00
|
|
|
} NICPeers;
|
|
|
|
|
2009-10-21 21:25:26 +08:00
|
|
|
typedef struct NICConf {
|
|
|
|
MACAddr macaddr;
|
2013-01-30 19:12:28 +08:00
|
|
|
NICPeers peers;
|
2010-12-08 19:35:05 +08:00
|
|
|
int32_t bootindex;
|
2009-10-21 21:25:26 +08:00
|
|
|
} NICConf;
|
|
|
|
|
|
|
|
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
|
2014-10-07 16:00:21 +08:00
|
|
|
DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
|
2009-10-21 21:25:26 +08:00
|
|
|
|
2013-01-30 19:12:28 +08:00
|
|
|
|
2012-07-24 23:35:13 +08:00
|
|
|
/* Net clients */
|
2007-11-18 01:14:51 +08:00
|
|
|
|
2012-07-24 23:35:13 +08:00
|
|
|
typedef void (NetPoll)(NetClientState *, bool enable);
|
2020-03-06 01:56:49 +08:00
|
|
|
typedef bool (NetCanReceive)(NetClientState *);
|
2012-07-24 23:35:13 +08:00
|
|
|
typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
|
|
|
|
typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
|
|
|
|
typedef void (NetCleanup) (NetClientState *);
|
|
|
|
typedef void (LinkStatusChanged)(NetClientState *);
|
2013-01-30 19:12:27 +08:00
|
|
|
typedef void (NetClientDestructor)(NetClientState *);
|
net: add support of mac-programming over macvtap in QEMU side
Currently macvtap based macvlan device is working in promiscuous
mode, we want to implement mac-programming over macvtap through
Libvirt for better performance.
Design:
QEMU notifies Libvirt when rx-filter config is changed in guest,
then Libvirt query the rx-filter information by a monitor command,
and sync the change to macvtap device. Related rx-filter config
of the nic contains main mac, rx-mode items and vlan table.
This patch adds a QMP event to notify management of rx-filter change,
and adds a monitor command for management to query rx-filter
information.
Test:
If we repeatedly add/remove vlan, and change macaddr of vlan
interfaces in guest by a loop script.
Result:
The events will flood the QMP client(management), management takes
too much resource to process the events.
Event_throttle API (set rate to 1 ms) can avoid the events to flood
QMP client, but it could cause an unexpected delay (~1ms), guests
guests normally expect rx-filter updates immediately.
So we use a flag for each nic to avoid events flooding, the event
is emitted once until the query command is executed. The flag
implementation could not introduce unexpected delay.
There maybe exist an uncontrollable delay if we let Libvirt do the
real change, guests normally expect rx-filter updates immediately.
But it's another separate issue, we can investigate it when the
work in Libvirt side is done.
Michael S. Tsirkin: tweaked to enable events on start
Michael S. Tsirkin: fixed not to crash when no id
Michael S. Tsirkin: fold in patch:
"additional fixes for mac-programming feature"
Amos Kong: always notify QMP client if mactable is changed
Amos Kong: return NULL list if no net client supports rx-filter query
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2013-06-14 15:45:52 +08:00
|
|
|
typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
|
2014-02-07 00:02:16 +08:00
|
|
|
typedef bool (HasUfo)(NetClientState *);
|
|
|
|
typedef bool (HasVnetHdr)(NetClientState *);
|
|
|
|
typedef bool (HasVnetHdrLen)(NetClientState *, int);
|
|
|
|
typedef void (UsingVnetHdr)(NetClientState *, bool);
|
|
|
|
typedef void (SetOffload)(NetClientState *, int, int, int, int, int);
|
|
|
|
typedef void (SetVnetHdrLen)(NetClientState *, int);
|
2015-06-17 21:23:44 +08:00
|
|
|
typedef int (SetVnetLE)(NetClientState *, bool);
|
|
|
|
typedef int (SetVnetBE)(NetClientState *, bool);
|
2016-05-13 15:35:19 +08:00
|
|
|
typedef struct SocketReadState SocketReadState;
|
|
|
|
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
|
2019-02-27 21:24:09 +08:00
|
|
|
typedef void (NetAnnounce)(NetClientState *);
|
2009-01-09 03:45:03 +08:00
|
|
|
|
2009-11-26 02:49:01 +08:00
|
|
|
typedef struct NetClientInfo {
|
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>
2016-07-14 11:50:23 +08:00
|
|
|
NetClientDriver type;
|
2009-11-26 02:49:01 +08:00
|
|
|
size_t size;
|
|
|
|
NetReceive *receive;
|
|
|
|
NetReceive *receive_raw;
|
|
|
|
NetReceiveIOV *receive_iov;
|
|
|
|
NetCanReceive *can_receive;
|
|
|
|
NetCleanup *cleanup;
|
|
|
|
LinkStatusChanged *link_status_changed;
|
net: add support of mac-programming over macvtap in QEMU side
Currently macvtap based macvlan device is working in promiscuous
mode, we want to implement mac-programming over macvtap through
Libvirt for better performance.
Design:
QEMU notifies Libvirt when rx-filter config is changed in guest,
then Libvirt query the rx-filter information by a monitor command,
and sync the change to macvtap device. Related rx-filter config
of the nic contains main mac, rx-mode items and vlan table.
This patch adds a QMP event to notify management of rx-filter change,
and adds a monitor command for management to query rx-filter
information.
Test:
If we repeatedly add/remove vlan, and change macaddr of vlan
interfaces in guest by a loop script.
Result:
The events will flood the QMP client(management), management takes
too much resource to process the events.
Event_throttle API (set rate to 1 ms) can avoid the events to flood
QMP client, but it could cause an unexpected delay (~1ms), guests
guests normally expect rx-filter updates immediately.
So we use a flag for each nic to avoid events flooding, the event
is emitted once until the query command is executed. The flag
implementation could not introduce unexpected delay.
There maybe exist an uncontrollable delay if we let Libvirt do the
real change, guests normally expect rx-filter updates immediately.
But it's another separate issue, we can investigate it when the
work in Libvirt side is done.
Michael S. Tsirkin: tweaked to enable events on start
Michael S. Tsirkin: fixed not to crash when no id
Michael S. Tsirkin: fold in patch:
"additional fixes for mac-programming feature"
Amos Kong: always notify QMP client if mactable is changed
Amos Kong: return NULL list if no net client supports rx-filter query
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2013-06-14 15:45:52 +08:00
|
|
|
QueryRxFilter *query_rx_filter;
|
2009-12-24 20:46:29 +08:00
|
|
|
NetPoll *poll;
|
2014-02-07 00:02:16 +08:00
|
|
|
HasUfo *has_ufo;
|
|
|
|
HasVnetHdr *has_vnet_hdr;
|
|
|
|
HasVnetHdrLen *has_vnet_hdr_len;
|
|
|
|
UsingVnetHdr *using_vnet_hdr;
|
|
|
|
SetOffload *set_offload;
|
|
|
|
SetVnetHdrLen *set_vnet_hdr_len;
|
2015-06-17 21:23:44 +08:00
|
|
|
SetVnetLE *set_vnet_le;
|
|
|
|
SetVnetBE *set_vnet_be;
|
2019-02-27 21:24:09 +08:00
|
|
|
NetAnnounce *announce;
|
2009-11-26 02:49:01 +08:00
|
|
|
} NetClientInfo;
|
|
|
|
|
2012-07-24 23:35:13 +08:00
|
|
|
struct NetClientState {
|
2009-11-26 02:49:30 +08:00
|
|
|
NetClientInfo *info;
|
2009-01-09 03:44:06 +08:00
|
|
|
int link_down;
|
2012-07-24 23:35:13 +08:00
|
|
|
QTAILQ_ENTRY(NetClientState) next;
|
|
|
|
NetClientState *peer;
|
2013-08-03 03:47:08 +08:00
|
|
|
NetQueue *incoming_queue;
|
2009-01-08 01:42:25 +08:00
|
|
|
char *model;
|
2009-01-08 01:43:44 +08:00
|
|
|
char *name;
|
2007-11-18 01:14:51 +08:00
|
|
|
char info_str[256];
|
2009-10-28 02:16:36 +08:00
|
|
|
unsigned receive_disabled : 1;
|
2013-01-30 19:12:27 +08:00
|
|
|
NetClientDestructor *destructor;
|
2013-01-30 19:12:28 +08:00
|
|
|
unsigned int queue_index;
|
net: add support of mac-programming over macvtap in QEMU side
Currently macvtap based macvlan device is working in promiscuous
mode, we want to implement mac-programming over macvtap through
Libvirt for better performance.
Design:
QEMU notifies Libvirt when rx-filter config is changed in guest,
then Libvirt query the rx-filter information by a monitor command,
and sync the change to macvtap device. Related rx-filter config
of the nic contains main mac, rx-mode items and vlan table.
This patch adds a QMP event to notify management of rx-filter change,
and adds a monitor command for management to query rx-filter
information.
Test:
If we repeatedly add/remove vlan, and change macaddr of vlan
interfaces in guest by a loop script.
Result:
The events will flood the QMP client(management), management takes
too much resource to process the events.
Event_throttle API (set rate to 1 ms) can avoid the events to flood
QMP client, but it could cause an unexpected delay (~1ms), guests
guests normally expect rx-filter updates immediately.
So we use a flag for each nic to avoid events flooding, the event
is emitted once until the query command is executed. The flag
implementation could not introduce unexpected delay.
There maybe exist an uncontrollable delay if we let Libvirt do the
real change, guests normally expect rx-filter updates immediately.
But it's another separate issue, we can investigate it when the
work in Libvirt side is done.
Michael S. Tsirkin: tweaked to enable events on start
Michael S. Tsirkin: fixed not to crash when no id
Michael S. Tsirkin: fold in patch:
"additional fixes for mac-programming feature"
Amos Kong: always notify QMP client if mactable is changed
Amos Kong: return NULL list if no net client supports rx-filter query
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Markus Armbruster <armbru@redhat.com>
Signed-off-by: Amos Kong <akong@redhat.com>
Signed-off-by: Michael S. Tsirkin <mst@redhat.com>
2013-06-14 15:45:52 +08:00
|
|
|
unsigned rxfilter_notify_enabled:1;
|
2016-06-07 00:45:06 +08:00
|
|
|
int vring_enable;
|
2017-07-04 14:53:45 +08:00
|
|
|
int vnet_hdr_len;
|
2020-03-18 04:17:11 +08:00
|
|
|
bool is_netdev;
|
2018-12-06 20:10:34 +08:00
|
|
|
QTAILQ_HEAD(, NetFilterState) filters;
|
2007-11-18 01:14:51 +08:00
|
|
|
};
|
|
|
|
|
2009-11-26 02:49:10 +08:00
|
|
|
typedef struct NICState {
|
2013-02-22 23:15:06 +08:00
|
|
|
NetClientState *ncs;
|
2009-11-26 02:49:10 +08:00
|
|
|
NICConf *conf;
|
|
|
|
void *opaque;
|
2010-09-21 00:08:41 +08:00
|
|
|
bool peer_deleted;
|
2009-11-26 02:49:10 +08:00
|
|
|
} NICState;
|
|
|
|
|
2016-05-13 15:35:19 +08:00
|
|
|
struct SocketReadState {
|
2017-07-04 14:53:46 +08:00
|
|
|
/* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
|
|
|
|
int state;
|
|
|
|
/* This flag decide whether to read the vnet_hdr_len field */
|
|
|
|
bool vnet_hdr;
|
2016-05-13 15:35:19 +08:00
|
|
|
uint32_t index;
|
|
|
|
uint32_t packet_len;
|
2017-07-04 14:53:46 +08:00
|
|
|
uint32_t vnet_hdr_len;
|
2016-05-13 15:35:19 +08:00
|
|
|
uint8_t buf[NET_BUFSIZE];
|
|
|
|
SocketReadStateFinalize *finalize;
|
|
|
|
};
|
|
|
|
|
|
|
|
int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size);
|
2015-03-14 12:09:25 +08:00
|
|
|
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
2012-07-24 23:35:13 +08:00
|
|
|
NetClientState *qemu_find_netdev(const char *id);
|
2013-01-30 19:12:25 +08:00
|
|
|
int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
|
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>
2016-07-14 11:50:23 +08:00
|
|
|
NetClientDriver type, int max);
|
2012-07-24 23:35:13 +08:00
|
|
|
NetClientState *qemu_new_net_client(NetClientInfo *info,
|
|
|
|
NetClientState *peer,
|
|
|
|
const char *model,
|
|
|
|
const char *name);
|
2009-11-26 02:49:10 +08:00
|
|
|
NICState *qemu_new_nic(NetClientInfo *info,
|
|
|
|
NICConf *conf,
|
|
|
|
const char *model,
|
|
|
|
const char *name,
|
|
|
|
void *opaque);
|
2013-01-30 19:12:24 +08:00
|
|
|
void qemu_del_nic(NICState *nic);
|
2013-01-30 19:12:28 +08:00
|
|
|
NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
|
2013-01-30 19:12:22 +08:00
|
|
|
NetClientState *qemu_get_queue(NICState *nic);
|
2013-01-30 19:12:23 +08:00
|
|
|
NICState *qemu_get_nic(NetClientState *nc);
|
|
|
|
void *qemu_get_nic_opaque(NetClientState *nc);
|
2012-07-24 23:35:15 +08:00
|
|
|
void qemu_del_net_client(NetClientState *nc);
|
2009-11-26 02:49:31 +08:00
|
|
|
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
|
|
|
|
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
|
2012-07-24 23:35:14 +08:00
|
|
|
int qemu_can_send_packet(NetClientState *nc);
|
|
|
|
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
|
2008-12-18 03:13:11 +08:00
|
|
|
int iovcnt);
|
2012-07-24 23:35:14 +08:00
|
|
|
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
|
2009-04-29 19:15:26 +08:00
|
|
|
int iovcnt, NetPacketSent *sent_cb);
|
2019-01-17 19:43:54 +08:00
|
|
|
ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
|
2012-07-24 23:35:14 +08:00
|
|
|
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
|
|
|
|
ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
|
2009-04-29 19:15:26 +08:00
|
|
|
int size, NetPacketSent *sent_cb);
|
2012-07-24 23:35:14 +08:00
|
|
|
void qemu_purge_queued_packets(NetClientState *nc);
|
|
|
|
void qemu_flush_queued_packets(NetClientState *nc);
|
virtio_net: flush uncompleted TX on reset
If the backend could not transmit a packet right away for some reason,
the packet is queued for asynchronous sending. The corresponding vq
element is tracked in the async_tx.elem field of the VirtIONetQueue,
for later freeing when the transmission is complete.
If a reset happens before completion, virtio_net_tx_complete() will push
async_tx.elem back to the guest anyway, and we end up with the inuse flag
of the vq being equal to -1. The next call to virtqueue_pop() is then
likely to fail with "Virtqueue size exceeded".
This can be reproduced easily by starting a guest with an hubport backend
that is not connected to a functional network, eg,
-device virtio-net-pci,netdev=hub0 -netdev hubport,id=hub0,hubid=0
and no other -netdev hubport,hubid=0 on the command line.
The appropriate fix is to ensure that such an asynchronous transmission
cannot survive a device reset. So for all queues, we first try to send
the packet again, and eventually we purge it if the backend still could
not deliver it.
CC: qemu-stable@nongnu.org
Reported-by: R. Nageswara Sastry <nasastry@in.ibm.com>
Buglink: https://github.com/open-power-host-os/qemu/issues/37
Signed-off-by: Greg Kurz <groug@kaod.org>
Tested-by: R. Nageswara Sastry <nasastry@in.ibm.com>
Signed-off-by: Jason Wang <jasowang@redhat.com>
2018-03-20 18:44:56 +08:00
|
|
|
void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge);
|
2012-07-24 23:35:14 +08:00
|
|
|
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
|
2014-02-20 19:14:07 +08:00
|
|
|
bool qemu_has_ufo(NetClientState *nc);
|
|
|
|
bool qemu_has_vnet_hdr(NetClientState *nc);
|
|
|
|
bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
|
|
|
|
void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
|
|
|
|
void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
|
|
|
|
int ecn, int ufo);
|
|
|
|
void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
|
2015-06-17 21:23:44 +08:00
|
|
|
int qemu_set_vnet_le(NetClientState *nc, bool is_le);
|
|
|
|
int qemu_set_vnet_be(NetClientState *nc, bool is_be);
|
2009-10-21 21:25:22 +08:00
|
|
|
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
|
2009-09-25 09:53:51 +08:00
|
|
|
int qemu_show_nic_models(const char *arg, const char *const *models);
|
2009-01-14 03:03:57 +08:00
|
|
|
void qemu_check_nic_model(NICInfo *nd, const char *model);
|
2009-09-25 09:53:51 +08:00
|
|
|
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
|
|
|
|
const char *default_model);
|
2007-11-18 01:14:51 +08:00
|
|
|
|
2012-07-24 23:35:16 +08:00
|
|
|
void print_net_client(Monitor *mon, NetClientState *nc);
|
2015-02-06 21:18:24 +08:00
|
|
|
void hmp_info_network(Monitor *mon, const QDict *qdict);
|
2016-05-13 15:35:19 +08:00
|
|
|
void net_socket_rs_init(SocketReadState *rs,
|
2017-07-04 14:53:46 +08:00
|
|
|
SocketReadStateFinalize *finalize,
|
|
|
|
bool vnet_hdr);
|
2007-11-18 01:14:51 +08:00
|
|
|
|
|
|
|
/* NIC info */
|
|
|
|
|
|
|
|
#define MAX_NICS 8
|
|
|
|
|
|
|
|
struct NICInfo {
|
2011-07-20 18:20:22 +08:00
|
|
|
MACAddr macaddr;
|
2009-10-06 19:16:53 +08:00
|
|
|
char *model;
|
|
|
|
char *name;
|
|
|
|
char *devaddr;
|
2012-07-24 23:35:13 +08:00
|
|
|
NetClientState *netdev;
|
2011-05-20 23:50:01 +08:00
|
|
|
int used; /* is this slot in nd_table[] being used? */
|
|
|
|
int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
|
2009-06-22 00:51:18 +08:00
|
|
|
int nvectors;
|
2007-11-18 01:14:51 +08:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int nb_nics;
|
|
|
|
extern NICInfo nd_table[MAX_NICS];
|
2014-05-28 06:39:33 +08:00
|
|
|
extern const char *host_net_devices[];
|
2007-11-18 01:14:51 +08:00
|
|
|
|
2008-11-01 03:10:00 +08:00
|
|
|
/* from net.c */
|
2009-10-09 02:58:25 +08:00
|
|
|
int net_client_parse(QemuOptsList *opts_list, const char *str);
|
2018-02-21 18:18:30 +08:00
|
|
|
int net_init_clients(Error **errp);
|
2010-02-11 21:44:58 +08:00
|
|
|
void net_check_clients(void);
|
2008-11-01 03:10:00 +08:00
|
|
|
void net_cleanup(void);
|
hmp: Name HMP command handler functions hmp_COMMAND()
Some are called do_COMMAND() (old ones, usually), some hmp_COMMAND(),
and sometimes COMMAND pointlessly differs in spelling.
Normalize to hmp_COMMAND(), where COMMAND is exactly the command name
with '-' replaced by '_'.
Exceptions:
* do_device_add() and client_migrate_info() *not* renamed to
hmp_device_add(), hmp_client_migrate_info(), because they're also
QMP handlers. They still need to be converted to QAPI.
* do_memory_dump(), do_physical_memory_dump(), do_ioport_read(),
do_ioport_write() renamed do hmp_* instead of hmp_x(), hmp_xp(),
hmp_i(), hmp_o(), because those names are too cryptic for my taste.
* do_info_help() renamed to hmp_info_help() instead of hmp_info(),
because it only covers help.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
2015-02-06 20:55:43 +08:00
|
|
|
void hmp_host_net_add(Monitor *mon, const QDict *qdict);
|
|
|
|
void hmp_host_net_remove(Monitor *mon, const QDict *qdict);
|
2012-04-19 04:34:15 +08:00
|
|
|
void netdev_add(QemuOpts *opts, Error **errp);
|
2008-11-01 03:10:00 +08:00
|
|
|
|
2012-10-24 14:43:34 +08:00
|
|
|
int net_hub_id_for_client(NetClientState *nc, int *id);
|
|
|
|
NetClientState *net_hub_port_find(int hub_id);
|
|
|
|
|
2008-12-19 06:43:48 +08:00
|
|
|
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
|
|
|
|
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
|
Add support for net bridge
The most common use of -net tap is to connect a tap device to a bridge. This
requires the use of a script and running qemu as root in order to allocate a
tap device to pass to the script.
This model is great for portability and flexibility but it's incredibly
difficult to eliminate the need to run qemu as root. The only really viable
mechanism is to use tunctl to create a tap device, attach it to a bridge as
root, and then hand that tap device to qemu. The problem with this mechanism
is that it requires administrator intervention whenever a user wants to create
a guest.
By essentially writing a helper that implements the most common qemu-ifup
script that can be safely given cap_net_admin, we can dramatically simplify
things for non-privileged users. We still support existing -net tap options
as a mechanism for advanced users and backwards compatibility.
Currently, this is very Linux centric but there's really no reason why it
couldn't be extended for other Unixes.
A typical invocation would be similar to one of the following:
qemu linux.img -net bridge -net nic,model=virtio
qemu linux.img -net tap,helper="/usr/local/libexec/qemu-bridge-helper"
-net nic,model=virtio
qemu linux.img -netdev bridge,id=hn0
-device virtio-net-pci,netdev=hn0,id=nic1
qemu linux.img -netdev tap,helper="/usr/local/libexec/qemu-bridge-helper",id=hn0
-device virtio-net-pci,netdev=hn0,id=nic1
The default bridge that we attach to is br0. The thinking is that a distro
could preconfigure such an interface to allow out-of-the-box bridged networking.
Alternatively, if a user wants to use a different bridge, a typical invocation
would be simliar to one of the following:
qemu linux.img -net bridge,br=qemubr0 -net nic,model=virtio
qemu linux.img -net tap,helper="/usr/local/libexec/qemu-bridge-helper --br=qemubr0"
-net nic,model=virtio
qemu linux.img -netdev bridge,br=qemubr0,id=hn0
-device virtio-net-pci,netdev=hn0,id=nic1
qemu linux.img -netdev tap,helper="/usr/local/libexec/qemu-bridge-helper --br=qemubr0",id=hn0
-device virtio-net-pci,netdev=hn0,id=nic1
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
Signed-off-by: Richa Marwaha <rmarwah@linux.vnet.ibm.com>
Signed-off-by: Corey Bryant <coreyb@linux.vnet.ibm.com>
Signed-off-by: Anthony Liguori <aliguori@us.ibm.com>
2012-01-26 22:42:27 +08:00
|
|
|
#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
|
|
|
|
#define DEFAULT_BRIDGE_INTERFACE "br0"
|
2008-12-19 06:43:48 +08:00
|
|
|
|
2009-10-21 21:25:26 +08:00
|
|
|
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
|
2009-05-15 05:35:07 +08:00
|
|
|
|
2017-12-16 02:41:43 +08:00
|
|
|
#define POLYNOMIAL_BE 0x04c11db6
|
2017-12-16 02:41:44 +08:00
|
|
|
#define POLYNOMIAL_LE 0xedb88320
|
2017-12-16 02:41:43 +08:00
|
|
|
uint32_t net_crc32(const uint8_t *p, int len);
|
2017-12-16 02:41:44 +08:00
|
|
|
uint32_t net_crc32_le(const uint8_t *p, int len);
|
2012-03-05 11:08:50 +08:00
|
|
|
|
2012-01-14 00:07:20 +08:00
|
|
|
#define vmstate_offset_macaddr(_state, _field) \
|
|
|
|
vmstate_offset_array(_state, _field.a, uint8_t, \
|
|
|
|
sizeof(typeof_field(_state, _field)))
|
|
|
|
|
|
|
|
#define VMSTATE_MACADDR(_field, _state) { \
|
|
|
|
.name = (stringify(_field)), \
|
|
|
|
.size = sizeof(MACAddr), \
|
|
|
|
.info = &vmstate_info_buffer, \
|
|
|
|
.flags = VMS_BUFFER, \
|
|
|
|
.offset = vmstate_offset_macaddr(_state, _field), \
|
|
|
|
}
|
|
|
|
|
2007-11-18 01:14:51 +08:00
|
|
|
#endif
|