[sr-dev] git:master: dispatcher(k): restore actve state via MI

Daniel-Constantin Mierla miconda at gmail.com
Thu Oct 20 23:52:31 CEST 2011


Module: sip-router
Branch: master
Commit: 25bedcd991bc0225c50467abf0b6e48618893cbf
URL:    http://git.sip-router.org/cgi-bin/gitweb.cgi/sip-router/?a=commit;h=25bedcd991bc0225c50467abf0b6e48618893cbf

Author: Daniel-Constantin Mierla <miconda at gmail.com>
Committer: Daniel-Constantin Mierla <miconda at gmail.com>
Date:   Thu Oct 20 23:50:08 2011 +0200

dispatcher(k): restore actve state via MI

- resetting the state flags were not in effect for active state,
  reported by Asgaroth
- added define to check whether a destionation addres should be skipped
  or not based on its state

---

 modules_k/dispatcher/dispatch.c |   32 ++++++++++++++++++--------------
 modules_k/dispatcher/dispatch.h |    3 +++
 2 files changed, 21 insertions(+), 14 deletions(-)

diff --git a/modules_k/dispatcher/dispatch.c b/modules_k/dispatcher/dispatch.c
index 9bb942a..3049adc 100644
--- a/modules_k/dispatcher/dispatch.c
+++ b/modules_k/dispatcher/dispatch.c
@@ -1221,8 +1221,7 @@ int ds_get_leastloaded(ds_set_t *dset)
 	t = dset->dlist[k].dload;
 	for(j=1; j<dset->nr; j++)
 	{
-		if(!((dset->dlist[j].flags & DS_INACTIVE_DST)
-				|| (dset->dlist[j].flags & DS_PROBING_DST)))
+		if(!ds_skip_dst(dset->dlist[j].flags & DS_PROBING_DST))
 		{
 			if(dset->dlist[j].dload<t)
 			{
@@ -1692,8 +1691,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
 	else
 		hash = hash%idx->nr;
 	i=hash;
-	while ((idx->dlist[i].flags & DS_INACTIVE_DST)
-			|| (idx->dlist[i].flags & DS_PROBING_DST))
+	while (ds_skip_dst(idx->dlist[i].flags))
 	{
 		if(ds_use_default!=0 && idx->nr!=1)
 			i = (i+1)%(idx->nr-1);
@@ -1705,8 +1703,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
 			if(ds_use_default!=0)
 			{
 				i = idx->nr-1;
-				if((idx->dlist[i].flags & DS_INACTIVE_DST)
-						|| (idx->dlist[i].flags & DS_PROBING_DST))
+				if(ds_skip_dst(idx->dlist[i].flags))
 					return -1;
 				break;
 			} else {
@@ -1769,7 +1766,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
 
 		for(i=hash-1; i>=0; i--)
 		{	
-			if((idx->dlist[i].flags & DS_INACTIVE_DST)
+			if(ds_skip_dst(idx->dlist[i].flags)
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
 				continue;
 			LM_DBG("using entry [%d/%d]\n", set, i);
@@ -1803,7 +1800,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
 
 		for(i=idx->nr-1; i>hash; i--)
 		{	
-			if((idx->dlist[i].flags & DS_INACTIVE_DST)
+			if(ds_skip_dst(idx->dlist[i].flags)
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
 				continue;
 			LM_DBG("using entry [%d/%d]\n", set, i);
@@ -2026,9 +2023,9 @@ int ds_set_state(int group, str *address, int state, int type, struct sip_msg *m
 			/* remove the Probing/Inactive-State? Set the fail-count to 0. */
 			if (state == DS_PROBING_DST) {
 				if (type) {
-					if (idx->dlist[i].flags & DS_INACTIVE_DST) {
+					if (idx->dlist[i].flags & DS_DISABLED_DST) {
 						LM_INFO("Ignoring the request to set this destination"
-								" to probing: It is already inactive!\n");
+								" to probing: It is disabled by admin!\n");
 						return 0;
 					}
 					
@@ -2050,7 +2047,7 @@ int ds_set_state(int group, str *address, int state, int type, struct sip_msg *m
 	
 			/*  Type 2 means reply from OPTIONS-Ping */
 			if (type == 2) {
-				if (idx->dlist[i].flags & DS_INACTIVE_DST) {
+				if (idx->dlist[i].flags & DS_DISABLED_DST) {
 					LM_INFO("Ignoring the request to set this destination"
 							" to active: It is already administratively deactivated!\n");
 					return 0;
@@ -2135,6 +2132,9 @@ int ds_reinit_state(int group, str *address, int state)
 				&& strncasecmp(idx->dlist[i].uri.s, address->s,
 					address->len)==0)
 		{
+			/* reset the bits used for states */
+			idx->dlist[i].flags &= ~(DS_STATES_ALL);
+			/* set the new states */
 			idx->dlist[i].flags |= state;
 			return 0;
 		}
@@ -2165,10 +2165,10 @@ int ds_print_list(FILE *fout)
 		{
 			fprintf(fout, "\n set #%d\n", list->id);
 		
-			if (list->dlist[j].flags&DS_INACTIVE_DST)
+			if (list->dlist[j].flags&DS_DISABLED_DST)
   				fprintf(fout, "    Disabled         ");
-  			else if (list->dlist[j].flags&DS_PROBING_DST)
-  				fprintf(fout, "    Probing          ");
+			else if (list->dlist[j].flags&DS_INACTIVE_DST)
+				fprintf(fout, "    Inactive         ");
   			else {
   				fprintf(fout, "    Active");
   				/* Optional: Print the tries for this host. */
@@ -2180,6 +2180,10 @@ int ds_print_list(FILE *fout)
   					fprintf(fout, "           ");
   				}
   			}
+			if (list->dlist[j].flags&DS_PROBING_DST)
+				fprintf(fout, "(P)");
+			else
+				fprintf(fout, "(*)");
 
   			fprintf(fout, "   %.*s\n",
   				list->dlist[j].uri.len, list->dlist[j].uri.s);		
diff --git a/modules_k/dispatcher/dispatch.h b/modules_k/dispatcher/dispatch.h
index d468e01..6fcd4a5 100644
--- a/modules_k/dispatcher/dispatch.h
+++ b/modules_k/dispatcher/dispatch.h
@@ -52,8 +52,11 @@
 #define DS_INACTIVE_DST		1  /*!< inactive destination */
 #define DS_PROBING_DST		2  /*!< checking destination */
 #define DS_DISABLED_DST		4  /*!< admin disabled destination */
+#define DS_STATES_ALL		7  /*!< all bits for the states of destination */
 #define DS_RESET_FAIL_DST	8  /*!< Reset-Failure-Counter */
 
+#define ds_skip_dst(flags)	((flags) & (DS_INACTIVE_DST|DS_DISABLED_DST))
+
 extern str ds_db_url;
 extern str ds_table_name;
 extern str ds_set_id_col;




More information about the sr-dev mailing list