Skip to content

Commit 880c899

Browse files
committed
Add "S[r] ttl=XXX" and "S[r] tos=XXX" sub-commands.
PR: #59
1 parent 1fa3ac9 commit 880c899

18 files changed

+278
-17
lines changed

modules/dtls_gw/rtpp_dtls_gw.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,8 @@ rtpp_dtls_gw_setup_sender(struct rtpp_module_priv *pvt,
248248
abort();
249249
}
250250

251-
if (rtpp_create_listener(pvt->cfsp, dtls_strmp->laddr, &lport, fds) == -1)
251+
if (rtpp_create_listener(pvt->cfsp, dtls_strmp->laddr, &lport, fds,
252+
dtls_strmp->tos) == -1)
252253
return (-1);
253254
CALL_SMETHOD(pvt->cfsp->sessinfo, append, spa, sidx, fds);
254255
CALL_METHOD(pvt->cfsp->rtpp_proc_cf, nudge);

src/Makefile.am

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,8 @@ BASE_SOURCES=main.c rtp.h rtpp_server.c \
7575
$(CMDSRCDIR)/rpcpv1_norecord.c $(CMDSRCDIR)/rpcpv1_norecord.h \
7676
$(CMDSRCDIR)/rpcpv1_ul_subc.c $(CMDSRCDIR)/rpcpv1_ul_subc.h \
7777
$(RTPP_AUTOSRC_SOURCES) rtpp_epoll.c rtpp_str.c rtpp_str.h \
78-
rtpp_sbuf.c rtpp_sbuf.h rtpp_refproxy.c rtpp_command_reply.c
78+
rtpp_sbuf.c rtpp_sbuf.h rtpp_refproxy.c rtpp_command_reply.c \
79+
$(CMDSRCDIR)/rpcpv1_ul_subc_set.c $(CMDSRCDIR)/rpcpv1_ul_subc_set.h
7980
BASE_SOURCES+=$(ADV_DIR)/packet_observer.h $(ADV_DIR)/pproc_manager.c \
8081
$(ADV_DIR)/pproc_manager.h
8182
BASE_SOURCES+=rtpp_modman.c rtpp_module_if_static.c rtpp_module_if_static.h

src/commands/rpcpv1_copy.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ get_args4remote(const struct rtpp_cfg *cfsp, const char *rname, struct rtpp_log
8080
if (laddr == NULL)
8181
return (-1);
8282
int lport;
83-
if (rtpp_create_listener(cfsp, laddr, &lport, fds) != 0) {
83+
if (rtpp_create_listener(cfsp, laddr, &lport, fds, ap->tos) != 0) {
8484
RTPP_LOG(log, RTPP_LOG_ERR, "can't create listener");
8585
return (-1);
8686
}
@@ -97,7 +97,6 @@ handle_copy(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, struct rtpp_s
9797
int idx, const char *rname, const struct record_opts *rop)
9898
{
9999
int remote;
100-
struct remote_copy_args rargs = {0};
101100

102101
remote = (rname != NULL && strncmp("udp:", rname, 4) == 0)? 1 : 0;
103102

@@ -134,9 +133,11 @@ handle_copy(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, struct rtpp_s
134133
}
135134

136135
int rval = -1;
137-
if (remote)
136+
struct remote_copy_args rargs = {.tos = spa->rtp->stream[idx]->tos};
137+
if (remote) {
138138
if (get_args4remote(cfsp, rname, spa->log, &rargs) != 0)
139139
return (-1);
140+
}
140141

141142
if (spa->rtp->stream[idx]->rrc == NULL) {
142143
spa->rtp->stream[idx]->rrc = rtpp_record_ctor(cfsp, &rargs, spa, rname, idx, RECORD_RTP);

src/commands/rpcpv1_query.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -260,7 +260,8 @@ handle_query(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd,
260260
.strmp_in = spp->stream[idx],
261261
.strmp_out = spp->stream[NOT(idx)],
262262
.subc_args = &(cmd->subc.args[i]),
263-
.resp = &(cmd->subc.res[i])
263+
.resp = &(cmd->subc.res[i]),
264+
.log = spp->log,
264265
};
265266
rsc.resp->result = cmd->after_success[i].handler(
266267
&cmd->after_success[i].args, &rsc);

src/commands/rpcpv1_ul.c

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -448,6 +448,7 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
448448
struct rtpp_session *spa, *spb;
449449
struct rtpp_socket *fd;
450450
struct ul_opts *ulop;
451+
int desired_tos;
451452

452453
pidx = 1;
453454
lport = 0;
@@ -466,14 +467,16 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
466467
if (sidx != -1) {
467468
RTPP_DBG_ASSERT(cmd->cca.op == UPDATE || cmd->cca.op == LOOKUP);
468469
spa = cmd->sp;
470+
desired_tos = spa->rtp->stream[sidx]->tos;
469471
fd = CALL_SMETHOD(spa->rtp->stream[sidx], get_skt, HEREVAL);
470472
if (fd == NULL || ulop->new_port != 0) {
471473
if (ulop->local_addr != NULL) {
472474
spa->rtp->stream[sidx]->laddr = ulop->local_addr;
473475
} else if (ulop->new_port != 0 && ulop->lidx == -1 && spa->rtp->stream[sidx]->laddr != ulop->lia[0]) {
474476
spa->rtp->stream[sidx]->laddr = ulop->lia[0];
475477
}
476-
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds) == -1) {
478+
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds,
479+
desired_tos) == -1) {
477480
if (fd != NULL)
478481
RTPP_OBJ_DECREF(fd);
479482
RTPP_LOG(spa->log, RTPP_LOG_ERR, "can't create listener");
@@ -496,9 +499,9 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
496499
if (spa->complete == 0) {
497500
rtpp_command_get_stats(cmd)->nsess_complete.cnt++;
498501
CALL_SMETHOD(spa->rtp->stream[0]->ttl, reset_with,
499-
cfsp->max_ttl);
502+
spa->rtp->stream[0]->stream_ttl);
500503
CALL_SMETHOD(spa->rtp->stream[1]->ttl, reset_with,
501-
cfsp->max_ttl);
504+
spa->rtp->stream[1]->stream_ttl);
502505
}
503506
spa->complete = 1;
504507
}
@@ -698,7 +701,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
698701
.strmp_in = spa->rtp->stream[pidx],
699702
.strmp_out = spa->rtp->stream[NOT(pidx)],
700703
.subc_args = &(cmd->subc.args[i]),
701-
.resp = &(cmd->subc.res[i])
704+
.resp = &(cmd->subc.res[i]),
705+
.log = spa->log,
702706
};
703707
rsc.resp->result = cmd->after_success[i].handler(
704708
&cmd->after_success[i].args, &rsc);

