Statistics
| Branch: | Revision:

root / net.h @ 2ef924b4

History | View | Annotate | Download (5.5 kB)

1
#ifndef QEMU_NET_H
2
#define QEMU_NET_H
3

    
4
#include "qemu-queue.h"
5
#include "qemu-common.h"
6
#include "qdict.h"
7
#include "qemu-option.h"
8
#include "net-queue.h"
9

    
10
struct MACAddr {
11
    uint8_t a[6];
12
};
13

    
14
/* VLANs support */
15

    
16
typedef int (NetCanReceive)(VLANClientState *);
17
typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
18
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
19
typedef void (NetCleanup) (VLANClientState *);
20
typedef void (LinkStatusChanged)(VLANClientState *);
21

    
22
struct VLANClientState {
23
    NetReceive *receive;
24
    NetReceiveIOV *receive_iov;
25
    /* Packets may still be sent if this returns zero.  It's used to
26
       rate-limit the slirp code.  */
27
    NetCanReceive *can_receive;
28
    NetCleanup *cleanup;
29
    LinkStatusChanged *link_status_changed;
30
    int link_down;
31
    void *opaque;
32
    QTAILQ_ENTRY(VLANClientState) next;
33
    struct VLANState *vlan;
34
    VLANClientState *peer;
35
    NetQueue *send_queue;
36
    char *model;
37
    char *name;
38
    char info_str[256];
39
};
40

    
41
struct VLANState {
42
    int id;
43
    QTAILQ_HEAD(, VLANClientState) clients;
44
    QTAILQ_ENTRY(VLANState) next;
45
    unsigned int nb_guest_devs, nb_host_devs;
46
    NetQueue *send_queue;
47
};
48

    
49
VLANState *qemu_find_vlan(int id, int allocate);
50
VLANClientState *qemu_find_netdev(const char *id);
51
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
52
                                      VLANClientState *peer,
53
                                      const char *model,
54
                                      const char *name,
55
                                      NetCanReceive *can_receive,
56
                                      NetReceive *receive,
57
                                      NetReceiveIOV *receive_iov,
58
                                      NetCleanup *cleanup,
59
                                      void *opaque);
60
void qemu_del_vlan_client(VLANClientState *vc);
61
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
62
int qemu_can_send_packet(VLANClientState *vc);
63
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
64
                          int iovcnt);
65
ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
66
                                int iovcnt, NetPacketSent *sent_cb);
67
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
68
ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
69
                               int size, NetPacketSent *sent_cb);
70
void qemu_purge_queued_packets(VLANClientState *vc);
71
void qemu_flush_queued_packets(VLANClientState *vc);
72
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
73
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
74
int qemu_show_nic_models(const char *arg, const char *const *models);
75
void qemu_check_nic_model(NICInfo *nd, const char *model);
76
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
77
                        const char *default_model);
78

    
79
void do_info_network(Monitor *mon);
80
void do_set_link(Monitor *mon, const QDict *qdict);
81

    
82
void do_info_usernet(Monitor *mon);
83

    
84
/* NIC info */
85

    
86
#define MAX_NICS 8
87
enum {
88
        NIC_NVECTORS_UNSPECIFIED = -1
89
};
90

    
91
struct NICInfo {
92
    uint8_t macaddr[6];
93
    char *model;
94
    char *name;
95
    char *devaddr;
96
    VLANState *vlan;
97
    VLANClientState *netdev;
98
    VLANClientState *vc;
99
    void *private;
100
    int used;
101
    int bootable;
102
    int nvectors;
103
};
104

    
105
extern int nb_nics;
106
extern NICInfo nd_table[MAX_NICS];
107

    
108
/* BT HCI info */
109

    
110
struct HCIInfo {
111
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
112
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
113
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
114
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
115
    void *opaque;
116
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
117
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
118
};
119

    
120
struct HCIInfo *qemu_next_hci(void);
121

    
122
/* checksumming functions (net-checksum.c) */
123
uint32_t net_checksum_add(int len, uint8_t *buf);
124
uint16_t net_checksum_finish(uint32_t sum);
125
uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
126
                             uint8_t *addrs, uint8_t *buf);
127
void net_checksum_calculate(uint8_t *data, int length);
128

    
129
/* from net.c */
130
extern const char *legacy_tftp_prefix;
131
extern const char *legacy_bootp_filename;
132

    
133
int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
134
void net_client_uninit(NICInfo *nd);
135
int net_client_parse(QemuOptsList *opts_list, const char *str);
136
int net_init_clients(void);
137
int net_slirp_smb(const char *exported_dir);
138
void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
139
void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
140
int net_slirp_redir(const char *redir_str);
141
void net_cleanup(void);
142
void net_set_boot_mask(int boot_mask);
143
void net_host_device_add(Monitor *mon, const QDict *qdict);
144
void net_host_device_remove(Monitor *mon, const QDict *qdict);
145

    
146
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
147
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
148
#ifdef __sun__
149
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
150
#else
151
#define SMBD_COMMAND "/usr/sbin/smbd"
152
#endif
153

    
154
void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
155
VLANClientState *qdev_get_vlan_client(DeviceState *dev,
156
                                      NetCanReceive *can_receive,
157
                                      NetReceive *receive,
158
                                      NetReceiveIOV *receive_iov,
159
                                      NetCleanup *cleanup,
160
                                      void *opaque);
161

    
162
#endif