Skip to content

Commit 7ae8a2b

Browse files
committed
Add test to simulate handling of NAT'ed contact header and
check that the contact received in re-INVITE matches. This is to test add_contact_alias() and handle_ruri_alias() functions on Kamailio and fix_nated_contact() and restore_nated_ruri() in the OpenSIPS/master.
1 parent 56e10e8 commit 7ae8a2b

17 files changed

Lines changed: 317 additions & 33 deletions

‎functions‎

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,7 @@ then
101101
BOB_TIMEOUT=90
102102
TEST_SET="${TEST_SET},11,12,13,14,reinv_brkn1,reinv_brkn2,reinv_bad_ack"
103103
fi
104+
TEST_SET="${TEST_SET},early_cancel_lost100"
104105

105106
MM_ROOT="${MM_ROOT:-"${BUILDDIR}/dist/${MM_TYPE}"}"
106107

@@ -109,10 +110,10 @@ then
109110
TEST_SET="${TEST_SET},inv_brkn1"
110111
fi
111112

112-
#if [ "${MM_TYPE}" != "opensips" -o "${MM_BRANCH}" = "1.11" ]
113-
#then
114-
TEST_SET="${TEST_SET},early_cancel_lost100"
115-
#fi
113+
if [ "${MM_TYPE}" = "kamailio" ] || [ "${MM_TYPE}" = "opensips" -a "${MM_BRANCH}" = "master" ]
114+
then
115+
TEST_SET="${TEST_SET},nated_contact"
116+
fi
116117

117118
#if [ "${MM_TYPE}" = "kamailio" ]
118119
#then

‎lib/alice_testcore.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
from ..test_cases.reinv_frombob import a_test_reinv_frombob
5959
from ..test_cases.reinv_bad_ack import a_test_reinv_bad_ack
6060
from ..test_cases.inv_brkn1 import a_test_inv_brkn1
61+
from ..test_cases.nated_contact import a_test_nated_contact
6162

6263
ALL_TESTS = (a_test1, a_test2, a_test3, a_test4, a_test5, a_test6, a_test7, \
6364
a_test8, a_test9, a_test10, a_test11, a_test12, a_test13, a_test14, \
6465
a_test_early_cancel, a_test_early_cancel_lost100, a_test_reinvite, \
6566
a_test_reinv_fail, a_test_reinv_brkn1, a_test_reinv_brkn2, \
6667
a_test_reinv_onhold, a_test_reinv_adelay, a_test_reinv_frombob, \
67-
a_test_reinv_bad_ack, a_test_inv_brkn1)
68+
a_test_reinv_bad_ack, a_test_inv_brkn1, a_test_nated_contact)
6869

6970
class a_cfg(object):
7071
test_class = None

‎lib/bob_testcore.py‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,13 +58,14 @@
5858
from ..test_cases.reinv_frombob import b_test_reinv_frombob
5959
from ..test_cases.reinv_bad_ack import b_test_reinv_bad_ack
6060
from ..test_cases.inv_brkn1 import b_test_inv_brkn1
61+
from ..test_cases.nated_contact import b_test_nated_contact
6162

6263
ALL_TESTS = (b_test1, b_test2, b_test3, b_test4, b_test5, b_test6, b_test7, \
6364
b_test8, b_test9, b_test10, b_test11, b_test12, b_test13, b_test14, \
6465
b_test_early_cancel, b_test_early_cancel_lost100, b_test_reinvite, \
6566
b_test_reinv_fail, b_test_reinv_brkn1, b_test_reinv_brkn2, \
6667
b_test_reinv_onhold, b_test_reinv_adelay, b_test_reinv_frombob, \
67-
b_test_reinv_bad_ack, b_test_inv_brkn1)
68+
b_test_reinv_bad_ack, b_test_inv_brkn1, b_test_nated_contact)
6869

6970
class STMHooks(object):
7071
lossemul = 0

‎scenarios/UAC/opensips.cfg.in‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ loadmodule "uac_auth/uac_auth.so"
1212
loadmodule "sl/sl.so"
1313
loadmodule "tm/tm.so"
1414
loadmodule "rr/rr.so"
15+
loadmodule "nathelper/nathelper.so"
1516
loadmodule "maxfwd/maxfwd.so"
1617
loadmodule "rtpproxy/rtpproxy.so"
1718
loadmodule "textops/textops.so"
@@ -29,6 +30,12 @@ loadmodule "uri/uri.so"
2930
modparam("uac_auth", "credential", "mightyuser:VoIPTests.NET:s3cr3tpAssw0Rd")
3031
modparam("rtpproxy", "rtpproxy_sock", RTPP_SOCK_TEST)
3132

