]> git.proxmox.com Git - qemu.git/blame - net.h
qdev: mac addr property fixups
[qemu.git] / net.h
CommitLineData
87ecb68b
PB
1#ifndef QEMU_NET_H
2#define QEMU_NET_H
3
72cf2d4f 4#include "qemu-queue.h"
fbe78f4f 5#include "qemu-common.h"
f18c16de 6#include "qdict.h"
13cf8f21 7#include "qemu-option.h"
f7105843 8#include "net-queue.h"
fbe78f4f 9
76d32cba
GH
10struct MACAddr {
11 uint8_t a[6];
12};
13
87ecb68b
PB
14/* VLANs support */
15
e3f5ec2b 16typedef int (NetCanReceive)(VLANClientState *);
4f1c942b 17typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
e3f5ec2b 18typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
b946a153 19typedef void (NetCleanup) (VLANClientState *);
34b25ca7
AL
20typedef void (LinkStatusChanged)(VLANClientState *);
21
87ecb68b 22struct VLANClientState {
cda9046b
MM
23 NetReceive *receive;
24 NetReceiveIOV *receive_iov;
87ecb68b
PB
25 /* Packets may still be sent if this returns zero. It's used to
26 rate-limit the slirp code. */
cda9046b 27 NetCanReceive *can_receive;
b946a153 28 NetCleanup *cleanup;
34b25ca7 29 LinkStatusChanged *link_status_changed;
436e5e53 30 int link_down;
87ecb68b 31 void *opaque;
5610c3aa 32 QTAILQ_ENTRY(VLANClientState) next;
87ecb68b 33 struct VLANState *vlan;
283c7c63 34 VLANClientState *peer;
9a6ecb30 35 NetQueue *send_queue;
bf38c1a0 36 char *model;
676cff29 37 char *name;
87ecb68b
PB
38 char info_str[256];
39};
40
41struct VLANState {
42 int id;
5610c3aa
MM
43 QTAILQ_HEAD(, VLANClientState) clients;
44 QTAILQ_ENTRY(VLANState) next;
87ecb68b 45 unsigned int nb_guest_devs, nb_host_devs;
f7105843 46 NetQueue *send_queue;
87ecb68b
PB
47};
48
1a609520 49VLANState *qemu_find_vlan(int id, int allocate);
87ecb68b 50VLANClientState *qemu_new_vlan_client(VLANState *vlan,
283c7c63 51 VLANClientState *peer,
bf38c1a0 52 const char *model,
7a9f6e4a 53 const char *name,
cda9046b
MM
54 NetCanReceive *can_receive,
55 NetReceive *receive,
56 NetReceiveIOV *receive_iov,
b946a153 57 NetCleanup *cleanup,
87ecb68b 58 void *opaque);
dcf414d6 59void qemu_del_vlan_client(VLANClientState *vc);
8b13c4a7 60VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
87ecb68b 61int qemu_can_send_packet(VLANClientState *vc);
fbe78f4f
AL
62ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
63 int iovcnt);
f3b6c7fc
MM
64ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
65 int iovcnt, NetPacketSent *sent_cb);
87ecb68b 66void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
f3b6c7fc
MM
67ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
68 int size, NetPacketSent *sent_cb);
8cad5516 69void qemu_purge_queued_packets(VLANClientState *vc);
f3b6c7fc 70void qemu_flush_queued_packets(VLANClientState *vc);
7cb7434b 71void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
76d32cba 72void qemu_macaddr_default_if_unset(MACAddr *macaddr);
07caea31 73int qemu_show_nic_models(const char *arg, const char *const *models);
d07f22c5 74void qemu_check_nic_model(NICInfo *nd, const char *model);
07caea31
MA
75int qemu_find_nic_model(NICInfo *nd, const char * const *models,
76 const char *default_model);
87ecb68b 77
376253ec 78void do_info_network(Monitor *mon);
f18c16de 79void do_set_link(Monitor *mon, const QDict *qdict);
87ecb68b 80
6dbe553f
JK
81void do_info_usernet(Monitor *mon);
82
87ecb68b
PB
83/* NIC info */
84
85#define MAX_NICS 8
ffe6370c
MT
86enum {
87 NIC_NVECTORS_UNSPECIFIED = -1
88};
87ecb68b
PB
89
90struct NICInfo {
91 uint8_t macaddr[6];
9203f520
MM
92 char *model;
93 char *name;
94 char *devaddr;
87ecb68b 95 VLANState *vlan;
5869c4d5 96 VLANClientState *netdev;
ae50b274 97 VLANClientState *vc;
72da4208 98 void *private;
7697079b 99 int used;
406c8df3 100 int bootable;
ffe6370c 101 int nvectors;
87ecb68b
PB
102};
103
104extern int nb_nics;
105extern NICInfo nd_table[MAX_NICS];
106
1ae26a18
AZ
107/* BT HCI info */
108
109struct HCIInfo {
110 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
111 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
112 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
113 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
114 void *opaque;
115 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
116 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
117};
118
119struct HCIInfo *qemu_next_hci(void);
120
48c64363
AL
121/* checksumming functions (net-checksum.c) */
122uint32_t net_checksum_add(int len, uint8_t *buf);
123uint16_t net_checksum_finish(uint32_t sum);
124uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
125 uint8_t *addrs, uint8_t *buf);
126void net_checksum_calculate(uint8_t *data, int length);
127
63a01ef8 128/* from net.c */
ad196a9d
JK
129extern const char *legacy_tftp_prefix;
130extern const char *legacy_bootp_filename;
131
f6b134ac 132int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
8b13c4a7 133void net_client_uninit(NICInfo *nd);
7f161aae 134int net_client_parse(QemuOptsList *opts_list, const char *str);
dc1c9fe8 135int net_init_clients(void);
0752706d 136int net_slirp_smb(const char *exported_dir);
1d4daa91
LC
137void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
138void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
0752706d 139int net_slirp_redir(const char *redir_str);
63a01ef8 140void net_cleanup(void);
406c8df3 141void net_set_boot_mask(int boot_mask);
f18c16de
LC
142void net_host_device_add(Monitor *mon, const QDict *qdict);
143void net_host_device_remove(Monitor *mon, const QDict *qdict);
63a01ef8 144
f54825cc
AJ
145#define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
146#define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
147#ifdef __sun__
148#define SMBD_COMMAND "/usr/sfw/sbin/smbd"
149#else
150#define SMBD_COMMAND "/usr/sbin/smbd"
151#endif
152
9d07d757
PB
153void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
154VLANClientState *qdev_get_vlan_client(DeviceState *dev,
cda9046b
MM
155 NetCanReceive *can_receive,
156 NetReceive *receive,
157 NetReceiveIOV *receive_iov,
9d07d757
PB
158 NetCleanup *cleanup,
159 void *opaque);
160
87ecb68b 161#endif