root / net.h @ b50a3a21
History | View | Annotate | Download (5.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 | 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 | ca77d175 | Mark McLoughlin | NetReceive *receive_raw; |
49 | cda9046b | Mark McLoughlin | NetReceiveIOV *receive_iov; |
50 | 87ecb68b | pbrook | /* Packets may still be sent if this returns zero. It's used to
|
51 | 87ecb68b | pbrook | rate-limit the slirp code. */
|
52 | cda9046b | Mark McLoughlin | NetCanReceive *can_receive; |
53 | b946a153 | aliguori | NetCleanup *cleanup; |
54 | 34b25ca7 | aliguori | LinkStatusChanged *link_status_changed; |
55 | 436e5e53 | aliguori | int link_down;
|
56 | 87ecb68b | pbrook | void *opaque;
|
57 | 5610c3aa | Mark McLoughlin | QTAILQ_ENTRY(VLANClientState) next; |
58 | 87ecb68b | pbrook | struct VLANState *vlan;
|
59 | 283c7c63 | Mark McLoughlin | VLANClientState *peer; |
60 | 9a6ecb30 | Mark McLoughlin | NetQueue *send_queue; |
61 | bf38c1a0 | aliguori | char *model;
|
62 | 676cff29 | aliguori | char *name;
|
63 | 87ecb68b | pbrook | char info_str[256]; |
64 | 893379ef | Mark McLoughlin | unsigned receive_disabled : 1; |
65 | 87ecb68b | pbrook | }; |
66 | 87ecb68b | pbrook | |
67 | 87ecb68b | pbrook | struct VLANState {
|
68 | 87ecb68b | pbrook | int id;
|
69 | 5610c3aa | Mark McLoughlin | QTAILQ_HEAD(, VLANClientState) clients; |
70 | 5610c3aa | Mark McLoughlin | QTAILQ_ENTRY(VLANState) next; |
71 | 87ecb68b | pbrook | unsigned int nb_guest_devs, nb_host_devs; |
72 | f7105843 | Mark McLoughlin | NetQueue *send_queue; |
73 | 87ecb68b | pbrook | }; |
74 | 87ecb68b | pbrook | |
75 | 1a609520 | Jan Kiszka | VLANState *qemu_find_vlan(int id, int allocate); |
76 | 2ef924b4 | Gerd Hoffmann | VLANClientState *qemu_find_netdev(const char *id); |
77 | 9f092040 | Anthony Liguori | VLANClientState *qemu_new_vlan_client(net_client_type type, |
78 | a7f085c6 | Anthony Liguori | VLANState *vlan, |
79 | 283c7c63 | Mark McLoughlin | VLANClientState *peer, |
80 | bf38c1a0 | aliguori | const char *model, |
81 | 7a9f6e4a | aliguori | const char *name, |
82 | cda9046b | Mark McLoughlin | NetCanReceive *can_receive, |
83 | cda9046b | Mark McLoughlin | NetReceive *receive, |
84 | 70783b9c | Mark McLoughlin | NetReceive *receive_raw, |
85 | cda9046b | Mark McLoughlin | NetReceiveIOV *receive_iov, |
86 | b946a153 | aliguori | NetCleanup *cleanup, |
87 | 87ecb68b | pbrook | void *opaque);
|
88 | dcf414d6 | balrog | void qemu_del_vlan_client(VLANClientState *vc);
|
89 | 8b13c4a7 | aliguori | VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
|
90 | 68ac40d2 | Mark McLoughlin | VLANClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
|
91 | 68ac40d2 | Mark McLoughlin | const char *client_str); |
92 | 87ecb68b | pbrook | int qemu_can_send_packet(VLANClientState *vc);
|
93 | fbe78f4f | aliguori | ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov, |
94 | fbe78f4f | aliguori | int iovcnt);
|
95 | f3b6c7fc | Mark McLoughlin | ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov, |
96 | f3b6c7fc | Mark McLoughlin | int iovcnt, NetPacketSent *sent_cb);
|
97 | 87ecb68b | pbrook | void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size); |
98 | ca77d175 | Mark McLoughlin | ssize_t qemu_send_packet_raw(VLANClientState *vc, const uint8_t *buf, int size); |
99 | f3b6c7fc | Mark McLoughlin | ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
|
100 | f3b6c7fc | Mark McLoughlin | int size, NetPacketSent *sent_cb);
|
101 | 8cad5516 | Mark McLoughlin | void qemu_purge_queued_packets(VLANClientState *vc);
|
102 | f3b6c7fc | Mark McLoughlin | void qemu_flush_queued_packets(VLANClientState *vc);
|
103 | 7cb7434b | aliguori | void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]); |
104 | 76d32cba | Gerd Hoffmann | void qemu_macaddr_default_if_unset(MACAddr *macaddr);
|
105 | 07caea31 | Markus Armbruster | int qemu_show_nic_models(const char *arg, const char *const *models); |
106 | d07f22c5 | aliguori | void qemu_check_nic_model(NICInfo *nd, const char *model); |
107 | 07caea31 | Markus Armbruster | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
108 | 07caea31 | Markus Armbruster | const char *default_model); |
109 | 87ecb68b | pbrook | |
110 | 376253ec | aliguori | void do_info_network(Monitor *mon);
|
111 | f18c16de | Luiz Capitulino | void do_set_link(Monitor *mon, const QDict *qdict); |
112 | 87ecb68b | pbrook | |
113 | 87ecb68b | pbrook | /* NIC info */
|
114 | 87ecb68b | pbrook | |
115 | 87ecb68b | pbrook | #define MAX_NICS 8 |
116 | ffe6370c | Michael S. Tsirkin | enum {
|
117 | ffe6370c | Michael S. Tsirkin | NIC_NVECTORS_UNSPECIFIED = -1
|
118 | ffe6370c | Michael S. Tsirkin | }; |
119 | 87ecb68b | pbrook | |
120 | 87ecb68b | pbrook | struct NICInfo {
|
121 | 87ecb68b | pbrook | uint8_t macaddr[6];
|
122 | 9203f520 | Mark McLoughlin | char *model;
|
123 | 9203f520 | Mark McLoughlin | char *name;
|
124 | 9203f520 | Mark McLoughlin | char *devaddr;
|
125 | 87ecb68b | pbrook | VLANState *vlan; |
126 | 5869c4d5 | Mark McLoughlin | VLANClientState *netdev; |
127 | 7697079b | aliguori | int used;
|
128 | 406c8df3 | Glauber Costa | int bootable;
|
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 | 87ecb68b | pbrook | |
135 | 1ae26a18 | balrog | /* BT HCI info */
|
136 | 1ae26a18 | balrog | |
137 | 1ae26a18 | balrog | struct HCIInfo {
|
138 | 1ae26a18 | balrog | int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr); |
139 | 1ae26a18 | balrog | void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
140 | 1ae26a18 | balrog | void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
141 | 1ae26a18 | balrog | void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len); |
142 | 1ae26a18 | balrog | void *opaque;
|
143 | 1ae26a18 | balrog | void (*evt_recv)(void *opaque, const uint8_t *data, int len); |
144 | 1ae26a18 | balrog | void (*acl_recv)(void *opaque, const uint8_t *data, int len); |
145 | 1ae26a18 | balrog | }; |
146 | 1ae26a18 | balrog | |
147 | 1ae26a18 | balrog | struct HCIInfo *qemu_next_hci(void); |
148 | 1ae26a18 | balrog | |
149 | 63a01ef8 | aliguori | /* from net.c */
|
150 | ad196a9d | Jan Kiszka | extern const char *legacy_tftp_prefix; |
151 | ad196a9d | Jan Kiszka | extern const char *legacy_bootp_filename; |
152 | ad196a9d | Jan Kiszka | |
153 | f6b134ac | Mark McLoughlin | int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev); |
154 | 8b13c4a7 | aliguori | void net_client_uninit(NICInfo *nd);
|
155 | 7f161aae | Mark McLoughlin | int net_client_parse(QemuOptsList *opts_list, const char *str); |
156 | dc1c9fe8 | Mark McLoughlin | int net_init_clients(void); |
157 | 63a01ef8 | aliguori | void net_cleanup(void); |
158 | 406c8df3 | Glauber Costa | void net_set_boot_mask(int boot_mask); |
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 | 63a01ef8 | aliguori | |
162 | f54825cc | aurel32 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
163 | f54825cc | aurel32 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" |
164 | f54825cc | aurel32 | #ifdef __sun__
|
165 | f54825cc | aurel32 | #define SMBD_COMMAND "/usr/sfw/sbin/smbd" |
166 | f54825cc | aurel32 | #else
|
167 | f54825cc | aurel32 | #define SMBD_COMMAND "/usr/sbin/smbd" |
168 | f54825cc | aurel32 | #endif
|
169 | f54825cc | aurel32 | |
170 | ed16ab5a | Gerd Hoffmann | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
|
171 | 9d07d757 | Paul Brook | |
172 | 5281d757 | Mark McLoughlin | int net_handle_fd_param(Monitor *mon, const char *param); |
173 | 5281d757 | Mark McLoughlin | |
174 | 87ecb68b | pbrook | #endif |