root / include / net / net.h @ 067404be
History | View | Annotate | Download (7 kB)
1 | 87ecb68b | pbrook | #ifndef QEMU_NET_H
|
---|---|---|---|
2 | 87ecb68b | pbrook | #define QEMU_NET_H
|
3 | 87ecb68b | pbrook | |
4 | 1de7afc9 | Paolo Bonzini | #include "qemu/queue.h" |
5 | fbe78f4f | aliguori | #include "qemu-common.h" |
6 | 7b1b5d19 | Paolo Bonzini | #include "qapi/qmp/qdict.h" |
7 | 1de7afc9 | Paolo Bonzini | #include "qemu/option.h" |
8 | e1144d00 | Mark McLoughlin | #include "net/queue.h" |
9 | caf71f86 | Paolo Bonzini | #include "migration/vmstate.h" |
10 | 2be64a68 | Laszlo Ersek | #include "qapi-types.h" |
11 | fbe78f4f | aliguori | |
12 | 1ceef9f2 | Jason Wang | #define MAX_QUEUE_NUM 1024 |
13 | 1ceef9f2 | Jason Wang | |
14 | d32fcad3 | Scott Feldman | /* Maximum GSO packet size (64k) plus plenty of room for
|
15 | d32fcad3 | Scott Feldman | * the ethernet and virtio_net headers
|
16 | d32fcad3 | Scott Feldman | */
|
17 | d32fcad3 | Scott Feldman | #define NET_BUFSIZE (4096 + 65536) |
18 | d32fcad3 | Scott Feldman | |
19 | 76d32cba | Gerd Hoffmann | struct MACAddr {
|
20 | 76d32cba | Gerd Hoffmann | uint8_t a[6];
|
21 | 76d32cba | Gerd Hoffmann | }; |
22 | 76d32cba | Gerd Hoffmann | |
23 | ed16ab5a | Gerd Hoffmann | /* qdev nic properties */
|
24 | ed16ab5a | Gerd Hoffmann | |
25 | 1ceef9f2 | Jason Wang | typedef struct NICPeers { |
26 | 1ceef9f2 | Jason Wang | NetClientState *ncs[MAX_QUEUE_NUM]; |
27 | 1ceef9f2 | Jason Wang | } NICPeers; |
28 | 1ceef9f2 | Jason Wang | |
29 | ed16ab5a | Gerd Hoffmann | typedef struct NICConf { |
30 | ed16ab5a | Gerd Hoffmann | MACAddr macaddr; |
31 | 1ceef9f2 | Jason Wang | NICPeers peers; |
32 | 1ca4d09a | Gleb Natapov | int32_t bootindex; |
33 | 1ceef9f2 | Jason Wang | int32_t queues; |
34 | ed16ab5a | Gerd Hoffmann | } NICConf; |
35 | ed16ab5a | Gerd Hoffmann | |
36 | ed16ab5a | Gerd Hoffmann | #define DEFINE_NIC_PROPERTIES(_state, _conf) \
|
37 | ed16ab5a | Gerd Hoffmann | DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
|
38 | 1ceef9f2 | Jason Wang | DEFINE_PROP_VLAN("vlan", _state, _conf.peers), \
|
39 | 1ceef9f2 | Jason Wang | DEFINE_PROP_NETDEV("netdev", _state, _conf.peers), \
|
40 | 1ca4d09a | Gleb Natapov | DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) |
41 | ed16ab5a | Gerd Hoffmann | |
42 | 1ceef9f2 | Jason Wang | |
43 | 4e68f7a0 | Stefan Hajnoczi | /* Net clients */
|
44 | 87ecb68b | pbrook | |
45 | 4e68f7a0 | Stefan Hajnoczi | typedef void (NetPoll)(NetClientState *, bool enable); |
46 | 4e68f7a0 | Stefan Hajnoczi | typedef int (NetCanReceive)(NetClientState *); |
47 | 4e68f7a0 | Stefan Hajnoczi | typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); |
48 | 4e68f7a0 | Stefan Hajnoczi | typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); |
49 | 4e68f7a0 | Stefan Hajnoczi | typedef void (NetCleanup) (NetClientState *); |
50 | 4e68f7a0 | Stefan Hajnoczi | typedef void (LinkStatusChanged)(NetClientState *); |
51 | f7860455 | Jason Wang | typedef void (NetClientDestructor)(NetClientState *); |
52 | b1be4280 | Amos Kong | typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
|
53 | 34b25ca7 | aliguori | |
54 | 3ed79cc9 | Mark McLoughlin | typedef struct NetClientInfo { |
55 | 2be64a68 | Laszlo Ersek | NetClientOptionsKind type; |
56 | 3ed79cc9 | Mark McLoughlin | size_t size; |
57 | 3ed79cc9 | Mark McLoughlin | NetReceive *receive; |
58 | 3ed79cc9 | Mark McLoughlin | NetReceive *receive_raw; |
59 | 3ed79cc9 | Mark McLoughlin | NetReceiveIOV *receive_iov; |
60 | 3ed79cc9 | Mark McLoughlin | NetCanReceive *can_receive; |
61 | 3ed79cc9 | Mark McLoughlin | NetCleanup *cleanup; |
62 | 3ed79cc9 | Mark McLoughlin | LinkStatusChanged *link_status_changed; |
63 | b1be4280 | Amos Kong | QueryRxFilter *query_rx_filter; |
64 | ceb69615 | Michael S. Tsirkin | NetPoll *poll; |
65 | 3ed79cc9 | Mark McLoughlin | } NetClientInfo; |
66 | 3ed79cc9 | Mark McLoughlin | |
67 | 4e68f7a0 | Stefan Hajnoczi | struct NetClientState {
|
68 | 665a3b07 | Mark McLoughlin | NetClientInfo *info; |
69 | 436e5e53 | aliguori | int link_down;
|
70 | 4e68f7a0 | Stefan Hajnoczi | QTAILQ_ENTRY(NetClientState) next; |
71 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *peer; |
72 | 067404be | Jan Kiszka | NetQueue *incoming_queue; |
73 | bf38c1a0 | aliguori | char *model;
|
74 | 676cff29 | aliguori | char *name;
|
75 | 87ecb68b | pbrook | char info_str[256]; |
76 | 893379ef | Mark McLoughlin | unsigned receive_disabled : 1; |
77 | f7860455 | Jason Wang | NetClientDestructor *destructor; |
78 | 1ceef9f2 | Jason Wang | unsigned int queue_index; |
79 | b1be4280 | Amos Kong | unsigned rxfilter_notify_enabled:1; |
80 | 87ecb68b | pbrook | }; |
81 | 87ecb68b | pbrook | |
82 | ebef2c09 | Mark McLoughlin | typedef struct NICState { |
83 | f6b26cf2 | Jason Wang | NetClientState *ncs; |
84 | ebef2c09 | Mark McLoughlin | NICConf *conf; |
85 | ebef2c09 | Mark McLoughlin | void *opaque;
|
86 | a083a89d | Michael S. Tsirkin | bool peer_deleted;
|
87 | ebef2c09 | Mark McLoughlin | } NICState; |
88 | ebef2c09 | Mark McLoughlin | |
89 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *qemu_find_netdev(const char *id); |
90 | 6c51ae73 | Jason Wang | int qemu_find_net_clients_except(const char *id, NetClientState **ncs, |
91 | 6c51ae73 | Jason Wang | NetClientOptionsKind type, int max);
|
92 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *qemu_new_net_client(NetClientInfo *info, |
93 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *peer, |
94 | 4e68f7a0 | Stefan Hajnoczi | const char *model, |
95 | 4e68f7a0 | Stefan Hajnoczi | 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 | 948ecf21 | Jason Wang | void qemu_del_nic(NICState *nic);
|
102 | 1ceef9f2 | Jason Wang | NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
|
103 | b356f76d | Jason Wang | NetClientState *qemu_get_queue(NICState *nic); |
104 | cc1f0f45 | Jason Wang | NICState *qemu_get_nic(NetClientState *nc); |
105 | cc1f0f45 | Jason Wang | void *qemu_get_nic_opaque(NetClientState *nc);
|
106 | b20c6b9e | Stefan Hajnoczi | void qemu_del_net_client(NetClientState *nc);
|
107 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
|
108 | 4e68f7a0 | Stefan Hajnoczi | const char *client_str); |
109 | 57f9ef17 | Mark McLoughlin | typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); |
110 | 57f9ef17 | Mark McLoughlin | void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); |
111 | 35277d14 | Stefan Hajnoczi | int qemu_can_send_packet(NetClientState *nc);
|
112 | 35277d14 | Stefan Hajnoczi | ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, |
113 | fbe78f4f | aliguori | int iovcnt);
|
114 | 35277d14 | Stefan Hajnoczi | ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov, |
115 | f3b6c7fc | Mark McLoughlin | int iovcnt, NetPacketSent *sent_cb);
|
116 | 35277d14 | Stefan Hajnoczi | void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); |
117 | 35277d14 | Stefan Hajnoczi | ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size); |
118 | 35277d14 | Stefan Hajnoczi | ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
|
119 | f3b6c7fc | Mark McLoughlin | int size, NetPacketSent *sent_cb);
|
120 | 35277d14 | Stefan Hajnoczi | void qemu_purge_queued_packets(NetClientState *nc);
|
121 | 35277d14 | Stefan Hajnoczi | void qemu_flush_queued_packets(NetClientState *nc);
|
122 | 35277d14 | Stefan Hajnoczi | void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); |
123 | 76d32cba | Gerd Hoffmann | void qemu_macaddr_default_if_unset(MACAddr *macaddr);
|
124 | 07caea31 | Markus Armbruster | int qemu_show_nic_models(const char *arg, const char *const *models); |
125 | d07f22c5 | aliguori | void qemu_check_nic_model(NICInfo *nd, const char *model); |
126 | 07caea31 | Markus Armbruster | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
127 | 07caea31 | Markus Armbruster | const char *default_model); |
128 | 87ecb68b | pbrook | |
129 | 86a77c38 | Zhi Yong Wu | ssize_t qemu_deliver_packet(NetClientState *sender, |
130 | 86a77c38 | Zhi Yong Wu | unsigned flags,
|
131 | 86a77c38 | Zhi Yong Wu | const uint8_t *data,
|
132 | 86a77c38 | Zhi Yong Wu | size_t size, |
133 | 86a77c38 | Zhi Yong Wu | void *opaque);
|
134 | 86a77c38 | Zhi Yong Wu | ssize_t qemu_deliver_packet_iov(NetClientState *sender, |
135 | 86a77c38 | Zhi Yong Wu | unsigned flags,
|
136 | 86a77c38 | Zhi Yong Wu | const struct iovec *iov, |
137 | 86a77c38 | Zhi Yong Wu | int iovcnt,
|
138 | 86a77c38 | Zhi Yong Wu | void *opaque);
|
139 | 86a77c38 | Zhi Yong Wu | |
140 | 1a859593 | Zhi Yong Wu | void print_net_client(Monitor *mon, NetClientState *nc);
|
141 | 84f2d0ea | Wenchao Xia | void do_info_network(Monitor *mon, const QDict *qdict); |
142 | 87ecb68b | pbrook | |
143 | 87ecb68b | pbrook | /* NIC info */
|
144 | 87ecb68b | pbrook | |
145 | 87ecb68b | pbrook | #define MAX_NICS 8 |
146 | 87ecb68b | pbrook | |
147 | 87ecb68b | pbrook | struct NICInfo {
|
148 | 6eed1856 | Jan Kiszka | MACAddr macaddr; |
149 | 9203f520 | Mark McLoughlin | char *model;
|
150 | 9203f520 | Mark McLoughlin | char *name;
|
151 | 9203f520 | Mark McLoughlin | char *devaddr;
|
152 | 4e68f7a0 | Stefan Hajnoczi | NetClientState *netdev; |
153 | 48e2faf2 | Peter Maydell | int used; /* is this slot in nd_table[] being used? */ |
154 | 48e2faf2 | Peter Maydell | int instantiated; /* does this NICInfo correspond to an instantiated NIC? */ |
155 | ffe6370c | Michael S. Tsirkin | int nvectors;
|
156 | 87ecb68b | pbrook | }; |
157 | 87ecb68b | pbrook | |
158 | 87ecb68b | pbrook | extern int nb_nics; |
159 | 87ecb68b | pbrook | extern NICInfo nd_table[MAX_NICS];
|
160 | cb4522cc | Gerd Hoffmann | extern int default_net; |
161 | 87ecb68b | pbrook | |
162 | 63a01ef8 | aliguori | /* from net.c */
|
163 | ad196a9d | Jan Kiszka | extern const char *legacy_tftp_prefix; |
164 | ad196a9d | Jan Kiszka | extern const char *legacy_bootp_filename; |
165 | ad196a9d | Jan Kiszka | |
166 | 4559a1db | Luiz Capitulino | int net_client_init(QemuOpts *opts, int is_netdev, Error **errp); |
167 | 7f161aae | Mark McLoughlin | int net_client_parse(QemuOptsList *opts_list, const char *str); |
168 | dc1c9fe8 | Mark McLoughlin | int net_init_clients(void); |
169 | 668680f7 | Markus Armbruster | void net_check_clients(void); |
170 | 63a01ef8 | aliguori | void net_cleanup(void); |
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 | 928059a3 | Luiz Capitulino | void netdev_add(QemuOpts *opts, Error **errp);
|
174 | 928059a3 | Luiz Capitulino | int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret); |
175 | 63a01ef8 | aliguori | |
176 | 1422e32d | Paolo Bonzini | int net_hub_id_for_client(NetClientState *nc, int *id); |
177 | 1422e32d | Paolo Bonzini | NetClientState *net_hub_port_find(int hub_id);
|
178 | 1422e32d | Paolo Bonzini | |
179 | f54825cc | aurel32 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
180 | f54825cc | aurel32 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" |
181 | a7c36ee4 | Corey Bryant | #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper" |
182 | a7c36ee4 | Corey Bryant | #define DEFAULT_BRIDGE_INTERFACE "br0" |
183 | f54825cc | aurel32 | |
184 | ed16ab5a | Gerd Hoffmann | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
|
185 | 9d07d757 | Paul Brook | |
186 | 7fc8d918 | Jason Wang | #define POLYNOMIAL 0x04c11db6 |
187 | 7fc8d918 | Jason Wang | unsigned compute_mcast_idx(const uint8_t *ep); |
188 | 7fc8d918 | Jason Wang | |
189 | 701a8f76 | Paolo Bonzini | #define vmstate_offset_macaddr(_state, _field) \
|
190 | 701a8f76 | Paolo Bonzini | vmstate_offset_array(_state, _field.a, uint8_t, \ |
191 | 701a8f76 | Paolo Bonzini | sizeof(typeof_field(_state, _field)))
|
192 | 701a8f76 | Paolo Bonzini | |
193 | 701a8f76 | Paolo Bonzini | #define VMSTATE_MACADDR(_field, _state) { \
|
194 | 701a8f76 | Paolo Bonzini | .name = (stringify(_field)), \ |
195 | 701a8f76 | Paolo Bonzini | .size = sizeof(MACAddr), \
|
196 | 701a8f76 | Paolo Bonzini | .info = &vmstate_info_buffer, \ |
197 | 701a8f76 | Paolo Bonzini | .flags = VMS_BUFFER, \ |
198 | 701a8f76 | Paolo Bonzini | .offset = vmstate_offset_macaddr(_state, _field), \ |
199 | 701a8f76 | Paolo Bonzini | } |
200 | 701a8f76 | Paolo Bonzini | |
201 | 87ecb68b | pbrook | #endif |