pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 1 | #ifndef QEMU_NET_H |
| 2 | #define QEMU_NET_H |
| 3 | |
Blue Swirl | 72cf2d4 | 2009-09-12 07:36:22 +0000 | [diff] [blame] | 4 | #include "qemu-queue.h" |
aliguori | fbe78f4 | 2008-12-17 19:13:11 +0000 | [diff] [blame] | 5 | #include "qemu-common.h" |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 6 | #include "qdict.h" |
Mark McLoughlin | 13cf8f2 | 2009-10-06 12:17:14 +0100 | [diff] [blame] | 7 | #include "qemu-option.h" |
Mark McLoughlin | e1144d0 | 2009-10-23 17:52:16 +0100 | [diff] [blame] | 8 | #include "net/queue.h" |
aliguori | fbe78f4 | 2008-12-17 19:13:11 +0000 | [diff] [blame] | 9 | |
Gerd Hoffmann | 76d32cb | 2009-10-21 15:25:22 +0200 | [diff] [blame] | 10 | struct MACAddr { |
| 11 | uint8_t a[6]; |
| 12 | }; |
| 13 | |
Gerd Hoffmann | ed16ab5 | 2009-10-21 15:25:26 +0200 | [diff] [blame] | 14 | /* qdev nic properties */ |
| 15 | |
| 16 | typedef struct NICConf { |
| 17 | MACAddr macaddr; |
| 18 | VLANState *vlan; |
| 19 | VLANClientState *peer; |
| 20 | } NICConf; |
| 21 | |
| 22 | #define DEFINE_NIC_PROPERTIES(_state, _conf) \ |
| 23 | DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ |
| 24 | DEFINE_PROP_VLAN("vlan", _state, _conf.vlan), \ |
| 25 | DEFINE_PROP_NETDEV("netdev", _state, _conf.peer) |
| 26 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 27 | /* VLANs support */ |
| 28 | |
Mark McLoughlin | bb6e636 | 2009-10-22 17:43:38 +0100 | [diff] [blame] | 29 | typedef enum { |
| 30 | NET_CLIENT_TYPE_NONE, |
| 31 | NET_CLIENT_TYPE_NIC, |
| 32 | NET_CLIENT_TYPE_SLIRP, |
| 33 | NET_CLIENT_TYPE_TAP, |
| 34 | NET_CLIENT_TYPE_SOCKET, |
| 35 | NET_CLIENT_TYPE_VDE, |
| 36 | NET_CLIENT_TYPE_DUMP |
| 37 | } net_client_type; |
| 38 | |
Mark McLoughlin | e3f5ec2 | 2009-05-18 13:33:03 +0100 | [diff] [blame] | 39 | typedef int (NetCanReceive)(VLANClientState *); |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 40 | typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); |
Mark McLoughlin | e3f5ec2 | 2009-05-18 13:33:03 +0100 | [diff] [blame] | 41 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 42 | typedef void (NetCleanup) (VLANClientState *); |
aliguori | 34b25ca | 2009-01-08 19:45:03 +0000 | [diff] [blame] | 43 | typedef void (LinkStatusChanged)(VLANClientState *); |
| 44 | |
Mark McLoughlin | 3ed79cc | 2009-11-25 18:49:01 +0000 | [diff] [blame] | 45 | typedef struct NetClientInfo { |
| 46 | net_client_type type; |
| 47 | size_t size; |
| 48 | NetReceive *receive; |
| 49 | NetReceive *receive_raw; |
| 50 | NetReceiveIOV *receive_iov; |
| 51 | NetCanReceive *can_receive; |
| 52 | NetCleanup *cleanup; |
| 53 | LinkStatusChanged *link_status_changed; |
| 54 | } NetClientInfo; |
| 55 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 56 | struct VLANClientState { |
Mark McLoughlin | bb6e636 | 2009-10-22 17:43:38 +0100 | [diff] [blame] | 57 | net_client_type type; |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 58 | NetReceive *receive; |
Mark McLoughlin | ca77d17 | 2009-10-22 17:43:41 +0100 | [diff] [blame] | 59 | NetReceive *receive_raw; |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 60 | NetReceiveIOV *receive_iov; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 61 | /* Packets may still be sent if this returns zero. It's used to |
| 62 | rate-limit the slirp code. */ |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 63 | NetCanReceive *can_receive; |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 64 | NetCleanup *cleanup; |
aliguori | 34b25ca | 2009-01-08 19:45:03 +0000 | [diff] [blame] | 65 | LinkStatusChanged *link_status_changed; |
aliguori | 436e5e5 | 2009-01-08 19:44:06 +0000 | [diff] [blame] | 66 | int link_down; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 67 | void *opaque; |
Mark McLoughlin | 5610c3a | 2009-10-08 19:58:23 +0100 | [diff] [blame] | 68 | QTAILQ_ENTRY(VLANClientState) next; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 69 | struct VLANState *vlan; |
Mark McLoughlin | 283c7c6 | 2009-10-08 19:58:30 +0100 | [diff] [blame] | 70 | VLANClientState *peer; |
Mark McLoughlin | 9a6ecb3 | 2009-10-08 19:58:32 +0100 | [diff] [blame] | 71 | NetQueue *send_queue; |
aliguori | bf38c1a | 2009-01-07 17:42:25 +0000 | [diff] [blame] | 72 | char *model; |
aliguori | 676cff2 | 2009-01-07 17:43:44 +0000 | [diff] [blame] | 73 | char *name; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 74 | char info_str[256]; |
Mark McLoughlin | 893379e | 2009-10-27 18:16:36 +0000 | [diff] [blame] | 75 | unsigned receive_disabled : 1; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 76 | }; |
| 77 | |
Mark McLoughlin | ebef2c0 | 2009-11-25 18:49:10 +0000 | [diff] [blame^] | 78 | typedef struct NICState { |
| 79 | VLANClientState nc; |
| 80 | NICConf *conf; |
| 81 | void *opaque; |
| 82 | } NICState; |
| 83 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 84 | struct VLANState { |
| 85 | int id; |
Mark McLoughlin | 5610c3a | 2009-10-08 19:58:23 +0100 | [diff] [blame] | 86 | QTAILQ_HEAD(, VLANClientState) clients; |
| 87 | QTAILQ_ENTRY(VLANState) next; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 88 | unsigned int nb_guest_devs, nb_host_devs; |
Mark McLoughlin | f710584 | 2009-10-08 19:58:31 +0100 | [diff] [blame] | 89 | NetQueue *send_queue; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 90 | }; |
| 91 | |
Jan Kiszka | 1a60952 | 2009-06-24 14:42:31 +0200 | [diff] [blame] | 92 | VLANState *qemu_find_vlan(int id, int allocate); |
Gerd Hoffmann | 2ef924b | 2009-10-21 15:25:24 +0200 | [diff] [blame] | 93 | VLANClientState *qemu_find_netdev(const char *id); |
Mark McLoughlin | 45460d1 | 2009-11-25 18:49:02 +0000 | [diff] [blame] | 94 | VLANClientState *qemu_new_net_client(NetClientInfo *info, |
| 95 | VLANState *vlan, |
| 96 | VLANClientState *peer, |
| 97 | const char *model, |
| 98 | const char *name); |
Mark McLoughlin | ebef2c0 | 2009-11-25 18:49:10 +0000 | [diff] [blame^] | 99 | NICState *qemu_new_nic(NetClientInfo *info, |
| 100 | NICConf *conf, |
| 101 | const char *model, |
| 102 | const char *name, |
| 103 | void *opaque); |
Anthony Liguori | 9f09204 | 2009-10-22 15:29:03 -0500 | [diff] [blame] | 104 | VLANClientState *qemu_new_vlan_client(net_client_type type, |
Anthony Liguori | a7f085c | 2009-10-22 15:27:24 -0500 | [diff] [blame] | 105 | VLANState *vlan, |
Mark McLoughlin | 283c7c6 | 2009-10-08 19:58:30 +0100 | [diff] [blame] | 106 | VLANClientState *peer, |
aliguori | bf38c1a | 2009-01-07 17:42:25 +0000 | [diff] [blame] | 107 | const char *model, |
aliguori | 7a9f6e4 | 2009-01-07 17:48:51 +0000 | [diff] [blame] | 108 | const char *name, |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 109 | NetCanReceive *can_receive, |
| 110 | NetReceive *receive, |
Mark McLoughlin | 70783b9 | 2009-10-22 17:43:42 +0100 | [diff] [blame] | 111 | NetReceive *receive_raw, |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 112 | NetReceiveIOV *receive_iov, |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 113 | NetCleanup *cleanup, |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 114 | void *opaque); |
balrog | dcf414d | 2008-07-17 21:00:05 +0000 | [diff] [blame] | 115 | void qemu_del_vlan_client(VLANClientState *vc); |
aliguori | 8b13c4a | 2009-02-11 15:20:51 +0000 | [diff] [blame] | 116 | VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); |
Mark McLoughlin | 68ac40d | 2009-11-25 18:48:54 +0000 | [diff] [blame] | 117 | VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, |
| 118 | const char *client_str); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 119 | int qemu_can_send_packet(VLANClientState *vc); |
aliguori | fbe78f4 | 2008-12-17 19:13:11 +0000 | [diff] [blame] | 120 | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
| 121 | int iovcnt); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 122 | ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, |
| 123 | int iovcnt, NetPacketSent *sent_cb); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 124 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
Mark McLoughlin | ca77d17 | 2009-10-22 17:43:41 +0100 | [diff] [blame] | 125 | ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 126 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, |
| 127 | int size, NetPacketSent *sent_cb); |
Mark McLoughlin | 8cad551 | 2009-06-18 18:21:29 +0100 | [diff] [blame] | 128 | void qemu_purge_queued_packets(VLANClientState *vc); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 129 | void qemu_flush_queued_packets(VLANClientState *vc); |
aliguori | 7cb7434b | 2009-01-07 17:46:21 +0000 | [diff] [blame] | 130 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
Gerd Hoffmann | 76d32cb | 2009-10-21 15:25:22 +0200 | [diff] [blame] | 131 | void qemu_macaddr_default_if_unset(MACAddr *macaddr); |
Markus Armbruster | 07caea3 | 2009-09-25 03:53:51 +0200 | [diff] [blame] | 132 | int qemu_show_nic_models(const char *arg, const char *const *models); |
aliguori | d07f22c | 2009-01-13 19:03:57 +0000 | [diff] [blame] | 133 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
Markus Armbruster | 07caea3 | 2009-09-25 03:53:51 +0200 | [diff] [blame] | 134 | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
| 135 | const char *default_model); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 136 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 137 | void do_info_network(Monitor *mon); |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 138 | void do_set_link(Monitor *mon, const QDict *qdict); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 139 | |
| 140 | /* NIC info */ |
| 141 | |
| 142 | #define MAX_NICS 8 |
Michael S. Tsirkin | ffe6370 | 2009-06-21 19:51:18 +0300 | [diff] [blame] | 143 | enum { |
| 144 | NIC_NVECTORS_UNSPECIFIED = -1 |
| 145 | }; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 146 | |
| 147 | struct NICInfo { |
| 148 | uint8_t macaddr[6]; |
Mark McLoughlin | 9203f52 | 2009-10-06 12:16:53 +0100 | [diff] [blame] | 149 | char *model; |
| 150 | char *name; |
| 151 | char *devaddr; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 152 | VLANState *vlan; |
Mark McLoughlin | 5869c4d | 2009-10-08 19:58:29 +0100 | [diff] [blame] | 153 | VLANClientState *netdev; |
aliguori | 7697079 | 2009-02-11 15:20:03 +0000 | [diff] [blame] | 154 | int used; |
Glauber Costa | 406c8df | 2009-06-17 09:05:30 -0400 | [diff] [blame] | 155 | int bootable; |
Michael S. Tsirkin | ffe6370 | 2009-06-21 19:51:18 +0300 | [diff] [blame] | 156 | int nvectors; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
| 159 | extern int nb_nics; |
| 160 | extern NICInfo nd_table[MAX_NICS]; |
| 161 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 162 | /* BT HCI info */ |
| 163 | |
| 164 | struct HCIInfo { |
| 165 | int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); |
| 166 | void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 167 | void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 168 | void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 169 | void *opaque; |
| 170 | void (*evt_recv)(void *opaque, const uint8_t *data, int len); |
| 171 | void (*acl_recv)(void *opaque, const uint8_t *data, int len); |
| 172 | }; |
| 173 | |
| 174 | struct HCIInfo *qemu_next_hci(void); |
| 175 | |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 176 | /* from net.c */ |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 177 | extern const char *legacy_tftp_prefix; |
| 178 | extern const char *legacy_bootp_filename; |
| 179 | |
Mark McLoughlin | f6b134a | 2009-10-08 19:58:27 +0100 | [diff] [blame] | 180 | int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev); |
aliguori | 8b13c4a | 2009-02-11 15:20:51 +0000 | [diff] [blame] | 181 | void net_client_uninit(NICInfo *nd); |
Mark McLoughlin | 7f161aa | 2009-10-08 19:58:25 +0100 | [diff] [blame] | 182 | int net_client_parse(QemuOptsList *opts_list, const char *str); |
Mark McLoughlin | dc1c9fe | 2009-10-06 12:17:16 +0100 | [diff] [blame] | 183 | int net_init_clients(void); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 184 | void net_cleanup(void); |
Glauber Costa | 406c8df | 2009-06-17 09:05:30 -0400 | [diff] [blame] | 185 | void net_set_boot_mask(int boot_mask); |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 186 | void net_host_device_add(Monitor *mon, const QDict *qdict); |
| 187 | void net_host_device_remove(Monitor *mon, const QDict *qdict); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 188 | |
aurel32 | f54825c | 2008-12-18 22:43:48 +0000 | [diff] [blame] | 189 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
| 190 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" |
| 191 | #ifdef __sun__ |
| 192 | #define SMBD_COMMAND "/usr/sfw/sbin/smbd" |
| 193 | #else |
| 194 | #define SMBD_COMMAND "/usr/sbin/smbd" |
| 195 | #endif |
| 196 | |
Gerd Hoffmann | ed16ab5 | 2009-10-21 15:25:26 +0200 | [diff] [blame] | 197 | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); |
Paul Brook | 9d07d75 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 198 | |
Mark McLoughlin | 5281d75 | 2009-10-22 17:49:07 +0100 | [diff] [blame] | 199 | int net_handle_fd_param(Monitor *mon, const char *param); |
| 200 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 201 | #endif |