Add ser 0.8.11, a very fast and configurable SIP proxy.

This commit is contained in:
Maxim Sobolev 2003-09-14 16:51:56 +00:00
parent 4e90ca4aa5
commit f0fb6b9efa
Notes: svn2git 2021-03-31 03:12:20 +00:00
svn path=/head/; revision=88981
17 changed files with 1069 additions and 0 deletions

View file

@ -592,6 +592,7 @@
SUBDIR += sdl_net
SUBDIR += sendfile
SUBDIR += sendip
SUBDIR += ser
SUBDIR += serveez
SUBDIR += sharity-light
SUBDIR += silc-client

45
net/ser/Makefile Normal file
View file

@ -0,0 +1,45 @@
# New ports collection makefile for: ser
# Date created: 6 November 2002
# Whom: andrei
#
# $FreeBSD$
#
PORTNAME= ser
PORTVERSION= 0.8.11
CATEGORIES= net
MASTER_SITES= ftp://ftp.berlios.de/pub/ser/${PORTVERSION}/src/
DISTNAME= ${PORTNAME}-${PORTVERSION}_src
MAINTAINER= sobomax@FreeBSD.org
COMMENT= A very fast and configurable SIP proxy
BUILD_DEPENDS= ${LOCALBASE}/lib/mysql/libmysqlclient.a:${PORTSDIR}/databases/mysql40-client
LIB_DEPENDS= radiusclient.0:${PORTSDIR}/net/radiusclient
RUN_DEPENDS= ${LOCALBASE}/lib/mysql/libmysqlclient.a:${PORTSDIR}/databases/mysql40-client
WRKSRC= ${WRKDIR}/${PORTNAME}-${PORTVERSION}
USE_GMAKE= yes
CFLAGS+= -I${LOCALBASE}/include
MAN8= ser.8
MAN5= ser.cfg.5
MANCOMPRESSED= no
post-install:
${SED} 's|%%LOCALBASE%%|${LOCALBASE}|g ; s|%%PREFIX%%|${PREFIX}|g' \
${WRKSRC}/modules/acc/etc/radiusclient.conf > \
${WRKDIR}/radiusclient.conf
${INSTALL_DATA} ${WRKSRC}/modules/acc/etc/sip_dictionary \
${PREFIX}/etc/ser
${INSTALL_DATA} ${WRKSRC}/modules/acc/etc/servers \
${PREFIX}/etc/ser/servers.sample
${INSTALL_DATA} ${WRKDIR}/radiusclient.conf \
${PREFIX}/etc/ser/radiusclient.conf.default
if [ ! -e ${PREFIX}/etc/ser/radiusclient.conf ]; then \
${INSTALL_DATA} ${WRKDIR}/radiusclient.conf \
${PREFIX}/etc/ser/radiusclient.conf; \
fi
.include <bsd.port.mk>

1
net/ser/distinfo Normal file
View file

@ -0,0 +1 @@
MD5 (ser-0.8.11_src.tar.gz) = 47510a4794f6d8bb788e49eaa31e0b63

View file

@ -0,0 +1,38 @@
$FreeBSD$
--- Makefile.orig Fri Aug 29 19:58:39 2003
+++ Makefile Wed Sep 10 19:38:09 2003
@@ -46,8 +46,8 @@
exclude_modules?= cpl cpl-c ext extcmd mangler pdt \
postgres snmp \
im radius_acc radius_auth \
- jabber mysql \
- auth_radius group_radius uri_radius
+ jabber \
+ group_radius uri_radius
# always exclude the CVS dir
override exclude_modules+= CVS $(skip_modules)
@@ -247,7 +247,7 @@
chmod 644 $(cfg-prefix)/$(cfg-dir)ser.cfg.sample
if [ -z "${skip_cfg_install}" -a \
! -f $(cfg-prefix)/$(cfg-dir)ser.cfg ]; then \
- mv -f $(cfg-prefix)/$(cfg-dir)ser.cfg.sample \
+ cp $(cfg-prefix)/$(cfg-dir)ser.cfg.sample \
$(cfg-prefix)/$(cfg-dir)ser.cfg; \
fi
# $(INSTALL-CFG) etc/ser.cfg $(cfg-prefix)/$(cfg-dir)
@@ -256,10 +256,10 @@
$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/ser
$(INSTALL-BIN) ser $(bin-prefix)/$(bin-dir)
$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/sc
- $(INSTALL-BIN) scripts/sc $(bin-prefix)/$(bin-dir)
+ $(INSTALL-SCRIPT) scripts/sc $(bin-prefix)/$(bin-dir)
mv -f $(bin-prefix)/$(bin-dir)/sc $(bin-prefix)/$(bin-dir)/serctl
$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/ser_mysql.sh
- $(INSTALL-BIN) scripts/ser_mysql.sh $(bin-prefix)/$(bin-dir)
+ $(INSTALL-SCRIPT) scripts/ser_mysql.sh $(bin-prefix)/$(bin-dir)
$(INSTALL-TOUCH) $(bin-prefix)/$(bin-dir)/gen_ha1
$(INSTALL-BIN) utils/gen_ha1/gen_ha1 $(bin-prefix)/$(bin-dir)

View file

