Skip to content

Commit 271eed5

Browse files
committed
rtpproxy: hook up notification socket into rtp.io automatically when
rtp.io is enabled. Start notification listener process always, turn it into dummy if rtp.io is not enabled and notification socket is not configured either. WiP.
1 parent 16134b3 commit 271eed5

File tree

3 files changed

+76
-27
lines changed

3 files changed

+76
-27
lines changed

modules/rtpproxy/notification_process.c

Lines changed: 63 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,26 @@ int init_rtpp_notify(void)
325325
return 0;
326326
}
327327

328+
static rtp_io_getrnsock_t
329+
rtp_io_rnsock_f(void)
330+
{
331+
static rtp_io_getrnsock_t _rtp_io_getrnsock = {0};
332+
if (_rtp_io_getrnsock == NULL)
333+
_rtp_io_getrnsock = (rtp_io_getrnsock_t)find_export("rtp_io_getrnsock", 0);
334+
return _rtp_io_getrnsock;
335+
}
336+
337+
int fill_rtp_io_rnsock(void)
338+
{
339+
340+
rtp_io_getrnsock_t rtp_io_rnsock = rtp_io_rnsock_f();
341+
if (rtp_io_rnsock == NULL)
342+
return -1;
343+
if (rtp_io_rnsock(&rtpp_notify_cfg) != 0)
344+
return -1;
345+
return 0;
346+
}
347+
328348
void notification_listener_process(int rank)
329349
{
330350
struct sockaddr_un saddr_un;
@@ -335,12 +355,19 @@ void notification_listener_process(int rank)
335355
struct sockaddr* saddr;
336356
int len, n;
337357
int optval = 1;
338-
int socket_fd;
358+
int socket_fd = -1;
339359
str *rn_name = &rtpp_notify_cfg.name;
360+
struct rtpp_sock *rn_sock = &rtpp_notify_cfg.sock;
361+
362+
if (rn_name->s == NULL) {
363+
if (fill_rtp_io_rnsock() != 0)
364+
goto serve;
365+
}
340366

341367
*rtpp_notify_process_no = process_no;
342368

343-
if (rtpp_notify_cfg.sock.rn_umode == CM_TCP) {
369+
switch (rn_sock->rn_umode) {
370+
case CM_TCP:
344371
p = strrchr(rn_name->s, ':');
345372
if (!p) {
346373
LM_ERR("invalid udp address <%.*s>\n", rn_name->len, rn_name->s);
@@ -371,7 +398,8 @@ void notification_listener_process(int rank)
371398
saddr = (struct sockaddr*)&saddr_in;
372399
len = sizeof(saddr_in);
373400
LM_DBG("binding socket %d to %s:%d\n", socket_fd, rn_name->s, port);
374-
} else {
401+
break;
402+
case CM_UNIX:
375403
/* create socket */
376404
socket_fd = socket(AF_UNIX, SOCK_STREAM, 0);
377405
if (socket_fd == -1) {
@@ -386,34 +414,50 @@ void notification_listener_process(int rank)
386414
saddr = (struct sockaddr*)&saddr_un;
387415
len = sizeof(saddr_un);
388416
LM_DBG("binding unix socket %s\n", rn_name->s);
417+
break;
418+
case CM_RTPIO:
419+
socket_fd = rn_sock->fd;
420+
len = -1;
421+
saddr = NULL;
422+
LM_DBG("using rtp.io notification socket %d\n", socket_fd);
423+
break;
424+
default:
425+
abort();
389426
}
390427

391-
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval,
428+
if (rn_sock->rn_umode != CM_RTPIO) {
429+
if (setsockopt(socket_fd, SOL_SOCKET, SO_REUSEADDR, (void*)&optval,
392430
sizeof(optval)) == -1) {
393-
LM_ERR("setsockopt failed %s\n", strerror(errno));
394-
return;
395-
}
431+
LM_ERR("setsockopt failed %s\n", strerror(errno));
432+
return;
433+
}
396434

397-
if (bind(socket_fd, saddr, len) == -1) {
398-
LM_ERR("failed to bind to socket: %s\n", strerror(errno));
399-
return;
400-
}
435+
if (bind(socket_fd, saddr, len) == -1) {
436+
LM_ERR("failed to bind to socket: %s\n", strerror(errno));
437+
return;
438+
}
401439

402-
/* open socket for listening */
403-
if(listen(socket_fd, 10) == -1) {
404-
LM_ERR("socket listen failed: %s(%d)\n", strerror(errno), errno);
405-
close(socket_fd);
406-
return;
440+
/* open socket for listening */
441+
if(listen(socket_fd, 10) == -1) {
442+
LM_ERR("socket listen failed: %s(%d)\n", strerror(errno), errno);
443+
close(socket_fd);
444+
return;
445+
}
407446
}
408447

448+
serve:
409449
if (reactor_proc_init("RTPProxy events") < 0) {
410450
LM_ERR("failed to init the RTPProxy events\n");
411451
return;
412452
}
413453

414-
if (reactor_proc_add_fd( socket_fd, rtpproxy_io_new_callback, NULL) < 0) {
415-
LM_CRIT("failed to add RTPProxy listen socket to reactor\n");
416-
return;
454+
if (socket_fd != -1) {
455+
reactor_proc_cb_f cb_f = (rn_sock->rn_umode != CM_RTPIO) ? rtpproxy_io_new_callback :
456+
rtpproxy_io_callback;
457+
if (reactor_proc_add_fd(socket_fd, cb_f, NULL) < 0) {
458+
LM_CRIT("failed to add RTPProxy listen socket to reactor\n");
459+
return;
460+
}
417461
}
418462

419463
reactor_proc_loop();

modules/rtpproxy/rtpproxy.c

Lines changed: 11 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,6 @@
188188
#include "rtpproxy_vcmd.h"
189189
#include "rtppn_connect.h"
190190
#include "../rtp_relay/rtp_relay.h"
191-
#include "../rtp.io/rtp_io_api.h"
192191

193192
#define NH_TABLE_VERSION 0
194193

@@ -568,7 +567,7 @@ struct module_exports exports = {
568567
mi_cmds, /* exported MI functions */
569568
0, /* exported pseudo-variables */
570569
0, /* exported transformations */
571-
0, /* extra processes */
570+
procs, /* extra processes */
572571
mod_preinit,
573572
mod_init,
574573
0, /* reply processing */
@@ -634,8 +633,6 @@ static int rtpproxy_set_notify(modparam_t type, void * val)
634633
rtpp_notify_cfg.name.s = p;
635634
rtpp_notify_cfg.name.len = strlen(p);
636635

637-
exports.procs = procs;
638-
639636
return 0;
640637
}
641638

@@ -1310,11 +1307,11 @@ mod_init(void)
13101307
" timeout notification feature\n");
13111308
return -1;
13121309
}
1310+
}
13131311

1314-
if (init_rtpp_notify() < 0) {
1315-
LM_ERR("cannot init notify handlers\n");
1316-
return -1;
1317-
}
1312+
if (init_rtpp_notify() < 0) {
1313+
LM_ERR("cannot init notify handlers\n");
1314+
return -1;
13181315
}
13191316

13201317
ei_id = evi_publish_event(event_name);
@@ -1542,6 +1539,12 @@ int connect_rtpproxies(struct rtpp_set *filter)
15421539
LM_ERR("rtp.io is not loaded\n");
15431540
return -1;
15441541
}
1542+
if (rtpp_notify_cfg.name.s == NULL) {
1543+
if (fill_rtp_io_rnsock() != 0) {
1544+
LM_ERR("rtp.io notification socket cannot be initialized\n");
1545+
return -1;
1546+
}
1547+
}
15451548
rtpp_socks[pnode->idx].fd = gcs_f(myrank);
15461549
}
15471550
break;

modules/rtpproxy/rtpproxy.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
#include "../../pvar.h"
3131
#include "../dialog/dlg_load.h"
3232
#include "../../rw_locking.h"
33+
#include "../rtp.io/rtp_io_api.h"
3334

3435
struct rtpproxy_vcmd;
3536

@@ -168,6 +169,7 @@ extern struct rtpp_set_head ** rtpp_set_list;
168169
int init_rtpp_notify();
169170
void update_rtpp_notify();
170171
void notification_listener_process(int rank);
172+
int fill_rtp_io_rnsock(void);
171173

172174
/* Functions from nathelper */
173175
struct rtpp_set *get_rtpp_set(nh_set_param_t *);

0 commit comments

Comments
 (0)