diff options
Diffstat (limited to 'src/charon/config/policies')
-rw-r--r-- | src/charon/config/policies/local_policy_store.c | 45 | ||||
-rw-r--r-- | src/charon/config/policies/policy.c | 41 | ||||
-rw-r--r-- | src/charon/config/policies/policy.h | 10 | ||||
-rwxr-xr-x | src/charon/config/policies/policy_store.h | 8 |
4 files changed, 45 insertions, 59 deletions
diff --git a/src/charon/config/policies/local_policy_store.c b/src/charon/config/policies/local_policy_store.c index 5253cb3fa..577b83a28 100644 --- a/src/charon/config/policies/local_policy_store.c +++ b/src/charon/config/policies/local_policy_store.c @@ -1,8 +1,8 @@ /** * @file local_policy_store.c - * + * * @brief Implementation of local_policy_store_t. - * + * */ /* @@ -24,8 +24,8 @@ #include "local_policy_store.h" +#include <daemon.h> #include <utils/linked_list.h> -#include <utils/logger_manager.h> typedef struct private_local_policy_store_t private_local_policy_store_t; @@ -49,11 +49,6 @@ struct private_local_policy_store_t { * Mutex to exclusivly access list */ pthread_mutex_t mutex; - - /** - * Assigned logger - */ - logger_t *logger; }; /** @@ -116,8 +111,7 @@ static policy_t *get_policy(private_local_policy_store_t *this, policy_t *candidate; policy_t *found = NULL; - this->logger->log(this->logger, CONTROL|LEVEL1, - "searching policy for ID pair %D...%D", my_id, other_id); + DBG2(SIG_DBG_CFG, "searching policy for ID pair %D...%D", my_id, other_id); pthread_mutex_lock(&(this->mutex)); iterator = this->policies->create_iterator(this->policies, TRUE); @@ -149,16 +143,14 @@ static policy_t *get_policy(private_local_policy_store_t *this, if (!contains_traffic_selectors(candidate, TRUE, my_ts, my_host) || !contains_traffic_selectors(candidate, FALSE, other_ts, other_host)) { - this->logger->log(this->logger, CONTROL|LEVEL2, - "candidate '%s' inacceptable due traffic selector mismatch", - candidate->get_name(candidate)); + DBG2(SIG_DBG_CFG, "candidate '%s' inacceptable due traffic " + "selector mismatch", candidate->get_name(candidate)); continue; } - this->logger->log(this->logger, CONTROL|LEVEL2, - "candidate policy '%s': %D...%D (prio=%d)", - candidate->get_name(candidate), - candidate_my_id, candidate_other_id, prio); + DBG2(SIG_DBG_CFG, "candidate policy '%s': %D...%D (prio=%d)", + candidate->get_name(candidate), + candidate_my_id, candidate_other_id, prio); if (prio > best_prio) { @@ -174,10 +166,8 @@ static policy_t *get_policy(private_local_policy_store_t *this, identification_t *found_my_id = found->get_my_id(found); identification_t *found_other_id = found->get_other_id(found); - this->logger->log(this->logger, CONTROL, - "found matching policy '%s': %D...%D (prio=%d)", - found->get_name(found), - found_my_id, found_other_id, best_prio); + DBG1(SIG_DBG_CFG, "found matching policy '%s': %D...%D (prio=%d)", + found->get_name(found), found_my_id, found_other_id, best_prio); /* give out a new reference to it */ found->get_ref(found); } @@ -193,7 +183,7 @@ static policy_t *get_policy_by_name(private_local_policy_store_t *this, char *na iterator_t *iterator; policy_t *current, *found = NULL; - this->logger->log(this->logger, CONTROL|LEVEL1, "looking for policy \"%s\"", name); + DBG2(SIG_DBG_CFG, "looking for policy '%s'", name); pthread_mutex_lock(&(this->mutex)); iterator = this->policies->create_iterator(this->policies, TRUE); @@ -246,6 +236,15 @@ static status_t delete_policy(private_local_policy_store_t *this, char *name) } /** + * Implementation of policy_store_t.create_iterator. + */ +static iterator_t* create_iterator(private_local_policy_store_t *this) +{ + return this->policies->create_iterator_locked(this->policies, + &this->mutex); +} + +/** * Implementation of policy_store_t.destroy. */ static void destroy(private_local_policy_store_t *this) @@ -273,11 +272,11 @@ local_policy_store_t *local_policy_store_create(void) this->public.policy_store.get_policy = (policy_t*(*)(policy_store_t*,identification_t*,identification_t*,linked_list_t*,linked_list_t*,host_t*,host_t*))get_policy; this->public.policy_store.get_policy_by_name = (policy_t*(*)(policy_store_t*,char*))get_policy_by_name; this->public.policy_store.delete_policy = (status_t(*)(policy_store_t*,char*))delete_policy; + this->public.policy_store.create_iterator = (iterator_t*(*)(policy_store_t*))create_iterator; this->public.policy_store.destroy = (void(*)(policy_store_t*))destroy; /* private variables */ this->policies = linked_list_create(); - this->logger = logger_manager->get_logger(logger_manager, CONFIG); pthread_mutex_init(&(this->mutex), NULL); return (&this->public); diff --git a/src/charon/config/policies/policy.c b/src/charon/config/policies/policy.c index e3a1100b9..dcae0504c 100644 --- a/src/charon/config/policies/policy.c +++ b/src/charon/config/policies/policy.c @@ -27,34 +27,23 @@ #include "policy.h" +#include <daemon.h> #include <utils/linked_list.h> #include <utils/identification.h> -#include <utils/logger_manager.h> -/** - * String mappings for auth_method_t. - */ -static const char *const auth_method_name[] = { +ENUM(auth_method_names, RSA_DIGITAL_SIGNATURE, DSS_DIGITAL_SIGNATURE, "RSA signature", "pre-shared key", "DSS signature" -}; +); -enum_names auth_method_names = - { RSA_DIGITAL_SIGNATURE, DSS_DIGITAL_SIGNATURE, auth_method_name, NULL }; -/** - * String mappings for dpd_action_t. - */ -static const char *const dpd_action_name[] = { +ENUM(dpd_action_names, DPD_NONE, DPD_RESTART, "DPD_NONE", "DPD_CLEAR", "DPD_ROUTE", "DPD_RESTART" -}; - -enum_names dpd_action_names = - { DPD_NONE, DPD_RESTART, dpd_action_name, NULL }; +); typedef struct private_policy_t private_policy_t; @@ -148,11 +137,6 @@ struct private_policy_t { * What to do with an SA when other peer seams to be dead? */ bool dpd_action; - - /** - * logger - */ - logger_t *logger; }; /** @@ -239,9 +223,7 @@ static linked_list_t *select_traffic_selectors(private_policy_t *this, traffic_selector_t *supplied_ts, *stored_ts, *selected_ts; linked_list_t *selected = linked_list_create(); - this->logger->log(this->logger, CONTROL|LEVEL1, - "selecting traffic selectors for %s host", - stored == this->my_ts ? "local" : "remote"); + DBG2(SIG_DBG_CFG, "selecting traffic selectors"); stored_iter = stored->create_iterator(stored, TRUE); supplied_iter = supplied->create_iterator(supplied, TRUE); @@ -258,10 +240,8 @@ static linked_list_t *select_traffic_selectors(private_policy_t *this, /* iterate over all supplied traffic selectors */ while (supplied_iter->iterate(supplied_iter, (void**)&supplied_ts)) { - this->logger->log(this->logger, CONTROL|LEVEL2, - " stored %s <=> %s received", - stored_ts->get_string(stored_ts), - supplied_ts->get_string(supplied_ts)); + DBG2(SIG_DBG_CFG, "stored %R <=> %R received", + stored_ts, supplied_ts); selected_ts = stored_ts->get_subset(stored_ts, supplied_ts); if (selected_ts) @@ -269,8 +249,8 @@ static linked_list_t *select_traffic_selectors(private_policy_t *this, /* got a match, add to list */ selected->insert_last(selected, (void*)selected_ts); - this->logger->log(this->logger, CONTROL|LEVEL1, " got a match: %s", - selected_ts->get_string(selected_ts)); + DBG2(SIG_DBG_CFG, "found traffic selector for %s: %R", + stored == this->my_ts ? "us" : "other", selected_ts); } } stored_ts->destroy(stored_ts); @@ -554,7 +534,6 @@ policy_t *policy_create(char *name, identification_t *my_id, identification_t *o this->proposals = linked_list_create(); this->my_ts = linked_list_create(); this->other_ts = linked_list_create(); - this->logger = logger_manager->get_logger(logger_manager, CONFIG); return &this->public; } diff --git a/src/charon/config/policies/policy.h b/src/charon/config/policies/policy.h index 6d80319b4..84f5f2bc9 100644 --- a/src/charon/config/policies/policy.h +++ b/src/charon/config/policies/policy.h @@ -58,11 +58,11 @@ enum auth_method_t { }; /** - * string mappings for auth_method_t. - * + * enum names for auth_method_t. + * * @ingroup config */ -extern enum_names auth_method_names; +extern enum_name_t *auth_method_names; typedef enum dpd_action_t dpd_action_t; @@ -86,9 +86,9 @@ enum dpd_action_t { }; /** - * String mappings for dpd_action_t. + * enum names for dpd_action_t. */ -extern enum_names dpd_action_names; +extern enum_name_t *dpd_action_names; typedef struct policy_t policy_t; diff --git a/src/charon/config/policies/policy_store.h b/src/charon/config/policies/policy_store.h index 2ea57b8b4..a09263b13 100755 --- a/src/charon/config/policies/policy_store.h +++ b/src/charon/config/policies/policy_store.h @@ -101,6 +101,14 @@ struct policy_store_t { status_t (*delete_policy) (policy_store_t *this, char *name); /** + * @brief Get an iterator for the stored policies. + * + * @param this calling object + * @return iterator over all stored policies + */ + iterator_t* (*create_iterator) (policy_store_t *this); + + /** * @brief Destroys a policy_store_t object. * * @param this calling object |