VirtualBox

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

Last change on this file since 34244 was 28800, checked in by vboxsync, 15 years ago

Automated rebranding to Oracle copyright/license strings via filemuncher

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

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