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.
6 * The V3VEE Project is a joint project between Northwestern University
7 * and the University of New Mexico. You can find out more at
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.
14 * Author: Jack Lange <jarusl@cs.northwestern.edu>
16 * This is free software. You are permitted to use,
17 * redistribute, and modify it as specified in the file "V3VEE_LICENSE".
21 #ifndef __VMM_SOCKET_H__
22 #define __VMM_SOCKET_H__
24 #include <palacios/vmm.h>
26 #define V3_SOCK void *
30 #define V3_Create_UDP_Socket() ({ \
31 extern struct v3_socket_hooks * sock_hooks; \
33 if ((sock_hooks) && (sock_hooks)->udp_socket) { \
34 sock = (sock_hooks)->udp_socket(0,0); \
41 #define V3_Create_TCP_Socket() ({ \
42 extern struct v3_socket_hooks * sock_hooks; \
44 if ((sock_hooks) && (sock_hooks)->tcp_socket) { \
45 sock = (sock_hooks)->tcp_socket(0,0); \
51 #define V3_Close_Socket(sock) \
53 extern struct v3_socket_hooks * sock_hooks; \
54 if ((sock_hooks) && (sock_hooks)->close) { \
55 (sock_hooks)->close(sock); \
61 #define V3_Bind_Socket(sock, port) ({ \
62 extern struct v3_socket_hooks * sock_hooks; \
64 if ((sock_hooks) && (sock_hooks)->bind) { \
65 ret = (sock_hooks)->bind(sock, port); \
71 #define V3_Accept_Socket() (-1)
72 #define V3_Select_Socket() (-1)
76 #define V3_Connect_To_IP(sock, ip, port) ({ \
77 extern struct v3_socket_hooks * sock_hooks; \
79 if ((sock_hooks) && (sock_hooks)->connect_to_ip) { \
80 ret = (sock_hooks)->connect_to_ip(sock, ip, port); \
86 #define V3_Connect_To_Host(sock, hostname, port) ({ \
87 extern struct v3_socket_hooks * sock_hooks; \
89 if ((sock_hooks) && (sock_hooks)->connect_to_host) { \
90 ret = (sock_hooks)->connect_to_host(sock, hostname, port); \
96 #define V3_Send(sock, buf, len) ({ \
97 extern struct v3_socket_hooks * sock_hooks; \
99 if ((sock_hooks) && (sock_hooks)->send) { \
100 ret = (sock_hooks)->send(sock, buf, len); \
105 #define V3_Recv(sock, buf, len) ({ \
106 extern struct v3_socket_hooks * sock_hooks; \
108 if ((sock_hooks) && (sock_hooks)->recv) { \
109 ret = (sock_hooks)->recv(sock, buf, len); \
114 #define V3_SendTo_Host(sock, hostname, port, buf, len) ({ \
115 extern struct v3_socket_hooks * sock_hooks; \
117 if ((sock_hooks) && (sock_hooks)->sendto_host) { \
118 ret = (sock_hooks)->sendto_host(sock, hostname, port, buf, len); \
124 #define V3_SendTo_IP(sock, ip, port, buf, len) ({ \
125 extern struct v3_socket_hooks * sock_hooks; \
127 if ((sock_hooks) && (sock_hooks)->sendto_ip) { \
128 ret = (sock_hooks)->sendto_ip(sock, ip, port, buf, len); \
134 #define V3_RecvFrom_Host(sock, hostname, port, buf, len) ({ \
135 extern struct v3_socket_hooks * sock_hooks; \
137 if ((sock_hooks) && (sock_hooks)->recvfrom_host) { \
138 ret = (sock_hooks)->recvfrom_host(sock, hostname, port, buf, len); \
144 #define V3_RecvFrom_IP(sock, ip, port, buf, len) ({ \
145 extern struct v3_socket_hooks * sock_hooks; \
147 if ((sock_hooks) && (sock_hooks)->recvfrom_ip) { \
148 ret = (sock_hooks)->recvfrom_ip(sock, ip, port, buf, len); \
158 long tv_sec; /* seconds */
159 long tv_usec; /* and microseconds */
165 struct v3_sock_set * next;
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)
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);
180 // Socket Destruction
181 void (*close)(V3_SOCK sock);
183 // Network Server Calls
184 int (*bind_socket)(const V3_SOCK sock, const int port);
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);
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);
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);
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);
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);
214 void V3_Init_Socket(struct v3_socket_hooks * hooks);