Statistics
| Branch: | Revision:

root / net.h @ bb6e6364

History | View | Annotate | Download (5.8 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 f7105843 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 ed16ab5a Gerd Hoffmann
} NICConf;
21 ed16ab5a Gerd Hoffmann
22 ed16ab5a Gerd Hoffmann
#define DEFINE_NIC_PROPERTIES(_state, _conf)                            \
23 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_MACADDR("mac",   _state, _conf.macaddr),                \
24 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_VLAN("vlan",     _state, _conf.vlan),                   \
25 ed16ab5a Gerd Hoffmann
    DEFINE_PROP_NETDEV("netdev", _state, _conf.peer)
26 ed16ab5a Gerd Hoffmann
27 87ecb68b pbrook
/* VLANs support */
28 87ecb68b pbrook
29 bb6e6364 Mark McLoughlin
typedef enum {
30 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NONE,
31 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_NIC,
32 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SLIRP,
33 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_TAP,
34 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_SOCKET,
35 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_VDE,
36 bb6e6364 Mark McLoughlin
    NET_CLIENT_TYPE_DUMP
37 bb6e6364 Mark McLoughlin
} net_client_type;
38 bb6e6364 Mark McLoughlin
39 e3f5ec2b Mark McLoughlin
typedef int (NetCanReceive)(VLANClientState *);
40 4f1c942b Mark McLoughlin
typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
41 e3f5ec2b Mark McLoughlin
typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
42 b946a153 aliguori
typedef void (NetCleanup) (VLANClientState *);
43 34b25ca7 aliguori
typedef void (LinkStatusChanged)(VLANClientState *);
44 34b25ca7 aliguori
45 87ecb68b pbrook
struct VLANClientState {
46 bb6e6364 Mark McLoughlin
    net_client_type type;
47 cda9046b Mark McLoughlin
    NetReceive *receive;
48 cda9046b Mark McLoughlin
    NetReceiveIOV *receive_iov;
49 87ecb68b pbrook
    /* Packets may still be sent if this returns zero.  It's used to
50 87ecb68b pbrook
       rate-limit the slirp code.  */
51 cda9046b Mark McLoughlin
    NetCanReceive *can_receive;
52 b946a153 aliguori
    NetCleanup *cleanup;
53 34b25ca7 aliguori
    LinkStatusChanged *link_status_changed;
54 436e5e53 aliguori
    int link_down;
55 87ecb68b pbrook
    void *opaque;
56 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANClientState) next;
57 87ecb68b pbrook
    struct VLANState *vlan;
58 283c7c63 Mark McLoughlin
    VLANClientState *peer;
59 9a6ecb30 Mark McLoughlin
    NetQueue *send_queue;
60 bf38c1a0 aliguori
    char *model;
61 676cff29 aliguori
    char *name;
62 87ecb68b pbrook
    char info_str[256];
63 87ecb68b pbrook
};
64 87ecb68b pbrook
65 87ecb68b pbrook
struct VLANState {
66 87ecb68b pbrook
    int id;
67 5610c3aa Mark McLoughlin
    QTAILQ_HEAD(, VLANClientState) clients;
68 5610c3aa Mark McLoughlin
    QTAILQ_ENTRY(VLANState) next;
69 87ecb68b pbrook
    unsigned int nb_guest_devs, nb_host_devs;
70 f7105843 Mark McLoughlin
    NetQueue *send_queue;
71 87ecb68b pbrook
};
72 87ecb68b pbrook
73 1a609520 Jan Kiszka
VLANState *qemu_find_vlan(int id, int allocate);
74 2ef924b4 Gerd Hoffmann
VLANClientState *qemu_find_netdev(const char *id);
75 87ecb68b pbrook
VLANClientState *qemu_new_vlan_client(VLANState *vlan,
76 283c7c63 Mark McLoughlin
                                      VLANClientState *peer,
77 bf38c1a0 aliguori
                                      const char *model,
78 7a9f6e4a aliguori
                                      const char *name,
79 cda9046b Mark McLoughlin
                                      NetCanReceive *can_receive,
80 cda9046b Mark McLoughlin
                                      NetReceive *receive,
81 cda9046b Mark McLoughlin
                                      NetReceiveIOV *receive_iov,
82 b946a153 aliguori
                                      NetCleanup *cleanup,
83 87ecb68b pbrook
                                      void *opaque);
84 dcf414d6 balrog
void qemu_del_vlan_client(VLANClientState *vc);
85 8b13c4a7 aliguori
VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
86 87ecb68b pbrook
int qemu_can_send_packet(VLANClientState *vc);
87 fbe78f4f aliguori
ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
88 fbe78f4f aliguori
                          int iovcnt);
89 f3b6c7fc Mark McLoughlin
ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
90 f3b6c7fc Mark McLoughlin
                                int iovcnt, NetPacketSent *sent_cb);
91 87ecb68b pbrook
void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
92 f3b6c7fc Mark McLoughlin
ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
93 f3b6c7fc Mark McLoughlin
                               int size, NetPacketSent *sent_cb);
