blob: 89e7706be49ef745cba7975a254d651951210789 [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_NET_H
2#define QEMU_NET_H
3
aliguorifbe78f42008-12-17 19:13:11 +00004#include "qemu-common.h"
5
pbrook87ecb682007-11-17 17:14:51 +00006/* VLANs support */
7
8typedef struct VLANClientState VLANClientState;
9
Mark McLoughline3f5ec22009-05-18 13:33:03 +010010typedef int (NetCanReceive)(VLANClientState *);
Mark McLoughlin4f1c9422009-05-18 13:40:55 +010011typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
Mark McLoughline3f5ec22009-05-18 13:33:03 +010012typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
aliguorib946a152009-04-17 17:11:08 +000013typedef void (NetCleanup) (VLANClientState *);
aliguori34b25ca2009-01-08 19:45:03 +000014typedef void (LinkStatusChanged)(VLANClientState *);
15
pbrook87ecb682007-11-17 17:14:51 +000016struct VLANClientState {
Mark McLoughlincda90462009-05-18 13:13:16 +010017 NetReceive *receive;
18 NetReceiveIOV *receive_iov;
pbrook87ecb682007-11-17 17:14:51 +000019 /* Packets may still be sent if this returns zero. It's used to
20 rate-limit the slirp code. */
Mark McLoughlincda90462009-05-18 13:13:16 +010021 NetCanReceive *can_receive;
aliguorib946a152009-04-17 17:11:08 +000022 NetCleanup *cleanup;
aliguori34b25ca2009-01-08 19:45:03 +000023 LinkStatusChanged *link_status_changed;
aliguori436e5e52009-01-08 19:44:06 +000024 int link_down;
pbrook87ecb682007-11-17 17:14:51 +000025 void *opaque;
26 struct VLANClientState *next;
27 struct VLANState *vlan;
aliguoribf38c1a2009-01-07 17:42:25 +000028 char *model;
aliguori676cff22009-01-07 17:43:44 +000029 char *name;
pbrook87ecb682007-11-17 17:14:51 +000030 char info_str[256];
31};
32
aliguori764a4d12009-04-21 19:56:41 +000033typedef struct VLANPacket VLANPacket;
34
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010035typedef void (NetPacketSent) (VLANClientState *);
36
aliguori764a4d12009-04-21 19:56:41 +000037struct VLANPacket {
38 struct VLANPacket *next;
39 VLANClientState *sender;
40 int size;
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010041 NetPacketSent *sent_cb;
aliguori764a4d12009-04-21 19:56:41 +000042 uint8_t data[0];
43};
44
pbrook87ecb682007-11-17 17:14:51 +000045struct VLANState {
46 int id;
47 VLANClientState *first_client;
48 struct VLANState *next;
49 unsigned int nb_guest_devs, nb_host_devs;
aliguori764a4d12009-04-21 19:56:41 +000050 VLANPacket *send_queue;
51 int delivering;
pbrook87ecb682007-11-17 17:14:51 +000052};
53
54VLANState *qemu_find_vlan(int id);
55VLANClientState *qemu_new_vlan_client(VLANState *vlan,
aliguoribf38c1a2009-01-07 17:42:25 +000056 const char *model,
aliguori7a9f6e42009-01-07 17:48:51 +000057 const char *name,
Mark McLoughlincda90462009-05-18 13:13:16 +010058 NetCanReceive *can_receive,
59 NetReceive *receive,
60 NetReceiveIOV *receive_iov,
aliguorib946a152009-04-17 17:11:08 +000061 NetCleanup *cleanup,
pbrook87ecb682007-11-17 17:14:51 +000062 void *opaque);
balrogdcf414d2008-07-17 21:00:05 +000063void qemu_del_vlan_client(VLANClientState *vc);
aliguori8b13c4a2009-02-11 15:20:51 +000064VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
pbrook87ecb682007-11-17 17:14:51 +000065int qemu_can_send_packet(VLANClientState *vc);
aliguorifbe78f42008-12-17 19:13:11 +000066ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
67 int iovcnt);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010068ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
69 int iovcnt, NetPacketSent *sent_cb);
pbrook87ecb682007-11-17 17:14:51 +000070void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
Mark McLoughlinf3b6c7f2009-04-29 12:15:26 +010071ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
72 int size, NetPacketSent *sent_cb);
73void qemu_flush_queued_packets(VLANClientState *vc);
aliguori7cb7434b2009-01-07 17:46:21 +000074void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
aliguorid07f22c2009-01-13 19:03:57 +000075void qemu_check_nic_model(NICInfo *nd, const char *model);
76void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
77 const char *default_model);
pbrook87ecb682007-11-17 17:14:51 +000078void qemu_handler_true(void *opaque);
79
aliguori376253e2009-03-05 23:01:23 +000080void do_info_network(Monitor *mon);
81int do_set_link(Monitor *mon, const char *name, const char *up_or_down);
pbrook87ecb682007-11-17 17:14:51 +000082
83/* NIC info */
84
85#define MAX_NICS 8
86
87struct NICInfo {
88 uint8_t macaddr[6];
89 const char *model;
aliguori7a9f6e42009-01-07 17:48:51 +000090 const char *name;
pbrook87ecb682007-11-17 17:14:51 +000091 VLANState *vlan;
aliguori72da4202009-02-11 15:19:52 +000092 void *private;
aliguori76970792009-02-11 15:20:03 +000093 int used;
pbrook87ecb682007-11-17 17:14:51 +000094};
95
96extern int nb_nics;
97extern NICInfo nd_table[MAX_NICS];
98
balrog1ae26a12008-09-28 23:19:47 +000099/* BT HCI info */
100
101struct HCIInfo {
102 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
103 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
104 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
105 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
106 void *opaque;
107 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
108 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
109};
110
111struct HCIInfo *qemu_next_hci(void);
112
aliguori48c64362008-07-29 19:40:04 +0000113/* checksumming functions (net-checksum.c) */
114uint32_t net_checksum_add(int len, uint8_t *buf);
115uint16_t net_checksum_finish(uint32_t sum);
116uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
117 uint8_t *addrs, uint8_t *buf);
118void net_checksum_calculate(uint8_t *data, int length);
119
aliguori63a01ef2008-10-31 19:10:00 +0000120/* from net.c */
Jan Kiszka10ae5a72009-05-08 12:34:18 +0200121int net_client_init(Monitor *mon, const char *device, const char *p);
aliguori8b13c4a2009-02-11 15:20:51 +0000122void net_client_uninit(NICInfo *nd);
aliguori63a01ef2008-10-31 19:10:00 +0000123int net_client_parse(const char *str);
124void net_slirp_smb(const char *exported_dir);
Alexander Grafc1261d82009-05-26 13:03:26 +0200125void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2);
aliguori63a01ef2008-10-31 19:10:00 +0000126void net_cleanup(void);
127int slirp_is_inited(void);
128void net_client_check(void);
aliguori376253e2009-03-05 23:01:23 +0000129void net_host_device_add(Monitor *mon, const char *device, const char *opts);
130void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
aliguori63a01ef2008-10-31 19:10:00 +0000131
aurel32f54825c2008-12-18 22:43:48 +0000132#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
133#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
134#ifdef __sun__
135#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
136#else
137#define SMBD_COMMAND "/usr/sbin/smbd"
138#endif
139
Paul Brook9d07d752009-05-14 22:35:07 +0100140void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
141VLANClientState *qdev_get_vlan_client(DeviceState *dev,
Mark McLoughlincda90462009-05-18 13:13:16 +0100142 NetCanReceive *can_receive,
143 NetReceive *receive,
144 NetReceiveIOV *receive_iov,
Paul Brook9d07d752009-05-14 22:35:07 +0100145 NetCleanup *cleanup,
146 void *opaque);
147
pbrook87ecb682007-11-17 17:14:51 +0000148#endif