diff options
author | Christian Grothoff <christian@grothoff.org> | 2012-01-07 19:26:53 +0000 |
---|---|---|
committer | Christian Grothoff <christian@grothoff.org> | 2012-01-07 19:26:53 +0000 |
commit | 6610dea80399451f4eae448c001bf8e425d6e5ab (patch) | |
tree | 25fd0840f3226defde9d5c017512ff91daa4b71a /src/vpn/gnunet-service-vpn.c | |
parent | 4c6f5a7ae36bbed02ecd1ae78ecff44e93c0970b (diff) | |
download | gnunet-6610dea80399451f4eae448c001bf8e425d6e5ab.tar.gz gnunet-6610dea80399451f4eae448c001bf8e425d6e5ab.zip |
-defining IPC messages for VPN
Diffstat (limited to 'src/vpn/gnunet-service-vpn.c')
-rw-r--r-- | src/vpn/gnunet-service-vpn.c | 113 |
1 files changed, 85 insertions, 28 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 | */ |
53 | struct destination_entry | 54 | struct 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 | */ |
111 | struct tunnel_notify_queue | 112 | struct 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 | */ |
138 | struct tunnel_state | 139 | struct 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, | |||
370 | static size_t | 371 | static size_t |
371 | send_to_peer_notify_callback (void *cls, size_t size, void *buf) | 372 | send_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 | */ |
409 | static void | 410 | static void |
410 | send_to_tunnel (struct tunnel_notify_queue *tnq, | 411 | send_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 | */ |
439 | static void | 440 | static void |
440 | route_packet (struct destination_entry *destination, | 441 | route_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 | */ | ||
1077 | static void | ||
1078 | service_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 | */ | ||
1094 | static void | ||
1095 | service_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 | */ |
1070 | static void * | 1106 | static 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 | */ | ||
1161 | static void | ||
1162 | client_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 | ||