Skip to content

Commit 16819f4

Browse files
sobomaxrazvancrainea
authored andcommitted
rtp.io: integrate notification channel
Allocate a single notification socketpair to be shared by all opensips workers, pass one side to the hosted rtpproxy process and provide API for the rtpproxy module to tap into the other end.
1 parent d3731a5 commit 16819f4

6 files changed

Lines changed: 85 additions & 6 deletions

File tree

modules/rtp.io/rtp_io.c

Lines changed: 44 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,8 @@
2929
#include "../../dprint.h"
3030
#include "../../timer.h"
3131

32+
#include "../rtpproxy/rtpproxy.h"
33+
#include "../rtpproxy/notification_process.h"
3234
#include "rtp_io.h"
3335
#include "rtp_io_util.h"
3436
#include "rtp_io_params.h"
@@ -40,7 +42,7 @@ static void mod_destroy(void);
4042

4143
static const dep_export_t deps = {
4244
{ /* OpenSIPS module dependencies */
43-
{ MOD_TYPE_DEFAULT, "rtpproxy", DEP_SILENT|DEP_REVERSE },
45+
{ MOD_TYPE_DEFAULT, "rtpproxy", (DEP_SILENT|DEP_REVERSE) & (~DEP_REVERSE_CINIT) },
4446
{ MOD_TYPE_NULL, NULL, 0 },
4547
},
4648
{ /* modparam dependencies */
@@ -49,12 +51,14 @@ static const dep_export_t deps = {
4951
};
5052

5153
static int rtp_io_getchildsock(int);
54+
static int rtp_io_getrnsock(struct rtpp_notify_cfg *);
5255

5356
/*
5457
* Exported functions
5558
*/
5659
static const cmd_export_t cmds[] = {
5760
{"rtp_io_getchildsock", (cmd_function)rtp_io_getchildsock, {0}, 0},
61+
{"rtp_io_getrnsock", (cmd_function)rtp_io_getrnsock, {0}, 0},
5862
{0}
5963
};
6064

@@ -162,17 +166,29 @@ static int mod_init(void)
162166
ENV_ADD(argv_stat[i], e1);
163167
}
164168

169+
struct rtpp_n_sock *n_sock = &rpi_descp->n_sock;
170+
int *fdp = n_sock->_fds;
171+
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fdp) < 0)
172+
goto e1;
173+
snprintf(n_sock->_name, sizeof(n_sock->_name), "fd:%d", n_sock->fds.rtpp);
174+
n_sock->name.s = n_sock->_name;
175+
n_sock->name.len = strlen(n_sock->_name);
176+
ENV_ADD("-n", e2);
177+
ENV_ADD("%s", e2, n_sock->name.s);
165178
for (int i = 0; i < nsocks; i++) {
166179
int *fdp = &rpi_descp->socks->holder[i * 2];
167180
if (socketpair(AF_UNIX, SOCK_STREAM, 0, fdp) < 0)
168-
goto e1;
169-
ENV_ADD("-s", e1);
170-
ENV_ADD("fd:%d", e1, fdp[0]);
181+
goto e2;
182+
ENV_ADD("-s", e2);
183+
ENV_ADD("fd:%d", e2, fdp[0]);
171184
}
172185

173186
rpi_descp->socks->n = nsocks;
174187

175188
return 0;
189+
e2:
190+
close(n_sock->_fds[0]);
191+
close(n_sock->_fds[1]);
176192
e1:
177193
free(rpi_descp->socks);
178194
e0:
@@ -198,6 +214,7 @@ void mod_destroy(void)
198214
}
199215
rtp_io_close_serv_socks();
200216
rtp_io_close_cnlt_socks();
217+
rtp_io_close_cnlt_nsock();
201218
free(rpi_descp->socks);
202219
}
203220

