changeset 278:50bfb29bf036

Try better handling several pending requests for the same session (not very clean yet)
author Sebastien Decugis <sdecugis@nict.go.jp>
date Fri, 23 Apr 2010 17:22:09 +0900
parents c94e4ea39f97
children a26655da5c14
files extensions/app_radgw/rgw_clients.c extensions/app_radgw/rgw_msg.c extensions/app_radgw/rgw_worker.c
diffstat 3 files changed, 45 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/extensions/app_radgw/rgw_clients.c	Fri Apr 23 14:33:26 2010 +0900
+++ b/extensions/app_radgw/rgw_clients.c	Fri Apr 23 17:22:09 2010 +0900
@@ -259,15 +259,23 @@
 		}
 		rgw_msg_free(msg);
 	} else {
-		/* Update information for new message */
-		if (cli->last[idx].ans) {
-			/* Free it */
-			radius_msg_free(cli->last[idx].ans);
-			free(cli->last[idx].ans);
-			cli->last[idx].ans = NULL;
+		/* We have not just received this message already */
+		if (cli->last[idx].port == 0) { /* first message from this client */
+			/* Just add the new information */
+			ASSERT(cli->last[idx].ans == NULL);
+			cli->last[idx].id = (*msg)->radius.hdr->identifier;
+			cli->last[idx].port = (*msg)->port;
+		} else { 
+			/* We have got previous message(s), update the info only if answered already */
+			if (cli->last[idx].ans) {
+				cli->last[idx].id = (*msg)->radius.hdr->identifier;
+				cli->last[idx].port = (*msg)->port;
+				/* Free the previous answer */
+				radius_msg_free(cli->last[idx].ans);
+				free(cli->last[idx].ans);
+				cli->last[idx].ans = NULL;
+			} 
 		}
-		cli->last[idx].id = (*msg)->radius.hdr->identifier;
-		cli->last[idx].port = (*msg)->port;
 	}
 	
 	return 0;
@@ -606,6 +614,8 @@
 		free(cli->last[idx].ans);
 	}
 	cli->last[idx].ans = *msg;
+	cli->last[idx].id = req->radius.hdr->identifier;
+	cli->last[idx].port = req->port;
 	*msg = NULL;
 	
 	/* Finished */
--- a/extensions/app_radgw/rgw_msg.c	Fri Apr 23 14:33:26 2010 +0900
+++ b/extensions/app_radgw/rgw_msg.c	Fri Apr 23 17:22:09 2010 +0900
@@ -267,7 +267,13 @@
 	
 	if (*session) {
 		CHECK_FCT( fd_sess_getsid(*session, &sess_str) );
-		TRACE_DEBUG(FULL, "Session '%s' has been successfully %s.", sess_str, idx ? "created" : "retrieved");
+		if (idx == 0) {
+			TRACE_DEBUG(INFO, "Another message was translated for this session ('%s') and not answered yet, discarding the new RADIUS request.", sess_str);
+			*session = NULL;
+			return EALREADY;
+		}
+		
+		TRACE_DEBUG(FULL, "Translating new message for session '%s'...", sess_str);
 		
 		/* Add the Session-Id AVP as first AVP */
 		CHECK_FCT( fd_msg_avp_new ( cache_sess_id, 0, &avp ) );
--- a/extensions/app_radgw/rgw_worker.c	Fri Apr 23 14:33:26 2010 +0900
+++ b/extensions/app_radgw/rgw_worker.c	Fri Apr 23 17:22:09 2010 +0900
@@ -146,12 +146,26 @@
 		CHECK_FCT_DO( rgw_plg_loop_req(&msg, &session, &diam_msg, cli), 
 			{
 				/* An error occurred, discard message */
+				if (diam_msg) {
+					CHECK_FCT_DO( fd_msg_free(diam_msg), );
+					diam_msg = NULL;
+				}
+				if (session) {
+					CHECK_FCT_DO( fd_sess_destroy(&session), );
+				}
 				rgw_msg_free(&msg);
 				rgw_clients_dispose(&cli);
 				continue;
 			}  );
 		if (msg == NULL) {
 			rgw_clients_dispose(&cli);
+			if (diam_msg) {
+				CHECK_FCT_DO( fd_msg_free(diam_msg), );
+				diam_msg = NULL;
+			}
+			if (session) {
+				CHECK_FCT_DO( fd_sess_destroy(&session), );
+			}
 			continue; /* the message was handled already */
 		}
 		
@@ -175,7 +189,7 @@
 					msg->radius.hdr->code, rgw_msg_code_str(msg->radius.hdr->code));
 		}
 		
-		/* Check the session is correct */
+		/* Check the session is correct (for debug) */
 		ASSERT(session != NULL);
 		
 		if (pb) {
@@ -297,6 +311,11 @@
 		*ans = NULL;
 	}
 	
+	/* Clear the RADIUS request */
+	if (pa->rad) {
+		rgw_msg_free(&pa->rad);
+	}
+	
 	/* Release reference on the client */
 	rgw_clients_dispose(&pa->cli);
 	
"Welcome to our mercurial repository"