@ -0,0 +1,82 @@
$FreeBSD$
--- Makefile.defs.orig Mon Sep 1 20:47:57 2003
+++ Makefile.defs Wed Sep 10 19:39:20 2003
@@ -114,10 +114,11 @@
INSTALL-TOUCH = touch # used to create the file first (good to
# make solaris install work)
# INSTALL-CFG = $(INSTALL) -m 644
-INSTALL-BIN = $(INSTALL) -m 755
-INSTALL-MODULES = $(INSTALL) -m 755
-INSTALL-DOC = $(INSTALL) -m 644
-INSTALL-MAN = $(INSTALL) -m 644
+INSTALL-BIN = $(BSD_INSTALL_PROGRAM)
+INSTALL-MODULES = $(BSD_INSTALL_PROGRAM)
+INSTALL-DOC = $(BSD_INSTALL_MAN)
+INSTALL-MAN = $(BSD_INSTALL_MAN)
+INSTALL-SCRIPT = $(BSD_INSTALL_SCRIPT)
#set some vars from the environment (and not make builtins)
CC := $(shell echo "$${CC}")
@@ -265,10 +266,10 @@
-DSHM_MEM -DSHM_MMAP \
-DADAPTIVE_WAIT -DADAPTIVE_WAIT_LOOPS=1024 \
-DDNS_IP_HACK \
- -DUSE_IPV6 \
- -DUSE_TCP \
-DDISABLE_NAGLE \
- -DF_MALLOC \
+ #-DUSE_IPV6 \
+ #-DUSE_TCP \
+ #-DF_MALLOC \
# -DDBG_QM_MALLOC \
#-DF_MALLOC \
#-DNO_DEBUG \
@@ -374,8 +375,8 @@
found_lock_method=yes
endif
-CFLAGS=
-LDFLAGS=
+#CFLAGS=
+#LDFLAGS=
# setting CFLAGS
ifeq ($(mode), release)
#if i386
@@ -383,7 +384,7 @@
# if gcc
ifeq ($(CC_NAME), gcc)
#common stuff
- CFLAGS=-g -O9 -funroll-loops -Wcast-align $(PROFILE) \
+ CFLAGS+=-funroll-loops -Wcast-align $(PROFILE) \
-Wall \
#if gcc 3.0
ifeq ($(CC_SHORTVER), 3.0)
@@ -409,7 +410,7 @@
else # CC_NAME, gcc
ifeq ($(CC_NAME), icc)
- CFLAGS=-g -O3 -ipo -ipo_obj -unroll $(PROFILE) \
+ CFLAGS+=-ipo -ipo_obj -unroll $(PROFILE) \
-tpp6 -xK #-openmp #optimize for PIII
# -prefetch doesn't seem to work
#( ty to inline acroos files, unroll loops,prefetch,
@@ -428,7 +429,7 @@
#if gcc
ifeq ($(CC_NAME), gcc)
#common stuff
- CFLAGS=-g -O9 -funroll-loops $(PROFILE) \
+ CFLAGS+=-funroll-loops $(PROFILE) \
-Wall\
#-Wcast-align \
#-Wmissing-prototypes
@@ -486,7 +487,7 @@
# if gcc
ifeq ($(CC_NAME), gcc)
#common stuff
- CFLAGS=-O9 -funroll-loops -Wcast-align $(PROFILE) \
+ CFLAGS+=-funroll-loops -Wcast-align $(PROFILE) \
-Wall \
#if gcc 3.0
ifeq ($(CC_SHORTVER), 3.0)

View file

@ -0,0 +1,14 @@
$FreeBSD$
--- modules/acc/acc_mod.c 2003/07/06 18:04:54 1.1
+++ modules/acc/acc_mod.c 2003/07/06 18:05:26
@@ -92,7 +92,7 @@
int log_level=L_NOTICE;
char *log_fmt=DEFAULT_LOG_FMT;
#ifdef RAD_ACC
-char *radius_config = "/usr/local/etc/radiusclient/radiusclient.conf";
+char *radius_config = (CFG_DIR "radiusclient.conf");
int radius_flag = 0;
int radius_missed_flag = 0;
int service_type = PW_SIP;

View file

@ -0,0 +1,42 @@
$FreeBSD$
--- modules/acc/etc/radiusclient.conf 2003/07/06 17:56:08 1.1
+++ modules/acc/etc/radiusclient.conf 2003/07/06 17:57:54
@@ -22,7 +22,7 @@
# name of the issue file. it's only display when no username is passed
# on the radlogin command line
-issue /usr/local/etc/radiusclient/issue
+issue %%LOCALBASE%%/etc/radiusclient/issue
# RADIUS settings
@@ -44,23 +44,23 @@
# file holding shared secrets used for the communication
# between the RADIUS client and server
-servers /home/jiri/sip_router/modules/acc/etc/servers
+servers %%PREFIX%%/etc/ser/servers
# dictionary of allowed attributes and values
# just like in the normal RADIUS distributions
-dictionary /home/jiri/sip_router/modules/acc/etc/sip_dictionary
+dictionary %%PREFIX%%/etc/ser/sip_dictionary
# program to call for a RADIUS authenticated login
-login_radius /usr/local/sbin/login.radius
+login_radius %%LOCALBASE%%/sbin/login.radius
# file which holds sequence number for communication with the
# RADIUS server
seqfile /var/run/radius.seq
# file which specifies mapping between ttyname and NAS-Port attribute
-mapfile /usr/local/etc/radiusclient/port-id-map
+mapfile %%LOCALBASE%%/etc/radiusclient/port-id-map
# default authentication realm to append to all usernames if no
# realm was explicitly specified by the user

View file

