Skip to content

Commit c73f227

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

18 files changed

+268
-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
@@ -442,6 +442,7 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
442442
struct rtpp_session *spa, *spb;
443443
struct rtpp_socket *fd;
444444
struct ul_opts *ulop;
445+
int desired_tos;
445446

446447
pidx = 1;
447448
lport = 0;
@@ -460,14 +461,16 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
460461
if (sidx != -1) {
461462
RTPP_DBG_ASSERT(cmd->cca.op == UPDATE || cmd->cca.op == LOOKUP);
462463
spa = cmd->sp;
464+
desired_tos = spa->rtp->stream[sidx]->tos;
463465
fd = CALL_SMETHOD(spa->rtp->stream[sidx], get_skt, HEREVAL);
464466
if (fd == NULL || ulop->new_port != 0) {
465467
if (ulop->local_addr != NULL) {
466468
spa->rtp->stream[sidx]->laddr = ulop->local_addr;
467469
} else if (ulop->new_port != 0 && ulop->lidx == -1 && spa->rtp->stream[sidx]->laddr != ulop->lia[0]) {
468470
spa->rtp->stream[sidx]->laddr = ulop->lia[0];
469471
}
470-
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds) == -1) {
472+
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds,
473+
desired_tos) == -1) {
471474
if (fd != NULL)
472475
RTPP_OBJ_DECREF(fd);
473476
RTPP_LOG(spa->log, RTPP_LOG_ERR, "can't create listener");
@@ -490,9 +493,9 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
490493
if (spa->complete == 0) {
491494
rtpp_command_get_stats(cmd)->nsess_complete.cnt++;
492495
CALL_SMETHOD(spa->rtp->stream[0]->ttl, reset_with,
493-
cfsp->max_ttl);
496+
spa->rtp->stream[0]->stream_ttl);
494497
CALL_SMETHOD(spa->rtp->stream[1]->ttl, reset_with,
495-
cfsp->max_ttl);
498+
spa->rtp->stream[1]->stream_ttl);
496499
}
497500
spa->complete = 1;
498501
}
@@ -692,7 +695,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
692695
.strmp_in = spa->rtp->stream[pidx],
693696
.strmp_out = spa->rtp->stream[NOT(pidx)],
694697
.subc_args = &(cmd->subc.args[i]),
695-
.resp = &(cmd->subc.res[i])
698+
.resp = &(cmd->subc.res[i]),
699+
.log = spa->log,
696700
};
697701
rsc.resp->result = cmd->after_success[i].handler(
698702
&cmd->after_success[i].args, &rsc);

src/commands/rpcpv1_ul_subc.c

Lines changed: 9 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
@@ -98,6 +99,13 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *
9899
asp->handler = handle_delete_as_subc;
99100
break;
100101

102+
case 'S':
103+
case 's':
104+
if (subc_args->c != 2 || subc_args->v[0].len < 1 || subc_args->v[0].len > 2)
105+
return (-1);
106+
return (handle_set_subc_parse(cfsp, &subc_args->v[0].s[1], &subc_args->v[1], asp));
107+
break;
108+
101109
default:
102110
return (-1);
103111
}

src/commands/rpcpv1_ul_subc_set.c

