Statistics
| Branch: | Revision:

root / net.h @ 0834c9ea

History | View | Annotate | Download (6.5 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 2be64a68 Laszlo Ersek
#include "qapi-types.h"
11 fbe78f4f aliguori
12 76d32cba Gerd Hoffmann
struct MACAddr {
13 76d32cba Gerd Hoffmann
    uint8_t a[6];
14 76d32cba Gerd Hoffmann
};
15 76d32cba Gerd Hoffmann
16 ed16ab5a Gerd Hoffmann
/* qdev nic properties */
17 ed16ab5a Gerd Hoffmann
18 ed16ab5a Gerd Hoffmann
typedef struct NICConf {
19 ed16ab5a Gerd Hoffmann
    MACAddr macaddr;
20 4e68f7a0 Stefan Hajnoczi
    NetClientState *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 606c10e2 Zhi Yong Wu
    DEFINE_PROP_VLAN("vlan",     _state, _conf.peer),                   \
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 4e68f7a0 Stefan Hajnoczi
/* Net clients */
31 87ecb68b pbrook
32 4e68f7a0 Stefan Hajnoczi
typedef void (NetPoll)(NetClientState *, bool enable);
33 4e68f7a0 Stefan Hajnoczi
typedef int (NetCanReceive)(NetClientState *);
34 4e68f7a0 Stefan Hajnoczi
typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
35 4e68f7a0 Stefan Hajnoczi
typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
36 4e68f7a0 Stefan Hajnoczi
typedef void (NetCleanup) (NetClientState *);
37 4e68f7a0 Stefan Hajnoczi
typedef void (LinkStatusChanged)(NetClientState *);
38 34b25ca7 aliguori
39 3ed79cc9 Mark McLoughlin
typedef struct NetClientInfo {
40 2be64a68 Laszlo Ersek
    NetClientOptionsKind type;
41 3ed79cc9 Mark McLoughlin
    size_t size;
42 3ed79cc9 Mark McLoughlin
    NetReceive *receive;
43 3ed79cc9 Mark McLoughlin
    NetReceive *receive_raw;
44 3ed79cc9 Mark McLoughlin
    NetReceiveIOV *receive_iov;
45 3ed79cc9 Mark McLoughlin
    NetCanReceive *can_receive;
46 3ed79cc9 Mark McLoughlin
    NetCleanup *cleanup;
47 3ed79cc9 Mark McLoughlin
    LinkStatusChanged *link_status_changed;
48 ceb69615 Michael S. Tsirkin
    NetPoll *poll;
49 3ed79cc9 Mark McLoughlin
} NetClientInfo;
50 3ed79cc9 Mark McLoughlin
51 4e68f7a0 Stefan Hajnoczi
struct NetClientState {
52 665a3b07 Mark McLoughlin
    NetClientInfo *info;
53 436e5e53 aliguori
    int link_down;
54 4e68f7a0 Stefan Hajnoczi
    QTAILQ_ENTRY(NetClientState) next;
55 4e68f7a0 Stefan Hajnoczi
    NetClientState *peer;
56 9a6ecb30 Mark McLoughlin
    NetQueue *send_queue;
57 bf38c1a0 aliguori
    char *model;
58 676cff29 aliguori
    char *name;
59 87ecb68b pbrook
    char info_str[256];
60 893379ef Mark McLoughlin
    unsigned receive_disabled : 1;
61 87ecb68b pbrook
};
62 87ecb68b pbrook
63 ebef2c09 Mark McLoughlin
typedef struct NICState {
64 4e68f7a0 Stefan Hajnoczi
    NetClientState nc;
65 ebef2c09 Mark McLoughlin
    NICConf *conf;
66 ebef2c09 Mark McLoughlin
    void *opaque;
67 a083a89d Michael S. Tsirkin
    bool peer_deleted;
68 ebef2c09 Mark McLoughlin
} NICState;
69 ebef2c09 Mark McLoughlin
70 4e68f7a0 Stefan Hajnoczi
NetClientState *qemu_find_netdev(const char *id);
71 4e68f7a0 Stefan Hajnoczi
NetClientState *qemu_new_net_client(NetClientInfo *info,
72 4e68f7a0 Stefan Hajnoczi
                                    NetClientState *peer,
73 4e68f7a0 Stefan Hajnoczi
                                    const char *model,
74 4e68f7a0 Stefan Hajnoczi
                                    const char *name);
75 ebef2c09 Mark McLoughlin
NICState *qemu_new_nic(NetClientInfo *info,
76 ebef2c09 Mark McLoughlin
                       NICConf *conf,
77 ebef2c09 Mark McLoughlin
                       const char *model,
78 ebef2c09 Mark McLoughlin
                       const char *name,
79 ebef2c09 Mark McLoughlin
                       void *opaque);
80 b20c6b9e Stefan Hajnoczi
void qemu_del_net_client(NetClientState *nc);
81 4e68f7a0 Stefan Hajnoczi
NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
82 4e68f7a0 Stefan Hajnoczi
                                              const char *client_str);
83 57f9ef17 Mark McLoughlin
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
84 57f9ef17 Mark McLoughlin
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
85 35277d14 Stefan Hajnoczi
int qemu_can_send_packet(NetClientState *nc);
86 35277d14 Stefan Hajnoczi
ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
87 fbe78f4f aliguori
                          int iovcnt);
