]>
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 | ||
76d32cba GH |
14 | struct MACAddr { |
15 | uint8_t a[6]; | |
16 | }; | |
17 | ||
ed16ab5a GH |
18 | /* qdev nic properties */ |
19 | ||
1ceef9f2 JW |
20 | typedef struct NICPeers { |
21 | NetClientState *ncs[MAX_QUEUE_NUM]; | |
22 | } NICPeers; | |
23 | ||
ed16ab5a GH |
24 | typedef struct NICConf { |
25 | MACAddr macaddr; | |
1ceef9f2 | 26 | NICPeers peers; |
1ca4d09a | 27 | int32_t bootindex; |
1ceef9f2 | 28 | int32_t queues; |
ed16ab5a GH |
29 | } NICConf; |
30 | ||
31 | #define DEFINE_NIC_PROPERTIES(_state, _conf) \ | |
32 | DEFINE_PROP_MACADDR("mac", _state, _conf.macaddr), \ | |
1ceef9f2 JW |
33 | DEFINE_PROP_VLAN("vlan", _state, _conf.peers), \ |
34 | DEFINE_PROP_NETDEV("netdev", _state, _conf.peers), \ | |
1ca4d09a | 35 | DEFINE_PROP_INT32("bootindex", _state, _conf.bootindex, -1) |
ed16ab5a | 36 | |
1ceef9f2 | 37 | |
4e68f7a0 | 38 | /* Net clients */ |
87ecb68b | 39 | |
4e68f7a0 SH |
40 | typedef void (NetPoll)(NetClientState *, bool enable); |
41 | typedef int (NetCanReceive)(NetClientState *); | |
42 | typedef ssize_t (NetReceive)(NetClientState *, const uint8_t *, size_t); | |
43 | typedef ssize_t (NetReceiveIOV)(NetClientState *, const struct iovec *, int); | |
44 | typedef void (NetCleanup) (NetClientState *); | |
45 | typedef void (LinkStatusChanged)(NetClientState *); | |
f7860455 | 46 | typedef void (NetClientDestructor)(NetClientState *); |
34b25ca7 | 47 | |
3ed79cc9 | 48 | typedef struct NetClientInfo { |
2be64a68 | 49 | NetClientOptionsKind type; |
3ed79cc9 MM |
50 | size_t size; |
51 | NetReceive *receive; | |
52 | NetReceive *receive_raw; | |
53 | NetReceiveIOV *receive_iov; | |
54 | NetCanReceive *can_receive; | |
55 | NetCleanup *cleanup; | |
56 | LinkStatusChanged *link_status_changed; | |
ceb69615 | 57 | NetPoll *poll; |
3ed79cc9 MM |
58 | } NetClientInfo; |
59 | ||
4e68f7a0 | 60 | struct NetClientState { |
665a3b07 | 61 | NetClientInfo *info; |
436e5e53 | 62 | int link_down; |
4e68f7a0 SH |
63 | QTAILQ_ENTRY(NetClientState) next; |
64 | NetClientState *peer; | |
9a6ecb30 | 65 | NetQueue *send_queue; |
bf38c1a0 | 66 | char *model; |
676cff29 | 67 | char *name; |
87ecb68b | 68 | char info_str[256]; |
893379ef | 69 | unsigned receive_disabled : 1; |
f7860455 | 70 | NetClientDestructor *destructor; |
1ceef9f2 | 71 | unsigned int queue_index; |
87ecb68b PB |
72 | }; |
73 | ||
ebef2c09 | 74 | typedef struct NICState { |
f6b26cf2 | 75 | NetClientState *ncs; |
ebef2c09 MM |
76 | NICConf *conf; |
77 | void *opaque; | |
a083a89d | 78 | bool peer_deleted; |
ebef2c09 MM |
79 | } NICState; |
80 | ||
4e68f7a0 | 81 | NetClientState *qemu_find_netdev(const char *id); |
6c51ae73 JW |
82 | int qemu_find_net_clients_except(const char *id, NetClientState **ncs, |
83 | NetClientOptionsKind type, int max); | |
4e68f7a0 SH |
84 | NetClientState *qemu_new_net_client(NetClientInfo *info, |
85 | NetClientState *peer, | |
86 | const char *model, | |
87 | const char *name); | |
ebef2c09 MM |
88 | NICState *qemu_new_nic(NetClientInfo *info, |
89 | NICConf *conf, | |
90 | const char *model, | |
91 | const char *name, | |
92 | void *opaque); | |
948ecf21 | 93 | void qemu_del_nic(NICState *nic); |
1ceef9f2 | 94 | NetClientState *qemu_get_subqueue(NICState *nic, int queue_index); |
b356f76d | 95 | NetClientState *qemu_get_queue(NICState *nic); |
cc1f0f45 JW |
96 | NICState *qemu_get_nic(NetClientState *nc); |
97 | void *qemu_get_nic_opaque(NetClientState *nc); | |
b20c6b9e | 98 | void qemu_del_net_client(NetClientState *nc); |
4e68f7a0 SH |
99 | NetClientState *qemu_find_vlan_client_by_name(Monitor *mon, int vlan_id, |
100 | const char *client_str); | |
57f9ef17 MM |
101 | typedef void (*qemu_nic_foreach)(NICState *nic, void *opaque); |
102 | void qemu_foreach_nic(qemu_nic_foreach func, void *opaque); | |
35277d14 SH |
103 | int qemu_can_send_packet(NetClientState *nc); |
104 | ssize_t qemu_sendv_packet(NetClientState *nc, const struct iovec *iov, | |
fbe78f4f | 105 | int iovcnt); |
35277d14 | 106 | ssize_t qemu_sendv_packet_async(NetClientState *nc, const struct iovec *iov, |
f3b6c7fc | 107 | int iovcnt, NetPacketSent *sent_cb); |
35277d14 SH |
108 | void qemu_send_packet(NetClientState *nc, const uint8_t *buf, int size); |
109 | ssize_t qemu_send_packet_raw(NetClientState *nc, const uint8_t *buf, int size); | |
110 | ssize_t qemu_send_packet_async(NetClientState *nc, const uint8_t *buf, | |
f3b6c7fc | 111 | int size, NetPacketSent *sent_cb); |
35277d14 SH |
112 | void qemu_purge_queued_packets(NetClientState *nc); |
113 | void qemu_flush_queued_packets(NetClientState *nc); | |
114 | void qemu_format_nic_info_str(NetClientState *nc, uint8_t macaddr[6]); | |
76d32cba | 115 | void qemu_macaddr_default_if_unset(MACAddr *macaddr); |
07caea31 | 116 | int qemu_show_nic_models(const char *arg, const char *const *models); |
d07f22c5 | 117 | void qemu_check_nic_model(NICInfo *nd, const char *model); |
07caea31 MA |
118 | int qemu_find_nic_model(NICInfo *nd, const char * const *models, |
119 | const char *default_model); | |
87ecb68b | 120 | |
86a77c38 ZYW |
121 | ssize_t qemu_deliver_packet(NetClientState *sender, |
122 | unsigned flags, | |
123 | const uint8_t *data, | |
124 | size_t size, | |
125 | void *opaque); | |
126 | ssize_t qemu_deliver_packet_iov(NetClientState *sender, | |
127 | unsigned flags, | |
128 | const struct iovec *iov, | |
129 | int iovcnt, | |
130 | void *opaque); | |
131 | ||
1a859593 | 132 | void print_net_client(Monitor *mon, NetClientState *nc); |
84f2d0ea | 133 | void do_info_network(Monitor *mon, const QDict *qdict); |
87ecb68b PB |
134 | |
135 | /* NIC info */ | |
136 | ||
137 | #define MAX_NICS 8 | |
138 | ||
139 | struct NICInfo { | |
6eed1856 | 140 | MACAddr macaddr; |
9203f520 MM |
141 | char *model; |
142 | char *name; | |
143 | char *devaddr; | |
4e68f7a0 | 144 | NetClientState *netdev; |
48e2faf2 PM |
145 | int used; /* is this slot in nd_table[] being used? */ |
146 | int instantiated; /* does this NICInfo correspond to an instantiated NIC? */ | |
ffe6370c | 147 | int nvectors; |
87ecb68b PB |
148 | }; |
149 | ||
150 | extern int nb_nics; | |
151 | extern NICInfo nd_table[MAX_NICS]; | |
cb4522cc | 152 | extern int default_net; |
87ecb68b | 153 | |
63a01ef8 | 154 | /* from net.c */ |
ad196a9d JK |
155 | extern const char *legacy_tftp_prefix; |
156 | extern const char *legacy_bootp_filename; | |
157 | ||
4559a1db | 158 | int net_client_init(QemuOpts *opts, int is_netdev, Error **errp); |
7f161aae | 159 | int net_client_parse(QemuOptsList *opts_list, const char *str); |
dc1c9fe8 | 160 | int net_init_clients(void); |
668680f7 | 161 | void net_check_clients(void); |
63a01ef8 | 162 | void net_cleanup(void); |
f18c16de LC |
163 | void net_host_device_add(Monitor *mon, const QDict *qdict); |
164 | void net_host_device_remove(Monitor *mon, const QDict *qdict); | |
928059a3 LC |
165 | void netdev_add(QemuOpts *opts, Error **errp); |
166 | int qmp_netdev_add(Monitor *mon, const QDict *qdict, QObject **ret); | |
63a01ef8 | 167 | |
1422e32d PB |
168 | int net_hub_id_for_client(NetClientState *nc, int *id); |
169 | NetClientState *net_hub_port_find(int hub_id); | |
170 | ||
f54825cc AJ |
171 | #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup" |
172 | #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown" | |
a7c36ee4 CB |
173 | #define DEFAULT_BRIDGE_HELPER CONFIG_QEMU_HELPERDIR "/qemu-bridge-helper" |
174 | #define DEFAULT_BRIDGE_INTERFACE "br0" | |
f54825cc | 175 | |
ed16ab5a | 176 | void qdev_set_nic_properties(DeviceState *dev, NICInfo *nd); |
9d07d757 | 177 | |
7fc8d918 JW |
178 | #define POLYNOMIAL 0x04c11db6 |
179 | unsigned compute_mcast_idx(const uint8_t *ep); | |
180 | ||
701a8f76 PB |
181 | #define vmstate_offset_macaddr(_state, _field) \ |
182 | vmstate_offset_array(_state, _field.a, uint8_t, \ | |
183 | sizeof(typeof_field(_state, _field))) | |
184 | ||
185 | #define VMSTATE_MACADDR(_field, _state) { \ | |
186 | .name = (stringify(_field)), \ | |
187 | .size = sizeof(MACAddr), \ | |
188 | .info = &vmstate_info_buffer, \ | |
189 | .flags = VMS_BUFFER, \ | |
190 | .offset = vmstate_offset_macaddr(_state, _field), \ | |
191 | } | |
192 | ||
87ecb68b | 193 | #endif |