Update version and changelog for 0.11.0 release
[qemu-kvm/fedora.git] / net.h
blobbab02f5de94a5f082c37e9360cdce65de081a214
1 #ifndef QEMU_NET_H
2 #define QEMU_NET_H
4 #include "sys-queue.h"
5 #include "qemu-common.h"
7 /* VLANs support */
9 typedef struct VLANClientState VLANClientState;
11 typedef int (NetCanReceive)(VLANClientState *);
12 typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
13 typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
14 typedef void (NetCleanup) (VLANClientState *);
15 typedef void (LinkStatusChanged)(VLANClientState *);
17 struct VLANClientState {
18 NetReceive *receive;
19 NetReceiveIOV *receive_iov;
20 /* Packets may still be sent if this returns zero. It's used to
21 rate-limit the slirp code. */
22 NetCanReceive *can_receive;
23 NetCleanup *cleanup;
24 LinkStatusChanged *link_status_changed;
25 int link_down;
26 void *opaque;
27 struct VLANClientState *next;
28 struct VLANState *vlan;
29 char *model;
30 char *name;
31 char info_str[256];
34 typedef struct VLANPacket VLANPacket;
36 typedef void (NetPacketSent) (VLANClientState *, ssize_t);
38 struct VLANPacket {
39 TAILQ_ENTRY(VLANPacket) entry;
40 VLANClientState *sender;
41 int size;
42 NetPacketSent *sent_cb;
43 uint8_t data[0];
46 struct VLANState {
47 int id;
48 VLANClientState *first_client;
49 struct VLANState *next;
50 unsigned int nb_guest_devs, nb_host_devs;
51 TAILQ_HEAD(send_queue, VLANPacket) send_queue;
52 int delivering;
55 VLANState *qemu_find_vlan(int id, int allocate);
56 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
57 const char *model,
58 const char *name,
59 NetCanReceive *can_receive,
60 NetReceive *receive,
61 NetReceiveIOV *receive_iov,
62 NetCleanup *cleanup,
63 void *opaque);
64 void qemu_del_vlan_client(VLANClientState *vc);
65 VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
66 int qemu_can_send_packet(VLANClientState *vc);
67 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
68 int iovcnt);
69 ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
70 int iovcnt, NetPacketSent *sent_cb);
71 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
72 ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
73 int size, NetPacketSent *sent_cb);
74 void qemu_purge_queued_packets(VLANClientState *vc);
75 void qemu_flush_queued_packets(VLANClientState *vc);
76 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
77 void qemu_check_nic_model(NICInfo *nd, const char *model);
78 void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
79 const char *default_model);
80 void qemu_handler_true(void *opaque);
82 void do_info_network(Monitor *mon);
83 void do_set_link(Monitor *mon, const char *name, const char *up_or_down);
85 void do_info_usernet(Monitor *mon);
87 /* NIC info */
89 #define MAX_NICS 8
90 enum {
91 NIC_NVECTORS_UNSPECIFIED = -1
94 struct NICInfo {
95 uint8_t macaddr[6];
96 const char *model;
97 const char *name;
98 const char *devaddr;
99 const char *id;
100 VLANState *vlan;
101 VLANClientState *vc;
102 void *private;
103 int used;
104 int bootable;
105 int nvectors;
108 extern int nb_nics;
109 extern NICInfo nd_table[MAX_NICS];
111 /* BT HCI info */
113 struct HCIInfo {
114 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
115 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
116 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
117 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
118 void *opaque;
119 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
120 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
123 struct HCIInfo *qemu_next_hci(void);
125 /* checksumming functions (net-checksum.c) */
126 uint32_t net_checksum_add(int len, uint8_t *buf);
127 uint16_t net_checksum_finish(uint32_t sum);
128 uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
129 uint8_t *addrs, uint8_t *buf);
130 void net_checksum_calculate(uint8_t *data, int length);
132 /* from net.c */
133 extern const char *legacy_tftp_prefix;
134 extern const char *legacy_bootp_filename;
136 int net_client_init(Monitor *mon, const char *device, const char *p);
137 void net_client_uninit(NICInfo *nd);
138 int net_client_parse(const char *str);
139 void net_slirp_smb(const char *exported_dir);
140 void net_slirp_hostfwd_add(Monitor *mon, const char *arg1,
141 const char *arg2, const char *arg3);
142 void net_slirp_hostfwd_remove(Monitor *mon, const char *arg1,
143 const char *arg2, const char *arg3);
144 void net_slirp_redir(const char *redir_str);
145 void net_cleanup(void);
146 void net_client_check(void);
147 void net_set_boot_mask(int boot_mask);
148 void net_host_device_add(Monitor *mon, const char *device, const char *opts);
149 void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
151 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
152 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
153 #ifdef __sun__
154 #define SMBD_COMMAND "/usr/sfw/sbin/smbd"
155 #else
156 #define SMBD_COMMAND "/usr/sbin/smbd"
157 #endif
159 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
160 VLANClientState *qdev_get_vlan_client(DeviceState *dev,
161 NetCanReceive *can_receive,
162 NetReceive *receive,
163 NetReceiveIOV *receive_iov,
164 NetCleanup *cleanup,
165 void *opaque);
167 #endif