blob: f46e6c67567436260eb8648fb31426068b1b0ba9 [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_NET_H
2#define QEMU_NET_H
3
Jan Kiszka9da43182009-08-26 12:47:04 +02004#include "sys-queue.h"
aliguorifbe78f42008-12-17 19:13:11 +00005#include "qemu-common.h"
Luiz Capitulinof18c16d2009-08-28 15:27:14 -03006#include "qdict.h"
aliguorifbe78f42008-12-17 19:13:11 +00007
pbrook87ecb682007-11-17 17:14:51 +00008/* VLANs support */
9
10typedef struct VLANClientState VLANClientState;
11
Mark McLoughline3f5ec22009-05-18 13:33:03 +010012typedef int (NetCanReceive)(VLANClientState *);
Mark McLoughlin4f1c9422009-05-18 13:40:55 +010013typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
Mark McLoughline3f5ec22009-05-18 13:33:03 +010014typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
aliguorib946a152009-04-17 17:11:08 +000015typedef void (NetCleanup) (VLANClientState *);
aliguori34b25ca2009-01-08 19:45:03 +000016typedef void (LinkStatusChanged)(VLANClientState *);
17
pbrook87ecb682007-11-17 17:14:51 +000018struct VLANClientState {
Mark McLoughlincda90462009-05-18 13:13:16 +010019 NetReceive *receive;
20 NetReceiveIOV *receive_iov;
pbrook87ecb682007-11-17 17:14:51 +000021 /* Packets may still be sent if this returns zero. It's used to
22 rate-limit the slirp code. */
Mark McLoughlincda90462009-05-18 13:13:16 +010023 NetCanReceive *can_receive;
aliguorib946a152009-04-17 17:11:08 +000024 NetCleanup *cleanup;
aliguori34b25ca2009-01-08 19:45:03 +000025 LinkStatusChanged *link_status_changed;
aliguori436e5e52009-01-08 19:44:06 +000026 int link_down;
pbrook87ecb682007-11-17 17:14:51 +000027 void *opaque;
28 struct VLANClientState *next;
29 struct VLANState *vlan;
aliguoribf38c1a2009-01-07 17:42:25 +000030 char *model;
aliguori676cff22009-01-07 17:43:44 +000031 char *name;
pbrook87ecb682007-11-17 17:14:51 +000032 char info_str[256];
33};
34
aliguori764a4d12009-04-21 19:56:41 +000035typedef struct VLANPacket VLANPacket;
36
Mark McLoughlin783527a2009-06-18 18:21:35 +010037typedef void (NetPacketSent) (VLANClientState *, ssize_t);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010038
aliguori764a4d12009-04-21 19:56:41 +000039struct VLANPacket {
Jan Kiszka9da43182009-08-26 12:47:04 +020040 TAILQ_ENTRY(VLANPacket) entry;
aliguori764a4d12009-04-21 19:56:41 +000041 VLANClientState *sender;
42 int size;
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010043 NetPacketSent *sent_cb;
aliguori764a4d12009-04-21 19:56:41 +000044 uint8_t data[0];
45};
46
pbrook87ecb682007-11-17 17:14:51 +000047struct VLANState {
48 int id;
49 VLANClientState *first_client;
50 struct VLANState *next;
51 unsigned int nb_guest_devs, nb_host_devs;
Jan Kiszka9da43182009-08-26 12:47:04 +020052 TAILQ_HEAD(send_queue, VLANPacket) send_queue;
aliguori764a4d12009-04-21 19:56:41 +000053 int delivering;
pbrook87ecb682007-11-17 17:14:51 +000054};
55
Jan Kiszka1a609522009-06-24 14:42:31 +020056VLANState *qemu_find_vlan(int id, int allocate);
pbrook87ecb682007-11-17 17:14:51 +000057VLANClientState *qemu_new_vlan_client(VLANState *vlan,
aliguoribf38c1a2009-01-07 17:42:25 +000058 const char *model,
aliguori7a9f6e42009-01-07 17:48:51 +000059 const char *name,
Mark McLoughlincda90462009-05-18 13:13:16 +010060 NetCanReceive *can_receive,
61 NetReceive *receive,
62 NetReceiveIOV *receive_iov,
aliguorib946a152009-04-17 17:11:08 +000063 NetCleanup *cleanup,
pbrook87ecb682007-11-17 17:14:51 +000064 void *opaque);
balrogdcf414d2008-07-17 21:00:05 +000065void qemu_del_vlan_client(VLANClientState *vc);
aliguori8b13c4a2009-02-11 15:20:51 +000066VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
pbrook87ecb682007-11-17 17:14:51 +000067int qemu_can_send_packet(VLANClientState *vc);
aliguorifbe78f42008-12-17 19:13:11 +000068ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
69 int iovcnt);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010070ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
71 int iovcnt, NetPacketSent *sent_cb);
pbrook87ecb682007-11-17 17:14:51 +000072void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010073ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
74 int size, NetPacketSent *sent_cb);
Mark McLoughlin8cad5512009-06-18 18:21:29 +010075void qemu_purge_queued_packets(VLANClientState *vc);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010076void qemu_flush_queued_packets(VLANClientState *vc);
aliguori7cb7434b2009-01-07 17:46:21 +000077void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
aliguorid07f22c2009-01-13 19:03:57 +000078void qemu_check_nic_model(NICInfo *nd, const char *model);
79void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
80 const char *default_model);
pbrook87ecb682007-11-17 17:14:51 +000081void qemu_handler_true(void *opaque);
82
aliguori376253e2009-03-05 23:01:23 +000083void do_info_network(Monitor *mon);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -030084void do_set_link(Monitor *mon, const QDict *qdict);
pbrook87ecb682007-11-17 17:14:51 +000085
Jan Kiszka6dbe5532009-06-24 14:42:29 +020086void do_info_usernet(Monitor *mon);
87
pbrook87ecb682007-11-17 17:14:51 +000088/* NIC info */
89
90#define MAX_NICS 8
Michael S. Tsirkinffe63702009-06-21 19:51:18 +030091enum {
92 NIC_NVECTORS_UNSPECIFIED = -1
93};
pbrook87ecb682007-11-17 17:14:51 +000094
95struct NICInfo {
96 uint8_t macaddr[6];
97 const char *model;
aliguori7a9f6e42009-01-07 17:48:51 +000098 const char *name;
Markus Armbruster5607c382009-06-18 15:14:08 +020099 const char *devaddr;
Gerd Hoffmanneb54b6d2009-07-15 13:43:35 +0200100 const char *id;
pbrook87ecb682007-11-17 17:14:51 +0000101 VLANState *vlan;
Mark McLoughlinae50b272009-07-01 16:46:38 +0100102 VLANClientState *vc;
aliguori72da4202009-02-11 15:19:52 +0000103 void *private;
aliguori76970792009-02-11 15:20:03 +0000104 int used;
Glauber Costa406c8df2009-06-17 09:05:30 -0400105 int bootable;
Michael S. Tsirkinffe63702009-06-21 19:51:18 +0300106 int nvectors;
pbrook87ecb682007-11-17 17:14:51 +0000107};
108
109extern int nb_nics;
110extern NICInfo nd_table[MAX_NICS];
111
balrog1ae26a12008-09-28 23:19:47 +0000112/* BT HCI info */
113
114struct HCIInfo {
115 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
116 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
117 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
118 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
119 void *opaque;
120 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
121 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
122};
123
124struct HCIInfo *qemu_next_hci(void);
125
aliguori48c64362008-07-29 19:40:04 +0000126/* checksumming functions (net-checksum.c) */
127uint32_t net_checksum_add(int len, uint8_t *buf);
128uint16_t net_checksum_finish(uint32_t sum);
129uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
130 uint8_t *addrs, uint8_t *buf);
131void net_checksum_calculate(uint8_t *data, int length);
132
aliguori63a01ef2008-10-31 19:10:00 +0000133/* from net.c */
Jan Kiszkaad196a92009-06-24 14:42:28 +0200134extern const char *legacy_tftp_prefix;
135extern const char *legacy_bootp_filename;
136
Jan Kiszka10ae5a72009-05-08 12:34:18 +0200137int net_client_init(Monitor *mon, const char *device, const char *p);
aliguori8b13c4a2009-02-11 15:20:51 +0000138void net_client_uninit(NICInfo *nd);
aliguori63a01ef2008-10-31 19:10:00 +0000139int net_client_parse(const char *str);
140void net_slirp_smb(const char *exported_dir);
Luiz Capitulino1d4daa92009-08-28 15:27:15 -0300141void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
142void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
Jan Kiszkaf3546de2009-06-24 14:42:28 +0200143void net_slirp_redir(const char *redir_str);
aliguori63a01ef2008-10-31 19:10:00 +0000144void net_cleanup(void);
aliguori63a01ef2008-10-31 19:10:00 +0000145void net_client_check(void);
Glauber Costa406c8df2009-06-17 09:05:30 -0400146void net_set_boot_mask(int boot_mask);
Luiz Capitulinof18c16d2009-08-28 15:27:14 -0300147void net_host_device_add(Monitor *mon, const QDict *qdict);
148void net_host_device_remove(Monitor *mon, const QDict *qdict);
aliguori63a01ef2008-10-31 19:10:00 +0000149
aurel32f54825c2008-12-18 22:43:48 +0000150#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
151#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
152#ifdef __sun__
153#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
154#else
155#define SMBD_COMMAND "/usr/sbin/smbd"
156#endif
157
Paul Brook9d07d752009-05-14 22:35:07 +0100158void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
159VLANClientState *qdev_get_vlan_client(DeviceState *dev,
Mark McLoughlincda90462009-05-18 13:13:16 +0100160 NetCanReceive *can_receive,
161 NetReceive *receive,
162 NetReceiveIOV *receive_iov,
Paul Brook9d07d752009-05-14 22:35:07 +0100163 NetCleanup *cleanup,
164 void *opaque);
165
pbrook87ecb682007-11-17 17:14:51 +0000166#endif