94 8cad5516 Mark McLoughlin
void qemu_purge_queued_packets(VLANClientState *vc);
95 f3b6c7fc Mark McLoughlin
void qemu_flush_queued_packets(VLANClientState *vc);
96 7cb7434b aliguori
void qemu_format_nic_info_str(VLANClientState *vc, 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 376253ec aliguori
void do_info_network(Monitor *mon);
104 f18c16de Luiz Capitulino
void do_set_link(Monitor *mon, const QDict *qdict);
105 87ecb68b pbrook
106 6dbe553f Jan Kiszka
void do_info_usernet(Monitor *mon);
107 6dbe553f Jan Kiszka
108 87ecb68b pbrook
/* NIC info */
109 87ecb68b pbrook
110 87ecb68b pbrook
#define MAX_NICS 8
111 ffe6370c Michael S. Tsirkin
enum {
112 ffe6370c Michael S. Tsirkin
        NIC_NVECTORS_UNSPECIFIED = -1
113 ffe6370c Michael S. Tsirkin
};
114 87ecb68b pbrook
115 87ecb68b pbrook
struct NICInfo {
116 87ecb68b pbrook
    uint8_t macaddr[6];
117 9203f520 Mark McLoughlin
    char *model;
118 9203f520 Mark McLoughlin
    char *name;
119 9203f520 Mark McLoughlin
    char *devaddr;
120 87ecb68b pbrook
    VLANState *vlan;
121 5869c4d5 Mark McLoughlin
    VLANClientState *netdev;
122 ae50b274 Mark McLoughlin
    VLANClientState *vc;
123 72da4208 aliguori
    void *private;
124 7697079b aliguori
    int used;
125 406c8df3 Glauber Costa
    int bootable;
126 ffe6370c Michael S. Tsirkin
    int nvectors;
127 87ecb68b pbrook
};
128 87ecb68b pbrook
129 87ecb68b pbrook
extern int nb_nics;
130 87ecb68b pbrook
extern NICInfo nd_table[MAX_NICS];
131 87ecb68b pbrook
132 1ae26a18 balrog
/* BT HCI info */
133 1ae26a18 balrog
134 1ae26a18 balrog
struct HCIInfo {
135 1ae26a18 balrog
    int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
136 1ae26a18 balrog
    void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
137 1ae26a18 balrog
    void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
138 1ae26a18 balrog
    void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
139 1ae26a18 balrog
    void *opaque;
140 1ae26a18 balrog
    void (*evt_recv)(void *opaque, const uint8_t *data, int len);
141 1ae26a18 balrog
    void (*acl_recv)(void *opaque, const uint8_t *data, int len);
142 1ae26a18 balrog
};
143 1ae26a18 balrog
144 1ae26a18 balrog
struct HCIInfo *qemu_next_hci(void);
145 1ae26a18 balrog
146 48c64363 aliguori
/* checksumming functions (net-checksum.c) */
147 48c64363 aliguori
uint32_t net_checksum_add(int len, uint8_t *buf);
148 48c64363 aliguori
uint16_t net_checksum_finish(uint32_t sum);
149 48c64363 aliguori
uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
150 48c64363 aliguori
                             uint8_t *addrs, uint8_t *buf);
151 48c64363 aliguori
void net_checksum_calculate(uint8_t *data, int length);
152 48c64363 aliguori
153 63a01ef8 aliguori
/* from net.c */
154 ad196a9d Jan Kiszka
extern const char *legacy_tftp_prefix;
155 ad196a9d Jan Kiszka
extern const char *legacy_bootp_filename;
156 ad196a9d Jan Kiszka
157 f6b134ac Mark McLoughlin
int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
158 8b13c4a7 aliguori
void net_client_uninit(NICInfo *nd);
159 7f161aae Mark McLoughlin
int net_client_parse(QemuOptsList *opts_list, const char *str);
160 dc1c9fe8 Mark McLoughlin
int net_init_clients(void);
161 0752706d Markus Armbruster
int net_slirp_smb(const char *exported_dir);
162 1d4daa91 Luiz Capitulino
void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
163 1d4daa91 Luiz Capitulino
void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
164 0752706d Markus Armbruster
int net_slirp_redir(const char *redir_str);
165 63a01ef8 aliguori
void net_cleanup(void);
166 406c8df3 Glauber Costa
void net_set_boot_mask(int boot_mask);
167 f18c16de Luiz Capitulino
void net_host_device_add(Monitor *mon, const QDict *qdict);
168 f18c16de Luiz Capitulino
void net_host_device_remove(Monitor *mon, const QDict *qdict);
169 63a01ef8 aliguori
170 f54825cc aurel32
#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
171 f54825cc aurel32
#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
172 f54825cc aurel32
#ifdef __sun__
173 f54825cc aurel32
#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
174 f54825cc aurel32
#else
175 f54825cc aurel32
#define SMBD_COMMAND "/usr/sbin/smbd"
176 f54825cc aurel32
#endif
177 f54825cc aurel32
178 ed16ab5a Gerd Hoffmann
void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
179 9d07d757 Paul Brook
180 87ecb68b pbrook
#endif