Palacios Public Git Repository

To checkout Palacios execute

  git clone http://v3vee.org/palacios/palacios.web/palacios.git
This will give you the master branch. You probably want the devel branch or one of the release branches. To switch to the devel branch, simply execute
  cd palacios
  git checkout --track -b devel origin/devel
The other branches are similar.


added socket interface
[palacios.git] / palacios / include / palacios / vmm_socket.h
1 /*
2  * This file is part of the Palacios Virtual Machine Monitor developed
3  * by the V3VEE Project with funding from the United States National 
4  * Science Foundation and the Department of Energy.  
5  *
6  * The V3VEE Project is a joint project between Northwestern University
7  * and the University of New Mexico.  You can find out more at 
8  * http://www.v3vee.org
9  *
10  * Copyright (c) 2008, Jack Lange <jarusl@cs.northwestern.edu> 
11  * Copyright (c) 2008, The V3VEE Project <http://www.v3vee.org> 
12  * All rights reserved.
13  *
14  * Author: Jack Lange <jarusl@cs.northwestern.edu>
15  *
16  * This is free software.  You are permitted to use,
17  * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
18  */
19
20
21 #ifndef __VMM_SOCKET_H__
22 #define __VMM_SOCKET_H__
23
24 #include <palacios/vmm.h>
25
26 #define V3_SOCK void *
27
28 #ifdef __V3VEE__
29
30 #define V3_Create_UDP_Socket() ({                       \
31       extern struct v3_socket_hooks * sock_hooks;       \
32       V3_SOCK sock = 0;                                 \
33       if ((sock_hooks) && (sock_hooks)->udp_socket) {   \
34         sock = (sock_hooks)->udp_socket(0,0);           \
35       }                                                 \
36       sock;                                             \
37     })
38
39
40
41 #define V3_Create_TCP_Socket() ({                       \
42       extern struct v3_socket_hooks * sock_hooks;       \
43       V3_SOCK sock = 0;                                 \
44       if ((sock_hooks) && (sock_hooks)->tcp_socket) {   \
45         sock = (sock_hooks)->tcp_socket(0,0);           \
46       }                                                 \
47       sock;                                             \
48     })
49
50
51 #define V3_Close_Socket(sock) \
52   do {                                                  \
53     extern struct v3_socket_hooks * sock_hooks;         \
54     if ((sock_hooks) && (sock_hooks)->close) {          \
55       (sock_hooks)->close(sock);                        \
56     }                                                   \
57   } while (0);
58
59
60
61 #define V3_Bind_Socket(sock, port) ({                           \
62       extern struct v3_socket_hooks * sock_hooks;               \
63       int ret = -1;                                             \
64       if ((sock_hooks) && (sock_hooks)->bind) {                 \
65         ret = (sock_hooks)->bind(sock, port);                   \
66       }                                                         \
67       ret;                                                      \
68     })
69
70
71 #define V3_Accept_Socket() (-1)
72 #define V3_Select_Socket() (-1)
73
74
75
76 #define V3_Connect_To_IP(sock, ip, port) ({                     \
77       extern struct v3_socket_hooks * sock_hooks;               \
78       int ret = -1;                                             \
79       if ((sock_hooks) && (sock_hooks)->connect_to_ip) {        \
80         ret = (sock_hooks)->connect_to_ip(sock, ip, port);      \
81       }                                                         \
82       ret;                                                      \
83     })
84
85
86 #define V3_Connect_To_Host(sock, hostname, port) ({                     \
87       extern struct v3_socket_hooks * sock_hooks;                       \
88       int ret = -1;                                                     \
89       if ((sock_hooks) && (sock_hooks)->connect_to_host) {              \
90         ret = (sock_hooks)->connect_to_host(sock, hostname, port);      \
91       }                                                                 \
92       ret;                                                              \
93     })
94
95
96 #define V3_Send(sock, buf, len) ({                              \
97       extern struct v3_socket_hooks * sock_hooks;               \
98       int ret = -1;                                             \
99       if ((sock_hooks) && (sock_hooks)->send) {                 \
100         ret = (sock_hooks)->send(sock, buf, len);               \
101       }                                                         \
102       ret;                                                      \
103     })
104
105 #define V3_Recv(sock, buf, len) ({                              \
106       extern struct v3_socket_hooks * sock_hooks;               \
107       int ret = -1;                                             \
108       if ((sock_hooks) && (sock_hooks)->recv) {                 \
109         ret = (sock_hooks)->recv(sock, buf, len);               \
110       }                                                         \
111       ret;                                                      \
112     })
113
114 #define V3_SendTo_Host(sock, hostname, port, buf, len) ({               \
115       extern struct v3_socket_hooks * sock_hooks;                       \
116       int ret = -1;                                                     \
117       if ((sock_hooks) && (sock_hooks)->sendto_host) {                  \
118         ret = (sock_hooks)->sendto_host(sock, hostname, port, buf, len); \
119       }                                                                 \
120       ret;                                                              \
121     })
122
123
124 #define V3_SendTo_IP(sock, ip, port, buf, len) ({                       \
125       extern struct v3_socket_hooks * sock_hooks;                       \
126       int ret = -1;                                                     \
127       if ((sock_hooks) && (sock_hooks)->sendto_ip) {                    \
128         ret = (sock_hooks)->sendto_ip(sock, ip, port, buf, len);        \
129       }                                                                 \
130       ret;                                                              \
131     })
132
133
134 #define V3_RecvFrom_Host(sock, hostname, port, buf, len) ({             \
135       extern struct v3_socket_hooks * sock_hooks;                       \
136       int ret = -1;                                                     \
137       if ((sock_hooks) && (sock_hooks)->recvfrom_host) {                        \
138         ret = (sock_hooks)->recvfrom_host(sock, hostname, port, buf, len); \
139       }                                                                 \
140       ret;                                                              \
141     })
142
143
144 #define V3_RecvFrom_IP(sock, ip, port, buf, len) ({                     \
145       extern struct v3_socket_hooks * sock_hooks;                       \
146       int ret = -1;                                                     \
147       if ((sock_hooks) && (sock_hooks)->recvfrom_ip) {                  \
148         ret = (sock_hooks)->recvfrom_ip(sock, ip, port, buf, len);      \
149       }                                                                 \
150       ret;                                                              \
151     })
152
153
154 #endif
155
156
157 struct v3_timeval {
158   long    tv_sec;         /* seconds */
159   long    tv_usec;        /* and microseconds */
160 };
161
162 struct v3_sock_set {
163   V3_SOCK sock;
164   unsigned int is_set;
165   struct v3_sock_set * next;
166 };
167
168
169 #define v3_set_sock(n, p)  ((p)->fd_bits[(n)/8] |=  (1 << ((n) & 7)))
170 #define v3_clr_sock(n, p)  ((p)->fd_bits[(n)/8] &= ~(1 << ((n) & 7)))
171 #define v3_isset_sock(n,p) ((p)->fd_bits[(n)/8] &   (1 << ((n) & 7)))
172 #define v3_zero_sockset(p)    
173
174
175 struct v3_socket_hooks {
176   // Socket creation routines
177   V3_SOCK (*tcp_socket)(const int bufsize, const int nodelay, const int nonblocking);
178   V3_SOCK (*udp_socket)(const int bufsize, const int nonblocking);
179
180   // Socket Destruction
181   void (*close)(V3_SOCK sock);
182
183   // Network Server Calls
184   int (*bind_socket)(const V3_SOCK sock, const int port);
185   
186   int (*accept)(const V3_SOCK const sock);
187   // This going to suck
188   int (*select)(struct v3_sock_set * rset, \
189                 struct v3_sock_set * wset, \
190                 struct v3_sock_set * eset, \
191                 struct v3_timeval tv);
192
193   // Connect calls
194   int (*connect_to_ip)(const V3_SOCK sock, const int hostip, const int port);
195   int (*connect_to_host)(const V3_SOCK sock, const char * hostname, const int port);
196
197   // TCP Data Transfer
198   int (*send)(const V3_SOCK sock, const char * buf, const int len);
199   int (*recv)(const V3_SOCK sock, char * buf, const int len);
200   
201   // UDP Data Transfer
202   int (*sendto_host)(const V3_SOCK sock, const char * hostname, const int port, 
203                     const char * buf, const int len);
204   int (*sendto_ip)(const V3_SOCK sock, const int ip_addr, const int port, 
205                   const char * buf, const int len);
206   
207   int (*recvfrom_host)(const V3_SOCK sock, const char * hostname, const int port, 
208                          char * buf, const int len);
209   int (*recvfrom_ip)(const V3_SOCK sock, const int ip_addr, const int port, 
210                          char * buf, const int len);
211 };
212
213
214 void V3_Init_Socket(struct v3_socket_hooks * hooks);
215
216
217 #endif