blob: 71a9a443e00fa5240cbd5b1c6d760483a2739fca [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_NET_H
2#define QEMU_NET_H
3
Blue Swirl72cf2d42009-09-12 07:36:22 +00004#include "qemu-queue.h"
aliguorifbe78f42008-12-17 19:13:11 +00005#include "qemu-common.h"
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03006#include "qdict.h"
Mark McLoughlin13cf8f22009-10-06 12:17:14 +01007#include "qemu-option.h"
Mark McLoughline1144d02009-10-23 17:52:16 +01008#include "net/queue.h"
aliguorifbe78f42008-12-17 19:13:11 +00009
Gerd Hoffmann76d32cb2009-10-21 15:25:22 +020010struct MACAddr {
11 uint8_t a[6];
12};
13
Gerd Hoffmanned16ab52009-10-21 15:25:26 +020014/* qdev nic properties */
15
16typedef struct NICConf {
17 MACAddr macaddr;
18 VLANState *vlan;
19 VLANClientState *peer;
20} NICConf;
21
22#define DEFINE_NIC_PROPERTIES(_state, _conf) \
23 DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
24 DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \
25 DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
26
pbrook87ecb682007-11-17 17:14:51 +000027/* VLANs support */
28
Mark McLoughlinbb6e6362009-10-22 17:43:38 +010029typedef enum {
30 NET_CLIENT_TYPE_NONE,
31 NET_CLIENT_TYPE_NIC,
32 NET_CLIENT_TYPE_SLIRP,
33 NET_CLIENT_TYPE_TAP,
34 NET_CLIENT_TYPE_SOCKET,
35 NET_CLIENT_TYPE_VDE,
36 NET_CLIENT_TYPE_DUMP
37} net_client_type;
38
Mark McLoughline3f5ec22009-05-18 13:33:03 +010039typedef int (NetCanReceive)(VLANClientState *);
Mark McLoughlin4f1c9422009-05-18 13:40:55 +010040typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
Mark McLoughline3f5ec22009-05-18 13:33:03 +010041typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
aliguorib946a152009-04-17 17:11:08 +000042typedef void (NetCleanup) (VLANClientState *);
aliguori34b25ca2009-01-08 19:45:03 +000043typedef void (LinkStatusChanged)(VLANClientState *);
44
Mark McLoughlin3ed79cc2009-11-25 18:49:01 +000045typedef struct NetClientInfo {
46 net_client_type type;
47 size_t size;
48 NetReceive *receive;
49 NetReceive *receive_raw;
50 NetReceiveIOV *receive_iov;
51 NetCanReceive *can_receive;
52 NetCleanup *cleanup;
53 LinkStatusChanged *link_status_changed;
54} NetClientInfo;
55
pbrook87ecb682007-11-17 17:14:51 +000056struct VLANClientState {
Mark McLoughlinbb6e6362009-10-22 17:43:38 +010057 net_client_type type;
Mark McLoughlincda90462009-05-18 13:13:16 +010058 NetReceive *receive;
Mark McLoughlinca77d172009-10-22 17:43:41 +010059 NetReceive *receive_raw;
Mark McLoughlincda90462009-05-18 13:13:16 +010060 NetReceiveIOV *receive_iov;
pbrook87ecb682007-11-17 17:14:51 +000061 /* Packets may still be sent if this returns zero. It's used to
62 rate-limit the slirp code. */
Mark McLoughlincda90462009-05-18 13:13:16 +010063 NetCanReceive *can_receive;
aliguorib946a152009-04-17 17:11:08 +000064 NetCleanup *cleanup;
aliguori34b25ca2009-01-08 19:45:03 +000065 LinkStatusChanged *link_status_changed;
aliguori436e5e52009-01-08 19:44:06 +000066 int link_down;
pbrook87ecb682007-11-17 17:14:51 +000067 void *opaque;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +010068 QTAILQ_ENTRY(VLANClientState) next;
pbrook87ecb682007-11-17 17:14:51 +000069 struct VLANState *vlan;
Mark McLoughlin283c7c62009-10-08 19:58:30 +010070 VLANClientState *peer;
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +010071 NetQueue *send_queue;
aliguoribf38c1a2009-01-07 17:42:25 +000072 char *model;
aliguori676cff22009-01-07 17:43:44 +000073 char *name;
pbrook87ecb682007-11-17 17:14:51 +000074 char info_str[256];
Mark McLoughlin893379e2009-10-27 18:16:36 +000075 unsigned receive_disabled : 1;
pbrook87ecb682007-11-17 17:14:51 +000076};
77
78struct VLANState {
79 int id;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +010080 QTAILQ_HEAD(, VLANClientState) clients;
81 QTAILQ_ENTRY(VLANState) next;
pbrook87ecb682007-11-17 17:14:51 +000082 unsigned int nb_guest_devs, nb_host_devs;
Mark McLoughlinf7105842009-10-08 19:58:31 +010083 NetQueue *send_queue;
pbrook87ecb682007-11-17 17:14:51 +000084};
85
Jan Kiszka1a609522009-06-24 14:42:31 +020086VLANState *qemu_find_vlan(int id, int allocate);
Gerd Hoffmann2ef924b2009-10-21 15:25:24 +020087VLANClientState *qemu_find_netdev(const char *id);
Mark McLoughlin45460d12009-11-25 18:49:02 +000088VLANClientState *qemu_new_net_client(NetClientInfo *info,
89 VLANState *vlan,
90 VLANClientState *peer,
91 const char *model,
92 const char *name);
Anthony Liguori9f092042009-10-22 15:29:03 -050093VLANClientState *qemu_new_vlan_client(net_client_type type,
Anthony Liguoria7f085c2009-10-22 15:27:24 -050094 VLANState *vlan,
Mark McLoughlin283c7c62009-10-08 19:58:30 +010095 VLANClientState *peer,
aliguoribf38c1a2009-01-07 17:42:25 +000096 const char *model,
aliguori7a9f6e42009-01-07 17:48:51 +000097 const char *name,
Mark McLoughlincda90462009-05-18 13:13:16 +010098 NetCanReceive *can_receive,
99 NetReceive *receive,
Mark McLoughlin70783b92009-10-22 17:43:42 +0100100 NetReceive *receive_raw,
Mark McLoughlincda90462009-05-18 13:13:16 +0100101 NetReceiveIOV *receive_iov,
aliguorib946a152009-04-17 17:11:08 +0000102 NetCleanup *cleanup,
pbrook87ecb682007-11-17 17:14:51 +0000103 void *opaque);
balrogdcf414d2008-07-17 21:00:05 +0000104void qemu_del_vlan_client(VLANClientState *vc);
aliguori8b13c4a2009-02-11 15:20:51 +0000105VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
Mark McLoughlin68ac40d2009-11-25 18:48:54 +0000106VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
107 const char *client_str);
pbrook87ecb682007-11-17 17:14:51 +0000108int qemu_can_send_packet(VLANClientState *vc);
aliguorifbe78f42008-12-17 19:13:11 +0000109ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
110 int iovcnt);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100111ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
112 int iovcnt, NetPacketSent *sent_cb);
pbrook87ecb682007-11-17 17:14:51 +0000113void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
Mark McLoughlinca77d172009-10-22 17:43:41 +0100114ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100115ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
116 int size, NetPacketSent *sent_cb);
Mark McLoughlin8cad5512009-06-18 18:21:29 +0100117void qemu_purge_queued_packets(VLANClientState *vc);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +0100118void qemu_flush_queued_packets(VLANClientState *vc);
aliguori7cb7434b2009-01-07 17:46:21 +0000119void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
Gerd Hoffmann76d32cb2009-10-21 15:25:22 +0200120void qemu_macaddr_default_if_unset(MACAddr *macaddr);
Markus Armbruster07caea32009-09-25 03:53:51 +0200121int qemu_show_nic_models(const char *arg, const char *const *models);
aliguorid07f22c2009-01-13 19:03:57 +0000122void qemu_check_nic_model(NICInfo *nd, const char *model);
Markus Armbruster07caea32009-09-25 03:53:51 +0200123int qemu_find_nic_model(NICInfo *nd, const char * const *models,
124 const char *default_model);
pbrook87ecb682007-11-17 17:14:51 +0000125
aliguori376253e2009-03-05 23:01:23 +0000126void do_info_network(Monitor *mon);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300127void do_set_link(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +0000128
129/* NIC info */
130
131#define MAX_NICS 8
Michael S. Tsirkinffe63702009-06-21 19:51:18 +0300132enum {
133 NIC_NVECTORS_UNSPECIFIED = -1
134};
pbrook87ecb682007-11-17 17:14:51 +0000135
136struct NICInfo {
137 uint8_t macaddr[6];
Mark McLoughlin9203f522009-10-06 12:16:53 +0100138 char *model;
139 char *name;
140 char *devaddr;
pbrook87ecb682007-11-17 17:14:51 +0000141 VLANState *vlan;
Mark McLoughlin5869c4d2009-10-08 19:58:29 +0100142 VLANClientState *netdev;
aliguori76970792009-02-11 15:20:03 +0000143 int used;
Glauber Costa406c8df2009-06-17 09:05:30 -0400144 int bootable;
Michael S. Tsirkinffe63702009-06-21 19:51:18 +0300145 int nvectors;
pbrook87ecb682007-11-17 17:14:51 +0000146};
147
148extern int nb_nics;
149extern NICInfo nd_table[MAX_NICS];
150
balrog1ae26a12008-09-28 23:19:47 +0000151/* BT HCI info */
152
153struct HCIInfo {
154 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
155 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
156 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
157 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
158 void *opaque;
159 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
160 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
161};
162
163struct HCIInfo *qemu_next_hci(void);
164
aliguori63a01ef2008-10-31 19:10:00 +0000165/* from net.c */
Jan Kiszkaad196a92009-06-24 14:42:28 +0200166extern const char *legacy_tftp_prefix;
167extern const char *legacy_bootp_filename;
168
Mark McLoughlinf6b134a2009-10-08 19:58:27 +0100169int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
aliguori8b13c4a2009-02-11 15:20:51 +0000170void net_client_uninit(NICInfo *nd);
Mark McLoughlin7f161aa2009-10-08 19:58:25 +0100171int net_client_parse(QemuOptsList *opts_list, const char *str);
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +0100172int net_init_clients(void);
aliguori63a01ef2008-10-31 19:10:00 +0000173void net_cleanup(void);
Glauber Costa406c8df2009-06-17 09:05:30 -0400174void net_set_boot_mask(int boot_mask);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300175void net_host_device_add(Monitor *mon, const QDict *qdict);
176void net_host_device_remove(Monitor *mon, const QDict *qdict);
aliguori63a01ef2008-10-31 19:10:00 +0000177
aurel32f54825c2008-12-18 22:43:48 +0000178#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
179#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
180#ifdef __sun__
181#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
182#else
183#define SMBD_COMMAND "/usr/sbin/smbd"
184#endif
185
Gerd Hoffmanned16ab52009-10-21 15:25:26 +0200186void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
Paul Brook9d07d752009-05-14 22:35:07 +0100187
Mark McLoughlin5281d752009-10-22 17:49:07 +0100188int net_handle_fd_param(Monitor *mon, const char *param);
189
pbrook87ecb682007-11-17 17:14:51 +0000190#endif