33+
#if OPENSIPS_VER_FULL == master || OPENSIPS_VER > 33
34+
#define NAT_PCONTACT "private-contact"
35+
#else
36+
#define NAT_PCONTACT INT(1)
37+
#endif
38+
3239
socket=udp:127.0.0.1:5060
3340
socket=udp:[::1]:5060
3441

@@ -70,13 +77,27 @@ route {
7077
};
7178

7279
if (is_method("BYE")) {
73-
xlog(" calling rtpproxy_unforce()\n");
80+
xlog(" calling rtpproxy_unforce()\n");
7481
rtpproxy_unforce();
7582
};
7683

7784
record_route();
7885

86+
if (is_method("INVITE") && !has_totag() && nat_uac_test(NAT_PCONTACT)) {
87+
xlog(" NAT contact detected\n");
88+
#if OPENSIPS_VER_FULL == master
89+
if (fix_nated_contact("", "preserve-uri")) {
90+
xlog(" adding alias\n");
91+
};
92+
#endif
93+
};
94+
7995
if (loose_route()) {
96+
#if OPENSIPS_VER_FULL == master
97+
if (restore_nated_ruri()) {
98+
xlog(" alias removed from the R-URI\n");
99+
};
100+
#endif
80101
t_relay();
81102
exit;
82103
};
@@ -96,6 +117,14 @@ onreply_route[1]
96117
{
97118
xlog("OpenSIPS received a reply $rs/$rm from $si\n");
98119
if (STATUS =~ "(183)|2[0-9][0-9]") {
120+
if (nat_uac_test(NAT_PCONTACT)) {
121+
xlog(" NAT contact detected\n");
122+
#if OPENSIPS_VER_FULL == master
123+
if (fix_nated_contact("", "preserve-uri")) {
124+
xlog(" adding alias\n");
125+
};
126+
#endif
127+
};
99128
xlog(" calling search()\n");
100129
if(!search("^Content-Length:[ ]*0")) {
101130
xlog(" calling rtpproxy_answer()\n");
@@ -119,7 +148,7 @@ failure_route[invite]
119148
xlog(" uac_auth() FAILURE\n");
120149
}
121150
}
122-
xlog(" calling rtpproxy_unforce()\n");
151+
xlog(" calling rtpproxy_unforce()\n");
123152
rtpproxy_unforce();
124153
}
125154

