Merge pull request #133 from wtoorop/features/stub-only-getdns_query

Features/stub only getdns query
This commit is contained in:
wtoorop 2016-01-05 13:25:18 +01:00
commit 6dba2b98a0
5 changed files with 98 additions and 71 deletions

View File

@ -2583,7 +2583,14 @@ _getdns_ns_dns_setup(struct getdns_context *context)
return GETDNS_RETURN_GENERIC_ERROR;
#ifdef STUB_NATIVE_DNSSEC
# ifdef DNSSEC_ROADBLOCK_AVOIDANCE
# ifdef HAVE_LIBUNBOUND
return ub_setup_recursing(context->unbound_ctx, context);
# else
/* Return NOT_IMPLEMENTED on query with an
* roadblock avoidance extension.
*/
return GETDNS_RETURN_GOOD;
# endif
# else
return GETDNS_RETURN_GOOD;
# endif

View File

@ -38,13 +38,14 @@
#include <stdio.h>
#include <string.h>
#include "config.h"
#include "general.h"
#include "gldns/wire2str.h"
#include "context.h"
#include "types-internal.h"
#include "util-internal.h"
#include "dnssec.h"
#include "stub.h"
#include "general.h"
#include "dict.h"
/* cancel, cleanup and send timeout to callback */
static void
@ -330,6 +331,84 @@ _getdns_submit_netreq(getdns_network_req *netreq)
return _getdns_submit_stub_request(netreq);
}
/**
* structure used by validate_extensions() to check extension formats
*/
typedef struct getdns_extension_format
{
char *extstring;
getdns_data_type exttype;
int implemented;
} getdns_extension_format;
static int
extformatcmp(const void *a, const void *b)
{
return strcmp(((getdns_extension_format *) a)->extstring,
((getdns_extension_format *) b)->extstring);
}
/*---------------------------------------- validate_extensions */
static getdns_return_t
validate_extensions(struct getdns_dict * extensions)
{
/**
* this is a comprehensive list of extensions and their data types
* used by validate_extensions()
* The list has to be in sorted order for bsearch lookup in function
* validate_extensions.
*/
static getdns_extension_format extformats[] = {
{"add_opt_parameters" , t_dict, 1},
{"add_warning_for_bad_dns" , t_int , 1},
{"dnssec_return_only_secure" , t_int , 1},
{"dnssec_return_status" , t_int , 1},
{"dnssec_return_validation_chain", t_int , 1},
{"dnssec_roadblock_avoidance" , t_int ,
#if defined(DNSSEC_ROADBLOCK_AVOIDANCE) && defined(HAVE_LIBUNBOUND)
1},
#else
0},
#endif
{"edns_cookies" , t_int ,
#ifdef EDNS_COOKIES
1},
#else
0},
#endif
{"return_api_information" , t_int , 1},
{"return_both_v4_and_v6" , t_int , 1},
{"return_call_reporting" , t_int , 1},
{"specify_class" , t_int , 1},
};
struct getdns_dict_item *item;
getdns_extension_format *extformat;
if (extensions)
RBTREE_FOR(item, struct getdns_dict_item *,
&(extensions->root)) {
getdns_extension_format key;
key.extstring = (char *) item->node.key;
extformat = bsearch(&key, extformats,
sizeof(extformats) /
sizeof(getdns_extension_format),
sizeof(getdns_extension_format), extformatcmp);
if (!extformat)
return GETDNS_RETURN_NO_SUCH_EXTENSION;
if (!extformat->implemented)
return GETDNS_RETURN_NOT_IMPLEMENTED;
if (item->i.dtype != extformat->exttype)
return GETDNS_RETURN_EXTENSION_MISFORMAT;
}
return GETDNS_RETURN_GOOD;
} /* _getdns_validate_extensions */
static getdns_return_t
getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
const char *name, uint16_t request_type, getdns_dict *extensions,
@ -348,7 +427,7 @@ getdns_general_ns(getdns_context *context, getdns_eventloop *loop,
if ((r = _getdns_validate_dname(name)))
return r;
if (extensions && (r = _getdns_validate_extensions(extensions)))
if (extensions && (r = validate_extensions(extensions)))
return r;
/* Set up the context assuming we won't use the specified namespaces.

View File

@ -458,7 +458,13 @@ print_usage(FILE *out, const char *progname)
{
fprintf(out, "usage: %s [<option> ...] \\\n"
"\t\t[@<upstream> ...] [+<extension> ...] [<name>] [<type>]\n", progname);
fprintf(out, "\ndefault mode: recursive, synchronous resolution of NS record using UDP with TCP fallback\n");
fprintf(out, "\ndefault mode: "
#ifdef HAVE_LIBUNBOUND
"recursive"
#else
"stub"
#endif
", synchronous resolution of NS record using UDP with TCP fallback\n");
fprintf(out, "\nupstreams: @<ip>[%%<scope_id>][@<port>][#<tls port>][~<tls name>][^<tsig spec>]\n");
fprintf(out, "\ntsig spec: [<algorithm>:]<name>:<secret in Base64>\n");
fprintf(out, "\nextensions:\n");

View File

@ -160,15 +160,6 @@ typedef enum network_req_state_enum
NET_REQ_CANCELED
} network_req_state;
/**
* structure used by validate_extensions() to check extension formats
*/
typedef struct getdns_extension_format
{
char *extstring;
getdns_data_type exttype;
} getdns_extension_format;
/* State for async tcp stub resolving */
typedef struct getdns_tcp_state {

View File

@ -52,30 +52,6 @@
#include "gldns/gbuffer.h"
#include "gldns/pkthdr.h"
/**
* this is a comprehensive list of extensions and their data types
* used by validate_extensions()
* The list has to be in sorted order for bsearch lookup in function
* validate_extensions.
*/
static getdns_extension_format extformats[] = {
{"add_opt_parameters", t_dict},
{"add_warning_for_bad_dns", t_int},
{"dnssec_return_only_secure", t_int},
{"dnssec_return_status", t_int},
{"dnssec_return_validation_chain", t_int},
#ifdef DNSSEC_ROADBLOCK_AVOIDANCE
{"dnssec_roadblock_avoidance", t_int},
#endif
#ifdef EDNS_COOKIES
{"edns_cookies", t_int},
#endif
{"return_api_information", t_int},
{"return_both_v4_and_v6", t_int},
{"return_call_reporting", t_int},
{"specify_class", t_int},
};
getdns_return_t
getdns_dict_util_get_string(struct getdns_dict * dict, char *name, char **result)
@ -1040,38 +1016,6 @@ error_free_result:
return NULL;
}
static int
extformatcmp(const void *a, const void *b)
{
return strcmp(((getdns_extension_format *) a)->extstring,
((getdns_extension_format *) b)->extstring);
}
/*---------------------------------------- validate_extensions */
getdns_return_t
_getdns_validate_extensions(struct getdns_dict * extensions)
{
struct getdns_dict_item *item;
getdns_extension_format *extformat;
if (extensions)
RBTREE_FOR(item, struct getdns_dict_item *,
&(extensions->root)) {
getdns_extension_format key;
key.extstring = (char *) item->node.key;
extformat = bsearch(&key, extformats,
sizeof(extformats) /
sizeof(getdns_extension_format),
sizeof(getdns_extension_format), extformatcmp);
if (!extformat)
return GETDNS_RETURN_NO_SUCH_EXTENSION;
if (item->i.dtype != extformat->exttype)
return GETDNS_RETURN_EXTENSION_MISFORMAT;
}
return GETDNS_RETURN_GOOD;
} /* _getdns_validate_extensions */
#ifdef HAVE_LIBUNBOUND
getdns_return_t