VirtualBox

source: vbox/trunk/src/VBox/Devices/Network/slirp/socket.h@ 28023

最後變更 在這個檔案從28023是 28023,由 vboxsync 提交於 15 年 前

NAT: FD_CLOSE(win) and POLLHUB(Unix) events are processed in common way.

Darwin specific in handling closing connection was added.

  • 屬性 svn:eol-style 設為 native
檔案大小: 6.8 KB
 
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
23struct 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#ifndef RT_OS_WINDOWS
74 int so_poll_index;
75#endif /* !RT_OS_WINDOWS */
76 /*
77 * FD_CLOSE/POLLHUP event has been occurred on socket
78 */
79 int so_close;
80
81 void (* so_timeout)(PNATState pData, struct socket *so, void *arg);
82 void *so_timeout_arg;
83
84#ifdef VBOX_WITH_NAT_SERVICE
85 /* storage of source ether address */
86 unsigned char so_ethaddr[6];
87#endif
88 /* required for port-forwarding */
89 struct libalias *so_la;
90};
91
92#ifdef VBOX_WITH_SLIRP_MT
93# define SOCKET_LOCK(so) \
94 do { \
95 int rc; \
96 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
97 Log2(("lock:%s:%d L on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
98 Assert(!RTCritSectIsOwner(&(so)->so_mutex)); \
99 rc = RTCritSectEnter(&(so)->so_mutex); \
100 AssertRC(rc); \
101 } while (0)
102# define SOCKET_UNLOCK(so) \
103 do { \
104 int rc; \
105 if ((so) != NULL) Log2(("lock:%s:%d U on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
106 rc = RTCritSectLeave(&(so)->so_mutex); \
107 Assert(rc); \
108 } while (0)
109# define SOCKET_LOCK_CREATE(so) \
110 do { \
111 int rc; \
112 rc = RTCritSectInit(&(so)->so_mutex); \
113 AssertRC(rc); \
114 } while (0)
115# define SOCKET_LOCK_DESTROY(so) \
116 do { \
117 int rc = RTCritSectDelete(&(so)->so_mutex); \
118 AssertRC(rc); \
119 } while (0)
120#else
121# define SOCKET_LOCK(so) do {} while (0)
122# define SOCKET_UNLOCK(so) do {} while (0)
123# define SOCKET_LOCK_CREATE(so) do {} while (0)
124# define SOCKET_LOCK_DESTROY(so) do {} while (0)
125#endif
126/*
127 * Socket state bits. (peer means the host on the Internet,
128 * local host means the host on the other end of the modem)
129 */
130#define SS_NOFDREF 0x001 /* No fd reference */
131
132#define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
133#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
134#define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
135#define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
136/* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
137#define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
138
139/* #define SS_CTL 0x080 */
140#define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
141#define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
142
143extern struct socket tcb;
144
145#if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
146struct iovec
147{
148 char *iov_base;
149 size_t iov_len;
150};
151#endif
152
153void so_init (void);
154struct socket * solookup (struct socket *, struct in_addr, u_int, struct in_addr, u_int);
155struct socket * socreate (void);
156void sofree (PNATState, struct socket *);
157#ifdef VBOX_WITH_SLIRP_MT
158void soread_queue (PNATState, struct socket *, int *);
159#endif
160int soread (PNATState, struct socket *);
161void sorecvoob (PNATState, struct socket *);
162int sosendoob (struct socket *);
163int sowrite (PNATState, struct socket *);
164void sorecvfrom (PNATState, struct socket *);
165int sosendto (PNATState, struct socket *, struct mbuf *);
166struct socket * solisten (PNATState, u_int32_t, u_int, u_int32_t, u_int, int);
167void sorwakeup (struct socket *);
168void sowwakeup (struct socket *);
169void soisfconnecting (register struct socket *);
170void soisfconnected (register struct socket *);
171void sofcantrcvmore (struct socket *);
172void sofcantsendmore (struct socket *);
173void soisfdisconnected (struct socket *);
174void sofwdrain (struct socket *);
175
176#endif /* _SOCKET_H_ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette