Browse code

rtpengine: Fix typo in RPC response handling

Olle E. Johansson authored on 03/01/2022 15:36:26
Showing 1 changed files
... ...
@@ -1341,7 +1341,7 @@ static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx)
1341 1341
 	LM_DBG("current rtpengines list version: %d (%u)\n",
1342 1342
 			_rtpe_list_version->vernum,
1343 1343
 			(unsigned int)_rtpe_list_version->vertime);
1344
-	rpc->rpl_printf(c, "Ok. Reload successful.");
1344
+	rpc->rpl_printf(ctx, "Ok. Reload successful.");
1345 1345
 }
1346 1346
 
1347 1347
 static int rtpengine_rpc_iterate(rpc_t* rpc, void* ctx, const str *rtpp_url,
Browse code

rtpengine: Add RPC success message on reload

Olle E. Johansson authored on 03/01/2022 15:14:19
Showing 1 changed files
... ...
@@ -283,7 +283,7 @@ static str body_intermediate;
283 283
 static str rtp_inst_pv_param = {NULL, 0};
284 284
 static pv_spec_t *rtp_inst_pvar = NULL;
285 285
 
286
-/* array with the sockets used by rtpporxy (per process)*/
286
+/* array with the sockets used by rtpproxy (per process)*/
287 287
 static unsigned int *rtpp_no = 0;
288 288
 static gen_lock_t *rtpp_no_lock = 0;
289 289
 static int *rtpp_socks = 0;
... ...
@@ -1341,6 +1341,7 @@ static void rtpengine_rpc_reload(rpc_t* rpc, void* ctx)
1341 1341
 	LM_DBG("current rtpengines list version: %d (%u)\n",
1342 1342
 			_rtpe_list_version->vernum,
1343 1343
 			(unsigned int)_rtpe_list_version->vertime);
1344
+	rpc->rpl_printf(c, "Ok. Reload successful.");
1344 1345
 }
1345 1346
 
1346 1347
 static int rtpengine_rpc_iterate(rpc_t* rpc, void* ctx, const str *rtpp_url,
Browse code

rtpengine: Don't recheck node if disabled permanently

Stefan Mititelu authored on 18/10/2021 10:33:53 • Henning Westerholt committed on 21/10/2021 09:47:33
Showing 1 changed files
... ...
@@ -2707,7 +2707,8 @@ select_node:
2707 2707
 		}
2708 2708
 
2709 2709
 		cp = send_rtpp_command(node, ng_flags.dict, &ret);
2710
-		if (cp == NULL) {
2710
+		/* if node is disabled permanent, don't recheck it later */
2711
+		if (cp == NULL && node->rn_recheck_ticks != RTPENGINE_MAX_RECHECK_TICKS) {
2711 2712
 			node->rn_disabled = 1;
2712 2713
 			node->rn_recheck_ticks = get_ticks() + cfg_get(rtpengine,rtpengine_cfg,rtpengine_disable_tout);
2713 2714
 		}
Browse code

rtpengine: added rtpengine_query_v()

- do a query cmd and store the response in a variable as a json

Daniel-Constantin Mierla authored on 27/08/2021 16:28:12
Showing 1 changed files
... ...
@@ -78,6 +78,7 @@
78 78
 #include "../../core/rpc_lookup.h"
79 79
 #include "../../core/kemi.h"
80 80
 #include "../../core/char_msg_val.h"
81
+#include "../../core/utils/srjson.h"
81 82
 #include "../../modules/tm/tm_load.h"
82 83
 #include "../../modules/crypto/api.h"
83 84
 #include "../../modules/lwsc/api.h"
... ...
@@ -216,6 +217,10 @@ static int rtpengine_manage1_f(struct sip_msg *, char *, char *);
216 217
 static int rtpengine_query1_f(struct sip_msg *, char *, char *);
217 218
 static int rtpengine_info1_f(struct sip_msg *, char *, char *);
218 219
 
220
+static int w_rtpengine_query_v(sip_msg_t *msg, char *pfmt, char *pvar);
221
+static int fixup_rtpengine_query_v(void **param, int param_no);
222
+static int fixup_free_rtpengine_query_v(void **param, int param_no);
223
+
219 224
 static int parse_flags(struct ng_flags_parse *, struct sip_msg *, enum rtpe_operation *, const char *);
220 225
 
221 226
 static int rtpengine_offer_answer(struct sip_msg *msg, const char *flags, enum rtpe_operation op, int more);
... ...
@@ -443,6 +448,9 @@ static cmd_export_t cmds[] = {
443 448
 	{"rtpengine_query",	(cmd_function)rtpengine_query1_f,	1,
444 449
 		fixup_spve_null, 0,
445 450
 		ANY_ROUTE},
451
+	{"rtpengine_query_v",	(cmd_function)w_rtpengine_query_v,	2,
452
+		fixup_rtpengine_query_v, fixup_free_rtpengine_query_v,
453
+		ANY_ROUTE},
446 454
 	{0, 0, 0, 0, 0, 0}
447 455
 };
448 456
 
... ...
@@ -4165,6 +4173,241 @@ pv_get_rtpestat_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
4165 4173
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_rtpstat_wrap, parms, 1, OP_ANY);
4166 4174
 }
4167 4175
 
