/**
* @file exit/gnunet-daemon-exit.c
- * @brief tool to allow IP traffic exit from the GNUnet mesh to the Internet
+ * @brief tool to allow IP traffic exit from the GNUnet cadet to the Internet
* @author Philipp Toelke
* @author Christian Grothoff
*
#include "gnunet_protocols.h"
#include "gnunet_applications.h"
#include "gnunet_dht_service.h"
-#include "gnunet_mesh_service.h"
+#include "gnunet_cadet_service.h"
#include "gnunet_dnsparser_lib.h"
#include "gnunet_dnsstub_lib.h"
#include "gnunet_statistics_service.h"
/**
- * Maximum path compression length for mesh regex announcing for IPv4 address
+ * Maximum path compression length for cadet regex announcing for IPv4 address
* based regex.
*/
#define REGEX_MAX_PATH_LEN_IPV4 4
/**
- * Maximum path compression length for mesh regex announcing for IPv6 address
+ * Maximum path compression length for cadet regex announcing for IPv6 address
* based regex.
*/
#define REGEX_MAX_PATH_LEN_IPV6 8
struct ChannelState
{
/**
- * Mesh channel that is used for this connection.
+ * Cadet channel that is used for this connection.
*/
- struct GNUNET_MESH_Channel *channel;
+ struct GNUNET_CADET_Channel *channel;
/**
* Who is the other end of this channel.
/**
* Active channel transmission request (or NULL).
*/
- struct GNUNET_MESH_TransmitHandle *th;
+ struct GNUNET_CADET_TransmitHandle *th;
/**
* #GNUNET_NO if this is a channel for TCP/UDP,
static struct GNUNET_STATISTICS_Handle *stats;
/**
- * The handle to mesh
+ * The handle to cadet
*/
-static struct GNUNET_MESH_Handle *mesh_handle;
+static struct GNUNET_CADET_Handle *cadet_handle;
/**
* This hashmaps contains the mapping from peer, service-descriptor,
/**
- * We got a reply from DNS for a request of a MESH channel. Send it
+ * We got a reply from DNS for a request of a CADET channel. Send it
* via the channel (after changing the request ID back).
*
* @param cls the 'struct ChannelState'
* @return number of bytes written to buf
*/
static size_t
-transmit_reply_to_mesh (void *cls,
+transmit_reply_to_cadet (void *cls,
size_t size,
void *buf)
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Processing DNS result from stub resolver\n");
GNUNET_assert (NULL == cls);
- /* Handle case that this is a reply to a request from a MESH DNS channel */
+ /* Handle case that this is a reply to a request from a CADET DNS channel */
ts = channels[dns->id];
if ( (NULL == ts) ||
(ts->specifics.dns.rs != rs) )
return;
LOG (GNUNET_ERROR_TYPE_DEBUG,
- "Got a response from the stub resolver for DNS request received via MESH!\n");
+ "Got a response from the stub resolver for DNS request received via CADET!\n");
channels[dns->id] = NULL;
GNUNET_free_non_null (ts->specifics.dns.reply);
ts->specifics.dns.reply = GNUNET_malloc (r);
ts->specifics.dns.reply_length = r;
memcpy (ts->specifics.dns.reply, dns, r);
if (NULL != ts->th)
- GNUNET_MESH_notify_transmit_ready_cancel (ts->th);
- ts->th = GNUNET_MESH_notify_transmit_ready (ts->channel,
+ GNUNET_CADET_notify_transmit_ready_cancel (ts->th);
+ ts->th = GNUNET_CADET_notify_transmit_ready (ts->channel,
GNUNET_NO,
GNUNET_TIME_UNIT_FOREVER_REL,
sizeof (struct GNUNET_MessageHeader) + r,
- &transmit_reply_to_mesh,
+ &transmit_reply_to_cadet,
ts);
}
/**
- * Process a request via mesh to perform a DNS query.
+ * Process a request via cadet to perform a DNS query.
*
* @param cls closure, NULL
* @param channel connection to the other end
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel,
+receive_dns_request (void *cls GNUNET_UNUSED, struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
/**
- * MESH is ready to receive a message for the channel. Transmit it.
+ * CADET is ready to receive a message for the channel. Transmit it.
*
* @param cls the 'struct ChannelState'.
* @param size number of bytes available in buf
send_to_peer_notify_callback (void *cls, size_t size, void *buf)
{
struct ChannelState *s = cls;
- struct GNUNET_MESH_Channel *channel = s->channel;
+ struct GNUNET_CADET_Channel *channel = s->channel;
struct ChannelMessageQueue *tnq;
s->th = NULL;
return 0;
if (0 == size)
{
- s->th = GNUNET_MESH_notify_transmit_ready (channel,
+ s->th = GNUNET_CADET_notify_transmit_ready (channel,
GNUNET_NO /* corking */,
GNUNET_TIME_UNIT_FOREVER_REL,
tnq->len,
tnq);
GNUNET_free (tnq);
if (NULL != (tnq = s->specifics.tcp_udp.head))
- s->th = GNUNET_MESH_notify_transmit_ready (channel,
+ s->th = GNUNET_CADET_notify_transmit_ready (channel,
GNUNET_NO /* corking */,
GNUNET_TIME_UNIT_FOREVER_REL,
tnq->len,
&send_to_peer_notify_callback,
s);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes transmitted via mesh channels"),
+ gettext_noop ("# Bytes transmitted via cadet channels"),
size, GNUNET_NO);
return size;
}
/**
- * Send the given packet via the mesh channel.
+ * Send the given packet via the cadet channel.
*
* @param s channel destination
* @param tnq message to queue
*/
static void
-send_packet_to_mesh_channel (struct ChannelState *s,
+send_packet_to_cadet_channel (struct ChannelState *s,
struct ChannelMessageQueue *tnq)
{
- struct GNUNET_MESH_Channel *mesh_channel;
+ struct GNUNET_CADET_Channel *cadet_channel;
- mesh_channel = s->channel;
+ cadet_channel = s->channel;
GNUNET_assert (NULL != s);
GNUNET_CONTAINER_DLL_insert_tail (s->specifics.tcp_udp.head, s->specifics.tcp_udp.tail, tnq);
if (NULL == s->th)
- s->th = GNUNET_MESH_notify_transmit_ready (mesh_channel,
+ s->th = GNUNET_CADET_notify_transmit_ready (cadet_channel,
GNUNET_NO /* cork */,
GNUNET_TIME_UNIT_FOREVER_REL,
tnq->len,
memcpy (&i2v->icmp_header,
icmp,
pktlen);
- send_packet_to_mesh_channel (state, tnq);
+ send_packet_to_cadet_channel (state, tnq);
}
memcpy (&urm[1],
&udp[1],
pktlen - sizeof (struct GNUNET_TUN_UdpHeader));
- send_packet_to_mesh_channel (state, tnq);
+ send_packet_to_cadet_channel (state, tnq);
}
memcpy (&tdm->tcp_header,
buf,
pktlen);
- send_packet_to_mesh_channel (state, tnq);
+ send_packet_to_cadet_channel (state, tnq);
}
* We are starting a fresh connection (TCP or UDP) and need
* to pick a source port and IP address (within the correct
* range and address family) to associate replies with the
- * connection / correct mesh channel. This function generates
+ * connection / correct cadet channel. This function generates
* a "fresh" source IP and source port number for a connection
* After picking a good source address, this function sets up
* the state in the 'connections_map' and 'connections_heap'
s = GNUNET_CONTAINER_heap_remove_root (connections_heap);
GNUNET_assert (state != s);
s->specifics.tcp_udp.heap_node = NULL;
- GNUNET_MESH_channel_destroy (s->channel);
+ GNUNET_CADET_channel_destroy (s->channel);
GNUNET_assert (GNUNET_OK ==
GNUNET_CONTAINER_multihashmap_remove (connections_map,
&s->specifics.tcp_udp.state_key,
/**
- * Process a request via mesh to send a request to a TCP service
+ * Process a request via cadet to send a request to a TCP service
* offered by this system.
*
* @param cls closure, NULL
*/
static int
receive_tcp_service (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# TCP service creation requests received via mesh"),
+ gettext_noop ("# TCP service creation requests received via cadet"),
1, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
/* check that we got at least a valid header */
if (pkt_len < sizeof (struct GNUNET_EXIT_TcpServiceStartMessage))
GNUNET_i2s (&state->peer),
GNUNET_h2s (&start->service_descriptor),
(unsigned int) ntohs (start->tcp_header.destination_port));
- if (NULL == (state->specifics.tcp_udp.serv = find_service (tcp_services, &start->service_descriptor,
- ntohs (start->tcp_header.destination_port))))
+ if (NULL == (state->specifics.tcp_udp.serv =
+ find_service (tcp_services,
+ &start->service_descriptor,
+ ntohs (start->tcp_header.destination_port))))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("No service found for %s on port %d!\n"),
+ _("No service %s found for %s on port %d!\n"),
+ GNUNET_h2s (&start->service_descriptor),
"TCP",
ntohs (start->tcp_header.destination_port));
GNUNET_STATISTICS_update (stats,
* GNUNET_SYSERR to close it (signal serious error)
*/
static int
-receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel,
+receive_tcp_remote (void *cls GNUNET_UNUSED, struct GNUNET_CADET_Channel *channel,
void **channel_ctx GNUNET_UNUSED,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# TCP IP-exit creation requests received via mesh"),
+ gettext_noop ("# TCP IP-exit creation requests received via cadet"),
1, GNUNET_NO);
if (pkt_len < sizeof (struct GNUNET_EXIT_TcpInternetStartMessage))
{
* #GNUNET_SYSERR to close it (signal serious error)
*/
static int
-receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_MESH_Channel *channel,
+receive_tcp_data (void *cls GNUNET_UNUSED, struct GNUNET_CADET_Channel *channel,
void **channel_ctx GNUNET_UNUSED,
const struct GNUNET_MessageHeader *message)
{
uint16_t pkt_len = ntohs (message->size);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# TCP data requests received via mesh"),
+ gettext_noop ("# TCP data requests received via cadet"),
1, GNUNET_NO);
if (pkt_len < sizeof (struct GNUNET_EXIT_TcpDataMessage))
{
*/
static int
receive_icmp_remote (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# ICMP IP-exit requests received via mesh"),
+ gettext_noop ("# ICMP IP-exit requests received via cadet"),
1, GNUNET_NO);
if (pkt_len < sizeof (struct GNUNET_EXIT_IcmpInternetMessage))
{
/**
- * Process a request via mesh to send ICMP data to a service
+ * Process a request via cadet to send ICMP data to a service
* offered by this system.
*
* @param cls closure, NULL
*/
static int
receive_icmp_service (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# ICMP service requests received via mesh"),
+ gettext_noop ("# ICMP service requests received via cadet"),
1, GNUNET_NO);
/* check that we got at least a valid header */
if (pkt_len < sizeof (struct GNUNET_EXIT_IcmpServiceMessage))
*/
static int
receive_udp_remote (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# UDP IP-exit requests received via mesh"),
+ gettext_noop ("# UDP IP-exit requests received via cadet"),
1, GNUNET_NO);
if (pkt_len < sizeof (struct GNUNET_EXIT_UdpInternetMessage))
{
/**
- * Process a request via mesh to send a request to a UDP service
+ * Process a request via cadet to send a request to a UDP service
* offered by this system.
*
* @param cls closure, NULL
*/
static int
receive_udp_service (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
void **channel_ctx,
const struct GNUNET_MessageHeader *message)
{
state->is_dns = GNUNET_NO;
}
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Bytes received from MESH"),
+ gettext_noop ("# Bytes received from CADET"),
pkt_len, GNUNET_NO);
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# UDP service requests received via mesh"),
+ gettext_noop ("# UDP service requests received via cadet"),
1, GNUNET_NO);
/* check that we got at least a valid header */
if (pkt_len < sizeof (struct GNUNET_EXIT_UdpServiceMessage))
GNUNET_i2s (&state->peer),
GNUNET_h2s (&msg->service_descriptor),
(unsigned int) ntohs (msg->destination_port));
- if (NULL == (state->specifics.tcp_udp.serv = find_service (udp_services, &msg->service_descriptor,
- ntohs (msg->destination_port))))
+ if (NULL == (state->specifics.tcp_udp.serv =
+ find_service (udp_services,
+ &msg->service_descriptor,
+ ntohs (msg->destination_port))))
{
GNUNET_log (GNUNET_ERROR_TYPE_INFO,
- _("No service found for %s on port %d!\n"),
+ _("No service %s found for %s on port %d!\n"),
+ GNUNET_h2s (&msg->service_descriptor),
"UDP",
ntohs (msg->destination_port));
GNUNET_STATISTICS_update (stats,
/**
- * Callback from GNUNET_MESH for new channels.
+ * Callback from GNUNET_CADET for new channels.
*
* @param cls closure
* @param channel new handle to the channel
*/
static void *
new_channel (void *cls,
- struct GNUNET_MESH_Channel *channel,
+ struct GNUNET_CADET_Channel *channel,
const struct GNUNET_PeerIdentity *initiator,
- uint32_t port, enum GNUNET_MESH_ChannelOption options)
+ uint32_t port, enum GNUNET_CADET_ChannelOption options)
{
struct ChannelState *s = GNUNET_new (struct ChannelState);
s->is_dns = GNUNET_SYSERR;
s->peer = *initiator;
GNUNET_STATISTICS_update (stats,
- gettext_noop ("# Inbound MESH channels created"),
+ gettext_noop ("# Inbound CADET channels created"),
1, GNUNET_NO);
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Received inbound channel from `%s'\n",
/**
- * Function called by mesh whenever an inbound channel is destroyed.
+ * Function called by cadet whenever an inbound channel is destroyed.
* Should clean up any associated state.
*
- * @param cls closure (set from #GNUNET_MESH_connect)
+ * @param cls closure (set from #GNUNET_CADET_connect)
* @param channel connection to the other end (henceforth invalid)
* @param channel_ctx place where local state associated
* with the channel is stored
*/
static void
clean_channel (void *cls,
- const struct GNUNET_MESH_Channel *channel,
+ const struct GNUNET_CADET_Channel *channel,
void *channel_ctx)
{
struct ChannelState *s = channel_ctx;
}
if (NULL != s->th)
{
- GNUNET_MESH_notify_transmit_ready_cancel (s->th);
+ GNUNET_CADET_notify_transmit_ready_cancel (s->th);
s->th = NULL;
}
GNUNET_free (s);
}
+/**
+ * Function scheduled as very last function if the service
+ * disabled itself because the helper is not installed
+ * properly. Does nothing, except for keeping the
+ * service process alive by virtue of being scheduled.
+ *
+ * @param cls NULL
+ * @param tc scheduler context
+ */
+static void
+dummy_task (void *cls,
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
+{
+ /* just terminate */
+}
+
+
/**
* Function scheduled as very last function, cleans up after us
+ *
+ * @param cls NULL
+ * @param tc scheduler context
*/
static void
cleanup (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tskctx)
+ const struct GNUNET_SCHEDULER_TaskContext *tc)
{
unsigned int i;
GNUNET_REGEX_announce_cancel (regex6);
regex6 = NULL;
}
- if (NULL != mesh_handle)
+ if (NULL != cadet_handle)
{
- GNUNET_MESH_disconnect (mesh_handle);
- mesh_handle = NULL;
+ GNUNET_CADET_disconnect (cadet_handle);
+ cadet_handle = NULL;
}
if (NULL != connections_map)
{
char *hostname;
char *hostport;
struct LocalService *serv;
+ char *n;
+ size_t slen;
+
+ slen = strlen (name);
+ GNUNET_assert (slen >= 8);
+ n = GNUNET_strndup (name, slen - 8 /* remove .gnunet. */);
for (redirect = strtok (cpy, " "); redirect != NULL;
redirect = strtok (NULL, " "))
if (NULL == (hostport = strstr (hostname, ":")))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("Option `%s' for domain `%s' is not formatted correctly!\n"),
- redirect,
- name);
+ _("Option `%s' for domain `%s' is not formatted correctly!\n"),
+ redirect,
+ name);
continue;
}
hostport[0] = '\0';
if (!((local_port > 0) && (local_port < 65536)))
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
- _("`%s' is not a valid port number (for domain `%s')!"),
+ _("`%s' is not a valid port number (for domain `%s')!"),
redirect,
- name);
+ name);
continue;
}
if (!((remote_port > 0) && (remote_port < 65536)))
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("No addresses found for hostname `%s' of service `%s'!\n"),
hostname,
- name);
+ n);
GNUNET_free (serv);
continue;
}
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Service `%s' configured for IPv4, but IPv4 is disabled!\n"),
- name);
+ n);
freeaddrinfo (res);
GNUNET_free (serv);
continue;
{
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("Service `%s' configured for IPv4, but IPv4 is disabled!\n"),
- name);
+ n);
freeaddrinfo (res);
GNUNET_free (serv);
continue;
GNUNET_log (GNUNET_ERROR_TYPE_WARNING,
_("No IP addresses found for hostname `%s' of service `%s'!\n"),
hostname,
- name);
+ n);
GNUNET_free (serv);
continue;
}
freeaddrinfo (res);
}
store_service ((IPPROTO_UDP == proto) ? udp_services : tcp_services,
- name,
+ n,
local_port,
serv);
}
+ GNUNET_free (n);
}
const char *cfgfile,
const struct GNUNET_CONFIGURATION_Handle *cfg_)
{
- static struct GNUNET_MESH_MessageHandler handlers[] = {
+ static struct GNUNET_CADET_MessageHandler handlers[] = {
{&receive_icmp_service, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_SERVICE, 0},
{&receive_icmp_remote, GNUNET_MESSAGE_TYPE_VPN_ICMP_TO_INTERNET, 0},
{&receive_udp_service, GNUNET_MESSAGE_TYPE_VPN_UDP_TO_SERVICE, 0},
{
GNUNET_free (binary);
GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
- _("`%s' must be installed SUID, refusing to run\n"),
+ _("`%s' must be installed SUID, EXIT will not work\n"),
"gnunet-helper-exit");
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &dummy_task,
+ NULL);
global_ret = 1;
return;
}
app_idx++;
}
GNUNET_free_non_null (dns_exit);
- GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL, &cleanup, cls);
+ GNUNET_SCHEDULER_add_delayed (GNUNET_TIME_UNIT_FOREVER_REL,
+ &cleanup,
+ cls);
if (GNUNET_OK !=
GNUNET_CONFIGURATION_get_value_number (cfg, "exit", "MAX_CONNECTIONS",
GNUNET_SCHEDULER_shutdown ();
return;
}
- mesh_handle
- = GNUNET_MESH_connect (cfg, NULL,
+ cadet_handle
+ = GNUNET_CADET_connect (cfg, NULL,
&new_channel,
&clean_channel, handlers,
apptypes);
- if (NULL == mesh_handle)
+ if (NULL == cadet_handle)
{
GNUNET_SCHEDULER_shutdown ();
return;
}
- /* Mesh handle acquired, now announce regular expressions matching our exit */
+ /* Cadet handle acquired, now announce regular expressions matching our exit */
if ( (GNUNET_YES == ipv4_enabled) && (GNUNET_YES == ipv4_exit) )
{
policy = NULL;