1*0e62ebd2SMark Johnston /*- 2*0e62ebd2SMark Johnston * SPDX-License-Identifier: BSD-3-Clause 3*0e62ebd2SMark Johnston * 4*0e62ebd2SMark Johnston * Copyright (c) 1995,1996 Danny Gasparovski. All rights reserved. 5*0e62ebd2SMark Johnston * 6*0e62ebd2SMark Johnston * Redistribution and use in source and binary forms, with or without 7*0e62ebd2SMark Johnston * modification, are permitted provided that the following conditions 8*0e62ebd2SMark Johnston * are met: 9*0e62ebd2SMark Johnston * 1. Redistributions of source code must retain the above copyright 10*0e62ebd2SMark Johnston * notice, this list of conditions and the following disclaimer. 11*0e62ebd2SMark Johnston * 2. Redistributions in binary form must reproduce the above copyright 12*0e62ebd2SMark Johnston * notice, this list of conditions and the following disclaimer in the 13*0e62ebd2SMark Johnston * documentation and/or other materials provided with the distribution. 14*0e62ebd2SMark Johnston * 3. Neither the name of the copyright holder nor the names of its 15*0e62ebd2SMark Johnston * contributors may be used to endorse or promote products derived 16*0e62ebd2SMark Johnston * from this software without specific prior written permission. 17*0e62ebd2SMark Johnston * 18*0e62ebd2SMark Johnston * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, 19*0e62ebd2SMark Johnston * INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY 20*0e62ebd2SMark Johnston * AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 21*0e62ebd2SMark Johnston * DANNY GASPAROVSKI OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, 22*0e62ebd2SMark Johnston * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT 23*0e62ebd2SMark Johnston * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24*0e62ebd2SMark Johnston * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25*0e62ebd2SMark Johnston * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26*0e62ebd2SMark Johnston * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF 27*0e62ebd2SMark Johnston * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28*0e62ebd2SMark Johnston */ 29*0e62ebd2SMark Johnston 30*0e62ebd2SMark Johnston #ifndef LIBSLIRP_H 31*0e62ebd2SMark Johnston #define LIBSLIRP_H 32*0e62ebd2SMark Johnston 33*0e62ebd2SMark Johnston #include <stdint.h> 34*0e62ebd2SMark Johnston #include <stdbool.h> 35*0e62ebd2SMark Johnston #include <sys/types.h> 36*0e62ebd2SMark Johnston 37*0e62ebd2SMark Johnston #ifdef _WIN32 38*0e62ebd2SMark Johnston #include <winsock2.h> 39*0e62ebd2SMark Johnston #include <ws2tcpip.h> 40*0e62ebd2SMark Johnston #include <in6addr.h> 41*0e62ebd2SMark Johnston #include <basetsd.h> 42*0e62ebd2SMark Johnston typedef SSIZE_T slirp_ssize_t; 43*0e62ebd2SMark Johnston #ifdef BUILDING_LIBSLIRP 44*0e62ebd2SMark Johnston # define SLIRP_EXPORT __declspec(dllexport) 45*0e62ebd2SMark Johnston #else 46*0e62ebd2SMark Johnston # define SLIRP_EXPORT __declspec(dllimport) 47*0e62ebd2SMark Johnston #endif 48*0e62ebd2SMark Johnston #else 49*0e62ebd2SMark Johnston #include <sys/types.h> 50*0e62ebd2SMark Johnston typedef ssize_t slirp_ssize_t; 51*0e62ebd2SMark Johnston #include <netinet/in.h> 52*0e62ebd2SMark Johnston #include <arpa/inet.h> 53*0e62ebd2SMark Johnston #define SLIRP_EXPORT 54*0e62ebd2SMark Johnston #endif 55*0e62ebd2SMark Johnston 56*0e62ebd2SMark Johnston #ifdef __cplusplus 57*0e62ebd2SMark Johnston extern "C" { 58*0e62ebd2SMark Johnston #endif 59*0e62ebd2SMark Johnston 60*0e62ebd2SMark Johnston /* Opaque structure containing the slirp state */ 61*0e62ebd2SMark Johnston typedef struct Slirp Slirp; 62*0e62ebd2SMark Johnston 63*0e62ebd2SMark Johnston /* Flags passed to SlirpAddPollCb and to be returned by SlirpGetREventsCb. */ 64*0e62ebd2SMark Johnston enum { 65*0e62ebd2SMark Johnston SLIRP_POLL_IN = 1 << 0, 66*0e62ebd2SMark Johnston SLIRP_POLL_OUT = 1 << 1, 67*0e62ebd2SMark Johnston SLIRP_POLL_PRI = 1 << 2, 68*0e62ebd2SMark Johnston SLIRP_POLL_ERR = 1 << 3, 69*0e62ebd2SMark Johnston SLIRP_POLL_HUP = 1 << 4, 70*0e62ebd2SMark Johnston }; 71*0e62ebd2SMark Johnston 72*0e62ebd2SMark Johnston /* Callback for application to get data from the guest */ 73*0e62ebd2SMark Johnston typedef slirp_ssize_t (*SlirpReadCb)(void *buf, size_t len, void *opaque); 74*0e62ebd2SMark Johnston /* Callback for application to send data to the guest */ 75*0e62ebd2SMark Johnston typedef slirp_ssize_t (*SlirpWriteCb)(const void *buf, size_t len, void *opaque); 76*0e62ebd2SMark Johnston /* Timer callback */ 77*0e62ebd2SMark Johnston typedef void (*SlirpTimerCb)(void *opaque); 78*0e62ebd2SMark Johnston /* Callback for libslirp to register polling callbacks */ 79*0e62ebd2SMark Johnston typedef int (*SlirpAddPollCb)(int fd, int events, void *opaque); 80*0e62ebd2SMark Johnston /* Callback for libslirp to get polling result */ 81*0e62ebd2SMark Johnston typedef int (*SlirpGetREventsCb)(int idx, void *opaque); 82*0e62ebd2SMark Johnston 83*0e62ebd2SMark Johnston /* For now libslirp creates only a timer for the IPv6 RA */ 84*0e62ebd2SMark Johnston typedef enum SlirpTimerId { 85*0e62ebd2SMark Johnston SLIRP_TIMER_RA, 86*0e62ebd2SMark Johnston SLIRP_TIMER_NUM, 87*0e62ebd2SMark Johnston } SlirpTimerId; 88*0e62ebd2SMark Johnston 89*0e62ebd2SMark Johnston /* 90*0e62ebd2SMark Johnston * Callbacks from slirp, to be set by the application. 91*0e62ebd2SMark Johnston * 92*0e62ebd2SMark Johnston * The opaque parameter is set to the opaque pointer given in the slirp_new / 93*0e62ebd2SMark Johnston * slirp_init call. 94*0e62ebd2SMark Johnston */ 95*0e62ebd2SMark Johnston typedef struct SlirpCb { 96*0e62ebd2SMark Johnston /* 97*0e62ebd2SMark Johnston * Send an ethernet frame to the guest network. The opaque parameter is the 98*0e62ebd2SMark Johnston * one given to slirp_init(). If the guest is not ready to receive a frame, 99*0e62ebd2SMark Johnston * the function can just drop the data. TCP will then handle retransmissions 100*0e62ebd2SMark Johnston * at a lower pace. 101*0e62ebd2SMark Johnston * <0 reports an IO error. 102*0e62ebd2SMark Johnston */ 103*0e62ebd2SMark Johnston SlirpWriteCb send_packet; 104*0e62ebd2SMark Johnston /* Print a message for an error due to guest misbehavior. */ 105*0e62ebd2SMark Johnston void (*guest_error)(const char *msg, void *opaque); 106*0e62ebd2SMark Johnston /* Return the virtual clock value in nanoseconds */ 107*0e62ebd2SMark Johnston int64_t (*clock_get_ns)(void *opaque); 108*0e62ebd2SMark Johnston /* Create a new timer with the given callback and opaque data. Not 109*0e62ebd2SMark Johnston * needed if timer_new_opaque is provided. */ 110*0e62ebd2SMark Johnston void *(*timer_new)(SlirpTimerCb cb, void *cb_opaque, void *opaque); 111*0e62ebd2SMark Johnston /* Remove and free a timer */ 112*0e62ebd2SMark Johnston void (*timer_free)(void *timer, void *opaque); 113*0e62ebd2SMark Johnston /* Modify a timer to expire at @expire_time (ms) */ 114*0e62ebd2SMark Johnston void (*timer_mod)(void *timer, int64_t expire_time, void *opaque); 115*0e62ebd2SMark Johnston /* Register a fd for future polling */ 116*0e62ebd2SMark Johnston void (*register_poll_fd)(int fd, void *opaque); 117*0e62ebd2SMark Johnston /* Unregister a fd */ 118*0e62ebd2SMark Johnston void (*unregister_poll_fd)(int fd, void *opaque); 119*0e62ebd2SMark Johnston /* Kick the io-thread, to signal that new events may be processed because some TCP buffer 120*0e62ebd2SMark Johnston * can now receive more data, i.e. slirp_socket_can_recv will return 1. */ 121*0e62ebd2SMark Johnston void (*notify)(void *opaque); 122*0e62ebd2SMark Johnston 123*0e62ebd2SMark Johnston /* 124*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 4 begin 125*0e62ebd2SMark Johnston */ 126*0e62ebd2SMark Johnston 127*0e62ebd2SMark Johnston /* Initialization has completed and a Slirp* has been created. */ 128*0e62ebd2SMark Johnston void (*init_completed)(Slirp *slirp, void *opaque); 129*0e62ebd2SMark Johnston /* Create a new timer. When the timer fires, the application passes 130*0e62ebd2SMark Johnston * the SlirpTimerId and cb_opaque to slirp_handle_timer. */ 131*0e62ebd2SMark Johnston void *(*timer_new_opaque)(SlirpTimerId id, void *cb_opaque, void *opaque); 132*0e62ebd2SMark Johnston } SlirpCb; 133*0e62ebd2SMark Johnston 134*0e62ebd2SMark Johnston #define SLIRP_CONFIG_VERSION_MIN 1 135*0e62ebd2SMark Johnston #define SLIRP_CONFIG_VERSION_MAX 5 136*0e62ebd2SMark Johnston 137*0e62ebd2SMark Johnston typedef struct SlirpConfig { 138*0e62ebd2SMark Johnston /* Version must be provided */ 139*0e62ebd2SMark Johnston uint32_t version; 140*0e62ebd2SMark Johnston /* 141*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 1 begin 142*0e62ebd2SMark Johnston */ 143*0e62ebd2SMark Johnston /* Whether to prevent the guest from accessing the Internet */ 144*0e62ebd2SMark Johnston int restricted; 145*0e62ebd2SMark Johnston /* Whether IPv4 is enabled */ 146*0e62ebd2SMark Johnston bool in_enabled; 147*0e62ebd2SMark Johnston /* Virtual network for the guest */ 148*0e62ebd2SMark Johnston struct in_addr vnetwork; 149*0e62ebd2SMark Johnston /* Mask for the virtual network for the guest */ 150*0e62ebd2SMark Johnston struct in_addr vnetmask; 151*0e62ebd2SMark Johnston /* Virtual address for the host exposed to the guest */ 152*0e62ebd2SMark Johnston struct in_addr vhost; 153*0e62ebd2SMark Johnston /* Whether IPv6 is enabled */ 154*0e62ebd2SMark Johnston bool in6_enabled; 155*0e62ebd2SMark Johnston /* Virtual IPv6 network for the guest */ 156*0e62ebd2SMark Johnston struct in6_addr vprefix_addr6; 157*0e62ebd2SMark Johnston /* Len of the virtual IPv6 network for the guest */ 158*0e62ebd2SMark Johnston uint8_t vprefix_len; 159*0e62ebd2SMark Johnston /* Virtual address for the host exposed to the guest */ 160*0e62ebd2SMark Johnston struct in6_addr vhost6; 161*0e62ebd2SMark Johnston /* Hostname exposed to the guest in DHCP hostname option */ 162*0e62ebd2SMark Johnston const char *vhostname; 163*0e62ebd2SMark Johnston /* Hostname exposed to the guest in the DHCP TFTP server name option */ 164*0e62ebd2SMark Johnston const char *tftp_server_name; 165*0e62ebd2SMark Johnston /* Path of the files served by TFTP */ 166*0e62ebd2SMark Johnston const char *tftp_path; 167*0e62ebd2SMark Johnston /* Boot file name exposed to the guest via DHCP */ 168*0e62ebd2SMark Johnston const char *bootfile; 169*0e62ebd2SMark Johnston /* Start of the DHCP range */ 170*0e62ebd2SMark Johnston struct in_addr vdhcp_start; 171*0e62ebd2SMark Johnston /* Virtual address for the DNS server exposed to the guest */ 172*0e62ebd2SMark Johnston struct in_addr vnameserver; 173*0e62ebd2SMark Johnston /* Virtual IPv6 address for the DNS server exposed to the guest */ 174*0e62ebd2SMark Johnston struct in6_addr vnameserver6; 175*0e62ebd2SMark Johnston /* DNS search names exposed to the guest via DHCP */ 176*0e62ebd2SMark Johnston const char **vdnssearch; 177*0e62ebd2SMark Johnston /* Domain name exposed to the guest via DHCP */ 178*0e62ebd2SMark Johnston const char *vdomainname; 179*0e62ebd2SMark Johnston /* MTU when sending packets to the guest */ 180*0e62ebd2SMark Johnston /* Default: IF_MTU_DEFAULT */ 181*0e62ebd2SMark Johnston size_t if_mtu; 182*0e62ebd2SMark Johnston /* MRU when receiving packets from the guest */ 183*0e62ebd2SMark Johnston /* Default: IF_MRU_DEFAULT */ 184*0e62ebd2SMark Johnston size_t if_mru; 185*0e62ebd2SMark Johnston /* Prohibit connecting to 127.0.0.1:* */ 186*0e62ebd2SMark Johnston bool disable_host_loopback; 187*0e62ebd2SMark Johnston /* 188*0e62ebd2SMark Johnston * Enable emulation code (*warning*: this code isn't safe, it is not 189*0e62ebd2SMark Johnston * recommended to enable it) 190*0e62ebd2SMark Johnston */ 191*0e62ebd2SMark Johnston bool enable_emu; 192*0e62ebd2SMark Johnston 193*0e62ebd2SMark Johnston /* 194*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 2 begin 195*0e62ebd2SMark Johnston */ 196*0e62ebd2SMark Johnston /* Address to be used when sending data to the Internet */ 197*0e62ebd2SMark Johnston struct sockaddr_in *outbound_addr; 198*0e62ebd2SMark Johnston /* IPv6 Address to be used when sending data to the Internet */ 199*0e62ebd2SMark Johnston struct sockaddr_in6 *outbound_addr6; 200*0e62ebd2SMark Johnston 201*0e62ebd2SMark Johnston /* 202*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 3 begin 203*0e62ebd2SMark Johnston */ 204*0e62ebd2SMark Johnston /* slirp will not redirect/serve any DNS packet */ 205*0e62ebd2SMark Johnston bool disable_dns; 206*0e62ebd2SMark Johnston 207*0e62ebd2SMark Johnston /* 208*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 4 begin 209*0e62ebd2SMark Johnston */ 210*0e62ebd2SMark Johnston /* slirp will not reply to any DHCP requests */ 211*0e62ebd2SMark Johnston bool disable_dhcp; 212*0e62ebd2SMark Johnston 213*0e62ebd2SMark Johnston /* 214*0e62ebd2SMark Johnston * Fields introduced in SlirpConfig version 5 begin 215*0e62ebd2SMark Johnston */ 216*0e62ebd2SMark Johnston /* Manufacturer ID (IANA Private Enterprise number) */ 217*0e62ebd2SMark Johnston uint32_t mfr_id; 218*0e62ebd2SMark Johnston /* 219*0e62ebd2SMark Johnston * MAC address allocated for an out-of-band management controller, to be 220*0e62ebd2SMark Johnston * retrieved through NC-SI. 221*0e62ebd2SMark Johnston */ 222*0e62ebd2SMark Johnston uint8_t oob_eth_addr[6]; 223*0e62ebd2SMark Johnston } SlirpConfig; 224*0e62ebd2SMark Johnston 225*0e62ebd2SMark Johnston /* Create a new instance of a slirp stack */ 226*0e62ebd2SMark Johnston SLIRP_EXPORT 227*0e62ebd2SMark Johnston Slirp *slirp_new(const SlirpConfig *cfg, const SlirpCb *callbacks, 228*0e62ebd2SMark Johnston void *opaque); 229*0e62ebd2SMark Johnston /* slirp_init is deprecated in favor of slirp_new */ 230*0e62ebd2SMark Johnston SLIRP_EXPORT 231*0e62ebd2SMark Johnston Slirp *slirp_init(int restricted, bool in_enabled, struct in_addr vnetwork, 232*0e62ebd2SMark Johnston struct in_addr vnetmask, struct in_addr vhost, 233*0e62ebd2SMark Johnston bool in6_enabled, struct in6_addr vprefix_addr6, 234*0e62ebd2SMark Johnston uint8_t vprefix_len, struct in6_addr vhost6, 235*0e62ebd2SMark Johnston const char *vhostname, const char *tftp_server_name, 236*0e62ebd2SMark Johnston const char *tftp_path, const char *bootfile, 237*0e62ebd2SMark Johnston struct in_addr vdhcp_start, struct in_addr vnameserver, 238*0e62ebd2SMark Johnston struct in6_addr vnameserver6, const char **vdnssearch, 239*0e62ebd2SMark Johnston const char *vdomainname, const SlirpCb *callbacks, 240*0e62ebd2SMark Johnston void *opaque); 241*0e62ebd2SMark Johnston /* Shut down an instance of a slirp stack */ 242*0e62ebd2SMark Johnston SLIRP_EXPORT 243*0e62ebd2SMark Johnston void slirp_cleanup(Slirp *slirp); 244*0e62ebd2SMark Johnston 245*0e62ebd2SMark Johnston /* This is called by the application when it is about to sleep through poll(). 246*0e62ebd2SMark Johnston * *timeout is set to the amount of virtual time (in ms) that the application intends to 247*0e62ebd2SMark Johnston * wait (UINT32_MAX if infinite). slirp_pollfds_fill updates it according to 248*0e62ebd2SMark Johnston * e.g. TCP timers, so the application knows it should sleep a smaller amount of 249*0e62ebd2SMark Johnston * time. slirp_pollfds_fill calls add_poll for each file descriptor 250*0e62ebd2SMark Johnston * that should be monitored along the sleep. The opaque pointer is passed as 251*0e62ebd2SMark Johnston * such to add_poll, and add_poll returns an index. */ 252*0e62ebd2SMark Johnston SLIRP_EXPORT 253*0e62ebd2SMark Johnston void slirp_pollfds_fill(Slirp *slirp, uint32_t *timeout, 254*0e62ebd2SMark Johnston SlirpAddPollCb add_poll, void *opaque); 255*0e62ebd2SMark Johnston 256*0e62ebd2SMark Johnston /* This is called by the application after sleeping, to report which file 257*0e62ebd2SMark Johnston * descriptors are available. slirp_pollfds_poll calls get_revents on each file 258*0e62ebd2SMark Johnston * descriptor, giving it the index that add_poll returned during the 259*0e62ebd2SMark Johnston * slirp_pollfds_fill call, to know whether the descriptor is available for 260*0e62ebd2SMark Johnston * read/write/etc. (SLIRP_POLL_*) 261*0e62ebd2SMark Johnston * select_error should be passed 1 if poll() returned an error. */ 262*0e62ebd2SMark Johnston SLIRP_EXPORT 263*0e62ebd2SMark Johnston void slirp_pollfds_poll(Slirp *slirp, int select_error, 264*0e62ebd2SMark Johnston SlirpGetREventsCb get_revents, void *opaque); 265*0e62ebd2SMark Johnston 266*0e62ebd2SMark Johnston /* This is called by the application when the guest emits a packet on the 267*0e62ebd2SMark Johnston * guest network, to be interpreted by slirp. */ 268*0e62ebd2SMark Johnston SLIRP_EXPORT 269*0e62ebd2SMark Johnston void slirp_input(Slirp *slirp, const uint8_t *pkt, int pkt_len); 270*0e62ebd2SMark Johnston 271*0e62ebd2SMark Johnston /* This is called by the application when a timer expires, if it provides 272*0e62ebd2SMark Johnston * the timer_new_opaque callback. It is not needed if the application only 273*0e62ebd2SMark Johnston * uses timer_new. */ 274*0e62ebd2SMark Johnston SLIRP_EXPORT 275*0e62ebd2SMark Johnston void slirp_handle_timer(Slirp *slirp, SlirpTimerId id, void *cb_opaque); 276*0e62ebd2SMark Johnston 277*0e62ebd2SMark Johnston /* These set up / remove port forwarding between a host port in the real world 278*0e62ebd2SMark Johnston * and the guest network. */ 279*0e62ebd2SMark Johnston SLIRP_EXPORT 280*0e62ebd2SMark Johnston int slirp_add_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, 281*0e62ebd2SMark Johnston int host_port, struct in_addr guest_addr, int guest_port); 282*0e62ebd2SMark Johnston SLIRP_EXPORT 283*0e62ebd2SMark Johnston int slirp_remove_hostfwd(Slirp *slirp, int is_udp, struct in_addr host_addr, 284*0e62ebd2SMark Johnston int host_port); 285*0e62ebd2SMark Johnston 286*0e62ebd2SMark Johnston #define SLIRP_HOSTFWD_UDP 1 287*0e62ebd2SMark Johnston #define SLIRP_HOSTFWD_V6ONLY 2 288*0e62ebd2SMark Johnston SLIRP_EXPORT 289*0e62ebd2SMark Johnston int slirp_add_hostxfwd(Slirp *slirp, 290*0e62ebd2SMark Johnston const struct sockaddr *haddr, socklen_t haddrlen, 291*0e62ebd2SMark Johnston const struct sockaddr *gaddr, socklen_t gaddrlen, 292*0e62ebd2SMark Johnston int flags); 293*0e62ebd2SMark Johnston SLIRP_EXPORT 294*0e62ebd2SMark Johnston int slirp_remove_hostxfwd(Slirp *slirp, 295*0e62ebd2SMark Johnston const struct sockaddr *haddr, socklen_t haddrlen, 296*0e62ebd2SMark Johnston int flags); 297*0e62ebd2SMark Johnston 298*0e62ebd2SMark Johnston /* Set up port forwarding between a port in the guest network and a 299*0e62ebd2SMark Johnston * command running on the host */ 300*0e62ebd2SMark Johnston SLIRP_EXPORT 301*0e62ebd2SMark Johnston int slirp_add_exec(Slirp *slirp, const char *cmdline, 302*0e62ebd2SMark Johnston struct in_addr *guest_addr, int guest_port); 303*0e62ebd2SMark Johnston /* Set up port forwarding between a port in the guest network and a 304*0e62ebd2SMark Johnston * Unix port on the host */ 305*0e62ebd2SMark Johnston SLIRP_EXPORT 306*0e62ebd2SMark Johnston int slirp_add_unix(Slirp *slirp, const char *unixsock, 307*0e62ebd2SMark Johnston struct in_addr *guest_addr, int guest_port); 308*0e62ebd2SMark Johnston /* Set up port forwarding between a port in the guest network and a 309*0e62ebd2SMark Johnston * callback that will receive the data coming from the port */ 310*0e62ebd2SMark Johnston SLIRP_EXPORT 311*0e62ebd2SMark Johnston int slirp_add_guestfwd(Slirp *slirp, SlirpWriteCb write_cb, void *opaque, 312*0e62ebd2SMark Johnston struct in_addr *guest_addr, int guest_port); 313*0e62ebd2SMark Johnston 314*0e62ebd2SMark Johnston /* TODO: rather identify a guestfwd through an opaque pointer instead of through 315*0e62ebd2SMark Johnston * the guest_addr */ 316*0e62ebd2SMark Johnston 317*0e62ebd2SMark Johnston /* This is called by the application for a guestfwd, to determine how much data 318*0e62ebd2SMark Johnston * can be received by the forwarded port through a call to slirp_socket_recv. */ 319*0e62ebd2SMark Johnston SLIRP_EXPORT 320*0e62ebd2SMark Johnston size_t slirp_socket_can_recv(Slirp *slirp, struct in_addr guest_addr, 321*0e62ebd2SMark Johnston int guest_port); 322*0e62ebd2SMark Johnston /* This is called by the application for a guestfwd, to provide the data to be 323*0e62ebd2SMark Johnston * sent on the forwarded port */ 324*0e62ebd2SMark Johnston SLIRP_EXPORT 325*0e62ebd2SMark Johnston void slirp_socket_recv(Slirp *slirp, struct in_addr guest_addr, int guest_port, 326*0e62ebd2SMark Johnston const uint8_t *buf, int size); 327*0e62ebd2SMark Johnston 328*0e62ebd2SMark Johnston /* Remove entries added by slirp_add_exec, slirp_add_unix or slirp_add_guestfwd */ 329*0e62ebd2SMark Johnston SLIRP_EXPORT 330*0e62ebd2SMark Johnston int slirp_remove_guestfwd(Slirp *slirp, struct in_addr guest_addr, 331*0e62ebd2SMark Johnston int guest_port); 332*0e62ebd2SMark Johnston 333*0e62ebd2SMark Johnston /* Return a human-readable state of the slirp stack */ 334*0e62ebd2SMark Johnston SLIRP_EXPORT 335*0e62ebd2SMark Johnston char *slirp_connection_info(Slirp *slirp); 336*0e62ebd2SMark Johnston 337*0e62ebd2SMark Johnston /* Return a human-readable state of the NDP/ARP tables */ 338*0e62ebd2SMark Johnston SLIRP_EXPORT 339*0e62ebd2SMark Johnston char *slirp_neighbor_info(Slirp *slirp); 340*0e62ebd2SMark Johnston 341*0e62ebd2SMark Johnston /* Save the slirp state through the write_cb. The opaque pointer is passed as 342*0e62ebd2SMark Johnston * such to the write_cb. */ 343*0e62ebd2SMark Johnston SLIRP_EXPORT 344*0e62ebd2SMark Johnston int slirp_state_save(Slirp *s, SlirpWriteCb write_cb, void *opaque); 345*0e62ebd2SMark Johnston 346*0e62ebd2SMark Johnston /* Returns the version of the slirp state, to be saved along the state */ 347*0e62ebd2SMark Johnston SLIRP_EXPORT 348*0e62ebd2SMark Johnston int slirp_state_version(void); 349*0e62ebd2SMark Johnston 350*0e62ebd2SMark Johnston /* Load the slirp state through the read_cb. The opaque pointer is passed as 351*0e62ebd2SMark Johnston * such to the read_cb. The version should be given as it was obtained from 352*0e62ebd2SMark Johnston * slirp_state_version when slirp_state_save was called. */ 353*0e62ebd2SMark Johnston SLIRP_EXPORT 354*0e62ebd2SMark Johnston int slirp_state_load(Slirp *s, int version_id, SlirpReadCb read_cb, 355*0e62ebd2SMark Johnston void *opaque); 356*0e62ebd2SMark Johnston 357*0e62ebd2SMark Johnston /* Return the version of the slirp implementation */ 358*0e62ebd2SMark Johnston SLIRP_EXPORT 359*0e62ebd2SMark Johnston const char *slirp_version_string(void); 360*0e62ebd2SMark Johnston 361*0e62ebd2SMark Johnston #ifdef __cplusplus 362*0e62ebd2SMark Johnston } /* extern "C" */ 363*0e62ebd2SMark Johnston #endif 364*0e62ebd2SMark Johnston 365*0e62ebd2SMark Johnston #endif /* LIBSLIRP_H */ 366