Skip to content

Commit

Permalink
libknet: first big hammer on logging
Browse files Browse the repository at this point in the history
still needs fine tuning as we go to understand exactly what to log
in debugging mode

Signed-off-by: Fabio M. Di Nitto <fdinitto@redhat.com>
  • Loading branch information
fabbione committed Nov 2, 2012
1 parent 3c569e7 commit 708d7c3
Show file tree
Hide file tree
Showing 11 changed files with 319 additions and 138 deletions.
6 changes: 4 additions & 2 deletions kronosnetd/vty_cli_cmds.c
Expand Up @@ -805,6 +805,8 @@ static int knet_cmd_link_dyn(struct knet_vty *vty)

static int knet_cmd_link_timer(struct knet_vty *vty)
{
struct knet_cfg *knet_iface = (struct knet_cfg *)vty->iface;
struct knet_host *host = (struct knet_host *)vty->host;
struct knet_link *klink = (struct knet_link *)vty->link;
int paramlen = 0, paramoffset = 0;
char *param = NULL;
Expand All @@ -816,7 +818,7 @@ static int knet_cmd_link_timer(struct knet_vty *vty)
get_param(vty, 2, &param, &paramlen, &paramoffset);
holdtime = param_to_int(param, paramlen);

knet_link_timeout(klink, keepalive, holdtime, 2048);
knet_link_timeout(knet_iface->cfg_ring.knet_h, host->node_id, klink, keepalive, holdtime, 2048);

return 0;
}
Expand Down Expand Up @@ -928,7 +930,7 @@ static int knet_cmd_link(struct knet_vty *vty)
klink->sock = host->listener4->sock;
}

knet_link_timeout(klink, 1000, 5000, 2048);
knet_link_timeout(knet_iface->cfg_ring.knet_h, host->node_id, klink, 1000, 5000, 2048);

knet_link_enable(knet_iface->cfg_ring.knet_h, host->node_id, klink, 1);
}
Expand Down
1 change: 1 addition & 0 deletions libknet/common.c
Expand Up @@ -52,6 +52,7 @@ int _dst_cache_update(knet_handle_t knet_h, uint16_t node_id)
write_retry++;
goto try_again;
} else {
log_debug(knet_h, KNET_SUB_COMMON, "Unable to write to comm pipe");
return -1;
}
}
Expand Down
26 changes: 10 additions & 16 deletions libknet/crypto.c
Expand Up @@ -5,14 +5,7 @@

#include "crypto.h"
#include "nsscrypto.h"
#include "libknet.h"

#ifdef CRYPTO_DEBUG
#include <stdio.h>
#define log_printf(format, args...) fprintf(stderr, format "\n", ##args);
#else
#define log_printf(format, args...);
#endif
#include "libknet-private.h"

/*
* internal module switch data
Expand Down Expand Up @@ -40,42 +33,43 @@ static int get_model(const char *model)
*/

int crypto_encrypt_and_sign (
struct crypto_instance *instance,
knet_handle_t knet_h,
const unsigned char *buf_in,
const ssize_t buf_in_len,
unsigned char *buf_out,
ssize_t *buf_out_len)
{
return modules_cmds[instance->model].crypt(instance->model_instance,
buf_in, buf_in_len, buf_out, buf_out_len);
return modules_cmds[knet_h->crypto_instance->model].crypt(knet_h, buf_in, buf_in_len, buf_out, buf_out_len);
}

int crypto_authenticate_and_decrypt (struct crypto_instance *instance,
int crypto_authenticate_and_decrypt (
knet_handle_t knet_h,
unsigned char *buf,
ssize_t *buf_len)
{
return modules_cmds[instance->model].decrypt(instance->model_instance, buf, buf_len);
return modules_cmds[knet_h->crypto_instance->model].decrypt(knet_h, buf, buf_len);
}

int crypto_init(
knet_handle_t knet_h,
struct knet_handle_crypto_cfg *knet_handle_crypto_cfg)
{
log_printf("Initizializing crypto module [%s/%s/%s]",
log_debug(knet_h, KNET_SUB_CRYPTO,
"Initizializing crypto module [%s/%s/%s]",
knet_handle_crypto_cfg->crypto_model,
knet_handle_crypto_cfg->crypto_cipher_type,
knet_handle_crypto_cfg->crypto_hash_type);

knet_h->crypto_instance = malloc(sizeof(struct crypto_instance));

if (!knet_h->crypto_instance) {
log_printf("no memory from crypto");
log_err(knet_h, KNET_SUB_CRYPTO, "Unable to allocate memory for crypto instance");
return -1;
}

knet_h->crypto_instance->model = get_model(knet_handle_crypto_cfg->crypto_model);
if (knet_h->crypto_instance->model < 0) {
log_printf("model %s not supported", knet_handle_crypto_cfg->crypto_model);
log_err(knet_h, KNET_SUB_CRYPTO, "model %s not supported", knet_handle_crypto_cfg->crypto_model);
goto out_err;
}

Expand Down
17 changes: 12 additions & 5 deletions libknet/crypto.h
Expand Up @@ -11,19 +11,26 @@ struct crypto_instance {

typedef struct {
const char *model_name;
int (*init) (knet_handle_t knet_h, struct knet_handle_crypto_cfg *knet_handle_crypto_cfg);
int (*init) (knet_handle_t knet_h,
struct knet_handle_crypto_cfg *knet_handle_crypto_cfg);
void (*fini) (knet_handle_t knet_h);
int (*crypt) (void *model_instance, const unsigned char *buf_in, const ssize_t buf_in_len, unsigned char *buf_out, ssize_t *buf_out_len);
int (*decrypt) (void *model_instance, unsigned char *buf, ssize_t *buf_len);
int (*crypt) (knet_handle_t knet_h,
const unsigned char *buf_in,
const ssize_t buf_in_len,
unsigned char *buf_out,
ssize_t *buf_out_len);
int (*decrypt) (knet_handle_t knet_h,
unsigned char *buf,
ssize_t *buf_len);
} crypto_model_t;

int crypto_authenticate_and_decrypt (
struct crypto_instance *instance,
knet_handle_t knet_h,
unsigned char *buf,
ssize_t *buf_len);

int crypto_encrypt_and_sign (
struct crypto_instance *instance,
knet_handle_t knet_h,
const unsigned char *buf_in,
const ssize_t buf_in_len,
unsigned char *buf_out,
Expand Down

0 comments on commit 708d7c3

Please sign in to comment.