projects
/
oweals
/
gnunet.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
Merge branch 'master' into getopt
[oweals/gnunet.git]
/
src
/
dns
/
dnsstub.c
diff --git
a/src/dns/dnsstub.c
b/src/dns/dnsstub.c
index caf90f3d297bc22334553d48813e43ce3ac80606..68cd55275085ed85a70f8824e7f88b4d6af79798 100644
(file)
--- a/
src/dns/dnsstub.c
+++ b/
src/dns/dnsstub.c
@@
-1,6
+1,6
@@
/*
This file is part of GNUnet.
/*
This file is part of GNUnet.
- (C) 2012 Christian Grothoff (and other contributing authors)
+ Copyright (C) 2012 GNUnet e.V.
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
GNUnet is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published
@@
-14,8
+14,8
@@
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
You should have received a copy of the GNU General Public License
along with GNUnet; see the file COPYING. If not, write to the
- Free Software Foundation, Inc., 5
9 Temple Place - Suite 330
,
- Boston, MA 0211
1-1307
, USA.
+ Free Software Foundation, Inc., 5
1 Franklin Street, Fifth Floor
,
+ Boston, MA 0211
0-1301
, USA.
*/
/**
* @file dns/dnsstub.c
*/
/**
* @file dns/dnsstub.c
@@
-24,6
+24,7
@@
*/
#include "platform.h"
#include "gnunet_util_lib.h"
*/
#include "platform.h"
#include "gnunet_util_lib.h"
+#include "gnunet_tun_lib.h"
#include "gnunet_dnsstub_lib.h"
/**
#include "gnunet_dnsstub_lib.h"
/**
@@
-43,7
+44,7
@@
*/
struct GNUNET_DNSSTUB_RequestSocket
{
*/
struct GNUNET_DNSSTUB_RequestSocket
{
-
+
/**
* UDP socket we use for this request for IPv4
*/
/**
* UDP socket we use for this request for IPv4
*/
@@
-60,14
+61,14
@@
struct GNUNET_DNSSTUB_RequestSocket
GNUNET_DNSSTUB_ResultCallback rc;
/**
GNUNET_DNSSTUB_ResultCallback rc;
/**
- * Closure for
'rc'
.
+ * Closure for
@e rc
.
*/
void *rc_cls;
/**
* Task for reading from dnsout4 and dnsout6.
*/
*/
void *rc_cls;
/**
* Task for reading from dnsout4 and dnsout6.
*/
-
GNUNET_SCHEDULER_TaskIdentifier
read_task;
+
struct GNUNET_SCHEDULER_Task *
read_task;
/**
* When should this request time out?
/**
* When should this request time out?
@@
-80,7
+81,7
@@
struct GNUNET_DNSSTUB_RequestSocket
struct sockaddr_storage addr;
/**
struct sockaddr_storage addr;
/**
- * Number of bytes in
'addr'
.
+ * Number of bytes in
@e addr
.
*/
socklen_t addrlen;
*/
socklen_t addrlen;
@@
-89,18
+90,18
@@
struct GNUNET_DNSSTUB_RequestSocket
/**
* Handle to the stub resolver.
/**
* Handle to the stub resolver.
- */
+ */
struct GNUNET_DNSSTUB_Context
{
/**
struct GNUNET_DNSSTUB_Context
{
/**
- * Array of all open sockets for DNS requests.
+ * Array of all open sockets for DNS requests.
*/
struct GNUNET_DNSSTUB_RequestSocket sockets[DNS_SOCKET_MAX];
/**
* IP address to use for the DNS server if we are a DNS exit service
*/
struct GNUNET_DNSSTUB_RequestSocket sockets[DNS_SOCKET_MAX];
/**
* IP address to use for the DNS server if we are a DNS exit service
- * (for VPN via
mesh
); otherwise NULL.
+ * (for VPN via
cadet
); otherwise NULL.
*/
char *dns_exit;
};
*/
char *dns_exit;
};
@@
-108,7
+109,7
@@
struct GNUNET_DNSSTUB_Context
/**
/**
- * We're done with a
GNUNET_DNSSTUB_RequestSocket
, close it for now.
+ * We're done with a
`struct GNUNET_DNSSTUB_RequestSocket`
, close it for now.
*
* @param rs request socket to clean up
*/
*
* @param rs request socket to clean up
*/
@@
-125,10
+126,10
@@
cleanup_rs (struct GNUNET_DNSSTUB_RequestSocket *rs)
GNUNET_NETWORK_socket_close (rs->dnsout6);
rs->dnsout6 = NULL;
}
GNUNET_NETWORK_socket_close (rs->dnsout6);
rs->dnsout6 = NULL;
}
- if (
GNUNET_SCHEDULER_NO_TASK
!= rs->read_task)
+ if (
NULL
!= rs->read_task)
{
GNUNET_SCHEDULER_cancel (rs->read_task);
{
GNUNET_SCHEDULER_cancel (rs->read_task);
- rs->read_task =
GNUNET_SCHEDULER_NO_TASK
;
+ rs->read_task =
NULL
;
}
}
}
}
@@
-137,8
+138,8
@@
cleanup_rs (struct GNUNET_DNSSTUB_RequestSocket *rs)
* Open source port for sending DNS requests
*
* @param af AF_INET or AF_INET6
* Open source port for sending DNS requests
*
* @param af AF_INET or AF_INET6
- * @return GNUNET_OK on success
- */
+ * @return
#
GNUNET_OK on success
+ */
static struct GNUNET_NETWORK_Handle *
open_socket (int af)
{
static struct GNUNET_NETWORK_Handle *
open_socket (int af)
{
@@
-167,12
+168,11
@@
open_socket (int af)
return NULL;
}
sa->sa_family = af;
return NULL;
}
sa->sa_family = af;
- if (GNUNET_OK !=
- GNUNET_NETWORK_socket_bind (ret,
- sa,
- alen))
- {
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ if (GNUNET_OK != GNUNET_NETWORK_socket_bind (ret,
+ sa,
+ alen))
+ {
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Could not bind to any port: %s\n"),
STRERROR (errno));
GNUNET_NETWORK_socket_close (ret);
_("Could not bind to any port: %s\n"),
STRERROR (errno));
GNUNET_NETWORK_socket_close (ret);
@@
-186,16
+186,14
@@
open_socket (int af)
* Read a DNS response from the (unhindered) UDP-Socket
*
* @param cls socket to read from
* Read a DNS response from the (unhindered) UDP-Socket
*
* @param cls socket to read from
- * @param tc scheduler context (must be shutdown or read ready)
*/
static void
*/
static void
-read_response (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc);
+read_response (void *cls);
/**
* Get a socket of the specified address family to send out a
/**
* Get a socket of the specified address family to send out a
- * UDP DNS request to the Internet.
+ * UDP DNS request to the Internet.
*
* @param ctx the DNSSTUB context
* @param af desired address family
*
* @param ctx the DNSSTUB context
* @param af desired address family
@@
-208,7
+206,7
@@
get_request_socket (struct GNUNET_DNSSTUB_Context *ctx,
struct GNUNET_DNSSTUB_RequestSocket *rs;
struct GNUNET_NETWORK_FDSet *rset;
struct GNUNET_DNSSTUB_RequestSocket *rs;
struct GNUNET_NETWORK_FDSet *rset;
- rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
+ rs = &ctx->sockets[GNUNET_CRYPTO_random_u32 (GNUNET_CRYPTO_QUALITY_NONCE,
DNS_SOCKET_MAX)];
rs->timeout = GNUNET_TIME_relative_to_absolute (REQUEST_TIMEOUT);
switch (af)
DNS_SOCKET_MAX)];
rs->timeout = GNUNET_TIME_relative_to_absolute (REQUEST_TIMEOUT);
switch (af)
@@
-223,11
+221,11
@@
get_request_socket (struct GNUNET_DNSSTUB_Context *ctx,
break;
default:
return NULL;
break;
default:
return NULL;
- }
- if (
GNUNET_SCHEDULER_NO_TASK
!= rs->read_task)
+ }
+ if (
NULL
!= rs->read_task)
{
GNUNET_SCHEDULER_cancel (rs->read_task);
{
GNUNET_SCHEDULER_cancel (rs->read_task);
- rs->read_task =
GNUNET_SCHEDULER_NO_TASK
;
+ rs->read_task =
NULL
;
}
if ( (NULL == rs->dnsout4) &&
(NULL == rs->dnsout6) )
}
if ( (NULL == rs->dnsout4) &&
(NULL == rs->dnsout6) )
@@
-280,13
+278,13
@@
GNUNET_DNSSTUB_resolve (struct GNUNET_DNSSTUB_Context *ctx,
else
ret = rs->dnsout6;
GNUNET_assert (NULL != ret);
else
ret = rs->dnsout6;
GNUNET_assert (NULL != ret);
- memcpy (&rs->addr,
+
GNUNET_
memcpy (&rs->addr,
sa,
sa_len);
rs->addrlen = sa_len;
rs->rc = rc;
rs->rc_cls = rc_cls;
sa,
sa_len);
rs->addrlen = sa_len;
rs->rc = rc;
rs->rc_cls = rc_cls;
- if (GNUNET_SYSERR ==
+ if (GNUNET_SYSERR ==
GNUNET_NETWORK_socket_sendto (ret,
request,
request_len,
GNUNET_NETWORK_socket_sendto (ret,
request,
request_len,
@@
-351,7
+349,7
@@
GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
#endif
sa = (struct sockaddr *) &v6;
af = AF_INET6;
#endif
sa = (struct sockaddr *) &v6;
af = AF_INET6;
- }
+ }
else
{
GNUNET_break (0);
else
{
GNUNET_break (0);
@@
-370,7
+368,7
@@
GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
ctx->dns_exit);
return NULL;
}
ctx->dns_exit);
return NULL;
}
- memcpy (&rs->addr,
+
GNUNET_
memcpy (&rs->addr,
sa,
salen);
rs->addrlen = salen;
sa,
salen);
rs->addrlen = salen;
@@
-384,9
+382,7
@@
GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
_("Failed to send DNS request to %s\n"),
GNUNET_a2s (sa, salen));
rs->timeout = GNUNET_TIME_relative_to_absolute (REQUEST_TIMEOUT);
_("Failed to send DNS request to %s\n"),
GNUNET_a2s (sa, salen));
rs->timeout = GNUNET_TIME_relative_to_absolute (REQUEST_TIMEOUT);
-
return rs;
return rs;
-
}
}
@@
-396,7
+392,7
@@
GNUNET_DNSSTUB_resolve2 (struct GNUNET_DNSSTUB_Context *ctx,
*
* @param rs request socket with callback details
* @param dnsout socket to read from
*
* @param rs request socket with callback details
* @param dnsout socket to read from
- * @return
GNUNET_OK on success, GNUNET_NO on drop,
GNUNET_SYSERR on IO-errors (closed socket)
+ * @return
#GNUNET_OK on success, #GNUNET_NO on drop, #
GNUNET_SYSERR on IO-errors (closed socket)
*/
static int
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
*/
static int
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
@@
-420,13
+416,13
@@
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving %d byte DNS reply\n",
#endif
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
"Receiving %d byte DNS reply\n",
- len);
+ len);
{
unsigned char buf[len] GNUNET_ALIGN;
addrlen = sizeof (addr);
{
unsigned char buf[len] GNUNET_ALIGN;
addrlen = sizeof (addr);
- memset (&addr, 0, sizeof (addr));
- r = GNUNET_NETWORK_socket_recvfrom (dnsout,
+ memset (&addr, 0, sizeof (addr));
+ r = GNUNET_NETWORK_socket_recvfrom (dnsout,
buf, sizeof (buf),
(struct sockaddr*) &addr, &addrlen);
if (-1 == r)
buf, sizeof (buf),
(struct sockaddr*) &addr, &addrlen);
if (-1 == r)
@@
-437,20
+433,21
@@
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
}
if (sizeof (struct GNUNET_TUN_DnsHeader) > r)
{
}
if (sizeof (struct GNUNET_TUN_DnsHeader) > r)
{
- GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
+ GNUNET_log (GNUNET_ERROR_TYPE_ERROR,
_("Received DNS response that is too small (%u bytes)"),
_("Received DNS response that is too small (%u bytes)"),
- r);
+
(unsigned int)
r);
return GNUNET_NO;
}
dns = (struct GNUNET_TUN_DnsHeader *) buf;
if ( (addrlen != rs->addrlen) ||
return GNUNET_NO;
}
dns = (struct GNUNET_TUN_DnsHeader *) buf;
if ( (addrlen != rs->addrlen) ||
- (0 != memcmp (&rs->addr,
- &addr,
- addrlen)) ||
+ (GNUNET_YES !=
+ GNUNET_TUN_sockaddr_cmp ((struct sockaddr *) &rs->addr,
+ (struct sockaddr *) &addr,
+ GNUNET_YES)) ||
(0 == GNUNET_TIME_absolute_get_remaining (rs->timeout).rel_value_us) )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
(0 == GNUNET_TIME_absolute_get_remaining (rs->timeout).rel_value_us) )
{
GNUNET_log (GNUNET_ERROR_TYPE_DEBUG,
- "Request timeout or invalid sender address; ignoring reply\n");
+ "Request timeout or invalid sender address; ignoring reply\n");
return GNUNET_NO;
}
if (NULL != rs->rc)
return GNUNET_NO;
}
if (NULL != rs->rc)
@@
-458,7
+455,7
@@
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
rs,
dns,
r);
rs,
dns,
r);
- }
+ }
return GNUNET_OK;
}
return GNUNET_OK;
}
@@
-467,19
+464,19
@@
do_dns_read (struct GNUNET_DNSSTUB_RequestSocket *rs,
* Read a DNS response from the (unhindered) UDP-Socket
*
* @param cls socket to read from
* Read a DNS response from the (unhindered) UDP-Socket
*
* @param cls socket to read from
- * @param tc scheduler context (must be shutdown or read ready)
*/
static void
*/
static void
-read_response (void *cls,
- const struct GNUNET_SCHEDULER_TaskContext *tc)
+read_response (void *cls)
{
struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
struct GNUNET_NETWORK_FDSet *rset;
{
struct GNUNET_DNSSTUB_RequestSocket *rs = cls;
struct GNUNET_NETWORK_FDSet *rset;
+ const struct GNUNET_SCHEDULER_TaskContext *tc;
- rs->read_task = GNUNET_SCHEDULER_NO_TASK;
+ rs->read_task = NULL;
+ tc = GNUNET_SCHEDULER_get_task_context ();
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
{
if (0 == (tc->reason & GNUNET_SCHEDULER_REASON_READ_READY))
{
- /* timeout
or shutdown
*/
+ /* timeout */
cleanup_rs (rs);
return;
}
cleanup_rs (rs);
return;
}
@@
-530,8
+527,8
@@
struct GNUNET_DNSSTUB_Context *
GNUNET_DNSSTUB_start (const char *dns_ip)
{
struct GNUNET_DNSSTUB_Context *ctx;
GNUNET_DNSSTUB_start (const char *dns_ip)
{
struct GNUNET_DNSSTUB_Context *ctx;
-
- ctx = GNUNET_
malloc (sizeof (struct GNUNET_DNSSTUB_Context)
);
+
+ ctx = GNUNET_
new (struct GNUNET_DNSSTUB_Context
);
if (NULL != dns_ip)
ctx->dns_exit = GNUNET_strdup (dns_ip);
return ctx;
if (NULL != dns_ip)
ctx->dns_exit = GNUNET_strdup (dns_ip);
return ctx;