4176
+/**
4177
+ *
4178
+ */
4179
+static srjson_t *rtpengine_query_v_build_json(srjson_doc_t *jdoc,
4180
+		bencode_item_t *dict)
4181
+{
4182
+	srjson_t *vnode;
4183
+	srjson_t *tnode;
4184
+	bencode_item_t *it;
4185
+	str sval;
4186
+
4187
+	if(jdoc==NULL || dict==NULL) {
4188
+		LM_ERR("invalid parameters\n");
4189
+		return NULL;
4190
+	}
4191
+
4192
+	switch (dict->type) {
4193
+		case BENCODE_STRING:
4194
+			return srjson_CreateStr(jdoc, dict->iov[1].iov_base, dict->iov[1].iov_len);
4195
+
4196
+		case BENCODE_INTEGER:
4197
+			return srjson_CreateNumber(jdoc, dict->value);
4198
+
4199
+		case BENCODE_LIST:
4200
+			vnode = srjson_CreateArray(jdoc);
4201
+			if(vnode==NULL) {
4202
+				LM_ERR("failed to create the array node\n");
4203
+				return NULL;
4204
+			}
4205
+			for (it = dict->child; it; it = it->sibling) {
4206
+				tnode = rtpengine_query_v_build_json(jdoc, it);
4207
+				if (!tnode) {
4208
+					srjson_Delete(jdoc, vnode);
4209
+					return NULL;
4210
+				}
4211
+				srjson_AddItemToArray(jdoc, vnode, tnode);
4212
+			}
4213
+			return vnode;
4214
+
4215
+		case BENCODE_DICTIONARY:
4216
+			vnode = srjson_CreateObject(jdoc);
4217
+			if(vnode==NULL) {
4218
+				LM_ERR("failed to create the object node\n");
4219
+				return NULL;
4220
+			}
4221
+			for (it = dict->child; it; it = it->sibling) {
4222
+				/* name of the item */
4223
+				sval.s = it->iov[1].iov_base;
4224
+				sval.len = it->iov[1].iov_len;
4225
+				/* value of the item */
4226
+				it = it->sibling;
4227
+				tnode = rtpengine_query_v_build_json(jdoc, it);
4228
+				if (!tnode) {
4229
+					srjson_Delete(jdoc, vnode);
4230
+					return NULL;
4231
+				}
4232
+				srjson_AddStrItemToObject(jdoc, vnode, sval.s, sval.len, tnode);
4233
+			}
4234
+			return vnode;
4235
+
4236
+		default:
4237
+			LM_ERR("unsupported bencode item type %d\n", dict->type);
4238
+			return NULL;
4239
+	}
4240
+}
4241
+
4242
+/**
4243
+ *
4244
+ */
4245
+static int rtpengine_query_v_print(bencode_item_t *dict, str *fmt,
4246
+		str *bout)
4247
+{
4248
+	srjson_doc_t jdoc;
4249
+
4250
+	if(fmt==NULL || fmt->s==NULL || fmt->len<=0) {
4251
+		LM_ERR("invalid format parameter\n");
4252
+		return -1;
4253
+	}
4254
+	if(fmt->s[0]!='j' && fmt->s[0]!='J') {
4255
+		LM_ERR("invalid format parameter value: %.*s\n", fmt->len, fmt->s);
4256
+		return -1;
4257
+	}
4258
+
4259
+	srjson_InitDoc(&jdoc, NULL);
4260
+	jdoc.root = rtpengine_query_v_build_json(&jdoc, dict);
4261
+
4262
+	if(jdoc.root==NULL) {
4263
+		LM_ERR("failed to build json document\n");
4264
+		return -1;
4265
+	}
4266
+
4267
+	if(fmt->len>1 && (fmt->s[1]=='p' || fmt->s[1]=='P')) {
4268
+		bout->s = srjson_Print(&jdoc, jdoc.root);
4269
+	} else {
4270
+		bout->s = srjson_PrintUnformatted(&jdoc, jdoc.root);
4271
+	}
4272
+	if(bout->s==NULL) {
4273
+		LM_ERR("unable to serialize json document\n");
4274
+		srjson_DestroyDoc(&jdoc);
4275
+		return -1;
4276
+	}
4277
+	bout->len = strlen(bout->s);
4278
+	srjson_DestroyDoc(&jdoc);
4279
+
4280
+	return 0;
4281
+}
4282
+
4283
+/**
4284
+ *
4285
+ */
4286
+static int rtpengine_query_v_wrap(struct sip_msg *msg, void *d, int more,
4287
+		enum rtpe_operation op)
4288
+{
4289
+	void **parms;
4290
+	str *fmt = NULL;
4291
+	pv_spec_t *dst = NULL;
4292
+	pv_value_t val = {0};
4293
+	bencode_buffer_t bencbuf;
4294
+	bencode_item_t *dict;
4295
+
4296
+	parms = d;
4297
+	fmt = parms[0];
4298
+	dst = parms[1];
4299
+
4300
+	dict = rtpp_function_call_ok(&bencbuf, msg, OP_QUERY, NULL, NULL);
4301
+	if (!dict) {
4302
+		return -1;
4303
+	}
4304
+	if(rtpengine_query_v_print(dict, fmt, &val.rs)<0) {
4305
+		goto error;
4306
+	}
4307
+
4308
+	val.flags = PV_VAL_STR;
4309
+	if(dst->setf) {
4310
+		dst->setf(msg, &dst->pvp, (int)EQ_T, &val);
4311
+	} else {
4312
+		LM_WARN("target pv is not writable\n");
4313
+	}
4314
+
4315
+	/* val.rs.s is allocated by srjson print */
4316
+	free(val.rs.s);
4317
+
4318
+	bencode_buffer_free(&bencbuf);
4319
+	return 1;
4320
+
4321
+error:
4322
+	bencode_buffer_free(&bencbuf);
4323
+	return -1;
4324
+}
4325
+
4326
+/**
4327
+ *
4328
+ */
4329
+static int ki_rtpengine_query_v(sip_msg_t *msg, str *fmt, str *dpv)
4330
+{
4331
+	void *parms[2];
4332
+	pv_spec_t *dst;
4333
+
4334
+	dst = pv_cache_get(dpv);
4335
+	if(dst==NULL) {
4336
+		LM_ERR("failed to get pv spec for: %.*s\n", dpv->len, dpv->s);
4337
+		return -1;
4338
+	}
4339
+	if(dst->setf==NULL) {
4340
+		LM_ERR("target pv is not writable: %.*s\n", dpv->len, dpv->s);
4341
+		return -1;
4342
+	}
4343
+	parms[0] = fmt;
4344
+	parms[1] = dst;
4345
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_query_v_wrap, parms, 1, OP_ANY);
4346
+}
4347
+
4348
+/*
4349
+ * Store the cmd QUERY result to variable
4350
+ */
4351
+static int w_rtpengine_query_v(sip_msg_t *msg, char *pfmt, char *pvar)
4352
+{
4353
+	void *parms[2];
4354
+	str fmt = {NULL, 0};
4355
+	pv_spec_t *dst;
4356
+
4357
+	if(fixup_get_svalue(msg, (gparam_t*)pfmt, &fmt) < 0 || fmt.len <= 0) {
4358
+		LM_ERR("fmt has no value\n");
4359
+		return -1;
4360
+	}
4361
+	dst = (pv_spec_t *)pvar;
4362
+
4363
+	parms[0] = &fmt;
4364
+	parms[1] = dst;
4365
+
4366
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_query_v_wrap, parms, 1, OP_ANY);
4367
+}
4368
+
4369
+/**
4370
+ *
4371
+ */
4372
+static int fixup_rtpengine_query_v(void **param, int param_no)
4373
+{
4374
+	if(param_no == 1) {
4375
+		return fixup_spve_null(param, 1);
4376
+	}
4377
+
4378
+	if(param_no == 2) {
4379
+		if(fixup_pvar_null(param, 1) != 0) {
4380
+			LM_ERR("failed to fixup result pvar\n");
4381
+			return -1;
4382
+		}
4383
+		if(((pv_spec_t *)(*param))->setf == NULL) {
4384
+			LM_ERR("result pvar is not writeble\n");
4385
+			return -1;
4386
+		}
4387
+		return 0;
4388
+	}
4389
+
4390
+	LM_ERR("invalid parameter number <%d>\n", param_no);
4391
+	return -1;
4392
+}
4393
+
4394
+/**
4395
+ *
4396
+ */
4397
+static int fixup_free_rtpengine_query_v(void **param, int param_no)
4398
+{
4399
+	if(param_no == 1) {
4400
+		return fixup_free_spve_null(param, 1);
4401
+	}
4402
+
4403
+	if(param_no == 2) {
4404
+		return fixup_free_pvar_null(param, 1);
4405
+	}
4406
+
4407
+	LM_ERR("invalid parameter number <%d>\n", param_no);
4408
+	return -1;
4409
+}
4410
+
4168 4411
 static int
