Statistics
| Branch: | Revision:

root / net.h @ b4bf0a9a

History | View | Annotate | Download (5.7 kB)

1 87ecb68b pbrook
#ifndef QEMU_NET_H
2 87ecb68b pbrook
#define QEMU_NET_H
3 87ecb68b pbrook
4 ceb69615 Michael S. Tsirkin
#include <stdbool.h>
5 72cf2d4f Blue Swirl
#include "qemu-queue.h"
6 fbe78f4f aliguori
#include "qemu-common.h"
7 f18c16de Luiz Capitulino
#include "qdict.h"
8 13cf8f21 Mark McLoughlin
#include "qemu-option.h"
9 e1144d00 Mark McLoughlin
#include "net/queue.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 ed16ab5a Gerd Hoffmann
} NICConf;
22 ed16ab5a Gerd Hoffmann
23 ed16ab5a Gerd Hoffmann
#define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
24 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
25 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
26 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
27 ed16ab5a Gerd Hoffmann
28 87ecb68b pbrook
/* VLANs support */
29 87ecb68b pbrook
30 bb6e6364 Mark McLoughlin
typedef enum {
31 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NONE,
32 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NIC,
33 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SLIRP,
34 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_TAP,
35 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SOCKET,
36 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_VDE,
37 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_DUMP
38 bb6e6364 Mark McLoughlin
} net_client_type;
39 bb6e6364 Mark McLoughlin
40 ceb69615 Michael S. Tsirkin
typedef void (NetPoll)(VLANClientState *, bool enable);
41 e3f5ec2b Mark McLoughlin
typedef int (NetCanReceive)(VLANClientState *);
42 4f1c942b Mark McLoughlin
typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
43 e3f5ec2b Mark McLoughlin
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
44 b946a153 aliguori
typedef void (NetCleanup) (VLANClientState *);
45 34b25ca7 aliguori
typedef void (LinkStatusChanged)(VLANClientState *);
46 34b25ca7 aliguori
47 3ed79cc9 Mark McLoughlin
typedef struct NetClientInfo {
48 3ed79cc9 Mark McLoughlin
    net_client_type type;
49 3ed79cc9 Mark McLoughlin
    size_t size;
50 3ed79cc9 Mark McLoughlin
    NetReceive *receive;
51 3ed79cc9 Mark McLoughlin
    NetReceive *receive_raw;
52 3ed79cc9 Mark McLoughlin
    NetReceiveIOV *receive_iov;
53 3ed79cc9 Mark McLoughlin
    NetCanReceive *can_receive;
54 3ed79cc9 Mark McLoughlin
    NetCleanup *cleanup;
55 3ed79cc9 Mark McLoughlin
    LinkStatusChanged *link_status_changed;
56 ceb69615 Michael S. Tsirkin
    NetPoll *poll;
57 3ed79cc9 Mark McLoughlin
} NetClientInfo;
58 3ed79cc9 Mark McLoughlin
59 87ecb68b pbrook
struct VLANClientState {
60 665a3b07 Mark McLoughlin
    NetClientInfo *info;
61 436e5e53 aliguori
    int link_down;
62 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANClientState) next;
63 87ecb68b pbrook
    struct VLANState *vlan;
64 283c7c63 Mark McLoughlin
    VLANClientState *peer;
65 9a6ecb30 Mark McLoughlin
    NetQueue *send_queue;
66 bf38c1a0 aliguori
    char *model;
67 676cff29 aliguori
    char *name;
68 87ecb68b pbrook
    char info_str[256];
69 893379ef Mark McLoughlin
    unsigned receive_disabled : 1;
70 87ecb68b pbrook
};
71 87ecb68b pbrook
72 ebef2c09 Mark McLoughlin
typedef struct NICState {
73 ebef2c09 Mark McLoughlin
    VLANClientState nc;
74 ebef2c09 Mark McLoughlin
    NICConf *conf;
75 ebef2c09 Mark McLoughlin
    void *opaque;
76 ebef2c09 Mark McLoughlin
} NICState;
77 ebef2c09 Mark McLoughlin
78 87ecb68b pbrook
struct VLANState {
79 87ecb68b pbrook
    int id;
80 5610c3aa Mark McLoughlin
    QTAILQ_HEAD(, VLANClientState) clients;
81 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANState) next;
82 87ecb68b pbrook
    unsigned int nb_guest_devs, nb_host_devs;
83 f7105843 Mark McLoughlin
    NetQueue *send_queue;
84 87ecb68b pbrook
};
85 87ecb68b pbrook
86 1a609520 Jan Kiszka
VLANState *qemu_find_vlan(int id, int allocate);
87 2ef924b4 Gerd Hoffmann
VLANClientState *qemu_find_netdev(const char *id);
88 45460d1a Mark McLoughlin
VLANClientState *qemu_new_net_client(NetClientInfo *info,
89 45460d1a Mark McLoughlin
                                     VLANState *vlan,
90 45460d1a Mark McLoughlin
                                     VLANClientState *peer,
91 45460d1a Mark McLoughlin
                                     const char *model,
92 45460d1a Mark McLoughlin
                                     const char *name);
93 ebef2c09 Mark McLoughlin
NICState *qemu_new_nic(NetClientInfo *info,
94 ebef2c09 Mark McLoughlin
                       NICConf *conf,
95 ebef2c09 Mark McLoughlin
                       const char *model,
96 ebef2c09 Mark McLoughlin
                       const char *name,
97 ebef2c09 Mark McLoughlin
                       void *opaque);
