blob: 4d204e06e6a808414d8d73f9be4c9261f09b0b2b [file] [log] [blame]
pbrook87ecb682007-11-17 17:14:51 +00001#ifndef QEMU_NET_H
2#define QEMU_NET_H
3
aliguorifbe78f42008-12-17 19:13:11 +00004#include "qemu-common.h"
5
pbrook87ecb682007-11-17 17:14:51 +00006/* VLANs support */
7
8typedef struct VLANClientState VLANClientState;
9
Mark McLoughlincda90462009-05-18 13:13:16 +010010typedef int (NetCanReceive)(void *);
11typedef void (NetReceive)(void *, const uint8_t *, size_t);
12typedef ssize_t (NetReceiveIOV)(void *, const struct iovec *, int);
aliguorib946a152009-04-17 17:11:08 +000013typedef void (NetCleanup) (VLANClientState *);
aliguori34b25ca2009-01-08 19:45:03 +000014typedef void (LinkStatusChanged)(VLANClientState *);
15
pbrook87ecb682007-11-17 17:14:51 +000016struct VLANClientState {
Mark McLoughlincda90462009-05-18 13:13:16 +010017 NetReceive *receive;
18 NetReceiveIOV *receive_iov;
pbrook87ecb682007-11-17 17:14:51 +000019 /* Packets may still be sent if this returns zero. It's used to
20 rate-limit the slirp code. */
Mark McLoughlincda90462009-05-18 13:13:16 +010021 NetCanReceive *can_receive;
aliguorib946a152009-04-17 17:11:08 +000022 NetCleanup *cleanup;
aliguori34b25ca2009-01-08 19:45:03 +000023 LinkStatusChanged *link_status_changed;
aliguori436e5e52009-01-08 19:44:06 +000024 int link_down;
pbrook87ecb682007-11-17 17:14:51 +000025 void *opaque;
26 struct VLANClientState *next;
27 struct VLANState *vlan;
aliguoribf38c1a2009-01-07 17:42:25 +000028 char *model;
aliguori676cff22009-01-07 17:43:44 +000029 char *name;
pbrook87ecb682007-11-17 17:14:51 +000030 char info_str[256];
31};
32
aliguori764a4d12009-04-21 19:56:41 +000033typedef struct VLANPacket VLANPacket;
34
35struct VLANPacket {
36 struct VLANPacket *next;
37 VLANClientState *sender;
38 int size;
39 uint8_t data[0];
40};
41
pbrook87ecb682007-11-17 17:14:51 +000042struct VLANState {
43 int id;
44 VLANClientState *first_client;
45 struct VLANState *next;
46 unsigned int nb_guest_devs, nb_host_devs;
aliguori764a4d12009-04-21 19:56:41 +000047 VLANPacket *send_queue;
48 int delivering;
pbrook87ecb682007-11-17 17:14:51 +000049};
50
51VLANState *qemu_find_vlan(int id);
52VLANClientState *qemu_new_vlan_client(VLANState *vlan,
aliguoribf38c1a2009-01-07 17:42:25 +000053 const char *model,
aliguori7a9f6e42009-01-07 17:48:51 +000054 const char *name,
Mark McLoughlincda90462009-05-18 13:13:16 +010055 NetCanReceive *can_receive,
56 NetReceive *receive,
57 NetReceiveIOV *receive_iov,
aliguorib946a152009-04-17 17:11:08 +000058 NetCleanup *cleanup,
pbrook87ecb682007-11-17 17:14:51 +000059 void *opaque);
balrogdcf414d2008-07-17 21:00:05 +000060void qemu_del_vlan_client(VLANClientState *vc);
aliguori8b13c4a2009-02-11 15:20:51 +000061VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
pbrook87ecb682007-11-17 17:14:51 +000062int qemu_can_send_packet(VLANClientState *vc);
aliguorifbe78f42008-12-17 19:13:11 +000063ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
64 int iovcnt);
pbrook87ecb682007-11-17 17:14:51 +000065void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
aliguori7cb7434b2009-01-07 17:46:21 +000066void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
aliguorid07f22c2009-01-13 19:03:57 +000067void qemu_check_nic_model(NICInfo *nd, const char *model);
68void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
69 const char *default_model);
pbrook87ecb682007-11-17 17:14:51 +000070void qemu_handler_true(void *opaque);
71
aliguori376253e2009-03-05 23:01:23 +000072void do_info_network(Monitor *mon);
73int do_set_link(Monitor *mon, const char *name, const char *up_or_down);
pbrook87ecb682007-11-17 17:14:51 +000074
75/* NIC info */
76
77#define MAX_NICS 8
78
79struct NICInfo {
80 uint8_t macaddr[6];
81 const char *model;
aliguori7a9f6e42009-01-07 17:48:51 +000082 const char *name;
pbrook87ecb682007-11-17 17:14:51 +000083 VLANState *vlan;
aliguori72da4202009-02-11 15:19:52 +000084 void *private;
aliguori76970792009-02-11 15:20:03 +000085 int used;
pbrook87ecb682007-11-17 17:14:51 +000086};
87
88extern int nb_nics;
89extern NICInfo nd_table[MAX_NICS];
90
balrog1ae26a12008-09-28 23:19:47 +000091/* BT HCI info */
92
93struct HCIInfo {
94 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
95 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
96 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
97 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
98 void *opaque;
99 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
100 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
101};
102
103struct HCIInfo *qemu_next_hci(void);
104
aliguori48c64362008-07-29 19:40:04 +0000105/* checksumming functions (net-checksum.c) */
106uint32_t net_checksum_add(int len, uint8_t *buf);
107uint16_t net_checksum_finish(uint32_t sum);
108uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
109 uint8_t *addrs, uint8_t *buf);
110void net_checksum_calculate(uint8_t *data, int length);
111
aliguori63a01ef2008-10-31 19:10:00 +0000112/* from net.c */
Jan Kiszka10ae5a72009-05-08 12:34:18 +0200113int net_client_init(Monitor *mon, const char *device, const char *p);
aliguori8b13c4a2009-02-11 15:20:51 +0000114void net_client_uninit(NICInfo *nd);
aliguori63a01ef2008-10-31 19:10:00 +0000115int net_client_parse(const char *str);
116void net_slirp_smb(const char *exported_dir);
Alexander Grafc1261d82009-05-26 13:03:26 +0200117void net_slirp_redir(Monitor *mon, const char *redir_str, const char *redir_opt2);
aliguori63a01ef2008-10-31 19:10:00 +0000118void net_cleanup(void);
119int slirp_is_inited(void);
120void net_client_check(void);
aliguori376253e2009-03-05 23:01:23 +0000121void net_host_device_add(Monitor *mon, const char *device, const char *opts);
122void net_host_device_remove(Monitor *mon, int vlan_id, const char *device);
aliguori63a01ef2008-10-31 19:10:00 +0000123
aurel32f54825c2008-12-18 22:43:48 +0000124#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
125#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
126#ifdef __sun__
127#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
128#else
129#define SMBD_COMMAND "/usr/sbin/smbd"
130#endif
131
Paul Brook9d07d752009-05-14 22:35:07 +0100132void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
133VLANClientState *qdev_get_vlan_client(DeviceState *dev,
Mark McLoughlincda90462009-05-18 13:13:16 +0100134 NetCanReceive *can_receive,
135 NetReceive *receive,
136 NetReceiveIOV *receive_iov,
Paul Brook9d07d752009-05-14 22:35:07 +0100137 NetCleanup *cleanup,
138 void *opaque);
139
pbrook87ecb682007-11-17 17:14:51 +0000140#endif