88 35277d14 Stefan Hajnoczi
ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
89 f3b6c7fc Mark McLoughlin
                                int iovcnt, NetPacketSent *sent_cb);
90 35277d14 Stefan Hajnoczi
void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
91 35277d14 Stefan Hajnoczi
ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
92 35277d14 Stefan Hajnoczi
ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
93 f3b6c7fc Mark McLoughlin
                               int size, NetPacketSent *sent_cb);
94 35277d14 Stefan Hajnoczi
void qemu_purge_queued_packets(NetClientState *nc);
95 35277d14 Stefan Hajnoczi
void qemu_flush_queued_packets(NetClientState *nc);
96 35277d14 Stefan Hajnoczi
void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
97 76d32cba Gerd Hoffmann
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
98 07caea31 Markus Armbruster
int qemu_show_nic_models(const char *arg, const char *const *models);
99 d07f22c5 aliguori
void qemu_check_nic_model(NICInfo *nd, const char *model);
100 07caea31 Markus Armbruster
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
101 07caea31 Markus Armbruster
                        const char *default_model);
102 87ecb68b pbrook
103 86a77c38 Zhi Yong Wu
ssize_t qemu_deliver_packet(NetClientState *sender,
104 86a77c38 Zhi Yong Wu
                            unsigned flags,
105 86a77c38 Zhi Yong Wu
                            const uint8_t *data,
106 86a77c38 Zhi Yong Wu
                            size_t size,
107 86a77c38 Zhi Yong Wu
                            void *opaque);
108 86a77c38 Zhi Yong Wu
ssize_t qemu_deliver_packet_iov(NetClientState *sender,
109 86a77c38 Zhi Yong Wu
                            unsigned flags,
110 86a77c38 Zhi Yong Wu
                            const struct iovec *iov,
111 86a77c38 Zhi Yong Wu
                            int iovcnt,
112 86a77c38 Zhi Yong Wu
                            void *opaque);
