Browse code

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 authored on 20/10/2011 21:50:08
Showing 2 changed files
... ...
@@ -1221,8 +1221,7 @@ int ds_get_leastloaded(ds_set_t *dset)
1221 1221
 	t = dset->dlist[k].dload;
1222 1222
 	for(j=1; j<dset->nr; j++)
1223 1223
 	{
1224
-		if(!((dset->dlist[j].flags & DS_INACTIVE_DST)
1225
-				|| (dset->dlist[j].flags & DS_PROBING_DST)))
1224
+		if(!ds_skip_dst(dset->dlist[j].flags & DS_PROBING_DST))
1226 1225
 		{
1227 1226
 			if(dset->dlist[j].dload<t)
1228 1227
 			{
... ...
@@ -1692,8 +1691,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
1692 1691
 	else
1693 1692
 		hash = hash%idx->nr;
1694 1693
 	i=hash;
1695
-	while ((idx->dlist[i].flags & DS_INACTIVE_DST)
1696
-			|| (idx->dlist[i].flags & DS_PROBING_DST))
1694
+	while (ds_skip_dst(idx->dlist[i].flags))
1697 1695
 	{
1698 1696
 		if(ds_use_default!=0 && idx->nr!=1)
1699 1697
 			i = (i+1)%(idx->nr-1);
... ...
@@ -1705,8 +1703,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
1705 1703
 			if(ds_use_default!=0)
1706 1704
 			{
1707 1705
 				i = idx->nr-1;
1708
-				if((idx->dlist[i].flags & DS_INACTIVE_DST)
1709
-						|| (idx->dlist[i].flags & DS_PROBING_DST))
1706
+				if(ds_skip_dst(idx->dlist[i].flags))
1710 1707
 					return -1;
1711 1708
 				break;
1712 1709
 			} else {
... ...
@@ -1769,7 +1766,7 @@ int ds_select_dst(struct sip_msg *msg, int set, int alg, int mode)
1769 1766
 
1770 1767
 		for(i=hash-1; i>=0; i--)
1771 1768
 		{	
1772
-			if((idx->dlist[i].flags & DS_INACTIVE_DST)
1769
+			if(ds_skip_dst(idx->dlist[i].flags)
1773 1770
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
1774 1771
 				continue;
1775 1772
 			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)
1803 1800
 
1804 1801
 		for(i=idx->nr-1; i>hash; i--)
1805 1802
 		{	
1806
-			if((idx->dlist[i].flags & DS_INACTIVE_DST)
1803
+			if(ds_skip_dst(idx->dlist[i].flags)
1807 1804
 					|| (ds_use_default!=0 && i==(idx->nr-1)))
1808 1805
 				continue;
1809 1806
 			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
2026 2023
 			/* remove the Probing/Inactive-State? Set the fail-count to 0. */
2027 2024
 			if (state == DS_PROBING_DST) {
2028 2025
 				if (type) {
2029
-					if (idx->dlist[i].flags & DS_INACTIVE_DST) {
2026
+					if (idx->dlist[i].flags & DS_DISABLED_DST) {
2030 2027
 						LM_INFO("Ignoring the request to set this destination"
2031
-								" to probing: It is already inactive!\n");
2028
+								" to probing: It is disabled by admin!\n");
2032 2029
 						return 0;
2033 2030
 					}
2034 2031
 					
... ...
@@ -2050,7 +2047,7 @@ int ds_set_state(int group, str *address, int state, int type, struct sip_msg *m
2050 2047
 	
2051 2048
 			/*  Type 2 means reply from OPTIONS-Ping */
2052 2049
 			if (type == 2) {
2053
-				if (idx->dlist[i].flags & DS_INACTIVE_DST) {
2050
+				if (idx->dlist[i].flags & DS_DISABLED_DST) {
2054 2051
 					LM_INFO("Ignoring the request to set this destination"
2055 2052
 							" to active: It is already administratively deactivated!\n");
2056 2053
 					return 0;
... ...
@@ -2135,6 +2132,9 @@ int ds_reinit_state(int group, str *address, int state)
2135 2132
 				&& strncasecmp(idx->dlist[i].uri.s, address->s,
2136 2133
 					address->len)==0)
2137 2134
 		{
2135
+			/* reset the bits used for states */
2136
+			idx->dlist[i].flags &= ~(DS_STATES_ALL);
2137
+			/* set the new states */
2138 2138
 			idx->dlist[i].flags |= state;
2139 2139
 			return 0;
2140 2140
 		}
... ...
@@ -2165,10 +2165,10 @@ int ds_print_list(FILE *fout)
2165 2165
 		{
2166 2166
 			fprintf(fout, "\n set #%d\n", list->id);
2167 2167
 		
2168
-			if (list->dlist[j].flags&DS_INACTIVE_DST)
2168
+			if (list->dlist[j].flags&DS_DISABLED_DST)
2169 2169
   				fprintf(fout, "    Disabled         ");
2170
-  			else if (list->dlist[j].flags&DS_PROBING_DST)
2171
-  				fprintf(fout, "    Probing          ");
2170
+			else if (list->dlist[j].flags&DS_INACTIVE_DST)
2171
+				fprintf(fout, "    Inactive         ");
2172 2172
   			else {
2173 2173
   				fprintf(fout, "    Active");
2174 2174
   				/* Optional: Print the tries for this host. */
... ...
@@ -2180,6 +2180,10 @@ int ds_print_list(FILE *fout)
2180 2180
   					fprintf(fout, "           ");
2181 2181
   				}
2182 2182
   			}
2183
+			if (list->dlist[j].flags&DS_PROBING_DST)
2184
+				fprintf(fout, "(P)");
2185
+			else
2186
+				fprintf(fout, "(*)");
2183 2187
 
2184 2188
   			fprintf(fout, "   %.*s\n",
2185 2189
   				list->dlist[j].uri.len, list->dlist[j].uri.s);		
... ...
@@ -52,8 +52,11 @@
52 52
 #define DS_INACTIVE_DST		1  /*!< inactive destination */
53 53
 #define DS_PROBING_DST		2  /*!< checking destination */
54 54
 #define DS_DISABLED_DST		4  /*!< admin disabled destination */
55
+#define DS_STATES_ALL		7  /*!< all bits for the states of destination */
55 56
 #define DS_RESET_FAIL_DST	8  /*!< Reset-Failure-Counter */
56 57
 
58
+#define ds_skip_dst(flags)	((flags) & (DS_INACTIVE_DST|DS_DISABLED_DST))
59
+
57 60
 extern str ds_db_url;
58 61
 extern str ds_table_name;
59 62
 extern str ds_set_id_col;