Statistics
| Branch: | Revision:

root / net.h @ 250b086e

History | View | Annotate | Download (6.6 kB)

1 87ecb68b pbrook
#ifndef QEMU_NET_H
2 87ecb68b pbrook
#define QEMU_NET_H
3 87ecb68b pbrook
4 72cf2d4f Blue Swirl
#include "qemu-queue.h"
5 fbe78f4f aliguori
#include "qemu-common.h"
6 f18c16de Luiz Capitulino
#include "qdict.h"
7 13cf8f21 Mark McLoughlin
#include "qemu-option.h"
8 e1144d00 Mark McLoughlin
#include "net/queue.h"
9 701a8f76 Paolo Bonzini
#include "vmstate.h"
10 fbe78f4f aliguori
11 76d32cba Gerd Hoffmann
struct MACAddr {
12 76d32cba Gerd Hoffmann
    uint8_t a[6];
13 76d32cba Gerd Hoffmann
};
14 76d32cba Gerd Hoffmann
15 ed16ab5a Gerd Hoffmann
/* qdev nic properties */
16 ed16ab5a Gerd Hoffmann
17 ed16ab5a Gerd Hoffmann
typedef struct NICConf {
18 ed16ab5a Gerd Hoffmann
    MACAddr macaddr;
19 ed16ab5a Gerd Hoffmann
    VLANState *vlan;
20 ed16ab5a Gerd Hoffmann
    VLANClientState *peer;
21 1ca4d09a Gleb Natapov
    int32_t bootindex;
22 ed16ab5a Gerd Hoffmann
} NICConf;
23 ed16ab5a Gerd Hoffmann
24 ed16ab5a Gerd Hoffmann
#define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
25 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
26 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
27 1ca4d09a Gleb Natapov
    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer),                   \
28 1ca4d09a Gleb Natapov
    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
29 ed16ab5a Gerd Hoffmann
30 87ecb68b pbrook
/* VLANs support */
31 87ecb68b pbrook
32 bb6e6364 Mark McLoughlin
typedef enum {
33 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NONE,
34 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NIC,
35 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_USER,
36 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_TAP,
37 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SOCKET,
38 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_VDE,
39 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_DUMP,
40 a7c36ee4 Corey Bryant
    NET_CLIENT_TYPE_BRIDGE,
41 6f7b3b1b Jan Kiszka
42 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_MAX
43 bb6e6364 Mark McLoughlin
} net_client_type;
44 bb6e6364 Mark McLoughlin
45 ceb69615 Michael S. Tsirkin
typedef void (NetPoll)(VLANClientState *, bool enable);
46 e3f5ec2b Mark McLoughlin
typedef int (NetCanReceive)(VLANClientState *);
47 4f1c942b Mark McLoughlin
typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
48 e3f5ec2b Mark McLoughlin
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
49 b946a153 aliguori
typedef void (NetCleanup) (VLANClientState *);
50 34b25ca7 aliguori
typedef void (LinkStatusChanged)(VLANClientState *);
51 34b25ca7 aliguori
52 3ed79cc9 Mark McLoughlin
typedef struct NetClientInfo {
53 3ed79cc9 Mark McLoughlin
    net_client_type type;
54 3ed79cc9 Mark McLoughlin
    size_t size;
55 3ed79cc9 Mark McLoughlin
    NetReceive *receive;
56 3ed79cc9 Mark McLoughlin
    NetReceive *receive_raw;
57 3ed79cc9 Mark McLoughlin
    NetReceiveIOV *receive_iov;
58 3ed79cc9 Mark McLoughlin
    NetCanReceive *can_receive;
59 3ed79cc9 Mark McLoughlin
    NetCleanup *cleanup;
60 3ed79cc9 Mark McLoughlin
    LinkStatusChanged *link_status_changed;
61 ceb69615 Michael S. Tsirkin
    NetPoll *poll;
62 3ed79cc9 Mark McLoughlin
} NetClientInfo;
63 3ed79cc9 Mark McLoughlin
64 87ecb68b pbrook
struct VLANClientState {
65 665a3b07 Mark McLoughlin
    NetClientInfo *info;
66 436e5e53 aliguori
    int link_down;
67 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANClientState) next;
68 87ecb68b pbrook
    struct VLANState *vlan;
