00001 #ifndef QEMU_NET_H
00002 #define QEMU_NET_H
00003
00004 #include "qemu-common.h"
00005
00006
00007
00008 typedef ssize_t (IOReadvHandler)(void *, const struct iovec *, int);
00009
00010 typedef struct VLANClientState VLANClientState;
00011
00012 typedef void (NetCleanup) (VLANClientState *);
00013 typedef void (LinkStatusChanged)(VLANClientState *);
00014
00015 struct VLANClientState {
00016 IOReadHandler *fd_read;
00017 IOReadvHandler *fd_readv;
00018
00019
00020 IOCanRWHandler *fd_can_read;
00021 NetCleanup *cleanup;
00022 LinkStatusChanged *link_status_changed;
00023 int link_down;
00024 void *opaque;
00025 struct VLANClientState *next;
00026 struct VLANState *vlan;
00027 char *model;
00028 char *name;
00029 char info_str[256];
00030 };
00031
00032 struct VLANState {
00033 int id;
00034 VLANClientState *first_client;
00035 struct VLANState *next;
00036 unsigned int nb_guest_devs, nb_host_devs;
00037 };
00038
00039 VLANState *qemu_find_vlan(int id);
00040 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
00041 const char *model,
00042 const char *name,
00043 IOReadHandler *fd_read,
00044 IOCanRWHandler *fd_can_read,
00045 NetCleanup *cleanup,
00046 void *opaque);
00047 void qemu_del_vlan_client(VLANClientState *vc);
00048 VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
00049 int qemu_can_send_packet(VLANClientState *vc);
00050 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
00051 int iovcnt);
00052 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
00053 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
00054 void qemu_check_nic_model(NICInfo *nd, const char *model);
00055 void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
00056 const char *default_model);
00057 void qemu_handler_true(void *opaque);
00058
00059 void do_info_network(void);
00060 int do_set_link(const char *name, const char *up_or_down);
00061
00062
00063
00064 #define MAX_NICS 8
00065
00066 struct NICInfo {
00067 uint8_t macaddr[6];
00068 const char *model;
00069 const char *name;
00070 VLANState *vlan;
00071 void *private;
00072 int used;
00073 };
00074
00075 extern int nb_nics;
00076 extern NICInfo nd_table[MAX_NICS];
00077
00078
00079
00080 struct HCIInfo {
00081 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
00082 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
00083 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
00084 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
00085 void *opaque;
00086 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
00087 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
00088 };
00089
00090 struct HCIInfo *qemu_next_hci(void);
00091
00092
00093 uint32_t net_checksum_add(int len, uint8_t *buf);
00094 uint16_t net_checksum_finish(uint32_t sum);
00095 uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
00096 uint8_t *addrs, uint8_t *buf);
00097 void net_checksum_calculate(uint8_t *data, int length);
00098
00099
00100 int net_client_init(const char *device, const char *p);
00101 void net_client_uninit(NICInfo *nd);
00102 int net_client_parse(const char *str);
00103 void net_slirp_smb(const char *exported_dir);
00104 void net_slirp_redir(const char *redir_str);
00105 void net_cleanup(void);
00106 int slirp_is_inited(void);
00107 void net_client_check(void);
00108 void net_host_device_add(const char *device, const char *opts);
00109 void net_host_device_remove(int vlan_id, const char *device);
00110
00111 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
00112 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
00113 #ifdef __sun__
00114 #define SMBD_COMMAND "/usr/sfw/sbin/smbd"
00115 #else
00116 #define SMBD_COMMAND "/usr/sbin/smbd"
00117 #endif
00118
00119 #endif