VirtualBox

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

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

NAT: slirp file headers

  • 屬性 svn:eol-style 設為 native
  • 屬性 svn:keywords 設為 Author Date Id Revision
檔案大小: 7.6 KB
 
1/* $Id: socket.h 28449 2010-04-19 09:52:59Z vboxsync $ */
2/** @file
3 * NAT - socket handling (declarations/defines).
4 */
5
6/*
7 * Copyright (C) 2006-2010 Sun Microsystems, Inc.
8 *
9 * This file is part of VirtualBox Open Source Edition (OSE), as
10 * available from http://www.alldomusa.eu.org. This file is free software;
11 * you can redistribute it and/or modify it under the terms of the GNU
12 * General Public License (GPL) as published by the Free Software
13 * Foundation, in version 2 as it comes in the "COPYING" file of the
14 * VirtualBox OSE distribution. VirtualBox OSE is distributed in the
15 * hope that it will be useful, but WITHOUT ANY WARRANTY of any kind.
16 *
17 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
18 * Clara, CA 95054 USA or visit http://www.sun.com if you need
19 * additional information or have any questions.
20 */
21
22/*
23 * This code is based on:
24 *
25 * Copyright (c) 1995 Danny Gasparovski.
26 *
27 * Please read the file COPYRIGHT for the
28 * terms and conditions of the copyright.
29 */
30
31/* MINE */
32
33#ifndef _SLIRP_SOCKET_H_
34#define _SLIRP_SOCKET_H_
35#ifdef VBOX_WITH_SLIRP_MT
36#include <iprt/critsect.h>
37#endif
38
39#define SO_EXPIRE 240000
40#define SO_EXPIREFAST 10000
41
42/*
43 * Our socket structure
44 */
45
46struct socket
47{
48 struct socket *so_next;
49 struct socket *so_prev; /* For a linked list of sockets */
50
51#if !defined(RT_OS_WINDOWS)
52 int s; /* The actual socket */
53#else
54 union {
55 int s;
56 HANDLE sh;
57 };
58 uint64_t so_icmp_id; /* XXX: hack */
59 uint64_t so_icmp_seq; /* XXX: hack */
60#endif
61
62 /* XXX union these with not-yet-used sbuf params */
63 struct mbuf *so_m; /* Pointer to the original SYN packet,
64 * for non-blocking connect()'s, and
65 * PING reply's */
66 struct tcpiphdr *so_ti; /* Pointer to the original ti within
67 * so_mconn, for non-blocking connections */
68 int so_urgc;
69 struct in_addr so_faddr; /* foreign host table entry */
70 struct in_addr so_laddr; /* local host table entry */
71 u_int16_t so_fport; /* foreign port */
72 u_int16_t so_lport; /* local port */
73 u_int16_t so_hlport; /* host local port */
74 struct in_addr so_hladdr; /* local host addr */
75
76 u_int8_t so_iptos; /* Type of service */
77 u_int8_t so_emu; /* Is the socket emulated? */
78
79 u_char so_type; /* Type of socket, UDP or TCP */
80 int so_state; /* internal state flags SS_*, below */
81
82 struct tcpcb *so_tcpcb; /* pointer to TCP protocol control block */
83 u_int so_expire; /* When the socket will expire */
84
85 int so_queued; /* Number of packets queued from this socket */
86 int so_nqueued; /* Number of packets queued in a row
87 * Used to determine when to "downgrade" a session
88 * from fastq to batchq */
89
90 struct sbuf so_rcv; /* Receive buffer */
91 struct sbuf so_snd; /* Send buffer */
92#ifdef VBOX_WITH_SLIRP_MT
93 RTCRITSECT so_mutex;
94 int so_deleted;
95#endif
96#ifndef RT_OS_WINDOWS
97 int so_poll_index;
98#endif /* !RT_OS_WINDOWS */
99 /*
100 * FD_CLOSE/POLLHUP event has been occurred on socket
101 */
102 int so_close;
103
104 void (* so_timeout)(PNATState pData, struct socket *so, void *arg);
105 void *so_timeout_arg;
106
107#ifdef VBOX_WITH_NAT_SERVICE
108 /* storage of source ether address */
109 unsigned char so_ethaddr[6];
110#endif
111 /* required for port-forwarding */
112 struct libalias *so_la;
113};
114
115#ifdef VBOX_WITH_SLIRP_MT
116# define SOCKET_LOCK(so) \
117 do { \
118 int rc; \
119 /* Assert(strcmp(RTThreadSelfName(), "EMT") != 0); */ \
120 Log2(("lock:%s:%d L on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
121 Assert(!RTCritSectIsOwner(&(so)->so_mutex)); \
122 rc = RTCritSectEnter(&(so)->so_mutex); \
123 AssertRC(rc); \
124 } while (0)
125# define SOCKET_UNLOCK(so) \
126 do { \
127 int rc; \
128 if ((so) != NULL) Log2(("lock:%s:%d U on %R[natsock]\n", __FUNCTION__, __LINE__, (so))); \
129 rc = RTCritSectLeave(&(so)->so_mutex); \
130 Assert(rc); \
131 } while (0)
132# define SOCKET_LOCK_CREATE(so) \
133 do { \
134 int rc; \
135 rc = RTCritSectInit(&(so)->so_mutex); \
136 AssertRC(rc); \
137 } while (0)
138# define SOCKET_LOCK_DESTROY(so) \
139 do { \
140 int rc = RTCritSectDelete(&(so)->so_mutex); \
141 AssertRC(rc); \
142 } while (0)
143#else
144# define SOCKET_LOCK(so) do {} while (0)
145# define SOCKET_UNLOCK(so) do {} while (0)
146# define SOCKET_LOCK_CREATE(so) do {} while (0)
147# define SOCKET_LOCK_DESTROY(so) do {} while (0)
148#endif
149/*
150 * Socket state bits. (peer means the host on the Internet,
151 * local host means the host on the other end of the modem)
152 */
153#define SS_NOFDREF 0x001 /* No fd reference */
154
155#define SS_ISFCONNECTING 0x002 /* Socket is connecting to peer (non-blocking connect()'s) */
156#define SS_ISFCONNECTED 0x004 /* Socket is connected to peer */
157#define SS_FCANTRCVMORE 0x008 /* Socket can't receive more from peer (for half-closes) */
158#define SS_FCANTSENDMORE 0x010 /* Socket can't send more to peer (for half-closes) */
159/* #define SS_ISFDISCONNECTED 0x020*/ /* Socket has disconnected from peer, in 2MSL state */
160#define SS_FWDRAIN 0x040 /* We received a FIN, drain data and set SS_FCANTSENDMORE */
161
162/* #define SS_CTL 0x080 */
163#define SS_FACCEPTCONN 0x100 /* Socket is accepting connections from a host on the internet */
164#define SS_FACCEPTONCE 0x200 /* If set, the SS_FACCEPTCONN socket will die after one accept */
165
166extern struct socket tcb;
167
168#if defined(DECLARE_IOVEC) && !defined(HAVE_READV)
169struct iovec
170{
171 char *iov_base;
172 size_t iov_len;
173};
174#endif
175
176void so_init (void);
177struct socket * solookup (struct socket *, struct in_addr, u_int, struct in_addr, u_int);
178struct socket * socreate (void);
179void sofree (PNATState, struct socket *);
180#ifdef VBOX_WITH_SLIRP_MT
181void soread_queue (PNATState, struct socket *, int *);
182#endif
183int soread (PNATState, struct socket *);
184void sorecvoob (PNATState, struct socket *);
185int sosendoob (struct socket *);
186int sowrite (PNATState, struct socket *);
187void sorecvfrom (PNATState, struct socket *);
188int sosendto (PNATState, struct socket *, struct mbuf *);
189struct socket * solisten (PNATState, u_int32_t, u_int, u_int32_t, u_int, int);
190void sorwakeup (struct socket *);
191void sowwakeup (struct socket *);
192void soisfconnecting (register struct socket *);
193void soisfconnected (register struct socket *);
194void sofcantrcvmore (struct socket *);
195void sofcantsendmore (struct socket *);
196void soisfdisconnected (struct socket *);
197void sofwdrain (struct socket *);
198
199#endif /* _SOCKET_H_ */
注意: 瀏覽 TracBrowser 來幫助您使用儲存庫瀏覽器

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