69 283c7c63 Mark McLoughlin
    VLANClientState *peer;
70 9a6ecb30 Mark McLoughlin
    NetQueue *send_queue;
71 bf38c1a0 aliguori
    char *model;
72 676cff29 aliguori
    char *name;
73 87ecb68b pbrook
    char info_str[256];
74 893379ef Mark McLoughlin
    unsigned receive_disabled : 1;
75 87ecb68b pbrook
};
76 87ecb68b pbrook
77 ebef2c09 Mark McLoughlin
typedef struct NICState {
78 ebef2c09 Mark McLoughlin
    VLANClientState nc;
79 ebef2c09 Mark McLoughlin
    NICConf *conf;
80 ebef2c09 Mark McLoughlin
    void *opaque;
81 a083a89d Michael S. Tsirkin
    bool peer_deleted;
82 ebef2c09 Mark McLoughlin
} NICState;
83 ebef2c09 Mark McLoughlin
84 87ecb68b pbrook
struct VLANState {
85 87ecb68b pbrook
    int id;
86 5610c3aa Mark McLoughlin
    QTAILQ_HEAD(, VLANClientState) clients;
87 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANState) next;
88 f7105843 Mark McLoughlin
    NetQueue *send_queue;
89 87ecb68b pbrook
};
90 87ecb68b pbrook
91 1a609520 Jan Kiszka
VLANState *qemu_find_vlan(int id, int allocate);
92 2ef924b4 Gerd Hoffmann
VLANClientState *qemu_find_netdev(const char *id);
93 45460d1a Mark McLoughlin
VLANClientState *qemu_new_net_client(NetClientInfo *info,
94 45460d1a Mark McLoughlin
                                     VLANState *vlan,
95 45460d1a Mark McLoughlin
                                     VLANClientState *peer,
96 45460d1a Mark McLoughlin
                                     const char *model,
97 45460d1a Mark McLoughlin
                                     const char *name);
98 ebef2c09 Mark McLoughlin
NICState *qemu_new_nic(NetClientInfo *info,
99 ebef2c09 Mark McLoughlin
                       NICConf *conf,
100 ebef2c09 Mark McLoughlin
                       const char *model,
101 ebef2c09 Mark McLoughlin
                       const char *name,
102 ebef2c09 Mark McLoughlin
                       void *opaque);
103 dcf414d6 balrog
void qemu_del_vlan_client(VLANClientState *vc);
104 68ac40d2 Mark McLoughlin
VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
105 68ac40d2 Mark McLoughlin
                                               const char *client_str);
106 57f9ef17 Mark McLoughlin
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
107 57f9ef17 Mark McLoughlin
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
108 87ecb68b pbrook
int qemu_can_send_packet(VLANClientState *vc);
109 fbe78f4f aliguori
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
110 fbe78f4f aliguori
                          int iovcnt);
111 f3b6c7fc Mark McLoughlin
ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
112 f3b6c7fc Mark McLoughlin
                                int iovcnt, NetPacketSent *sent_cb);
113 87ecb68b pbrook
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
114 ca77d175 Mark McLoughlin
ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size);
115 f3b6c7fc Mark McLoughlin
ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
116 f3b6c7fc Mark McLoughlin
                               int size, NetPacketSent *sent_cb);
117 8cad5516 Mark McLoughlin
void qemu_purge_queued_packets(VLANClientState *vc);
118 f3b6c7fc Mark McLoughlin
void qemu_flush_queued_packets(VLANClientState *vc);
119 7cb7434b aliguori
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
120 76d32cba Gerd Hoffmann
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
121 07caea31 Markus Armbruster
int qemu_show_nic_models(const char *arg, const char *const *models);
122 d07f22c5 aliguori
void qemu_check_nic_model(NICInfo *nd, const char *model);
123 07caea31 Markus Armbruster
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
124 07caea31 Markus Armbruster
                        const char *default_model);
