added name property in CHILD_SA, allows proper status output

This commit is contained in:
Martin Willi
2006-08-25 09:07:37 +00:00
parent 7106403bd8
commit 9be547c0ed
5 changed files with 75 additions and 14 deletions
+33 -7
View File
@@ -69,6 +69,11 @@ struct private_child_sa_t {
*/
child_sa_t public;
/**
* Name of the policy used by this CHILD_SA
*/
char *name;
struct {
/** address of peer */
host_t *addr;
@@ -157,6 +162,23 @@ struct private_child_sa_t {
logger_t *logger;
};
/**
* Implementation of child_sa_t.get_name.
*/
static char *get_name(private_child_sa_t *this)
{
return this->name;
}
/**
* Implementation of child_sa_t.set_name.
*/
static void set_name(private_child_sa_t *this, char* name)
{
free(this->name);
this->name = strdup(name);
}
/**
* Implements child_sa_t.get_reqid
*/
@@ -588,7 +610,7 @@ static status_t get_use_time(private_child_sa_t *this, bool inbound, time_t *use
/**
* Implementation of child_sa_t.log_status.
*/
static void log_status(private_child_sa_t *this, logger_t *logger, char* name)
static void log_status(private_child_sa_t *this, logger_t *logger)
{
iterator_t *iterator;
char use_in_str[12] = "unused";
@@ -657,20 +679,20 @@ static void log_status(private_child_sa_t *this, logger_t *logger, char* name)
logger->log(logger, CONTROL|LEVEL1,
" \"%s\": state: %s, reqid: %d, ",
name, mapping_find(child_sa_state_m, this->state), this->reqid);
this->name, mapping_find(child_sa_state_m, this->state), this->reqid);
logger->log(logger, CONTROL|LEVEL1,
" \"%s\": %s (%s%s), SPIs (in/out): 0x%x/0x%x",
name, this->protocol == PROTO_ESP ? "ESP" : "AH",
this->name, this->protocol == PROTO_ESP ? "ESP" : "AH",
enc_str, int_str,
htonl(this->me.spi), htonl(this->other.spi));
logger->log(logger, CONTROL|LEVEL1,
" \"%s\": rekeying: %s, key age (in/out): %s/%s",
name, rekey_str, use_in_str, use_out_str);
this->name, rekey_str, use_in_str, use_out_str);
}
else
{
logger->log(logger, CONTROL|LEVEL1, " \"%s\": state: %s, reqid: %d",
name, mapping_find(child_sa_state_m, this->state),
this->name, mapping_find(child_sa_state_m, this->state),
this->reqid);
}
@@ -711,7 +733,7 @@ static void log_status(private_child_sa_t *this, logger_t *logger, char* name)
logger->log(logger, CONTROL,
" \"%s\": %s====%s, last use (in/out/fwd): %s/%s/%s",
name, my_str, other_str, pol_in_str, pol_out_str, pol_fwd_str);
this->name, my_str, other_str, pol_in_str, pol_out_str, pol_fwd_str);
}
iterator->destroy(iterator);
}
@@ -911,6 +933,7 @@ static void destroy(private_child_sa_t *this)
this->other_ts->destroy(this->other_ts);
this->me.addr->destroy(this->me.addr);
this->other.addr->destroy(this->other.addr);
free(this->name);
free(this);
}
@@ -925,6 +948,8 @@ child_sa_t * child_sa_create(u_int32_t rekey, host_t *me, host_t* other,
private_child_sa_t *this = malloc_thing(private_child_sa_t);
/* public functions */
this->public.get_name = (char*(*)(child_sa_t*))get_name;
this->public.set_name = (void(*)(child_sa_t*,char*))set_name;
this->public.get_reqid = (u_int32_t(*)(child_sa_t*))get_reqid;
this->public.get_spi = (u_int32_t(*)(child_sa_t*, bool))get_spi;
this->public.get_protocol = (protocol_id_t(*)(child_sa_t*))get_protocol;
@@ -940,11 +965,12 @@ child_sa_t * child_sa_create(u_int32_t rekey, host_t *me, host_t* other,
this->public.get_rekeying_transaction = (void* (*)(child_sa_t*))get_rekeying_transaction;
this->public.set_state = (void(*)(child_sa_t*,child_sa_state_t))set_state;
this->public.get_state = (child_sa_state_t(*)(child_sa_t*))get_state;
this->public.log_status = (void (*)(child_sa_t*, logger_t*, char*))log_status;
this->public.log_status = (void (*)(child_sa_t*, logger_t*))log_status;
this->public.destroy = (void(*)(child_sa_t*))destroy;
/* private data */
this->logger = logger_manager->get_logger(logger_manager, CHILD_SA);
this->name = strdup("(uninitialized)");
this->me.addr = me->clone(me);
this->other.addr = other->clone(other);
this->me.spi = 0;
+18 -4
View File
@@ -101,6 +101,22 @@ typedef struct child_sa_t child_sa_t;
*/
struct child_sa_t {
/**
* @brief Get the name of the policy this CHILD_SA uses.
*
* @param this calling object
* @return name
*/
char* (*get_name) (child_sa_t *this);
/**
* @brief Set the name of the policy this IKE_SA uses.
*
* @param this calling object
* @param name name, gets cloned
*/
void (*set_name) (child_sa_t *this, char* name);
/**
* @brief Get the unique reqid of the CHILD SA.
*
@@ -267,14 +283,12 @@ struct child_sa_t {
* The status of ESP/AH SAs is logged with the supplied logger in
* a human readable form.
* Supplying NULL as logger uses the internal child_sa logger
* to do the logging. The name is only a log-prefix without further
* meaning.
* to do the logging.
*
* @param this calling object
* @param logger logger to use for logging
* @param name connection name
*/
void (*log_status) (child_sa_t *this, logger_t *logger, char *name);
void (*log_status) (child_sa_t *this, logger_t *logger);
/**
* @brief Destroys a child_sa.
+20 -3
View File
@@ -1726,14 +1726,31 @@ static void log_status(private_ike_sa_t *this, logger_t *logger, char *name)
{
iterator_t *iterator;
child_sa_t *child_sa;
bool contains_child = FALSE;
if (name == NULL || streq(name, this->name))
/* check for a CHILD_SA with specified name. We then print the IKE_SA,
* even it has another name */
if (name != NULL)
{
iterator = this->child_sas->create_iterator(this->child_sas, TRUE);
while (iterator->iterate(iterator, (void**)&child_sa))
{
if (streq(name, child_sa->get_name(child_sa)))
{
contains_child = TRUE;
break;
}
}
iterator->destroy(iterator);
}
if (name == NULL || contains_child || streq(name, this->name))
{
if (logger == NULL)
{
logger = this->logger;
}
logger->log(logger, CONTROL|LEVEL1,
logger->log(logger, CONTROL|LEVEL1,
" \"%s\": IKE_SA in state %s, SPIs: 0x%.16llx 0x%.16llx",
this->name,
mapping_find(ike_sa_state_m, this->state),
@@ -1750,7 +1767,7 @@ static void log_status(private_ike_sa_t *this, logger_t *logger, char *name)
while (iterator->has_next(iterator))
{
iterator->current(iterator, (void**)&child_sa);
child_sa->log_status(child_sa, logger, this->name);
child_sa->log_status(child_sa, logger);
}
iterator->destroy(iterator);
}
@@ -287,6 +287,7 @@ static status_t get_request(private_create_child_sa_t *this, message_t **result)
this->policy->get_soft_lifetime(this->policy),
this->policy->get_hard_lifetime(this->policy),
use_natt);
this->child_sa->set_name(this->child_sa, this->policy->get_name(this->policy));
if (this->child_sa->alloc(this->child_sa, proposals) != SUCCESS)
{
this->logger->log(this->logger, ERROR,
@@ -697,6 +698,7 @@ static status_t get_response(private_create_child_sa_t *this, message_t *request
this->child_sa = child_sa_create(reqid, me, other,
soft_lifetime, hard_lifetime,
use_natt);
this->child_sa->set_name(this->child_sa, this->policy->get_name(this->policy));
if (install_child_sa(this, FALSE) != SUCCESS)
{
this->logger->log(this->logger, ERROR,
+2
View File
@@ -305,6 +305,7 @@ static status_t get_request(private_ike_auth_t *this, message_t **result)
hard_lifetime = this->policy->get_hard_lifetime(this->policy);
this->child_sa = child_sa_create(0, me, other, soft_lifetime, hard_lifetime,
this->ike_sa->is_natt_enabled(this->ike_sa));
this->child_sa->set_name(this->child_sa, this->policy->get_name(this->policy));
if (this->child_sa->alloc(this->child_sa, proposal_list) != SUCCESS)
{
this->logger->log(this->logger, ERROR,
@@ -770,6 +771,7 @@ static status_t get_response(private_ike_auth_t *this, message_t *request,
this->child_sa = child_sa_create(0, me, other,
soft_lifetime, hard_lifetime,
use_natt);
this->child_sa->set_name(this->child_sa, this->policy->get_name(this->policy));
if (install_child_sa(this, FALSE) != SUCCESS)
{
this->logger->log(this->logger, ERROR,