@ -0,0 +1,14 @@
$FreeBSD$
--- modules/auth_radius/authrad_mod.c.orig Sat May 3 00:36:29 2003
+++ modules/auth_radius/authrad_mod.c Mon Sep 8 01:28:58 2003
@@ -59,7 +59,7 @@
/*
* Module parameter variables
*/
-char* radius_config = "/usr/local/etc/radiusclient/radiusclient.conf";
+char* radius_config = (CFG_DIR "radiusclient.conf");
int service_type = PW_SIP;

View file

@ -0,0 +1,14 @@
$FreeBSD$
--- modules/group_radius/grouprad_mod.c 2003/07/06 18:04:54 1.1
+++ modules/group_radius/grouprad_mod.c 2003/07/06 18:05:41
@@ -52,7 +52,7 @@
/*
* Module parameter variables
*/
-char* radius_config = "/usr/local/etc/radiusclient/radiusclient.conf";
+char* radius_config = (CFG_DIR "radiusclient.conf");
int use_domain = 1; /* By default we use domain */

View file

@ -0,0 +1,15 @@
$FreeBSD$
--- modules/nathelper/README.orig Sun Jul 6 17:32:22 2003
+++ modules/nathelper/README Sun Jul 6 20:53:30 2003
@@ -43,3 +43,9 @@
address with source address of the message)
Desc: Rewrites SDP body in accordance with mode flag
Example: if (search("User-Agent: Cisco ATA.*") {fix_nated_sdp(3);};
+
+Name: force_rtp_proxy
+Params: none
+Desc: Rewrites SDP body to ensure that media is passed throuth RTP
+ proxy
+Example: if (search("User-Agent: Cisco ATA.*") {force_rtp_proxy(3);};

View file

@ -0,0 +1,649 @@
$FreeBSD$
--- modules/nathelper/nathelper.c.orig Mon Jun 23 22:34:37 2003
+++ modules/nathelper/nathelper.c Sat Aug 2 09:03:54 2003
@@ -5,6 +5,10 @@
* we received this message from
* fix_nated_sdp() - replaces IP address in the SDP with IP address
* and/or adds direction=active option to the SDP
+ * force_rtp_proxy() - rewrite IP address and UDP port in the SDP
+ * body in such a way that RTP traffic visits
+ * RTP proxy running on the same machine as a
+ * ser itself
*
* Beware, those functions will only work correctly if the UA supports
* symmetric signalling and media (not all do)!!!
@@ -48,9 +52,15 @@
#include "../../timer.h"
#include "../../ut.h"
#include "../registrar/sip_msg.h"
+#include <sys/types.h>
+#include <sys/uio.h>
+#include <sys/un.h>
+#include <ctype.h>
+#include <errno.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
+#include <unistd.h>
MODULE_VERSION
@@ -58,6 +68,14 @@
static int fix_nated_sdp_f(struct sip_msg *, char *, char *);
static int update_clen(struct sip_msg *, int);
static int extract_mediaip(str *, str *);
+static int extract_mediaport(str *, str *);
+static int alter_mediaip(struct sip_msg *, str *, str *, str *, int *, int);
+static int alter_mediaport(struct sip_msg *, str *, str *, str *, int *, int);
+static int fixate_sdp_f(struct sip_msg *, char *, char *);
+static char *send_rtpp_command(str *, char, int);
+static int unforce_rtp_proxy_f(struct sip_msg *, char *, char *);
+static int force_rtp_proxy_f(struct sip_msg *, char *, char *);
+
static void timer(unsigned int, void *);
inline static int fixup_str2int(void**, int);
static int mod_init(void);
@@ -71,12 +89,15 @@
static cmd_export_t cmds[]={
{"fix_nated_contact", fix_nated_contact_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
{"fix_nated_sdp", fix_nated_sdp_f, 1, fixup_str2int, REQUEST_ROUTE | ONREPLY_ROUTE },
- {0,0,0,0,0}
+ {"fixate_sdp", fixate_sdp_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
+ {"force_rtp_proxy", force_rtp_proxy_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
+ {"unforce_rtp_proxy", unforce_rtp_proxy_f, 0, 0, REQUEST_ROUTE | ONREPLY_ROUTE },
+ {0, 0, 0, 0, 0}
};
static param_export_t params[]={
{"natping_interval", INT_PARAM, &natping_interval},
- {0,0,0}
+ {0, 0, 0}
};
struct module_exports exports={
@@ -268,21 +289,28 @@
#define ADD_ADIRECTION 0x01
#define FIX_MEDIAIP 0x02
+#define ADD_ANORTPPROXY 0x04
#define ADIRECTION "a=direction:active\r\n"
-#define ADIRECTION_LEN 21
+#define ADIRECTION_LEN 20
#define AOLDMEDIAIP "a=oldmediaip:"
#define AOLDMEDIAIP_LEN 13
+#define AOLDMEDIPRT "a=oldmediaport:"
+#define AOLDMEDIPRT_LEN 15
+
+#define ANORTPPROXY "a=nortpproxy:yes\r\n"
+#define ANORTPPROXY_LEN 18
+
#define CLEN_LEN 10
static int
fix_nated_sdp_f(struct sip_msg* msg, char* str1, char* str2)
{
- str body, mediaip;
- int level, added_len, offset, len;
- char *buf, *cp;
+ str body, body1, oldip, oldip1, newip;
+ int level, added_len;
+ char *buf;
struct lump* anchor;
level = (int)(long)str1;
@@ -293,82 +321,66 @@
return -1;
}
- if (level & ADD_ADIRECTION) {
+ if (level & (ADD_ADIRECTION | ADD_ANORTPPROXY)) {
anchor = anchor_lump(&(msg->add_rm),
body.s + body.len - msg->buf, 0, 0);
if (anchor == NULL) {
LOG(L_ERR, "ERROR: fix_nated_sdp: anchor_lump failed\n");
return -1;
}
- buf = pkg_malloc(ADIRECTION_LEN * sizeof(char));
- if (buf == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");
- return -1;
+ if (level & ADD_ADIRECTION) {
+ buf = pkg_malloc(ADIRECTION_LEN * sizeof(char));
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");
+ return -1;
+ }
+ memcpy(buf, ADIRECTION, ADIRECTION_LEN);
+ if (insert_new_lump_after(anchor, buf, ADIRECTION_LEN, 0) == NULL) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ added_len += ADIRECTION_LEN;
}
- memcpy(buf, ADIRECTION, ADIRECTION_LEN);
- if (insert_new_lump_after(anchor, buf, ADIRECTION_LEN - 1, 0) == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");
- pkg_free(buf);
- return -1;
+ if (level & ADD_ANORTPPROXY) {
+ buf = pkg_malloc(ANORTPPROXY_LEN * sizeof(char));
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");
+ return -1;
+ }
+ memcpy(buf, ANORTPPROXY, ANORTPPROXY_LEN);
+ if (insert_new_lump_after(anchor, buf, ANORTPPROXY_LEN, 0) == NULL) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ added_len += ANORTPPROXY_LEN;
}
- added_len += ADIRECTION_LEN - 1;
}
if (level & FIX_MEDIAIP) {
- if (extract_mediaip(&body, &mediaip) == -1) {
+ if (extract_mediaip(&body, &oldip) == -1) {
LOG(L_ERR, "ERROR: fix_nated_sdp: can't extract media IP from the SDP\n");
goto finalise;
}
-
- /* check that updating mediaip is really necessary */
- if (7 == mediaip.len && memcmp("0.0.0.0", mediaip.s, 7) == 0)
- goto finalise;
- cp = ip_addr2a(&msg->rcv.src_ip);
- len = strlen(cp);
- if (len == mediaip.len && memcmp(cp, mediaip.s, len) == 0)
- goto finalise;
-
- anchor = anchor_lump(&(msg->add_rm),
- body.s + body.len - msg->buf, 0, 0);
- if (anchor == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: anchor_lump failed\n");
- return -1;
- }
- buf = pkg_malloc(AOLDMEDIAIP_LEN + mediaip.len + CRLF_LEN);
- if (buf == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");
- return -1;
- }
- memcpy(buf, AOLDMEDIAIP, AOLDMEDIAIP_LEN);
- memcpy(buf + AOLDMEDIAIP_LEN, mediaip.s, mediaip.len);
- memcpy(buf + AOLDMEDIAIP_LEN + mediaip.len, CRLF, CRLF_LEN);
- if (insert_new_lump_after(anchor, buf,
- AOLDMEDIAIP_LEN + mediaip.len + CRLF_LEN, 0) == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");
- pkg_free(buf);
- return -1;
+ body1.s = oldip.s + oldip.len;
+ body1.len = body.s + body.len - body1.s;
+ if (extract_mediaip(&body1, &oldip1) == -1) {
+ oldip1.len = 0;
}
- added_len += AOLDMEDIAIP_LEN + mediaip.len + CRLF_LEN;
- buf = pkg_malloc(len);
- if (buf == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: out of memory\n");
- return -1;
- }
- offset = mediaip.s - msg->buf;
- anchor = del_lump(&msg->add_rm, offset, mediaip.len, 0);
- if (anchor == NULL) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: del_lump failed\n");
- pkg_free(buf);
+ newip.s = ip_addr2a(&msg->rcv.src_ip);
+ newip.len = strlen(newip.s);
+ if (alter_mediaip(msg, &body, &oldip, &newip,
+ &added_len, 1) == -1) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: can't alter media IP");
return -1;
}
- memcpy(buf, cp, len);
- if (insert_new_lump_after(anchor, buf, len, 0) == 0) {
- LOG(L_ERR, "ERROR: fix_nated_sdp: insert_new_lump_after failed\n");
- pkg_free(buf);
+ if (oldip1.len > 0 && alter_mediaip(msg, &body, &oldip1, &newip,
+ &added_len, 0) == -1) {
+ LOG(L_ERR, "ERROR: fix_nated_sdp: can't alter media IP");
return -1;
}
- added_len += len - mediaip.len;
}
finalise:
@@ -425,7 +437,7 @@
cp = cp1 + 2;
}
if (cp1 == NULL) {
- LOG(L_ERR, "ERROR: extract_mediaip: no `c=' in SDP\n");
+ LOG(L_DBG, "ERROR: extract_mediaip: no `c=' in SDP\n");
return -1;
}
mediaip->s = cp1 + 2;
@@ -449,6 +461,418 @@
LOG(L_ERR, "ERROR: extract_mediaip: no `IP4' in `c=' field\n");
return -1;
}
+ return 1;
+}
+
+static int
+extract_mediaport(str *body, str *mediaport)
+{
+ char *cp, *cp1;
+ int len;
+
+ cp1 = NULL;
+ for (cp = body->s; (len = body->s + body->len - cp) > 0;) {
+ cp1 = ser_memmem(cp, "m=", len, 2);
+ if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
+ break;
+ cp = cp1 + 2;
+ }
+ if (cp1 == NULL) {
+ LOG(L_ERR, "ERROR: extract_mediaport: no `m=' in SDP\n");
+ return -1;
+ }
+ mediaport->s = cp1 + 2;
+ mediaport->len = eat_line(mediaport->s, body->s + body->len -
+ mediaport->s) - mediaport->s;
+ trim_len(mediaport->len, mediaport->s, *mediaport);
+
+ if (mediaport->len < 7 || memcmp(mediaport->s, "audio", 5) != 0 ||
+ !isspace(mediaport->s[5])) {
+ LOG(L_ERR, "ERROR: extract_mediaport: can't parse `m=' in SDP\n");
+ return -1;
+ }
+ cp = eat_space_end(mediaport->s + 5, mediaport->s + mediaport->len);
+ mediaport->len = eat_token_end(cp, mediaport->s + mediaport->len) - cp;
+ mediaport->s = cp;
+ return 1;
+}
+
+static int
+alter_mediaip(struct sip_msg *msg, str *body, str *oldip, str *newip,
+ int *clendelta, int preserve)
+{
+ char *buf;
+ int offset;
+ struct lump* anchor;
+
+ /* check that updating mediaip is really necessary */
+ if (7 == oldip->len && memcmp("0.0.0.0", oldip->s, 7) == 0)
+ return 0;
+ if (newip->len == oldip->len &&
+ memcmp(newip->s, oldip->s, newip->len) == 0)
+ return 0;
+
+ if (preserve != 0) {
+ anchor = anchor_lump(&(msg->add_rm),
+ body->s + body->len - msg->buf, 0, 0);
+ if (anchor == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaip: anchor_lump failed\n");
+ return -1;
+ }
+ buf = pkg_malloc(AOLDMEDIAIP_LEN + oldip->len + CRLF_LEN);
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaip: out of memory\n");
+ return -1;
+ }
+ memcpy(buf, AOLDMEDIAIP, AOLDMEDIAIP_LEN);
+ memcpy(buf + AOLDMEDIAIP_LEN, oldip->s, oldip->len);
+ memcpy(buf + AOLDMEDIAIP_LEN + oldip->len, CRLF, CRLF_LEN);
+ if (insert_new_lump_after(anchor, buf,
+ AOLDMEDIAIP_LEN + oldip->len + CRLF_LEN, 0) == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaip: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ *clendelta += AOLDMEDIAIP_LEN + oldip->len + CRLF_LEN;
+ }
+
+ buf = pkg_malloc(newip->len);
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaip: out of memory\n");
+ return -1;
+ }
+ offset = oldip->s - msg->buf;
+ anchor = del_lump(&msg->add_rm, offset, oldip->len, 0);
+ if (anchor == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaip: del_lump failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ memcpy(buf, newip->s, newip->len);
+ if (insert_new_lump_after(anchor, buf, newip->len, 0) == 0) {
+ LOG(L_ERR, "ERROR: alter_mediaip: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ *clendelta += newip->len - oldip->len;
+ return 0;
+}
+
+static int
+alter_mediaport(struct sip_msg *msg, str *body, str *oldport, str *newport,
+ int *clendelta, int preserve)
+{
+ char *buf;
+ int offset;
+ struct lump* anchor;
+
+ /* check that updating mediaport is really necessary */
+ if (newport->len == oldport->len &&
+ memcmp(newport->s, oldport->s, newport->len) == 0)
+ return 0;
+
+ if (preserve != 0) {
+ anchor = anchor_lump(&(msg->add_rm),
+ body->s + body->len - msg->buf, 0, 0);
+ if (anchor == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaport: anchor_lump failed\n");
+ return -1;
+ }
+ buf = pkg_malloc(AOLDMEDIPRT_LEN + oldport->len + CRLF_LEN);
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaport: out of memory\n");
+ return -1;
+ }
+ memcpy(buf, AOLDMEDIPRT, AOLDMEDIPRT_LEN);
+ memcpy(buf + AOLDMEDIPRT_LEN, oldport->s, oldport->len);
+ memcpy(buf + AOLDMEDIPRT_LEN + oldport->len, CRLF, CRLF_LEN);
+ if (insert_new_lump_after(anchor, buf,
+ AOLDMEDIPRT_LEN + oldport->len + CRLF_LEN, 0) == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaport: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ *clendelta += AOLDMEDIPRT_LEN + oldport->len + CRLF_LEN;
+ }
+
+ buf = pkg_malloc(newport->len);
+ if (buf == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaport: out of memory\n");
+ return -1;
+ }
+ offset = oldport->s - msg->buf;
+ anchor = del_lump(&msg->add_rm, offset, oldport->len, 0);
+ if (anchor == NULL) {
+ LOG(L_ERR, "ERROR: alter_mediaport: del_lump failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ memcpy(buf, newport->s, newport->len);
+ if (insert_new_lump_after(anchor, buf, newport->len, 0) == 0) {
+ LOG(L_ERR, "ERROR: alter_mediaport: insert_new_lump_after failed\n");
+ pkg_free(buf);
+ return -1;
+ }
+ *clendelta += newport->len - oldport->len;
+ return 0;
+}
+
+static int
+fixate_sdp_f(struct sip_msg* msg, char* str1, char* str2)
+{
+ char *cp, *cp1;
+ int len, cldelta;
+ str body, body1, newip, newip1, newport, dest, oldip, oldport;
+ struct sip_uri ruri;
+ struct hdr_field *hdr;
+ struct via_body *rvia;
+
+ if (msg->first_line.type == SIP_REQUEST &&
+ msg->first_line.u.request.method_value == METHOD_INVITE) {
+ LOG(L_ERR, "DEBUG: fixate_sdp: request\n");
+ if (msg->parsed_uri_ok) {
+ dest = msg->parsed_uri.host;
+ } else {
+ if (parse_uri(msg->new_uri.s, msg->new_uri.len, &ruri) < 0) {
+ LOG(L_ERR, "ERROR: fixate_sdp: can't parse request uri\n");
+ return -1;
+ }
+ dest = ruri.host;
+ }
+ } else if (msg->first_line.type == SIP_REPLY) {
+ LOG(L_ERR, "DEBUG: fixate_sdp: reply\n");
+ rvia = NULL;
+ for (hdr=msg->headers; hdr; hdr=hdr->next) {
+ if (hdr->type == HDR_VIA)
+ rvia = hdr->parsed;
+ }
+ if (rvia == NULL) {
+ LOG(L_ERR, "ERROR: fixate_sdp: no or incorrect Via in reply\n");
+ return -1;
+ }
+ if (rvia->received != NULL) {
+ dest = rvia->received->value;
+ } else {
+ dest = rvia->host;
+ }
+ } else {
+ return -1;
+ }
+
+ if (extract_body(msg, &body) == -1 || body.len == 0)
+ return -1;
+ if (extract_mediaip(&body, &newip) == -1) {
+ LOG(L_ERR, "ERROR: fixate_sdp: can't extract media IP from the SDP\n");
+ return -1;
+ }
+ body1.s = newip.s + newip.len;
+ body1.len = body.s + body.len - body1.s;
+ if (extract_mediaip(&body1, &newip1) == -1) {
+ newip1.len = 0;
+ }
+ if (newip.len != dest.len || memcmp(newip.s, dest.s, dest.len) != 0)
+ return -1;
+ if (extract_mediaport(&body, &newport) == -1) {
+ LOG(L_ERR, "ERROR: fixate_sdp: can't extract media port from the SDP\n");
+ return -1;
+ }
+
+ for (cp = body.s; (len = body.s + body.len - cp) >= AOLDMEDIAIP_LEN;) {
+ cp1 = ser_memmem(cp, AOLDMEDIAIP, len, AOLDMEDIAIP_LEN);
+ if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
+ break;
+ cp = cp1 + AOLDMEDIAIP_LEN;
+ }
+ if (cp1 == NULL) {
+ oldip.len = 0;
+ } else {
+ oldip.s = cp1 + AOLDMEDIAIP_LEN;
+ oldip.len = eat_line(oldip.s, body.s + body.len -
+ oldip.s) - oldip.s;
+ trim_len(oldip.len, oldip.s, oldip);
+ }
+ if (newip.len == oldip.len &&
+ memcmp(newip.s, oldip.s, newip.len) == 0)
+ oldip.len = 0;
+
+ for (cp = body.s; (len = body.s + body.len - cp) >= AOLDMEDIPRT_LEN;) {
+ cp1 = ser_memmem(cp, AOLDMEDIPRT, len, AOLDMEDIPRT_LEN);
+ if (cp1 == NULL || cp1[-1] == '\n' || cp1[-1] == '\r')
+ break;
+ cp = cp1 + AOLDMEDIPRT_LEN;
+ }
+ if (cp1 == NULL) {
+ oldport.len = 0;
+ } else {
+ oldport.s = cp1 + AOLDMEDIPRT_LEN;
+ oldport.len = eat_line(oldport.s, body.s + body.len -
+ oldport.s) - oldport.s;
+ trim_len(oldport.len, oldport.s, oldport);
+ }
+ if (newport.len == oldport.len &&
+ memcmp(newport.s, oldport.s, newport.len) == 0)
+ oldport.len = 0;
+
+ cldelta = 0;
+
+ if (oldip.len != 0) {
+ if (alter_mediaip(msg, &body, &newip, &oldip,
+ &cldelta, 0) == -1)
+ return -1;
+ if (newip1.len > 0 && alter_mediaip(msg, &body1, &newip1,
+ &oldip, &cldelta, 0) == -1)
+ return -1;
+ }
+ if (oldport.len != 0 &&
+ alter_mediaport(msg, &body, &newport, &oldport, &cldelta, 0) == -1)
+ return -1;
+
+ if (cldelta == 0)
+ return 1;
+
+ return (update_clen(msg, body.len + cldelta));
+}
+
+static char *
+send_rtpp_command(str *callid, char command, int getreply)
+{
+ struct sockaddr_un addr;
+ int fd, len;
+ struct iovec v[3];
+ static char buf[16];
+ char cmd[2] = {' ', ' '};
+
+ memset(&addr, 0, sizeof(addr));
+ addr.sun_family = AF_LOCAL;
+ strncpy(addr.sun_path, "/var/run/rtpproxy.sock",
+ sizeof(addr.sun_path) - 1);
+#if !defined(__linux__)
+ addr.sun_len = strlen(addr.sun_path);
+#endif
+
+ fd = socket(AF_LOCAL, SOCK_STREAM, 0);
+ if (fd < 0) {
+ LOG(L_ERR, "ERROR: send_rtpp_command: can't create socket\n");
+ return NULL;
+ }
+ if (connect(fd, (struct sockaddr *) &addr, sizeof(addr)) < 0) {
+ close(fd);
+ LOG(L_ERR, "ERROR: send_rtpp_command: can't connect to RTP proxy\n");
+ return NULL;
+ }
+
+ cmd[0] = command;
+ v[0].iov_base = cmd;
+ v[0].iov_len = 2;
+ v[1].iov_base = callid->s;
+ v[1].iov_len = callid->len;
+ v[2].iov_base = "\n";
+ v[2].iov_len = 1;
+ do {
+ len = writev(fd, v, 3);
+ } while (len == -1 && errno == EINTR);
+ if (len <= 0) {
+ close(fd);
+ LOG(L_ERR, "ERROR: send_rtpp_command: can't send command to a RTP proxy\n");
+ return NULL;
+ }
+
+ if (getreply != 0) {
+ do {
+ len = read(fd, buf, sizeof(buf) - 1);
+ } while (len == -1 && errno == EINTR);
+ close(fd);
+ if (len <= 0) {
+ LOG(L_ERR, "ERROR: send_rtpp_command: can't read reply from a RTP proxy\n");
+ return NULL;
+ }
+ buf[len] = '\0';
+ }
+
+ return buf;
+}
+
+static int
+unforce_rtp_proxy_f(struct sip_msg* msg, char* str1, char* str2)
+{
+
+ if (msg->callid == NULL || msg->callid->body.len <= 0) {
+ LOG(L_ERR, "ERROR: unforce_rtp_proxy: no Call-Id field\n");
+ return -1;
+ }
+ send_rtpp_command(&(msg->callid->body), 'D', 0);
+
+ return 1;
+}
+
+static int
+force_rtp_proxy_f(struct sip_msg* msg, char* str1, char* str2)
+{
+ str body, body1, oldport, oldip, oldip1, newport, newip;
+ int create, port, cldelta, len;
+ char buf[16];
+ char *cp, *cp1;
+
+ if (msg->first_line.type == SIP_REQUEST &&
+ msg->first_line.u.request.method_value == METHOD_INVITE) {
+ create = 1;
+ } else if (msg->first_line.type == SIP_REPLY) {
+ create = 0;
+ } else {
+ return -1;
+ }
+ if (msg->callid == NULL || msg->callid->body.len <= 0) {
+ LOG(L_ERR, "ERROR: force_rtp_proxy: no Call-Id field\n");
+ return -1;
+ }
+ if (extract_body(msg, &body) == -1 || body.len == 0)
+ return -1;
+ for (cp = body.s; (len = body.s + body.len - cp) >= ANORTPPROXY_LEN;) {
+ cp1 = ser_memmem(cp, ANORTPPROXY, len, ANORTPPROXY_LEN);
+ if (cp1 == NULL)
+ break;
+ if (cp1[-1] == '\n' || cp1[-1] == '\r')
+ return 1;
+ cp = cp1 + ANORTPPROXY_LEN;
+ }
+ if (extract_mediaip(&body, &oldip) == -1) {
+ LOG(L_ERR, "ERROR: force_rtp_proxy: can't extract media IP from the message\n");
+ return -1;
+ }
+ body1.s = oldip.s + oldip.len;
+ body1.len = body.s + body.len - body1.s;
+ if (extract_mediaip(&body1, &oldip1) == -1) {
+ oldip1.len = 0;
+ }
+ if (extract_mediaport(&body, &oldport) == -1) {
+ LOG(L_ERR, "ERROR: force_rtp_proxy: can't extract media port from the message\n");
+ return -1;
+ }
+ cp = send_rtpp_command(&(msg->callid->body), create ? 'U' : 'L', 1);
+ if (cp == NULL)
+ return -1;
+ port = atoi(cp);
+ if (port <= 0 || port > 65535)
+ return -1;
+
+ newport.s = buf;
+ newport.len = sprintf(buf, "%d", port);
+ newip.s = ip_addr2a(&msg->rcv.dst_ip);
+ newip.len = strlen(newip.s);
+
+ cldelta = 0;
+ if (alter_mediaip(msg, &body, &oldip, &newip, &cldelta, 0) == -1)
+ return -1;
+ if (oldip1.len > 0 &&
+ alter_mediaip(msg, &body1, &oldip1, &newip, &cldelta, 0) == -1)
+ return -1;
+ if (alter_mediaport(msg, &body, &oldport, &newport, &cldelta, 0) == -1)
+ return -1;
+
+ if (cldelta == 0)
+ return 1;
+
+ return (update_clen(msg, body.len + cldelta));
return 1;
}

View file

@ -0,0 +1,14 @@
$FreeBSD$
--- modules/postgres/Makefile.orig Wed Jul 30 19:34:46 2003
+++ modules/postgres/Makefile Wed Sep 10 19:40:11 2003
@@ -7,7 +7,7 @@
NAME=postgres.so
# libpq-fe.h locations
-DEFS +=-I/usr/local/pgsql/include -I/usr/include/postgresql
+DEFS +=-I$(LOCALBASE)/pgsql/include -I/usr/include/postgresql
LIBS=-L$(LOCALBASE)/pgsql/lib -L$(LOCALBASE)/lib/pgsql -L/usr/pkg/lib \
-L/usr/pkg/lib/pgsql -lpq

View file

@ -0,0 +1,25 @@
$FreeBSD$
--- modules/tm/t_lookup.c 2003/07/29 04:01:00 1.1
+++ modules/tm/t_lookup.c 2003/07/29 04:05:47
@@ -94,8 +94,8 @@
#include "t_lookup.h"
#define EQ_VIA_LEN(_via)\
- ( (p_msg->via1->bsize-(p_msg->_via->name.s-(p_msg->_via->hdr.s+p_msg->_via->hdr.len)))==\
- (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len))) )
+ ( (p_msg->_via->port_str.s + p_msg->_via->port_str.len - p_msg->_via->name.s)==\
+ (t_msg->_via->port_str.s + t_msg->_via->port_str.len - t_msg->_via->name.s) )
@@ -113,7 +113,7 @@
#define EQ_VIA_STR(_via)\
( memcmp( t_msg->_via->name.s,\
p_msg->_via->name.s,\
- (t_msg->via1->bsize-(t_msg->_via->name.s-(t_msg->_via->hdr.s+t_msg->_via->hdr.len)))\
+ (t_msg->_via->port_str.s+t_msg->_via->port_str.len - t_msg->_via->name.s)\
)==0 )

View file

@ -0,0 +1,14 @@
$FreeBSD$
--- modules/uri_radius/urirad_mod.c 2003/07/06 18:04:54 1.1
+++ modules/uri_radius/urirad_mod.c 2003/07/06 18:05:59
@@ -48,7 +48,7 @@
/*
* Module parameter variables
*/
-char* radius_config = "/usr/local/etc/radiusclient/radiusclient.conf";
+char* radius_config = (CFG_DIR "radiusclient.conf");
int service_type = PW_CALL_CHECK;
/*

View file

@ -0,0 +1,16 @@
$FreeBSD$
--- udp_server.c.orig Sat Jun 21 21:38:32 2003
+++ udp_server.c Sun Jul 6 20:53:30 2003
@@ -326,6 +326,10 @@
continue; /* goto skip;*/
else goto error;
}
+ if (len < 8) {
+ /* Message is too short, just drop it already */
+ continue;
+ }
/* we must 0-term the messages, receive_msg expects it */
buf[len]=0; /* no need to save the previous char */

15
net/ser/pkg-descr Normal file
View file

@ -0,0 +1,15 @@
ser or SIP Express Router is a very fast and flexible SIP (RFC3621)
proxy server. Written entirely in C, ser can handle thousands calls
per second even on low-budget hardware. C Shell like scripting language
provides full control over the server's behaviour. It's modular
architecture allows only required functionality to be loaded.
Currently the following modules are available: Digest Authentication,
CPL scripts, Instant Messaging, MySQL support, Presence Agent, Radius
Authentication, Record Routing, SMS Gateway, Jabber Gateway, Transaction
Module, Registrar and User Location.
WWW: http://www.iptel.org/ser/
- Andrei Pelinescu-Onciul
pelinescu-onciul@fokus.gmd.de

70
net/ser/pkg-plist Normal file
View file

@ -0,0 +1,70 @@
etc/ser/radiusclient.conf.default
etc/ser/ser.cfg.sample
etc/ser/servers.sample
etc/ser/sip_dictionary
lib/ser/modules/acc.so
lib/ser/modules/auth.so
lib/ser/modules/auth_db.so
lib/ser/modules/auth_radius.so
lib/ser/modules/dbtext.so
lib/ser/modules/domain.so
lib/ser/modules/enum.so
lib/ser/modules/exec.so
lib/ser/modules/group.so
lib/ser/modules/maxfwd.so
lib/ser/modules/msilo.so
lib/ser/modules/mysql.so
lib/ser/modules/nathelper.so
lib/ser/modules/pa.so
lib/ser/modules/permissions.so
lib/ser/modules/pike.so
lib/ser/modules/print.so
lib/ser/modules/registrar.so
lib/ser/modules/rr.so
lib/ser/modules/sl.so
lib/ser/modules/sms.so
lib/ser/modules/textops.so
lib/ser/modules/tm.so
lib/ser/modules/uri.so
lib/ser/modules/usrloc.so
lib/ser/modules/xlog.so
lib/ser/modules/vm.so
sbin/gen_ha1
sbin/ser
sbin/ser_mysql.sh
sbin/serctl
share/doc/ser/AUTHORS
share/doc/ser/INSTALL
share/doc/ser/NEWS
share/doc/ser/README
share/doc/ser/README-MODULES
share/doc/ser/README.acc
share/doc/ser/README.auth
share/doc/ser/README.auth_db
share/doc/ser/README.auth_radius
share/doc/ser/README.dbtext
share/doc/ser/README.domain
share/doc/ser/README.enum
share/doc/ser/README.exec
share/doc/ser/README.group
share/doc/ser/README.maxfwd
share/doc/ser/README.msilo
share/doc/ser/README.nathelper
share/doc/ser/README.pa
share/doc/ser/README.permissions
share/doc/ser/README.pike
share/doc/ser/README.print
share/doc/ser/README.registrar
share/doc/ser/README.rr
share/doc/ser/README.sl
share/doc/ser/README.sms
share/doc/ser/README.textops
share/doc/ser/README.tm
share/doc/ser/README.uri
share/doc/ser/README.usrloc
share/doc/ser/README.xlog
share/doc/ser/README.vm
@dirrm share/doc/ser
@dirrm lib/ser/modules
@dirrm lib/ser
@dirrm etc/ser