Răsfoiți Sursa

dispatcher: added ping socket configuration

- new dispatcher modparam 'ds_ping_socket'
- new gateway param 'ping_socket'
Michael Furmur 6 luni în urmă
părinte
comite
1414fe8d97

+ 31 - 2
src/modules/dispatcher/dispatch.c

@@ -385,6 +385,9 @@ int ds_set_attrs(ds_dest_t *dest, str *vattrs)
 		} else if(pit->name.len == 8
 				  && strncasecmp(pit->name.s, "sockname", 8) == 0) {
 			dest->attrs.sockname = pit->body;
+		} else if(pit->name.len == 11
+				  && strncasecmp(pit->name.s, "ping_socket", 11) == 0) {
+			dest->attrs.ping_socket = pit->body;
 		} else if(pit->name.len == 7
 				  && strncasecmp(pit->name.s, "rweight", 7) == 0) {
 			tmp_ival = 0;
@@ -652,6 +655,27 @@ ds_dest_t *pack_dest(str iuri, int flags, int priority, str *attrs, int dload)
 		dp->sock = ds_default_sockinfo;
 	}
 
+	/* set send socket to be used for sending the probing requests */
+	if(dp->attrs.ping_socket.s && dp->attrs.ping_socket.len > 0) {
+		/* parse_phostport(...) expects 0-terminated string
+		 * - after socket parameter is either ';' or '\0' */
+		STR_VTOZ(dp->attrs.ping_socket.s[dp->attrs.ping_socket.len], c);
+		if(parse_phostport(
+				   dp->attrs.ping_socket.s, &host.s, &host.len, &port, &proto)
+				!= 0) {
+			LM_ERR("bad socket <%.*s>\n", dp->attrs.ping_socket.len,
+					dp->attrs.ping_socket.s);
+			STR_ZTOV(dp->attrs.ping_socket.s[dp->attrs.ping_socket.len], c);
+			goto err;
+		}
+		STR_ZTOV(dp->attrs.ping_socket.s[dp->attrs.ping_socket.len], c);
+		dp->sock = grep_sock_info(&host, (unsigned short)port, proto);
+		if(dp->sock == 0) {
+			LM_ERR("non-local socket <%.*s>\n", dp->attrs.ping_socket.len,
+					dp->attrs.ping_socket.s);
+			goto err;
+		}
+	}
 
 	dp->host.s = dp->uri.s + (puri.host.s - uri.s);
 	dp->host.len = puri.host.len;
@@ -4128,12 +4152,17 @@ void ds_ping_set(ds_set_t *node)
 			 *		transaction_cb cb, void* cbp); */
 			set_uac_req(&uac_r, &ds_ping_method, 0, 0, 0, TMCB_LOCAL_COMPLETED,
 					ds_options_callback, (void *)(long)node->id);