98 dcf414d6 balrog
void qemu_del_vlan_client(VLANClientState *vc);
99 68ac40d2 Mark McLoughlin
VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
100 68ac40d2 Mark McLoughlin
                                               const char *client_str);
101 57f9ef17 Mark McLoughlin
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
102 57f9ef17 Mark McLoughlin
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
103 87ecb68b pbrook
int qemu_can_send_packet(VLANClientState *vc);
104 fbe78f4f aliguori
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
105 fbe78f4f aliguori
                          int iovcnt);
106 f3b6c7fc Mark McLoughlin
ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
107 f3b6c7fc Mark McLoughlin
                                int iovcnt, NetPacketSent *sent_cb);
108 87ecb68b pbrook
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
109 ca77d175 Mark McLoughlin
ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size);
110 f3b6c7fc Mark McLoughlin
ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
111 f3b6c7fc Mark McLoughlin
                               int size, NetPacketSent *sent_cb);
112 8cad5516 Mark McLoughlin
void qemu_purge_queued_packets(VLANClientState *vc);
113 f3b6c7fc Mark McLoughlin
void qemu_flush_queued_packets(VLANClientState *vc);
114 7cb7434b aliguori
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
115 76d32cba Gerd Hoffmann
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
116 07caea31 Markus Armbruster
int qemu_show_nic_models(const char *arg, const char *const *models);
117 d07f22c5 aliguori
void qemu_check_nic_model(NICInfo *nd, const char *model);
118 07caea31 Markus Armbruster
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
119 07caea31 Markus Armbruster
                        const char *default_model);
120 87ecb68b pbrook
121 376253ec aliguori
void do_info_network(Monitor *mon);
122 f18c16de Luiz Capitulino
void do_set_link(Monitor *mon, const QDict *qdict);
123 87ecb68b pbrook
124 87ecb68b pbrook
/* NIC info */
125 87ecb68b pbrook
126 87ecb68b pbrook
#define MAX_NICS 8
127 ffe6370c Michael S. Tsirkin
enum {
128 ffe6370c Michael S. Tsirkin
        NIC_NVECTORS_UNSPECIFIED = -1
129 ffe6370c Michael S. Tsirkin
};
130 87ecb68b pbrook
131 87ecb68b pbrook
struct NICInfo {
132 87ecb68b pbrook
    uint8_t macaddr[6];
133 9203f520 Mark McLoughlin
    char *model;
134 9203f520 Mark McLoughlin
    char *name;
135 9203f520 Mark McLoughlin
    char *devaddr;
136 87ecb68b pbrook
    VLANState *vlan;
137 5869c4d5 Mark McLoughlin
    VLANClientState *netdev;
138 7697079b aliguori
    int used;
139 406c8df3 Glauber Costa
    int bootable;
140 ffe6370c Michael S. Tsirkin
    int nvectors;
141 87ecb68b pbrook
};
142 87ecb68b pbrook
143 87ecb68b pbrook
extern int nb_nics;
144 87ecb68b pbrook
extern NICInfo nd_table[MAX_NICS];
145 cb4522cc Gerd Hoffmann
extern int default_net;
146 87ecb68b pbrook
147 1ae26a18 balrog
/* BT HCI info */
148 1ae26a18 balrog
149 1ae26a18 balrog
struct HCIInfo {
150 1ae26a18 balrog
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
151 1ae26a18 balrog
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
152 1ae26a18 balrog
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
153 1ae26a18 balrog
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
154 1ae26a18 balrog
    void *opaque;
155 1ae26a18 balrog
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
156 1ae26a18 balrog
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
157 1ae26a18 balrog
};
158 1ae26a18 balrog
159 1ae26a18 balrog
struct HCIInfo *qemu_next_hci(void);
160 1ae26a18 balrog
161 63a01ef8 aliguori
/* from net.c */
162 ad196a9d Jan Kiszka
extern const char *legacy_tftp_prefix;
163 ad196a9d Jan Kiszka
extern const char *legacy_bootp_filename;
164 ad196a9d Jan Kiszka
165 f6b134ac Mark McLoughlin
int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
166 8b13c4a7 aliguori
void net_client_uninit(NICInfo *nd);
167 7f161aae Mark McLoughlin
int net_client_parse(QemuOptsList *opts_list, const char *str);
168 dc1c9fe8 Mark McLoughlin
int net_init_clients(void);
169 63a01ef8 aliguori
void net_cleanup(void);
170 406c8df3 Glauber Costa
void net_set_boot_mask(int boot_mask);
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 63a01ef8 aliguori
174 f54825cc aurel32
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
175 f54825cc aurel32
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
176 f54825cc aurel32
#ifdef __sun__
177 f54825cc aurel32
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
178 f54825cc aurel32
#else
179 f54825cc aurel32
#define SMBD_COMMAND "/usr/sbin/smbd"
180 f54825cc aurel32
#endif
181 f54825cc aurel32
182 ed16ab5a Gerd Hoffmann
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
183 9d07d757 Paul Brook
184 5281d757 Mark McLoughlin
int net_handle_fd_param(Monitor *mon, const char *param);
185 5281d757 Mark McLoughlin
186 87ecb68b pbrook
#endif