2007-11-17 20:14:51 +03:00
|
|
|
#ifndef QEMU_NET_H
|
|
|
|
#define QEMU_NET_H
|
|
|
|
|
2012-12-17 21:20:00 +04:00
|
|
|
#include "qemu/queue.h"
|
2018-02-11 12:36:01 +03:00
|
|
|
#include "qapi/qapi-types-net.h"
|
2009-10-23 20:52:16 +04:00
|
|
|
#include "net/queue.h"
|
2008-12-17 22:13:11 +03:00
|
|
|
|
2016-06-01 11:23:37 +03: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 15:12:28 +04:00
|
|
|
#define MAX_QUEUE_NUM 1024
|
|
|
|
|
2013-03-18 22:43:44 +04: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 17:25:22 +04:00
|
|
|
struct MACAddr {
|
|
|
|
uint8_t a[6];
|
|
|
|
};
|
|
|
|
|
2009-10-21 17:25:26 +04:00
|
|
|
/* qdev nic properties */
|
|
|
|
|
2013-01-30 15:12:28 +04:00
|
|
|
typedef struct NICPeers {
|
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
2014-05-26 14:04:08 +04:00
|
|
|
int32_t queues;
|
2013-01-30 15:12:28 +04:00
|
|
|
} NICPeers;
|
|
|
|
|
2009-10-21 17:25:26 +04:00
|
|
|
typedef struct NICConf {
|
|
|
|
MACAddr macaddr;
|
2013-01-30 15:12:28 +04:00
|
|
|
NICPeers peers;
|
2010-12-08 14:35:05 +03:00
|
|
|
int32_t bootindex;
|
2009-10-21 17:25:26 +04:00
|
|
|
} NICConf;
|
|
|
|
|
|
|
|
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
|
2014-10-07 12:00:21 +04:00
|
|
|
DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
|
2009-10-21 17:25:26 +04:00
|
|
|
|
2013-01-30 15:12:28 +04:00
|
|
|
|
2012-07-24 19:35:13 +04:00
|
|
|
/* Net clients */
|
2007-11-17 20:14:51 +03:00
|
|
|
|
2012-07-24 19:35:13 +04:00
|
|
|
typedef void (NetPoll)(NetClientState *, bool enable);
|
2020-03-05 20:56:49 +03:00
|
|
|
typedef bool (NetCanReceive)(NetClientState *);
|
2012-07-24 19:35:13 +04: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 15:12:27 +04: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 11:45:52 +04:00
|
|
|
typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
|
2014-02-06 20:02:16 +04: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 16:23:44 +03:00
|
|
|
typedef int (SetVnetLE)(NetClientState *, bool);
|
|
|
|
typedef int (SetVnetBE)(NetClientState *, bool);
|
2016-05-13 10:35:19 +03:00
|
|
|
typedef struct SocketReadState SocketReadState;
|
|
|
|
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
|
2019-02-27 16:24:09 +03:00
|
|
|
typedef void (NetAnnounce)(NetClientState *);
|
2009-01-08 22:45:03 +03:00
|
|
|
|
2009-11-25 21:49:01 +03: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 06:50:23 +03:00
|
|
|
NetClientDriver type;
|
2009-11-25 21:49:01 +03: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 11:45:52 +04:00
|
|
|
QueryRxFilter *query_rx_filter;
|
2009-12-24 15:46:29 +03:00
|
|
|
NetPoll *poll;
|
2014-02-06 20:02:16 +04: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 16:23:44 +03:00
|
|
|
SetVnetLE *set_vnet_le;
|
|
|
|
SetVnetBE *set_vnet_be;
|
2019-02-27 16:24:09 +03:00
|
|
|
NetAnnounce *announce;
|
2009-11-25 21:49:01 +03:00
|
|
|
} NetClientInfo;
|
|
|
|
|
2012-07-24 19:35:13 +04:00
|
|
|
struct NetClientState {
|
2009-11-25 21:49:30 +03:00
|
|
|
NetClientInfo *info;
|
2009-01-08 22:44:06 +03:00
|
|
|
int link_down;
|
2012-07-24 19:35:13 +04:00
|
|
|
QTAILQ_ENTRY(NetClientState) next;
|
|
|
|
NetClientState *peer;
|
2013-08-02 23:47:08 +04:00
|
|
|
NetQueue *incoming_queue;
|
2009-01-07 20:42:25 +03:00
|
|
|
char *model;
|
2009-01-07 20:43:44 +03:00
|
|
|
char *name;
|
2007-11-17 20:14:51 +03:00
|
|
|
char info_str[256];
|
2009-10-27 21:16:36 +03:00
|
|
|
unsigned receive_disabled : 1;
|
2013-01-30 15:12:27 +04:00
|
|
|
NetClientDestructor *destructor;
|
2013-01-30 15:12:28 +04: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 11:45:52 +04:00
|
|
|
unsigned rxfilter_notify_enabled:1;
|
2016-06-06 19:45:06 +03:00
|
|
|
int vring_enable;
|
2017-07-04 09:53:45 +03:00
|
|
|
int vnet_hdr_len;
|
2020-03-17 23:17:11 +03:00
|
|
|
bool is_netdev;
|
2018-12-06 15:10:34 +03:00
|
|
|
QTAILQ_HEAD(, NetFilterState) filters;
|
2007-11-17 20:14:51 +03:00
|
|
|
};
|
|
|
|
|
2009-11-25 21:49:10 +03:00
|
|
|
typedef struct NICState {
|
2013-02-22 19:15:06 +04:00
|
|
|
NetClientState *ncs;
|
2009-11-25 21:49:10 +03:00
|
|
|
NICConf *conf;
|
|
|
|
void *opaque;
|
2010-09-20 20:08:41 +04:00
|
|
|
bool peer_deleted;
|
2009-11-25 21:49:10 +03:00
|
|
|
} NICState;
|
|
|
|
|
2016-05-13 10:35:19 +03:00
|
|
|
struct SocketReadState {
|
2017-07-04 09:53:46 +03: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 10:35:19 +03:00
|
|
|
uint32_t index;
|
|
|
|
uint32_t packet_len;
|
2017-07-04 09:53:46 +03:00
|
|
|
uint32_t vnet_hdr_len;
|
2016-05-13 10:35:19 +03:00
|
|
|
uint8_t buf[NET_BUFSIZE];
|
|
|
|
SocketReadStateFinalize *finalize;
|
|
|
|
};
|
|
|
|
|
|
|
|
int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size);
|
2015-03-14 07:09:25 +03:00
|
|
|
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
2012-07-24 19:35:13 +04:00
|
|
|
NetClientState *qemu_find_netdev(const char *id);
|
2013-01-30 15:12:25 +04: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 06:50:23 +03:00
|
|
|
NetClientDriver type, int max);
|
2012-07-24 19:35:13 +04:00
|
|
|
NetClientState *qemu_new_net_client(NetClientInfo *info,
|
|
|
|
NetClientState *peer,
|
|
|
|
const char *model,
|
|
|
|
const char *name);
|
2009-11-25 21:49:10 +03:00
|
|
|
NICState *qemu_new_nic(NetClientInfo *info,
|
|
|
|
NICConf *conf,
|
|
|
|
const char *model,
|
|
|
|
const char *name,
|
|
|
|
void *opaque);
|
2013-01-30 15:12:24 +04:00
|
|
|
void qemu_del_nic(NICState *nic);
|
2013-01-30 15:12:28 +04:00
|
|
|
NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
|
2013-01-30 15:12:22 +04:00
|
|
|
NetClientState *qemu_get_queue(NICState *nic);
|
2013-01-30 15:12:23 +04:00
|
|
|
NICState *qemu_get_nic(NetClientState *nc);
|
|
|
|
void *qemu_get_nic_opaque(NetClientState *nc);
|
2012-07-24 19:35:15 +04:00
|
|
|
void qemu_del_net_client(NetClientState *nc);
|
2009-11-25 21:49:31 +03:00
|
|
|
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
|
|
|
|
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
|
2012-07-24 19:35:14 +04:00
|
|
|
int qemu_can_send_packet(NetClientState *nc);
|
|
|
|
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
|
2008-12-17 22:13:11 +03:00
|
|
|
int iovcnt);
|
2012-07-24 19:35:14 +04:00
|
|
|
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
|
2009-04-29 15:15:26 +04:00
|
|
|
int iovcnt, NetPacketSent *sent_cb);
|
2019-01-17 14:43:54 +03:00
|
|
|
ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
|
2012-07-24 19:35:14 +04: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 15:15:26 +04:00
|
|
|
int size, NetPacketSent *sent_cb);
|
2012-07-24 19:35:14 +04: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 13:44:56 +03:00
|
|
|
void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge);
|
2012-07-24 19:35:14 +04:00
|
|
|
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
|
2014-02-20 15:14:07 +04: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 16:23:44 +03:00
|
|
|
int qemu_set_vnet_le(NetClientState *nc, bool is_le);
|
|
|
|
int qemu_set_vnet_be(NetClientState *nc, bool is_be);
|
2009-10-21 17:25:22 +04:00
|
|
|
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
|
2009-09-25 05:53:51 +04:00
|
|
|
int qemu_show_nic_models(const char *arg, const char *const *models);
|
2009-01-13 22:03:57 +03:00
|
|
|
void qemu_check_nic_model(NICInfo *nd, const char *model);
|
2009-09-25 05:53:51 +04:00
|
|
|
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
|
|
|
|
const char *default_model);
|
2007-11-17 20:14:51 +03:00
|
|
|
|
2012-07-24 19:35:16 +04:00
|
|
|
void print_net_client(Monitor *mon, NetClientState *nc);
|
2015-02-06 16:18:24 +03:00
|
|
|
void hmp_info_network(Monitor *mon, const QDict *qdict);
|
2016-05-13 10:35:19 +03:00
|
|
|
void net_socket_rs_init(SocketReadState *rs,
|
2017-07-04 09:53:46 +03:00
|
|
|
SocketReadStateFinalize *finalize,
|
|
|
|
bool vnet_hdr);
|
2020-07-01 17:55:25 +03:00
|
|
|
NetClientState *qemu_get_peer(NetClientState *nc, int queue_index);
|
2007-11-17 20:14:51 +03:00
|
|
|
|
|
|
|
/* NIC info */
|
|
|
|
|
|
|
|
#define MAX_NICS 8
|
|
|
|
|
|
|
|
struct NICInfo {
|
2011-07-20 14:20:22 +04:00
|
|
|
MACAddr macaddr;
|
2009-10-06 15:16:53 +04:00
|
|
|
char *model;
|
|
|
|
char *name;
|
|
|
|
char *devaddr;
|
2012-07-24 19:35:13 +04:00
|
|
|
NetClientState *netdev;
|
2011-05-20 19:50:01 +04:00
|
|
|
int used; /* is this slot in nd_table[] being used? */
|
|
|
|
int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
|
2009-06-21 20:51:18 +04:00
|
|
|
int nvectors;
|
2007-11-17 20:14:51 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int nb_nics;
|
|
|
|
extern NICInfo nd_table[MAX_NICS];
|
2014-05-28 02:39:33 +04:00
|
|
|
extern const char *host_net_devices[];
|
2007-11-17 20:14:51 +03:00
|
|
|
|
2008-10-31 22:10:00 +03:00
|
|
|
/* from net.c */
|
2009-10-08 22:58:25 +04:00
|
|
|
int net_client_parse(QemuOptsList *opts_list, const char *str);
|
2020-11-11 13:52:22 +03:00
|
|
|
void show_netdevs(void);
|
2018-02-21 13:18:30 +03:00
|
|
|
int net_init_clients(Error **errp);
|
2010-02-11 16:44:58 +03:00
|
|
|
void net_check_clients(void);
|
2008-10-31 22:10:00 +03: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 15:55:43 +03:00
|
|
|
void hmp_host_net_add(Monitor *mon, const QDict *qdict);
|
|
|
|
void hmp_host_net_remove(Monitor *mon, const QDict *qdict);
|
2012-04-19 00:34:15 +04:00
|
|
|
void netdev_add(QemuOpts *opts, Error **errp);
|
2008-10-31 22:10:00 +03:00
|
|
|
|
2012-10-24 10:43:34 +04:00
|
|
|
int net_hub_id_for_client(NetClientState *nc, int *id);
|
|
|
|
NetClientState *net_hub_port_find(int hub_id);
|
|
|
|
|
2020-08-18 12:56:16 +03:00
|
|
|
#define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup"
|
|
|
|
#define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/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 18:42:27 +04:00
|
|
|
#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
|
|
|
|
#define DEFAULT_BRIDGE_INTERFACE "br0"
|
2008-12-19 01:43:48 +03:00
|
|
|
|
2009-10-21 17:25:26 +04:00
|
|
|
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
|
2009-05-15 01:35:07 +04:00
|
|
|
|
2017-12-15 21:41:43 +03:00
|
|
|
#define POLYNOMIAL_BE 0x04c11db6
|
2017-12-15 21:41:44 +03:00
|
|
|
#define POLYNOMIAL_LE 0xedb88320
|
2017-12-15 21:41:43 +03:00
|
|
|
uint32_t net_crc32(const uint8_t *p, int len);
|
2017-12-15 21:41:44 +03:00
|
|
|
uint32_t net_crc32_le(const uint8_t *p, int len);
|
2012-03-05 07:08:50 +04:00
|
|
|
|
2012-01-13 20:07:20 +04: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-17 20:14:51 +03:00
|
|
|
#endif
|