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.


clear instruction to 0 before decoding with xed
[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
27 #ifdef __V3VEE__
28
29
30 typedef void * v3_sock_t;
31
32 v3_sock_t v3_create_udp_socket(struct v3_vm_info * vm);
33 v3_sock_t v3_create_tcp_socket(struct v3_vm_info * vm);
34
35 void v3_socket_close(v3_sock_t sock);
36
37 int v3_socket_bind(v3_sock_t sock, uint16_t port);
38 int v3_socket_listen(const v3_sock_t sock, int backlog);
39 v3_sock_t v3_socket_accept(const v3_sock_t sock, uint32_t * remote_ip, uint32_t * port);
40
41 int v3_connect_to_ip(const v3_sock_t sock, const uint32_t hostip, const uint16_t port);
42 int v3_connect_to_host(const v3_sock_t sock, const char * hostname, const uint16_t port);
43
44
45 int v3_socket_send(const v3_sock_t sock, const uint8_t * buf, const uint32_t len);
46 int v3_socket_recv(const v3_sock_t sock, uint8_t * buf, const uint32_t len);
47
48
49 int v3_socket_send_to_host(const v3_sock_t sock, const char * hostname, const uint16_t port, 
50                            const uint8_t * buf, const uint32_t len);
51 int v3_socket_send_to_ip(const v3_sock_t sock, const uint32_t ip, const uint16_t port, 
52                          const uint8_t * buf, const uint32_t len);
53 int v3_socket_recv_from_host(const v3_sock_t sock, const char * hostname, const uint16_t port, 
54                              uint8_t * buf, const uint32_t len);
55 int v3_socket_recv_from_ip(const v3_sock_t sock, const uint32_t ip, const uint16_t port, 
56                            uint8_t * buf, const uint32_t len);
57
58
59 #define V3_Select_Socket(rset,wset,eset,tv) ({                          \
60             extern struct v3_socket_hooks * sock_hooks;                 \
61             int ret = -1;                                               \
62             if ((sock_hooks) && (sock_hooks)->select) {                 \
63                 ret = (sock_hooks)->select(rset, wset, eset, tv);       \
64             }                                                           \
65             ret;                                                        \
66         })
67
68
69
70
71
72
73
74 #define V3_SOCK_SET(n, p)  ((p)->fd_bits[(n) / 8] |=  (1 << ((n) & 7)))
75 #define V3_SOCK_CLR(n, p)  ((p)->fd_bits[(n) / 8] &= ~(1 << ((n) & 7)))
76 #define V3_SOCK_ISSET(n,p) ((p)->fd_bits[(n) / 8] &   (1 << ((n) & 7)))
77 #define V3_SOCK_ZERO(p)    memset((void *)(p), 0, sizeof(*(p)))
78
79
80 uint32_t v3_inet_addr(const char * ip_str);
81 char * v3_inet_ntoa(uint32_t addr);
82 uint16_t v3_htons(uint16_t s);
83 uint16_t v3_ntohs(uint16_t s);
84 uint32_t v3_htonl(uint32_t s);
85 uint32_t v3_ntohl(uint32_t s);
86
87
88
89
90 #endif
91
92
93 struct v3_timeval {
94     long    tv_sec;         /* seconds */
95     long    tv_usec;        /* and microseconds */
96 };
97
98
99 #define V3_SOCK_SETSIZE    1000
100
101 typedef struct v3_sock_set {
102     /* This format needs to match the standard posix FD_SET format, so it can be cast */
103     unsigned char fd_bits [(V3_SOCK_SETSIZE + 7) / 8];
104 } v3_sock_set;
105
106
107
108 struct v3_socket_hooks {
109     /* Socket creation routines */
110     void *(*tcp_socket)(const int bufsize, const int nodelay, const int nonblocking, void * priv_data);
111     void *(*udp_socket)(const int bufsize, const int nonblocking, void * priv_data);
112
113     /* Socket Destruction */
114     void (*close)(void * sock);
115
116     /* Network Server Calls */
117     int (*bind)(const void * sock, const int port);
118
119     int (*listen)(const void * sock, int backlog);
120   
121     void *(*accept)(const void * sock, unsigned int * remote_ip, unsigned int * port);
122     /* This going to suck */
123     int (*select)(struct v3_sock_set * rset, \
124                   struct v3_sock_set * wset, \
125                   struct v3_sock_set * eset, \
126                   struct v3_timeval tv);
127
128     /* Connect calls */
129     int (*connect_to_ip)(const void * sock, const int hostip, const int port);
130     int (*connect_to_host)(const void * sock, const char * hostname, const int port);
131
132     /* TCP Data Transfer */
133     int (*send)(const void * sock, const char * buf, const int len);
134     int (*recv)(const void * sock, char * buf, const int len);
135   
136     /* UDP Data Transfer */
137     int (*sendto_host)(const void * sock, const char * hostname, const int port, 
138                        const char * buf, const int len);
139     int (*sendto_ip)(const void * sock, const int ip_addr, const int port, 
140                      const char * buf, const int len);
141   
142     int (*recvfrom_host)(const void * sock, const char * hostname, const int port, 
143                          char * buf, const int len);
144     int (*recvfrom_ip)(const void * sock, const int ip_addr, const int port, 
145                        char * buf, const int len);
146 };
147
148
149 extern void V3_Init_Sockets(struct v3_socket_hooks * hooks);
150
151 #endif