aboutsummaryrefslogtreecommitdiff
path: root/src/vpn
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2012-01-07 19:26:53 +0000
committerChristian Grothoff <christian@grothoff.org>2012-01-07 19:26:53 +0000
commit6610dea80399451f4eae448c001bf8e425d6e5ab (patch)
tree25fd0840f3226defde9d5c017512ff91daa4b71a /src/vpn
parent4c6f5a7ae36bbed02ecd1ae78ecff44e93c0970b (diff)
downloadgnunet-6610dea80399451f4eae448c001bf8e425d6e5ab.tar.gz
gnunet-6610dea80399451f4eae448c001bf8e425d6e5ab.zip
-defining IPC messages for VPN
Diffstat (limited to 'src/vpn')
-rw-r--r--src/vpn/gnunet-service-vpn.c113
-rw-r--r--src/vpn/vpn.h115
-rw-r--r--src/vpn/vpn_api.c15
3 files changed, 211 insertions, 32 deletions
diff --git a/src/vpn/gnunet-service-vpn.c b/src/vpn/gnunet-service-vpn.c
index 8f0236846..e736b7746 100644
--- a/src/vpn/gnunet-service-vpn.c
+++ b/src/vpn/gnunet-service-vpn.c
@@ -44,13 +44,14 @@
44#include "gnunet_mesh_service.h" 44#include "gnunet_mesh_service.h"
45#include "gnunet_constants.h" 45#include "gnunet_constants.h"
46#include "tcpip_tun.h" 46#include "tcpip_tun.h"
47#include "vpn.h"
47 48
48 49
49/** 50/**
50 * Information we track for each IP address to determine which tunnel 51 * Information we track for each IP address to determine which tunnel
51 * to send the traffic over to the destination. 52 * to send the traffic over to the destination.
52 */ 53 */
53struct destination_entry 54struct DestinationEntry
54{ 55{
55 /** 56 /**
56 * Information about the tunnel to use, NULL if no tunnel 57 * Information about the tunnel to use, NULL if no tunnel
@@ -108,17 +109,17 @@ struct destination_entry
108/** 109/**
109 * A messages we have in queue for a particular tunnel. 110 * A messages we have in queue for a particular tunnel.
110 */ 111 */
111struct tunnel_notify_queue 112struct TunnelMessageQueueEntry
112{ 113{
113 /** 114 /**
114 * This is a doubly-linked list. 115 * This is a doubly-linked list.
115 */ 116 */
116 struct tunnel_notify_queue *next; 117 struct TunnelMessageQueueEntry *next;
117 118
118 /** 119 /**
119 * This is a doubly-linked list. 120 * This is a doubly-linked list.
120 */ 121 */
121 struct tunnel_notify_queue *prev; 122 struct TunnelMessageQueueEntry *prev;
122 123
123 /** 124 /**
124 * Number of bytes in 'msg'. 125 * Number of bytes in 'msg'.
@@ -135,7 +136,7 @@ struct tunnel_notify_queue
135/** 136/**
136 * State we keep for each of our tunnels. 137 * State we keep for each of our tunnels.
137 */ 138 */
138struct tunnel_state 139struct TunnelState
139{ 140{
140 /** 141 /**
141 * Active transmission handle, NULL for none. 142 * Active transmission handle, NULL for none.
@@ -150,12 +151,12 @@ struct tunnel_state
150 /** 151 /**
151 * Head of list of messages scheduled for transmission. 152 * Head of list of messages scheduled for transmission.
152 */ 153 */
153 struct tunnel_notify_queue *head; 154 struct TunnelMessageQueueEntry *head;
154 155
155 /** 156 /**
156 * Tail of list of messages scheduled for transmission. 157 * Tail of list of messages scheduled for transmission.
157 */ 158 */
158 struct tunnel_notify_queue *tail; 159 struct TunnelMessageQueueEntry *tail;
159 160
160 /** 161 /**
161 * Destination to which this tunnel leads. Note that 162 * Destination to which this tunnel leads. Note that
@@ -163,7 +164,7 @@ struct tunnel_state
163 * local copy) and that the 'heap_node' should always 164 * local copy) and that the 'heap_node' should always
164 * be NULL. 165 * be NULL.
165 */ 166 */
166 struct destination_entry destination; 167 struct DestinationEntry destination;
167 168
168 /** 169 /**
169 * GNUNET_NO if this is a tunnel to an Internet-exit, 170 * GNUNET_NO if this is a tunnel to an Internet-exit,
@@ -362,7 +363,7 @@ get_tunnel_key_from_ips (int af,
362/** 363/**
363 * Send a message from the message queue via mesh. 364 * Send a message from the message queue via mesh.
364 * 365 *
365 * @param cls the 'struct tunnel_state' with the message queue 366 * @param cls the 'struct TunnelState' with the message queue
366 * @param size number of bytes available in buf 367 * @param size number of bytes available in buf
367 * @param buf where to copy the message 368 * @param buf where to copy the message
368 * @return number of bytes copied to buf 369 * @return number of bytes copied to buf
@@ -370,8 +371,8 @@ get_tunnel_key_from_ips (int af,
370static size_t 371static size_t
371send_to_peer_notify_callback (void *cls, size_t size, void *buf) 372send_to_peer_notify_callback (void *cls, size_t size, void *buf)
372{ 373{
373 struct tunnel_state *ts = cls; 374 struct TunnelState *ts = cls;
374 struct tunnel_notify_queue *tnq; 375 struct TunnelMessageQueueEntry *tnq;
375 size_t ret; 376 size_t ret;
376 377
377 ts->th = NULL; 378 ts->th = NULL;
@@ -407,8 +408,8 @@ send_to_peer_notify_callback (void *cls, size_t size, void *buf)
407 * @param ts tunnel to queue the message for 408 * @param ts tunnel to queue the message for
408 */ 409 */
409static void 410static void
410send_to_tunnel (struct tunnel_notify_queue *tnq, 411send_to_tunnel (struct TunnelMessageQueueEntry *tnq,
411 struct tunnel_state *ts) 412 struct TunnelState *ts)
412{ 413{
413 GNUNET_CONTAINER_DLL_insert_tail (ts->head, 414 GNUNET_CONTAINER_DLL_insert_tail (ts->head,
414 ts->tail, 415 ts->tail,
@@ -437,7 +438,7 @@ send_to_tunnel (struct tunnel_notify_queue *tnq,
437 * @param payload_length number of bytes in payload 438 * @param payload_length number of bytes in payload
438 */ 439 */
439static void 440static void
440route_packet (struct destination_entry *destination, 441route_packet (struct DestinationEntry *destination,
441 int af, 442 int af,
442 uint8_t protocol, 443 uint8_t protocol,
443 const void *source_ip, 444 const void *source_ip,
@@ -446,8 +447,8 @@ route_packet (struct destination_entry *destination,
446 size_t payload_length) 447 size_t payload_length)
447{ 448{
448 GNUNET_HashCode key; 449 GNUNET_HashCode key;
449 struct tunnel_state *ts; 450 struct TunnelState *ts;
450 struct tunnel_notify_queue *tnq; 451 struct TunnelMessageQueueEntry *tnq;
451 452
452 switch (protocol) 453 switch (protocol)
453 { 454 {
@@ -524,24 +525,24 @@ route_packet (struct destination_entry *destination,
524 case IPPROTO_UDP: 525 case IPPROTO_UDP:
525 if (destination->is_service) 526 if (destination->is_service)
526 { 527 {
527 tnq = GNUNET_malloc (sizeof (struct tunnel_notify_queue) + 42); 528 tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + 42);
528 // FIXME: build message! 529 // FIXME: build message!
529 } 530 }
530 else 531 else
531 { 532 {
532 tnq = GNUNET_malloc (sizeof (struct tunnel_notify_queue) + 42); 533 tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + 42);
533 // FIXME: build message! 534 // FIXME: build message!
534 } 535 }
535 break; 536 break;
536 case IPPROTO_TCP: 537 case IPPROTO_TCP:
537 if (destination->is_service) 538 if (destination->is_service)
538 { 539 {
539 tnq = GNUNET_malloc (sizeof (struct tunnel_notify_queue) + 42); 540 tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + 42);
540 // FIXME: build message! 541 // FIXME: build message!
541 } 542 }
542 else 543 else
543 { 544 {
544 tnq = GNUNET_malloc (sizeof (struct tunnel_notify_queue) + 42); 545 tnq = GNUNET_malloc (sizeof (struct TunnelMessageQueueEntry) + 42);
545 // FIXME: build message! 546 // FIXME: build message!
546 } 547 }
547 break; 548 break;
@@ -572,7 +573,7 @@ message_token (void *cls GNUNET_UNUSED, void *client GNUNET_UNUSED,
572 const struct tun_header *tun; 573 const struct tun_header *tun;
573 size_t mlen; 574 size_t mlen;
574 GNUNET_HashCode key; 575 GNUNET_HashCode key;
575 struct destination_entry *de; 576 struct DestinationEntry *de;
576 577
577 mlen = ntohs (message->size); 578 mlen = ntohs (message->size);
578 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) || 579 if ( (ntohs (message->type) != GNUNET_MESSAGE_TYPE_VPN_HELPER) ||
@@ -699,7 +700,7 @@ receive_udp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
699 struct remote_addr *s = (struct remote_addr *) desc; 700 struct remote_addr *s = (struct remote_addr *) desc;
700 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1); 701 struct udp_pkt *pkt = (struct udp_pkt *) (desc + 1);
701 const struct GNUNET_PeerIdentity *other = sender; 702 const struct GNUNET_PeerIdentity *other = sender;
702 struct tunnel_state *ts = *tunnel_ctx; 703 struct TunnelState *ts = *tunnel_ctx;
703 704
704 if (16 == ts->addrlen) 705 if (16 == ts->addrlen)
705 { 706 {
@@ -887,7 +888,7 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
887 struct remote_addr *s = (struct remote_addr *) desc; 888 struct remote_addr *s = (struct remote_addr *) desc;
888 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1); 889 struct tcp_pkt *pkt = (struct tcp_pkt *) (desc + 1);
889 const struct GNUNET_PeerIdentity *other = sender; 890 const struct GNUNET_PeerIdentity *other = sender;
890 struct tunnel_state *ts = *tunnel_ctx; 891 struct TunnelState *ts = *tunnel_ctx;
891 892
892 size_t pktlen = 893 size_t pktlen =
893 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) - 894 ntohs (message->size) - sizeof (struct GNUNET_MessageHeader) -
@@ -1065,6 +1066,41 @@ receive_tcp_back (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Tunnel *tunnel,
1065 1066
1066 1067
1067/** 1068/**
1069 * A client asks us to setup a redirection via some exit
1070 * node to a particular IP. Setup the redirection and
1071 * give the client the allocated IP.
1072 *
1073 * @param cls unused
1074 * @param client requesting client
1075 * @param message redirection request (a 'struct RedirectToIpRequestMessage')
1076 */
1077static void
1078service_redirect_to_ip (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *client,
1079 const struct GNUNET_MessageHeader *message)
1080{
1081 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1082}
1083
1084
1085/**
1086 * A client asks us to setup a redirection to a particular peer
1087 * offering a service. Setup the redirection and give the client the
1088 * allocated IP.
1089 *
1090 * @param cls unused
1091 * @param client requesting client
1092 * @param message redirection request (a 'struct RedirectToPeerRequestMessage')
1093 */
1094static void
1095service_redirect_to_service (void *cls GNUNET_UNUSED, struct GNUNET_SERVER_Client *client,
1096 const struct GNUNET_MessageHeader *message)
1097{
1098 GNUNET_SERVER_receive_done (client, GNUNET_SYSERR);
1099}
1100
1101
1102
1103/**
1068 * FIXME: document. 1104 * FIXME: document.
1069 */ 1105 */
1070static void * 1106static void *
@@ -1116,6 +1152,20 @@ cleanup (void *cls GNUNET_UNUSED,
1116 1152
1117 1153
1118/** 1154/**
1155 * A client has disconnected from us. If we are currently building
1156 * a tunnel for it, cancel the operation.
1157 *
1158 * @param cls unused
1159 * @param client handle to the client that disconnected
1160 */
1161static void
1162client_disconnect (void *cls, struct GNUNET_SERVER_Client *client)
1163{
1164 // FIXME
1165}
1166
1167
1168/**
1119 * Main function that will be run by the scheduler. 1169 * Main function that will be run by the scheduler.
1120 * 1170 *
1121 * @param cls closure 1171 * @param cls closure
@@ -1127,7 +1177,15 @@ run (void *cls,
1127 struct GNUNET_SERVER_Handle *server, 1177 struct GNUNET_SERVER_Handle *server,
1128 const struct GNUNET_CONFIGURATION_Handle *cfg_) 1178 const struct GNUNET_CONFIGURATION_Handle *cfg_)
1129{ 1179{
1130 static const struct GNUNET_MESH_MessageHandler handlers[] = { 1180 static const struct GNUNET_SERVER_MessageHandler service_handlers[] = {
1181 /* callback, cls, type, size */
1182 {&service_redirect_to_ip, NULL, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, 0},
1183 {&service_redirect_to_service, NULL,
1184 GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE,
1185 sizeof (struct RedirectToServiceRequestMessage) },
1186 {NULL, NULL, 0, 0}
1187 };
1188 static const struct GNUNET_MESH_MessageHandler mesh_handlers[] = {
1131 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0}, 1189 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_UDP_BACK, 0},
1132 {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK, 0}, 1190 {receive_tcp_back, GNUNET_MESSAGE_TYPE_VPN_SERVICE_TCP_BACK, 0},
1133 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK, 0}, 1191 {receive_udp_back, GNUNET_MESSAGE_TYPE_VPN_REMOTE_UDP_BACK, 0},
@@ -1231,13 +1289,12 @@ run (void *cls,
1231 GNUNET_MESH_connect (cfg_, 42 /* queue length */, NULL, 1289 GNUNET_MESH_connect (cfg_, 42 /* queue length */, NULL,
1232 &new_tunnel, 1290 &new_tunnel,
1233 &tunnel_cleaner, 1291 &tunnel_cleaner,
1234 handlers, 1292 mesh_handlers,
1235 types); 1293 types);
1236 // FIXME: register service handlers to allow destination mappings to
1237 // be created!
1238
1239 helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv, 1294 helper_handle = GNUNET_HELPER_start ("gnunet-helper-vpn", vpn_argv,
1240 &message_token, NULL); 1295 &message_token, NULL);
1296 GNUNET_SERVER_add_handlers (server, service_handlers);
1297 GNUNET_SERVER_disconnect_notify (server, &client_disconnect, NULL);
1241 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls); 1298 GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
1242} 1299}
1243 1300
diff --git a/src/vpn/vpn.h b/src/vpn/vpn.h
index da7fa6eb8..90bcdaa61 100644
--- a/src/vpn/vpn.h
+++ b/src/vpn/vpn.h
@@ -28,8 +28,123 @@
28 28
29#include "gnunet_util_lib.h" 29#include "gnunet_util_lib.h"
30 30
31/**
32 * Message send by the VPN client to the VPN service requesting
33 * the setup of a redirection from some IP via an exit node to
34 * some global Internet address.
35 */
36struct RedirectToIpRequestMessage
37{
38 /**
39 * Type is GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP
40 */
41 struct GNUNET_MessageHeader header;
42
43 /**
44 * GNUNET_YES to notify only after completion of the mesh-level connection,
45 * GNUNET_NO to notify as soon as an address was allocated (in nbo).
46 */
47 int32_t nac;
48
49 /**
50 * How long should the redirection be maintained at most?
51 */
52 struct GNUNET_TIME_AbsoluteNBO expiration_time;
53
54 /**
55 * Address family desired for the result (AF_INET or AF_INET6 or AF_UNSPEC, in nbo)
56 */
57 int32_t result_af;
58
59 /**
60 * Address family used for the destination address (AF_INET or AF_INET6, in nbo)
61 */
62 int32_t addr_af;
63
64 /**
65 * Unique ID to match a future response to this request.
66 * Picked by the client.
67 */
68 uint64_t request_id;
69
70 /* followed by destination address ('struct in_addr' or 'struct in6_addr') */
71
72};
73
74
75/**
76 * Message send by the VPN client to the VPN service requesting
77 * the setup of a redirection from some IP to a service running
78 * at a particular peer.
79 */
80struct RedirectToServiceRequestMessage
81{
82 /**
83 * Type is GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP
84 */
85 struct GNUNET_MessageHeader header;
86
87 /**
88 * GNUNET_YES to notify only after completion of the mesh-level connection,
89 * GNUNET_NO to notify as soon as an address was allocated (in nbo).
90 */
91 int32_t nac;
92
93 /**
94 * How long should the redirection be maintained at most?
95 */
96 struct GNUNET_TIME_AbsoluteNBO expiration_time;
97
98 /**
99 * Desired protocol (IPPROTO_UDP or IPPROTO_TCP)
100 */
101 int32_t protocol;
102
103 /**
104 * Address family desired for the result (AF_INET or AF_INET6 or AF_UNSPEC, in nbo)
105 */
106 int32_t result_af;
107
108 /**
109 * Target peer offering the service.
110 */
111 struct GNUNET_PeerIdentity target;
112
113 /**
114 * Service descriptor identifying the service.
115 */
116 struct GNUNET_PeerIdentity desc;
117
118 /**
119 * Unique ID to match a future response to this request.
120 * Picked by the client.
121 */
122 uint64_t request_id;
123
124};
125
126
127/**
128 * Response from the VPN service to a VPN client informing about
129 * the IP that was assigned for the requested redirection.
130 */
131struct RedirectToIpResponseMessage
132{
133
134 /**
135 * Type is GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP
136 */
137 struct GNUNET_MessageHeader header;
31 138
139 /**
140 * Address family of the allocated address that follows; will match
141 * "result_af" from the request, of be "AF_UNSPEC" on errors.
142 */
143 int32_t result_af;
32 144
145 /* followed by destination address ('struct in_addr' or 'struct in6_addr') */
146
147};
33 148
34 149
35#endif 150#endif
diff --git a/src/vpn/vpn_api.c b/src/vpn/vpn_api.c
index 5c351a190..b6fab37bf 100644
--- a/src/vpn/vpn_api.c
+++ b/src/vpn/vpn_api.c
@@ -107,9 +107,14 @@ struct GNUNET_VPN_RedirectionRequest
107 struct GNUNET_TIME_Absolute expiration_time; 107 struct GNUNET_TIME_Absolute expiration_time;
108 108
109 /** 109 /**
110 * AF_INET or AF_INET6. 110 * Desired address family for the result.
111 */ 111 */
112 int af; 112 int result_af;
113
114 /**
115 * Address family of 'addr'. AF_INET or AF_INET6.
116 */
117 int addr_af;
113 118
114 /** 119 /**
115 * GNUNET_YES if we are to call the callback only after successful 120 * GNUNET_YES if we are to call the callback only after successful
@@ -192,7 +197,8 @@ GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *rh,
192 * limitations, the longest inactive mappings will be destroyed. 197 * limitations, the longest inactive mappings will be destroyed.
193 * 198 *
194 * @param vh VPN handle 199 * @param vh VPN handle
195 * @param af address family, AF_INET or AF_INET6 200 * @param result_af desired address family for the returned allocation
201 * @param addr_af address family for 'addr', AF_INET or AF_INET6
196 * @param addr destination IP address on the Internet; destination 202 * @param addr destination IP address on the Internet; destination
197 * port is to be taken from the VPN packet itself 203 * port is to be taken from the VPN packet itself
198 * @param nac GNUNET_YES to notify via callback only after completion of 204 * @param nac GNUNET_YES to notify via callback only after completion of
@@ -208,7 +214,8 @@ GNUNET_VPN_redirect_to_peer (struct GNUNET_VPN_Handle *rh,
208 */ 214 */
209struct GNUNET_VPN_RedirectionRequest * 215struct GNUNET_VPN_RedirectionRequest *
210GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *rh, 216GNUNET_VPN_redirect_to_ip (struct GNUNET_VPN_Handle *rh,
211 int af, 217 int result_af,
218 int addr_af,
212 const void *addr, 219 const void *addr,
213 int nac, 220 int nac,
214 struct GNUNET_TIME_Absolute expiration_time, 221 struct GNUNET_TIME_Absolute expiration_time,