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 */
162 struct v3_sock_entry {
165 struct v3_sock_set * next;
169 unsigned int num_socks;
170 struct v3_sock_entry * socks;
174 void v3_init_sock_set(struct v3_sock_set * sock_set);
176 void v3_set_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // adds socket to the sockset
177 void v3_clr_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // deletes socket from sockset
178 int v3_isset_sock(struct v3_sock_set * sock_set, V3_SOCK sock); // checks is_set vairable
179 void v3_zero_sockset(struct v3_sock_set * sock_set); // clears all is_set variables.
183 #define v3_foreach_sock(/* (struct v3_sock_set *) */ sock_set, /* (struct v3_sock_entry *) */ iter) \
184 for (iter = sock_set->socks; iter != NULL; iter = iter->next)
188 struct v3_socket_hooks {
189 // Socket creation routines
190 V3_SOCK (*tcp_socket)(const int bufsize, const int nodelay, const int nonblocking);
191 V3_SOCK (*udp_socket)(const int bufsize, const int nonblocking);
193 // Socket Destruction
194 void (*close)(V3_SOCK sock);
196 // Network Server Calls
197 int (*bind_socket)(const V3_SOCK sock, const int port);
199 int (*accept)(const V3_SOCK const sock, unsigned int * remote_ip);
200 // This going to suck
201 int (*select)(struct v3_sock_set * rset, \
202 struct v3_sock_set * wset, \
203 struct v3_sock_set * eset, \
204 struct v3_timeval tv);
207 int (*connect_to_ip)(const V3_SOCK sock, const int hostip, const int port);
208 int (*connect_to_host)(const V3_SOCK sock, const char * hostname, const int port);
211 int (*send)(const V3_SOCK sock, const char * buf, const int len);
212 int (*recv)(const V3_SOCK sock, char * buf, const int len);
215 int (*sendto_host)(const V3_SOCK sock, const char * hostname, const int port,
216 const char * buf, const int len);
217 int (*sendto_ip)(const V3_SOCK sock, const int ip_addr, const int port,
218 const char * buf, const int len);
220 int (*recvfrom_host)(const V3_SOCK sock, const char * hostname, const int port,
221 char * buf, const int len);
222 int (*recvfrom_ip)(const V3_SOCK sock, const int ip_addr, const int port,
223 char * buf, const int len);
227 void V3_Init_Socket(struct v3_socket_hooks * hooks);