]>
Commit | Line | Data |
---|---|---|
87ecb68b PB |
1 | #ifndef QEMU_NET_H |
2 | #define QEMU_NET_H | |
3 | ||
1de7afc9 | 4 | #include "qemu/queue.h" |
fbe78f4f | 5 | #include "qemu-common.h" |
7b1b5d19 | 6 | #include "qapi/qmp/qdict.h" |
1de7afc9 | 7 | #include "qemu/option.h" |
e1144d00 | 8 | #include "net/queue.h" |
caf71f86 | 9 | #include "migration/vmstate.h" |
2be64a68 | 10 | #include "qapi-types.h" |
fbe78f4f | 11 | |
1ceef9f2 JW |
12 | #define MAX_QUEUE_NUM 1024 |
13 | ||
d32fcad3 SF |
14 | /* Maximum GSO packet size (64k) plus plenty of room for |
15 | * the ethernet and virtio_net headers | |
16 | */ | |
17 | #define NET_BUFSIZE (4096 + 65536) | |
18 | ||
76d32cba GH |
19 | struct MACAddr { |
20 | uint8_t a[6]; | |
21 | }; | |
22 | ||
ed16ab5a GH |
23 | /* qdev nic properties */ |
24 | ||
1ceef9f2 JW |
25 | typedef struct NICPeers { |
26 | NetClientState *ncs[MAX_QUEUE_NUM]; | |
575a1c0e | 27 | int32_t queues; |
1ceef9f2 JW |
28 | } NICPeers; |
29 | ||
ed16ab5a GH |
30 | typedef struct NICConf { |
31 | MACAddr macaddr; | |
1ceef9f2 | 32 | NICPeers peers; |
1ca4d09a | 33 | int32_t bootindex; |
ed16ab5a GH |
34 | } NICConf; |
35 | ||
36 | #define DEFINE_NIC_PROPERTIES(_state, _conf) \ | |
37 | DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ | |
1ceef9f2 | 38 | DEFINE_PROP_VLAN("vlan", _state, _conf.peers), \ |
45e8a9e1 | 39 | DEFINE_PROP_NETDEV("netdev", _state, _conf.peers) |
ed16ab5a | 40 | |
1ceef9f2 | 41 | |
4e68f7a0 | 42 | /* Net clients */ |
87ecb68b | 43 | |
4e68f7a0 SH |
44 | typedef void (NetPoll)(NetClientState *, bool enable); |
45 | typedef int (NetCanReceive)(NetClientState *); | |
46 | typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); | |
47 | typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); | |
48 | typedef void (NetCleanup) (NetClientState *); | |
49 | typedef void (LinkStatusChanged)(NetClientState *); | |
f7860455 | 50 | typedef void (NetClientDestructor)(NetClientState *); |
b1be4280 | 51 | typedef RxFilterInfo *(QueryRxFilter)(NetClientState *); |
1f55ac45 VM |
52 | typedef bool (HasUfo)(NetClientState *); |
53 | typedef bool (HasVnetHdr)(NetClientState *); | |
54 | typedef bool (HasVnetHdrLen)(NetClientState *, int); | |
55 | typedef void (UsingVnetHdr)(NetClientState *, bool); | |
56 | typedef void (SetOffload)(NetClientState *, int, int, int, int, int); | |
57 | typedef void (SetVnetHdrLen)(NetClientState *, int); | |
c80cd6bb GK |
58 | typedef int (SetVnetLE)(NetClientState *, bool); |
59 | typedef int (SetVnetBE)(NetClientState *, bool); | |
34b25ca7 | 60 | |
3ed79cc9 | 61 | typedef struct NetClientInfo { |
2be64a68 | 62 | NetClientOptionsKind type; |
3ed79cc9 MM |
63 | size_t size; |
64 | NetReceive *receive; | |
65 | NetReceive *receive_raw; | |
66 | NetReceiveIOV *receive_iov; | |
67 | NetCanReceive *can_receive; | |
68 | NetCleanup *cleanup; | |
69 | LinkStatusChanged *link_status_changed; | |
b1be4280 | 70 | QueryRxFilter *query_rx_filter; |
ceb69615 | 71 | NetPoll *poll; |
1f55ac45 VM |
72 | HasUfo *has_ufo; |
73 | HasVnetHdr *has_vnet_hdr; | |
74 | HasVnetHdrLen *has_vnet_hdr_len; | |
75 | UsingVnetHdr *using_vnet_hdr; | |
76 | SetOffload *set_offload; | |
77 | SetVnetHdrLen *set_vnet_hdr_len; | |
c80cd6bb GK |
78 | SetVnetLE *set_vnet_le; |
79 | SetVnetBE *set_vnet_be; | |
3ed79cc9 MM |
80 | } NetClientInfo; |
81 | ||
4e68f7a0 | 82 | struct NetClientState { |
665a3b07 | 83 | NetClientInfo *info; |
436e5e53 | 84 | int link_down; |
4e68f7a0 SH |
85 | QTAILQ_ENTRY(NetClientState) next; |
86 | NetClientState *peer; | |
067404be | 87 | NetQueue *incoming_queue; |
bf38c1a0 | 88 | char *model; |
676cff29 | 89 | char *name; |
87ecb68b | 90 | char info_str[256]; |
893379ef | 91 | unsigned receive_disabled : 1; |
f7860455 | 92 | NetClientDestructor *destructor; |
1ceef9f2 | 93 | unsigned int queue_index; |
b1be4280 | 94 | unsigned rxfilter_notify_enabled:1; |
fdccce45 | 95 | QTAILQ_HEAD(, NetFilterState) filters; |
87ecb68b PB |
96 | }; |
97 | ||
ebef2c09 | 98 | typedef struct NICState { |
f6b26cf2 | 99 | NetClientState *ncs; |
ebef2c09 MM |
100 | NICConf *conf; |
101 | void *opaque; | |
a083a89d | 102 | bool peer_deleted; |
ebef2c09 MM |
103 | } NICState; |
104 | ||
890ee6ab | 105 | char *qemu_mac_strdup_printf(const uint8_t *macaddr); |
4e68f7a0 | 106 | NetClientState *qemu_find_netdev(const char *id); |
6c51ae73 JW |
107 | int qemu_find_net_clients_except(const char *id, NetClientState **ncs, |
108 | NetClientOptionsKind type, int max); | |
4e68f7a0 SH |
109 | NetClientState *qemu_new_net_client(NetClientInfo *info, |
110 | NetClientState *peer, | |
111 | const char *model, | |
112 | const char *name); | |
ebef2c09 MM |
113 | NICState *qemu_new_nic(NetClientInfo *info, |
114 | NICConf *conf, | |
115 | const char *model, | |
116 | const char *name, | |
117 | void *opaque); | |
948ecf21 | 118 | void qemu_del_nic(NICState *nic); |
1ceef9f2 | 119 | NetClientState *qemu_get_subqueue(NICState *nic, int queue_index); |
b356f76d | 120 | NetClientState *qemu_get_queue(NICState *nic); |
cc1f0f45 JW |
121 | NICState *qemu_get_nic(NetClientState *nc); |
122 | void *qemu_get_nic_opaque(NetClientState *nc); | |
b20c6b9e | 123 | void qemu_del_net_client(NetClientState *nc); |
4e68f7a0 SH |
124 | NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, |
125 | const char *client_str); | |
57f9ef17 MM |
126 | typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); |
127 | void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); | |
35277d14 SH |
128 | int qemu_can_send_packet(NetClientState *nc); |
129 | ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, | |
fbe78f4f | 130 | int iovcnt); |
35277d14 | 131 | ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov, |
f3b6c7fc | 132 | int iovcnt, NetPacketSent *sent_cb); |
35277d14 SH |
133 | void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); |
134 | ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size); | |
135 | ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf, | |
f3b6c7fc | 136 | int size, NetPacketSent *sent_cb); |
35277d14 SH |
137 | void qemu_purge_queued_packets(NetClientState *nc); |
138 | void qemu_flush_queued_packets(NetClientState *nc); | |
139 | void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); | |
d6085e3a SH |
140 | bool qemu_has_ufo(NetClientState *nc); |
141 | bool qemu_has_vnet_hdr(NetClientState *nc); | |
142 | bool qemu_has_vnet_hdr_len(NetClientState *nc, int len); | |
143 | void qemu_using_vnet_hdr(NetClientState *nc, bool enable); | |
144 | void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6, | |
145 | int ecn, int ufo); | |
146 | void qemu_set_vnet_hdr_len(NetClientState *nc, int len); | |
c80cd6bb GK |
147 | int qemu_set_vnet_le(NetClientState *nc, bool is_le); |
148 | int qemu_set_vnet_be(NetClientState *nc, bool is_be); | |
76d32cba | 149 | void qemu_macaddr_default_if_unset(MACAddr *macaddr); |
07caea31 | 150 | int qemu_show_nic_models(const char *arg, const char *const *models); |
d07f22c5 | 151 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
07caea31 MA |
152 | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
153 | const char *default_model); | |
87ecb68b | 154 | |
86a77c38 ZYW |
155 | ssize_t qemu_deliver_packet_iov(NetClientState *sender, |
156 | unsigned flags, | |
157 | const struct iovec *iov, | |
158 | int iovcnt, | |
159 | void *opaque); | |
160 | ||
1a859593 | 161 | void print_net_client(Monitor *mon, NetClientState *nc); |
1ce6be24 | 162 | void hmp_info_network(Monitor *mon, const QDict *qdict); |
87ecb68b PB |
163 | |
164 | /* NIC info */ | |
165 | ||
166 | #define MAX_NICS 8 | |
167 | ||
168 | struct NICInfo { | |
6eed1856 | 169 | MACAddr macaddr; |
9203f520 MM |
170 | char *model; |
171 | char *name; | |
172 | char *devaddr; | |
4e68f7a0 | 173 | NetClientState *netdev; |
48e2faf2 PM |
174 | int used; /* is this slot in nd_table[] being used? */ |
175 | int instantiated; /* does this NICInfo correspond to an instantiated NIC? */ | |
ffe6370c | 176 | int nvectors; |
87ecb68b PB |
177 | }; |
178 | ||
179 | extern int nb_nics; | |
180 | extern NICInfo nd_table[MAX_NICS]; | |
cb4522cc | 181 | extern int default_net; |
84007e81 | 182 | extern const char *host_net_devices[]; |
87ecb68b | 183 | |
63a01ef8 | 184 | /* from net.c */ |
ad196a9d JK |
185 | extern const char *legacy_tftp_prefix; |
186 | extern const char *legacy_bootp_filename; | |
187 | ||
4559a1db | 188 | int net_client_init(QemuOpts *opts, int is_netdev, Error **errp); |
7f161aae | 189 | int net_client_parse(QemuOptsList *opts_list, const char *str); |
dc1c9fe8 | 190 | int net_init_clients(void); |
668680f7 | 191 | void net_check_clients(void); |
63a01ef8 | 192 | void net_cleanup(void); |
3e5a50d6 MA |
193 | void hmp_host_net_add(Monitor *mon, const QDict *qdict); |
194 | void hmp_host_net_remove(Monitor *mon, const QDict *qdict); | |
928059a3 | 195 | void netdev_add(QemuOpts *opts, Error **errp); |
485febc6 | 196 | void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp); |
63a01ef8 | 197 | |
1422e32d PB |
198 | int net_hub_id_for_client(NetClientState *nc, int *id); |
199 | NetClientState *net_hub_port_find(int hub_id); | |
200 | ||
f54825cc AJ |
201 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
202 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" | |
a7c36ee4 CB |
203 | #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper" |
204 | #define DEFAULT_BRIDGE_INTERFACE "br0" | |
f54825cc | 205 | |
ed16ab5a | 206 | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); |
9d07d757 | 207 | |
7fc8d918 JW |
208 | #define POLYNOMIAL 0x04c11db6 |
209 | unsigned compute_mcast_idx(const uint8_t *ep); | |
210 | ||
701a8f76 PB |
211 | #define vmstate_offset_macaddr(_state, _field) \ |
212 | vmstate_offset_array(_state, _field.a, uint8_t, \ | |
213 | sizeof(typeof_field(_state, _field))) | |
214 | ||
215 | #define VMSTATE_MACADDR(_field, _state) { \ | |
216 | .name = (stringify(_field)), \ | |
217 | .size = sizeof(MACAddr), \ | |
218 | .info = &vmstate_info_buffer, \ | |
219 | .flags = VMS_BUFFER, \ | |
220 | .offset = vmstate_offset_macaddr(_state, _field), \ | |
221 | } | |
222 | ||
87ecb68b | 223 | #endif |