Browse code

dispatcher: new parameter ds_default_sockname

- allow to set default send socket by name

Daniel-Constantin Mierla authored on 05/04/2020 08:29:30
Showing 1 changed files
... ...
@@ -102,13 +102,14 @@ static int ds_ping_interval = 0;
102 102
 int ds_ping_latency_stats = 0;
103 103
 int ds_latency_estimator_alpha_i = 900;
104 104
 float ds_latency_estimator_alpha = 0.9f;
105
-int ds_probing_mode  = DS_PROBE_NONE;
105
+int ds_probing_mode = DS_PROBE_NONE;
106 106
 
107 107
 static str ds_ping_reply_codes_str= STR_NULL;
108 108
 static int** ds_ping_reply_codes = NULL;
109 109
 static int* ds_ping_reply_codes_cnt;
110 110
 
111
-str ds_default_socket       = STR_NULL;
111
+str ds_default_socket = STR_NULL;
112
+str ds_default_sockname = STR_NULL;
112 113
 struct socket_info * ds_default_sockinfo = NULL;
113 114
 
114 115
 int ds_hash_size = 0;
... ...
@@ -280,6 +281,7 @@ static param_export_t params[]={
280 281
 	{"ds_hash_check_interval", INT_PARAM, &ds_hash_check_interval},
281 282
 	{"outbound_proxy",     PARAM_STR, &ds_outbound_proxy},
282 283
 	{"ds_default_socket",  PARAM_STR, &ds_default_socket},
284
+	{"ds_default_sockname",PARAM_STR, &ds_default_sockname},
283 285
 	{"ds_timer_mode",      PARAM_INT, &ds_timer_mode},
284 286
 	{"event_callback",     PARAM_STR, &ds_event_callback},
285 287
 	{"ds_attrs_none",      PARAM_INT, &ds_attrs_none},
... ...
@@ -347,23 +349,34 @@ static int mod_init(void)
347 349
 	cfg_get(dispatcher, dispatcher_cfg, inactive_threshold) =
348 350
 			inactive_threshold;
349 351
 
350
-	if(ds_default_socket.s && ds_default_socket.len > 0) {
351
-		if(parse_phostport(
352
-				   ds_default_socket.s, &host.s, &host.len, &port, &proto)
353
-				!= 0) {
354
-			LM_ERR("bad socket <%.*s>\n", ds_default_socket.len,
355
-					ds_default_socket.s);
356
-			return -1;
357
-		}
358
-		ds_default_sockinfo =
359
-				grep_sock_info(&host, (unsigned short)port, proto);
352
+	if(ds_default_sockname.s && ds_default_sockname.len > 0) {
353
+		ds_default_sockinfo = ksr_get_socket_by_name(&ds_default_sockname);
360 354
 		if(ds_default_sockinfo == 0) {
361
-			LM_ERR("non-local socket <%.*s>\n", ds_default_socket.len,
362
-					ds_default_socket.s);
355
+			LM_ERR("non-local socket name <%.*s>\n", ds_default_sockname.len,
356
+					ds_default_sockname.s);
363 357
 			return -1;
364 358
 		}
365
-		LM_INFO("default dispatcher socket set to <%.*s>\n",
366
-				ds_default_socket.len, ds_default_socket.s);
359
+		LM_INFO("default dispatcher socket set by name to <%.*s>\n",
360
+				ds_default_sockname.len, ds_default_sockname.s);
361
+	} else {
362
+		if(ds_default_socket.s && ds_default_socket.len > 0) {
363
+			if(parse_phostport(
364
+					ds_default_socket.s, &host.s, &host.len, &port, &proto)
365
+					!= 0) {
366
+				LM_ERR("bad socket <%.*s>\n", ds_default_socket.len,
367
+						ds_default_socket.s);
368
+				return -1;
369
+			}
370
+			ds_default_sockinfo =
371
+					grep_sock_info(&host, (unsigned short)port, proto);
372
+			if(ds_default_sockinfo == 0) {
373
+				LM_ERR("non-local socket <%.*s>\n", ds_default_socket.len,
374
+						ds_default_socket.s);
375
+				return -1;
376
+			}
377
+			LM_INFO("default dispatcher socket set to <%.*s>\n",
378
+					ds_default_socket.len, ds_default_socket.s);
379
+		}
367 380
 	}
368 381
 
369 382
 	if(ds_init_data() != 0)
... ...
@@ -1559,7 +1572,7 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle)
1559 1572
 				rpc->fault(ctx, 500, "Internal error creating dest struct");
1560 1573
 				return -1;
1561 1574
 			}
1562
-			if(rpc->struct_add(wh, "SSdddS",
1575
+			if(rpc->struct_add(wh, "SSdddSS",
1563 1576
 						"BODY", &(node->dlist[j].attrs.body),
1564 1577
 						"DUID", (node->dlist[j].attrs.duid.s)
1565 1578
 									? &(node->dlist[j].attrs.duid) : &data,
... ...
@@ -1567,7 +1580,9 @@ int ds_rpc_print_set(ds_set_t *node, rpc_t *rpc, void *ctx, void *rpc_handle)
1567 1580
 						"WEIGHT", node->dlist[j].attrs.weight,
1568 1581
 						"RWEIGHT", node->dlist[j].attrs.rweight,
1569 1582
 						"SOCKET", (node->dlist[j].attrs.socket.s)
1570
-									? &(node->dlist[j].attrs.socket) : &data)
1583
+									? &(node->dlist[j].attrs.socket) : &data,
1584
+						"SOCKNAME", (node->dlist[j].attrs.sockname.s)
1585
+									? &(node->dlist[j].attrs.sockname) : &data)
1571 1586
 					< 0) {
1572 1587
 				rpc->fault(ctx, 500, "Internal error creating attrs struct");
1573 1588
 				return -1;