net.h 3.6 KB
Newer Older
P
pbrook 已提交
1 2 3
#ifndef QEMU_NET_H
#define QEMU_NET_H

A
aliguori 已提交
4 5
#include "qemu-common.h"

P
pbrook 已提交
6 7
/* VLANs support */

A
aliguori 已提交
8 9
typedef ssize_t (IOReadvHandler)(void *, const struct iovec *, int);

P
pbrook 已提交
10 11
typedef struct VLANClientState VLANClientState;

12 13
typedef void (LinkStatusChanged)(VLANClientState *);

P
pbrook 已提交
14 15
struct VLANClientState {
    IOReadHandler *fd_read;
A
aliguori 已提交
16
    IOReadvHandler *fd_readv;
P
pbrook 已提交
17 18 19
    /* Packets may still be sent if this returns zero.  It's used to
       rate-limit the slirp code.  */
    IOCanRWHandler *fd_can_read;
20
    LinkStatusChanged *link_status_changed;
21
    int link_down;
P
pbrook 已提交
22 23 24
    void *opaque;
    struct VLANClientState *next;
    struct VLANState *vlan;
25
    char *model;
26
    char *name;
P
pbrook 已提交
27 28 29 30 31 32 33 34 35 36 37 38
    char info_str[256];
};

struct VLANState {
    int id;
    VLANClientState *first_client;
    struct VLANState *next;
    unsigned int nb_guest_devs, nb_host_devs;
};

VLANState *qemu_find_vlan(int id);
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
39
                                      const char *model,
40
                                      const char *name,
P
pbrook 已提交
41 42 43
                                      IOReadHandler *fd_read,
                                      IOCanRWHandler *fd_can_read,
                                      void *opaque);
44
void qemu_del_vlan_client(VLANClientState *vc);
45
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
P
pbrook 已提交
46
int qemu_can_send_packet(VLANClientState *vc);
A
aliguori 已提交
47 48
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
                          int iovcnt);
P
pbrook 已提交
49
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
50
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
51 52 53
void qemu_check_nic_model(NICInfo *nd, const char *model);
void qemu_check_nic_model_list(NICInfo *nd, const char * const *models,
                               const char *default_model);
P
pbrook 已提交
54 55 56
void qemu_handler_true(void *opaque);

void do_info_network(void);
57
int do_set_link(const char *name, const char *up_or_down);
P
pbrook 已提交
58 59 60 61 62 63 64 65

/* NIC info */

#define MAX_NICS 8

struct NICInfo {
    uint8_t macaddr[6];
    const char *model;
66
    const char *name;
P
pbrook 已提交
67
    VLANState *vlan;
68
    void *private;
69
    int used;
P
pbrook 已提交
70 71 72 73 74
};

extern int nb_nics;
extern NICInfo nd_table[MAX_NICS];

75 76 77 78 79 80 81 82 83 84 85 86 87 88
/* BT HCI info */

struct HCIInfo {
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
    void *opaque;
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
};

struct HCIInfo *qemu_next_hci(void);

89 90 91 92 93 94 95
/* checksumming functions (net-checksum.c) */
uint32_t net_checksum_add(int len, uint8_t *buf);
uint16_t net_checksum_finish(uint32_t sum);
uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
                             uint8_t *addrs, uint8_t *buf);
void net_checksum_calculate(uint8_t *data, int length);

96 97
/* from net.c */
int net_client_init(const char *device, const char *p);
98
void net_client_uninit(NICInfo *nd);
99 100 101 102 103 104
int net_client_parse(const char *str);
void net_slirp_smb(const char *exported_dir);
void net_slirp_redir(const char *redir_str);
void net_cleanup(void);
int slirp_is_inited(void);
void net_client_check(void);
105 106
void net_host_device_add(const char *device, const char *opts);
void net_host_device_remove(int vlan_id, const char *device);
107

108 109 110 111 112 113 114 115
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
#ifdef __sun__
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
#else
#define SMBD_COMMAND "/usr/sbin/smbd"
#endif

P
pbrook 已提交
116
#endif