113 86a77c38 Zhi Yong Wu
114 1a859593 Zhi Yong Wu
void print_net_client(Monitor *mon, NetClientState *nc);
115 376253ec aliguori
void do_info_network(Monitor *mon);
116 87ecb68b pbrook
117 87ecb68b pbrook
/* NIC info */
118 87ecb68b pbrook
119 87ecb68b pbrook
#define MAX_NICS 8
120 87ecb68b pbrook
121 87ecb68b pbrook
struct NICInfo {
122 6eed1856 Jan Kiszka
    MACAddr macaddr;
123 9203f520 Mark McLoughlin
    char *model;
124 9203f520 Mark McLoughlin
    char *name;
125 9203f520 Mark McLoughlin
    char *devaddr;
126 4e68f7a0 Stefan Hajnoczi
    NetClientState *netdev;
127 48e2faf2 Peter Maydell
    int used;         /* is this slot in nd_table[] being used? */
128 48e2faf2 Peter Maydell
    int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
129 ffe6370c Michael S. Tsirkin
    int nvectors;
130 87ecb68b pbrook
};
131 87ecb68b pbrook
132 87ecb68b pbrook
extern int nb_nics;
133 87ecb68b pbrook
extern NICInfo nd_table[MAX_NICS];
134 cb4522cc Gerd Hoffmann
extern int default_net;
135 87ecb68b pbrook
136 1ae26a18 balrog
/* BT HCI info */
137 1ae26a18 balrog
138 1ae26a18 balrog
struct HCIInfo {
139 1ae26a18 balrog
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
140 1ae26a18 balrog
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
141 1ae26a18 balrog
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
142 1ae26a18 balrog
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
143 1ae26a18 balrog
    void *opaque;
144 1ae26a18 balrog
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
145 1ae26a18 balrog
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
146 1ae26a18 balrog
};
147 1ae26a18 balrog
148 1ae26a18 balrog
struct HCIInfo *qemu_next_hci(void);
149 1ae26a18 balrog
150 63a01ef8 aliguori
/* from net.c */
151 ad196a9d Jan Kiszka
extern const char *legacy_tftp_prefix;
152 ad196a9d Jan Kiszka
extern const char *legacy_bootp_filename;
153 ad196a9d Jan Kiszka
154 4559a1db Luiz Capitulino
int net_client_init(QemuOpts *opts, int is_netdev, Error **errp);
155 7f161aae Mark McLoughlin
int net_client_parse(QemuOptsList *opts_list, const char *str);
156 dc1c9fe8 Mark McLoughlin
int net_init_clients(void);
157 668680f7 Markus Armbruster
void net_check_clients(void);
158 63a01ef8 aliguori
void net_cleanup(void);
159 f18c16de Luiz Capitulino
void net_host_device_add(Monitor *mon, const QDict *qdict);
160 f18c16de Luiz Capitulino
void net_host_device_remove(Monitor *mon, const QDict *qdict);
161 928059a3 Luiz Capitulino
void netdev_add(QemuOpts *opts, Error **errp);
162 928059a3 Luiz Capitulino
int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret);
163 63a01ef8 aliguori
164 f54825cc aurel32
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
165 f54825cc aurel32
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
166 a7c36ee4 Corey Bryant
#define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
167 a7c36ee4 Corey Bryant
#define DEFAULT_BRIDGE_INTERFACE "br0"
168 f54825cc aurel32
169 ed16ab5a Gerd Hoffmann
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
170 9d07d757 Paul Brook
171 7fc8d918 Jason Wang
#define POLYNOMIAL 0x04c11db6
172 7fc8d918 Jason Wang
unsigned compute_mcast_idx(const uint8_t *ep);
173 7fc8d918 Jason Wang
174 701a8f76 Paolo Bonzini
#define vmstate_offset_macaddr(_state, _field)                       \
175 701a8f76 Paolo Bonzini
    vmstate_offset_array(_state, _field.a, uint8_t,                \
176 701a8f76 Paolo Bonzini
                         sizeof(typeof_field(_state, _field)))
177 701a8f76 Paolo Bonzini
178 701a8f76 Paolo Bonzini
#define VMSTATE_MACADDR(_field, _state) {                            \
179 701a8f76 Paolo Bonzini
    .name       = (stringify(_field)),                               \
180 701a8f76 Paolo Bonzini
    .size       = sizeof(MACAddr),                                   \
181 701a8f76 Paolo Bonzini
    .info       = &vmstate_info_buffer,                              \
182 701a8f76 Paolo Bonzini
    .flags      = VMS_BUFFER,                                        \
183 701a8f76 Paolo Bonzini
    .offset     = vmstate_offset_macaddr(_state, _field),            \
184 701a8f76 Paolo Bonzini
}
185 701a8f76 Paolo Bonzini
186 87ecb68b pbrook
#endif