Lines changed: 148 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,148 @@
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 <stdint.h>
29+
#include <stdlib.h>
30+
#include <string.h>
31+
32+
#include "config.h"
33+
34+
#include "rtpp_codeptr.h"
35+
#include "rtpp_types.h"
36+
#include "rtpp_refcnt.h"
37+
#include "rtpp_log.h"
38+
#include "rtpp_log_obj.h"
39+
#include "rtpp_pipe.h"
40+
#include "rtpp_socket.h"
41+
#include "rtpp_session.h"
42+
#include "rtpp_stream.h"
43+
#include "rtpp_ttl.h"
44+
#include "rtpp_command.h"
45+
#include "rtpp_command_sub.h"
46+
#include "rtpp_command_args.h"
47+
#include "rtpp_command_private.h"
48+
#include "rtpp_mallocs.h"
49+
#include "rtpp_util.h"
50+
#include "commands/rpcpv1_ul.h"
51+
#include "commands/rpcpv1_ul_subc_set.h"
52+
53+
static int
54+
strmp_settos(const struct rtpp_subc_ctx *rscp, struct rtpp_stream *strmp, int val)
55+
{
56+
if (strmp->laddr->sa_family != AF_INET)
57+
return (-1);
58+
struct rtpp_socket *fd = CALL_SMETHOD(strmp, get_skt, HEREVAL);
59+
if (fd == NULL)
60+
goto out;
61+
int tres = CALL_SMETHOD(fd, settos, val);
62+
RTPP_OBJ_DECREF(fd);
63+
if (tres == -1) {
64+
RTPP_ELOG(rscp->log, RTPP_LOG_ERR, "unable to set TOS to %d", val);
65+
return (-1);
66+
}
67+
out:
68+
strmp->tos = val;
69+
return (0);
70+
}
71+
72+
static int
73+
rtpp_subcommand_set_handler(const struct after_success_h_args *ashap,
74+
const struct rtpp_subc_ctx *rscp)
75+
{
76+
const struct rtpp_subcommand_set *tap;
77+
struct rtpp_stream *strmp;
78+
79+
tap = (struct rtpp_subcommand_set *)ashap->dyn;
80+
switch (tap->direction) {
81+
case SET_FORWARD:
82+
strmp = rscp->strmp_in;
83+
break;
84+
85+
case SET_REVERSE:
86+
strmp = rscp->strmp_out;
87+
if (strmp == NULL)
88+
return (-1);
89+
break;
90+
91+
default:
92+
abort();
93+
}
94+
95+
switch (tap->param) {
96+
case SET_PRM_TTL:
97+
strmp->stream_ttl = tap->val;
98+
CALL_SMETHOD(strmp->ttl, reset_with, tap->val);
99+
break;
100+
101+
case SET_PRM_TOS:
102+
if (strmp_settos(rscp, strmp, tap->val) != 0)
103+
return (-1);
104+
struct rtpp_stream_pair rtcp = get_rtcp_pair(rscp->sessp, strmp);
105+
if (rtcp.ret != 0 || rtcp.in == NULL)
106+
break;
107+
if (strmp_settos(rscp, rtcp.in, tap->val) != 0)
108+
return (-1);
109+
break;
110+
111+
default:
112+
abort();
113+
}
114+
return (0);
115+
}
116+
117+
int
118+
handle_set_subc_parse(const struct rtpp_cfg *cfsp, const char *cp,
119+
const rtpp_str_const_t *v, struct after_success_h *asp)
120+
{
121+
struct rtpp_subcommand_set set_arg, *tap;
122+
123+
if (cp[0] == 'r' || cp[0] == 'R') {
124+
set_arg.direction = SET_REVERSE;
125+
} else {
126+
set_arg.direction = SET_FORWARD;
127+
}
128+
if (strcmp(v->s, "ttl=") == 0) {
129+
set_arg.param = SET_PRM_TTL;
130+
cp = v->s + 4;
131+
} else if (strcmp(v->s, "tos=") == 0) {
132+
set_arg.param = SET_PRM_TOS;
133+
cp = v->s + 4;
134+
} else {
135+
return (-1);
136+
}
137+
if (atoi_safe(cp, &set_arg.val) != ATOI_OK)
138+
return (-1);
139+
if (set_arg.val <= 0)
140+
return (-1);
141+
tap = rtpp_zmalloc(sizeof(set_arg));
142+
if (tap == NULL)
143+
return (-1);
144+
*tap = set_arg;
145+
asp->args.dyn = tap;
146+
asp->handler = rtpp_subcommand_set_handler;
147+
return (0);
148+
}

src/commands/rpcpv1_ul_subc_set.h

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
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+
int val;
44+
enum rtpp_subcommand_set_param param;
45+
enum rtpp_subcommand_set_direction direction;
46+
};
47+
48+
int handle_set_subc_parse(const struct rtpp_cfg *, const char *,
49+
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)