Skip to content

Commit

Permalink
dnssec: clang-format for coherent indentation and coding style
Browse files Browse the repository at this point in the history
  • Loading branch information
linuxmaniac committed May 18, 2023
1 parent 12aea06 commit d97cebf
Show file tree
Hide file tree
Showing 3 changed files with 96 additions and 99 deletions.
127 changes: 64 additions & 63 deletions src/modules/dnssec/dnssec_func.c
Expand Up @@ -37,16 +37,16 @@
#include "../../core/dprint.h"
#include "dnssec_func.h"

static struct libval_context *libval_ctx = NULL;
static struct libval_context *libval_ctx = NULL;
static unsigned int context_flags = 0;


unsigned int
set_context_flags(unsigned int flags) {
#define CHECK_AND_SET(flag) \
if ((flag & flags) != 0) {\
context_flags |= VAL_##flag;\
LOG(L_INFO, "setting param %s\n", #flag);\
unsigned int set_context_flags(unsigned int flags)
{
#define CHECK_AND_SET(flag) \
if((flag & flags) != 0) { \
context_flags |= VAL_##flag; \
LOG(L_INFO, "setting param %s\n", #flag); \
}
unsigned int old_flags = context_flags;
context_flags = 0;
Expand All @@ -57,99 +57,100 @@ set_context_flags(unsigned int flags) {
CHECK_AND_SET(QUERY_NO_DLV);
CHECK_AND_SET(QUERY_NO_EDNS0_FALLBACK);
CHECK_AND_SET(QUERY_RECURSE);
CHECK_AND_SET(QUERY_SKIP_RESOLVER);
CHECK_AND_SET(QUERY_SKIP_CACHE);
CHECK_AND_SET(QUERY_SKIP_RESOLVER);
CHECK_AND_SET(QUERY_SKIP_CACHE);

return old_flags;
}

static inline int
dnssec_init_context(void) {
if (libval_ctx == NULL) {
if (val_create_context(NULL, &libval_ctx) != VAL_NO_ERROR)
return -1;
if (context_flags != 0) {
val_context_setqflags(libval_ctx, VAL_CTX_FLAG_SET, context_flags);
static inline int dnssec_init_context(void)
{
if(libval_ctx == NULL) {
if(val_create_context(NULL, &libval_ctx) != VAL_NO_ERROR)
return -1;
if(context_flags != 0) {
val_context_setqflags(libval_ctx, VAL_CTX_FLAG_SET, context_flags);
}
}
return 0;
}
return 0;
}

struct hostent *
dnssec_gethostbyname(const char *name) {
val_status_t val_status;
struct hostent * res;
struct hostent *dnssec_gethostbyname(const char *name)
{
val_status_t val_status;
struct hostent *res;

if (dnssec_init_context())
return NULL;
if(dnssec_init_context())
return NULL;

LOG(L_INFO, " gethostbyname(%s) called: wrapper\n", name);
LOG(L_INFO, " gethostbyname(%s) called: wrapper\n", name);

res = val_gethostbyname(libval_ctx, name, &val_status);
res = val_gethostbyname(libval_ctx, name, &val_status);

if (val_istrusted(val_status) && !val_does_not_exist(val_status)) {
return res;
}
return NULL;
if(val_istrusted(val_status) && !val_does_not_exist(val_status)) {
return res;
}
return NULL;
}


struct hostent *
dnssec_gethostbyname2(const char *name, int family) {
val_status_t val_status;
struct hostent * res;
struct hostent *dnssec_gethostbyname2(const char *name, int family)
{
val_status_t val_status;
struct hostent *res;

if (dnssec_init_context())
return NULL;
if(dnssec_init_context())
return NULL;

LOG(L_INFO, " gethostbyname2(%s) called: wrapper\n", name);
LOG(L_INFO, " gethostbyname2(%s) called: wrapper\n", name);

res = val_gethostbyname2(libval_ctx, name, family, &val_status);
res = val_gethostbyname2(libval_ctx, name, family, &val_status);

if (val_istrusted(val_status) && !val_does_not_exist(val_status)) {
return res;
}
return NULL;
if(val_istrusted(val_status) && !val_does_not_exist(val_status)) {
return res;
}
return NULL;
}

int
dnssec_res_init(void) {
LOG(L_INFO, "res_init called: wrapper\n");
int dnssec_res_init(void)
{
LOG(L_INFO, "res_init called: wrapper\n");

return dnssec_init_context();
return dnssec_init_context();
}

int
dnssec_res_destroy(void) {
int dnssec_res_destroy(void)
{
LOG(L_INFO, "destroying dnssec context\n");
val_free_context(libval_ctx);
libval_ctx = NULL;
return 0;
}


int
dnssec_res_search(const char *dname, int class_h, int type_h,
unsigned char *answer, int anslen) {
val_status_t val_status;
int ret;
int dnssec_res_search(const char *dname, int class_h, int type_h,
unsigned char *answer, int anslen)
{
val_status_t val_status;
int ret;

if (dnssec_init_context())
return -1;
if(dnssec_init_context())
return -1;

LOG(L_INFO, "res_query(%s,%d,%d) called: wrapper\n",
dname, class_h, type_h);
LOG(L_INFO, "res_query(%s,%d,%d) called: wrapper\n", dname, class_h,
type_h);

ret = val_res_search(libval_ctx, dname, class_h, type_h, answer, anslen,
&val_status);
ret = val_res_search(
libval_ctx, dname, class_h, type_h, answer, anslen, &val_status);

if (val_istrusted(val_status) && !val_does_not_exist(val_status)) {
if(val_istrusted(val_status) && !val_does_not_exist(val_status)) {
return ret;
} else {
LOG(L_INFO, "invalid domain %s reason %s\n", dname, p_val_status(val_status));
} else {
LOG(L_INFO, "invalid domain %s reason %s\n", dname,
p_val_status(val_status));
}

return -1;
return -1;
}

/*! @} */
26 changes: 13 additions & 13 deletions src/modules/dnssec/dnssec_func.h
Expand Up @@ -31,24 +31,24 @@

struct hostent;

typedef enum {
QUERY_DONT_VALIDATE = 1<<0,
QUERY_IGNORE_SKEW = 1<<1,
QUERY_AC_DETAIL = 1<<2,
QUERY_NO_DLV = 1<<3,
QUERY_NO_EDNS0_FALLBACK = 1<<4,
QUERY_RECURSE = 1<<5,
QUERY_SKIP_RESOLVER = 1<<6,
QUERY_SKIP_CACHE = 1<<7
typedef enum
{
QUERY_DONT_VALIDATE = 1 << 0,
QUERY_IGNORE_SKEW = 1 << 1,
QUERY_AC_DETAIL = 1 << 2,
QUERY_NO_DLV = 1 << 3,
QUERY_NO_EDNS0_FALLBACK = 1 << 4,
QUERY_RECURSE = 1 << 5,
QUERY_SKIP_RESOLVER = 1 << 6,
QUERY_SKIP_CACHE = 1 << 7
} query_flags_t;

int dnssec_res_init(void);
int dnssec_res_destroy(void);
unsigned int set_context_flags(unsigned int flags);
struct hostent* dnssec_gethostbyname(const char *);
struct hostent* dnssec_gethostbyname2(const char *, int);
int dnssec_res_search(const char*, int, int, unsigned char*, int);
struct hostent *dnssec_gethostbyname(const char *);
struct hostent *dnssec_gethostbyname2(const char *, int);
int dnssec_res_search(const char *, int, int, unsigned char *, int);


#endif // DNSSEC_FUNC_H

42 changes: 19 additions & 23 deletions src/modules/dnssec/dnssec_mod.c
Expand Up @@ -49,37 +49,35 @@ static int dnssec_exit(void);


/* parameters */
static unsigned int flags=0;
static unsigned int flags = 0;

/* global variables */
gen_lock_t* timer_lock=0;
struct list_link* timer = 0;
gen_lock_t *timer_lock = 0;
struct list_link *timer = 0;


static param_export_t params[]={
{"general_query_flags", INT_PARAM, &flags},
{0,0,0}
};
static param_export_t params[] = {
{"general_query_flags", INT_PARAM, &flags}, {0, 0, 0}};


struct module_exports exports= {
"dnssec", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* exported functions */
params, /* exported parameters */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
dnssec_init, /* module initialization function */
0, /* per-child init function */
dnssec_exit /* module destroy function */
struct module_exports exports = {
"dnssec", /* module name */
DEFAULT_DLFLAGS, /* dlopen flags */
0, /* exported functions */
params, /* exported parameters */
0, /* RPC method exports */
0, /* exported pseudo-variables */
0, /* response handling function */
dnssec_init, /* module initialization function */
0, /* per-child init function */
dnssec_exit /* module destroy function */
};


static int load_dns(void)
{
struct dns_func_t *f = pkg_malloc(sizeof(struct dns_func_t));
if( NULL == f ) {
if(NULL == f) {
return -1;
}
memset(f, 0, sizeof(struct dns_func_t));
Expand All @@ -97,7 +95,8 @@ static int dnssec_init(void)
LOG(L_INFO, "DNSSEC - initializing\n");

//set parameters
if(flags) set_context_flags(flags);
if(flags)
set_context_flags(flags);

if(load_dns() != 0) {
LM_ERR("loaded dnssec wrappers failed\n");
Expand All @@ -107,11 +106,8 @@ static int dnssec_init(void)
}



static int dnssec_exit(void)
{
(void)dnssec_res_destroy();
return 0;
}


0 comments on commit d97cebf

Please sign in to comment.