Merge remote-tracking branch 'remotes/kevin/tags/for-upstream' into staging
[qemu/ar7.git] / include / net / net.h
blob6a6cbef24a4c261303a6b84ebe59cfb4853648cc
1 #ifndef QEMU_NET_H
2 #define QEMU_NET_H
4 #include "qemu/queue.h"
5 #include "qemu-common.h"
6 #include "qapi/qmp/qdict.h"
7 #include "qemu/option.h"
8 #include "net/queue.h"
9 #include "migration/vmstate.h"
10 #include "qapi-types.h"
12 #define MAX_QUEUE_NUM 1024
14 /* Maximum GSO packet size (64k) plus plenty of room for
15 * the ethernet and virtio_net headers
17 #define NET_BUFSIZE (4096 + 65536)
19 struct MACAddr {
20 uint8_t a[6];
23 /* qdev nic properties */
25 typedef struct NICPeers {
26 NetClientState *ncs[MAX_QUEUE_NUM];
27 int32_t queues;
28 } NICPeers;
30 typedef struct NICConf {
31 MACAddr macaddr;
32 NICPeers peers;
33 int32_t bootindex;
34 } NICConf;
36 #define DEFINE_NIC_PROPERTIES(_state, _conf) \
37 DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
38 DEFINE_PROP_VLAN("vlan", _state, _conf.peers), \
39 DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
42 /* Net clients */
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 *);
50 typedef void (NetClientDestructor)(NetClientState *);
51 typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
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);
58 typedef int (SetVnetLE)(NetClientState *, bool);
59 typedef int (SetVnetBE)(NetClientState *, bool);
61 typedef struct NetClientInfo {
62 NetClientOptionsKind type;
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;
70 QueryRxFilter *query_rx_filter;
71 NetPoll *poll;
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;
78 SetVnetLE *set_vnet_le;
79 SetVnetBE *set_vnet_be;
80 } NetClientInfo;
82 struct NetClientState {
83 NetClientInfo *info;
84 int link_down;
85 QTAILQ_ENTRY(NetClientState) next;
86 NetClientState *peer;
87 NetQueue *incoming_queue;
88 char *model;
89 char *name;
90 char info_str[256];
91 unsigned receive_disabled : 1;
92 NetClientDestructor *destructor;
93 unsigned int queue_index;
94 unsigned rxfilter_notify_enabled:1;
97 typedef struct NICState {
98 NetClientState *ncs;
99 NICConf *conf;
100 void *opaque;
101 bool peer_deleted;
102 } NICState;
104 char *qemu_mac_strdup_printf(const uint8_t *macaddr);
105 NetClientState *qemu_find_netdev(const char *id);
106 int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
107 NetClientOptionsKind type, int max);
108 NetClientState *qemu_new_net_client(NetClientInfo *info,
109 NetClientState *peer,
110 const char *model,
111 const char *name);
112 NICState *qemu_new_nic(NetClientInfo *info,
113 NICConf *conf,
114 const char *model,
115 const char *name,
116 void *opaque);
117 void qemu_del_nic(NICState *nic);
118 NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
119 NetClientState *qemu_get_queue(NICState *nic);
120 NICState *qemu_get_nic(NetClientState *nc);
121 void *qemu_get_nic_opaque(NetClientState *nc);
122 void qemu_del_net_client(NetClientState *nc);
123 NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id,
124 const char *client_str);
125 typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
126 void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
127 int qemu_can_send_packet(NetClientState *nc);
128 ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
129 int iovcnt);
130 ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
131 int iovcnt, NetPacketSent *sent_cb);
132 void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
133 ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
134 ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
135 int size, NetPacketSent *sent_cb);
136 void qemu_purge_queued_packets(NetClientState *nc);
137 void qemu_flush_queued_packets(NetClientState *nc);
138 void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
139 bool qemu_has_ufo(NetClientState *nc);
140 bool qemu_has_vnet_hdr(NetClientState *nc);
141 bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
142 void qemu_using_vnet_hdr(NetClientState *nc, bool enable);
143 void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
144 int ecn, int ufo);
145 void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
146 int qemu_set_vnet_le(NetClientState *nc, bool is_le);
147 int qemu_set_vnet_be(NetClientState *nc, bool is_be);
148 void qemu_macaddr_default_if_unset(MACAddr *macaddr);
149 int qemu_show_nic_models(const char *arg, const char *const *models);
150 void qemu_check_nic_model(NICInfo *nd, const char *model);
151 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
152 const char *default_model);
154 ssize_t qemu_deliver_packet(NetClientState *sender,
155 unsigned flags,
156 const uint8_t *data,
157 size_t size,
158 void *opaque);
159 ssize_t qemu_deliver_packet_iov(NetClientState *sender,
160 unsigned flags,
161 const struct iovec *iov,
162 int iovcnt,
163 void *opaque);
165 void print_net_client(Monitor *mon, NetClientState *nc);
166 void hmp_info_network(Monitor *mon, const QDict *qdict);
168 /* NIC info */
170 #define MAX_NICS 8
172 struct NICInfo {
173 MACAddr macaddr;
174 char *model;
175 char *name;
176 char *devaddr;
177 NetClientState *netdev;
178 int used; /* is this slot in nd_table[] being used? */
179 int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
180 int nvectors;
183 extern int nb_nics;
184 extern NICInfo nd_table[MAX_NICS];
185 extern int default_net;
186 extern const char *host_net_devices[];
188 /* from net.c */
189 extern const char *legacy_tftp_prefix;
190 extern const char *legacy_bootp_filename;
192 int net_client_init(QemuOpts *opts, int is_netdev, Error **errp);
193 int net_client_parse(QemuOptsList *opts_list, const char *str);
194 int net_init_clients(void);
195 void net_check_clients(void);
196 void net_cleanup(void);
197 void hmp_host_net_add(Monitor *mon, const QDict *qdict);
198 void hmp_host_net_remove(Monitor *mon, const QDict *qdict);
199 void netdev_add(QemuOpts *opts, Error **errp);
200 void qmp_netdev_add(QDict *qdict, QObject **ret, Error **errp);
202 int net_hub_id_for_client(NetClientState *nc, int *id);
203 NetClientState *net_hub_port_find(int hub_id);
205 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
206 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
207 #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
208 #define DEFAULT_BRIDGE_INTERFACE "br0"
210 void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
212 #define POLYNOMIAL 0x04c11db6
213 unsigned compute_mcast_idx(const uint8_t *ep);
215 #define vmstate_offset_macaddr(_state, _field) \
216 vmstate_offset_array(_state, _field.a, uint8_t, \
217 sizeof(typeof_field(_state, _field)))
219 #define VMSTATE_MACADDR(_field, _state) { \
220 .name = (stringify(_field)), \
221 .size = sizeof(MACAddr), \
222 .info = &vmstate_info_buffer, \
223 .flags = VMS_BUFFER, \
224 .offset = vmstate_offset_macaddr(_state, _field), \
227 #endif