pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 1 | #ifndef QEMU_NET_H |
| 2 | #define QEMU_NET_H |
| 3 | |
Jan Kiszka | 9da4318 | 2009-08-26 12:47:04 +0200 | [diff] [blame] | 4 | #include "sys-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" |
aliguori | fbe78f4 | 2008-12-17 19:13:11 +0000 | [diff] [blame] | 7 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 8 | /* VLANs support */ |
| 9 | |
| 10 | typedef struct VLANClientState VLANClientState; |
| 11 | |
Mark McLoughlin | e3f5ec2 | 2009-05-18 13:33:03 +0100 | [diff] [blame] | 12 | typedef int (NetCanReceive)(VLANClientState *); |
Mark McLoughlin | 4f1c942 | 2009-05-18 13:40:55 +0100 | [diff] [blame] | 13 | typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t); |
Mark McLoughlin | e3f5ec2 | 2009-05-18 13:33:03 +0100 | [diff] [blame] | 14 | typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int); |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 15 | typedef void (NetCleanup) (VLANClientState *); |
aliguori | 34b25ca | 2009-01-08 19:45:03 +0000 | [diff] [blame] | 16 | typedef void (LinkStatusChanged)(VLANClientState *); |
| 17 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 18 | struct VLANClientState { |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 19 | NetReceive *receive; |
| 20 | NetReceiveIOV *receive_iov; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 21 | /* Packets may still be sent if this returns zero. It's used to |
| 22 | rate-limit the slirp code. */ |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 23 | NetCanReceive *can_receive; |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 24 | NetCleanup *cleanup; |
aliguori | 34b25ca | 2009-01-08 19:45:03 +0000 | [diff] [blame] | 25 | LinkStatusChanged *link_status_changed; |
aliguori | 436e5e5 | 2009-01-08 19:44:06 +0000 | [diff] [blame] | 26 | int link_down; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 27 | void *opaque; |
| 28 | struct VLANClientState *next; |
| 29 | struct VLANState *vlan; |
aliguori | bf38c1a | 2009-01-07 17:42:25 +0000 | [diff] [blame] | 30 | char *model; |
aliguori | 676cff2 | 2009-01-07 17:43:44 +0000 | [diff] [blame] | 31 | char *name; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 32 | char info_str[256]; |
| 33 | }; |
| 34 | |
aliguori | 764a4d1 | 2009-04-21 19:56:41 +0000 | [diff] [blame] | 35 | typedef struct VLANPacket VLANPacket; |
| 36 | |
Mark McLoughlin | 783527a | 2009-06-18 18:21:35 +0100 | [diff] [blame] | 37 | typedef void (NetPacketSent) (VLANClientState *, ssize_t); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 38 | |
aliguori | 764a4d1 | 2009-04-21 19:56:41 +0000 | [diff] [blame] | 39 | struct VLANPacket { |
Jan Kiszka | 9da4318 | 2009-08-26 12:47:04 +0200 | [diff] [blame] | 40 | TAILQ_ENTRY(VLANPacket) entry; |
aliguori | 764a4d1 | 2009-04-21 19:56:41 +0000 | [diff] [blame] | 41 | VLANClientState *sender; |
| 42 | int size; |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 43 | NetPacketSent *sent_cb; |
aliguori | 764a4d1 | 2009-04-21 19:56:41 +0000 | [diff] [blame] | 44 | uint8_t data[0]; |
| 45 | }; |
| 46 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 47 | struct VLANState { |
| 48 | int id; |
| 49 | VLANClientState *first_client; |
| 50 | struct VLANState *next; |
| 51 | unsigned int nb_guest_devs, nb_host_devs; |
Jan Kiszka | 9da4318 | 2009-08-26 12:47:04 +0200 | [diff] [blame] | 52 | TAILQ_HEAD(send_queue, VLANPacket) send_queue; |
aliguori | 764a4d1 | 2009-04-21 19:56:41 +0000 | [diff] [blame] | 53 | int delivering; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 54 | }; |
| 55 | |
Jan Kiszka | 1a60952 | 2009-06-24 14:42:31 +0200 | [diff] [blame] | 56 | VLANState *qemu_find_vlan(int id, int allocate); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 57 | VLANClientState *qemu_new_vlan_client(VLANState *vlan, |
aliguori | bf38c1a | 2009-01-07 17:42:25 +0000 | [diff] [blame] | 58 | const char *model, |
aliguori | 7a9f6e4 | 2009-01-07 17:48:51 +0000 | [diff] [blame] | 59 | const char *name, |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 60 | NetCanReceive *can_receive, |
| 61 | NetReceive *receive, |
| 62 | NetReceiveIOV *receive_iov, |
aliguori | b946a15 | 2009-04-17 17:11:08 +0000 | [diff] [blame] | 63 | NetCleanup *cleanup, |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 64 | void *opaque); |
balrog | dcf414d | 2008-07-17 21:00:05 +0000 | [diff] [blame] | 65 | void qemu_del_vlan_client(VLANClientState *vc); |
aliguori | 8b13c4a | 2009-02-11 15:20:51 +0000 | [diff] [blame] | 66 | VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 67 | int qemu_can_send_packet(VLANClientState *vc); |
aliguori | fbe78f4 | 2008-12-17 19:13:11 +0000 | [diff] [blame] | 68 | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
| 69 | int iovcnt); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 70 | ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, |
| 71 | int iovcnt, NetPacketSent *sent_cb); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 72 | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 73 | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf, |
| 74 | int size, NetPacketSent *sent_cb); |
Mark McLoughlin | 8cad551 | 2009-06-18 18:21:29 +0100 | [diff] [blame] | 75 | void qemu_purge_queued_packets(VLANClientState *vc); |
Mark McLoughlin | f3b6c7f | 2009-04-29 12:15:26 +0100 | [diff] [blame] | 76 | void qemu_flush_queued_packets(VLANClientState *vc); |
aliguori | 7cb7434b | 2009-01-07 17:46:21 +0000 | [diff] [blame] | 77 | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
aliguori | d07f22c | 2009-01-13 19:03:57 +0000 | [diff] [blame] | 78 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
| 79 | void qemu_check_nic_model_list(NICInfo *nd, const char * const *models, |
| 80 | const char *default_model); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 81 | void qemu_handler_true(void *opaque); |
| 82 | |
aliguori | 376253e | 2009-03-05 23:01:23 +0000 | [diff] [blame] | 83 | void do_info_network(Monitor *mon); |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 84 | void do_set_link(Monitor *mon, const QDict *qdict); |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 85 | |
Jan Kiszka | 6dbe553 | 2009-06-24 14:42:29 +0200 | [diff] [blame] | 86 | void do_info_usernet(Monitor *mon); |
| 87 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 88 | /* NIC info */ |
| 89 | |
| 90 | #define MAX_NICS 8 |
Michael S. Tsirkin | ffe6370 | 2009-06-21 19:51:18 +0300 | [diff] [blame] | 91 | enum { |
| 92 | NIC_NVECTORS_UNSPECIFIED = -1 |
| 93 | }; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 94 | |
| 95 | struct NICInfo { |
| 96 | uint8_t macaddr[6]; |
| 97 | const char *model; |
aliguori | 7a9f6e4 | 2009-01-07 17:48:51 +0000 | [diff] [blame] | 98 | const char *name; |
Markus Armbruster | 5607c38 | 2009-06-18 15:14:08 +0200 | [diff] [blame] | 99 | const char *devaddr; |
Gerd Hoffmann | eb54b6d | 2009-07-15 13:43:35 +0200 | [diff] [blame] | 100 | const char *id; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 101 | VLANState *vlan; |
Mark McLoughlin | ae50b27 | 2009-07-01 16:46:38 +0100 | [diff] [blame] | 102 | VLANClientState *vc; |
aliguori | 72da420 | 2009-02-11 15:19:52 +0000 | [diff] [blame] | 103 | void *private; |
aliguori | 7697079 | 2009-02-11 15:20:03 +0000 | [diff] [blame] | 104 | int used; |
Glauber Costa | 406c8df | 2009-06-17 09:05:30 -0400 | [diff] [blame] | 105 | int bootable; |
Michael S. Tsirkin | ffe6370 | 2009-06-21 19:51:18 +0300 | [diff] [blame] | 106 | int nvectors; |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | extern int nb_nics; |
| 110 | extern NICInfo nd_table[MAX_NICS]; |
| 111 | |
balrog | 1ae26a1 | 2008-09-28 23:19:47 +0000 | [diff] [blame] | 112 | /* BT HCI info */ |
| 113 | |
| 114 | struct HCIInfo { |
| 115 | int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); |
| 116 | void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 117 | void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 118 | void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
| 119 | void *opaque; |
| 120 | void (*evt_recv)(void *opaque, const uint8_t *data, int len); |
| 121 | void (*acl_recv)(void *opaque, const uint8_t *data, int len); |
| 122 | }; |
| 123 | |
| 124 | struct HCIInfo *qemu_next_hci(void); |
| 125 | |
aliguori | 48c6436 | 2008-07-29 19:40:04 +0000 | [diff] [blame] | 126 | /* checksumming functions (net-checksum.c) */ |
| 127 | uint32_t net_checksum_add(int len, uint8_t *buf); |
| 128 | uint16_t net_checksum_finish(uint32_t sum); |
| 129 | uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto, |
| 130 | uint8_t *addrs, uint8_t *buf); |
| 131 | void net_checksum_calculate(uint8_t *data, int length); |
| 132 | |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 133 | /* from net.c */ |
Jan Kiszka | ad196a9 | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 134 | extern const char *legacy_tftp_prefix; |
| 135 | extern const char *legacy_bootp_filename; |
| 136 | |
Jan Kiszka | 10ae5a7 | 2009-05-08 12:34:18 +0200 | [diff] [blame] | 137 | int net_client_init(Monitor *mon, const char *device, const char *p); |
aliguori | 8b13c4a | 2009-02-11 15:20:51 +0000 | [diff] [blame] | 138 | void net_client_uninit(NICInfo *nd); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 139 | int net_client_parse(const char *str); |
| 140 | void net_slirp_smb(const char *exported_dir); |
Luiz Capitulino | 1d4daa9 | 2009-08-28 15:27:15 -0300 | [diff] [blame] | 141 | void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict); |
| 142 | void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict); |
Jan Kiszka | f3546de | 2009-06-24 14:42:28 +0200 | [diff] [blame] | 143 | void net_slirp_redir(const char *redir_str); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 144 | void net_cleanup(void); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 145 | void net_client_check(void); |
Glauber Costa | 406c8df | 2009-06-17 09:05:30 -0400 | [diff] [blame] | 146 | void net_set_boot_mask(int boot_mask); |
Luiz Capitulino | f18c16d | 2009-08-28 15:27:14 -0300 | [diff] [blame] | 147 | void net_host_device_add(Monitor *mon, const QDict *qdict); |
| 148 | void net_host_device_remove(Monitor *mon, const QDict *qdict); |
aliguori | 63a01ef | 2008-10-31 19:10:00 +0000 | [diff] [blame] | 149 | |
aurel32 | f54825c | 2008-12-18 22:43:48 +0000 | [diff] [blame] | 150 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
| 151 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" |
| 152 | #ifdef __sun__ |
| 153 | #define SMBD_COMMAND "/usr/sfw/sbin/smbd" |
| 154 | #else |
| 155 | #define SMBD_COMMAND "/usr/sbin/smbd" |
| 156 | #endif |
| 157 | |
Paul Brook | 9d07d75 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 158 | void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr); |
| 159 | VLANClientState *qdev_get_vlan_client(DeviceState *dev, |
Mark McLoughlin | cda9046 | 2009-05-18 13:13:16 +0100 | [diff] [blame] | 160 | NetCanReceive *can_receive, |
| 161 | NetReceive *receive, |
| 162 | NetReceiveIOV *receive_iov, |
Paul Brook | 9d07d75 | 2009-05-14 22:35:07 +0100 | [diff] [blame] | 163 | NetCleanup *cleanup, |
| 164 | void *opaque); |
| 165 | |
pbrook | 87ecb68 | 2007-11-17 17:14:51 +0000 | [diff] [blame] | 166 | #endif |