src/commands/rpcpv1_ul_subc.c

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright (c) 2006-2020 Sippy Software, Inc., http://www.sippysoft.com
2+
* Copyright (c) 2006-2025 Sippy Software, Inc., http://www.sippysoft.com
33
*
44
* Redistribution and use in source and binary forms, with or without
55
* modification, are permitted provided that the following conditions
@@ -45,6 +45,7 @@
4545
#include "commands/rpcpv1_ul.h"
4646
#include "commands/rpcpv1_ul_subc.h"
4747
#include "commands/rpcpv1_delete.h"
48+
#include "commands/rpcpv1_ul_subc_set.h"
4849

4950
#if ENABLE_MODULE_IF
5051
static int
@@ -72,6 +73,7 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *
7273
const struct rtpp_command_args *subc_args, struct after_success_h *asp)
7374
{
7475
struct delete_opts *dop;
76+
struct rtpp_subcommand_set *sop;
7577

7678
switch(subc_args->v[0].s[0]) {
7779
case 'M':
@@ -98,6 +100,17 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *
98100
asp->handler = handle_delete_as_subc;
99101
break;
100102

103+
case 'S':
104+
case 's':
105+
if (subc_args->c != 2 || subc_args->v[0].len < 1 || subc_args->v[0].len > 2)
106+
return (-1);
107+
sop = handle_set_subc_parse(cfsp, &subc_args->v[0].s[1], &subc_args->v[1], asp);
108+
if (sop == NULL)
109+
return (-1);
110+
asp->args.dyn = sop;
111+
RTPP_OBJ_DTOR_ATTACH_OBJ(cmd, sop);
112+
break;
113+
101114
default:
102115
return (-1);
103116
}

src/commands/rpcpv1_ul_subc_set.c

Lines changed: 152 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,152 @@
1+
/*
2+
* Copyright (c) 2025 Sippy Software, Inc., http://www.sippysoft.com
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23+
* SUCH DAMAGE.
24+
*
25+
*/
26+
27+
#include <sys/socket.h>
28+
#include <stddef.h>
29+
#include <stdint.h>
30+
#include <stdlib.h>
31+
#include <string.h>
32+
33+
#include "config.h"
34+
35+
#include "rtpp_codeptr.h"
36+
#include "rtpp_types.h"
37+
#include "rtpp_refcnt.h"
38+
#include "rtpp_log.h"
39+
#include "rtpp_log_obj.h"
40+
#include "rtpp_pipe.h"
41+
#include "rtpp_socket.h"
42+
#include "rtpp_session.h"
43+
#include "rtpp_stream.h"
44+
#include "rtpp_ttl.h"
45+
#include "rtpp_command.h"
46+
#include "rtpp_command_sub.h"
47+
#include "rtpp_command_args.h"
48+
#include "rtpp_command_private.h"
49+
#include "rtpp_mallocs.h"
50+
#include "rtpp_util.h"
51+
#include "commands/rpcpv1_ul.h"
52+
#include "commands/rpcpv1_ul_subc_set.h"
53+
54+
static int
55+
strmp_settos(const struct rtpp_subc_ctx *rscp, struct rtpp_stream *strmp, int val)
56+
{
57+
if (strmp->laddr->sa_family != AF_INET)
58+
return (-1);
59+
struct rtpp_socket *fd = CALL_SMETHOD(strmp, get_skt, HEREVAL);
60+
if (fd == NULL)
61+
goto out;
62+
int tres = CALL_SMETHOD(fd, settos, val);
63+
RTPP_OBJ_DECREF(fd);
64+
if (tres == -1) {
65+
RTPP_ELOG(rscp->log, RTPP_LOG_ERR, "unable to set TOS to %d", val);
66+
return (-1);
67+
}
68+
out:
69+
strmp->tos = val;
70+
return (0);
71+
}
72+
73+
static int
74+
rtpp_subcommand_set_handler(const struct after_success_h_args *ashap,
75+
const struct rtpp_subc_ctx *rscp)
76+
{
77+
const struct rtpp_subcommand_set *tap;
78+
struct rtpp_stream *strmp;
79+
80+
tap = (struct rtpp_subcommand_set *)ashap->dyn;
81+
switch (tap->direction) {
82+
case SET_FORWARD:
83+
strmp = rscp->strmp_in;
84+
break;
85+
86+
case SET_REVERSE:
87+
strmp = rscp->strmp_out;
88+
if (strmp == NULL)
89+
return (-1);
90+
break;
91+
92+
default:
93+
abort();
94+
}
95+
96+
switch (tap->param) {
97+
case SET_PRM_TTL:
98+
strmp->stream_ttl = tap->val;
99+
CALL_SMETHOD(strmp->ttl, reset_with, tap->val);
100+
break;
101+
102+
case SET_PRM_TOS:
103+
if (strmp_settos(rscp, strmp, tap->val) != 0)
104+
return (-1);
105+
struct rtpp_stream_pair rtcp = get_rtcp_pair(rscp->sessp, strmp);
106+
if (rtcp.ret != 0 || rtcp.in == NULL)
107+
break;
108+
if (strmp_settos(rscp, rtcp.in, tap->val) != 0)
109+
return (-1);
110+
break;
111+
112+
default:
113+
abort();
114+
}
115+
return (0);
116+
}
117+
118+
struct rtpp_subcommand_set *
119+
handle_set_subc_parse(const struct rtpp_cfg *cfsp, const char *cp,
120+
const rtpp_str_const_t *v, struct after_success_h *asp)
121+
{
122+
struct rtpp_subcommand_set set_arg, *tap;
123+
124+
if (cp[0] == 'r' || cp[0] == 'R') {
125+
set_arg.direction = SET_REVERSE;
126+
} else {
127+
set_arg.direction = SET_FORWARD;
128+
}
129+
if (v->len < 5)
130+
return (NULL);
131+
if (memcmp(v->s, "ttl=", 4) == 0) {
132+
set_arg.param = SET_PRM_TTL;
133+
cp = v->s + 4;
134+
} else if (memcmp(v->s, "tos=", 4) == 0) {
135+
set_arg.param = SET_PRM_TOS;
136+
cp = v->s + 4;
137+
} else {
138+
return (NULL);
139+
}
140+
if (atoi_safe(cp, &set_arg.val) != ATOI_OK)
141+
return (NULL);
142+
if (set_arg.val <= 0)
143+
return (NULL);
144+
tap = rtpp_rzmalloc(sizeof(set_arg), offsetof(struct rtpp_subcommand_set, rcnt));
145+
if (tap == NULL)
146+
return (NULL);
147+
tap->val = set_arg.val;
148+
tap->direction = set_arg.direction;
149+
tap->param = set_arg.param;
150+
asp->handler = rtpp_subcommand_set_handler;
151+
return (tap);
152+
}

src/commands/rpcpv1_ul_subc_set.h

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright (c) 2025 Sippy Software, Inc., http://www.sippysoft.com
3+
*
4+
* Redistribution and use in source and binary forms, with or without
5+
* modification, are permitted provided that the following conditions
6+
* are met:
7+
* 1. Redistributions of source code must retain the above copyright
8+
* notice, this list of conditions and the following disclaimer.
9+
* 2. Redistributions in binary form must reproduce the above copyright
10+
* notice, this list of conditions and the following disclaimer in the
11+
* documentation and/or other materials provided with the distribution.
12+
*
13+
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
14+
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
15+
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
16+
* ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
17+
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
18+
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
19+
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
20+
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
21+
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
22+
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
23+
* SUCH DAMAGE.
24+
*
25+
*/
26+
27+
struct rtpp_subc_ctx;
28+
struct after_success_h_args;
29+
30+
enum rtpp_subcommand_set_direction {
31+
SET_FORWARD = 0,
32+
SET_REVERSE = 1
33+
};
34+
35+
enum rtpp_subcommand_set_param {
36+
SET_PRM_TTL,
37+
SET_PRM_TOS,
38+
SET_PRM_SSRC_IN,
39+
SET_PRM_SSRC_OUT,
40+
};
41+
42+
struct rtpp_subcommand_set {
43+
struct rtpp_refcnt *rcnt;
44+
int val;
45+
enum rtpp_subcommand_set_param param;
46+
enum rtpp_subcommand_set_direction direction;
47+
};
48+
49+
struct rtpp_subcommand_set *handle_set_subc_parse(const struct rtpp_cfg *, const char *,
50+
const rtpp_str_const_t *, struct after_success_h *);

src/commands/rpcpv1_ver.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ const static struct proto_cap proto_caps[] = {
7070
{ "20230314", "Support for for \"fusing\" G and D commands" },
7171
{ "20230424", "Support for for \"longest_ipi\", \"rtpa_jlast\", \"rtpa_jmax\" and \"rtpa_javg\" counters" },
7272
{ "20250523", "Support for the \"P\" modifier in the C command"},
73+
{ "20251015", "Support for changing session's ttl / IP tos via S subcommand" },
7374
{ NULL, NULL }
7475
};
7576

src/rtpp_command.c

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ struct create_listener_args {
101101
const struct sockaddr *ia;
102102
struct rtpp_socket **fds;
103103
int *port;
104+
int tos;
104105
};
105106

106107
static enum rtpp_ptu_rval
@@ -129,9 +130,9 @@ create_listener(struct create_listener_args *ctap, unsigned int port, struct rtp
129130
}
130131
goto e1;
131132
}
132-
if ((ctap->ia->sa_family == AF_INET) && (ctap->cfs->tos >= 0) &&
133-
(CALL_SMETHOD(fd, settos, ctap->cfs->tos) == -1))
134-
RTPP_ELOG(ctap->cfs->glog, RTPP_LOG_ERR, "unable to set TOS to %d", ctap->cfs->tos);
133+
if ((ctap->ia->sa_family == AF_INET) && (ctap->tos >= 0) &&
134+
(CALL_SMETHOD(fd, settos, ctap->tos) == -1))
135+
RTPP_ELOG(ctap->cfs->glog, RTPP_LOG_ERR, "unable to set TOS to %d", ctap->tos);
135136
so_rcvbuf = 256 * 1024;
136137
if (CALL_SMETHOD(fd, setrbuf, so_rcvbuf) == -1)
137138
RTPP_ELOG(ctap->cfs->glog, RTPP_LOG_ERR, "unable to set 256K receive buffer size");
@@ -178,7 +179,7 @@ create_twinlistener(unsigned int port, void *ap)
178179

179180
int
180181
rtpp_create_listener(const struct rtpp_cfg *cfsp, const struct sockaddr *ia, int *port,
181-
struct rtpp_socket **fds)
182+
struct rtpp_socket **fds, int tos)
182183
{
183184
struct create_listener_args cta;
184185
int i;
@@ -189,6 +190,7 @@ rtpp_create_listener(const struct rtpp_cfg *cfsp, const struct sockaddr *ia, int
189190
cta.fds = fds;
190191
cta.ia = ia;
191192
cta.port = port;
193+
cta.tos = tos;
192194

193195
for (i = 0; i < 2; i++)
194196
fds[i] = NULL;

0 commit comments

Comments
 (0)