2007-11-17 18:14:51 +01:00
|
|
|
#ifndef QEMU_NET_H
|
|
|
|
#define QEMU_NET_H
|
|
|
|
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/queue.h"
|
2008-12-17 20:13:11 +01:00
|
|
|
#include "qemu-common.h"
|
2012-12-17 18:19:43 +01:00
|
|
|
#include "qapi/qmp/qdict.h"
|
2012-12-17 18:20:00 +01:00
|
|
|
#include "qemu/option.h"
|
2009-10-23 18:52:16 +02:00
|
|
|
#include "net/queue.h"
|
2012-12-17 18:19:50 +01:00
|
|
|
#include "migration/vmstate.h"
|
2012-07-17 16:17:12 +02:00
|
|
|
#include "qapi-types.h"
|
2008-12-17 20:13:11 +01:00
|
|
|
|
2016-06-01 10:23:37 +02: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 12:12:28 +01:00
|
|
|
#define MAX_QUEUE_NUM 1024
|
|
|
|
|
2013-03-18 19:43:44 +01: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 15:25:22 +02:00
|
|
|
struct MACAddr {
|
|
|
|
uint8_t a[6];
|
|
|
|
};
|
|
|
|
|
2009-10-21 15:25:26 +02:00
|
|
|
/* qdev nic properties */
|
|
|
|
|
2013-01-30 12:12:28 +01:00
|
|
|
typedef struct NICPeers {
|
|
|
|
NetClientState *ncs[MAX_QUEUE_NUM];
|
2014-05-26 12:04:08 +02:00
|
|
|
int32_t queues;
|
2013-01-30 12:12:28 +01:00
|
|
|
} NICPeers;
|
|
|
|
|
2009-10-21 15:25:26 +02:00
|
|
|
typedef struct NICConf {
|
|
|
|
MACAddr macaddr;
|
2013-01-30 12:12:28 +01:00
|
|
|
NICPeers peers;
|
2010-12-08 12:35:05 +01:00
|
|
|
int32_t bootindex;
|
2009-10-21 15:25:26 +02:00
|
|
|
} NICConf;
|
|
|
|
|
|
|
|
#define DEFINE_NIC_PROPERTIES(_state, _conf) \
|
|
|
|
DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
|
2013-01-30 12:12:28 +01:00
|
|
|
DEFINE_PROP_VLAN("vlan", _state, _conf.peers), \
|
2014-10-07 10:00:21 +02:00
|
|
|
DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
|
2009-10-21 15:25:26 +02:00
|
|
|
|
2013-01-30 12:12:28 +01:00
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
/* Net clients */
|
2007-11-17 18:14:51 +01:00
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
typedef void (NetPoll)(NetClientState *, bool enable);
|
|
|
|
typedef int (NetCanReceive)(NetClientState *);
|
|
|
|
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 12:12:27 +01: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 09:45:52 +02:00
|
|
|
typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
|
2014-02-06 17:02:16 +01: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 15:23:44 +02:00
|
|
|
typedef int (SetVnetLE)(NetClientState *, bool);
|
|
|
|
typedef int (SetVnetBE)(NetClientState *, bool);
|
2016-05-13 09:35:19 +02:00
|
|
|
typedef struct SocketReadState SocketReadState;
|
|
|
|
typedef void (SocketReadStateFinalize)(SocketReadState *rs);
|
2009-01-08 20:45:03 +01:00
|
|
|
|
2009-11-25 19:49:01 +01: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 05:50:23 +02:00
|
|
|
NetClientDriver type;
|
2009-11-25 19:49:01 +01: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 09:45:52 +02:00
|
|
|
QueryRxFilter *query_rx_filter;
|
2009-12-24 13:46:29 +01:00
|
|
|
NetPoll *poll;
|
2014-02-06 17:02:16 +01: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 15:23:44 +02:00
|
|
|
SetVnetLE *set_vnet_le;
|
|
|
|
SetVnetBE *set_vnet_be;
|
2009-11-25 19:49:01 +01:00
|
|
|
} NetClientInfo;
|
|
|
|
|
2012-07-24 17:35:13 +02:00
|
|
|
struct NetClientState {
|
2009-11-25 19:49:30 +01:00
|
|
|
NetClientInfo *info;
|
2009-01-08 20:44:06 +01:00
|
|
|
int link_down;
|
2012-07-24 17:35:13 +02:00
|
|
|
QTAILQ_ENTRY(NetClientState) next;
|
|
|
|
NetClientState *peer;
|
2013-08-02 21:47:08 +02:00
|
|
|
NetQueue *incoming_queue;
|
2009-01-07 18:42:25 +01:00
|
|
|
char *model;
|
2009-01-07 18:43:44 +01:00
|
|
|
char *name;
|
2007-11-17 18:14:51 +01:00
|
|
|
char info_str[256];
|
2009-10-27 19:16:36 +01:00
|
|
|
unsigned receive_disabled : 1;
|
2013-01-30 12:12:27 +01:00
|
|
|
NetClientDestructor *destructor;
|
2013-01-30 12:12:28 +01: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 09:45:52 +02:00
|
|
|
unsigned rxfilter_notify_enabled:1;
|
2016-06-06 18:45:06 +02:00
|
|
|
int vring_enable;
|
2016-01-26 06:00:22 +01:00
|
|
|
QTAILQ_HEAD(NetFilterHead, NetFilterState) filters;
|
2007-11-17 18:14:51 +01:00
|
|
|
};
|
|
|
|
|
2009-11-25 19:49:10 +01:00
|
|
|
typedef struct NICState {
|
2013-02-22 16:15:06 +01:00
|
|
|
NetClientState *ncs;
|
2009-11-25 19:49:10 +01:00
|
|
|
NICConf *conf;
|
|
|
|
void *opaque;
|
2010-09-20 18:08:41 +02:00
|
|
|
bool peer_deleted;
|
2009-11-25 19:49:10 +01:00
|
|
|
} NICState;
|
|
|
|
|
2016-05-13 09:35:19 +02:00
|
|
|
struct SocketReadState {
|
|
|
|
int state; /* 0 = getting length, 1 = getting data */
|
|
|
|
uint32_t index;
|
|
|
|
uint32_t packet_len;
|
|
|
|
uint8_t buf[NET_BUFSIZE];
|
|
|
|
SocketReadStateFinalize *finalize;
|
|
|
|
};
|
|
|
|
|
|
|
|
int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size);
|
2015-03-14 05:09:25 +01:00
|
|
|
char *qemu_mac_strdup_printf(const uint8_t *macaddr);
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState *qemu_find_netdev(const char *id);
|
2013-01-30 12:12:25 +01: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 05:50:23 +02:00
|
|
|
NetClientDriver type, int max);
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState *qemu_new_net_client(NetClientInfo *info,
|
|
|
|
NetClientState *peer,
|
|
|
|
const char *model,
|
|
|
|
const char *name);
|
2009-11-25 19:49:10 +01:00
|
|
|
NICState *qemu_new_nic(NetClientInfo *info,
|
|
|
|
NICConf *conf,
|
|
|
|
const char *model,
|
|
|
|
const char *name,
|
|
|
|
void *opaque);
|
2013-01-30 12:12:24 +01:00
|
|
|
void qemu_del_nic(NICState *nic);
|
2013-01-30 12:12:28 +01:00
|
|
|
NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
|
2013-01-30 12:12:22 +01:00
|
|
|
NetClientState *qemu_get_queue(NICState *nic);
|
2013-01-30 12:12:23 +01:00
|
|
|
NICState *qemu_get_nic(NetClientState *nc);
|
|
|
|
void *qemu_get_nic_opaque(NetClientState *nc);
|
2012-07-24 17:35:15 +02:00
|
|
|
void qemu_del_net_client(NetClientState *nc);
|
2009-11-25 19:49:31 +01:00
|
|
|
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
|
|
|
|
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
|
2012-07-24 17:35:14 +02:00
|
|
|
int qemu_can_send_packet(NetClientState *nc);
|
|
|
|
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
|
2008-12-17 20:13:11 +01:00
|
|
|
int iovcnt);
|
2012-07-24 17:35:14 +02:00
|
|
|
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
|
2009-04-29 13:15:26 +02:00
|
|
|
int iovcnt, NetPacketSent *sent_cb);
|
2012-07-24 17:35:14 +02:00
|
|
|
void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
|
|
|
|
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 13:15:26 +02:00
|
|
|
int size, NetPacketSent *sent_cb);
|
2012-07-24 17:35:14 +02:00
|
|
|
void qemu_purge_queued_packets(NetClientState *nc);
|
|
|
|
void qemu_flush_queued_packets(NetClientState *nc);
|
|
|
|
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
|
2014-02-20 12:14:07 +01: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 15:23:44 +02:00
|
|
|
int qemu_set_vnet_le(NetClientState *nc, bool is_le);
|
|
|
|
int qemu_set_vnet_be(NetClientState *nc, bool is_be);
|
2009-10-21 15:25:22 +02:00
|
|
|
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
|
2009-09-25 03:53:51 +02:00
|
|
|
int qemu_show_nic_models(const char *arg, const char *const *models);
|
2009-01-13 20:03:57 +01:00
|
|
|
void qemu_check_nic_model(NICInfo *nd, const char *model);
|
2009-09-25 03:53:51 +02:00
|
|
|
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
|
|
|
|
const char *default_model);
|
2007-11-17 18:14:51 +01:00
|
|
|
|
2012-07-24 17:35:17 +02:00
|
|
|
ssize_t qemu_deliver_packet_iov(NetClientState *sender,
|
|
|
|
unsigned flags,
|
|
|
|
const struct iovec *iov,
|
|
|
|
int iovcnt,
|
|
|
|
void *opaque);
|
|
|
|
|
2012-07-24 17:35:16 +02:00
|
|
|
void print_net_client(Monitor *mon, NetClientState *nc);
|
2015-02-06 14:18:24 +01:00
|
|
|
void hmp_info_network(Monitor *mon, const QDict *qdict);
|
2016-05-13 09:35:19 +02:00
|
|
|
void net_socket_rs_init(SocketReadState *rs,
|
|
|
|
SocketReadStateFinalize *finalize);
|
2007-11-17 18:14:51 +01:00
|
|
|
|
|
|
|
/* NIC info */
|
|
|
|
|
|
|
|
#define MAX_NICS 8
|
|
|
|
|
|
|
|
struct NICInfo {
|
2011-07-20 12:20:22 +02:00
|
|
|
MACAddr macaddr;
|
2009-10-06 13:16:53 +02:00
|
|
|
char *model;
|
|
|
|
char *name;
|
|
|
|
char *devaddr;
|
2012-07-24 17:35:13 +02:00
|
|
|
NetClientState *netdev;
|
2011-05-20 17:50:01 +02:00
|
|
|
int used; /* is this slot in nd_table[] being used? */
|
|
|
|
int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
|
2009-06-21 18:51:18 +02:00
|
|
|
int nvectors;
|
2007-11-17 18:14:51 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
extern int nb_nics;
|
|
|
|
extern NICInfo nd_table[MAX_NICS];
|
2014-05-28 00:39:33 +02:00
|
|
|
extern const char *host_net_devices[];
|
2007-11-17 18:14:51 +01:00
|
|
|
|
2008-10-31 20:10:00 +01:00
|
|
|
/* from net.c */
|
2009-06-24 14:42:28 +02:00
|
|
|
extern const char *legacy_tftp_prefix;
|
|
|
|
extern const char *legacy_bootp_filename;
|
|
|
|
|
2016-07-14 05:50:24 +02:00
|
|
|
int net_client_init(QemuOpts *opts, bool is_netdev, Error **errp);
|
2009-10-08 20:58:25 +02:00
|
|
|
int net_client_parse(QemuOptsList *opts_list, const char *str);
|
2009-10-06 13:17:16 +02:00
|
|
|
int net_init_clients(void);
|
2010-02-11 14:44:58 +01:00
|
|
|
void net_check_clients(void);
|
2008-10-31 20:10:00 +01: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 13:55:43 +01:00
|
|
|
void hmp_host_net_add(Monitor *mon, const QDict *qdict);
|
|
|
|
void hmp_host_net_remove(Monitor *mon, const QDict *qdict);
|
2012-04-18 22:34:15 +02:00
|
|
|
void netdev_add(QemuOpts *opts, Error **errp);
|
qmp: Wean off qerror_report()
The traditional QMP command handler interface
int qmp_FOO(Monitor *mon, const QDict *params, QObject **ret_data);
doesn't provide for returning an Error object. Instead, the handler
is expected to stash it in the monitor with qerror_report().
When we rebased QMP on top of QAPI, we didn't change this interface.
Instead, commit 776574d introduced "middle mode" as a temporary aid
for converting existing QMP commands to QAPI one by one. More than
three years later, we're still using it.
Middle mode has two effects:
* Instead of the native input marshallers
static void qmp_marshal_input_FOO(QDict *, QObject **, Error **)
it generates input marshallers conforming to the traditional QMP
command handler interface.
* It suppresses generation of code to register them with
qmp_register_command()
This permits giving them internal linkage.
As long as we need qmp-commands.hx, we can't use the registry behind
qmp_register_command(), so the latter has to stay for now.
The former has to go to get rid of qerror_report(). Changing all QMP
commands to fit the QAPI mold in one go was impractical back when we
started, but by now there are just a few stragglers left:
do_qmp_capabilities(), qmp_qom_set(), qmp_qom_get(), qmp_object_add(),
qmp_netdev_add(), do_device_add().
Switch middle mode to generate native input marshallers, and adapt the
stragglers. Simplifies both the monitor code and the stragglers.
Rename do_qmp_capabilities() to qmp_capabilities(), and
do_device_add() to qmp_device_add, because that's how QMP command
handlers are named today.
Signed-off-by: Markus Armbruster <armbru@redhat.com>
Reviewed-by: Stefan Hajnoczi <stefanha@redhat.com>
Reviewed-by: Eric Blake <eblake@redhat.com>
Reviewed-by: Luiz Capitulino <lcapitulino@redhat.com>
2015-03-13 17:25:50 +01:00
|
|
|
void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp);
|
2008-10-31 20:10:00 +01:00
|
|
|
|
2012-10-24 08:43:34 +02:00
|
|
|
int net_hub_id_for_client(NetClientState *nc, int *id);
|
|
|
|
NetClientState *net_hub_port_find(int hub_id);
|
|
|
|
|
2008-12-18 23:43:48 +01: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 15:42:27 +01:00
|
|
|
#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
|
|
|
|
#define DEFAULT_BRIDGE_INTERFACE "br0"
|
2008-12-18 23:43:48 +01:00
|
|
|
|
2009-10-21 15:25:26 +02:00
|
|
|
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
|
2009-05-14 23:35:07 +02:00
|
|
|
|
2012-03-05 04:08:50 +01:00
|
|
|
#define POLYNOMIAL 0x04c11db6
|
|
|
|
unsigned compute_mcast_idx(const uint8_t *ep);
|
|
|
|
|
2012-01-13 17:07:20 +01: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 18:14:51 +01:00
|
|
|
#endif
|