1
0
mirror of https://git.FreeBSD.org/ports.git synced 2024-11-25 00:51:21 +00:00

Sync nathelper with the SER's trunk.

This commit is contained in:
Maxim Sobolev 2007-04-24 02:53:46 +00:00
parent 59c0749b15
commit ca78aed46e
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=190770
4 changed files with 159 additions and 68 deletions

View File

@ -7,7 +7,7 @@
PORTNAME= ser
PORTVERSION= 0.9.6
PORTREVISION= 4
PORTREVISION= 5
CATEGORIES= net
MASTER_SITES= http://download.berlios.de/ser/ \
http://download2.berlios.de/ser/

View File

@ -1,7 +1,7 @@
$FreeBSD$
--- modules/nathelper/nathelper.c.orig
--- modules/nathelper/nathelper.c
+++ modules/nathelper/nathelper.c
@@ -110,14 +110,42 @@
*
@ -31,11 +31,11 @@ $FreeBSD$
+ * Such "disabled" proxies are periodically checked to see if they
+ * are back to normal in which case respective weight is restored
+ * resulting in traffic being sent to that proxy again.
+ *
*
+ * Those features can be enabled by specifying more than one "URI"
+ * in the rtpproxy_sock parameter, optionally followed by the weight,
+ * which if absent is assumed to be 1, for example:
*
+ *
+ * rtpproxy_sock="unix:/foo/bar=4 udp:1.2.3.4:3456=3 udp:5.6.7.8:5432=1"
+ *
+ * 2005-03-24 music-on-hold implemented (netch)
@ -47,7 +47,7 @@ $FreeBSD$
#include "../../flags.h"
#include "../../sr_module.h"
#include "../../dprint.h"
@@ -127,6 +155,7 @@
@@ -127,9 +155,13 @@
#include "../../forward.h"
#include "../../mem/mem.h"
#include "../../parser/parse_from.h"
@ -55,7 +55,13 @@ $FreeBSD$
#include "../../parser/parse_to.h"
#include "../../parser/parse_uri.h"
#include "../../parser/parser_f.h"
@@ -171,39 +200,30 @@
+ *
+ * 2007-04-23 Do NAT pinging in the separate dedicated process. It provides much
+ * better scalability than doing it in the main one.
#include "../../resolve.h"
#include "../../timer.h"
#include "../../trim.h"
@@ -171,39 +203,30 @@
#define NAT_UAC_TEST_S_1918 0x08
#define NAT_UAC_TEST_RPORT 0x10
@ -100,7 +106,7 @@ $FreeBSD$
struct socket_info* force_socket = 0;
@@ -218,27 +238,51 @@
@@ -218,27 +241,52 @@
{NULL, 0, 0}
};
@ -120,6 +126,7 @@ $FreeBSD$
+
+static char *rtpproxy_sock = "unix:/var/run/rtpproxy.sock"; /* list */
static char *force_socket_str = 0;
+static void mod_cleanup(void);
static int rtpproxy_disable = 0;
static int rtpproxy_disable_tout = 60;
static int rtpproxy_retr = 5;
@ -162,7 +169,7 @@ $FreeBSD$
{"unforce_rtp_proxy", unforce_rtp_proxy_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE },
{"force_rtp_proxy", force_rtp_proxy0_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
{"force_rtp_proxy", force_rtp_proxy1_f, 1, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
@@ -246,11 +290,16 @@
@@ -246,11 +294,16 @@
{"nat_uac_test", nat_uac_test_f, 1, fixup_str2int, REQUEST_ROUTE | ONREPLY_ROUTE | FAILURE_ROUTE },
{"fix_nated_register", fix_nated_register_f, 0, 0, REQUEST_ROUTE },
{"add_rcv_param", add_rcv_param_f, 0, 0, REQUEST_ROUTE },
@ -179,7 +186,7 @@ $FreeBSD$
{"ping_nated_only", INT_PARAM, &ping_nated_only },
{"rtpproxy_sock", STR_PARAM, &rtpproxy_sock },
{"rtpproxy_disable", INT_PARAM, &rtpproxy_disable },
@@ -259,6 +308,10 @@
@@ -259,6 +312,10 @@
{"rtpproxy_tout", INT_PARAM, &rtpproxy_tout },
{"received_avp", INT_PARAM, &rcv_avp_no },
{"force_socket", STR_PARAM, &force_socket_str },
@ -190,7 +197,16 @@ $FreeBSD$
{0, 0, 0}
};
@@ -277,8 +330,6 @@
@@ -268,7 +325,7 @@
params,
mod_init,
0, /* reply processing */
- 0, /* destroy function */
+ mod_cleanup, /* destroy function */
0, /* on_break */
child_init
};
@@ -277,8 +334,6 @@
mod_init(void)
{
int i;
@ -199,7 +215,7 @@ $FreeBSD$
struct in_addr addr;
str socket_str;
@@ -288,18 +339,9 @@
@@ -288,18 +343,9 @@
force_socket=grep_sock_info(&socket_str,0,0);
}
@ -221,7 +237,7 @@ $FreeBSD$
}
/* Prepare 1918 networks list */
@@ -309,25 +351,72 @@
@@ -309,25 +355,72 @@
nets_1918[i].netaddr = ntohl(addr.s_addr) & nets_1918[i].mask;
}
@ -311,7 +327,7 @@ $FreeBSD$
}
}
@@ -340,52 +429,66 @@
@@ -340,52 +433,75 @@
int n;
char *cp;
struct addrinfo hints, *res;
@ -345,6 +361,25 @@ $FreeBSD$
+ /*
+ * This is UDP or UDP6. Detect host and port; lookup host;
+ * do connect() in order to specify peer address
+static void
+mod_cleanup(void)
+{
- controlfd = socket((umode == 6) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
- if (controlfd == -1) {
- LOG(L_ERR, "nathelper: can't create socket\n");
- freeaddrinfo(res);
- return -1;
- }
+ natpinger_cleanup();
+}
- if (connect(controlfd, res->ai_addr, res->ai_addrlen) == -1) {
- LOG(L_ERR, "nathelper: can't connect to a RTP proxy\n");
- close(controlfd);
- freeaddrinfo(res);
- return -1;
- }
+ */
+ old_colon = cp = strrchr(pnode->rn_address, ':');
+ if (cp != NULL) {
@ -353,14 +388,10 @@ $FreeBSD$
+ cp++;
+ }
+ if (cp == NULL || *cp == '\0')
+ if (natpinger_child_init(rank) < 0)
+ return -1;
+ cp = CPORT;
- controlfd = socket((umode == 6) ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
- if (controlfd == -1) {
- LOG(L_ERR, "nathelper: can't create socket\n");
- freeaddrinfo(res);
- return -1;
- }
+
+ memset(&hints, 0, sizeof(hints));
+ hints.ai_flags = 0;
+ hints.ai_family = (pnode->rn_umode == 6) ? AF_INET6 : AF_INET;
@ -371,13 +402,7 @@ $FreeBSD$
+ }
+ if (old_colon)
+ *old_colon = ':'; /* restore rn_address */
- if (connect(controlfd, res->ai_addr, res->ai_addrlen) == -1) {
- LOG(L_ERR, "nathelper: can't connect to a RTP proxy\n");
- close(controlfd);
- freeaddrinfo(res);
- return -1;
- }
+
+ pnode->rn_fd = socket((pnode->rn_umode == 6)
+ ? AF_INET6 : AF_INET, SOCK_DGRAM, 0);
+ if (pnode->rn_fd == -1) {
@ -412,7 +437,7 @@ $FreeBSD$
isnulladdr(str *sx, int pf)
{
char *cp;
@@ -440,7 +543,7 @@
@@ -440,7 +556,7 @@
* assumes the to header is already parsed, so
* make sure it really is before calling this function
*/
@ -421,7 +446,7 @@ $FreeBSD$
get_to_tag(struct sip_msg* _m, str* _tag)
{
@@ -463,7 +566,7 @@
@@ -464,7 +580,7 @@
/*
* Extract tag from From header field of a request
*/
@ -430,7 +455,7 @@ $FreeBSD$
get_from_tag(struct sip_msg* _m, str* _tag)
{
@@ -488,7 +591,7 @@
@@ -489,7 +605,7 @@
* (so make sure it is, before calling this function or
* it might fail even if the message _has_ a callid)
*/
@ -439,7 +464,7 @@ $FreeBSD$
get_callid(struct sip_msg* _m, str* _cid)
{
@@ -562,9 +665,13 @@
@@ -563,9 +679,13 @@
if (anchor == 0)
return -1;
@ -456,7 +481,7 @@ $FreeBSD$
cp = ip_addr2a(&msg->rcv.src_ip);
len = c->uri.len + strlen(cp) + 6 /* :port */ - hostport.len + 1;
@@ -651,11 +758,22 @@
@@ -652,11 +772,22 @@
{
struct sip_uri uri;
contact_t* c;
@ -480,7 +505,7 @@ $FreeBSD$
}
/*
@@ -755,8 +873,8 @@
@@ -756,8 +887,8 @@
static int
fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
{
@ -491,7 +516,7 @@ $FreeBSD$
char *buf;
struct lump* anchor;
@@ -803,37 +921,43 @@
@@ -804,37 +935,43 @@
}
if (level & FIX_MEDIP) {
@ -563,7 +588,7 @@ $FreeBSD$
}
}
@@ -841,7 +965,7 @@
@@ -842,7 +979,7 @@
return 1;
}
@ -572,7 +597,7 @@ $FreeBSD$
extract_mediaip(str *body, str *mediaip, int *pf)
{
char *cp, *cp1;
@@ -855,7 +979,7 @@
@@ -856,7 +993,7 @@
cp = cp1 + 2;
}
if (cp1 == NULL) {
@ -581,7 +606,7 @@ $FreeBSD$
return -1;
}
mediaip->s = cp1 + 2;
@@ -897,11 +1021,12 @@
@@ -898,11 +1035,12 @@
return 1;
}
@ -596,7 +621,7 @@ $FreeBSD$
cp1 = NULL;
for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
@@ -914,32 +1039,62 @@
@@ -915,32 +1053,62 @@
LOG(L_ERR, "ERROR: extract_mediaport: no `m=' in SDP\n");
return -1;
}
@ -674,7 +699,7 @@ $FreeBSD$
{
char *buf;
int offset;
@@ -947,7 +1102,7 @@
@@ -948,7 +1116,7 @@
str omip, nip, oip;
/* check that updating mediaip is really necessary */
@ -683,7 +708,7 @@ $FreeBSD$
return 0;
if (newip->len == oldip->len &&
memcmp(newip->s, oldip->s, newip->len) == 0)
@@ -960,7 +1115,7 @@
@@ -961,7 +1129,7 @@
* another request comes.
*/
#if 0
@ -692,7 +717,7 @@ $FreeBSD$
* - alter_mediaip is called twice if 2 c= lines are present
* in the sdp (and we want to allow it)
* - the message flags are propagated in the on_reply_route
@@ -975,7 +1130,7 @@
@@ -976,7 +1144,7 @@
}
#endif
@ -701,7 +726,7 @@ $FreeBSD$
anchor = anchor_lump(msg, body->s + body->len - msg->buf, 0, 0);
if (anchor == NULL) {
LOG(L_ERR, "ERROR: alter_mediaip: anchor_lump failed\n");
@@ -1051,7 +1206,7 @@
@@ -1052,7 +1220,7 @@
return 0;
}
@ -710,7 +735,7 @@ $FreeBSD$
alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport,
int preserve)
{
@@ -1127,6 +1282,161 @@
@@ -1128,6 +1296,161 @@
return 0;
}
@ -872,7 +897,7 @@ $FreeBSD$
static char *
gencookie()
{
@@ -1138,45 +1448,58 @@
@@ -1139,45 +1462,58 @@
}
static int
@ -952,7 +977,7 @@ $FreeBSD$
{
struct sockaddr_un addr;
int fd, len, i;
@@ -1186,10 +1509,10 @@
@@ -1187,10 +1523,10 @@
len = 0;
cp = buf;
@ -965,7 +990,7 @@ $FreeBSD$
sizeof(addr.sun_path) - 1);
#ifdef HAVE_SOCKADDR_SA_LEN
addr.sun_len = strlen(addr.sun_path);
@@ -1198,12 +1521,12 @@
@@ -1199,12 +1535,12 @@
fd = socket(AF_LOCAL, SOCK_STREAM, 0);
if (fd < 0) {
LOG(L_ERR, "ERROR: send_rtpp_command: can't create socket\n");
@ -980,7 +1005,7 @@ $FreeBSD$
}
do {
@@ -1212,7 +1535,7 @@
@@ -1213,7 +1549,7 @@
if (len <= 0) {
close(fd);
LOG(L_ERR, "ERROR: send_rtpp_command: can't send command to a RTP proxy\n");
@ -989,7 +1014,7 @@ $FreeBSD$
}
do {
len = read(fd, buf, sizeof(buf) - 1);
@@ -1220,38 +1543,38 @@
@@ -1221,38 +1557,38 @@
close(fd);
if (len <= 0) {
LOG(L_ERR, "ERROR: send_rtpp_command: can't read reply from a RTP proxy\n");
@ -1035,7 +1060,7 @@ $FreeBSD$
}
if (len >= (v[0].iov_len - 1) &&
memcmp(buf, v[0].iov_base, (v[0].iov_len - 1)) == 0) {
@@ -1269,28 +1592,97 @@
@@ -1270,28 +1606,97 @@
if (i == rtpproxy_retr) {
LOG(L_ERR, "ERROR: send_rtpp_command: "
"timeout waiting reply from a RTP proxy\n");
@ -1140,7 +1165,7 @@ $FreeBSD$
if (get_callid(msg, &callid) == -1 || callid.len == 0) {
LOG(L_ERR, "ERROR: unforce_rtp_proxy: can't get Call-Id field\n");
return -1;
@@ -1306,29 +1698,139 @@
@@ -1307,29 +1712,139 @@
STR2IOVEC(callid, v[3]);
STR2IOVEC(from_tag, v[5]);
STR2IOVEC(to_tag, v[7]);
@ -1151,10 +1176,10 @@ $FreeBSD$
+ return -1;
+ }
+ send_rtpp_command(node, v, (to_tag.len > 0) ? 8 : 6);
+
+ return 1;
+}
+
return 1;
}
+/*
+ * Auxiliary for some functions.
+ * Returns pointer to first character of found line, or NULL if no such line.
@ -1204,7 +1229,7 @@ $FreeBSD$
+ t = find_sdp_line(p + 2, plimit, linechar);
+ return t ? t : defptr;
+}
+
+static int
+alter_line(struct sip_msg *msg, str *where, str *what)
+{
@ -1218,9 +1243,9 @@ $FreeBSD$
+ LOG(L_ERR, "insert_new_lump_after() failed\n");
+ return 0;
+ }
return 1;
}
+ return 1;
+}
+
+/*
+ * The following macro is used in force_rtp_proxy2_f() and twice
+ * in start_moh()
@ -1289,7 +1314,7 @@ $FreeBSD$
v[1].iov_base=opts;
asymmetric = flookup = force = real = 0;
@@ -1373,13 +1875,6 @@
@@ -1374,13 +1889,6 @@
}
}
@ -1303,7 +1328,7 @@ $FreeBSD$
if (msg->first_line.type == SIP_REQUEST &&
msg->first_line.u.request.method_value == METHOD_INVITE) {
create = 1;
@@ -1408,14 +1903,7 @@
@@ -1409,14 +1917,7 @@
LOG(L_ERR, "ERROR: force_rtp_proxy2: can't get From tag\n");
return -1;
}
@ -1319,7 +1344,7 @@ $FreeBSD$
proxied = 0;
for (cp = body.s; (len = body.s + body.len - cp) >= ANORTPPROXY_LEN;) {
cp1 = ser_memmem(cp, ANORTPPROXY, len, ANORTPPROXY_LEN);
@@ -1429,88 +1917,198 @@
@@ -1430,88 +1931,198 @@
}
if (proxied != 0 && force == 0)
return -1;
@ -1594,7 +1619,7 @@ $FreeBSD$
if (proxied == 0) {
cp = pkg_malloc(ANORTPPROXY_LEN * sizeof(char));
@@ -1554,75 +2152,41 @@
@@ -1555,75 +2166,41 @@
return force_rtp_proxy1_f(msg, arg, NULL);
}

View File

@ -1,6 +1,9 @@
--- modules/nathelper/nathelper.h
$FreeBSD$
--- /dev/null
+++ modules/nathelper/nathelper.h
@@ -0,0 +1,74 @@
@@ -0,0 +1,76 @@
+/*
+ * $Id: patch-modules::nathelper::nathelper.h,v 1.2 2005/04/05 13:10:08 netch Exp $
+ *
@ -41,6 +44,8 @@
+/* Parameters from nathelper.c */
+extern struct socket_info* force_socket;
+
+int natpinger_child_init(int);
+int natpinger_cleanup(void);
+/* Functions from nathelper.c */
+int isnulladdr(str *, int);
+int get_to_tag(struct sip_msg* _m, str* _tag);

View File

@ -1,9 +1,9 @@
$FreeBSD$
--- modules/nathelper/natping.c.orig
--- /dev/null
+++ modules/nathelper/natping.c
@@ -0,0 +1,190 @@
@@ -0,0 +1,251 @@
+/* $Id: patch-modules::nathelper::natping.c,v 1.4 2005/04/27 13:35:34 sobomax Exp $
+ *
+ * Copyright (C) 2005 Porta Software Ltd
@ -31,6 +31,8 @@ $FreeBSD$
+ *
+ */
+
+#include <unistd.h>
+#include <signal.h>
+#include "../usrloc/usrloc.h"
+#include "../tm/tm_load.h"
+#include "../../dprint.h"
@ -50,6 +52,7 @@ $FreeBSD$
+ */
+char *natping_method = NULL;
+
+static pid_t aux_process = -1;
+static usrloc_api_t ul;
+/* TM bind */
+static struct tm_binds tmb;
@ -57,6 +60,7 @@ $FreeBSD$
+static const char sbuf[4] = {0, 0, 0, 0};
+
+static void natping(unsigned int ticks, void *param);
+static void natping_cycle(void);
+
+int
+natpinger_init(void)
@ -92,16 +96,70 @@ $FreeBSD$
+ return -1;
+ }
+
+ register_timer(natping, NULL, natping_interval);
+ /*
+ * Use timer only in single process. For forked SER,
+ * use separate process (see natpinger_child_init())
+ */
+ if (dont_fork)
+ register_timer(natping, NULL, natping_interval);
+ }
+
+ return 0;
+}
+
+int
+natpinger_child_init(int rank)
+{
+
+ /* If forking is prohibited, use only timer. */
+ if (dont_fork)
+ return 0;
+
+ /* don't do anything for main process and TCP manager process */
+ if (rank == PROC_MAIN || rank == PROC_TCP_MAIN)
+ return 0;
+
+ /* only child 1 will fork the aux process */
+ if (rank != 1)
+ return 0;
+
+ aux_process = fork();
+ if (aux_process == -1) {
+ LOG(L_ERR, "natping_child_init(): fork: %s\n", strerror(errno));
+ return -1;
+ }
+ if (aux_process == 0) {
+ natping_cycle();
+ /*UNREACHED*/
+ _exit(1);
+ }
+ return 0;
+}
+
+int
+natpinger_cleanup(void)
+{
+
+ if (aux_process != -1)
+ kill(aux_process, SIGTERM);
+ return 0;
+}
+
+static void
+natping_cycle(void)
+{
+
+ signal(SIGTERM, SIG_DFL); /* no special treat */
+ for(;;) {
+ sleep(natping_interval);
+ natping(0, NULL);
+ }
+}
+
+static void
+natping(unsigned int ticks, void *param)
+{
+ int rval;
+ int rval, n;
+ void *buf, *cp;
+ str c;
+ struct sip_uri curi;
@ -135,6 +193,7 @@ $FreeBSD$
+ return;
+ }
+ }
+ n = 0;
+
+ if (buf == NULL)
+ return;
@ -144,6 +203,8 @@ $FreeBSD$
+ memcpy(&(c.len), cp, sizeof(c.len));
+ if (c.len == 0)
+ break;
+ if ((++n % 50) == 0)
+ usleep(1);
+ c.s = (char*)cp + sizeof(c.len);
+ cp = (char*)cp + sizeof(c.len) + c.len;
+ if (parse_uri(c.s, c.len, &curi) < 0) {