Statistics
| Branch: | Revision:

root / net.h @ 6f7b3b1b

History | View | Annotate | Download (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 fbe78f4f aliguori
10 76d32cba Gerd Hoffmann
struct MACAddr {
11 76d32cba Gerd Hoffmann
    uint8_t a[6];
12 76d32cba Gerd Hoffmann
};
13 76d32cba Gerd Hoffmann
14 ed16ab5a Gerd Hoffmann
/* qdev nic properties */
15 ed16ab5a Gerd Hoffmann
16 ed16ab5a Gerd Hoffmann
typedef struct NICConf {
17 ed16ab5a Gerd Hoffmann
    MACAddr macaddr;
18 ed16ab5a Gerd Hoffmann
    VLANState *vlan;
19 ed16ab5a Gerd Hoffmann
    VLANClientState *peer;
20 1ca4d09a Gleb Natapov
    int32_t bootindex;
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 1ca4d09a Gleb Natapov
    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer),                   \
27 1ca4d09a Gleb Natapov
    DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1)
28 ed16ab5a Gerd Hoffmann
29 87ecb68b pbrook
/* VLANs support */
30 87ecb68b pbrook
31 bb6e6364 Mark McLoughlin
typedef enum {
32 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NONE,
33 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NIC,
34 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_USER,
35 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_TAP,
36 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SOCKET,
37 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_VDE,
38 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_DUMP,
39 6f7b3b1b Jan Kiszka
40 6f7b3b1b Jan Kiszka
    NET_CLIENT_TYPE_MAX
41 bb6e6364 Mark McLoughlin
} net_client_type;
42 bb6e6364 Mark McLoughlin
43 ceb69615 Michael S. Tsirkin
typedef void (NetPoll)(VLANClientState *, bool enable);
44 e3f5ec2b Mark McLoughlin
typedef int (NetCanReceive)(VLANClientState *);
45 4f1c942b Mark McLoughlin
typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
46 e3f5ec2b Mark McLoughlin
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
47 b946a153 aliguori
typedef void (NetCleanup) (VLANClientState *);
48 34b25ca7 aliguori
typedef void (LinkStatusChanged)(VLANClientState *);
49 34b25ca7 aliguori
50 3ed79cc9 Mark McLoughlin
typedef struct NetClientInfo {
51 3ed79cc9 Mark McLoughlin
    net_client_type type;
52 3ed79cc9 Mark McLoughlin
    size_t size;
53 3ed79cc9 Mark McLoughlin
    NetReceive *receive;
54 3ed79cc9 Mark McLoughlin
    NetReceive *receive_raw;
55 3ed79cc9 Mark McLoughlin
    NetReceiveIOV *receive_iov;
56 3ed79cc9 Mark McLoughlin
    NetCanReceive *can_receive;
57 3ed79cc9 Mark McLoughlin
    NetCleanup *cleanup;
58 3ed79cc9 Mark McLoughlin
    LinkStatusChanged *link_status_changed;
59 ceb69615 Michael S. Tsirkin
    NetPoll *poll;
60 3ed79cc9 Mark McLoughlin
} NetClientInfo;
61 3ed79cc9 Mark McLoughlin
62 87ecb68b pbrook
struct VLANClientState {
63 665a3b07 Mark McLoughlin
    NetClientInfo *info;
64 436e5e53 aliguori
    int link_down;
65 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANClientState) next;
66 87ecb68b pbrook
    struct VLANState *vlan;
67 283c7c63 Mark McLoughlin
    VLANClientState *peer;
68 9a6ecb30 Mark McLoughlin
    NetQueue *send_queue;
69 bf38c1a0 aliguori
    char *model;
70 676cff29 aliguori
    char *name;
71 87ecb68b pbrook
    char info_str[256];
72 893379ef Mark McLoughlin
    unsigned receive_disabled : 1;
73 87ecb68b pbrook
};
74 87ecb68b pbrook
75 ebef2c09 Mark McLoughlin
typedef struct NICState {
76 ebef2c09 Mark McLoughlin
    VLANClientState nc;
77 ebef2c09 Mark McLoughlin
    NICConf *conf;
78 ebef2c09 Mark McLoughlin
    void *opaque;
79 a083a89d Michael S. Tsirkin
    bool peer_deleted;
80 ebef2c09 Mark McLoughlin
} NICState;
81 ebef2c09 Mark McLoughlin
82 87ecb68b pbrook
struct VLANState {
83 87ecb68b pbrook
    int id;
84 5610c3aa Mark McLoughlin
    QTAILQ_HEAD(, VLANClientState) clients;
85 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANState) next;
86 f7105843 Mark McLoughlin
    NetQueue *send_queue;
