bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 1995 Danny Gasparovski. |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 3 | * |
| 4 | * Please read the file COPYRIGHT for the |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 5 | * terms and conditions of the copyright. |
| 6 | */ |
| 7 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 8 | #ifndef _SLIRP_SOCKET_H_ |
| 9 | #define _SLIRP_SOCKET_H_ |
| 10 | |
| 11 | #define SO_EXPIRE 240000 |
| 12 | #define SO_EXPIREFAST 10000 |
| 13 | |
| 14 | /* |
| 15 | * Our socket structure |
| 16 | */ |
| 17 | |
| 18 | struct socket { |
| 19 | struct socket *so_next,*so_prev; /* For a linked list of sockets */ |
| 20 | |
| 21 | int s; /* The actual socket */ |
| 22 | |
Stefan Hajnoczi | 8917c3b | 2013-02-20 11:28:28 +0100 | [diff] [blame] | 23 | int pollfds_idx; /* GPollFD GArray index */ |
| 24 | |
Jan Kiszka | 460fec6 | 2009-06-24 14:42:31 +0200 | [diff] [blame] | 25 | Slirp *slirp; /* managing slirp instance */ |
| 26 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 27 | /* XXX union these with not-yet-used sbuf params */ |
| 28 | struct mbuf *so_m; /* Pointer to the original SYN packet, |
| 29 | * for non-blocking connect()'s, and |
| 30 | * PING reply's */ |
| 31 | struct tcpiphdr *so_ti; /* Pointer to the original ti within |
| 32 | * so_mconn, for non-blocking connections */ |
| 33 | int so_urgc; |
| 34 | struct in_addr so_faddr; /* foreign host table entry */ |
| 35 | struct in_addr so_laddr; /* local host table entry */ |
Stefan Weil | b6dce92 | 2010-07-22 22:15:23 +0200 | [diff] [blame] | 36 | uint16_t so_fport; /* foreign port */ |
| 37 | uint16_t so_lport; /* local port */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 38 | |
Stefan Weil | b6dce92 | 2010-07-22 22:15:23 +0200 | [diff] [blame] | 39 | uint8_t so_iptos; /* Type of service */ |
| 40 | uint8_t so_emu; /* Is the socket emulated? */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 41 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 42 | u_char so_type; /* Type of socket, UDP or TCP */ |
| 43 | int so_state; /* internal state flags SS_*, below */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 44 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 45 | struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */ |
| 46 | u_int so_expire; /* When the socket will expire */ |
ths | 3b46e62 | 2007-09-17 08:09:54 +0000 | [diff] [blame] | 47 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 48 | int so_queued; /* Number of packets queued from this socket */ |
| 49 | int so_nqueued; /* Number of packets queued in a row |
| 50 | * Used to determine when to "downgrade" a session |
| 51 | * from fastq to batchq */ |
ths | 5fafdf2 | 2007-09-16 21:08:06 +0000 | [diff] [blame] | 52 | |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 53 | struct sbuf so_rcv; /* Receive buffer */ |
| 54 | struct sbuf so_snd; /* Send buffer */ |
| 55 | void * extra; /* Extra pointer */ |
| 56 | }; |
| 57 | |
| 58 | |
| 59 | /* |
| 60 | * Socket state bits. (peer means the host on the Internet, |
| 61 | * local host means the host on the other end of the modem) |
| 62 | */ |
| 63 | #define SS_NOFDREF 0x001 /* No fd reference */ |
| 64 | |
| 65 | #define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */ |
| 66 | #define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */ |
| 67 | #define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */ |
| 68 | #define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */ |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 69 | #define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */ |
| 70 | |
| 71 | #define SS_CTL 0x080 |
| 72 | #define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */ |
| 73 | #define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */ |
| 74 | |
Jan Kiszka | f932b6c | 2009-06-24 14:42:29 +0200 | [diff] [blame] | 75 | #define SS_PERSISTENT_MASK 0xf000 /* Unremovable state bits */ |
Jan Kiszka | 6dd5ffb | 2009-06-24 14:42:29 +0200 | [diff] [blame] | 76 | #define SS_HOSTFWD 0x1000 /* Socket describes host->guest forwarding */ |
Jan Kiszka | 4a82347 | 2009-06-24 14:42:29 +0200 | [diff] [blame] | 77 | #define SS_INCOMING 0x2000 /* Connection was initiated by a host on the internet */ |
Jan Kiszka | f932b6c | 2009-06-24 14:42:29 +0200 | [diff] [blame] | 78 | |
Blue Swirl | 6cb9c6d | 2009-07-01 19:11:17 +0000 | [diff] [blame] | 79 | struct socket * solookup(struct socket *, struct in_addr, u_int, struct in_addr, u_int); |
| 80 | struct socket * socreate(Slirp *); |
| 81 | void sofree(struct socket *); |
| 82 | int soread(struct socket *); |
| 83 | void sorecvoob(struct socket *); |
| 84 | int sosendoob(struct socket *); |
| 85 | int sowrite(struct socket *); |
| 86 | void sorecvfrom(struct socket *); |
| 87 | int sosendto(struct socket *, struct mbuf *); |
Stefan Weil | b6dce92 | 2010-07-22 22:15:23 +0200 | [diff] [blame] | 88 | struct socket * tcp_listen(Slirp *, uint32_t, u_int, uint32_t, u_int, |
Blue Swirl | 6cb9c6d | 2009-07-01 19:11:17 +0000 | [diff] [blame] | 89 | int); |
| 90 | void soisfconnecting(register struct socket *); |
| 91 | void soisfconnected(register struct socket *); |
| 92 | void sofwdrain(struct socket *); |
blueswir1 | b9e82a5 | 2009-04-05 18:03:31 +0000 | [diff] [blame] | 93 | struct iovec; /* For win32 */ |
aliguori | e1c5a2b | 2009-01-08 19:18:21 +0000 | [diff] [blame] | 94 | size_t sopreprbuf(struct socket *so, struct iovec *iov, int *np); |
| 95 | int soreadbuf(struct socket *so, const char *buf, int size); |
bellard | f0cbd3e | 2004-04-22 00:10:48 +0000 | [diff] [blame] | 96 | |
| 97 | #endif /* _SOCKET_H_ */ |