@@ -146,6 +175,6 @@ failure_route[re_invite]
146175
failure_route[uac_auth_fail]
147176
{
148177
xlog("OpenSIPS handling $rm failure in from $si in failure_route[uac_auth_fail]\n");
149-
xlog(" calling rtpproxy_unforce()\n");
178+
xlog(" calling rtpproxy_unforce()\n");
150179
rtpproxy_unforce();
151180
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
#define NCMDS_BASE 275
1+
#define NCMDS_BASE 295
2+
#define NSESS_BASE 68
3+
#define NSESS_INCM 24
24

35
#include <rtpproxy.output/common.in>

‎scenarios/UAS/auth/opensips.cfg.in‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ loadmodule "auth/auth.so"
1414
loadmodule "sl/sl.so"
1515
loadmodule "tm/tm.so"
1616
loadmodule "rr/rr.so"
17+
loadmodule "nathelper/nathelper.so"
1718
loadmodule "maxfwd/maxfwd.so"
1819
loadmodule "rtpproxy/rtpproxy.so"
1920
loadmodule "textops/textops.so"
@@ -35,6 +36,12 @@ modparam("auth", "calculate_ha1", 1)
3536

3637
modparam("rtpproxy", "rtpproxy_sock", RTPP_SOCK_TEST)
3738

39+
#if OPENSIPS_VER_FULL == master || OPENSIPS_VER > 33
40+
#define NAT_PCONTACT "private-contact"
41+
#else
42+
#define NAT_PCONTACT INT(1)
43+
#endif
44+
3845
socket=udp:127.0.0.1:5060
3946
socket=udp:[::1]:5060
4047

@@ -86,13 +93,27 @@ route {
8693
};
8794

8895
if (is_method("BYE")) {
89-
xlog(" calling rtpproxy_unforce()\n");
96+
xlog(" calling rtpproxy_unforce()\n");
9097
rtpproxy_unforce();
9198
};
9299

93100
record_route();
94101

102+
if (is_method("INVITE") && !has_totag() && nat_uac_test(NAT_PCONTACT)) {
103+
xlog(" NAT contact detected\n");
104+
#if OPENSIPS_VER_FULL == master
105+
if (fix_nated_contact("", "preserve-uri")) {
106+
xlog(" adding alias\n");
107+
};
108+
#endif
109+
};
110+
95111
if (loose_route()) {
112+
#if OPENSIPS_VER_FULL == master
113+
if (restore_nated_ruri()) {
114+
xlog(" alias removed from the R-URI\n");
115+
};
116+
#endif
96117
t_relay();
97118
exit;
98119
};
@@ -112,6 +133,14 @@ onreply_route[1]
112133
{
113134
xlog("OpenSIPS received a reply $rs/$rm from $si\n");
114135
if (STATUS =~ "(183)|2[0-9][0-9]") {
136+
if (nat_uac_test(NAT_PCONTACT)) {
137+
xlog(" NAT contact detected\n");
138+
#if OPENSIPS_VER_FULL == master
139+
if (fix_nated_contact("", "preserve-uri")) {
140+
xlog(" adding alias\n");
141+
};
142+
#endif
143+
};
115144
xlog(" calling search()\n");
116145
if(!search("^Content-Length:[ ]*0")) {
117146
xlog(" calling rtpproxy_answer()\n");
@@ -135,7 +164,7 @@ failure_route[invite]
135164
xlog(" uac_auth() FAILURE\n");
136165
}
137166
}
138-
xlog(" calling rtpproxy_unforce()\n");
167+
xlog(" calling rtpproxy_unforce()\n");
139168
rtpproxy_unforce();
140169
}
141170

@@ -162,6 +191,6 @@ failure_route[re_invite]
162191
failure_route[uac_auth_fail]
163192
{
164193
xlog("OpenSIPS handling $rm failure in from $si in failure_route[uac_auth_fail]\n");
165-
xlog(" calling rtpproxy_unforce()\n");
194+
xlog(" calling rtpproxy_unforce()\n");
166195
rtpproxy_unforce();
167196
}

‎scenarios/UAS/auth_db/calculate_ha1/opensips.cfg.in‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ loadmodule "auth_db/auth_db.so"
1616
loadmodule "sl/sl.so"
1717
loadmodule "tm/tm.so"
1818
loadmodule "rr/rr.so"
19+
loadmodule "nathelper/nathelper.so"
1920
loadmodule "maxfwd/maxfwd.so"
2021
loadmodule "rtpproxy/rtpproxy.so"
2122
loadmodule "textops/textops.so"
@@ -39,6 +40,12 @@ modparam("auth_db", "db_url", "text://<#exec echo -n `pwd`>/scenarios/<#MM_AUTH>
3940

4041
modparam("rtpproxy", "rtpproxy_sock", RTPP_SOCK_TEST)
4142

43+
#if OPENSIPS_VER_FULL == master || OPENSIPS_VER > 33
44+
#define NAT_PCONTACT "private-contact"
45+
#else
46+
#define NAT_PCONTACT INT(1)
47+
#endif
48+
4249
socket=udp:127.0.0.1:5060
4350
socket=udp:[::1]:5060
4451

@@ -88,13 +95,27 @@ route {
8895
};
8996

9097
if (is_method("BYE")) {
91-
xlog(" calling rtpproxy_unforce()\n");
98+
xlog(" calling rtpproxy_unforce()\n");
9299
rtpproxy_unforce();
93100
};
94101

95102
record_route();
96103

104+
if (is_method("INVITE") && !has_totag() && nat_uac_test(NAT_PCONTACT)) {
105+
xlog(" NAT contact detected\n");
106+
#if OPENSIPS_VER_FULL == master
107+
if (fix_nated_contact("", "preserve-uri")) {
108+
xlog(" adding alias\n");
109+
};
110+
#endif
111+
};
112+
97113
if (loose_route()) {
114+
#if OPENSIPS_VER_FULL == master
115+
if (restore_nated_ruri()) {
116+
xlog(" alias removed from the R-URI\n");
117+
};
118+
#endif
98119
t_relay();
99120
exit;
100121
};
@@ -114,6 +135,14 @@ onreply_route[1]
114135
{
115136
xlog("OpenSIPS received a reply $rs/$rm from $si\n");
116137
if (STATUS =~ "(183)|2[0-9][0-9]") {
138+
if (nat_uac_test(NAT_PCONTACT)) {
139+
xlog(" NAT contact detected\n");
140+
#if OPENSIPS_VER_FULL == master
141+
if (fix_nated_contact("", "preserve-uri")) {
142+
xlog(" adding alias\n");
143+
};
144+
#endif
145+
};
117146
xlog(" calling search()\n");
118147
if(!search("^Content-Length:[ ]*0")) {
119148
xlog(" calling rtpproxy_answer()\n");
@@ -137,7 +166,7 @@ failure_route[invite]
137166
xlog(" uac_auth() FAILURE\n");
138167
}
139168
}
140-
xlog(" calling rtpproxy_unforce()\n");
169+
xlog(" calling rtpproxy_unforce()\n");
141170
rtpproxy_unforce();
142171
}
143172

@@ -164,6 +193,6 @@ failure_route[re_invite]
164193
failure_route[uac_auth_fail]
165194
{
166195
xlog("OpenSIPS handling $rm failure in from $si in failure_route[uac_auth_fail]\n");
167-
xlog(" calling rtpproxy_unforce()\n");
196+
xlog(" calling rtpproxy_unforce()\n");
168197
rtpproxy_unforce();
169198
}

‎scenarios/UAS/auth_db/ha1/opensips.cfg.in‎

Lines changed: 32 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ loadmodule "auth_db/auth_db.so"
1616
loadmodule "sl/sl.so"
1717
loadmodule "tm/tm.so"
1818
loadmodule "rr/rr.so"
19+
loadmodule "nathelper/nathelper.so"
1920
loadmodule "maxfwd/maxfwd.so"
2021
loadmodule "rtpproxy/rtpproxy.so"
2122
loadmodule "textops/textops.so"
@@ -39,6 +40,12 @@ modparam("auth_db", "db_url", "text://<#exec echo -n `pwd`>/scenarios/<#MM_AUTH>
3940

4041
modparam("rtpproxy", "rtpproxy_sock", RTPP_SOCK_TEST)
4142

43+
#if OPENSIPS_VER_FULL == master || OPENSIPS_VER > 33
44+
#define NAT_PCONTACT "private-contact"
45+
#else
46+
#define NAT_PCONTACT INT(1)
47+
#endif
48+
4249
socket=udp:127.0.0.1:5060
4350
socket=udp:[::1]:5060
4451

@@ -88,13 +95,27 @@ route {
8895
};
8996

9097
if (is_method("BYE")) {
91-
xlog(" calling rtpproxy_unforce()\n");
98+
xlog(" calling rtpproxy_unforce()\n");
9299
rtpproxy_unforce();
93100
};
94101

95102
record_route();
96103

104+
if (is_method("INVITE") && !has_totag() && nat_uac_test(NAT_PCONTACT)) {
105+
xlog(" NAT contact detected\n");
106+
#if OPENSIPS_VER_FULL == master
107+
if (fix_nated_contact("", "preserve-uri")) {
108+
xlog(" adding alias\n");
109+
};
110+
#endif
111+
};
112+
97113
if (loose_route()) {
114+
#if OPENSIPS_VER_FULL == master
115+
if (restore_nated_ruri()) {
116+
xlog(" alias removed from the R-URI\n");
117+
};
118+
#endif
98119
t_relay();
99120
exit;
100121
};
@@ -114,6 +135,14 @@ onreply_route[1]
114135
{
115136
xlog("OpenSIPS received a reply $rs/$rm from $si\n");
116137
if (STATUS =~ "(183)|2[0-9][0-9]") {
138+
if (nat_uac_test(NAT_PCONTACT)) {
139+
xlog(" NAT contact detected\n");
140+
#if OPENSIPS_VER_FULL == master
141+
if (fix_nated_contact("", "preserve-uri")) {
142+
xlog(" adding alias\n");
143+
};
144+
#endif
145+
};
117146
xlog(" calling search()\n");
118147
if(!search("^Content-Length:[ ]*0")) {
119148
xlog(" calling rtpproxy_answer()\n");
@@ -137,7 +166,7 @@ failure_route[invite]
137166
xlog(" uac_auth() FAILURE\n");
138167
}
139168
}
140-
xlog(" calling rtpproxy_unforce()\n");
169+
xlog(" calling rtpproxy_unforce()\n");
141170
rtpproxy_unforce();
142171
}
143172

@@ -164,6 +193,6 @@ failure_route[re_invite]
164193
failure_route[uac_auth_fail]
165194
{
166195
xlog("OpenSIPS handling $rm failure in from $si in failure_route[uac_auth_fail]\n");
167-
xlog(" calling rtpproxy_unforce()\n");
196+
xlog(" calling rtpproxy_unforce()\n");
168197
rtpproxy_unforce();
169198
}
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1-
#define NCMDS_BASE 259
1+
#define NCMDS_BASE 279
2+
#define NSESS_BASE 60
3+
#define NSESS_INCM 16
24

35
#include "rtpproxy.output/common.in"

0 commit comments

Comments
 (0)