Commit 7397ae97 authored by Thomas Klausner's avatar Thomas Klausner

Remove whitespace at end of line.

parent 9856eb69
......@@ -42,17 +42,17 @@ struct redir_line redirects_usages[H_U_MAX + 1];
int redir_entry_init()
{
int i;
TRACE_ENTRY("");
/* redirects_usages */
memset(&redirects_usages, 0, sizeof(redirects_usages));
for (i = 0; i <= H_U_MAX; i++) {
CHECK_POSIX( pthread_rwlock_init( &redirects_usages[i].lock, NULL) );
fd_list_init( &redirects_usages[i].sentinel, &redirects_usages[i] );
}
/* initialize the scores */
redirects_usages[ DONT_CACHE ].score = FD_SCORE_REDIR_ONCE;
redirects_usages[ ALL_SESSION ].score = FD_SCORE_REDIR_SESSION;
......@@ -72,23 +72,23 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
struct redir_entry * entry = NULL;
os0_t s;
size_t l;
TRACE_ENTRY("%p %p %d %p %p %zd %p %zd", e, targets, rhu, qry, nh, nhlen, oh, ohlen)
ASSERT(e && targets && (rhu <= H_U_MAX) && qry && nh && nhlen && oh && ohlen);
CHECK_MALLOC( entry = malloc(sizeof(struct redir_entry)) );
memset(entry, 0, sizeof(struct redir_entry));
entry->eyec = REDIR_ENTRY_EYEC;
CHECK_MALLOC( entry->from.s = os0dup(nh, nhlen) );
entry->from.l = nhlen;
fd_list_init(&entry->target_peers_list, entry);
fd_list_move_end(&entry->target_peers_list, targets);
fd_list_init(&entry->exp_list, entry);
entry->type = rhu;
fd_list_init(&entry->redir_list, entry);
/* finally initialize the data */
......@@ -96,7 +96,7 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
case DONT_CACHE:
entry->data.message.msg = qry;
break;
case ALL_SESSION:
{
/* There is a good chance that the session is already cached in the message, so retrieve it */
......@@ -113,7 +113,7 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
entry->data.session.l = l;
}
break;
case ALL_REALM:
{
/* Search the Destination-Realm of the message */
......@@ -131,7 +131,7 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
entry->data.realm.l = ahdr->avp_value->os.len;
}
break;
case REALM_AND_APPLICATION:
{
/* Search the Destination-Realm of the message */
......@@ -155,7 +155,7 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
entry->data.realm_app.a = hdr->msg_appl;
}
break;
case ALL_APPLICATION:
{
struct msg_hdr * hdr;
......@@ -163,12 +163,12 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
entry->data.app.a = hdr->msg_appl;
}
break;
case ALL_HOST:
CHECK_MALLOC( entry->data.host.s = os0dup(oh, ohlen) );
entry->data.host.l = ohlen;
break;
case ALL_USER:
{
/* Search the User-Name of the message */
......@@ -186,12 +186,12 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
entry->data.user.l = ahdr->avp_value->os.len;
}
break;
default:
ASSERT(0);
return EINVAL;
}
/* We're done */
*e = entry;
return 0;
......@@ -202,7 +202,7 @@ int redir_entry_new(struct redir_entry ** e, struct fd_list * targets, uint32_t
static int compare_entries_ptr(union matchdata * d1, union matchdata * d2) {
unsigned long v1 = (unsigned long) d1->message.msg;
unsigned long v2 = (unsigned long) d2->message.msg;
if (v1 > v2)
if (v1 > v2)
return 1;
if (v1 < v2)
return -1;
......@@ -210,9 +210,9 @@ static int compare_entries_ptr(union matchdata * d1, union matchdata * d2) {
}
/* Compare two applications (REALM_AND_APPLICATION and ALL_APPLICATION) */
static int compare_entries_appl(union matchdata * d1, union matchdata * d2) {
if (d1->app.a > d2->app.a)
if (d1->app.a > d2->app.a)
return 1;
if (d1->app.a < d2->app.a)
if (d1->app.a < d2->app.a)
return -1;
return 0;
}
......@@ -237,22 +237,22 @@ int (*redir_entry_cmp_key[H_U_MAX +1])(union matchdata * , union matchdata * ) =
int redir_entry_insert(struct redir_entry * e)
{
struct fd_list * li;
TRACE_ENTRY("%p", e);
CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC));
/* Write-Lock the line */
CHECK_POSIX( pthread_rwlock_wrlock( RWLOCK_REDIR(e) ) );
for (li = redirects_usages[e->type].sentinel.next; li != &redirects_usages[e->type].sentinel; li = li->next) {
struct redir_entry * n = li->o;
int cmp = redir_entry_cmp_key[e->type](&e->data, &n->data);
if (cmp <= 0)
break;
}
fd_list_insert_before(li, &e->redir_list);
/* unLock the line */
CHECK_POSIX( pthread_rwlock_unlock( RWLOCK_REDIR(e) ) );
......@@ -264,26 +264,26 @@ int redir_entry_destroy(struct redir_entry * e)
{
TRACE_ENTRY("%p", e);
CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC));
/* If the entry is linked, lock the rwlock also */
if (!FD_IS_LIST_EMPTY(&e->redir_list)) {
CHECK_POSIX( pthread_rwlock_wrlock( RWLOCK_REDIR(e) ) );
fd_list_unlink(&e->redir_list);
CHECK_POSIX( pthread_rwlock_unlock( RWLOCK_REDIR(e) ) );
}
/* Now unlink from other list */
fd_list_unlink(&e->exp_list);
/* Empty the targets list */
while (!FD_IS_LIST_EMPTY(&e->target_peers_list)) {
struct redir_host * h = (struct redir_host *)e->target_peers_list.next->o;
fd_list_unlink(&h->chain);
free(h->id);
free(h);
}
/* Now we can destroy the data safely */
switch (e->type) {
case DONT_CACHE:
......@@ -311,9 +311,9 @@ int redir_entry_destroy(struct redir_entry * e)
ASSERT(0);
return EINVAL;
}
free(e->from.s);
free(e);
return 0;
}
......@@ -40,23 +40,23 @@
/* Entries by their ascending expiration date, to accelerate the work of the expire thread */
static struct fd_list expire_list = FD_LIST_INITIALIZER(expire_list);
static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER;
static pthread_cond_t exp_cnd = PTHREAD_COND_INITIALIZER;
pthread_mutex_t redir_exp_peer_lock = PTHREAD_MUTEX_INITIALIZER;
/* The thread that handles expired entries cleanup. */
void * redir_exp_thr_fct(void * arg)
void * redir_exp_thr_fct(void * arg)
{
fd_log_threadname ( "Redirects/expire" );
TRACE_ENTRY( "" );
CHECK_POSIX_DO( pthread_mutex_lock(&redir_exp_peer_lock), goto fatal_error );
pthread_cleanup_push( fd_cleanup_mutex, &redir_exp_peer_lock );
do {
struct timespec now;
struct redir_entry * first;
again:
again:
/* Check if there are expiring entries available */
if (FD_IS_LIST_EMPTY(&expire_list)) {
/* Just wait for a change or cancelation */
......@@ -64,33 +64,33 @@ again:
/* Restart the loop on wakeup */
goto again;
}
/* Get the pointer to the entry that expires first */
first = (struct redir_entry *)(expire_list.next->o);
/* Get the current time */
CHECK_SYS_DO( clock_gettime(CLOCK_REALTIME, &now), break );
/* If first session is not expired, we just wait until it happens */
if ( TS_IS_INFERIOR( &now, &first->timeout ) ) {
CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ),
CHECK_POSIX_DO2( pthread_cond_timedwait( &exp_cnd, &redir_exp_peer_lock, &first->timeout ),
ETIMEDOUT, /* ETIMEDOUT is a normal error, continue */,
/* on other error, */ break );
/* on wakeup, loop */
goto again;
}
/* Now, the first entry in the list is expired; destroy it */
CHECK_FCT_DO( redir_entry_destroy( first ), break );
} while (1);
pthread_cleanup_pop( 0 );
CHECK_POSIX_DO( pthread_mutex_unlock(&redir_exp_peer_lock), );
fatal_error:
TRACE_DEBUG(INFO, "A system error occurred in redirect module! Expiry thread is terminating...");
ASSERT(0);
......@@ -103,33 +103,33 @@ int redir_exp_set(struct redir_entry * e, uint32_t duration)
struct fd_list * li;
TRACE_ENTRY("%p %d", e, duration);
CHECK_PARAMS(e && (e->eyec == REDIR_ENTRY_EYEC) && duration );
/* Unlink in case it was already set before */
fd_list_unlink(&e->exp_list);
/* Get current time */
CHECK_SYS( clock_gettime(CLOCK_REALTIME, &e->timeout) );
/* Add the duration */
e->timeout.tv_sec += duration;
/* now search the next element in the list */
for (li = expire_list.next; li != &expire_list; li = li->next) {
struct redir_entry * n = li->o;
if ( TS_IS_INFERIOR( &e->timeout, &n->timeout ) )
break;
}
/* Insert before this element */
fd_list_insert_before(li, &e->exp_list);
/* Signal the expiry thread if needed */
if (e->exp_list.prev == &expire_list) { /* it is the first element */
CHECK_POSIX( pthread_cond_signal(&exp_cnd) );
}
/* Done */
return 0;
}
......
......@@ -58,28 +58,28 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
size_t nhlen;
int nbrh = 0;
struct redir_entry * entry;
TRACE_ENTRY("%p %p", cbdata, msg);
CHECK_PARAMS(msg && *msg);
m = *msg;
/* First get the header */
CHECK_FCT( fd_msg_hdr(m, &hdr) );
/* Check if we have an error */
ASSERT(!(hdr->msg_flags & CMD_FLAG_REQUEST));
if (!(hdr->msg_flags & CMD_FLAG_ERROR)) {
/* This answer does not have the E flag, no need to process further */
return 0;
}
/* Now get the AVPs we are interested in */
CHECK_FCT( fd_msg_browse(m, MSG_BRW_FIRST_CHILD, &avp, NULL) );
while (avp) {
struct avp_hdr * ahdr;
CHECK_FCT( fd_msg_avp_hdr( avp, &ahdr ) );
if (! (ahdr->avp_flags & AVP_FLAG_VENDOR)) {
switch (ahdr->avp_code) {
......@@ -89,19 +89,19 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
ASSERT( ahdr->avp_value );
a_oh = ahdr->avp_value;
break;
case AC_RESULT_CODE:
/* Parse this AVP */
CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) );
ASSERT( ahdr->avp_value );
a_rc = ahdr->avp_value;
if (a_rc->u32 != ER_DIAMETER_REDIRECT_INDICATION) {
/* It is not a REDIRECT error, we don't do anything */
goto out;
}
break;
case AC_REDIRECT_HOST:
{
struct redir_host * h = NULL;
......@@ -111,20 +111,20 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
uint16_t port = 0;
int l4 = 0;
char proto = 0;
/* Parse this AVP */
CHECK_FCT( fd_msg_parse_dict ( avp, fd_g_config->cnf_dict, NULL ) );
ASSERT( ahdr->avp_value );
nbrh++;
CHECK_FCT_DO( fd_os_parse_DiameterURI(ahdr->avp_value->os.data, ahdr->avp_value->os.len,
CHECK_FCT_DO( fd_os_parse_DiameterURI(ahdr->avp_value->os.data, ahdr->avp_value->os.len,
&id, &len, &secure, &port, &l4, &proto),
{
TRACE_DEBUG(INFO, "Received an invalid Redirect-Host AVP value ('%.*s'), ignored", (int)ahdr->avp_value->os.len, ahdr->avp_value->os.data);
break;
} );
/* Now check if the transport & protocol are supported */
if (proto && (proto != 'd')) {
TRACE_DEBUG(FULL, "Ignored unsupported non-Diameter Redirect-Host AVP (%.*s)", (int)ahdr->avp_value->os.len, ahdr->avp_value->os.data);
......@@ -136,16 +136,16 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
free(id);
break;
}
/* It looks OK, save this entry. */
CHECK_MALLOC( h = malloc(sizeof(struct redir_host)) );
memset(h, 0, sizeof(struct redir_host));
fd_list_init(&h->chain, h);
h->id = id;
h->len = len;
/* later: secure, port */
/* The list is kept ordered by id so that it is faster to compare to candidates later */
for (li = task.rh.next; li != &task.rh; li = li->next) {
struct redir_host * nhost = li->o;
......@@ -182,18 +182,18 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
/* Go to next AVP */
CHECK_FCT( fd_msg_browse(avp, MSG_BRW_NEXT, &avp, NULL) );
}
/* Check we have received the necessary information */
if (!a_rc) {
TRACE_DEBUG(FULL, "Invalid Diameter answer without a Result-Code AVP, Redirect module gave up");
goto out;
}
if (!a_oh) {
TRACE_DEBUG(FULL, "Invalid Diameter answer without an Origin-Host AVP, Redirect module gave up");
goto out;
}
if (FD_IS_LIST_EMPTY(&task.rh)) {
TRACE_DEBUG(FULL, "Diameter answer with a DIAMETER_REDIRECT_INDICATION Result-Code AVP but no valid/supported Redirect-Host AVP, Redirect module gave up");
goto out;
......@@ -203,14 +203,14 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
TRACE_DEBUG(FULL, "Invalid Diameter Redirect answer with a Redirect-Host-Usage AVP but no Redirect-Max-Cache-Time, Redirect module gave up");
goto out;
}
/* It looks like we can process the Redirect indication */
/* Search for the peers we already know */
for (li = task.rh.next; li != &task.rh; li = li->next) {
struct redir_host * h = li->o;
struct peer_hdr * peer;
CHECK_FCT( fd_peer_getbyid( h->id, h->len, 1, &peer ) );
if (peer) {
known ++;
......@@ -220,28 +220,28 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
}
}
}
TRACE_DEBUG(FULL, "Redirect module: received %d Redirect-Hosts, %d are known peers, %d have an OPEN connection", nbrh, known, actives);
/* in this version, we only redirect when there are known active peers. TODO: add new peers via fd_peer_add when no active peer is available */
if (!actives) {
TRACE_DEBUG(INFO, "Unable to comply to Redirect indication: none of the peers included is in OPEN state");
goto out;
}
/* From this point, we will re-send the query to a different peer, so stop forwarding the answer here */
*msg = NULL;
/* Get the query's routing data & add the new error */
CHECK_FCT( fd_msg_answ_getq(m, &q) );
CHECK_FCT( fd_msg_rt_get(q, &rtd) );
CHECK_FCT( fd_msg_source_get( m, &nh, &nhlen ) );
CHECK_FCT( fd_rtd_error_add(rtd, nh, nhlen, a_oh->os.data, a_oh->os.len, a_rc->u32, NULL, NULL) );
/* Create a redir_rule */
CHECK_FCT( redir_entry_new(&entry, &task.rh, task.rhu, q, nh, nhlen, a_oh->os.data, a_oh->os.len) );
CHECK_POSIX( pthread_mutex_lock(&redir_exp_peer_lock) );
/* Insert in the split list */
CHECK_FCT( redir_entry_insert(entry) );
......@@ -252,12 +252,12 @@ int redir_fwd_cb(void * cbdata, struct msg ** msg)
/* Now we can get rid of the received answer and send again the query. */
CHECK_FCT( fd_msg_answ_detach(m) );
CHECK_FCT( fd_msg_free(m) );
/* Send it */
CHECK_FCT( fd_msg_send(&q, NULL, NULL) );
/* Done! */
out:
while (!FD_IS_LIST_EMPTY(&task.rh)) {
struct redir_host * h = task.rh.next->o;
......@@ -265,7 +265,7 @@ out:
free(h->id);
free(h);
}
return 0;
}
......
......@@ -40,17 +40,17 @@
static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchdata * data, int * nodata)
{
TRACE_ENTRY("%d %p %p %p", type, msg, data, nodata);
/* Initialize the data area */
memset(data, 0, sizeof(union matchdata));
*nodata = 0;
/* Now, find the appropriate information, depending on type */
switch (type) {
case DONT_CACHE:
data->message.msg = msg;
break;
case ALL_SESSION:
{
/* Get the sid from the message */
......@@ -64,7 +64,7 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
}
}
break;
case ALL_REALM:
{
/* Search the Destination-Realm in the message */
......@@ -81,7 +81,7 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
}
}
break;
case REALM_AND_APPLICATION:
{
/* Search the Destination-Realm of the message */
......@@ -95,7 +95,7 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
CHECK_FCT( fd_msg_avp_hdr( dr, &ahdr ) );
data->realm_app.s = ahdr->avp_value->os.data;
data->realm_app.l = ahdr->avp_value->os.len;
/* and then the application */
{
struct msg_hdr * hdr;
......@@ -106,7 +106,7 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
}
}
break;
case ALL_APPLICATION:
{
/* Retrieve the application from the message */
......@@ -115,11 +115,11 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
data->app.a = hdr->msg_appl;
}
break;
case ALL_HOST:
/* This is more complex, we need to match with all candidates in each rule, it'll be done later */
break;
case ALL_USER:
{
/* Search the User-Name of the message */
......@@ -136,7 +136,7 @@ static int get_data_to_match(enum redir_h_u type, struct msg *msg, union matchda
}
}
break;
default:
ASSERT(0);
return EINVAL;
......@@ -152,22 +152,22 @@ static int apply_rule(struct redir_entry * e, struct msg * msg, struct fd_list *
struct fd_list * lic, *lirh;
struct rtd_candidate * c_oh = NULL;
int cmp;
TRACE_ENTRY("%p %p %p", e, msg, candidates);
ASSERT( e && msg && candidates );
if (FD_IS_LIST_EMPTY(candidates)) {
TRACE_DEBUG(ANNOYING, "Skip Redirect rule since candidates list is empty");
return 0;
}
/* Now search common peers between e->target_peers_list and candidates */
TRACE_DEBUG(ANNOYING, "Message %p matches a Redirect rule (t:%d, @%p), processing candidates list", msg, e->type, e);
/* First, decrease the score of the host that we received the previous Redirect from, in case it is in the list */
for (lic = candidates->next; lic != candidates; lic = lic->next) {
struct rtd_candidate * cand = (struct rtd_candidate *) lic;
/* Special case: ALL_HOST rules: we decrease the score of the Origin-Host if present */
if (e->type == ALL_HOST) {
cmp = fd_os_almostcasesrch(cand->diamid, cand->diamidlen, e->data.host.s, e->data.host.l, NULL);
......@@ -178,32 +178,32 @@ static int apply_rule(struct redir_entry * e, struct msg * msg, struct fd_list *
continue;