Skip to content

Commit 569633d

Browse files
committed
Add T[r]XXX sub-command.
PR: #59
1 parent e16a796 commit 569633d

File tree

5 files changed

+146
-2
lines changed

5 files changed

+146
-2
lines changed

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_ttl.c $(CMDSRCDIR)/rpcpv1_ul_subc_ttl.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

src/commands/rpcpv1_ul_subc.c

Lines changed: 35 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-2021 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
@@ -35,6 +35,7 @@
3535
#include "rtpp_util.h"
3636
#include "rtpp_log.h"
3737
#include "rtpp_log_obj.h"
38+
#include "rtpp_mallocs.h"
3839
#include "rtpp_modman.h"
3940
#include "rtpp_codeptr.h"
4041
#include "rtpp_refcnt.h"
@@ -45,6 +46,7 @@
4546
#include "commands/rpcpv1_ul.h"
4647
#include "commands/rpcpv1_ul_subc.h"
4748
#include "commands/rpcpv1_delete.h"
49+
#include "commands/rpcpv1_ul_subc_ttl.h"
4850

4951
#if ENABLE_MODULE_IF
5052
static int
@@ -67,6 +69,31 @@ handle_mod_subc_parse(const struct rtpp_cfg *cfsp, const char *ip,
6769
}
6870
#endif
6971

72+
static int
73+
handle_ttl_subc_parse(const struct rtpp_cfg *cfsp, const char *cp,
74+
struct after_success_h *asp)
75+
{
76+
struct rtpp_subcommand_ttl ttl_arg, *tap;
77+
78+
if (cp[0] == 'r' || cp[0] == 'R') {
79+
ttl_arg.direction = TTL_REVERSE;
80+
cp += 1;
81+
} else {
82+
ttl_arg.direction = TTL_FORWARD;
83+
}
84+
if (atoi_safe(cp, &ttl_arg.ttl) != ATOI_OK)
85+
return (-1);
86+
if (ttl_arg.ttl <= 0)
87+
return (-1);
88+
tap = rtpp_zmalloc(sizeof(ttl_arg));
89+
if (tap == NULL)
90+
return (-1);
91+
*tap = ttl_arg;
92+
asp->args.dyn = tap;
93+
asp->handler = rtpp_subcommand_ttl_handler;
94+
return (0);
95+
}
96+
7097
int
7198
rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *cmd,
7299
const struct rtpp_command_args *subc_args, struct after_success_h *asp)
@@ -98,6 +125,13 @@ rtpp_subcommand_ul_opts_parse(const struct rtpp_cfg *cfsp, struct rtpp_command *
98125
asp->handler = handle_delete_as_subc;
99126
break;
100127

128+
case 'T':
129+
case 't':
130+
if (subc_args->c != 1)
131+
return (-1);
132+
return (handle_ttl_subc_parse(cfsp, &subc_args->v[0].s[1], asp));
133+
break;
134+
101135
default:
102136
return (-1);
103137
}

src/commands/rpcpv1_ul_subc_ttl.c

Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright (c) 2021 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+
31+
#include "rtpp_codeptr.h"
32+
#include "rtpp_types.h"
33+
#include "rtpp_stream.h"
34+
#include "rtpp_ttl.h"
35+
#include "rtpp_command.h"
36+
#include "rtpp_command_sub.h"
37+
#include "rtpp_command_args.h"
38+
#include "rtpp_command_private.h"
39+
#include "commands/rpcpv1_ul.h"
40+
#include "commands/rpcpv1_ul_subc_ttl.h"
41+
42+
int
43+
rtpp_subcommand_ttl_handler(const struct after_success_h_args *ashap,
44+
const struct rtpp_subc_ctx *rscp)
45+
{
46+
const struct rtpp_subcommand_ttl *tap;
47+
struct rtpp_stream *strmp;
48+
49+
tap = (struct rtpp_subcommand_ttl *)ashap->dyn;
50+
switch (tap->direction) {
51+
case TTL_FORWARD:
52+
strmp = rscp->strmp_in;
53+
break;
54+
55+
case TTL_REVERSE:
56+
strmp = rscp->strmp_out;
57+
if (strmp == NULL)
58+
return (-1);
59+
break;
60+
61+
default:
62+
abort();
63+
}
64+
65+
CALL_SMETHOD(strmp->ttl, reset_with, tap->ttl);
66+
return (0);
67+
}

src/commands/rpcpv1_ul_subc_ttl.h

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright (c) 2021 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_ttl_direction {
31+
TTL_FORWARD = 0,
32+
TTL_REVERSE = 1
33+
};
34+
35+
struct rtpp_subcommand_ttl {
36+
int ttl;
37+
enum rtpp_subcommand_ttl_direction direction;
38+
};
39+
40+
int rtpp_subcommand_ttl_handler(const struct after_success_h_args *,
41+
const struct rtpp_subc_ctx *);

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" },
7374
{ NULL, NULL }
7475
};
7576

0 commit comments

Comments
 (0)