Skip to content

Commit 04a8798

Browse files
committed
Document UL TOS protocol revision
1 parent d500372 commit 04a8798

12 files changed

Lines changed: 109 additions & 11 deletions

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/commands/rpcpv1_copy.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@
6161

6262
static int
6363
get_args4remote(const struct rtpp_cfg *cfsp, const char *rname, struct rtpp_log *log,
64-
struct remote_copy_args *ap)
64+
int desired_tos, struct remote_copy_args *ap)
6565
{
6666
char *tmp;
6767
const struct sockaddr *laddr;
@@ -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, desired_tos) != 0) {
8484
RTPP_LOG(log, RTPP_LOG_ERR, "can't create listener");
8585
return (-1);
8686
}
@@ -135,7 +135,7 @@ handle_copy(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, struct rtpp_s
135135

136136
int rval = -1;
137137
if (remote)
138-
if (get_args4remote(cfsp, rname, spa->log, &rargs) != 0)
138+
if (get_args4remote(cfsp, rname, spa->log, spa->rtp->stream[idx]->tos, &rargs) != 0)
139139
return (-1);
140140

141141
if (spa->rtp->stream[idx]->rrc == NULL) {

src/commands/rpcpv1_ul.c

Lines changed: 60 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ struct ul_opts {
105105
int new_port;
106106

107107
int onhold;
108+
int tos;
109+
int has_tos;
108110
};
109111

110112
#define BC_appendf(f, ...) { \
@@ -181,6 +183,8 @@ ul_opts_init(const struct rtpp_cfg *cfsp, struct ul_opts *ulop)
181183
ulop->lia[0] = ulop->lia[1] = ulop->reply.ia = cfsp->bindaddr[0];
182184
ulop->lidx = 1;
183185
ulop->pf = AF_INET;
186+
ulop->tos = -1;
187+
ulop->has_tos = 0;
184188
}
185189

186190
void
@@ -366,6 +370,30 @@ rtpp_command_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd
366370
ulop->new_port = 1;
367371
break;
368372

373+
case 't':
374+
case 'T': {
375+
const char *next, *vsp;
376+
enum atoi_rval arval;
377+
long ntos;
378+
379+
vsp = cp + 1;
380+
if (!isdigit((unsigned char)*vsp)) {
381+
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "command syntax error");
382+
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_INVLARG_8);
383+
goto err_undo_1;
384+
}
385+
arval = strtol_saferange(vsp, &ntos, 0, 255, &next);
386+
if (arval != ATOI_OK) {
387+
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "command syntax error");
388+
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_INVLARG_8);
389+
goto err_undo_1;
390+
}
391+
ulop->tos = (int)ntos;
392+
ulop->has_tos = 1;
393+
cp = (char *)next - 1;
394+
break;
395+
}
396+
369397
default:
370398
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "unknown command modifier `%c'",
371399
*cp);
@@ -442,6 +470,7 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
442470
struct rtpp_session *spa, *spb;
443471
struct rtpp_socket *fd;
444472
struct ul_opts *ulop;
473+
int desired_tos;
445474

