Browse code

uac: new functionality to force a default socket for register and request sending

- add new functionality to force a default socket with parameter "default_socket"
- works for uac REGISTER requests and also uac_send_req
- if used with uac_send_req an eventual specified socket takes priority over the
default socket

Henning Westerholt authored on 09/08/2019 08:45:53
Showing 5 changed files
... ...
@@ -562,6 +562,30 @@ modparam("uac", "reg_gc_interval", 60)
562 562
 				</programlisting>
563 563
 			</example>
564 564
 		</section>
565
+	<section id="uac.p.default_socket">
566
+		<title><varname>default_socket</varname> (str)</title>
567
+		<para>
568
+			Default socket to be used for generating registration requests and sending
569
+			requests with the function uac_req_send(). Useful e.g. when several public
570
+			interfaces are available.
571
+		</para>
572
+		<para>
573
+		<emphasis>
574
+			By default no default socket is defined, the send socket is choosen from the
575
+			<emphasis>tm</emphasis> module when the requests is send out. A send socket
576
+			in the $uac_reg variable used together with the uac_req_send() function will
577
+			override this parameter.
578
+		</emphasis>
579
+		</para>
580
+		<example>
581
+		<title>Set the <quote>default_socket</quote> parameter</title>
582
+ <programlisting format="linespecific">
583
+ ...
584
+ modparam("uac", "default_socket", "udp:192.168.0.125:5060")
585
+ ...
586
+ </programlisting>
587
+		</example>
588
+	</section>
565 589
 
566 590
 	</section>
567 591
 
... ...
@@ -90,6 +90,8 @@ struct rr_binds uac_rrb;
90 90
 pv_spec_t auth_username_spec;
91 91
 pv_spec_t auth_realm_spec;
92 92
 pv_spec_t auth_password_spec;
93
+str uac_default_socket = STR_NULL;
94
+struct socket_info * uac_default_sockinfo = NULL;
93 95
 
94 96
 static int w_replace_from(struct sip_msg* msg, char* p1, char* p2);
95 97
 static int w_restore_from(struct sip_msg* msg, char* p1, char* p2);
... ...
@@ -172,6 +174,7 @@ static param_export_t params[] = {
172 174
 	{"reg_random_delay",	INT_PARAM,			&reg_random_delay      },
173 175
 	{"reg_active",	INT_PARAM,			&reg_active_param      },
174 176
 	{"reg_gc_interval",		INT_PARAM,	&_uac_reg_gc_interval	},
177
+	{"default_socket",	PARAM_STR, &uac_default_socket},
175 178
 	{0, 0, 0}
176 179
 };
177 180
 
... ...
@@ -206,6 +209,8 @@ inline static int parse_auth_avp( char *avp_spec, pv_spec_t *avp, char *txt)
206 209
 static int mod_init(void)
207 210
 {
208 211
 	pv_spec_t avp_spec;
212
+	str host;
213
+	int port, proto;
209 214
 
210 215
 	if (restore_mode_str && *restore_mode_str) {
211 216
 		if (strcasecmp(restore_mode_str,"none")==0) {
... ...
@@ -349,6 +354,25 @@ static int mod_init(void)
349 354
 		/* add child to update local config framework structures */
350 355
 		cfg_register_child(1);
351 356
 	}
357
+
358
+	if(uac_default_socket.s && uac_default_socket.len > 0) {
359
+		if(parse_phostport(
360
+				   uac_default_socket.s, &host.s, &host.len, &port, &proto)
361
+				!= 0) {
362
+			LM_ERR("bad socket <%.*s>\n", uac_default_socket.len,
363
+					uac_default_socket.s);
364
+			return -1;
365
+		}
366
+		uac_default_sockinfo =
367
+				grep_sock_info(&host, (unsigned short)port, proto);
368
+		if(uac_default_sockinfo == 0) {
369
+			LM_ERR("non-local socket <%.*s>\n", uac_default_socket.len,
370
+					uac_default_socket.s);
371
+			return -1;
372
+		}
373
+		LM_INFO("default uac socket set to <%.*s>\n",
374
+				uac_default_socket.len, uac_default_socket.s);
375
+	}
352 376
 	init_from_replacer();
353 377
 
354 378
 	uac_req_init();
... ...
@@ -1013,6 +1013,10 @@ void uac_reg_tm_callback( struct cell *t, int type, struct tmcb_params *ps)
1013 1013
 		uac_r.cb  = uac_reg_tm_callback;
1014 1014
 		/* Callback parameter */
1015 1015
 		uac_r.cbp = (void*)uuid;
1016
+		/* default socket */
1017
+		if(uac_default_socket.s != NULL && uac_default_socket.len > 0) {
1018
+			uac_r.ssock = &uac_default_socket;
1019
+		}
1016 1020
 #ifdef UAC_OLD_AUTH
1017 1021
 		ret = uac_tmb.t_request(&uac_r,  /* UAC Req */
1018 1022
 				&s_ruri, /* Request-URI */
... ...
@@ -1171,6 +1175,10 @@ int uac_reg_update(reg_uac_t *reg, time_t tn)
1171 1175
 
1172 1176
 		ret = uac_tmb.t_request_within(&uac_r);
1173 1177
 	} else {
1178
+		/* default socket */
1179
+		if(uac_default_socket.s != NULL && uac_default_socket.len > 0) {
1180
+			uac_r.ssock = &uac_default_socket;
1181
+		}
1174 1182
 		ret = uac_tmb.t_request(&uac_r,  /* UAC Req */
1175 1183
 				&s_ruri, /* Request-URI */
1176 1184
 				&s_turi, /* To */
... ...
@@ -32,6 +32,9 @@ extern int reg_random_delay;
32 32
 extern str reg_contact_addr;
33 33
 extern str reg_db_url;
34 34
 extern str reg_db_table;
35
+extern str uac_default_socket;
36
+/* just to check for non-local sockets for now */
37
+extern struct socket_info * uac_default_sockinfo;
35 38
 
36 39
 extern str l_uuid_column;
37 40
 extern str l_username_column;
... ...
@@ -40,6 +40,7 @@
40 40
 #include "auth.h"
41 41
 #include "auth_hdr.h"
42 42
 #include "uac_send.h"
43
+#include "uac_reg.h"
43 44
 
44 45
 #define MAX_UACH_SIZE 2048
45 46
 #define MAX_UACB_SIZE 32768
... ...
@@ -820,7 +821,13 @@ int uac_req_send(void)
820 821
 	uac_r.method = &_uac_req.s_method;
821 822
 	uac_r.headers = (_uac_req.s_hdrs.len <= 0) ? NULL : &_uac_req.s_hdrs;
822 823
 	uac_r.body = (_uac_req.s_body.len <= 0) ? NULL : &_uac_req.s_body;
823
-	uac_r.ssock = (_uac_req.s_sock.len <= 0) ? NULL : &_uac_req.s_sock;
824
+
825
+	if (_uac_req.s_sock.s != NULL && _uac_req.s_sock.len > 0) {
826
+		uac_r.ssock = &_uac_req.s_sock;
827
+	} else if(uac_default_socket.s != NULL && uac_default_socket.len > 0) {
828
+		uac_r.ssock = &uac_default_socket;
829
+	}
830
+
824 831
 	if((_uac_req.s_auser.len > 0 && _uac_req.s_apasswd.len>0)
825 832
 			|| (_uac_req.evroute > 0))
826 833
 	{