]> git.proxmox.com Git - mirror_qemu.git/blob - slirp/libslirp.h
slirp: use polling callbacks, drop glib requirement
[mirror_qemu.git] / slirp / libslirp.h
1 #ifndef LIBSLIRP_H
2 #define LIBSLIRP_H
3
4 #include <stdint.h>
5 #include <stdbool.h>
6
7 #ifdef _WIN32
8 #include <winsock2.h>
9 #include <in6addr.h>
10 #else
11 #include <netinet/in.h>
12 #include <arpa/inet.h>
13 #endif
14
15 typedef struct Slirp Slirp;
16
17 enum {
18 SLIRP_POLL_IN = 1 << 0,
19 SLIRP_POLL_OUT = 1 << 1,
20 SLIRP_POLL_PRI = 1 << 2,
21 SLIRP_POLL_ERR = 1 << 3,
22 SLIRP_POLL_HUP = 1 << 4,
23 };
24
25 typedef ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque);
26 typedef void (*SlirpTimerCb)(void *opaque);
27 typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque);
28 typedef int (*SlirpGetREventsCb)(int idx, void *opaque);
29
30 /*
31 * Callbacks from slirp
32 */
33 typedef struct SlirpCb {
34 /*
35 * Send an ethernet frame to the guest network. The opaque
36 * parameter is the one given to slirp_init(). The function
37 * doesn't need to send all the data and may return <len (no
38 * buffering is done on libslirp side, so the data will be dropped
39 * in this case). <0 reports an IO error.
40 */
41 SlirpWriteCb send_packet;
42 /* Print a message for an error due to guest misbehavior. */
43 void (*guest_error)(const char *msg);
44 /* Return the virtual clock value in nanoseconds */
45 int64_t (*clock_get_ns)(void);
46 /* Create a new timer with the given callback and opaque data */
47 void *(*timer_new)(SlirpTimerCb cb, void *opaque);
48 /* Remove and free a timer */
49 void (*timer_free)(void *timer);
50 /* Modify a timer to expire at @expire_time */
51 void (*timer_mod)(void *timer, int64_t expire_time);
52 /* Register a fd for future polling */
53 void (*register_poll_fd)(int fd);
54 /* Unregister a fd */
55 void (*unregister_poll_fd)(int fd);
56 /* Kick the io-thread, to signal that new events may be processed */
57 void (*notify)(void);
58 } SlirpCb;
59
60
61 Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork,
62 struct in_addr vnetmask, struct in_addr vhost,
63 bool in6_enabled,
64 struct in6_addr vprefix_addr6, uint8_t vprefix_len,
65 struct in6_addr vhost6, const char *vhostname,
66 const char *tftp_server_name,
67 const char *tftp_path, const char *bootfile,
68 struct in_addr vdhcp_start, struct in_addr vnameserver,
69 struct in6_addr vnameserver6, const char **vdnssearch,
70 const char *vdomainname,
71 const SlirpCb *callbacks,
72 void *opaque);
73 void slirp_cleanup(Slirp *slirp);
74
75 void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout,
76 SlirpAddPollCb add_poll, void *opaque);
77
78 void slirp_pollfds_poll(Slirp *slirp, int select_error,
79 SlirpGetREventsCb get_revents, void *opaque);
80
81 void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len);
82
83 int slirp_add_hostfwd(Slirp *slirp, int is_udp,
84 struct in_addr host_addr, int host_port,
85 struct in_addr guest_addr, int guest_port);
86 int slirp_remove_hostfwd(Slirp *slirp, int is_udp,
87 struct in_addr host_addr, int host_port);
88 int slirp_add_exec(Slirp *slirp, const char *cmdline,
89 struct in_addr *guest_addr, int guest_port);
90 int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque,
91 struct in_addr *guest_addr, int guest_port);
92
93 char *slirp_connection_info(Slirp *slirp);
94
95 void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr,
96 int guest_port, const uint8_t *buf, int size);
97 size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr,
98 int guest_port);
99
100 #endif