-			if(node->dlist[j].attrs.sockname.s != NULL
-					&& node->dlist[j].attrs.sockname.len > 0) {
+			if(node->dlist[j].attrs.ping_socket.s != NULL
+					&& node->dlist[j].attrs.ping_socket.len > 0) {
+				uac_r.ssock = &node->dlist[j].attrs.ping_socket;
+			} else if(node->dlist[j].attrs.sockname.s != NULL
+					  && node->dlist[j].attrs.sockname.len > 0) {
 				uac_r.ssockname = &node->dlist[j].attrs.sockname;
 			} else if(node->dlist[j].attrs.socket.s != NULL
 					  && node->dlist[j].attrs.socket.len > 0) {
 				uac_r.ssock = &node->dlist[j].attrs.socket;
+			} else if(ds_ping_socket.s != NULL && ds_ping_socket.len > 0) {
+				uac_r.ssock = &ds_ping_socket;
 			} else if(ds_default_sockname.s != NULL
 					  && ds_default_sockname.len > 0) {
 				uac_r.ssockname = &ds_default_sockname;

+ 2 - 0
src/modules/dispatcher/dispatch.h

@@ -137,6 +137,7 @@ extern int ds_probing_mode;
 extern str ds_outbound_proxy;
 extern str ds_default_socket;
 extern str ds_default_sockname;
+extern str ds_ping_socket;
 extern struct socket_info *ds_default_sockinfo;
 
 int ds_init_data(void);
@@ -198,6 +199,7 @@ typedef struct _ds_attrs {
 	str body;
 	str duid;
 	str socket;
+	str ping_socket;
 	str sockname;
 	int maxload;
 	int weight;

+ 22 - 1
src/modules/dispatcher/dispatcher.c

@@ -114,6 +114,7 @@ static int* ds_ping_reply_codes_cnt;
 
 str ds_default_socket = STR_NULL;
 str ds_default_sockname = STR_NULL;
+str ds_ping_socket = STR_NULL;
 struct socket_info * ds_default_sockinfo = NULL;
 
 int ds_hash_size = 0;
@@ -312,6 +313,7 @@ static param_export_t params[]={
 	{"outbound_proxy",     PARAM_STR, &ds_outbound_proxy},
 	{"ds_default_socket",  PARAM_STR, &ds_default_socket},
 	{"ds_default_sockname",PARAM_STR, &ds_default_sockname},
+	{"ds_ping_socket",     PARAM_STR, &ds_ping_socket},
 	{"ds_timer_mode",      PARAM_INT, &ds_timer_mode},
 	{"event_callback",     PARAM_STR, &ds_event_callback},
 	{"ds_attrs_none",      PARAM_INT, &ds_attrs_none},
@@ -433,6 +435,21 @@ static int mod_init(void)
 		}
 	}
 
+	if(ds_ping_socket.s && ds_ping_socket.len > 0) {
+		if(parse_phostport(ds_ping_socket.s, &host.s, &host.len, &port, &proto)
+				!= 0) {
+			LM_ERR("bad socket <%.*s>\n", ds_ping_socket.len, ds_ping_socket.s);
+			return -1;
+		}
+		if(grep_sock_info(&host, (unsigned short)port, proto) == 0) {
+			LM_ERR("non-local socket <%.*s>\n", ds_ping_socket.len,
+					ds_ping_socket.s);
+			return -1;
+		}
+		LM_INFO("ping dispatcher socket set to <%.*s>\n", ds_ping_socket.len,
+				ds_ping_socket.s);
+	}
+
 	if(ds_init_data() != 0)
 		return -1;
 
@@ -1982,7 +1999,7 @@ int ds_rpc_print_set(
 				rpc->fault(ctx, 500, "Internal error creating dest struct");
 				return -1;
 			}
-			if(rpc->struct_add(wh, "SSdddSSSjj", "BODY",
+			if(rpc->struct_add(wh, "SSdddSSSSjj", "BODY",
 					   &(node->dlist[j].attrs.body), "DUID",
 					   (node->dlist[j].attrs.duid.s)
 							   ? &(node->dlist[j].attrs.duid)
@@ -1997,6 +2014,10 @@ int ds_rpc_print_set(
 					   (node->dlist[j].attrs.sockname.s)
 							   ? &(node->dlist[j].attrs.sockname)
 							   : &data,
+					   "PING_SOCKET",
+					   (node->dlist[j].attrs.ping_socket.s)
+							   ? &(node->dlist[j].attrs.ping_socket)
+							   : &data,
 					   "OBPROXY",
 					   (node->dlist[j].attrs.obproxy.s)
 							   ? &(node->dlist[j].attrs.obproxy)

+ 20 - 0
src/modules/dispatcher/doc/dispatcher_admin.xml

@@ -965,6 +965,22 @@ modparam("dispatcher", "ds_default_sockname", "sock1")
 		</example>
 	</section>
 
+	<section id="dispatcher.p.ds_ping_socket">
+		<title><varname>ds_ping_socket</varname> (str)</title>
+		<para>
+			Default socket to be used for sending ping requests
+			when a gateway has no "ping_socket" configured.
+		</para>
+		<example>
+		<title>Set the <quote>ds_ping_socket</quote> parameter</title>
+<programlisting format="linespecific">
+...
+modparam("dispatcher", "ds_ping_socket", "udp:192.168.0.125:5060")
+...
+</programlisting>
+		</example>
+	</section>
+
 	<section id="dispatcher.p.ds_timer_mode">
 		<title><varname>ds_timer_mode</varname> (int)</title>
 		<para>
@@ -2480,6 +2496,10 @@ kamcli dispatcher.oclist 1
 								used for sending the SIP traffic as well as OPTIONS
 								keepalives.</para>
 						</listitem>
+						<listitem>
+							<para>'ping_socket' - used to set the sending socket for ping requests.
+								It overwrites the general ds_ping_socket parameter.</para>
+						</listitem>
 						<listitem>
 							<para>'sockname' - used to set by name the sending socket for the
 								gateway. It is used for sending the SIP traffic as well as OPTIONS