changeset 548:345537783a90

Allow duplicate messages to be processed after Diameter answer has been received.
author Sebastien Decugis <sdecugis@nict.go.jp>
date Wed, 15 Sep 2010 10:41:43 +0900
parents 77b575250103
children 1b8809c7d7cc
files extensions/app_radgw/rgw.h extensions/app_radgw/rgw_clients.c extensions/app_radgw/rgw_worker.c
diffstat 3 files changed, 54 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/app_radgw/rgw.h	Tue Sep 14 17:12:17 2010 +0900
+++ b/extensions/app_radgw/rgw.h	Wed Sep 15 10:41:43 2010 +0900
@@ -99,6 +99,7 @@
 int rgw_clients_check_dup(struct rgw_radius_msg_meta **msg, struct rgw_client *cli);
 int rgw_clients_create_origin(struct rgw_radius_msg_meta *msg, struct rgw_client * cli, struct msg ** diam);
 int rgw_client_finish_send(struct radius_msg ** msg, struct rgw_radius_msg_meta * req, struct rgw_client * cli);
+int rgw_client_finish_nosend(struct rgw_radius_msg_meta * req, struct rgw_client * cli);
 void rgw_clients_dispose(struct rgw_client ** ref);
 void rgw_clients_dump(void);
 int rgw_clients_init(void);
--- a/extensions/app_radgw/rgw_clients.c	Tue Sep 14 17:12:17 2010 +0900
+++ b/extensions/app_radgw/rgw_clients.c	Wed Sep 15 10:41:43 2010 +0900
@@ -1052,3 +1052,53 @@
 	return 0;
 }
 
+/* Call this function when a RADIUS request has explicitely no answer (mainly accounting) so 
+that we purge the duplicate cache and allow further message to be translated again.
+This is useful for example when a temporary error occurred in Diameter (like UNABLE_TO_DELIVER) */
+int rgw_client_finish_nosend(struct rgw_radius_msg_meta * req, struct rgw_client * cli)
+{
+	int p;
+	struct fd_list * li;
+	
+	TRACE_ENTRY("%p %p", req, cli);
+	CHECK_PARAMS( req && cli );
+	
+	/* update the duplicate cache */
+	if (req->serv_type == RGW_PLG_TYPE_AUTH)
+		p = 0;
+	else
+		p = 1;
+	
+	CHECK_POSIX( pthread_mutex_lock( &cli->dupl_info[p].dupl_lock ) );
+	
+	/* Search this message in our list */
+	for (li = cli->dupl_info[p].dupl_by_id.next; li != &cli->dupl_info[p].dupl_by_id; li = li->next) {
+		int cmp = 0;
+		struct req_info * r = (struct req_info *)(li->o);
+		if (r->id < req->radius.hdr->identifier)
+			continue;
+		if (r->id > req->radius.hdr->identifier)
+			break;
+		if (r->port < req->port)
+			continue;
+		if (r->port > req->port)
+			break;
+		cmp = memcmp(&r->auth[0], &req->radius.hdr->authenticator[0], 16);
+		if (cmp < 0)
+			continue;
+		if (cmp > 0)
+			break;
+		
+		/* We have the request in our duplicate cache, remove it */
+		fd_list_unlink(&r->by_id);
+		fd_list_unlink(&r->by_time);
+		dupl_free_req_info(r);
+		break;
+	}
+		
+	CHECK_POSIX( pthread_mutex_unlock( &cli->dupl_info[p].dupl_lock ) );
+	
+	/* Finished */
+	return 0;
+}
+
--- a/extensions/app_radgw/rgw_worker.c	Tue Sep 14 17:12:17 2010 +0900
+++ b/extensions/app_radgw/rgw_worker.c	Wed Sep 15 10:41:43 2010 +0900
@@ -287,6 +287,9 @@
 	/* Now try and send the RADIUS answer */
 	if (rad_ans) {
 		CHECK_FCT_DO( rgw_client_finish_send(&rad_ans, pa->rad, pa->cli), );	
+	} else {
+		/* Remove the request from the duplicate cache */
+		CHECK_FCT_DO( rgw_client_finish_nosend(pa->rad, pa->cli), );
 	}
 
 out:
"Welcome to our mercurial repository"