]> git.proxmox.com Git - qemu.git/blob - net.h
net: allow NICs to be connected to netdevs
[qemu.git] / net.h
1 #ifndef QEMU_NET_H
2 #define QEMU_NET_H
3
4 #include "qemu-queue.h"
5 #include "qemu-common.h"
6 #include "qdict.h"
7 #include "qemu-option.h"
8
9 /* VLANs support */
10
11 typedef struct VLANClientState VLANClientState;
12
13 typedef int (NetCanReceive)(VLANClientState *);
14 typedef ssize_t (NetReceive)(VLANClientState *, const uint8_t *, size_t);
15 typedef ssize_t (NetReceiveIOV)(VLANClientState *, const struct iovec *, int);
16 typedef void (NetCleanup) (VLANClientState *);
17 typedef void (LinkStatusChanged)(VLANClientState *);
18
19 struct VLANClientState {
20 NetReceive *receive;
21 NetReceiveIOV *receive_iov;
22 /* Packets may still be sent if this returns zero. It's used to
23 rate-limit the slirp code. */
24 NetCanReceive *can_receive;
25 NetCleanup *cleanup;
26 LinkStatusChanged *link_status_changed;
27 int link_down;
28 void *opaque;
29 QTAILQ_ENTRY(VLANClientState) next;
30 struct VLANState *vlan;
31 VLANClientState *peer;
32 char *model;
33 char *name;
34 char info_str[256];
35 };
36
37 typedef struct VLANPacket VLANPacket;
38
39 typedef void (NetPacketSent) (VLANClientState *, ssize_t);
40
41 struct VLANPacket {
42 QTAILQ_ENTRY(VLANPacket) entry;
43 VLANClientState *sender;
44 int size;
45 NetPacketSent *sent_cb;
46 uint8_t data[0];
47 };
48
49 struct VLANState {
50 int id;
51 QTAILQ_HEAD(, VLANClientState) clients;
52 QTAILQ_ENTRY(VLANState) next;
53 unsigned int nb_guest_devs, nb_host_devs;
54 QTAILQ_HEAD(send_queue, VLANPacket) send_queue;
55 int delivering;
56 };
57
58 VLANState *qemu_find_vlan(int id, int allocate);
59 VLANClientState *qemu_new_vlan_client(VLANState *vlan,
60 VLANClientState *peer,
61 const char *model,
62 const char *name,
63 NetCanReceive *can_receive,
64 NetReceive *receive,
65 NetReceiveIOV *receive_iov,
66 NetCleanup *cleanup,
67 void *opaque);
68 void qemu_del_vlan_client(VLANClientState *vc);
69 VLANClientState *qemu_find_vlan_client(VLANState *vlan, void *opaque);
70 int qemu_can_send_packet(VLANClientState *vc);
71 ssize_t qemu_sendv_packet(VLANClientState *vc, const struct iovec *iov,
72 int iovcnt);
73 ssize_t qemu_sendv_packet_async(VLANClientState *vc, const struct iovec *iov,
74 int iovcnt, NetPacketSent *sent_cb);
75 void qemu_send_packet(VLANClientState *vc, const uint8_t *buf, int size);
76 ssize_t qemu_send_packet_async(VLANClientState *vc, const uint8_t *buf,
77 int size, NetPacketSent *sent_cb);
78 void qemu_purge_queued_packets(VLANClientState *vc);
79 void qemu_flush_queued_packets(VLANClientState *vc);
80 void qemu_format_nic_info_str(VLANClientState *vc, uint8_t macaddr[6]);
81 int qemu_show_nic_models(const char *arg, const char *const *models);
82 void qemu_check_nic_model(NICInfo *nd, const char *model);
83 int qemu_find_nic_model(NICInfo *nd, const char * const *models,
84 const char *default_model);
85
86 void do_info_network(Monitor *mon);
87 void do_set_link(Monitor *mon, const QDict *qdict);
88
89 void do_info_usernet(Monitor *mon);
90
91 /* NIC info */
92
93 #define MAX_NICS 8
94 enum {
95 NIC_NVECTORS_UNSPECIFIED = -1
96 };
97
98 struct NICInfo {
99 uint8_t macaddr[6];
100 char *model;
101 char *name;
102 char *devaddr;
103 VLANState *vlan;
104 VLANClientState *netdev;
105 VLANClientState *vc;
106 void *private;
107 int used;
108 int bootable;
109 int nvectors;
110 };
111
112 extern int nb_nics;
113 extern NICInfo nd_table[MAX_NICS];
114
115 /* BT HCI info */
116
117 struct HCIInfo {
118 int (*bdaddr_set)(struct HCIInfo *hci, const uint8_t *bd_addr);
119 void (*cmd_send)(struct HCIInfo *hci, const uint8_t *data, int len);
120 void (*sco_send)(struct HCIInfo *hci, const uint8_t *data, int len);
121 void (*acl_send)(struct HCIInfo *hci, const uint8_t *data, int len);
122 void *opaque;
123 void (*evt_recv)(void *opaque, const uint8_t *data, int len);
124 void (*acl_recv)(void *opaque, const uint8_t *data, int len);
125 };
126
127 struct HCIInfo *qemu_next_hci(void);
128
129 /* checksumming functions (net-checksum.c) */
130 uint32_t net_checksum_add(int len, uint8_t *buf);
131 uint16_t net_checksum_finish(uint32_t sum);
132 uint16_t net_checksum_tcpudp(uint16_t length, uint16_t proto,
133 uint8_t *addrs, uint8_t *buf);
134 void net_checksum_calculate(uint8_t *data, int length);
135
136 /* from net.c */
137 extern const char *legacy_tftp_prefix;
138 extern const char *legacy_bootp_filename;
139
140 int net_client_init(Monitor *mon, QemuOpts *opts, int is_netdev);
141 void net_client_uninit(NICInfo *nd);
142 int net_client_parse(QemuOptsList *opts_list, const char *str);
143 int net_init_clients(void);
144 int net_slirp_smb(const char *exported_dir);
145 void net_slirp_hostfwd_add(Monitor *mon, const QDict *qdict);
146 void net_slirp_hostfwd_remove(Monitor *mon, const QDict *qdict);
147 int net_slirp_redir(const char *redir_str);
148 void net_cleanup(void);
149 void net_set_boot_mask(int boot_mask);
150 void net_host_device_add(Monitor *mon, const QDict *qdict);
151 void net_host_device_remove(Monitor *mon, const QDict *qdict);
152
153 #define DEFAULT_NETWORK_SCRIPT "/etc/qemu-ifup"
154 #define DEFAULT_NETWORK_DOWN_SCRIPT "/etc/qemu-ifdown"
155 #ifdef __sun__
156 #define SMBD_COMMAND "/usr/sfw/sbin/smbd"
157 #else
158 #define SMBD_COMMAND "/usr/sbin/smbd"
159 #endif
160
161 void qdev_get_macaddr(DeviceState *dev, uint8_t *macaddr);
162 VLANClientState *qdev_get_vlan_client(DeviceState *dev,
163 NetCanReceive *can_receive,
164 NetReceive *receive,
165 NetReceiveIOV *receive_iov,
166 NetCleanup *cleanup,
167 void *opaque);
168
169 #endif