4169 4412
 set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri) {
4170 4413
 	pv_value_t val;
... ...
@@ -4529,6 +4772,11 @@ static sr_kemi_t sr_kemi_rtpengine_exports[] = {
4529 4772
         { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
4530 4773
             SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4531 4774
     },
4775
+   { str_init("rtpengine"), str_init("rtpengine_query_v"),
4776
+        SR_KEMIP_INT, ki_rtpengine_query_v,
4777
+        { SR_KEMIP_STR, SR_KEMIP_STR, SR_KEMIP_NONE,
4778
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4779
+    },
4532 4780
 
4533 4781
     { {0, 0}, {0, 0}, 0, NULL, { 0, 0, 0, 0, 0, 0 } }
4534 4782
 };
Browse code

rtpengine: aliased $rtpestat to $rtpstat

- can be useful when playing with rtpproxy in same config
- show an example of content for variable

Daniel-Constantin Mierla authored on 27/08/2021 10:56:40
Showing 1 changed files
... ...
@@ -245,7 +245,7 @@ static int add_rtpp_node_info(void *ptrs, struct rtpp_node *crt_rtpp, struct rtp
245 245
 static int rtpp_test_ping(struct rtpp_node *node);
246 246
 
247 247
 /* Pseudo-Variables */
248
-static int pv_get_rtpstat_f(struct sip_msg *, pv_param_t *, pv_value_t *);
248
+static int pv_get_rtpestat_f(struct sip_msg *, pv_param_t *, pv_value_t *);
249 249
 static int set_rtp_inst_pvar(struct sip_msg *msg, const str * const uri);
250 250
 static int pv_parse_var(str *inp, pv_elem_t **outp, int *got_any);
251 251
 static int mos_label_stats_parse(struct minmax_mos_label_stats *mmls);
... ...
@@ -448,7 +448,9 @@ static cmd_export_t cmds[] = {
448 448
 
449 449
 static pv_export_t mod_pvs[] = {
450 450
 	{{"rtpstat", (sizeof("rtpstat")-1)}, /* RTP-Statistics */
451
-	PVT_OTHER, pv_get_rtpstat_f, 0, 0, 0, 0, 0},
451
+	PVT_OTHER, pv_get_rtpestat_f, 0, 0, 0, 0, 0},
452
+	{{"rtpestat", (sizeof("rtpestat")-1)}, /* RTP-Statistics */
453
+	PVT_OTHER, pv_get_rtpestat_f, 0, 0, 0, 0, 0},
452 454
 	{{0, 0}, 0, 0, 0, 0, 0, 0, 0}
453 455
 };
454 456
 
... ...
@@ -4153,7 +4155,7 @@ error:
4153 4155
  * Returns the current RTP-Statistics from the RTP-Proxy
4154 4156
  */
4155 4157
 static int
4156
-pv_get_rtpstat_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
4158
+pv_get_rtpestat_f(struct sip_msg *msg, pv_param_t *param, pv_value_t *res)
4157 4159
 {
4158 4160
 	void *parms[2];
4159 4161
 
Browse code

rtpengine: add un/silence_media() methods

Richard Fuchs authored on 23/07/2021 17:34:18
Showing 1 changed files
... ...
@@ -137,6 +137,8 @@ static const char *command_strings[] = {
137 137
 	[OP_UNBLOCK_DTMF]	= "unblock DTMF",
138 138
 	[OP_BLOCK_MEDIA]	= "block media",
139 139
 	[OP_UNBLOCK_MEDIA]	= "unblock media",
140
+	[OP_SILENCE_MEDIA]	= "silence media",
141
+	[OP_UNSILENCE_MEDIA]	= "unsilence media",
140 142
 	[OP_START_FORWARDING]	= "start forwarding",
141 143
 	[OP_STOP_FORWARDING]	= "stop forwarding",
142 144
 	[OP_PLAY_MEDIA]		= "play media",
... ...
@@ -200,6 +202,8 @@ static int block_dtmf_f(struct sip_msg *, char *, char *);
200 202
 static int unblock_dtmf_f(struct sip_msg *, char *, char *);
201 203
 static int block_media_f(struct sip_msg *, char *, char *);
202 204
 static int unblock_media_f(struct sip_msg *, char *, char *);
205
+static int silence_media_f(struct sip_msg *, char *, char *);
206
+static int unsilence_media_f(struct sip_msg *, char *, char *);
203 207
 static int start_forwarding_f(struct sip_msg *, char *, char *);
204 208
 static int stop_forwarding_f(struct sip_msg *, char *, char *);
205 209
 static int play_media_f(struct sip_msg *, char *, char *);
... ...
@@ -355,6 +359,12 @@ static cmd_export_t cmds[] = {
355 359
 	{"unblock_media",	(cmd_function)unblock_media_f, 		0,
356 360
 		0, 0,
357 361
 		ANY_ROUTE},
362
+	{"silence_media",	(cmd_function)silence_media_f,	 	0,
363
+		0, 0,
364
+		ANY_ROUTE },
365
+	{"unsilence_media",	(cmd_function)unsilence_media_f, 	0,
366
+		0, 0,
367
+		ANY_ROUTE},
358 368
 	{"block_dtmf",		(cmd_function)block_dtmf_f,	 	1,
359 369
 		fixup_spve_null, 0,
360 370
 		ANY_ROUTE },
... ...
@@ -367,6 +377,12 @@ static cmd_export_t cmds[] = {
367 377
 	{"unblock_media",	(cmd_function)unblock_media_f, 		1,
368 378
 		fixup_spve_null, 0,
369 379
 		ANY_ROUTE},
380
+	{"silence_media",	(cmd_function)silence_media_f,	 	1,
381
+		fixup_spve_null, 0,
382
+		ANY_ROUTE },
383
+	{"unsilence_media",	(cmd_function)unsilence_media_f, 	1,
384
+		fixup_spve_null, 0,
385
+		ANY_ROUTE},
370 386
 	{"start_forwarding",	(cmd_function)start_forwarding_f,	0,
371 387
 		0, 0,
372 388
 		ANY_ROUTE },
... ...
@@ -2631,7 +2647,8 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2631 2647
 	bencode_list_add_string(item, ip_addr2a(&msg->rcv.src_ip));
2632 2648
 
2633 2649
 	if (op == OP_BLOCK_DTMF || op == OP_BLOCK_MEDIA || op == OP_UNBLOCK_DTMF
2634
-			|| op == OP_UNBLOCK_MEDIA || op == OP_START_FORWARDING || op == OP_STOP_FORWARDING)
2650
+			|| op == OP_UNBLOCK_MEDIA || op == OP_START_FORWARDING || op == OP_STOP_FORWARDING
2651
+			|| op == OP_SILENCE_MEDIA || op == OP_UNSILENCE_MEDIA)
2635 2652
 	{
2636 2653
 		if (ng_flags.directional)
2637 2654
 			bencode_dictionary_add_str(ng_flags.dict, "from-tag", &ng_flags.from_tag);
... ...
@@ -4018,6 +4035,18 @@ unblock_media_f(struct sip_msg* msg, char *str1, char *str2)
4018 4035
 	return rtpengine_generic_f(msg, str1, OP_UNBLOCK_MEDIA);
4019 4036
 }
4020 4037
 
4038
+static int
4039
+silence_media_f(struct sip_msg* msg, char *str1, char *str2)
4040
+{
4041
+	return rtpengine_generic_f(msg, str1, OP_SILENCE_MEDIA);
4042
+}
4043
+
4044
+static int
4045
+unsilence_media_f(struct sip_msg* msg, char *str1, char *str2)
4046
+{
4047
+	return rtpengine_generic_f(msg, str1, OP_UNSILENCE_MEDIA);
4048
+}
4049
+
4021 4050
 static int rtpengine_play_media(struct sip_msg *msg, void *d, int more, enum rtpe_operation op) {
4022 4051
 	bencode_buffer_t bencbuf;
4023 4052
 	long long duration;
... ...
@@ -4235,6 +4264,23 @@ static int ki_unblock_media(sip_msg_t *msg , str *flags)
4235 4264
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_UNBLOCK_MEDIA);
4236 4265
 }
4237 4266
 
4267
+static int ki_silence_media0(sip_msg_t *msg)
4268
+{
4269
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_SILENCE_MEDIA);
4270
+}
4271
+static int ki_silence_media(sip_msg_t *msg, str *flags)
4272
+{
4273
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_SILENCE_MEDIA);
4274
+}
4275
+static int ki_unsilence_media0(sip_msg_t *msg)
4276
+{
4277
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_UNSILENCE_MEDIA);
4278
+}
4279
+static int ki_unsilence_media(sip_msg_t *msg , str *flags)
4280
+{
4281
+	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, flags->s, 1, OP_UNSILENCE_MEDIA);
4282
+}
4283
+
4238 4284
 static int ki_block_dtmf0(sip_msg_t *msg)
4239 4285
 {
4240 4286
 	return rtpengine_rtpp_set_wrap(msg, rtpengine_simple_wrap, NULL, 1, OP_BLOCK_DTMF);
... ...
@@ -4403,6 +4449,27 @@ static sr_kemi_t sr_kemi_rtpengine_exports[] = {
4403 4449
             SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4404 4450
     },
4405 4451
 
4452
+	{ str_init("rtpengine"), str_init("silence_media0"),
4453
+        SR_KEMIP_INT, ki_silence_media0,
4454
+        { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
4455
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4456
+    },
4457
+    { str_init("rtpengine"), str_init("silence_media"),
4458
+        SR_KEMIP_INT, ki_silence_media,
4459
+        { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
4460
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4461
+    },
4462
+	{ str_init("rtpengine"), str_init("unsilence_media0"),
4463
+        SR_KEMIP_INT, ki_unsilence_media0,
4464
+        { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
4465
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4466
+    },
4467
+    { str_init("rtpengine"), str_init("unsilence_media"),
4468
+        SR_KEMIP_INT, ki_unsilence_media,
4469
+        { SR_KEMIP_STR, SR_KEMIP_NONE, SR_KEMIP_NONE,
4470
+            SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE }
4471
+    },
4472
+
4406 4473
 	{ str_init("rtpengine"), str_init("block_dtmf0"),
4407 4474
         SR_KEMIP_INT, ki_block_dtmf0,
4408 4475
         { SR_KEMIP_NONE, SR_KEMIP_NONE, SR_KEMIP_NONE,
Browse code

rtpengine: small debug log fix after merge of #2800

Henning Westerholt authored on 13/07/2021 13:04:10
Showing 1 changed files
... ...
@@ -3345,9 +3345,10 @@ select_rtpp_node(str callid, str viabranch, int do_test, struct rtpp_node **quer
3345 3345
 				node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
3346 3346
 			return node;
3347 3347
 		} else {
3348
-			LM_DBG("node=%.*s for calllen=%d callid=%.*s is disabled, either broke or timeout disabled! Return it\n",
3348
+			LM_DBG("node=%.*s for calllen=%d callid=%.*s is disabled, either broke or timeout disabled!\n",
3349 3349
 				node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
3350 3350
 			if (rtpengine_allow_op == 1) {
3351
+			        LM_DBG("Return it\n");
3351 3352
 				return node;
3352 3353
 			}
3353 3354
 		}
Browse code

rtpengine: add mode 2 for rtpengine_allow_op to return only manually disabled nodes

david authored on 13/07/2021 10:34:09 • Henning Westerholt committed on 13/07/2021 13:01:15
Showing 1 changed files
... ...
@@ -3347,8 +3347,10 @@ select_rtpp_node(str callid, str viabranch, int do_test, struct rtpp_node **quer
3347 3347
 		} else {
3348 3348
 			LM_DBG("node=%.*s for calllen=%d callid=%.*s is disabled, either broke or timeout disabled! Return it\n",
3349 3349
 				node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
3350
+			if (rtpengine_allow_op == 1) {
3351
+				return node;
3352
+			}
3350 3353
 		}
3351
-		/*return node;*/
3352 3354
 	}
3353 3355
 
3354 3356
 	return NULL;
Browse code

rtpengine: On rtpengine_allow_op, return node only if rtpengine is manually disabled

david authored on 12/07/2021 09:18:25 • Henning Westerholt committed on 13/07/2021 13:01:15
Showing 1 changed files
... ...
@@ -3343,11 +3343,12 @@ select_rtpp_node(str callid, str viabranch, int do_test, struct rtpp_node **quer
3343 3343
 		if (node->rn_recheck_ticks == RTPENGINE_MAX_RECHECK_TICKS) {
3344 3344
 			LM_DBG("node=%.*s for calllen=%d callid=%.*s is disabled(permanent) (probably still UP)! Return it\n",
3345 3345
 				node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
3346
+			return node;
3346 3347
 		} else {
3347 3348
 			LM_DBG("node=%.*s for calllen=%d callid=%.*s is disabled, either broke or timeout disabled! Return it\n",
3348 3349
 				node->rn_url.len, node->rn_url.s, callid.len, callid.len, callid.s);
3349 3350
 		}
3350
-		return node;
3351
+		/*return node;*/
3351 3352
 	}
3352 3353
 
3353 3354
 	return NULL;
Browse code

rtpengine: ignore mos 0 when selecting min-mos (#2771)

and computing average mos

Julien Chavanton authored on 10/06/2021 12:03:13 • GitHub committed on 10/06/2021 12:03:13
Showing 1 changed files
... ...
@@ -3588,13 +3588,15 @@ ssrc_ok:
3588 3588
 			continue;
3589 3589
 
3590 3590
 		if (decode_mos_vals_dict(&vals_decoded, ssrc_dict, "average MOS")) {
3591
-			average_vals.avg_samples++;
3592
-			average_vals.mos += vals_decoded.mos;
3593
-			average_vals.packetloss += vals_decoded.packetloss;
3594
-			average_vals.jitter += vals_decoded.jitter;
3595
-			average_vals.roundtrip += vals_decoded.roundtrip;
3596
-			average_vals.roundtrip_leg += vals_decoded.roundtrip_leg;
3597
-			average_vals.samples += vals_decoded.samples;
3591
+			if (vals_decoded.mos > 0) {
3592
+				average_vals.avg_samples++;
3593
+				average_vals.mos += vals_decoded.mos;
3594
+				average_vals.packetloss += vals_decoded.packetloss;
3595
+				average_vals.jitter += vals_decoded.jitter;
3596
+				average_vals.roundtrip += vals_decoded.roundtrip;
3597
+				average_vals.roundtrip_leg += vals_decoded.roundtrip_leg;
3598
+				average_vals.samples += vals_decoded.samples;
3599
+			}
3598 3600
 		}
3599 3601
 
3600 3602
 		if (decode_mos_vals_dict(&vals_decoded, ssrc_dict, "highest MOS")) {
... ...
@@ -3602,7 +3604,7 @@ ssrc_ok:
3602 3604
 				max_vals = vals_decoded;
3603 3605
 		}
3604 3606
 		if (decode_mos_vals_dict(&vals_decoded, ssrc_dict, "lowest MOS")) {
3605
-			if (vals_decoded.mos < min_vals.mos)
3607
+			if (vals_decoded.mos > 0 && vals_decoded.mos < min_vals.mos)
3606 3608
 				min_vals = vals_decoded;
3607 3609
 		}
3608 3610
 	}
Browse code

rtpengine: extract call-id/from-tag/to-tag only from sip messages

- they can be provided via flags in function parameters
- fix using functions in non-sip routing blocks (e.g., xhttp processing)

Daniel-Constantin Mierla authored on 30/04/2021 06:31:34
Showing 1 changed files
... ...
@@ -2477,17 +2477,19 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2477 2477
 
2478 2478
 	memset(&ng_flags, 0, sizeof(ng_flags));
2479 2479
 
2480
-	if (get_callid(msg, &ng_flags.call_id) == -1 || ng_flags.call_id.len == 0) {
2481
-		LM_ERR("can't get Call-Id field\n");
2482
-		return NULL;
2483
-	}
2484
-	if (get_to_tag(msg, &ng_flags.to_tag) == -1) {
2485
-		LM_ERR("can't get To tag\n");
2486
-		return NULL;
2487
-	}
2488
-	if (get_from_tag(msg, &ng_flags.from_tag) == -1 || ng_flags.from_tag.len == 0) {
2489
-		LM_ERR("can't get From tag\n");
2490
-		return NULL;
2480
+	if(IS_SIP(msg) || IS_SIP_REPLY(msg)) {
2481
+		if (get_callid(msg, &ng_flags.call_id) == -1 || ng_flags.call_id.len == 0) {
2482
+			LM_ERR("can't get Call-Id field\n");
2483
+			return NULL;
2484
+		}
2485
+		if (get_to_tag(msg, &ng_flags.to_tag) == -1) {
2486
+			LM_ERR("can't get To tag\n");
2487
+			return NULL;
2488
+		}
2489
+		if (get_from_tag(msg, &ng_flags.from_tag) == -1 || ng_flags.from_tag.len == 0) {
2490
+			LM_ERR("can't get From tag\n");
2491
+			return NULL;
2492
+		}
2491 2493
 	}
2492 2494
 	if (bencode_buffer_init(bencbuf)) {
2493 2495
 		LM_ERR("could not initialize bencode_buffer_t\n");
... ...
@@ -2535,6 +2537,18 @@ static bencode_item_t *rtpp_function_call(bencode_buffer_t *bencbuf, struct sip_
2535 2537
 	if (parse_flags(&ng_flags, msg, &op, flags_str))
2536 2538
 		goto error;
2537 2539
 
2540
+	if(!IS_SIP(msg) && !IS_SIP_REPLY(msg)) {
2541
+		/* check required values */
2542
+		if (ng_flags.call_id.len == 0) {
2543
+			LM_ERR("can't get Call-Id field\n");
2544
+			return NULL;
2545
+		}
2546
+		if (ng_flags.from_tag.len == 0) {
2547
+			LM_ERR("can't get From tag\n");
2548
+			return NULL;
2549
+		}
2550
+	}
2551
+
2538 2552
 	/* trickle ice sdp fragment? */
2539 2553
 	if (cont_type == 3)
2540 2554
 		bencode_list_add_string(ng_flags.flags, "fragment");
Browse code

rtpengine: add support for websocket protocol

Richard Fuchs authored on 24/03/2021 20:09:45
Showing 1 changed files
... ...
@@ -80,6 +80,7 @@
80 80
 #include "../../core/char_msg_val.h"
81 81
 #include "../../modules/tm/tm_load.h"
82 82
 #include "../../modules/crypto/api.h"
83
+#include "../../modules/lwsc/api.h"
83 84
 #include "rtpengine.h"
84 85
 #include "rtpengine_funcs.h"
85 86
 #include "rtpengine_hash.h"
... ...
@@ -300,7 +301,8 @@ static pv_spec_t *media_duration_pvar = NULL;
300 301
 char* force_send_ip_str="";
301 302
 int force_send_ip_af = AF_UNSPEC;
302 303
 
303
-
304
+static str _rtpe_wsapi = STR_NULL;
305
+lwsc_api_t _rtpe_lwscb = {0};
304 306
 
305 307
 static enum hash_algo_t hash_algo = RTP_HASH_CALLID;
306 308
 
... ...
@@ -525,6 +527,8 @@ static param_export_t params[] = {
525 527
 	{"mos_average_roundtrip_leg_B_pv",  PARAM_STR, &side_B_mos_stats.average.roundtrip_leg_param },
526 528
 	{"mos_average_samples_B_pv",    PARAM_STR, &side_B_mos_stats.average.samples_param     },
527 529
 
530
+	{"wsapi",                       PARAM_STR, &_rtpe_wsapi    },
531
+
528 532
 	{0, 0, 0}
529 533
 };
530 534
 
... ...
@@ -985,7 +989,7 @@ int add_rtpengine_socks(struct rtpp_set *rtpp_list, char *rtpengine,
985 989
 			pnode->rn_recheck_ticks = ticks + get_ticks();
986 990
 		}
987 991
 		pnode->rn_weight = local_weight;
988
-		pnode->rn_umode = 0;
992
+		pnode->rn_umode = RNU_UNKNOWN;
989 993
 		pnode->rn_disabled = disabled;
990 994
 		pnode->rn_displayed = 1;
991 995
 		pnode->rn_url.s = shm_malloc(p2 - p1 + 1);
... ...
@@ -1002,17 +1006,21 @@ int add_rtpengine_socks(struct rtpp_set *rtpp_list, char *rtpengine,
1002 1006
 		/* Leave only address in rn_address */
1003 1007
 		pnode->rn_address = pnode->rn_url.s;
1004 1008
 		if (strncasecmp(pnode->rn_address, "udp:", 4) == 0) {
1005
-			pnode->rn_umode = 1;
1009
+			pnode->rn_umode = RNU_UDP;
1006 1010
 			pnode->rn_address += 4;
1007 1011
 		} else if (strncasecmp(pnode->rn_address, "udp6:", 5) == 0) {
1008
-			pnode->rn_umode = 6;
1012
+			pnode->rn_umode = RNU_UDP6;
1009 1013
 			pnode->rn_address += 5;
1010 1014
 		} else if (strncasecmp(pnode->rn_address, "unix:", 5) == 0) {
1011
-			pnode->rn_umode = 0;
1015
+			pnode->rn_umode = RNU_LOCAL;
1012 1016
 			pnode->rn_address += 5;
1017
+		} else if (strncasecmp(pnode->rn_address, "ws://", 5) == 0) {
1018
+			pnode->rn_umode = RNU_WS;
1019
+		} else if (strncasecmp(pnode->rn_address, "wss://", 6) == 0) {
1020
+			pnode->rn_umode = RNU_WSS;
1013 1021
 		} else {
1014 1022
 			lock_release(rtpp_no_lock);
1015
-			LM_WARN("Node address must start with 'udp:' or 'udp6:' or 'unix:'. Ignore '%s'.\n", pnode->rn_address);
1023
+			LM_WARN("Node address must start with 'udp:' or 'udp6:' or 'unix:' or 'ws://' or 'wss://'. Ignore '%s'.\n", pnode->rn_address);
1016 1024
 			shm_free(pnode->rn_url.s);
1017 1025
 			shm_free(pnode);
1018 1026
 
... ...
@@ -1023,26 +1031,42 @@ int add_rtpengine_socks(struct rtpp_set *rtpp_list, char *rtpengine,
1023 1031
 			}
1024 1032
 		}
1025 1033
 
1026
-		/* Check the rn_address is 'hostname:port' */
1027
-		/* Check the rn_address port is valid */
1028
-		if(pnode->rn_umode == 6) {
1029
-                        p1 = strstr(pnode->rn_address, "]:");
1030
-                        if(p1 != NULL) {
1031
-                                p1++;
1032
-                        }
1033
-                } else {
1034
-                        p1 = strchr(pnode->rn_address, ':');
1035
-                }
1036
-		if (p1 != NULL) {
1037
-			p1++;
1038
-		}
1034
+		if (pnode->rn_umode != RNU_WS && pnode->rn_umode != RNU_WSS) {
1035
+			/* Check the rn_address is 'hostname:port' */
1036
+			/* Check the rn_address port is valid */
1037
+			if(pnode->rn_umode == RNU_UDP6) {
1038
+				p1 = strstr(pnode->rn_address, "]:");
1039
+				if(p1 != NULL) {
1040
+					p1++;
1041
+				}
1042
+			} else {
1043
+				p1 = strchr(pnode->rn_address, ':');
1044
+			}
1045
+			if (p1 != NULL) {
1046
+				p1++;
1047
+			}
1039 1048
 
1040
-		if (p1 != NULL && p1[0] != '\0') {
1041
-			s1.s = p1;
1042
-			s1.len = strlen(p1);
1043
-			if (str2int(&s1, &port) < 0 || port > 0xFFFF) {
1049
+			if (p1 != NULL && p1[0] != '\0') {
1050
+				s1.s = p1;
1051
+				s1.len = strlen(p1);
1052
+				if (str2int(&s1, &port) < 0 || port > 0xFFFF) {
1053
+					lock_release(rtpp_no_lock);
1054
+					LM_WARN("Node address must end with a valid port number. Ignore '%s'.\n", pnode->rn_address);
1055
+					shm_free(pnode->rn_url.s);
1056
+					shm_free(pnode);
1057
+
1058
+					if (!isDB) {
1059
+						continue;
1060
+					} else {
1061
+						return 0;
1062
+					}
1063
+				}
1064
+			}
1065
+		} else {
1066
+			/* websocket */
1067
+			if (_rtpe_lwscb.loaded == 0) {
1044 1068
 				lock_release(rtpp_no_lock);
1045
-				LM_WARN("Node address must end with a valid port number. Ignore '%s'.\n", pnode->rn_address);
1069
+				LM_WARN("Websocket protocol requested, but no websocket API loaded. Ignore '%s'.\n", pnode->rn_address);
1046 1070
 				shm_free(pnode->rn_url.s);
1047 1071
 				shm_free(pnode);
1048 1072
 
... ...
@@ -1607,6 +1631,19 @@ mod_init(void)
1607 1631
 		return -1;
1608 1632
 	}
1609 1633
 
1634
+	if(_rtpe_wsapi.s!=NULL && _rtpe_wsapi.len==4
1635
+			&& strncasecmp(_rtpe_wsapi.s, "lwsc", 4)==0) {
1636
+		if(lwsc_load_api(&_rtpe_lwscb)) {
1637
+			LM_ERR("failed to load WS API: %s\n", _rtpe_wsapi.s);
1638
+			return -1;
1639
+		}
1640
+	} else {
1641
+		if(_rtpe_wsapi.s!=NULL && _rtpe_wsapi.len>0) {
1642
+			LM_ERR("unsupported WS API: %s\n", _rtpe_wsapi.s);
1643
+			return -1;
1644
+		}
1645
+	}
1646
+
1610 1647
 	/* initialize the list of set; mod_destroy does shm_free() if fail */
1611 1648
 	if (!rtpp_set_list) {
1612 1649
 		rtpp_set_list = shm_malloc(sizeof(struct rtpp_set_head));
... ...
@@ -1831,7 +1868,8 @@ static int build_rtpp_socks(int lmode, int rtest) {
1831 1868
 			char *hostname;
1832 1869
 			char *hp;
1833 1870
 
1834
-			if (pnode->rn_umode == 0) {
1871
+			if (pnode->rn_umode == RNU_LOCAL || pnode->rn_umode == RNU_WS
1872
+					|| pnode->rn_umode == RNU_WSS) {
1835 1873
 				rtpp_socks[pnode->idx] = -1;
1836 1874
 				goto rptest;
1837 1875
 			}
... ...
@@ -1861,7 +1899,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
1861 1899
 			if (cp == NULL || *cp == '\0')
1862 1900
 				cp = CPORT;
1863 1901
 
1864
-			if(pnode->rn_umode == 6) {
1902
+			if(pnode->rn_umode == RNU_UDP6) {
1865 1903
 				hp = strrchr(hostname, ']');
1866 1904
 				if(hp != NULL)
1867 1905
 					*hp = '\0';
... ...
@@ -1875,7 +1913,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
1875 1913
 
1876 1914
 			memset(&hints, 0, sizeof(hints));
1877 1915
 			hints.ai_flags = 0;
1878
-			hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET;
1916
+			hints.ai_family = (pnode->rn_umode == RNU_UDP6) ? AF_INET6 : AF_INET;
1879 1917
 			hints.ai_socktype = SOCK_DGRAM;
1880 1918
 			if ((n = getaddrinfo(hp, cp, &hints, &res)) != 0) {
1881 1919
 				LM_ERR("%s\n", gai_strerror(n));
... ...
@@ -1890,7 +1928,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
1890 1928
 			}
1891 1929
 			pkg_free(hostname);
1892 1930
 
1893
-			rtpp_socks[pnode->idx] = socket((pnode->rn_umode == 6)
1931
+			rtpp_socks[pnode->idx] = socket((pnode->rn_umode == RNU_UDP6)
1894 1932
 				? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
1895 1933
 			if (rtpp_socks[pnode->idx] == -1) {
1896 1934
 				LM_ERR("can't create socket\n");
... ...
@@ -1912,7 +1950,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
1912 1950
 
1913 1951
 			if((0 <= control_cmd_tos) && (control_cmd_tos < 256)) {
1914 1952
 				unsigned char tos = control_cmd_tos;
1915
-				if (pnode->rn_umode == 6) {
1953
+				if (pnode->rn_umode == RNU_UDP6) {
1916 1954
 					if(setsockopt(rtpp_socks[pnode->idx], IPPROTO_IPV6,
1917 1955
 							IPV6_TCLASS, &control_cmd_tos,
1918 1956
 							sizeof(control_cmd_tos)))
... ...
@@ -2865,10 +2903,12 @@ send_rtpp_command(struct rtpp_node *node, bencode_item_t *dict, int *outlen)
2865 2903
 	int fd, len, i, vcnt;
2866 2904
 	int rtpengine_retr, rtpengine_tout_ms = 1000;
2867 2905
 	char *cp;
2868
-	static char buf[0x10000];
2906
+	static char buf[0x40000];
2869 2907
 	struct pollfd fds[1];
2870 2908
 	struct iovec *v;
2871 2909
 	str cmd = STR_NULL;
2910
+	const static str rtpe_proto = { "ng.rtpengine.com", 16 };
2911
+	str request, response;
2872 2912
 
2873 2913
 	v = bencode_iovec(dict, &vcnt, 1, 0);
2874 2914
 	if (!v) {
... ...
@@ -2878,7 +2918,9 @@ send_rtpp_command(struct rtpp_node *node, bencode_item_t *dict, int *outlen)
2878 2918
 
2879 2919
 	len = 0;
2880 2920
 	cp = buf;
2881
-	if (node->rn_umode == 0) {
2921
+	rtpengine_tout_ms = cfg_get(rtpengine,rtpengine_cfg,rtpengine_tout_ms);
2922
+
2923
+	if (node->rn_umode == RNU_LOCAL) {
2882 2924
 		memset(&addr, 0, sizeof(addr));
2883 2925
 		addr.sun_family = AF_LOCAL;
2884 2926
 		strncpy(addr.sun_path, node->rn_address,
... ...
@@ -2914,7 +2956,55 @@ send_rtpp_command(struct rtpp_node *node, bencode_item_t *dict, int *outlen)
2914 2956
 			LM_ERR("can't read reply from RTPEngine <%s>\n", node->rn_url.s);
2915 2957
 			goto badproxy;
2916 2958
 		}
2959
+	} else if (node->rn_umode == RNU_WS || node->rn_umode == RNU_WSS) {
2960
+		/* assemble full request string, flatten iovec */
2961
+		v[0].iov_base = gencookie();
2962
+		v[0].iov_len = strlen(v[0].iov_base);
2963
+		len = 0;
2964
+		for (i = 0; i <= vcnt; i++)
2965
+			len += v[i].iov_len;
2966
+		request.s = pkg_malloc(len + 1);
2967
+		if (!request.s) {
2968
+			LM_ERR("out of memory\n");
2969
+			goto badproxy;
2970
+		}
2971
+		len = 0;
2972
+		for (i = 0; i <= vcnt; i++) {
2973
+			memcpy(request.s + len, v[i].iov_base, v[i].iov_len);
2974
+			len += v[i].iov_len;
2975
+		}
2976
+		request.s[len] = '\0';
2977
+		request.len = len;
2978
+
2979
+		len = _rtpe_lwscb.request(&node->rn_url, (str *) &rtpe_proto, &request, &response,
2980
+				rtpengine_tout_ms * 1000);
2981
+
2982
+		if (len < 0) {
2983
+			LM_ERR("failed to do websocket request\n");
2984
+			goto badproxy;
2985
+		}
2986
+
2987
+		/* process/copy response; verify cookie */
2988
+		if (response.len < v[0].iov_len) {
2989
+			LM_ERR("empty or short websocket response\n");
2990
+			pkg_free(response.s);
2991
+			goto badproxy;
2992
+		}
2993
+		if (memcmp(response.s, v[0].iov_base, v[0].iov_len)) {
2994
+			LM_ERR("mismatched cookie in websocket response\n");
2995
+			pkg_free(response.s);
2996
+			goto badproxy;
2997
+		}
2998
+		len = response.len - v[0].iov_len;
2999
+		if (len >= sizeof(buf)) {
3000
+			LM_ERR("websocket response too large\n");
3001
+			pkg_free(response.s);
3002
+			goto badproxy;
3003
+		}
3004
+		memcpy(buf, response.s + v[0].iov_len, len);
3005
+		pkg_free(response.s);
2917 3006
 	} else {
3007
+		/* UDP or UDP6 */
2918 3008
 		fds[0].fd = rtpp_socks[node->idx];
2919 3009
 		fds[0].events = POLLIN;
2920 3010
 		fds[0].revents = 0;
... ...
@@ -2938,7 +3028,6 @@ send_rtpp_command(struct rtpp_node *node, bencode_item_t *dict, int *outlen)
2938 3028
 					cmd.len, cmd.s, node->rn_url.s);
2939 3029
 				goto badproxy;
2940 3030
 			}
2941
-			rtpengine_tout_ms = cfg_get(rtpengine,rtpengine_cfg,rtpengine_tout_ms);
2942 3031
 			while ((poll(fds, 1, rtpengine_tout_ms) == 1) &&
2943 3032
 				(fds[0].revents & POLLIN) != 0) {
2944 3033
 				do {
Browse code

rtpengine: remove square brackets from IPv6 address for getaddrinfo function

- After loading from DB rn_address is in form: [x:x:x:x:x:x:x:x]:nnnn, getaddrinfo function expect ipv6 in node argument without square brackets, otherwise, the argument is interpreted as FQDN.

Dennis Yurasov authored on 21/03/2021 14:45:04 • Daniel-Constantin Mierla committed on 22/03/2021 14:42:16
Showing 1 changed files
... ...
@@ -1829,6 +1829,7 @@ static int build_rtpp_socks(int lmode, int rtest) {
1829 1829
 		rtpe_reload_lock_get(rtpp_list->rset_lock);
1830 1830
 		for (pnode=rtpp_list->rn_first; pnode!=0; pnode = pnode->rn_next) {
1831 1831
 			char *hostname;
1832
+			char *hp;
1832 1833
 
1833 1834
 			if (pnode->rn_umode == 0) {
1834 1835
 				rtpp_socks[pnode->idx] = -1;
... ...
@@ -1860,11 +1861,23 @@ static int build_rtpp_socks(int lmode, int rtest) {
1860 1861
 			if (cp == NULL || *cp == '\0')
1861 1862
 				cp = CPORT;
1862 1863
 
1864
+			if(pnode->rn_umode == 6) {
1865
+				hp = strrchr(hostname, ']');
1866
+				if(hp != NULL)
1867
+					*hp = '\0';
1868
+
1869
+				hp = hostname;
1870
+				if(*hp == '[')
1871
+					hp++;
1872
+			} else {
1873
+				hp = hostname;
1874
+			}
1875
+
1863 1876
 			memset(&hints, 0, sizeof(hints));
1864 1877
 			hints.ai_flags = 0;
1865 1878
 			hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET;
1866 1879
 			hints.ai_socktype = SOCK_DGRAM;