Explorar o código

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
Daniel-Constantin Mierla %!s(int64=14) %!d(string=hai) anos
pai
achega
25bedcd991
Modificáronse 2 ficheiros con 21 adicións e 14 borrados
  1. 18 14
      modules_k/dispatcher/dispatch.c
  2. 3 0
      modules_k/dispatcher/dispatch.h

+ 18 - 14
modules_k/dispatcher/dispatch.c

@@ -1221,8 +1221,7 @@ int ds_get_leastloaded(ds_set_t *dset)
 	t = dset->dlist[k].dload;
 	t = dset->dlist[k].dload;
 	for(j=1; j<dset->nr; j++)
 	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)
 			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
 	else
 		hash = hash%idx->nr;
 		hash = hash%idx->nr;
 	i=hash;
 	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)
 		if(ds_use_default!=0 && idx->nr!=1)
 			i = (i+1)%(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)
 			if(ds_use_default!=0)
 			{
 			{
 				i = idx->nr-1;
 				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;
 					return -1;
 				break;
 				break;
 			} else {
 			} 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--)
 		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)))
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
 				continue;
 				continue;
 			LM_DBG("using entry [%d/%d]\n", set, i);
 			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--)
 		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)))
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
 				continue;
 				continue;
 			LM_DBG("using entry [%d/%d]\n", set, i);
 			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. */
 			/* remove the Probing/Inactive-State? Set the fail-count to 0. */
 			if (state == DS_PROBING_DST) {
 			if (state == DS_PROBING_DST) {
 				if (type) {
 				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"
 						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;
 						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 */
 			/*  Type 2 means reply from OPTIONS-Ping */
 			if (type == 2) {
 			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"
 					LM_INFO("Ignoring the request to set this destination"
 							" to active: It is already administratively deactivated!\n");
 							" to active: It is already administratively deactivated!\n");
 					return 0;
 					return 0;
@@ -2135,6 +2132,9 @@ int ds_reinit_state(int group, str *address, int state)
 				&& strncasecmp(idx->dlist[i].uri.s, address->s,
 				&& strncasecmp(idx->dlist[i].uri.s, address->s,
 					address->len)==0)
 					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;
 			idx->dlist[i].flags |= state;
 			return 0;
 			return 0;
 		}
 		}
@@ -2165,10 +2165,10 @@ int ds_print_list(FILE *fout)
 		{
 		{
 			fprintf(fout, "\n set #%d\n", list->id);
 			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         ");
   				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 {
   			else {
   				fprintf(fout, "    Active");
   				fprintf(fout, "    Active");
   				/* Optional: Print the tries for this host. */
   				/* Optional: Print the tries for this host. */
@@ -2180,6 +2180,10 @@ int ds_print_list(FILE *fout)
   					fprintf(fout, "           ");
   					fprintf(fout, "           ");
   				}
   				}
   			}
   			}
+			if (list->dlist[j].flags&DS_PROBING_DST)
+				fprintf(fout, "(P)");
+			else
+				fprintf(fout, "(*)");
 
 
   			fprintf(fout, "   %.*s\n",
   			fprintf(fout, "   %.*s\n",
   				list->dlist[j].uri.len, list->dlist[j].uri.s);		
   				list->dlist[j].uri.len, list->dlist[j].uri.s);		

+ 3 - 0
modules_k/dispatcher/dispatch.h

@@ -52,8 +52,11 @@
 #define DS_INACTIVE_DST		1  /*!< inactive destination */
 #define DS_INACTIVE_DST		1  /*!< inactive destination */
 #define DS_PROBING_DST		2  /*!< checking destination */
 #define DS_PROBING_DST		2  /*!< checking destination */
 #define DS_DISABLED_DST		4  /*!< admin disabled 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_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_db_url;
 extern str ds_table_name;
 extern str ds_table_name;
 extern str ds_set_id_col;
 extern str ds_set_id_col;