11422e32dSPaolo Bonzini #ifndef QEMU_NET_H
21422e32dSPaolo Bonzini #define QEMU_NET_H
31422e32dSPaolo Bonzini
41de7afc9SPaolo Bonzini #include "qemu/queue.h"
59af23989SMarkus Armbruster #include "qapi/qapi-types-net.h"
61422e32dSPaolo Bonzini #include "net/queue.h"
7ce35e229SEduardo Habkost #include "hw/qdev-properties-system.h"
81422e32dSPaolo Bonzini
96d1d4939SDmitry Fleytman #define MAC_FMT "%02X:%02X:%02X:%02X:%02X:%02X"
106d1d4939SDmitry Fleytman #define MAC_ARG(x) ((uint8_t *)(x))[0], ((uint8_t *)(x))[1], \
116d1d4939SDmitry Fleytman ((uint8_t *)(x))[2], ((uint8_t *)(x))[3], \
126d1d4939SDmitry Fleytman ((uint8_t *)(x))[4], ((uint8_t *)(x))[5]
136d1d4939SDmitry Fleytman
141ceef9f2SJason Wang #define MAX_QUEUE_NUM 1024
151ceef9f2SJason Wang
16d32fcad3SScott Feldman /* Maximum GSO packet size (64k) plus plenty of room for
17d32fcad3SScott Feldman * the ethernet and virtio_net headers
18d32fcad3SScott Feldman */
19d32fcad3SScott Feldman #define NET_BUFSIZE (4096 + 65536)
20d32fcad3SScott Feldman
211422e32dSPaolo Bonzini struct MACAddr {
221422e32dSPaolo Bonzini uint8_t a[6];
231422e32dSPaolo Bonzini };
241422e32dSPaolo Bonzini
251422e32dSPaolo Bonzini /* qdev nic properties */
261422e32dSPaolo Bonzini
271ceef9f2SJason Wang typedef struct NICPeers {
281ceef9f2SJason Wang NetClientState *ncs[MAX_QUEUE_NUM];
29575a1c0eSJiri Pirko int32_t queues;
301ceef9f2SJason Wang } NICPeers;
311ceef9f2SJason Wang
321422e32dSPaolo Bonzini typedef struct NICConf {
331422e32dSPaolo Bonzini MACAddr macaddr;
341ceef9f2SJason Wang NICPeers peers;
351422e32dSPaolo Bonzini int32_t bootindex;
361422e32dSPaolo Bonzini } NICConf;
371422e32dSPaolo Bonzini
381422e32dSPaolo Bonzini #define DEFINE_NIC_PROPERTIES(_state, _conf) \
391422e32dSPaolo Bonzini DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \
4045e8a9e1SGonglei DEFINE_PROP_NETDEV("netdev", _state, _conf.peers)
411422e32dSPaolo Bonzini
421ceef9f2SJason Wang
431422e32dSPaolo Bonzini /* Net clients */
441422e32dSPaolo Bonzini
451422e32dSPaolo Bonzini typedef void (NetPoll)(NetClientState *, bool enable);
46b8c4b67eSPhilippe Mathieu-Daudé typedef bool (NetCanReceive)(NetClientState *);
47eb92b753SEugenio Pérez typedef int (NetStart)(NetClientState *);
48539573c3SEugenio Pérez typedef int (NetLoad)(NetClientState *);
49c5e5269dSEugenio Pérez typedef void (NetStop)(NetClientState *);
501422e32dSPaolo Bonzini typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t);
511422e32dSPaolo Bonzini typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int);
521422e32dSPaolo Bonzini typedef void (NetCleanup) (NetClientState *);
531422e32dSPaolo Bonzini typedef void (LinkStatusChanged)(NetClientState *);
54f7860455SJason Wang typedef void (NetClientDestructor)(NetClientState *);
55b1be4280SAmos Kong typedef RxFilterInfo *(QueryRxFilter)(NetClientState *);
561f55ac45SVincenzo Maffione typedef bool (HasUfo)(NetClientState *);
57f03e0cf6SYuri Benditovich typedef bool (HasUso)(NetClientState *);
581f55ac45SVincenzo Maffione typedef bool (HasVnetHdr)(NetClientState *);
591f55ac45SVincenzo Maffione typedef bool (HasVnetHdrLen)(NetClientState *, int);
602ab0ec31SAndrew Melnychenko typedef void (SetOffload)(NetClientState *, int, int, int, int, int, int, int);
61481c5232SAkihiko Odaki typedef int (GetVnetHdrLen)(NetClientState *);
621f55ac45SVincenzo Maffione typedef void (SetVnetHdrLen)(NetClientState *, int);
63c80cd6bbSGreg Kurz typedef int (SetVnetLE)(NetClientState *, bool);
64c80cd6bbSGreg Kurz typedef int (SetVnetBE)(NetClientState *, bool);
6516a3df40SZhang Chen typedef struct SocketReadState SocketReadState;
6616a3df40SZhang Chen typedef void (SocketReadStateFinalize)(SocketReadState *rs);
6744b416adSDr. David Alan Gilbert typedef void (NetAnnounce)(NetClientState *);
688f364e34SAndrew Melnychenko typedef bool (SetSteeringEBPF)(NetClientState *, int);
69e287bf7bSKevin Wolf typedef bool (NetCheckPeerType)(NetClientState *, ObjectClass *, Error **);
701422e32dSPaolo Bonzini
711422e32dSPaolo Bonzini typedef struct NetClientInfo {
72f394b2e2SEric Blake NetClientDriver type;
731422e32dSPaolo Bonzini size_t size;
741422e32dSPaolo Bonzini NetReceive *receive;
751422e32dSPaolo Bonzini NetReceiveIOV *receive_iov;
761422e32dSPaolo Bonzini NetCanReceive *can_receive;
77eb92b753SEugenio Pérez NetStart *start;
78539573c3SEugenio Pérez NetLoad *load;
79c5e5269dSEugenio Pérez NetStop *stop;
801422e32dSPaolo Bonzini NetCleanup *cleanup;
811422e32dSPaolo Bonzini LinkStatusChanged *link_status_changed;
82b1be4280SAmos Kong QueryRxFilter *query_rx_filter;
831422e32dSPaolo Bonzini NetPoll *poll;
841f55ac45SVincenzo Maffione HasUfo *has_ufo;
85f03e0cf6SYuri Benditovich HasUso *has_uso;
861f55ac45SVincenzo Maffione HasVnetHdr *has_vnet_hdr;
871f55ac45SVincenzo Maffione HasVnetHdrLen *has_vnet_hdr_len;
881f55ac45SVincenzo Maffione SetOffload *set_offload;
891f55ac45SVincenzo Maffione SetVnetHdrLen *set_vnet_hdr_len;
90c80cd6bbSGreg Kurz SetVnetLE *set_vnet_le;
91c80cd6bbSGreg Kurz SetVnetBE *set_vnet_be;
9244b416adSDr. David Alan Gilbert NetAnnounce *announce;
938f364e34SAndrew Melnychenko SetSteeringEBPF *set_steering_ebpf;
94e287bf7bSKevin Wolf NetCheckPeerType *check_peer_type;
951422e32dSPaolo Bonzini } NetClientInfo;
961422e32dSPaolo Bonzini
971422e32dSPaolo Bonzini struct NetClientState {
981422e32dSPaolo Bonzini NetClientInfo *info;
991422e32dSPaolo Bonzini int link_down;
1001422e32dSPaolo Bonzini QTAILQ_ENTRY(NetClientState) next;
1011422e32dSPaolo Bonzini NetClientState *peer;
102067404beSJan Kiszka NetQueue *incoming_queue;
1031422e32dSPaolo Bonzini char *model;
1041422e32dSPaolo Bonzini char *name;
10556e6f594SJason Wang char info_str[256];
1061422e32dSPaolo Bonzini unsigned receive_disabled : 1;
107f7860455SJason Wang NetClientDestructor *destructor;
1081ceef9f2SJason Wang unsigned int queue_index;
109b1be4280SAmos Kong unsigned rxfilter_notify_enabled:1;
110bfc6cf31SMarc-André Lureau int vring_enable;
111d6b732e9SZhang Chen int vnet_hdr_len;
11208712fcbSEric Blake bool is_netdev;
113935344beSBin Meng bool do_not_pad; /* do not pad to the minimum ethernet frame length */
1142f849dbdSJason Wang bool is_datapath;
115eae3eb3eSPaolo Bonzini QTAILQ_HEAD(, NetFilterState) filters;
1161422e32dSPaolo Bonzini };
1171422e32dSPaolo Bonzini
118ae71d13dSMarkus Armbruster typedef QTAILQ_HEAD(NetClientStateList, NetClientState) NetClientStateList;
119ae71d13dSMarkus Armbruster
1201422e32dSPaolo Bonzini typedef struct NICState {
121f6b26cf2SJason Wang NetClientState *ncs;
1221422e32dSPaolo Bonzini NICConf *conf;
1239050f976SAkihiko Odaki MemReentrancyGuard *reentrancy_guard;
1241422e32dSPaolo Bonzini void *opaque;
1251422e32dSPaolo Bonzini bool peer_deleted;
1261422e32dSPaolo Bonzini } NICState;
1271422e32dSPaolo Bonzini
12816a3df40SZhang Chen struct SocketReadState {
1293cde5ea2SZhang Chen /* 0 = getting length, 1 = getting vnet header length, 2 = getting data */
1303cde5ea2SZhang Chen int state;
1313cde5ea2SZhang Chen /* This flag decide whether to read the vnet_hdr_len field */
1323cde5ea2SZhang Chen bool vnet_hdr;
13316a3df40SZhang Chen uint32_t index;
13416a3df40SZhang Chen uint32_t packet_len;
1353cde5ea2SZhang Chen uint32_t vnet_hdr_len;
13616a3df40SZhang Chen uint8_t buf[NET_BUFSIZE];
13716a3df40SZhang Chen SocketReadStateFinalize *finalize;
13816a3df40SZhang Chen };
13916a3df40SZhang Chen
14016a3df40SZhang Chen int net_fill_rstate(SocketReadState *rs, const uint8_t *buf, int size);
141890ee6abSScott Feldman char *qemu_mac_strdup_printf(const uint8_t *macaddr);
1421422e32dSPaolo Bonzini NetClientState *qemu_find_netdev(const char *id);
1436c51ae73SJason Wang int qemu_find_net_clients_except(const char *id, NetClientState **ncs,
144f394b2e2SEric Blake NetClientDriver type, int max);
1451422e32dSPaolo Bonzini NetClientState *qemu_new_net_client(NetClientInfo *info,
1461422e32dSPaolo Bonzini NetClientState *peer,
1471422e32dSPaolo Bonzini const char *model,
1481422e32dSPaolo Bonzini const char *name);
1492f849dbdSJason Wang NetClientState *qemu_new_net_control_client(NetClientInfo *info,
1502f849dbdSJason Wang NetClientState *peer,
1512f849dbdSJason Wang const char *model,
1522f849dbdSJason Wang const char *name);
1531422e32dSPaolo Bonzini NICState *qemu_new_nic(NetClientInfo *info,
1541422e32dSPaolo Bonzini NICConf *conf,
1551422e32dSPaolo Bonzini const char *model,
1561422e32dSPaolo Bonzini const char *name,
1577d0fefdfSAkihiko Odaki MemReentrancyGuard *reentrancy_guard,
1581422e32dSPaolo Bonzini void *opaque);
159948ecf21SJason Wang void qemu_del_nic(NICState *nic);
1601ceef9f2SJason Wang NetClientState *qemu_get_subqueue(NICState *nic, int queue_index);
161b356f76dSJason Wang NetClientState *qemu_get_queue(NICState *nic);
162cc1f0f45SJason Wang NICState *qemu_get_nic(NetClientState *nc);
163cc1f0f45SJason Wang void *qemu_get_nic_opaque(NetClientState *nc);
1641422e32dSPaolo Bonzini void qemu_del_net_client(NetClientState *nc);
1651422e32dSPaolo Bonzini typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque);
1661422e32dSPaolo Bonzini void qemu_foreach_nic(qemu_nic_foreach func, void *opaque);
167705df546SJason Wang int qemu_can_receive_packet(NetClientState *nc);
1681422e32dSPaolo Bonzini int qemu_can_send_packet(NetClientState *nc);
1691422e32dSPaolo Bonzini ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov,
1701422e32dSPaolo Bonzini int iovcnt);
1711422e32dSPaolo Bonzini ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov,
1721422e32dSPaolo Bonzini int iovcnt, NetPacketSent *sent_cb);
173625a526bSMarc-André Lureau ssize_t qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size);
174705df546SJason Wang ssize_t qemu_receive_packet(NetClientState *nc, const uint8_t *buf, int size);
1751422e32dSPaolo Bonzini ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size);
1761422e32dSPaolo Bonzini ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf,
1771422e32dSPaolo Bonzini int size, NetPacketSent *sent_cb);
1781422e32dSPaolo Bonzini void qemu_purge_queued_packets(NetClientState *nc);
1791422e32dSPaolo Bonzini void qemu_flush_queued_packets(NetClientState *nc);
18094b52958SGreg Kurz void qemu_flush_or_purge_queued_packets(NetClientState *nc, bool purge);
181ac149498SStefan Weil via void qemu_set_info_str(NetClientState *nc,
182ac149498SStefan Weil via const char *fmt, ...) G_GNUC_PRINTF(2, 3);
1831422e32dSPaolo Bonzini void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]);
184d6085e3aSStefan Hajnoczi bool qemu_has_ufo(NetClientState *nc);
185f03e0cf6SYuri Benditovich bool qemu_has_uso(NetClientState *nc);
186d6085e3aSStefan Hajnoczi bool qemu_has_vnet_hdr(NetClientState *nc);
187d6085e3aSStefan Hajnoczi bool qemu_has_vnet_hdr_len(NetClientState *nc, int len);
188d6085e3aSStefan Hajnoczi void qemu_set_offload(NetClientState *nc, int csum, int tso4, int tso6,
1892ab0ec31SAndrew Melnychenko int ecn, int ufo, int uso4, int uso6);
190481c5232SAkihiko Odaki int qemu_get_vnet_hdr_len(NetClientState *nc);
191d6085e3aSStefan Hajnoczi void qemu_set_vnet_hdr_len(NetClientState *nc, int len);
192c80cd6bbSGreg Kurz int qemu_set_vnet_le(NetClientState *nc, bool is_le);
193c80cd6bbSGreg Kurz int qemu_set_vnet_be(NetClientState *nc, bool is_be);
1941422e32dSPaolo Bonzini void qemu_macaddr_default_if_unset(MACAddr *macaddr);
19593e9d730SDavid Woodhouse /**
19693e9d730SDavid Woodhouse * qemu_find_nic_info: Obtain NIC configuration information
19793e9d730SDavid Woodhouse * @typename: Name of device object type
19893e9d730SDavid Woodhouse * @match_default: Match NIC configurations with no model specified
19993e9d730SDavid Woodhouse * @alias: Additional model string to match (for user convenience and
20093e9d730SDavid Woodhouse * backward compatibility).
20193e9d730SDavid Woodhouse *
20293e9d730SDavid Woodhouse * Search for a NIC configuration matching the NIC model constraints.
20393e9d730SDavid Woodhouse */
20493e9d730SDavid Woodhouse NICInfo *qemu_find_nic_info(const char *typename, bool match_default,
20593e9d730SDavid Woodhouse const char *alias);
20693e9d730SDavid Woodhouse /**
20793e9d730SDavid Woodhouse * qemu_configure_nic_device: Apply NIC configuration to a given device
20893e9d730SDavid Woodhouse * @dev: Network device to be configured
20993e9d730SDavid Woodhouse * @match_default: Match NIC configurations with no model specified
21093e9d730SDavid Woodhouse * @alias: Additional model string to match
21193e9d730SDavid Woodhouse *
21293e9d730SDavid Woodhouse * Search for a NIC configuration for the provided device, using the
21393e9d730SDavid Woodhouse * additionally specified matching constraints. If found, apply the
21493e9d730SDavid Woodhouse * configuration using qdev_set_nic_properties() and return %true.
21593e9d730SDavid Woodhouse *
21693e9d730SDavid Woodhouse * This is used by platform code which creates the device anyway,
21793e9d730SDavid Woodhouse * regardless of whether there is a configuration for it. This tends
21893e9d730SDavid Woodhouse * to be platforms which ignore `--nodefaults` and create net devices
21993e9d730SDavid Woodhouse * anyway, for example because the Ethernet device on that board is
22093e9d730SDavid Woodhouse * always physically present.
22193e9d730SDavid Woodhouse */
22293e9d730SDavid Woodhouse bool qemu_configure_nic_device(DeviceState *dev, bool match_default,
22393e9d730SDavid Woodhouse const char *alias);
2241422e32dSPaolo Bonzini
22593e9d730SDavid Woodhouse /**
22693e9d730SDavid Woodhouse * qemu_create_nic_device: Create a NIC device if a configuration exists for it
22793e9d730SDavid Woodhouse * @typename: Object typename of network device
22893e9d730SDavid Woodhouse * @match_default: Match NIC configurations with no model specified
22993e9d730SDavid Woodhouse * @alias: Additional model string to match
23093e9d730SDavid Woodhouse *
23193e9d730SDavid Woodhouse * Search for a NIC configuration for the provided device type. If found,
23293e9d730SDavid Woodhouse * create an object of the corresponding type and return it.
23393e9d730SDavid Woodhouse */
23493e9d730SDavid Woodhouse DeviceState *qemu_create_nic_device(const char *typename, bool match_default,
23593e9d730SDavid Woodhouse const char *alias);
236*93125e4bSDavid Woodhouse
237*93125e4bSDavid Woodhouse /*
238*93125e4bSDavid Woodhouse * qemu_create_nic_bus_devices: Create configured NIC devices for a given bus
239*93125e4bSDavid Woodhouse * @bus: Bus on which to create devices
240*93125e4bSDavid Woodhouse * @parent_type: Object type for devices to be created (e.g. TYPE_PCI_DEVICE)
241*93125e4bSDavid Woodhouse * @default_model: Object type name for default NIC model (or %NULL)
242*93125e4bSDavid Woodhouse * @alias: Additional model string to replace, for user convenience
243*93125e4bSDavid Woodhouse * @alias_target: Actual object type name to be used in place of @alias
244*93125e4bSDavid Woodhouse *
245*93125e4bSDavid Woodhouse * Instantiate dynamic NICs on a given bus, typically a PCI bus. This scans
246*93125e4bSDavid Woodhouse * for available NIC configurations which either specify a model which is
247*93125e4bSDavid Woodhouse * a child type of @parent_type, or which do not specify a model when
248*93125e4bSDavid Woodhouse * @default_model is non-NULL. Each device is instantiated on the given @bus.
249*93125e4bSDavid Woodhouse *
250*93125e4bSDavid Woodhouse * A single substitution is supported, e.g. "xen" → "xen-net-device" for the
251*93125e4bSDavid Woodhouse * Xen bus, or "virtio" → "virtio-net-pci" for PCI. This allows the user to
252*93125e4bSDavid Woodhouse * specify a more understandable "model=" parameter on the command line, not
253*93125e4bSDavid Woodhouse * only the real object typename.
254*93125e4bSDavid Woodhouse */
255*93125e4bSDavid Woodhouse void qemu_create_nic_bus_devices(BusState *bus, const char *parent_type,
256*93125e4bSDavid Woodhouse const char *default_model,
257*93125e4bSDavid Woodhouse const char *alias, const char *alias_target);
2581422e32dSPaolo Bonzini void print_net_client(Monitor *mon, NetClientState *nc);
25916a3df40SZhang Chen void net_socket_rs_init(SocketReadState *rs,
2603cde5ea2SZhang Chen SocketReadStateFinalize *finalize,
2613cde5ea2SZhang Chen bool vnet_hdr);
2620165daaeSCindy Lu NetClientState *qemu_get_peer(NetClientState *nc, int queue_index);
2631422e32dSPaolo Bonzini
264c6941b3bSThomas Huth /**
265c6941b3bSThomas Huth * qemu_get_nic_models:
266c6941b3bSThomas Huth * @device_type: Defines which devices should be taken into consideration
267c6941b3bSThomas Huth * (e.g. TYPE_DEVICE for all devices, or TYPE_PCI_DEVICE for PCI)
268c6941b3bSThomas Huth *
269c6941b3bSThomas Huth * Get an array of pointers to names of NIC devices that are available in
270c6941b3bSThomas Huth * the QEMU binary. The array is terminated with a NULL pointer entry.
271c6941b3bSThomas Huth * The caller is responsible for freeing the memory when it is not required
272c6941b3bSThomas Huth * anymore, e.g. with g_ptr_array_free(..., true).
273c6941b3bSThomas Huth *
274c6941b3bSThomas Huth * Returns: Pointer to the array that contains the pointers to the names.
275c6941b3bSThomas Huth */
276c6941b3bSThomas Huth GPtrArray *qemu_get_nic_models(const char *device_type);
277c6941b3bSThomas Huth
2781422e32dSPaolo Bonzini /* NIC info */
2791422e32dSPaolo Bonzini
2801422e32dSPaolo Bonzini #define MAX_NICS 8
2811422e32dSPaolo Bonzini
2821422e32dSPaolo Bonzini struct NICInfo {
2831422e32dSPaolo Bonzini MACAddr macaddr;
2841422e32dSPaolo Bonzini char *model;
2851422e32dSPaolo Bonzini char *name;
2861422e32dSPaolo Bonzini char *devaddr;
2871422e32dSPaolo Bonzini NetClientState *netdev;
2881422e32dSPaolo Bonzini int used; /* is this slot in nd_table[] being used? */
2891422e32dSPaolo Bonzini int instantiated; /* does this NICInfo correspond to an instantiated NIC? */
2901422e32dSPaolo Bonzini int nvectors;
2911422e32dSPaolo Bonzini };
2921422e32dSPaolo Bonzini
2931422e32dSPaolo Bonzini /* from net.c */
294ae71d13dSMarkus Armbruster extern NetClientStateList net_clients;
29573071f19SPhilippe Mathieu-Daudé bool netdev_is_modern(const char *optstr);
29673071f19SPhilippe Mathieu-Daudé void netdev_parse_modern(const char *optstr);
29773071f19SPhilippe Mathieu-Daudé void net_client_parse(QemuOptsList *opts_list, const char *optstr);
298ad6f932fSPaolo Bonzini void show_netdevs(void);
299d63ef17bSLaurent Vivier void net_init_clients(void);
3001422e32dSPaolo Bonzini void net_check_clients(void);
3011422e32dSPaolo Bonzini void net_cleanup(void);
3023e5a50d6SMarkus Armbruster void hmp_host_net_add(Monitor *mon, const QDict *qdict);
3033e5a50d6SMarkus Armbruster void hmp_host_net_remove(Monitor *mon, const QDict *qdict);
3041422e32dSPaolo Bonzini void netdev_add(QemuOpts *opts, Error **errp);
3051422e32dSPaolo Bonzini
3061422e32dSPaolo Bonzini int net_hub_id_for_client(NetClientState *nc, int *id);
3071422e32dSPaolo Bonzini
30863c4db4cSPaolo Bonzini #define DEFAULT_NETWORK_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifup"
30963c4db4cSPaolo Bonzini #define DEFAULT_NETWORK_DOWN_SCRIPT CONFIG_SYSCONFDIR "/qemu-ifdown"
3101422e32dSPaolo Bonzini #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper"
3111422e32dSPaolo Bonzini #define DEFAULT_BRIDGE_INTERFACE "br0"
3121422e32dSPaolo Bonzini
3131422e32dSPaolo Bonzini void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd);
3141422e32dSPaolo Bonzini
315eaba8f34SMark Cave-Ayland #define POLYNOMIAL_BE 0x04c11db6
316f1a7deb9SMark Cave-Ayland #define POLYNOMIAL_LE 0xedb88320
317eaba8f34SMark Cave-Ayland uint32_t net_crc32(const uint8_t *p, int len);
318f1a7deb9SMark Cave-Ayland uint32_t net_crc32_le(const uint8_t *p, int len);
3191422e32dSPaolo Bonzini
3201422e32dSPaolo Bonzini #define vmstate_offset_macaddr(_state, _field) \
3211422e32dSPaolo Bonzini vmstate_offset_array(_state, _field.a, uint8_t, \
3221422e32dSPaolo Bonzini sizeof(typeof_field(_state, _field)))
3231422e32dSPaolo Bonzini
3241422e32dSPaolo Bonzini #define VMSTATE_MACADDR(_field, _state) { \
3251422e32dSPaolo Bonzini .name = (stringify(_field)), \
3261422e32dSPaolo Bonzini .size = sizeof(MACAddr), \
3271422e32dSPaolo Bonzini .info = &vmstate_info_buffer, \
3281422e32dSPaolo Bonzini .flags = VMS_BUFFER, \
3291422e32dSPaolo Bonzini .offset = vmstate_offset_macaddr(_state, _field), \
3301422e32dSPaolo Bonzini }
3311422e32dSPaolo Bonzini
net_peer_needs_padding(NetClientState * nc)332bc38e31bSJason Wang static inline bool net_peer_needs_padding(NetClientState *nc)
333bc38e31bSJason Wang {
334bc38e31bSJason Wang return nc->peer && !nc->peer->do_not_pad;
335bc38e31bSJason Wang }
336bc38e31bSJason Wang
3371422e32dSPaolo Bonzini #endif
338