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