446475
pidx = 1;
447476
lport = 0;
@@ -460,14 +489,16 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
460489
if (sidx != -1) {
461490
RTPP_DBG_ASSERT(cmd->cca.op == UPDATE || cmd->cca.op == LOOKUP);
462491
spa = cmd->sp;
492+
desired_tos = ulop->has_tos ? ulop->tos : spa->rtp->stream[sidx]->tos;
463493
fd = CALL_SMETHOD(spa->rtp->stream[sidx], get_skt, HEREVAL);
464494
if (fd == NULL || ulop->new_port != 0) {
465495
if (ulop->local_addr != NULL) {
466496
spa->rtp->stream[sidx]->laddr = ulop->local_addr;
467497
} else if (ulop->new_port != 0 && ulop->lidx == -1 && spa->rtp->stream[sidx]->laddr != ulop->lia[0]) {
468498
spa->rtp->stream[sidx]->laddr = ulop->lia[0];
469499
}
470-
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds) == -1) {
500+
if (rtpp_create_listener(cfsp, spa->rtp->stream[sidx]->laddr, &lport, fds,
501+
desired_tos) == -1) {
471502
if (fd != NULL)
472503
RTPP_OBJ_DECREF(fd);
473504
RTPP_LOG(spa->log, RTPP_LOG_ERR, "can't create listener");
@@ -487,6 +518,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
487518
RTPP_OBJ_DECREF(fds[1]);
488519
spa->rtp->stream[sidx]->port = lport;
489520
spa->rtcp->stream[sidx]->port = lport + 1;
521+
spa->rtp->stream[sidx]->tos = desired_tos;
522+
spa->rtcp->stream[sidx]->tos = desired_tos;
490523
if (spa->complete == 0) {
491524
rtpp_command_get_stats(cmd)->nsess_complete.cnt++;
492525
CALL_SMETHOD(spa->rtp->stream[0]->ttl, reset_with,
@@ -495,6 +528,25 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
495528
cfsp->max_ttl);
496529
}
497530
spa->complete = 1;
531+
} else if (ulop->has_tos) {
532+
if (spa->rtp->stream[sidx]->laddr->sa_family == AF_INET) {
533+
if (CALL_SMETHOD(fd, settos, desired_tos) == -1) {
534+
RTPP_ELOG(spa->log, RTPP_LOG_ERR,
535+
"unable to set TOS to %d", desired_tos);
536+
}
537+
}
538+
struct rtpp_socket *rtcp_fd = CALL_SMETHOD(spa->rtcp->stream[sidx], get_skt, HEREVAL);
539+
if (rtcp_fd != NULL) {
540+
if (spa->rtcp->stream[sidx]->laddr->sa_family == AF_INET) {
541+
if (CALL_SMETHOD(rtcp_fd, settos, desired_tos) == -1) {
542+
RTPP_ELOG(spa->log, RTPP_LOG_ERR,
543+
"unable to set TOS to %d", desired_tos);
544+
}
545+
}
546+
RTPP_OBJ_DECREF(rtcp_fd);
547+
}
548+
spa->rtp->stream[sidx]->tos = desired_tos;
549+
spa->rtcp->stream[sidx]->tos = desired_tos;
498550
}
499551
if (fd != NULL) {
500552
RTPP_OBJ_DECREF(fd);
@@ -541,7 +593,8 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
541593
CALL_SMETHOD(cmd->reply, deliver_error, cfsp->overload_prot.ecode);
542594
goto err_undo_0;
543595
}
544-
if (rtpp_create_listener(cfsp, ulop->lia[0], &lport, fds) == -1) {
596+
desired_tos = ulop->has_tos ? ulop->tos : -1;
597+
if (rtpp_create_listener(cfsp, ulop->lia[0], &lport, fds, desired_tos) == -1) {
545598
RTPP_LOG(cmd->glog, RTPP_LOG_ERR, "can't create listener");
546599
CALL_SMETHOD(cmd->reply, deliver_error, ECODE_LSTFAIL_2);
547600
goto err_undo_0;
@@ -559,6 +612,11 @@ rtpp_command_ul_handle(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd, in
559612
handle_nomem(cmd, ECODE_NOMEM_4, NULL);
560613
return (-1);
561614
}
615+
int effective_tos = ulop->has_tos ? ulop->tos : cfsp->tos;
616+
for (int i = 0; i < 2; i++) {
617+
spa->rtp->stream[i]->tos = effective_tos;
618+
spa->rtcp->stream[i]->tos = effective_tos;
619+
}
562620

563621
rtpp_command_get_stats(cmd)->nsess_created.cnt++;
564622

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+
{ "20250530", "Support for per-stream TOS override via the UL command's \"T\" modifier" },
7374
{ NULL, NULL }
7475
};
7576

src/rtpp_command.c

Lines changed: 9 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,12 @@ 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+
int lt_tos = ctap->tos;
134+
if (lt_tos < 0)
135+
lt_tos = ctap->cfs->tos;
136+
if ((ctap->ia->sa_family == AF_INET) && (lt_tos >= 0) &&
137+
(CALL_SMETHOD(fd, settos, lt_tos) == -1))
138+
RTPP_ELOG(ctap->cfs->glog, RTPP_LOG_ERR, "unable to set TOS to %d", lt_tos);
135139
so_rcvbuf = 256 * 1024;
136140
if (CALL_SMETHOD(fd, setrbuf, so_rcvbuf) == -1)
137141
RTPP_ELOG(ctap->cfs->glog, RTPP_LOG_ERR, "unable to set 256K receive buffer size");
@@ -178,7 +182,7 @@ create_twinlistener(unsigned int port, void *ap)
178182

179183
int
180184
rtpp_create_listener(const struct rtpp_cfg *cfsp, const struct sockaddr *ia, int *port,
181-
struct rtpp_socket **fds)
185+
struct rtpp_socket **fds, int tos)
182186
{
183187
struct create_listener_args cta;
184188
int i;
@@ -189,6 +193,7 @@ rtpp_create_listener(const struct rtpp_cfg *cfsp, const struct sockaddr *ia, int
189193
cta.fds = fds;
190194
cta.ia = ia;
191195
cta.port = port;
196+
cta.tos = tos;
192197

193198
for (i = 0; i < 2; i++)
194199
fds[i] = NULL;

src/rtpp_command.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ struct rtpp_command *get_command(const struct rtpp_cfg *, struct rtpp_ctrl_sock
5252
const struct rtpp_timestamp *, struct rtpp_command_stats *csp,
5353
struct rtpp_cmd_rcache *);
5454
int rtpp_create_listener(const struct rtpp_cfg *, const struct sockaddr *, int *,
55-
struct rtpp_socket **) RTPP_EXPORT;
55+
struct rtpp_socket **, int) RTPP_EXPORT;
5656
struct rtpp_command *rtpp_command_ctor(const struct rtpp_cfg *, int, const struct rtpp_timestamp *,
5757
struct rtpp_command_stats *, int);
5858
int rtpp_command_split(struct rtpp_command *, int, int *, struct rtpp_cmd_rcache *);

src/rtpp_command_ecodes.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@
6161
#define ECODE_INVLARG_5 35
6262
#define ECODE_INVLARG_6 36
6363
#define ECODE_INVLARG_7 37
64+
#define ECODE_INVLARG_8 38
6465

6566
#define ECODE_SESUNKN 50
6667

src/rtpp_session.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -150,6 +150,8 @@ rtpp_session_ctor(const struct rtpp_cfg *cfs, struct common_cmd_args *ccap,
150150
for (i = 0; i < 2; i++) {
151151
pub->rtp->stream[i]->laddr = lia[i];
152152
pub->rtcp->stream[i]->laddr = lia[i];
153+
pub->rtp->stream[i]->tos = cfs->tos;
154+
pub->rtcp->stream[i]->tos = cfs->tos;
153155
}
154156
if (weak) {
155157
pub->rtp->stream[0]->weak = 1;

src/rtpp_stream.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -312,6 +312,7 @@ rtpp_stream_ctor(const struct r_stream_ctor_args *ap)
312312
pvt->rtpp_stats = ap->rtpp_stats;
313313
pvt->pub.side = ap->side;
314314
pvt->pub.pipe_type = ap->pipe_type;
315+
pvt->pub.tos = -1;
315316

316317
pvt->pub.stuid = CALL_SMETHOD(ap->guid, gen);
317318
pvt->pub.seuid = ap->seuid;

src/rtpp_stream.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,8 @@ DECLARE_CLASS_PUBTYPE(rtpp_stream, {
160160
char *codecs;
161161
/* Requested ptime */
162162
int ptime;
163+
/* Desired IP TOS/DSCP value */
164+
int tos;
163165
/* UID, read-only */
164166
uint64_t stuid;
165167
/* UID of the session we belong to, read-only */

0 commit comments

Comments
 (0)