Statistics
| Branch: | Revision:

root / net.h @ c5baaa48

History | View | Annotate | Download (5.4 kB)

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