]>
Commit | Line | Data |
---|---|---|
87ecb68b PB |
1 | #ifndef QEMU_NET_H |
2 | #define QEMU_NET_H | |
3 | ||
9da43187 | 4 | #include "sys-queue.h" |
fbe78f4f AL |
5 | #include "qemu-common.h" |
6 | ||
87ecb68b PB |
7 | /* VLANs support */ |
8 | ||
9 | typedef struct VLANClientState VLANClientState; | |
10 | ||
e3f5ec2b | 11 | typedef int (NetCanReceive)(VLANClientState *); |
4f1c942b | 12 | typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); |
e3f5ec2b | 13 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); |
b946a153 | 14 | typedef void (NetCleanup) (VLANClientState *); |
34b25ca7 AL |
15 | typedef void (LinkStatusChanged)(VLANClientState *); |
16 | ||
87ecb68b | 17 | struct VLANClientState { |
cda9046b MM |
18 | NetReceive *receive; |
19 | NetReceiveIOV *receive_iov; | |
87ecb68b PB |
20 | /* Packets may still be sent if this returns zero. It's used to |
21 | rate-limit the slirp code. */ | |
cda9046b | 22 | NetCanReceive *can_receive; |
b946a153 | 23 | NetCleanup *cleanup; |
34b25ca7 | 24 | LinkStatusChanged *link_status_changed; |
436e5e53 | 25 | int link_down; |
87ecb68b PB |
26 | void *opaque; |
27 | struct VLANClientState *next; | |
28 | struct VLANState *vlan; | |
bf38c1a0 | 29 | char *model; |
676cff29 | 30 | char *name; |
87ecb68b PB |
31 | char info_str[256]; |
32 | }; | |
33 | ||
764a4d1d AL |
34 | typedef struct VLANPacket VLANPacket; |
35 | ||
783527a9 | 36 | typedef void (NetPacketSent) (VLANClientState *, ssize_t); |
f3b6c7fc | 37 | |
764a4d1d | 38 | struct VLANPacket { |
9da43187 | 39 | TAILQ_ENTRY(VLANPacket) entry; |
764a4d1d AL |
40 | VLANClientState *sender; |
41 | int size; | |
f3b6c7fc | 42 | NetPacketSent *sent_cb; |
764a4d1d AL |
43 | uint8_t data[0]; |
44 | }; | |
45 | ||
87ecb68b PB |
46 | struct VLANState { |
47 | int id; | |
48 | VLANClientState *first_client; | |
49 | struct VLANState *next; | |
50 | unsigned int nb_guest_devs, nb_host_devs; | |
9da43187 | 51 | TAILQ_HEAD(send_queue, VLANPacket) send_queue; |
764a4d1d | 52 | int delivering; |
87ecb68b PB |
53 | }; |
54 | ||
1a609520 | 55 | VLANState *qemu_find_vlan(int id, int allocate); |
87ecb68b | 56 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
bf38c1a0 | 57 | const char *model, |
7a9f6e4a | 58 | const char *name, |
cda9046b MM |
59 | NetCanReceive *can_receive, |
60 | NetReceive *receive, | |
61 | NetReceiveIOV *receive_iov, | |
b946a153 | 62 | NetCleanup *cleanup, |
87ecb68b | 63 | void *opaque); |
dcf414d6 | 64 | void qemu_del_vlan_client(VLANClientState *vc); |
8b13c4a7 | 65 | VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); |
87ecb68b | 66 | int qemu_can_send_packet(VLANClientState *vc); |
fbe78f4f AL |
67 | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
68 | int iovcnt); | |
f3b6c7fc MM |
69 | ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, |
70 | int iovcnt, NetPacketSent *sent_cb); | |
87ecb68b | 71 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
f3b6c7fc MM |
72 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, |
73 | int size, NetPacketSent *sent_cb); | |
8cad5516 | 74 | void qemu_purge_queued_packets(VLANClientState *vc); |
f3b6c7fc | 75 | void qemu_flush_queued_packets(VLANClientState *vc); |
7cb7434b | 76 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
d07f22c5 AL |
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); | |
87ecb68b PB |
80 | void qemu_handler_true(void *opaque); |
81 | ||
376253ec | 82 | void do_info_network(Monitor *mon); |
c3cf0d3f | 83 | void do_set_link(Monitor *mon, const char *name, const char *up_or_down); |
87ecb68b | 84 | |
6dbe553f JK |
85 | void do_info_usernet(Monitor *mon); |
86 | ||
87ecb68b PB |
87 | /* NIC info */ |
88 | ||
89 | #define MAX_NICS 8 | |
ffe6370c MT |
90 | enum { |
91 | NIC_NVECTORS_UNSPECIFIED = -1 | |
92 | }; | |
87ecb68b PB |
93 | |
94 | struct NICInfo { | |
95 | uint8_t macaddr[6]; | |
96 | const char *model; | |
7a9f6e4a | 97 | const char *name; |
5607c388 | 98 | const char *devaddr; |
eb54b6dc | 99 | const char *id; |
87ecb68b | 100 | VLANState *vlan; |
ae50b274 | 101 | VLANClientState *vc; |
72da4208 | 102 | void *private; |
7697079b | 103 | int used; |
406c8df3 | 104 | int bootable; |
ffe6370c | 105 | int nvectors; |
87ecb68b PB |
106 | }; |
107 | ||
108 | extern int nb_nics; | |
109 | extern NICInfo nd_table[MAX_NICS]; | |
110 | ||
1ae26a18 AZ |
111 | /* BT HCI info */ |
112 | ||
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); | |
121 | }; | |
122 | ||
123 | struct HCIInfo *qemu_next_hci(void); | |
124 | ||
48c64363 AL |
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); | |
131 | ||
63a01ef8 | 132 | /* from net.c */ |
ad196a9d JK |
133 | extern const char *legacy_tftp_prefix; |
134 | extern const char *legacy_bootp_filename; | |
135 | ||
10ae5a7a | 136 | int net_client_init(Monitor *mon, const char *device, const char *p); |
8b13c4a7 | 137 | void net_client_uninit(NICInfo *nd); |
63a01ef8 AL |
138 | int net_client_parse(const char *str); |
139 | void net_slirp_smb(const char *exported_dir); | |
f13b572c JK |
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); | |
f3546deb | 144 | void net_slirp_redir(const char *redir_str); |
63a01ef8 | 145 | void net_cleanup(void); |
63a01ef8 | 146 | void net_client_check(void); |
406c8df3 | 147 | void net_set_boot_mask(int boot_mask); |
376253ec AL |
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); | |
63a01ef8 | 150 | |
f54825cc AJ |
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 | |
158 | ||
9d07d757 PB |
159 | void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr); |
160 | VLANClientState *qdev_get_vlan_client(DeviceState *dev, | |
cda9046b MM |
161 | NetCanReceive *can_receive, |
162 | NetReceive *receive, | |
163 | NetReceiveIOV *receive_iov, | |
9d07d757 PB |
164 | NetCleanup *cleanup, |
165 | void *opaque); | |
166 | ||
87ecb68b | 167 | #endif |