1 | /*
|
---|
2 | * Copyright (c) 1995 Danny Gasparovski.
|
---|
3 | *
|
---|
4 | * Please read the file COPYRIGHT for the
|
---|
5 | * terms and conditions of the copyright.
|
---|
6 | */
|
---|
7 |
|
---|
8 | /* MINE */
|
---|
9 |
|
---|
10 | #ifndef _SLIRP_SOCKET_H_
|
---|
11 | #define _SLIRP_SOCKET_H_
|
---|
12 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
13 | #include <iprt/critsect.h>
|
---|
14 | #endif
|
---|
15 |
|
---|
16 | #define SO_EXPIRE 240000
|
---|
17 | #define SO_EXPIREFAST 10000
|
---|
18 |
|
---|
19 | /*
|
---|
20 | * Our socket structure
|
---|
21 | */
|
---|
22 |
|
---|
23 | struct socket
|
---|
24 | {
|
---|
25 | struct socket *so_next;
|
---|
26 | struct socket *so_prev; /* For a linked list of sockets */
|
---|
27 |
|
---|
28 | #if !defined(RT_OS_WINDOWS)
|
---|
29 | int s; /* The actual socket */
|
---|
30 | #else
|
---|
31 | union {
|
---|
32 | int s;
|
---|
33 | HANDLE sh;
|
---|
34 | };
|
---|
35 | uint64_t so_icmp_id; /* XXX: hack */
|
---|
36 | uint64_t so_icmp_seq; /* XXX: hack */
|
---|
37 | #endif
|
---|
38 |
|
---|
39 | /* XXX union these with not-yet-used sbuf params */
|
---|
40 | struct mbuf *so_m; /* Pointer to the original SYN packet,
|
---|
41 | * for non-blocking connect()'s, and
|
---|
42 | * PING reply's */
|
---|
43 | struct tcpiphdr *so_ti; /* Pointer to the original ti within
|
---|
44 | * so_mconn, for non-blocking connections */
|
---|
45 | int so_urgc;
|
---|
46 | struct in_addr so_faddr; /* foreign host table entry */
|
---|
47 | struct in_addr so_laddr; /* local host table entry */
|
---|
48 | u_int16_t so_fport; /* foreign port */
|
---|
49 | u_int16_t so_lport; /* local port */
|
---|
50 | u_int16_t so_hlport; /* host local port */
|
---|
51 | struct in_addr so_hladdr; /* local host addr */
|
---|
52 |
|
---|
53 | u_int8_t so_iptos; /* Type of service */
|
---|
54 | u_int8_t so_emu; /* Is the socket emulated? */
|
---|
55 |
|
---|
56 | u_char so_type; /* Type of socket, UDP or TCP */
|
---|
57 | int so_state; /* internal state flags SS_*, below */
|
---|
58 |
|
---|
59 | struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
|
---|
60 | u_int so_expire; /* When the socket will expire */
|
---|
61 |
|
---|
62 | int so_queued; /* Number of packets queued from this socket */
|
---|
63 | int so_nqueued; /* Number of packets queued in a row
|
---|
64 | * Used to determine when to "downgrade" a session
|
---|
65 | * from fastq to batchq */
|
---|
66 |
|
---|
67 | struct sbuf so_rcv; /* Receive buffer */
|
---|
68 | struct sbuf so_snd; /* Send buffer */
|
---|
69 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
70 | RTCRITSECT so_mutex;
|
---|
71 | int so_deleted;
|
---|
72 | #endif
|
---|
73 | #if defined(VBOX_WITH_SIMPLIFIED_SLIRP_SYNC) && !defined(RT_OS_WINDOWS)
|
---|
74 | int so_poll_index;
|
---|
75 | #endif
|
---|
76 | };
|
---|
77 |
|
---|
78 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
79 | # define SOCKET_LOCK(so) \
|
---|
80 | do { \
|
---|
81 | int rc; \
|
---|
82 | /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
|
---|
83 | Log2(("lock:%s:%d L on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
|
---|
84 | Assert(!RTCritSectIsOwner(&(so)->so_mutex)); \
|
---|
85 | rc = RTCritSectEnter(&(so)->so_mutex); \
|
---|
86 | AssertReleaseRC(rc); \
|
---|
87 | } while (0)
|
---|
88 | # define SOCKET_UNLOCK(so) \
|
---|
89 | do { \
|
---|
90 | int rc; \
|
---|
91 | if ((so) != NULL) Log2(("lock:%s:%d U on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
|
---|
92 | rc = RTCritSectLeave(&(so)->so_mutex); \
|
---|
93 | AssertReleaseRC(rc); \
|
---|
94 | } while (0)
|
---|
95 | # define SOCKET_LOCK_CREATE(so) \
|
---|
96 | do { \
|
---|
97 | int rc; \
|
---|
98 | rc = RTCritSectInit(&(so)->so_mutex); \
|
---|
99 | AssertReleaseRC(rc); \
|
---|
100 | } while (0)
|
---|
101 | # define SOCKET_LOCK_DESTROY(so) \
|
---|
102 | do { \
|
---|
103 | int rc = RTCritSectDelete(&(so)->so_mutex); \
|
---|
104 | AssertReleaseRC(rc); \
|
---|
105 | } while (0)
|
---|
106 | #else
|
---|
107 | # define SOCKET_LOCK(so) do {} while (0)
|
---|
108 | # define SOCKET_UNLOCK(so) do {} while (0)
|
---|
109 | # define SOCKET_LOCK_CREATE(so) do {} while (0)
|
---|
110 | # define SOCKET_LOCK_DESTROY(so) do {} while (0)
|
---|
111 | #endif
|
---|
112 | /*
|
---|
113 | * Socket state bits. (peer means the host on the Internet,
|
---|
114 | * local host means the host on the other end of the modem)
|
---|
115 | */
|
---|
116 | #define SS_NOFDREF 0x001 /* No fd reference */
|
---|
117 |
|
---|
118 | #define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
|
---|
119 | #define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
|
---|
120 | #define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
|
---|
121 | #define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
|
---|
122 | /* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
|
---|
123 | #define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
|
---|
124 |
|
---|
125 | /* #define SS_CTL 0x080 */
|
---|
126 | #define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
|
---|
127 | #define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
|
---|
128 |
|
---|
129 | extern struct socket tcb;
|
---|
130 |
|
---|
131 | #if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
|
---|
132 | struct iovec
|
---|
133 | {
|
---|
134 | char *iov_base;
|
---|
135 | size_t iov_len;
|
---|
136 | };
|
---|
137 | #endif
|
---|
138 |
|
---|
139 | void so_init _P((void));
|
---|
140 | struct socket * solookup _P((struct socket *, struct in_addr, u_int, struct in_addr, u_int));
|
---|
141 | struct socket * socreate _P((void));
|
---|
142 | void sofree _P((PNATState, struct socket *));
|
---|
143 | #ifdef VBOX_WITH_SLIRP_MT
|
---|
144 | void soread_queue (PNATState, struct socket *, int *);
|
---|
145 | #endif
|
---|
146 | int soread _P((PNATState, struct socket *));
|
---|
147 | void sorecvoob _P((PNATState, struct socket *));
|
---|
148 | int sosendoob _P((struct socket *));
|
---|
149 | int sowrite _P((PNATState, struct socket *));
|
---|
150 | void sorecvfrom _P((PNATState, struct socket *));
|
---|
151 | int sosendto _P((PNATState, struct socket *, struct mbuf *));
|
---|
152 | struct socket * solisten _P((PNATState, u_int, u_int32_t, u_int, int));
|
---|
153 | void sorwakeup _P((struct socket *));
|
---|
154 | void sowwakeup _P((struct socket *));
|
---|
155 | void soisfconnecting _P((register struct socket *));
|
---|
156 | void soisfconnected _P((register struct socket *));
|
---|
157 | void sofcantrcvmore _P((struct socket *));
|
---|
158 | void sofcantsendmore _P((struct socket *));
|
---|
159 | void soisfdisconnected _P((struct socket *));
|
---|
160 | void sofwdrain _P((struct socket *));
|
---|
161 |
|
---|
162 | #endif /* _SOCKET_H_ */
|
---|