87 87ecb68b pbrook
};
88 87ecb68b pbrook
89 1a609520 Jan Kiszka
VLANState *qemu_find_vlan(int id, int allocate);
90 2ef924b4 Gerd Hoffmann
VLANClientState *qemu_find_netdev(const char *id);
91 45460d1a Mark McLoughlin
VLANClientState *qemu_new_net_client(NetClientInfo *info,
92 45460d1a Mark McLoughlin
                                     VLANState *vlan,
93 45460d1a Mark McLoughlin
                                     VLANClientState *peer,
94 45460d1a Mark McLoughlin
                                     const char *model,
95 45460d1a Mark McLoughlin
                                     const char *name);
96 ebef2c09 Mark McLoughlin
NICState *qemu_new_nic(NetClientInfo *info,
97 ebef2c09 Mark McLoughlin
                       NICConf *conf,
98 ebef2c09 Mark McLoughlin
                       const char *model,
99 ebef2c09 Mark McLoughlin
                       const char *name,
100 ebef2c09 Mark McLoughlin
                       void *opaque);
101 dcf414d6 balrog
void qemu_del_vlan_client(VLANClientState *vc);
102 68ac40d2 Mark McLoughlin
VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
103 68ac40d2 Mark McLoughlin
                                               const char *client_str);
104 57f9ef17 Mark McLoughlin
typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
105 57f9ef17 Mark McLoughlin
void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
106 87ecb68b pbrook
int qemu_can_send_packet(VLANClientState *vc);
107 fbe78f4f aliguori
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
108 fbe78f4f aliguori
                          int iovcnt);
109 f3b6c7fc Mark McLoughlin
ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
110 f3b6c7fc Mark McLoughlin
                                int iovcnt, NetPacketSent *sent_cb);
111 87ecb68b pbrook
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
112 ca77d175 Mark McLoughlin
ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size);
113 f3b6c7fc Mark McLoughlin
ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
114 f3b6c7fc Mark McLoughlin
                               int size, NetPacketSent *sent_cb);
115 8cad5516 Mark McLoughlin
void qemu_purge_queued_packets(VLANClientState *vc);
116 f3b6c7fc Mark McLoughlin
void qemu_flush_queued_packets(VLANClientState *vc);
117 7cb7434b aliguori
void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
118 76d32cba Gerd Hoffmann
void qemu_macaddr_default_if_unset(MACAddr *macaddr);
119 07caea31 Markus Armbruster
int qemu_show_nic_models(const char *arg, const char *const *models);
120 d07f22c5 aliguori
void qemu_check_nic_model(NICInfo *nd, const char *model);
121 07caea31 Markus Armbruster
int qemu_find_nic_model(NICInfo *nd, const char * const *models,
122 07caea31 Markus Armbruster
                        const char *default_model);
123 87ecb68b pbrook
124 376253ec aliguori
void do_info_network(Monitor *mon);
125 5369e3c0 Markus Armbruster
int do_set_link(Monitor *mon, const QDict *qdict, QObject **ret_data);
126 87ecb68b pbrook
127 87ecb68b pbrook
/* NIC info */
128 87ecb68b pbrook
129 87ecb68b pbrook
#define MAX_NICS 8
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 48e2faf2 Peter Maydell
    int used;         /* is this slot in nd_table[] being used? */
139 48e2faf2 Peter Maydell
    int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
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 7f161aae Mark McLoughlin
int net_client_parse(QemuOptsList *opts_list, const char *str);
167 dc1c9fe8 Mark McLoughlin
int net_init_clients(void);
168 668680f7 Markus Armbruster
void net_check_clients(void);
169 63a01ef8 aliguori
void net_cleanup(void);
170 f18c16de Luiz Capitulino
void net_host_device_add(Monitor *mon, const QDict *qdict);
171 f18c16de Luiz Capitulino
void net_host_device_remove(Monitor *mon, const QDict *qdict);
172 ae82d324 Markus Armbruster
int do_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret_data);
173 ae82d324 Markus Armbruster
int do_netdev_del(Monitor *mon, const QDict *qdict, QObject **ret_data);
174 63a01ef8 aliguori
175 f54825cc aurel32
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
176 f54825cc aurel32
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
177 f54825cc aurel32
#ifdef __sun__
178 f54825cc aurel32
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
179 f54825cc aurel32
#else
180 f54825cc aurel32
#define SMBD_COMMAND "/usr/sbin/smbd"
181 f54825cc aurel32
#endif
182 f54825cc aurel32
183 ed16ab5a Gerd Hoffmann
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
184 9d07d757 Paul Brook
185 5281d757 Mark McLoughlin
int net_handle_fd_param(Monitor *mon, const char *param);
186 5281d757 Mark McLoughlin
187 87ecb68b pbrook
#endif