]>
Commit | Line | Data |
---|---|---|
87ecb68b PB |
1 | #ifndef QEMU_NET_H |
2 | #define QEMU_NET_H | |
3 | ||
72cf2d4f | 4 | #include "qemu-queue.h" |
fbe78f4f | 5 | #include "qemu-common.h" |
f18c16de | 6 | #include "qdict.h" |
13cf8f21 | 7 | #include "qemu-option.h" |
f7105843 | 8 | #include "net-queue.h" |
fbe78f4f | 9 | |
87ecb68b PB |
10 | /* VLANs support */ |
11 | ||
e3f5ec2b | 12 | typedef int (NetCanReceive)(VLANClientState *); |
4f1c942b | 13 | typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); |
e3f5ec2b | 14 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); |
b946a153 | 15 | typedef void (NetCleanup) (VLANClientState *); |
34b25ca7 AL |
16 | typedef void (LinkStatusChanged)(VLANClientState *); |
17 | ||
87ecb68b | 18 | struct VLANClientState { |
cda9046b MM |
19 | NetReceive *receive; |
20 | NetReceiveIOV *receive_iov; | |
87ecb68b PB |
21 | /* Packets may still be sent if this returns zero. It's used to |
22 | rate-limit the slirp code. */ | |
cda9046b | 23 | NetCanReceive *can_receive; |
b946a153 | 24 | NetCleanup *cleanup; |
34b25ca7 | 25 | LinkStatusChanged *link_status_changed; |
436e5e53 | 26 | int link_down; |
87ecb68b | 27 | void *opaque; |
5610c3aa | 28 | QTAILQ_ENTRY(VLANClientState) next; |
87ecb68b | 29 | struct VLANState *vlan; |
283c7c63 | 30 | VLANClientState *peer; |
9a6ecb30 | 31 | NetQueue *send_queue; |
bf38c1a0 | 32 | char *model; |
676cff29 | 33 | char *name; |
87ecb68b PB |
34 | char info_str[256]; |
35 | }; | |
36 | ||
37 | struct VLANState { | |
38 | int id; | |
5610c3aa MM |
39 | QTAILQ_HEAD(, VLANClientState) clients; |
40 | QTAILQ_ENTRY(VLANState) next; | |
87ecb68b | 41 | unsigned int nb_guest_devs, nb_host_devs; |
f7105843 | 42 | NetQueue *send_queue; |
87ecb68b PB |
43 | }; |
44 | ||
1a609520 | 45 | VLANState *qemu_find_vlan(int id, int allocate); |
87ecb68b | 46 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
283c7c63 | 47 | VLANClientState *peer, |
bf38c1a0 | 48 | const char *model, |
7a9f6e4a | 49 | const char *name, |
cda9046b MM |
50 | NetCanReceive *can_receive, |
51 | NetReceive *receive, | |
52 | NetReceiveIOV *receive_iov, | |
b946a153 | 53 | NetCleanup *cleanup, |
87ecb68b | 54 | void *opaque); |
dcf414d6 | 55 | void qemu_del_vlan_client(VLANClientState *vc); |
8b13c4a7 | 56 | VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); |
87ecb68b | 57 | int qemu_can_send_packet(VLANClientState *vc); |
fbe78f4f AL |
58 | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
59 | int iovcnt); | |
f3b6c7fc MM |
60 | ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, |
61 | int iovcnt, NetPacketSent *sent_cb); | |
87ecb68b | 62 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
f3b6c7fc MM |
63 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, |
64 | int size, NetPacketSent *sent_cb); | |
8cad5516 | 65 | void qemu_purge_queued_packets(VLANClientState *vc); |
f3b6c7fc | 66 | void qemu_flush_queued_packets(VLANClientState *vc); |
7cb7434b | 67 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
07caea31 | 68 | int qemu_show_nic_models(const char *arg, const char *const *models); |
d07f22c5 | 69 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
07caea31 MA |
70 | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
71 | const char *default_model); | |
87ecb68b | 72 | |
376253ec | 73 | void do_info_network(Monitor *mon); |
f18c16de | 74 | void do_set_link(Monitor *mon, const QDict *qdict); |
87ecb68b | 75 | |
6dbe553f JK |
76 | void do_info_usernet(Monitor *mon); |
77 | ||
87ecb68b PB |
78 | /* NIC info */ |
79 | ||
80 | #define MAX_NICS 8 | |
ffe6370c MT |
81 | enum { |
82 | NIC_NVECTORS_UNSPECIFIED = -1 | |
83 | }; | |
87ecb68b PB |
84 | |
85 | struct NICInfo { | |
86 | uint8_t macaddr[6]; | |
9203f520 MM |
87 | char *model; |
88 | char *name; | |
89 | char *devaddr; | |
87ecb68b | 90 | VLANState *vlan; |
5869c4d5 | 91 | VLANClientState *netdev; |
ae50b274 | 92 | VLANClientState *vc; |
72da4208 | 93 | void *private; |
7697079b | 94 | int used; |
406c8df3 | 95 | int bootable; |
ffe6370c | 96 | int nvectors; |
87ecb68b PB |
97 | }; |
98 | ||
99 | extern int nb_nics; | |
100 | extern NICInfo nd_table[MAX_NICS]; | |
101 | ||
1ae26a18 AZ |
102 | /* BT HCI info */ |
103 | ||
104 | struct HCIInfo { | |
105 | int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); | |
106 | void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); | |
107 | void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); | |
108 | void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); | |
109 | void *opaque; | |
110 | void (*evt_recv)(void *opaque, const uint8_t *data, int len); | |
111 | void (*acl_recv)(void *opaque, const uint8_t *data, int len); | |
112 | }; | |
113 | ||
114 | struct HCIInfo *qemu_next_hci(void); | |
115 | ||
48c64363 AL |
116 | /* checksumming functions (net-checksum.c) */ |
117 | uint32_t net_checksum_add(int len, uint8_t *buf); | |
118 | uint16_t net_checksum_finish(uint32_t sum); | |
119 | uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, | |
120 | uint8_t *addrs, uint8_t *buf); | |
121 | void net_checksum_calculate(uint8_t *data, int length); | |
122 | ||
63a01ef8 | 123 | /* from net.c */ |
ad196a9d JK |
124 | extern const char *legacy_tftp_prefix; |
125 | extern const char *legacy_bootp_filename; | |
126 | ||
f6b134ac | 127 | int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev); |
8b13c4a7 | 128 | void net_client_uninit(NICInfo *nd); |
7f161aae | 129 | int net_client_parse(QemuOptsList *opts_list, const char *str); |
dc1c9fe8 | 130 | int net_init_clients(void); |
0752706d | 131 | int net_slirp_smb(const char *exported_dir); |
1d4daa91 LC |
132 | void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict); |
133 | void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict); | |
0752706d | 134 | int net_slirp_redir(const char *redir_str); |
63a01ef8 | 135 | void net_cleanup(void); |
406c8df3 | 136 | void net_set_boot_mask(int boot_mask); |
f18c16de LC |
137 | void net_host_device_add(Monitor *mon, const QDict *qdict); |
138 | void net_host_device_remove(Monitor *mon, const QDict *qdict); | |
63a01ef8 | 139 | |
f54825cc AJ |
140 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
141 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" | |
142 | #ifdef __sun__ | |
143 | #define SMBD_COMMAND "/usr/sfw/sbin/smbd" | |
144 | #else | |
145 | #define SMBD_COMMAND "/usr/sbin/smbd" | |
146 | #endif | |
147 | ||
9d07d757 PB |
148 | void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr); |
149 | VLANClientState *qdev_get_vlan_client(DeviceState *dev, | |
cda9046b MM |
150 | NetCanReceive *can_receive, |
151 | NetReceive *receive, | |
152 | NetReceiveIOV *receive_iov, | |
9d07d757 PB |
153 | NetCleanup *cleanup, |
154 | void *opaque); | |
155 | ||
87ecb68b | 156 | #endif |