@@ -206,11 +223,25 @@ void mod_destroy(void)
206223
static int
207224
child_init(int rank)
208225
{
226+
rtpproxy_is_nproc_t is_nproc_f;
227+
228+
is_nproc_f = (rtpproxy_is_nproc_t)find_export("rtpproxy_is_nproc", 0);
229+
if (is_nproc_f == NULL) {
230+
LM_ERR("rtpproxy_is_nproc() not found in the rtpproxy module\n");
231+
return -1;
232+
}
233+
int is_nproc = is_nproc_f(NPROC_CHECK);
234+
LM_DBG("rtp.io: child_init(%d), notifier: %d\n", rank, is_nproc);
209235
if (rank > rpi_descp->socks->n) {
210236
LM_ERR("BUG: rank is higher than the number of sockets!\n");
211237
return -1;
212238
}
213239

240+
if (!is_nproc && rtp_io_close_cnlt_nsock() != 0) {
241+
LM_ERR("rtp_io_close_cnlt_nsock() failed\n");
242+
return -1;
243+
}
244+
214245
if (rank <= 0) {
215246
if (rtp_io_close_cnlt_socks() != 0) {
216247
LM_ERR("rtp_io_close_cnlt_socks() failed\n");
@@ -240,3 +271,12 @@ static int rtp_io_getchildsock(int rank)
240271
int *fdp = &rpi_descp->socks->holder[(rank - 1) * 2];
241272
return (fdp[1]);
242273
}
274+
275+
static int rtp_io_getrnsock(struct rtpp_notify_cfg *rn_cfg)
276+
{
277+
278+
rn_cfg->name = rpi_descp->n_sock.name;
279+
rn_cfg->sock.rn_umode = CM_RTPIO;
280+
rn_cfg->sock.fd = rpi_descp->n_sock.fds.osips;
281+
return (0);
282+
};

modules/rtp.io/rtp_io.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,23 @@ struct rtp_io_socks {
2525
int holder[];
2626
};
2727

28+
struct rtpp_n_sock {
29+
char _name[32];
30+
str name;
31+
union {
32+
struct {
33+
int rtpp;
34+
int osips;
35+
} fds;
36+
int _fds[2];
37+
};
38+
};
39+
2840
struct rtp_io_desc {
2941
struct rtpp_cfg *rtpp_cfsp;
3042
struct rtpp_env_hd env;
3143
struct rtp_io_socks *socks;
44+
struct rtpp_n_sock n_sock;
3245
};
3346

3447
extern struct rtp_io_desc *rpi_descp;

modules/rtp.io/rtp_io_api.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
11
#pragma once
22

3+
struct rtpp_notify_cfg;
4+
35
typedef int (*rtp_io_getchildsock_t)(int);
6+
typedef int (*rtp_io_getrnsock_t)(struct rtpp_notify_cfg *);

modules/rtp.io/rtp_io_host.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,8 @@ void rtpproxy_host_process(int rank)
7272
goto e1;
7373
if (rtp_io_close_cnlt_socks() != 0)
7474
goto e1;
75+
if (rtp_io_close_cnlt_nsock() != 0)
76+
goto e1;
7577

7678
OPT_RESTORE();
7779
rpi_descp->rtpp_cfsp = rtpp_main(argc, argv);
@@ -101,5 +103,8 @@ ipc_shutdown_rtpp_host(int sender, void *param)
101103
if (rpi_descp->socks->holder[i] != -1)
102104
close(rpi_descp->socks->holder[i]);
103105
}
106+
if (rpi_descp->n_sock.fds.rtpp != -1) {
107+
close(rpi_descp->n_sock.fds.rtpp);
108+
}
104109
free(rpi_descp->socks);
105110
}

modules/rtp.io/rtp_io_util.c

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,19 +85,36 @@ int rtp_io_close_serv_socks(void)
8585

8686
for (int i = 0; i < (rpi_descp->socks->n * 2); i+=2) {
8787
if (rpi_descp->socks->holder[i] != -1) {
88-
close(rpi_descp->socks->holder[i]);
88+
if (close(rpi_descp->socks->holder[i]) != 0)
89+
return -1;
8990
rpi_descp->socks->holder[i] = -1;
9091
}
9192
}
93+
if (rpi_descp->n_sock.fds.rtpp != -1) {
94+
if (close(rpi_descp->n_sock.fds.rtpp) != 0)
95+
return -1;
96+
rpi_descp->n_sock.fds.rtpp = -1;
97+
}
9298
return (0);
9399
}
94100

101+
int rtp_io_close_cnlt_nsock(void)
102+
{
103+
if (rpi_descp->n_sock.fds.osips != -1) {
104+
if (close(rpi_descp->n_sock.fds.osips) != 0)
105+
return -1;
106+
rpi_descp->n_sock.fds.osips = -1;
107+
}
108+
return 0;
109+
}
110+
95111
int rtp_io_close_cnlt_socks(void)
96112
{
97113

98114
for (int i = 0; i < (rpi_descp->socks->n * 2); i+=2) {
99115
if (rpi_descp->socks->holder[i+1] != -1) {
100-
close(rpi_descp->socks->holder[i+1]);
116+
if (close(rpi_descp->socks->holder[i+1]) != 0)
117+
return -1;
101118
rpi_descp->socks->holder[i+1] = -1;
102119
}
103120
}

modules/rtp.io/rtp_io_util.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,3 +11,4 @@ const char *const * rtp_io_env_gen_argv(struct rtpp_env_hd *, int *);
1111

1212
int rtp_io_close_serv_socks(void);
1313
int rtp_io_close_cnlt_socks(void);
14+
int rtp_io_close_cnlt_nsock(void);

0 commit comments

Comments
 (0)