service that opens a virtual interface and allows its clients to allocate IPs on the virtual interface and to then redirect IP traffic received on those IPs via the GNUnet cadet More...
#include "platform.h"
#include "gnunet_util_lib.h"
#include "gnunet_common.h"
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
#include "gnunet_cadet_service.h"
#include "gnunet_statistics_service.h"
#include "gnunet_regex_service.h"
#include "vpn.h"
#include "exit.h"
Go to the source code of this file.
Data Structures | |
struct | DestinationChannel |
List of channels we keep for each destination port for a given destination entry. More... | |
struct | DestinationEntry |
Information we track for each IP address to determine which channel to send the traffic over to the destination. More... | |
struct | ChannelMessageQueueEntry |
A messages we have in queue for a particular channel. More... | |
struct | ChannelState |
This struct is saved into connections_map to allow finding the right channel given an IP packet from TUN. More... | |
Macros | |
#define | MAX_MESSAGE_QUEUE_SIZE 4 |
Maximum number of messages we allow in the queue for cadet. More... | |
Functions | |
static void | get_destination_key_from_ip (int af, const void *address, struct GNUNET_HashCode *key) |
Compute the key under which we would store an entry in the destination_map for the given IP address. More... | |
static void | get_channel_key_from_ips (int af, uint8_t protocol, const void *source_ip, uint16_t source_port, const void *destination_ip, uint16_t destination_port, struct GNUNET_HashCode *key) |
Compute the key under which we would store an entry in the channel_map for the given socket address pair. More... | |
static void | send_client_reply (struct GNUNET_SERVICE_Client *client, uint64_t request_id, int result_af, const void *addr) |
Notify the client about the result of its request. More... | |
static void | free_channel_state (struct ChannelState *ts) |
Free resources associated with a channel state. More... | |
static void | send_to_channel (struct ChannelState *ts, struct GNUNET_MQ_Envelope *env) |
Add the given message to the given channel and trigger the transmission process. More... | |
static const char * | print_channel_destination (const struct DestinationEntry *de) |
Output destination of a channel for diagnostics. More... | |
static void | channel_cleaner (void *cls, const struct GNUNET_CADET_Channel *channel) |
Function called whenever a channel is destroyed. More... | |
static void | make_up_icmpv4_payload (struct ChannelState *ts, struct GNUNET_TUN_IPv4Header *ipp, struct GNUNET_TUN_UdpHeader *udp) |
Synthesize a plausible ICMP payload for an ICMP error response on the given channel. More... | |
static void | make_up_icmpv6_payload (struct ChannelState *ts, struct GNUNET_TUN_IPv6Header *ipp, struct GNUNET_TUN_UdpHeader *udp) |
Synthesize a plausible ICMP payload for an ICMP error response on the given channel. More... | |
static int | check_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) |
We got an ICMP packet back from the CADET channel. More... | |
static void | handle_icmp_back (void *cls, const struct GNUNET_EXIT_IcmpToVPNMessage *i2v) |
We got an ICMP packet back from the CADET channel. More... | |
static int | check_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) |
We got a UDP packet back from the CADET channel. More... | |
static void | handle_udp_back (void *cls, const struct GNUNET_EXIT_UdpReplyMessage *reply) |
We got a UDP packet back from the CADET channel. More... | |
static int | check_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) |
We got a TCP packet back from the CADET channel. More... | |
static void | handle_tcp_back (void *cls, const struct GNUNET_EXIT_TcpDataMessage *data) |
We got a TCP packet back from the CADET channel. More... | |
static struct GNUNET_CADET_Channel * | create_channel (struct ChannelState *ts, const struct GNUNET_PeerIdentity *target, const struct GNUNET_HashCode *port) |
Create a channel for ts to target at port. More... | |
static void | handle_regex_result (void *cls, const struct GNUNET_PeerIdentity *id, const struct GNUNET_PeerIdentity *get_path, unsigned int get_path_length, const struct GNUNET_PeerIdentity *put_path, unsigned int put_path_length) |
Regex has found a potential exit peer for us; consider using it. More... | |
static struct ChannelState * | create_channel_to_destination (struct DestinationChannel *dt, int client_af) |
Initialize the given destination entry's cadet channel. More... | |
static void | expire_channel (struct ChannelState *except) |
We have too many active channels. More... | |
static void | route_packet (struct DestinationEntry *destination, int af, uint8_t protocol, const void *source_ip, const void *destination_ip, const void *payload, size_t payload_length) |
Route a packet via cadet to the given destination. More... | |
static int | message_token (void *cls, const struct GNUNET_MessageHeader *message) |
Receive packets from the helper-process (someone send to the local virtual channel interface). More... | |
static int | allocate_v4_address (struct in_addr *v4) |
Allocate an IPv4 address from the range of the channel for a new redirection. More... | |
static int | allocate_v6_address (struct in6_addr *v6) |
Allocate an IPv6 address from the range of the channel for a new redirection. More... | |
static void | free_destination_entry (struct DestinationEntry *de) |
Free resources occupied by a destination entry. More... | |
static void | expire_destination (struct DestinationEntry *except) |
We have too many active destinations. More... | |
static int | allocate_response_ip (int *result_af, void **addr, struct in_addr *v4, struct in6_addr *v6) |
Allocate an IP address for the response. More... | |
static int | check_client_redirect_to_ip (void *cls, const struct RedirectToIpRequestMessage *msg) |
A client asks us to setup a redirection via some exit node to a particular IP. More... | |
static void | handle_client_redirect_to_ip (void *cls, const struct RedirectToIpRequestMessage *msg) |
A client asks us to setup a redirection via some exit node to a particular IP. More... | |
static void | handle_client_redirect_to_service (void *cls, const struct RedirectToServiceRequestMessage *msg) |
A client asks us to setup a redirection to a particular peer offering a service. More... | |
static int | cleanup_destination (void *cls, const struct GNUNET_HashCode *key, void *value) |
Free memory occupied by an entry in the destination map. More... | |
static int | cleanup_channel (void *cls, const struct GNUNET_HashCode *key, void *value) |
Free memory occupied by an entry in the channel map. More... | |
static void | cleanup (void *cls) |
Function scheduled as very last function, cleans up after us. More... | |
static void * | client_connect_cb (void *cls, struct GNUNET_SERVICE_Client *c, struct GNUNET_MQ_Handle *mq) |
Callback called when a client connects to the service. More... | |
static void | client_disconnect_cb (void *cls, struct GNUNET_SERVICE_Client *c, void *internal_cls) |
Callback called when a client disconnected from the service. More... | |
static void | run (void *cls, const struct GNUNET_CONFIGURATION_Handle *cfg_, struct GNUNET_SERVICE_Handle *service) |
Main function that will be run by the scheduler. More... | |
GNUNET_SERVICE_MAIN (GNUNET_OS_project_data_gnunet(), "vpn", GNUNET_SERVICE_OPTION_NONE, &run, &client_connect_cb, &client_disconnect_cb, NULL, GNUNET_MQ_hd_var_size(client_redirect_to_ip, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, struct RedirectToIpRequestMessage, NULL), GNUNET_MQ_hd_fixed_size(client_redirect_to_service, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, struct RedirectToServiceRequestMessage, NULL), GNUNET_MQ_handler_end()) | |
Define "main" method using service macro. More... | |
Variables | |
static int | global_ret |
Return value from main(). More... | |
static const struct GNUNET_CONFIGURATION_Handle * | cfg |
Configuration we use. More... | |
static struct GNUNET_CADET_Handle * | cadet_handle |
Handle to the cadet service. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | destination_map |
Map from IP address to destination information (possibly with a CADET channel handle for fast setup). More... | |
static struct GNUNET_CONTAINER_Heap * | destination_heap |
Min-Heap sorted by activity time to expire old mappings. More... | |
static struct GNUNET_CONTAINER_MultiHashMap * | channel_map |
Map from source and destination address (IP+port) to connection information (mostly with the respective CADET channel handle). More... | |
static struct GNUNET_CONTAINER_Heap * | channel_heap |
Min-Heap sorted by activity time to expire old mappings; values are of type 'struct ChannelState'. More... | |
static struct GNUNET_STATISTICS_Handle * | stats |
Statistics. More... | |
static struct GNUNET_HELPER_Handle * | helper_handle |
The handle to the VPN helper process "gnunet-helper-vpn". More... | |
static char * | vpn_argv [7] |
Arguments to the vpn helper. More... | |
static unsigned long long | ipv6prefix |
Length of the prefix of the VPN's IPv6 network. More... | |
static unsigned long long | max_destination_mappings |
If there are more than this number of address-mappings, old ones will be removed. More... | |
static unsigned long long | max_channel_mappings |
If there are more than this number of open channels, old ones will be removed. More... | |
service that opens a virtual interface and allows its clients to allocate IPs on the virtual interface and to then redirect IP traffic received on those IPs via the GNUnet cadet
TODO:
Definition in file gnunet-service-vpn.c.
#define MAX_MESSAGE_QUEUE_SIZE 4 |
Maximum number of messages we allow in the queue for cadet.
Definition at line 48 of file gnunet-service-vpn.c.
|
static |
Compute the key under which we would store an entry in the destination_map for the given IP address.
af | address family (AF_INET or AF_INET6) |
address | IP address, struct in_addr or struct in6_addr |
key | where to store the key |
Definition at line 381 of file gnunet-service-vpn.c.
References address, GNUNET_assert, GNUNET_CRYPTO_hash(), and key.
Referenced by allocate_v4_address(), allocate_v6_address(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), and message_token().
|
static |
Compute the key under which we would store an entry in the channel_map for the given socket address pair.
af | address family (AF_INET or AF_INET6) |
protocol | IPPROTO_TCP or IPPROTO_UDP |
source_ip | sender's source IP, struct in_addr or struct in6_addr |
source_port | sender's source port |
destination_ip | sender's destination IP, struct in_addr or struct in6_addr |
destination_port | sender's destination port |
key | where to store the key |
Definition at line 415 of file gnunet-service-vpn.c.
References GNUNET_assert, GNUNET_memcpy, and key.
Referenced by free_channel_state(), and route_packet().
|
static |
Notify the client about the result of its request.
client | client to notify |
request_id | original request ID to include in response |
result_af | resulting address family |
addr | resulting IP address |
Definition at line 467 of file gnunet-service-vpn.c.
References env, GNUNET_assert, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_CLIENT_USE_IP, GNUNET_MQ_msg_extra, GNUNET_MQ_send(), GNUNET_SERVICE_client_get_mq(), res, and RedirectToIpResponseMessage::result_af.
Referenced by handle_client_redirect_to_ip(), and handle_client_redirect_to_service().
|
static |
Free resources associated with a channel state.
ts | state to free |
Definition at line 508 of file gnunet-service-vpn.c.
References ChannelState::af, ChannelState::channel, channel_map, ChannelState::destination, ChannelState::destination_ip, ChannelState::destination_port, get_channel_key_from_ips(), gettext_noop, GNUNET_assert, GNUNET_CADET_channel_destroy(), GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_REGEX_search_cancel(), GNUNET_STATISTICS_update(), GNUNET_YES, ChannelState::heap_node, DestinationEntry::heap_node, key, ChannelState::protocol, ChannelState::search, ChannelState::source_ip, ChannelState::source_port, stats, ChannelState::tmq_head, ChannelState::tmq_length, and ChannelState::tmq_tail.
Referenced by channel_cleaner(), cleanup_channel(), and expire_channel().
|
static |
Add the given message to the given channel and trigger the transmission process.
ts | channel to queue the message for |
env | message to queue |
Definition at line 565 of file gnunet-service-vpn.c.
References ChannelState::channel, env, gettext_noop, GNUNET_assert, GNUNET_CADET_get_mq(), GNUNET_MQ_discard(), GNUNET_MQ_env_set_options(), GNUNET_MQ_get_length(), GNUNET_MQ_PREF_OUT_OF_ORDER, GNUNET_MQ_PRIO_BEST_EFFORT, GNUNET_MQ_send(), GNUNET_MQ_unsent_head(), GNUNET_NO, GNUNET_STATISTICS_update(), MAX_MESSAGE_QUEUE_SIZE, mq, and stats.
Referenced by route_packet().
|
static |
Output destination of a channel for diagnostics.
de | destination to process |
Definition at line 596 of file gnunet-service-vpn.c.
References DestinationEntry::af, warningfilter::dest, DestinationEntry::details, DestinationEntry::exit_destination, GNUNET_h2s(), GNUNET_i2s(), GNUNET_snprintf(), DestinationEntry::ip, DestinationEntry::is_service, DestinationEntry::service_descriptor, DestinationEntry::service_destination, and DestinationEntry::target.
Referenced by channel_cleaner(), cleanup_channel(), expire_channel(), free_destination_entry(), handle_regex_result(), and route_packet().
|
static |
Function called whenever a channel is destroyed.
Should clean up any associated state.
cls | our struct ChannelState |
channel | connection to the other end (henceforth invalid) |
Definition at line 628 of file gnunet-service-vpn.c.
References ChannelState::channel, ChannelState::destination, free_channel_state(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and print_channel_destination().
Referenced by create_channel().
|
static |
Synthesize a plausible ICMP payload for an ICMP error response on the given channel.
ts | channel information |
ipp | IPv4 header to fill in (ICMP payload) |
udp | "UDP" header to fill in (ICMP payload); might actually also be the first 8 bytes of the TCP header |
Definition at line 651 of file gnunet-service-vpn.c.
References ChannelState::destination_ip, ChannelState::destination_port, GNUNET_TUN_initialize_ipv4_header(), ChannelState::protocol, ChannelState::source_ip, ChannelState::source_port, udp, and ChannelState::v4.
Referenced by handle_icmp_back().
|
static |
Synthesize a plausible ICMP payload for an ICMP error response on the given channel.
ts | channel information |
ipp | IPv6 header to fill in (ICMP payload) |
udp | "UDP" header to fill in (ICMP payload); might actually also be the first 8 bytes of the TCP header |
Definition at line 677 of file gnunet-service-vpn.c.
References ChannelState::destination_ip, ChannelState::destination_port, GNUNET_TUN_initialize_ipv6_header(), ChannelState::protocol, ChannelState::source_ip, ChannelState::source_port, udp, and ChannelState::v6.
Referenced by handle_icmp_back().
|
static |
We got an ICMP packet back from the CADET channel.
Check it is OK.
cls | our struct ChannelState * |
i2v | the actual message |
Definition at line 702 of file gnunet-service-vpn.c.
References ChannelState::af, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and ChannelState::heap_node.
|
static |
We got an ICMP packet back from the CADET channel.
Pass it on to the local virtual interface via the helper.
cls | our struct ChannelState * |
i2v | the actual message |
Definition at line 728 of file gnunet-service-vpn.c.
References GNUNET_EXIT_IcmpToVPNMessage::af, ChannelState::af, ChannelState::channel, ChannelState::destination_ip, ETH_P_IPV4, ETH_P_IPV6, GNUNET_TUN_Layer2PacketHeader::flags, gettext_noop, GNUNET_ALIGN, GNUNET_assert, GNUNET_break_op, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_heap_update_cost(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELPER_send(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_HELPER, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TUN_calculate_icmp_checksum(), GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE, GNUNET_TUN_ICMPTYPE6_ECHO_REPLY, GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST, GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG, GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM, GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED, GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE, GNUNET_TUN_ICMPTYPE_ECHO_REPLY, GNUNET_TUN_ICMPTYPE_ECHO_REQUEST, GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH, GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED, GNUNET_TUN_initialize_ipv4_header(), GNUNET_TUN_initialize_ipv6_header(), GNUNET_YES, GNUNET_EXIT_IcmpToVPNMessage::header, ChannelState::heap_node, helper_handle, GNUNET_EXIT_IcmpToVPNMessage::icmp_header, ipv4, ipv6, make_up_icmpv4_payload(), make_up_icmpv6_payload(), msg, GNUNET_TUN_Layer2PacketHeader::proto, GNUNET_MessageHeader::size, size, ChannelState::source_ip, stats, GNUNET_MessageHeader::type, GNUNET_TUN_IcmpHeader::type, udp, ChannelState::v4, and ChannelState::v6.
|
static |
We got a UDP packet back from the CADET channel.
Check that it is OK.
cls | our struct ChannelState * |
reply | the actual message |
Definition at line 1078 of file gnunet-service-vpn.c.
References ChannelState::af, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and ChannelState::heap_node.
|
static |
We got a UDP packet back from the CADET channel.
Pass it on to the local virtual interface via the helper.
cls | our struct ChannelState * |
reply | the actual message |
Definition at line 1104 of file gnunet-service-vpn.c.
References ChannelState::af, ChannelState::channel, ChannelState::destination_ip, GNUNET_EXIT_UdpReplyMessage::destination_port, ChannelState::destination_port, ETH_P_IPV4, ETH_P_IPV6, GNUNET_TUN_Layer2PacketHeader::flags, gettext_noop, GNUNET_ALIGN, GNUNET_assert, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_heap_update_cost(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELPER_send(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_HELPER, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TUN_calculate_udp4_checksum(), GNUNET_TUN_calculate_udp6_checksum(), GNUNET_TUN_initialize_ipv4_header(), GNUNET_TUN_initialize_ipv6_header(), GNUNET_YES, GNUNET_EXIT_UdpReplyMessage::header, ChannelState::heap_node, helper_handle, ipv4, ipv6, msg, GNUNET_TUN_Layer2PacketHeader::proto, GNUNET_MessageHeader::size, size, ChannelState::source_ip, GNUNET_EXIT_UdpReplyMessage::source_port, ChannelState::source_port, stats, GNUNET_MessageHeader::type, udp, ChannelState::v4, and ChannelState::v6.
|
static |
We got a TCP packet back from the CADET channel.
Check it is OK.
cls | our struct ChannelState * |
data | the actual message |
Definition at line 1228 of file gnunet-service-vpn.c.
References data, GNUNET_break_op, GNUNET_OK, GNUNET_SYSERR, and ChannelState::heap_node.
|
static |
We got a TCP packet back from the CADET channel.
Pass it on to the local virtual interface via the helper.
cls | our struct ChannelState * |
data | the actual message |
Definition at line 1254 of file gnunet-service-vpn.c.
References ChannelState::af, ChannelState::channel, data, ChannelState::destination_ip, ChannelState::destination_port, ETH_P_IPV4, ETH_P_IPV6, GNUNET_TUN_Layer2PacketHeader::flags, gettext_noop, GNUNET_ALIGN, GNUNET_CADET_receive_done(), GNUNET_CONTAINER_heap_update_cost(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_HELPER_send(), GNUNET_log, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_HELPER, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TUN_calculate_tcp4_checksum(), GNUNET_TUN_calculate_tcp6_checksum(), GNUNET_TUN_initialize_ipv4_header(), GNUNET_TUN_initialize_ipv6_header(), GNUNET_YES, ChannelState::heap_node, helper_handle, ipv4, ipv6, msg, GNUNET_TUN_Layer2PacketHeader::proto, GNUNET_MessageHeader::size, size, ChannelState::source_ip, ChannelState::source_port, stats, tcp, GNUNET_MessageHeader::type, ChannelState::v4, and ChannelState::v6.
|
static |
Create a channel for ts to target at port.
ts | channel state to create the channel for |
target | peer to connect to |
port | destination port |
Definition at line 1362 of file gnunet-service-vpn.c.
References cadet_handle, channel_cleaner(), GNUNET_CADET_channel_create(), GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_VPN, GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_VPN, GNUNET_MESSAGE_TYPE_VPN_UDP_REPLY, GNUNET_MQ_handler_end, GNUNET_MQ_hd_var_size, and port.
Referenced by create_channel_to_destination(), and handle_regex_result().
|
static |
Regex has found a potential exit peer for us; consider using it.
cls | the struct ChannelState |
id | Peer providing a regex that matches the string. |
get_path | Path of the get request. |
get_path_length | Length of get_path. |
put_path | Path of the put request. |
put_path_length | Length of the put_path. |
Definition at line 1402 of file gnunet-service-vpn.c.
References ChannelState::af, ChannelState::channel, create_channel(), ChannelState::destination, GNUNET_APPLICATION_PORT_IPV4_GATEWAY, GNUNET_APPLICATION_PORT_IPV6_GATEWAY, GNUNET_break, GNUNET_CRYPTO_hash(), GNUNET_ERROR_TYPE_INFO, GNUNET_i2s(), GNUNET_log, GNUNET_REGEX_search_cancel(), port, print_channel_destination(), and ChannelState::search.
Referenced by create_channel_to_destination().
|
static |
Initialize the given destination entry's cadet channel.
dt | destination channel for which we need to setup a channel |
client_af | address family of the address returned to the client |
Definition at line 1454 of file gnunet-service-vpn.c.
References address, DestinationEntry::af, ChannelState::af, cadet_port, cfg, ChannelState::channel, create_channel(), DestinationChannel::destination, ChannelState::destination, DestinationChannel::destination_port, ChannelState::destination_port, DestinationEntry::details, DestinationEntry::exit_destination, gettext_noop, GNUNET_APPLICATION_TYPE_EXIT_REGEX_PREFIX, GNUNET_asprintf(), GNUNET_assert, GNUNET_break, GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_NO, GNUNET_REGEX_ipv4toregexsearch(), GNUNET_REGEX_ipv6toregexsearch(), GNUNET_REGEX_search(), GNUNET_STATISTICS_update(), GNUNET_TUN_compute_service_cadet_port(), GNUNET_TUN_IPV4_REGEXLEN, GNUNET_TUN_IPV6_REGEXLEN, handle_regex_result(), DestinationEntry::heap_node, DestinationEntry::ip, DestinationEntry::is_service, ChannelState::search, DestinationEntry::service_descriptor, DestinationEntry::service_destination, stats, DestinationEntry::target, DestinationEntry::v4, and DestinationEntry::v6.
Referenced by route_packet().
|
static |
We have too many active channels.
Clean up the oldest channel.
except | channel that must NOT be cleaned up, even if it is the oldest |
Definition at line 1552 of file gnunet-service-vpn.c.
References channel_heap, ChannelState::destination, free_channel_state(), GNUNET_assert, GNUNET_CONTAINER_heap_peek(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, and print_channel_destination().
Referenced by route_packet().
|
static |
Route a packet via cadet to the given destination.
destination | description of the destination |
af | address family on this end (AF_INET or AF_INET6) |
protocol | IPPROTO_TCP or IPPROTO_UDP or IPPROTO_ICMP or IPPROTO_ICMPV6 |
source_ip | source IP used by the sender (struct in_addr or struct in6_addr) |
destination_ip | destination IP used by the sender (struct in_addr or struct in6_addr) |
payload | payload of the packet after the IP header |
payload_length | number of bytes in payload |
Definition at line 1579 of file gnunet-service-vpn.c.
References _, GNUNET_EXIT_TcpInternetStartMessage::af, GNUNET_EXIT_UdpInternetMessage::af, GNUNET_EXIT_IcmpServiceMessage::af, GNUNET_EXIT_IcmpInternetMessage::af, DestinationEntry::af, ChannelState::af, ChannelState::channel, channel_heap, channel_map, create_channel_to_destination(), DestinationChannel::destination, ChannelState::destination, ChannelState::destination_ip, GNUNET_EXIT_UdpServiceMessage::destination_port, GNUNET_EXIT_UdpInternetMessage::destination_port, DestinationChannel::destination_port, ChannelState::destination_port, DestinationEntry::details, DestinationEntry::dt_head, DestinationEntry::dt_tail, env, DestinationEntry::exit_destination, expire_channel(), get_channel_key_from_ips(), gettext_noop, GNUNET_assert, GNUNET_break, GNUNET_break_op, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_heap_update_cost(), GNUNET_CONTAINER_multihashmap_get(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_UNIQUE_ONLY, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_INFO, GNUNET_ERROR_TYPE_WARNING, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_MAX_MESSAGE_SIZE, GNUNET_memcpy, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, GNUNET_MESSAGE_TYPE_VPN_TCP_DATA_TO_EXIT, GNUNET_MESSAGE_TYPE_VPN_TCP_TO_INTERNET_START, GNUNET_MESSAGE_TYPE_VPN_TCP_TO_SERVICE_START, GNUNET_MESSAGE_TYPE_VPN_UDP_TO_INTERNET, GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, GNUNET_MQ_msg_extra, GNUNET_new, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_get(), GNUNET_TUN_ICMPTYPE6_DESTINATION_UNREACHABLE, GNUNET_TUN_ICMPTYPE6_ECHO_REPLY, GNUNET_TUN_ICMPTYPE6_ECHO_REQUEST, GNUNET_TUN_ICMPTYPE6_PACKET_TOO_BIG, GNUNET_TUN_ICMPTYPE6_PARAMETER_PROBLEM, GNUNET_TUN_ICMPTYPE6_TIME_EXCEEDED, GNUNET_TUN_ICMPTYPE_DESTINATION_UNREACHABLE, GNUNET_TUN_ICMPTYPE_ECHO_REPLY, GNUNET_TUN_ICMPTYPE_ECHO_REQUEST, GNUNET_TUN_ICMPTYPE_SOURCE_QUENCH, GNUNET_TUN_ICMPTYPE_TIME_EXCEEDED, GNUNET_YES, ChannelState::heap_node, GNUNET_EXIT_IcmpServiceMessage::icmp_header, GNUNET_EXIT_IcmpInternetMessage::icmp_header, DestinationEntry::ip, ChannelState::is_established, DestinationEntry::is_service, key, max_channel_mappings, DestinationChannel::next, payload, print_channel_destination(), ChannelState::protocol, GNUNET_EXIT_TcpServiceStartMessage::reserved, GNUNET_EXIT_TcpDataMessage::reserved, ChannelState::search, send_to_channel(), DestinationEntry::service_descriptor, DestinationEntry::service_destination, ChannelState::source_ip, GNUNET_EXIT_UdpServiceMessage::source_port, GNUNET_EXIT_UdpInternetMessage::source_port, ChannelState::source_port, stats, DestinationEntry::target, tcp, GNUNET_EXIT_TcpServiceStartMessage::tcp_header, GNUNET_EXIT_TcpInternetStartMessage::tcp_header, GNUNET_EXIT_TcpDataMessage::tcp_header, GNUNET_TUN_IcmpHeader::type, udp, DestinationEntry::v4, ChannelState::v4, DestinationEntry::v6, and ChannelState::v6.
Referenced by message_token().
|
static |
Receive packets from the helper-process (someone send to the local virtual channel interface).
Find the destination mapping, and if it exists, identify the correct CADET channel (or possibly create it) and forward the packet.
cls | closure, NULL |
message | message we got from the client (VPN channel interface) |
Definition at line 2273 of file gnunet-service-vpn.c.
References _, GNUNET_TUN_IPv4Header::destination_address, GNUNET_TUN_IPv6Header::destination_address, destination_map, ETH_P_IPV4, ETH_P_IPV6, get_destination_key_from_ip(), gettext_noop, GNUNET_break, GNUNET_CONTAINER_multihashmap_get(), GNUNET_ERROR_TYPE_INFO, GNUNET_log, GNUNET_MESSAGE_TYPE_VPN_HELPER, GNUNET_NO, GNUNET_OK, GNUNET_STATISTICS_update(), GNUNET_TUN_IPv4Header::header_length, key, GNUNET_TUN_IPv6Header::next_header, GNUNET_TUN_Layer2PacketHeader::proto, GNUNET_TUN_IPv4Header::protocol, route_packet(), GNUNET_MessageHeader::size, GNUNET_TUN_IPv4Header::source_address, GNUNET_TUN_IPv6Header::source_address, stats, and GNUNET_MessageHeader::type.
Referenced by run().
|
static |
Allocate an IPv4 address from the range of the channel for a new redirection.
v4 | where to store the address |
Definition at line 2388 of file gnunet-service-vpn.c.
References _, destination_map, get_destination_key_from_ip(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, key, and vpn_argv.
Referenced by allocate_response_ip().
|
static |
Allocate an IPv6 address from the range of the channel for a new redirection.
v6 | where to store the address |
Definition at line 2437 of file gnunet-service-vpn.c.
References _, destination_map, get_destination_key_from_ip(), GNUNET_assert, GNUNET_CONTAINER_multihashmap_contains(), GNUNET_CRYPTO_QUALITY_WEAK, GNUNET_CRYPTO_random_u32(), GNUNET_ERROR_TYPE_WARNING, GNUNET_log, GNUNET_memcmp, GNUNET_OK, GNUNET_SYSERR, GNUNET_YES, ipv6prefix, key, and vpn_argv.
Referenced by allocate_response_ip().
|
static |
Free resources occupied by a destination entry.
de | entry to free |
Definition at line 2491 of file gnunet-service-vpn.c.
References destination_map, DestinationEntry::dt_head, DestinationEntry::dt_tail, gettext_noop, GNUNET_assert, GNUNET_CONTAINER_DLL_remove, GNUNET_CONTAINER_heap_remove_node(), GNUNET_CONTAINER_multihashmap_remove(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_update(), GNUNET_YES, DestinationEntry::heap_node, DestinationEntry::key, print_channel_destination(), and stats.
Referenced by cleanup_destination(), and expire_destination().
|
static |
We have too many active destinations.
Clean up the oldest destination.
except | destination that must NOT be cleaned up, even if it is the oldest |
Definition at line 2525 of file gnunet-service-vpn.c.
References destination_heap, free_destination_entry(), GNUNET_assert, and GNUNET_CONTAINER_heap_peek().
Referenced by handle_client_redirect_to_ip(), and handle_client_redirect_to_service().
|
static |
Allocate an IP address for the response.
result_af | desired address family; set to the actual address family; can initially be AF_UNSPEC if there is no preference; will be set to AF_UNSPEC if the allocation failed |
addr | set to either v4 or v6 depending on which storage location was used; set to NULL if allocation failed |
v4 | storage space for an IPv4 address |
v6 | storage space for an IPv6 address |
* result_af
was an unsupported address family (not AF_INET, AF_INET6 or AF_UNSPEC) Definition at line 2552 of file gnunet-service-vpn.c.
References allocate_v4_address(), allocate_v6_address(), GNUNET_break, GNUNET_OK, GNUNET_SYSERR, DestinationEntry::v4, and DestinationEntry::v6.
Referenced by handle_client_redirect_to_ip(), and handle_client_redirect_to_service().
|
static |
A client asks us to setup a redirection via some exit node to a particular IP.
Check if msg is well-formed. allocated IP.
cls | client requesting client |
msg | redirection request |
Definition at line 2605 of file gnunet-service-vpn.c.
References RedirectToIpRequestMessage::addr_af, GNUNET_break, GNUNET_OK, GNUNET_SYSERR, consensus-simulation::int, msg, and GNUNET_MessageHeader::size.
|
static |
A client asks us to setup a redirection via some exit node to a particular IP.
Setup the redirection and give the client the allocated IP.
cls | client requesting client |
msg | redirection request |
Definition at line 2648 of file gnunet-service-vpn.c.
References GNUNET_TIME_Absolute::abs_value_us, RedirectToIpRequestMessage::addr_af, DestinationEntry::af, allocate_response_ip(), destination_heap, destination_map, DestinationEntry::details, DestinationEntry::exit_destination, expire_destination(), get_destination_key_from_ip(), gettext_noop, GNUNET_assert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_memcpy, GNUNET_new, GNUNET_NO, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_STATISTICS_update(), GNUNET_TIME_absolute_ntoh(), DestinationEntry::heap_node, consensus-simulation::int, DestinationEntry::ip, DestinationEntry::is_service, key, DestinationEntry::key, max_destination_mappings, msg, RedirectToIpRequestMessage::result_af, send_client_reply(), GNUNET_MessageHeader::size, and stats.
|
static |
A client asks us to setup a redirection to a particular peer offering a service.
Setup the redirection and give the client the allocated IP.
cls | requesting client |
msg | redirection request |
Definition at line 2726 of file gnunet-service-vpn.c.
References _, GNUNET_TIME_Absolute::abs_value_us, allocate_response_ip(), DestinationChannel::destination, destination_heap, destination_map, DestinationEntry::details, DestinationEntry::dt_head, DestinationEntry::dt_tail, expire_destination(), get_destination_key_from_ip(), GNUNET_assert, GNUNET_break, GNUNET_CONTAINER_DLL_insert, GNUNET_CONTAINER_heap_insert(), GNUNET_CONTAINER_multihashmap_put(), GNUNET_CONTAINER_multihashmap_size(), GNUNET_CONTAINER_MULTIHASHMAPOPTION_MULTIPLE, GNUNET_ERROR_TYPE_DEBUG, GNUNET_ERROR_TYPE_ERROR, GNUNET_h2s(), GNUNET_i2s(), GNUNET_log, GNUNET_new, GNUNET_OK, GNUNET_SERVICE_client_continue(), GNUNET_SERVICE_client_drop(), GNUNET_TIME_absolute_ntoh(), GNUNET_YES, DestinationEntry::heap_node, consensus-simulation::int, DestinationEntry::is_service, key, DestinationEntry::key, max_destination_mappings, msg, send_client_reply(), DestinationEntry::service_descriptor, DestinationEntry::service_destination, and DestinationEntry::target.
|
static |
Free memory occupied by an entry in the destination map.
cls | unused |
key | unused |
value | a struct DestinationEntry * |
Definition at line 2805 of file gnunet-service-vpn.c.
References free_destination_entry(), GNUNET_OK, and value.
Referenced by cleanup().
|
static |
Free memory occupied by an entry in the channel map.
cls | unused |
key | unused |
value | a struct ChannelState * |
Definition at line 2823 of file gnunet-service-vpn.c.
References ChannelState::destination, free_channel_state(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_log, GNUNET_OK, print_channel_destination(), and value.
Referenced by cleanup().
|
static |
Function scheduled as very last function, cleans up after us.
cls | unused |
Definition at line 2841 of file gnunet-service-vpn.c.
References cadet_handle, channel_heap, channel_map, cleanup_channel(), cleanup_destination(), destination_heap, destination_map, GNUNET_CADET_disconnect(), GNUNET_CONTAINER_heap_destroy(), GNUNET_CONTAINER_multihashmap_destroy(), GNUNET_CONTAINER_multihashmap_iterate(), GNUNET_ERROR_TYPE_DEBUG, GNUNET_free, GNUNET_HELPER_kill(), GNUNET_HELPER_wait(), GNUNET_log, GNUNET_NO, GNUNET_STATISTICS_destroy(), helper_handle, stats, and vpn_argv.
Referenced by run().
|
static |
Callback called when a client connects to the service.
cls | closure for the service |
c | the new client that connected to the service |
mq | the message queue used to send messages to the client |
Definition at line 2900 of file gnunet-service-vpn.c.
|
static |
Callback called when a client disconnected from the service.
cls | closure for the service |
c | the client that disconnected |
internal_cls | should be equal to c |
Definition at line 2916 of file gnunet-service-vpn.c.
References GNUNET_assert.
|
static |
Main function that will be run by the scheduler.
cls | closure |
cfg_ | configuration |
service | the initialized service |
Definition at line 2932 of file gnunet-service-vpn.c.
References _, cadet_handle, cfg, channel_heap, channel_map, cleanup(), destination_heap, destination_map, global_ret, GNUNET_CADET_connect(), GNUNET_CONFIGURATION_get_value_number(), GNUNET_CONFIGURATION_get_value_string(), GNUNET_CONTAINER_heap_create(), GNUNET_CONTAINER_HEAP_ORDER_MIN, GNUNET_CONTAINER_multihashmap_create(), GNUNET_ERROR_TYPE_ERROR, GNUNET_ERROR_TYPE_INFO, GNUNET_free, GNUNET_HELPER_start(), GNUNET_log, GNUNET_log_config_invalid(), GNUNET_log_config_missing(), GNUNET_NETWORK_test_pf(), GNUNET_NO, GNUNET_OK, GNUNET_OS_check_helper_binary(), GNUNET_OS_get_suid_binary_path(), GNUNET_OS_project_data_gnunet(), GNUNET_SCHEDULER_add_shutdown(), GNUNET_SCHEDULER_shutdown(), GNUNET_STATISTICS_create(), GNUNET_strdup, GNUNET_SYSERR, GNUNET_YES, helper_handle, ipv6prefix, max_channel_mappings, max_destination_mappings, message_token(), stats, and vpn_argv.
GNUNET_SERVICE_MAIN | ( | GNUNET_OS_project_data_gnunet() | , |
"vpn" | , | ||
GNUNET_SERVICE_OPTION_NONE | , | ||
& | run, | ||
& | client_connect_cb, | ||
& | client_disconnect_cb, | ||
NULL | , | ||
GNUNET_MQ_hd_var_size(client_redirect_to_ip, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_IP, struct RedirectToIpRequestMessage, NULL) | , | ||
GNUNET_MQ_hd_fixed_size(client_redirect_to_service, GNUNET_MESSAGE_TYPE_VPN_CLIENT_REDIRECT_TO_SERVICE, struct RedirectToServiceRequestMessage, NULL) | , | ||
GNUNET_MQ_handler_end() | |||
) |
Define "main" method using service macro.
|
static |
|
static |
Configuration we use.
Definition at line 309 of file gnunet-service-vpn.c.
Referenced by create_channel_to_destination(), and run().
|
static |
Handle to the cadet service.
Definition at line 314 of file gnunet-service-vpn.c.
Referenced by cleanup(), create_channel(), and run().
|
static |
Map from IP address to destination information (possibly with a CADET channel handle for fast setup).
Definition at line 320 of file gnunet-service-vpn.c.
Referenced by allocate_v4_address(), allocate_v6_address(), cleanup(), free_destination_entry(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), message_token(), and run().
|
static |
Min-Heap sorted by activity time to expire old mappings.
Definition at line 325 of file gnunet-service-vpn.c.
Referenced by cleanup(), expire_destination(), handle_client_redirect_to_ip(), handle_client_redirect_to_service(), and run().
|
static |
Map from source and destination address (IP+port) to connection information (mostly with the respective CADET channel handle).
Definition at line 331 of file gnunet-service-vpn.c.
Referenced by cleanup(), free_channel_state(), route_packet(), and run().
|
static |
Min-Heap sorted by activity time to expire old mappings; values are of type 'struct ChannelState'.
Definition at line 337 of file gnunet-service-vpn.c.
Referenced by cleanup(), expire_channel(), route_packet(), and run().
|
static |
Statistics.
Definition at line 342 of file gnunet-service-vpn.c.
Referenced by cleanup(), create_channel_to_destination(), free_channel_state(), free_destination_entry(), handle_client_redirect_to_ip(), handle_icmp_back(), handle_tcp_back(), handle_udp_back(), message_token(), route_packet(), run(), and send_to_channel().
|
static |
The handle to the VPN helper process "gnunet-helper-vpn".
Definition at line 347 of file gnunet-service-vpn.c.
Referenced by cleanup(), handle_icmp_back(), handle_tcp_back(), handle_udp_back(), and run().
|
static |
Arguments to the vpn helper.
Definition at line 352 of file gnunet-service-vpn.c.
Referenced by allocate_v4_address(), allocate_v6_address(), cleanup(), and run().
|
static |
Length of the prefix of the VPN's IPv6 network.
Definition at line 357 of file gnunet-service-vpn.c.
Referenced by allocate_v6_address(), and run().
|
static |
If there are more than this number of address-mappings, old ones will be removed.
Definition at line 363 of file gnunet-service-vpn.c.
Referenced by handle_client_redirect_to_ip(), handle_client_redirect_to_service(), and run().
|
static |
If there are more than this number of open channels, old ones will be removed.
Definition at line 369 of file gnunet-service-vpn.c.
Referenced by route_packet(), and run().