125 87ecb68b pbrook
126 376253ec aliguori
void do_info_network(Monitor *mon);
127 87ecb68b pbrook
128 87ecb68b pbrook
/* NIC info */
129 87ecb68b pbrook
130 87ecb68b pbrook
#define MAX_NICS 8
131 87ecb68b pbrook
132 87ecb68b pbrook
struct NICInfo {
133 6eed1856 Jan Kiszka
    MACAddr macaddr;
134 9203f520 Mark McLoughlin
    char *model;
135 9203f520 Mark McLoughlin
    char *name;
136 9203f520 Mark McLoughlin
    char *devaddr;
137 87ecb68b pbrook
    VLANState *vlan;
138 5869c4d5 Mark McLoughlin
    VLANClientState *netdev;
139 48e2faf2 Peter Maydell
    int used;         /* is this slot in nd_table[] being used? */
140 48e2faf2 Peter Maydell
    int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
141 ffe6370c Michael S. Tsirkin
    int nvectors;
142 87ecb68b pbrook
};
143 87ecb68b pbrook
144 87ecb68b pbrook
extern int nb_nics;
145 87ecb68b pbrook
extern NICInfo nd_table[MAX_NICS];
146 cb4522cc Gerd Hoffmann
extern int default_net;
147 87ecb68b pbrook
148 1ae26a18 balrog
/* BT HCI info */
149 1ae26a18 balrog
150 1ae26a18 balrog
struct HCIInfo {
151 1ae26a18 balrog
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
152 1ae26a18 balrog
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
153 1ae26a18 balrog
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
154 1ae26a18 balrog
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
155 1ae26a18 balrog
    void *opaque;
156 1ae26a18 balrog
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
157 1ae26a18 balrog
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
158 1ae26a18 balrog
};
159 1ae26a18 balrog
160 1ae26a18 balrog
struct HCIInfo *qemu_next_hci(void);
161 1ae26a18 balrog
162 63a01ef8 aliguori
/* from net.c */
163 ad196a9d Jan Kiszka
extern const char *legacy_tftp_prefix;
164 ad196a9d Jan Kiszka
extern const char *legacy_bootp_filename;
165 ad196a9d Jan Kiszka
166 f6b134ac Mark McLoughlin
int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
167 7f161aae Mark McLoughlin
int net_client_parse(QemuOptsList *opts_list, const char *str);
168 dc1c9fe8 Mark McLoughlin
int net_init_clients(void);
169 668680f7 Markus Armbruster
void net_check_clients(void);
170 63a01ef8 aliguori
void net_cleanup(void);
171 f18c16de Luiz Capitulino
void net_host_device_add(Monitor *mon, const QDict *qdict);
172 f18c16de Luiz Capitulino
void net_host_device_remove(Monitor *mon, const QDict *qdict);
173 ae82d324 Markus Armbruster
int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
174 ae82d324 Markus Armbruster
int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
175 63a01ef8 aliguori
176 f54825cc aurel32
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
177 f54825cc aurel32
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
178 a7c36ee4 Corey Bryant
#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
179 a7c36ee4 Corey Bryant
#define DEFAULT_BRIDGE_INTERFACE "br0"
180 f54825cc aurel32
181 ed16ab5a Gerd Hoffmann
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
182 9d07d757 Paul Brook
183 5281d757 Mark McLoughlin
int net_handle_fd_param(Monitor *mon, const char *param);
184 5281d757 Mark McLoughlin
185 701a8f76 Paolo Bonzini
#define vmstate_offset_macaddr(_state, _field)                       \
186 701a8f76 Paolo Bonzini
    vmstate_offset_array(_state, _field.a, uint8_t,                \
187 701a8f76 Paolo Bonzini
                         sizeof(typeof_field(_state, _field)))
188 701a8f76 Paolo Bonzini
189 701a8f76 Paolo Bonzini
#define VMSTATE_MACADDR(_field, _state) {                            \
190 701a8f76 Paolo Bonzini
    .name       = (stringify(_field)),                               \
191 701a8f76 Paolo Bonzini
    .size       = sizeof(MACAddr),                                   \
192 701a8f76 Paolo Bonzini
    .info       = &vmstate_info_buffer,                              \
193 701a8f76 Paolo Bonzini
    .flags      = VMS_BUFFER,                                        \
194 701a8f76 Paolo Bonzini
    .offset     = vmstate_offset_macaddr(_state, _field),            \
195 701a8f76 Paolo Bonzini
}
196 701a8f76 Paolo Bonzini
197 87ecb68b pbrook
#endif