blob: 605092a87d67162bf6ddef29245b145d94c91676 [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 McLoughlinf7105842009-10-08 19:58:31 +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
pbrook87ecb682007-11-17 17:14:51 +000014/* VLANs support */
15
Mark McLoughline3f5ec22009-05-18 13:33:03 +010016typedef int (NetCanReceive)(VLANClientState *);
Mark McLoughlin4f1c9422009-05-18 13:40:55 +010017typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
Mark McLoughline3f5ec22009-05-18 13:33:03 +010018typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
aliguorib946a152009-04-17 17:11:08 +000019typedef void (NetCleanup) (VLANClientState *);
aliguori34b25ca2009-01-08 19:45:03 +000020typedef void (LinkStatusChanged)(VLANClientState *);
21
pbrook87ecb682007-11-17 17:14:51 +000022struct VLANClientState {
Mark McLoughlincda90462009-05-18 13:13:16 +010023 NetReceive *receive;
24 NetReceiveIOV *receive_iov;
pbrook87ecb682007-11-17 17:14:51 +000025 /* Packets may still be sent if this returns zero. It's used to
26 rate-limit the slirp code. */
Mark McLoughlincda90462009-05-18 13:13:16 +010027 NetCanReceive *can_receive;
aliguorib946a152009-04-17 17:11:08 +000028 NetCleanup *cleanup;
aliguori34b25ca2009-01-08 19:45:03 +000029 LinkStatusChanged *link_status_changed;
aliguori436e5e52009-01-08 19:44:06 +000030 int link_down;
pbrook87ecb682007-11-17 17:14:51 +000031 void *opaque;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +010032 QTAILQ_ENTRY(VLANClientState) next;
pbrook87ecb682007-11-17 17:14:51 +000033 struct VLANState *vlan;
Mark McLoughlin283c7c62009-10-08 19:58:30 +010034 VLANClientState *peer;
Mark McLoughlin9a6ecb32009-10-08 19:58:32 +010035 NetQueue *send_queue;
aliguoribf38c1a2009-01-07 17:42:25 +000036 char *model;
aliguori676cff22009-01-07 17:43:44 +000037 char *name;
pbrook87ecb682007-11-17 17:14:51 +000038 char info_str[256];
39};
40
41struct VLANState {
42 int id;
Mark McLoughlin5610c3a2009-10-08 19:58:23 +010043 QTAILQ_HEAD(, VLANClientState) clients;
44 QTAILQ_ENTRY(VLANState) next;
pbrook87ecb682007-11-17 17:14:51 +000045 unsigned int nb_guest_devs, nb_host_devs;
Mark McLoughlinf7105842009-10-08 19:58:31 +010046 NetQueue *send_queue;
pbrook87ecb682007-11-17 17:14:51 +000047};
48
Jan Kiszka1a609522009-06-24 14:42:31 +020049VLANState *qemu_find_vlan(int id, int allocate);
pbrook87ecb682007-11-17 17:14:51 +000050VLANClientState *qemu_new_vlan_client(VLANState *vlan,
Mark McLoughlin283c7c62009-10-08 19:58:30 +010051 VLANClientState *peer,
aliguoribf38c1a2009-01-07 17:42:25 +000052 const char *model,
aliguori7a9f6e42009-01-07 17:48:51 +000053 const char *name,
Mark McLoughlincda90462009-05-18 13:13:16 +010054 NetCanReceive *can_receive,
55 NetReceive *receive,
56 NetReceiveIOV *receive_iov,
aliguorib946a152009-04-17 17:11:08 +000057 NetCleanup *cleanup,
pbrook87ecb682007-11-17 17:14:51 +000058 void *opaque);
balrogdcf414d2008-07-17 21:00:05 +000059void qemu_del_vlan_client(VLANClientState *vc);
aliguori8b13c4a2009-02-11 15:20:51 +000060VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
pbrook87ecb682007-11-17 17:14:51 +000061int qemu_can_send_packet(VLANClientState *vc);
aliguorifbe78f42008-12-17 19:13:11 +000062ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
63 int iovcnt);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010064ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
65 int iovcnt, NetPacketSent *sent_cb);
pbrook87ecb682007-11-17 17:14:51 +000066void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010067ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
68 int size, NetPacketSent *sent_cb);
Mark McLoughlin8cad5512009-06-18 18:21:29 +010069void qemu_purge_queued_packets(VLANClientState *vc);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010070void qemu_flush_queued_packets(VLANClientState *vc);
aliguori7cb7434b2009-01-07 17:46:21 +000071void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
Gerd Hoffmann76d32cb2009-10-21 15:25:22 +020072void qemu_macaddr_default_if_unset(MACAddr *macaddr);
Markus Armbruster07caea32009-09-25 03:53:51 +020073int qemu_show_nic_models(const char *arg, const char *const *models);
aliguorid07f22c2009-01-13 19:03:57 +000074void qemu_check_nic_model(NICInfo *nd, const char *model);
Markus Armbruster07caea32009-09-25 03:53:51 +020075int qemu_find_nic_model(NICInfo *nd, const char * const *models,
76 const char *default_model);
pbrook87ecb682007-11-17 17:14:51 +000077
aliguori376253e2009-03-05 23:01:23 +000078void do_info_network(Monitor *mon);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -030079void do_set_link(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +000080
Jan Kiszka6dbe5532009-06-24 14:42:29 +020081void do_info_usernet(Monitor *mon);
82
pbrook87ecb682007-11-17 17:14:51 +000083/* NIC info */
84
85#define MAX_NICS 8
Michael S. Tsirkinffe63702009-06-21 19:51:18 +030086enum {
87 NIC_NVECTORS_UNSPECIFIED = -1
88};
pbrook87ecb682007-11-17 17:14:51 +000089
90struct NICInfo {
91 uint8_t macaddr[6];
Mark McLoughlin9203f522009-10-06 12:16:53 +010092 char *model;
93 char *name;
94 char *devaddr;
pbrook87ecb682007-11-17 17:14:51 +000095 VLANState *vlan;
Mark McLoughlin5869c4d2009-10-08 19:58:29 +010096 VLANClientState *netdev;
Mark McLoughlinae50b272009-07-01 16:46:38 +010097 VLANClientState *vc;
aliguori72da4202009-02-11 15:19:52 +000098 void *private;
aliguori76970792009-02-11 15:20:03 +000099 int used;
Glauber Costa406c8df2009-06-17 09:05:30 -0400100 int bootable;
Michael S. Tsirkinffe63702009-06-21 19:51:18 +0300101 int nvectors;
pbrook87ecb682007-11-17 17:14:51 +0000102};
103
104extern int nb_nics;
105extern NICInfo nd_table[MAX_NICS];
106
balrog1ae26a12008-09-28 23:19:47 +0000107/* BT HCI info */
108
109struct HCIInfo {
110 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
111 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
112 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
113 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
114 void *opaque;
115 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
116 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
117};
118
119struct HCIInfo *qemu_next_hci(void);
120
aliguori48c64362008-07-29 19:40:04 +0000121/* checksumming functions (net-checksum.c) */
122uint32_t net_checksum_add(int len, uint8_t *buf);
123uint16_t net_checksum_finish(uint32_t sum);
124uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
125 uint8_t *addrs, uint8_t *buf);
126void net_checksum_calculate(uint8_t *data, int length);
127
aliguori63a01ef2008-10-31 19:10:00 +0000128/* from net.c */
Jan Kiszkaad196a92009-06-24 14:42:28 +0200129extern const char *legacy_tftp_prefix;
130extern const char *legacy_bootp_filename;
131
Mark McLoughlinf6b134a2009-10-08 19:58:27 +0100132int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
aliguori8b13c4a2009-02-11 15:20:51 +0000133void net_client_uninit(NICInfo *nd);
Mark McLoughlin7f161aa2009-10-08 19:58:25 +0100134int net_client_parse(QemuOptsList *opts_list, const char *str);
Mark McLoughlindc1c9fe2009-10-06 12:17:16 +0100135int net_init_clients(void);
Markus Armbruster07527062009-10-06 12:16:57 +0100136int net_slirp_smb(const char *exported_dir);
Luiz Capitulino1d4daa92009-08-28 15:27:15 -0300137void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
138void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
Markus Armbruster07527062009-10-06 12:16:57 +0100139int net_slirp_redir(const char *redir_str);
aliguori63a01ef2008-10-31 19:10:00 +0000140void net_cleanup(void);
Glauber Costa406c8df2009-06-17 09:05:30 -0400141void net_set_boot_mask(int boot_mask);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300142void net_host_device_add(Monitor *mon, const QDict *qdict);
143void net_host_device_remove(Monitor *mon, const QDict *qdict);
aliguori63a01ef2008-10-31 19:10:00 +0000144
aurel32f54825c2008-12-18 22:43:48 +0000145#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
146#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
147#ifdef __sun__
148#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
149#else
150#define SMBD_COMMAND "/usr/sbin/smbd"
151#endif
152
Paul Brook9d07d752009-05-14 22:35:07 +0100153void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
154VLANClientState *qdev_get_vlan_client(DeviceState *dev,
Mark McLoughlincda90462009-05-18 13:13:16 +0100155 NetCanReceive *can_receive,
156 NetReceive *receive,
157 NetReceiveIOV *receive_iov,
Paul Brook9d07d752009-05-14 22:35:07 +0100158 NetCleanup *cleanup,
159 void *opaque);
160
pbrook87ecb682007-11-17 17:14:51 +0000161#endif