Merge branch 'master' of git.mgm.sipwise.com:mediaproxy-ng

pull/16/head
Richard Fuchs 12 years ago
commit 93ab835686

@ -7,7 +7,16 @@ CFLAGS+= `pkg-config --cflags openssl`
CFLAGS+= `pcre-config --cflags`
CFLAGS+= -I/lib/modules/`uname -r`/build/include/ -I../kernel-module/
CFLAGS+= -D_GNU_SOURCE
CFLAGS+= -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\""
ifneq ($(MEDIAPROXY_VERSION),)
CFLAGS+= -DMEDIAPROXY_VERSION="\"$(MEDIAPROXY_VERSION)\""
else
DPKG_PRSCHNGLG= $(shell which dpkg-parsechangelog 2>/dev/null)
ifneq ($(DPKG_PRSCHNGLG),)
CFLAGS+= -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\""
else
CFLAGS+= -DMEDIAPROXY_VERSION="\"undefined\""
endif
endif
CFLAGS+= -DMP_PLUGIN_DIR="\"/usr/lib/mediaproxy-ng\""
#CFLAGS+= -DSRTCP_KEY_DERIVATION_RFC_COMPLIANCE
@ -27,10 +36,13 @@ LDFLAGS+= `pcre-config --libs`
LDFLAGS+= `xmlrpc-c-config client --libs`
ifneq ($(DBG),yes)
# support http://wiki.debian.org/Hardening for >=wheezy
CFLAGS+= `dpkg-buildflags --get CFLAGS`
CPPFLAGS+= `dpkg-buildflags --get CPPFLAGS`
LDFLAGS+= `dpkg-buildflags --get LDFLAGS`
DPKG_BLDFLGS= $(shell which dpkg-buildflags 2>/dev/null)
ifneq ($(DPKG_BLDFLGS),)
# support http://wiki.debian.org/Hardening for >=wheezy
CFLAGS+= `dpkg-buildflags --get CFLAGS`
CPPFLAGS+= `dpkg-buildflags --get CPPFLAGS`
LDFLAGS+= `dpkg-buildflags --get LDFLAGS`
endif
endif
SRCS= main.c kernel.c poller.c aux.c control_tcp.c streambuf.c call.c control_udp.c redis.c \

@ -500,6 +500,41 @@ dummy:
in->handler = &__sh_noop;
}
void callmaster_msg_mh_src(struct callmaster *cm, struct msghdr *mh) {
struct cmsghdr *ch;
struct in_pktinfo *pi;
struct in6_pktinfo *pi6;
struct sockaddr_in6 *sin6;
sin6 = mh->msg_name;
ch = CMSG_FIRSTHDR(mh);
ZERO(*ch);
if (IN6_IS_ADDR_V4MAPPED(&sin6->sin6_addr)) {
ch->cmsg_len = CMSG_LEN(sizeof(*pi));
ch->cmsg_level = IPPROTO_IP;
ch->cmsg_type = IP_PKTINFO;
pi = (void *) CMSG_DATA(ch);
ZERO(*pi);
pi->ipi_spec_dst.s_addr = cm->conf.ipv4;
mh->msg_controllen = CMSG_SPACE(sizeof(*pi));
}
else {
ch->cmsg_len = CMSG_LEN(sizeof(*pi6));
ch->cmsg_level = IPPROTO_IPV6;
ch->cmsg_type = IPV6_PKTINFO;
pi6 = (void *) CMSG_DATA(ch);
ZERO(*pi6);
pi6->ipi6_addr = cm->conf.ipv6;
mh->msg_controllen = CMSG_SPACE(sizeof(*pi6));
}
}
/* called with r->up (== cs) locked */
static int stream_packet(struct streamrelay *sr_incoming, str *s, struct sockaddr_in6 *fsin) {
struct streamrelay *sr_outgoing, *sr_out_rtcp, *sr_in_rtcp;
@ -510,9 +545,6 @@ static int stream_packet(struct streamrelay *sr_incoming, str *s, struct sockadd
struct msghdr mh;
struct iovec iov;
unsigned char buf[256];
struct cmsghdr *ch;
struct in_pktinfo *pi;
struct in6_pktinfo *pi6;
struct call *c;
struct callmaster *m;
unsigned char cc;
@ -625,9 +657,6 @@ forward:
mh.msg_control = buf;
mh.msg_controllen = sizeof(buf);
ch = CMSG_FIRSTHDR(&mh);
ZERO(*ch);
ZERO(sin6);
sin6.sin6_family = AF_INET6;
sin6.sin6_addr = sr_incoming->peer.ip46;
@ -635,28 +664,7 @@ forward:
mh.msg_name = &sin6;
mh.msg_namelen = sizeof(sin6);
if (IN6_IS_ADDR_V4MAPPED(&sin6.sin6_addr)) {
ch->cmsg_len = CMSG_LEN(sizeof(*pi));
ch->cmsg_level = IPPROTO_IP;
ch->cmsg_type = IP_PKTINFO;
pi = (void *) CMSG_DATA(ch);
ZERO(*pi);
pi->ipi_spec_dst.s_addr = m->conf.ipv4;
mh.msg_controllen = CMSG_SPACE(sizeof(*pi));
}
else {
ch->cmsg_len = CMSG_LEN(sizeof(*pi6));
ch->cmsg_level = IPPROTO_IPV6;
ch->cmsg_type = IPV6_PKTINFO;
pi6 = (void *) CMSG_DATA(ch);
ZERO(*pi6);
pi6->ipi6_addr = m->conf.ipv6;
mh.msg_controllen = CMSG_SPACE(sizeof(*pi6));
}
callmaster_msg_mh_src(m, &mh);
ZERO(iov);
iov.iov_base = s->s;

@ -183,6 +183,7 @@ struct callmaster *callmaster_new(struct poller *);
void callmaster_config(struct callmaster *m, struct callmaster_config *c);
void callmaster_exclude_port(struct callmaster *m, u_int16_t p);
int callmaster_has_ipv6(struct callmaster *);
void callmaster_msg_mh_src(struct callmaster *, struct msghdr *);
str *call_request_tcp(char **, struct callmaster *);

@ -85,7 +85,7 @@ static u_int32_t redis_ip;
static u_int16_t redis_port;
static int redis_db = -1;
static char *b2b_url;
static int log_level = LOG_INFO;
@ -97,6 +97,8 @@ static void sighandler(gpointer x) {
sigemptyset(&ss);
sigaddset(&ss, SIGINT);
sigaddset(&ss, SIGTERM);
sigaddset(&ss, SIGUSR1);
sigaddset(&ss, SIGUSR2);
ts.tv_sec = 0;
ts.tv_nsec = 100000000; /* 0.1 sec */
@ -108,9 +110,23 @@ static void sighandler(gpointer x) {
continue;
abort();
}
if (ret == SIGINT || ret == SIGTERM)
global_shutdown = 1;
else if (ret == SIGUSR1) {
if (log_level > 0) {
log_level--;
setlogmask(LOG_UPTO(log_level));
mylog(log_level, "Set log level to %d\n", log_level);
}
}
else if (ret == SIGUSR2) {
if (log_level < 7) {
log_level++;
setlogmask(LOG_UPTO(log_level));
mylog(log_level, "Set log level to %d\n", log_level);
}
}
else
abort();
}
@ -236,6 +252,7 @@ static void options(int *argc, char ***argv) {
{ "redis", 'r', 0, G_OPTION_ARG_STRING, &redisps, "Connect to Redis database", "IP:PORT" },
{ "redis-db", 'R', 0, G_OPTION_ARG_INT, &redis_db, "Which Redis DB to use", "INT" },
{ "b2b-url", 'b', 0, G_OPTION_ARG_STRING, &b2b_url, "XMLRPC URL of B2B UA" , "STRING" },
{ "log-level", 'L', 0, G_OPTION_ARG_INT, &log_level, "Mask log priorities above this level", "INT" },
{ NULL, }
};
@ -301,6 +318,10 @@ static void options(int *argc, char ***argv) {
if (redis_db < 0)
die("Must specify Redis DB number (--redis-db) when using Redis\n");
}
if ((log_level < LOG_EMERG) || (log_level > LOG_DEBUG))
die("Invalid log level (--log_level)\n");
setlogmask(LOG_UPTO(log_level));
}

@ -174,9 +174,14 @@ out:
}
static void output_init(struct msghdr *mh, struct iovec *iov, struct sockaddr_in6 *sin,
struct header *hdr, unsigned short code, u_int32_t *transaction)
struct header *hdr, unsigned short code, u_int32_t *transaction,
unsigned char *buf, int buflen)
{
ZERO(*mh);
mh->msg_control = buf;
mh->msg_controllen = buflen;
mh->msg_name = sin;
mh->msg_namelen = sizeof(*sin);
mh->msg_iov = iov;
@ -222,11 +227,13 @@ static inline void __output_add(struct msghdr *mh, struct tlv *tlv, unsigned int
__output_add(mh, &(attr)->tlv, sizeof(*(attr)), code, data, len)
static void output_finish(struct msghdr *mh) {
static void output_finish(struct msghdr *mh, struct callmaster *cm) {
struct header *hdr;
hdr = mh->msg_iov->iov_base;
hdr->msg_len = htons(hdr->msg_len);
callmaster_msg_mh_src(cm, mh);
}
static void fingerprint(struct msghdr *mh, struct fingerprint *fp) {
@ -278,7 +285,7 @@ static void integrity(struct msghdr *mh, struct msg_integrity *mi, str *pwd) {
static void stun_error_len(int fd, struct sockaddr_in6 *sin, struct header *req,
int code, char *reason, int len, u_int16_t add_attr, void *attr_cont,
int attr_len)
int attr_len, struct callmaster *cm)
{
struct header hdr;
struct error_code ec;
@ -286,8 +293,9 @@ static void stun_error_len(int fd, struct sockaddr_in6 *sin, struct header *req,
struct generic aa;
struct msghdr mh;
struct iovec iov[6]; /* hdr, ec, reason, aa, attr_cont, fp */
unsigned char buf[256];
output_init(&mh, iov, sin, &hdr, STUN_BINDING_ERROR_RESPONSE, req->transaction);
output_init(&mh, iov, sin, &hdr, STUN_BINDING_ERROR_RESPONSE, req->transaction, buf, sizeof(buf));
ec.codes = htonl(((code / 100) << 8) | (code % 100));
output_add_data(&mh, &ec, STUN_ERROR_CODE, reason, len);
@ -296,16 +304,16 @@ static void stun_error_len(int fd, struct sockaddr_in6 *sin, struct header *req,
fingerprint(&mh, &fp);
output_finish(&mh);
output_finish(&mh, cm);
sendmsg(fd, &mh, 0);
}
#define stun_error(fd, sin, str, code, reason) \
#define stun_error(cm, fd, sin, str, code, reason) \
stun_error_len(fd, sin, str, code, reason "\0\0\0", strlen(reason), \
0, NULL, 0)
#define stun_error_attrs(fd, sin, str, code, reason, type, content, len) \
0, NULL, 0, cm)
#define stun_error_attrs(cm, fd, sin, str, code, reason, type, content, len) \
stun_error_len(fd, sin, str, code, reason "\0\0\0", strlen(reason), \
type, content, len)
type, content, len, cm)
@ -367,8 +375,10 @@ static int stun_binding_success(int fd, struct header *req, struct stun_attrs *a
struct fingerprint fp;
struct msghdr mh;
struct iovec iov[4]; /* hdr, xma, mi, fp */
unsigned char buf[256];
struct callmaster *cm = peer->up->call->callmaster;
output_init(&mh, iov, sin, &hdr, STUN_BINDING_SUCCESS_RESPONSE, req->transaction);
output_init(&mh, iov, sin, &hdr, STUN_BINDING_SUCCESS_RESPONSE, req->transaction, buf, sizeof(buf));
xma.port = sin->sin6_port ^ htons(STUN_COOKIE >> 16);
if (IN6_IS_ADDR_V4MAPPED(&sin->sin6_addr)) {
@ -388,7 +398,7 @@ static int stun_binding_success(int fd, struct header *req, struct stun_attrs *a
integrity(&mh, &mi, &peer->ice_pwd);
fingerprint(&mh, &fp);
output_finish(&mh);
output_finish(&mh, cm);
sendmsg(fd, &mh, 0);
return 0;
@ -417,6 +427,7 @@ int stun(str *b, struct streamrelay *sr, struct sockaddr_in6 *sin) {
u_int16_t unknowns[UNKNOWNS_COUNT];
const char *err;
char addr[64];
struct callmaster *cm = sr->up->up->call->callmaster;
smart_ntop_port(addr, sin, sizeof(addr));
@ -442,7 +453,7 @@ int stun(str *b, struct streamrelay *sr, struct sockaddr_in6 *sin) {
goto ignore;
mylog(LOG_WARNING, "STUN packet contained unknown "
"\"comprehension required\" attribute(s)" SLF, SLP);
stun_error_attrs(sr->fd.fd, sin, req, 420, "Unknown attribute",
stun_error_attrs(cm, sr->fd.fd, sin, req, 420, "Unknown attribute",
STUN_UNKNOWN_ATTRIBUTES, unknowns,
u_int16_t_arr_len(unknowns) * 2);
return 0;
@ -474,11 +485,11 @@ int stun(str *b, struct streamrelay *sr, struct sockaddr_in6 *sin) {
bad_req:
mylog(LOG_INFO, "Received invalid STUN packet" SLF ": %s", SLP, err);
stun_error(sr->fd.fd, sin, req, 400, "Bad request");
stun_error(cm, sr->fd.fd, sin, req, 400, "Bad request");
return 0;
unauth:
mylog(LOG_INFO, "STUN authentication mismatch" SLF, SLP);
stun_error(sr->fd.fd, sin, req, 401, "Unauthorized");
stun_error(cm, sr->fd.fd, sin, req, 401, "Unauthorized");
return 0;
ignore:
mylog(LOG_INFO, "Not handling potential STUN packet" SLF ": %s", SLP, err);

1
debian/control vendored

@ -18,7 +18,6 @@ Homepage: http://sipwise.com/
Package: ngcp-mediaproxy-ng-daemon
Architecture: any
Depends: ${misc:Depends}, ${shlibs:Depends}
Pre-Depends: ngcp-mediaproxy-ng-kernel-dkms (>= ${source:Version})
Description: Proxy for RTP and media streams used in NGCP, userspace part.
This daemon handles the first stages of proxying media streams and talks to
the kernel part of the proxy for eventual high-performance packet forwarding.

@ -18,3 +18,4 @@ TABLE=0
# REDIS=127.0.0.1:6379
# REDIS_DB=1
# B2B_URL=http://127.0.0.1:8090/
# LOG_LEVEL=6

@ -61,6 +61,7 @@ OPTIONS=""
[ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL"
[ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback"
OPTIONS="$OPTIONS --table=$TABLE"
[ -z "$LOG_LEVEL" ] || OPTIONS="$OPTIONS --log-level=$LOG_LEVEL"
if test "$FORK" = "no" ; then
OPTIONS="$OPTIONS --foreground"
fi
@ -72,11 +73,16 @@ case "$1" in
set +e
modprobe xt_MEDIAPROXY
echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null
iptables -D INPUT -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -I INPUT -p udp -j MEDIAPROXY --id $TABLE
ip6tables -I INPUT -p udp -j MEDIAPROXY --id $TABLE
iptables -N mediaproxy 2> /dev/null
iptables -D INPUT -j mediaproxy 2> /dev/null
iptables -I INPUT -j mediaproxy
iptables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
ip6tables -N mediaproxy 2> /dev/null
ip6tables -D INPUT -j mediaproxy 2> /dev/null
ip6tables -I INPUT -j mediaproxy
ip6tables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
set -e
start-stop-daemon --start --quiet --pidfile $PIDFILE \
--exec $DAEMON -- $OPTIONS || echo -n " already running"
@ -91,9 +97,10 @@ case "$1" in
fi
set +e
echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null
iptables -D INPUT -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -D INPUT -j mediaproxy 2> /dev/null
iptables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -D INPUT -j mediaproxy 2> /dev/null
ip6tables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
rmmod ipt_MEDIAPROXY 2>/dev/null
rmmod xt_MEDIAPROXY 2>/dev/null
set -e
@ -114,14 +121,19 @@ case "$1" in
if [ -e /proc/mediaproxy/control ]; then
echo "del $TABLE" > /proc/mediaproxy/control 2>/dev/null
fi
iptables -D INPUT -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -D INPUT -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
iptables -D INPUT -j mediaproxy 2> /dev/null
iptables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
ip6tables -D INPUT -j mediaproxy 2> /dev/null
ip6tables -D mediaproxy -p udp -j MEDIAPROXY --id $TABLE 2>/dev/null
rmmod ipt_MEDIAPROXY 2>/dev/null
rmmod xt_MEDIAPROXY 2>/dev/null
modprobe xt_MEDIAPROXY
iptables -I INPUT -p udp -j MEDIAPROXY --id $TABLE
ip6tables -I INPUT -p udp -j MEDIAPROXY --id $TABLE
iptables -N mediaproxy 2> /dev/null
iptables -I INPUT -j mediaproxy
iptables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
ip6tables -N mediaproxy 2> /dev/null
ip6tables -I INPUT -j mediaproxy
ip6tables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
set -e
start-stop-daemon --start --quiet --pidfile \
$PIDFILE --exec $DAEMON -- $OPTIONS

@ -0,0 +1,120 @@
mediaproxy-ng for Enterprise Linux
==================================
Installing from RPMs
--------------------
There are three RPMs:
- *ngcp-mediaproxy-ng*: the userspace daemon
- *ngcp-mediaproxy-ng-kernel*: the iptables plugin
- *ngcp-mediaproxy-ng-dkms*: the kernel module source
All of the RPMs have correctly set dependencies and if you just want the
userspace daemon you can install it with yum (assuming you have access to a
CentOS repository).
The *ngcp-mediaproxy-ng-kernel* package is dependent on the
*ngcp-mediaproxy-ng*, and *ngcp-mediaproxy-ng-dkms* packages. The
*ngcp-mediaproxy-ng-dkms* package has a dependency (DKMS) that cannot be met
by the CentOS base repository. If you want to use in-kernel forwarding you
need to add the [*EPEL*](http://fedoraproject.org/wiki/EPEL) repository and
install the *dkms* package before attempting to install
*ngcp-mediaproxy-ng-dkms* or *ngcp-mediaproxy-ng-kernel*.
Note: installing *ngcp-mediaproxy-ng-dkms* builds a kernel module which requires
the sources for the running kernel. The *kernel-devel* and *kernel-headers*
packages are meta-packages that install the headers and source for the latest
kernel version. This will be what what you want unless you are running a custom
or older kernel. *ngcp-mediaproxy-ng-dkms* does not have *kernel-devel* and
*kernel-headers* as dependencies as this could cause problems if you are using
a custom or older kernel, so you need to install these manually.
RPM Compliation
---------------
To build the RPMs you need all of the packages listed in the Manual Compilation
section (except for *kernel-devel* and *kernel-headers*) plus:
- *redhat-rpm-config*
- *rpm-build*
To build the RPMs:
- Checkout (clone) the Git repository
- Create the `~/rpmbuild/SOURCES` directory
- Create a tar archive. For example, from within the cloned directory you can
use
`git archive --output ~/rpmbuild/SOURCES/ngcp-mediaproxy-ng-<version number>.tar.gz --prefix=ngcp-mediaproxy-ng-<version number>/ master`
where `<version number>` is the version number of the master branch
- Build the RPMs. For example,
`rpmbuild -ta ~/rpmbuild/SOURCES/ngcp-mediaproxy-ng-<version number>.tar.gz`
Once the build has completed the binary RPMs will be in `~/rpmbuild/RPMS`.
Manual Compilation
------------------
There are three parts to mediaproxy-ng, each of which can be found in the
respective subdirectories.
* `daemon`
The userspace daemon and workhorse, minimum requirement for anything
to work. Running `MEDIAPROXY_VERSION="\"<version number>\"" make` will
compile the binary, which will be called `mediaproxy-ng`. The
following software packages are required to compile the daemon:
- *gcc*
- *make*
- *pkgconfig*
- *glib2-devel*
- *libcurl-devel*
- *openssl-devel*
- *pcre-devel*
- *xmlrpc-c-devel*
- *zlib-devel*
* `iptables-extension`
Required for in-kernel packet forwarding. Running
`MEDIAPROXY_VERSION="\"<version number>\"" make` will compile the plugin
for `iptables` and `ip6tables`. The file will be called
`libxt_MEDIAPROXY.so` and should be copied into the directory
`/lib/xtables/` in 32-bit environments and `/lib64/xtables/` in 64-bit
environments. The following software packages are required to compile
the plugin:
- *gcc*
- *make*
- *iptables-devel*
* `kernel-module`
Required for in-kernel packet forwarding. Compilation of the kernel
module requires the kernel development packages for the kernel version
you are using (see output of `uname -r`) to be installed. Running
`MEDIAPROXY_VERSION="\"<version number>\"" make` will compile the kernel
module.
Successful compilation of the module will produce the file
`xt_MEDIAPROXY.ko`. The module can be inserted into the running kernel
manually through `insmod xt_MEDIAPROXY.ko` (which will result in an
error if depending modules aren't loaded, for example the `x_tables`
module), but it's recommended to copy the module into
`/lib/modules/<version number>/updates/`, followed by running
`depmod -a`. After this, the module can be loaded by issuing
`modprobe xt_MEDIAPROXY`.
The following software packages are required to compile the plugin:
- *gcc*
- *make*
- *kernel-devel*
- *kernel-headers*
Note: the *kernel-devel* and *kernel-headers* packages are meta-packages
that install the headers and source for the latest kernel version. This
will be what you want unless you are running a custom or older kernel.

@ -0,0 +1,219 @@
#!/bin/bash
#
# mediaproxy-ng Startup script for NGCP mediaproxy-ng
#
# chkconfig: 345 84 16
# description: NGCP mediaproxy-ng
#
# processname: mediaproxy-ng
# config: /etc/sysconfig/mediaproxy-ng
# pidfile: /var/run/mediaproxy-ng.pid
#
### BEGIN INIT INFO
# Provides: mediaproxy-ng
# Required-Start: $local_fs $network
# Short-Description: NGCP mediaproxy-ng
# Description: NGCP mediaproxy-ng
### END INIT INFO
# Source function library.
. /etc/rc.d/init.d/functions
if [ -f /etc/sysconfig/mediaproxy-ng ]
then
. /etc/sysconfig/mediaproxy-ng
else
echo "Error: /etc/sysconfig/mediproxy-ng not present"
exit -1
fi
mediaproxy_ng=/usr/sbin/mediaproxy-ng
prog=mediaproxy-ng
pidfile=${PIDFILE-/var/run/mediaproxy-ng.pid}
lockfile=${LOCKFILE-/var/lock/subsys/mediaproxy-ng}
cachefile=/var/lib/mediaproxy-ng/mediaproxy-ng.cfg
RETVAL=0
OPTS="--pidfile $pidfile"
MODULE=0
IP6=0
build_opts() {
shopt -s nocasematch
RPMS=`rpm -qa | grep ngcp-mediaproxy-ng-kernel`
if [[ "$KERNEL" == "yes" && -n "$TABLE" && -n "$RPMS" ]]
then
MODULE=1
OPTS+=" --table=$TABLE"
else
MODULE=0
OPTS+=" --table=-1"
fi
if [[ "$FALLBACK" != "yes" ]]
then
OPTS+=" --no-fallback"
fi
shopt -u nocasematch
if [[ -n "$RTP_IP" ]]
then
OPTS+=" --ip=$RTP_IP"
fi
if [[ -n "$RTP_ADV_IP" ]]
then
OPTS+=" --advertised-ip=$RTP_ADV_IP"
fi
if [[ -n "$RTP_IP6" ]]
then
OPTS+=" --ip6=$RTP_IP6"
IP6=1
fi
if [[ -n "$RTP_ADV_IP6" ]]
then
OPTS+=" --advertised-ip6=$RTP_ADV_IP6"
fi
if [[ -n "$LISTEN_TCP" ]]
then
OPTS+=" --listen-tcp=$LISTEN_TCP"
fi
if [[ -n "$LISTEN_UDP" ]]
then
OPTS+=" --listen-udp=$LISTEN_UDP"
fi
if [[ -n "$LISTEN_NG" ]]
then
OPTS+=" --listen-ng=$LISTEN_NG"
fi
if [[ -n "$TOS" ]]
then
OPTS+=" --tos=$TOS"
fi
if [[ -n "$TIMEOUT" ]]
then
OPTS+=" --timeout=$TIMEOUT"
fi
if [[ -n "$SILENT_TIMEOUT" ]]
then
OPTS+=" --silent-timeout=$SILENT_TIMEOUT"
fi
if [[ -n "$PORT_MIN" ]]
then
OPTS+=" --port-min=$PORT_MIN"
fi
if [[ -n "$PORT_MAX" ]]
then
OPTS+=" --port-max=$PORT_MAX"
fi
if [[ -n "$REDIS" ]]
then
OPTS+=" --redis=$REDIS"
fi
if [[ -n "$REDIS_DB" ]]
then
OPTS+=" --redis-db=$REDIS_DB"
fi
if [[ -n "$B2B_URL" ]]
then
OPTS+=" --b2b-url=$B2B_URL"
fi
if [[ -n "$LOG_LEVEL" ]]
then
OPTS+=" --log-level=$LOG_LEVEL"
fi
}
start() {
build_opts
if [[ $MODULE == 1 ]]
then
echo "Loading module for in-kernel packet forwarding"
modprobe xt_MEDIAPROXY
iptables -N mediaproxy
iptables -t filter -A INPUT -j mediaproxy
iptables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
if [[ IP6 == 1 ]]
then
ip6tables -I mediaproxy -p udp -j MEDIAPROXY --id $TABLE
fi
cat <<EOF > "$cachefile"
CUR_TABLE=$TABLE
CUR_IP6=$IP6
EOF
fi
echo -n $"Starting $prog: "
daemon --pidfile=${pidfile} $mediaproxy_ng $OPTS
RETVAL=$?
echo
[ $RETVAL = 0 ] && touch ${lockfile}
return $RETVAL
}
stop() {
echo -n $"Stopping $prog: "
killproc -p ${pidfile} $mediaproxy_ng
RETVAL=$?
echo
if [ -f "$cachefile" ]
then
. "$cachefile"
echo "Unloading module for in-kernel packet forwarding"
echo "del $TABLE" > /proc/mediaproxy/control
iptables -D mediaproxy -p udp -j MEDIAPROXY --id $CUR_TABLE
if [[ CUR_IP6 == 1 ]]
then
ip6tables -D mediaproxy -p udp -j MEDIAPROXY --id $CUR_TABLE
fi
iptables -t filter -D INPUT -j mediaproxy
iptables -X mediaproxy
# rmmod xt_MEDIAPROXY
rm -f $cachefile
fi
[ $RETVAL = 0 ] && rm -f ${lockfile} ${pidfile}
}
# See how we were called.
case "$1" in
start)
start
;;
stop)
stop
;;
status)
status -p ${pidfile} $mediaproxy_ng
RETVAL=$?
;;
restart)
stop
start
;;
condrestart|try-restart)
if status -p ${pidfile} $mediaproxy_ng >&/dev/null; then
stop
start
fi
;;
*)
echo $"Usage: $prog {start|stop|restart|condrestart|try-restart|status}"
RETVAL=2
esac
exit $RETVAL

@ -0,0 +1,174 @@
Name: ngcp-mediaproxy-ng
Version: 2.3.0
Release: 3%{?dist}
Summary: The Sipwise NGCP mediaproxy-ng
Group: System Environment/Daemons
License: unknown
URL: https://github.com/crocodilertc/mediaproxy-ng
Source: %{name}-%{version}.tar.gz
Conflicts: %{name}-kernel < %{version}
BuildRoot: %(mktemp -ud %{_tmppath}/%{name}-%{version}-%{release}-XXXXXX)
BuildRequires: gcc make pkgconfig redhat-rpm-config
BuildRequires: glib2-devel libcurl-devel openssl-devel pcre-devel
BuildRequires: xmlrpc-c-devel zlib-devel
Requires: glibc libcurl openssl pcre xmlrpc-c
%description
The Sipwise NGCP mediaproxy-ng is a proxy for RTP traffic and other UDP based
media traffic. It's meant to be used with the Kamailio SIP proxy and forms a
drop-in replacement for any of the other available RTP and media proxies.
%package kernel
Summary: NGCP mediaproxy-ng in-kernel packet forwarding
Group: System Environment/Daemons
BuildRequires: gcc make redhat-rpm-config iptables-devel
Requires: iptables iptables-ipv6 ngcp-mediaproxy-ng = %{version}
Requires: ngcp-mediaproxy-ng-dkms = %{version}
%description kernel
NGCP mediaproxy-ng in-kernel packet forwarding
%package dkms
Summary: Kernel module for NGCP mediaproxy-ng in-kernel packet forwarding
Group: System Environment/Daemons
BuildArch: noarch
BuildRequires: redhat-rpm-config
Requires: gcc make
Requires(post): epel-release dkms
Requires(preun): epel-release dkms
%description dkms
Kernel module for mediaproxy-ng in-kernel packet forwarding
%prep
%setup -q
%build
cd daemon
MEDIAPROXY_VERSION="\"%{version}-%{release}\"" make
cd ../iptables-extension
MEDIAPROXY_VERSION="\"%{version}-%{release}\"" make
cd ..
%install
[ "$RPM_BUILD_ROOT" != "/" ] && rm -rf "$RPM_BUILD_ROOT"
# Install the userspace daemon
mkdir -p $RPM_BUILD_ROOT/%{_sbindir}
install -m755 daemon/mediaproxy-ng $RPM_BUILD_ROOT/%{_sbindir}/mediaproxy-ng
## Install the init.d script and configuration file
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d
install -m755 el/mediaproxy-ng.init \
$RPM_BUILD_ROOT/%{_sysconfdir}/rc.d/init.d/mediaproxy-ng
mkdir -p $RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig
install -m644 el/mediaproxy-ng.sysconfig \
$RPM_BUILD_ROOT/%{_sysconfdir}/sysconfig/mediaproxy-ng
mkdir -p $RPM_BUILD_ROOT/%{_sharedstatedir}/mediaproxy-ng
# Install the iptables plugin
mkdir -p $RPM_BUILD_ROOT/%{_lib}/xtables
install -m755 iptables-extension/libxt_MEDIAPROXY.so \
$RPM_BUILD_ROOT/%{_lib}/xtables/libxt_MEDIAPROXY.so
# Install the documentation
mkdir -p $RPM_BUILD_ROOT/%{_docdir}/%{name}-%{version}-%{release}
install -m644 README.md \
$RPM_BUILD_ROOT/%{_docdir}/%{name}-%{version}-%{release}/README.md
install -m644 debian/changelog \
$RPM_BUILD_ROOT/%{_docdir}/%{name}-%{version}-%{release}/changelog
install -m644 debian/copyright \
$RPM_BUILD_ROOT/%{_docdir}/%{name}-%{version}-%{release}/copyright
install -m644 el/README.md \
$RPM_BUILD_ROOT/%{_docdir}/%{name}-%{version}-%{release}/README.el.md
## DKMS module source install
mkdir -p $RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}-%{release}
install -m644 kernel-module/Makefile \
$RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}-%{release}/Makefile
install -m644 kernel-module/xt_MEDIAPROXY.c \
$RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}-%{release}/xt_MEDIAPROXY.c
install -m644 kernel-module/xt_MEDIAPROXY.h \
$RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}-%{release}/xt_MEDIAPROXY.h
sed "s/__VERSION__/%{version}-%{release}/g" debian/dkms.conf.in > \
$RPM_BUILD_ROOT/%{_usrsrc}/%{name}-%{version}-%{release}/dkms.conf
%clean
rm -rf %{buildroot}
%pre
/usr/sbin/groupadd -r mediaproxy-ng 2> /dev/null || :
/usr/sbin/usradd -r -g mediaproxy-ng -s /bin/false -c "mediaproxy-ng daemon" \
-d %{_docdir}/%{name}-%{version}-%{release} mediaproxy-ng \
2> /dev/null || :
%post
/sbin/chkconfig --add mediaproxy-ng
%post dkms
# Add to DKMS registry, build, and install module
dkms add -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms build -m %{name} -v %{version}-%{release} --rpm_safe_upgrade &&
dkms install -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --force
true
%preun
/sbin/service mediaproxy-ng stop
/sbin/chkconfig --del mediaproxy-ng
%preun dkms
# Remove from DKMS registry
dkms remove -m %{name} -v %{version}-%{release} --rpm_safe_upgrade --all
true
%files
%defattr(-,root,root,-)
# Userspace daemon
%{_sbindir}/mediaproxy-ng
# init.d script and configuration file
%{_sysconfdir}/rc.d/init.d/mediaproxy-ng
%config(noreplace) %{_sysconfdir}/sysconfig/mediaproxy-ng
%dir %{_sharedstatedir}/mediaproxy-ng
# Documentation
%dir %{_docdir}/%{name}-%{version}-%{release}
%doc %{_docdir}/%{name}-%{version}-%{release}/README.md
%doc %{_docdir}/%{name}-%{version}-%{release}/changelog
%doc %{_docdir}/%{name}-%{version}-%{release}/copyright
%doc %{_docdir}/%{name}-%{version}-%{release}/README.el.md
%files kernel
%defattr(-,root,root,-)
/%{_lib}/xtables/libxt_MEDIAPROXY.so
%files dkms
%defattr(-,root,root,0755)
%{_usrsrc}/%{name}-%{version}-%{release}/
%changelog
* Thu Aug 15 2013 Peter Dunkley <peter.dunkley@crocodilertc.net>
- init.d scripts and configuration file
* Wed Aug 14 2013 Peter Dunkley <peter.dunkley@crocodilertc.net>
- First version of .spec file
- Builds and installs userspace daemon (but no init.d scripts etc yet)
- Builds and installs the iptables plugin
- DKMS package for the kernel module

@ -0,0 +1,39 @@
# For more information on configuring mediaproxy-ng see
# http://github.com/sipwise/mediproxy-ng
#
# (m) means the item is mandatory, (o) means the item is optional
#
KERNEL=yes # (m) "yes" enable in-kernel forwarding, "no" disables
TABLE=0 # (o) iptables table for in-kernel forwarding rules
# comment out when "KERNEL=no"
FALLBACK=yes # (m) "yes" enables fallback to userspace forwarding
# only, "no" disables
RTP_IP=127.0.0.1 # (m) Local IPv4 address for packet forwarding
#RTP_ADV_IP=127.0.0.1 # (o) IPv4 address to "advertise" for packet forwarding
#RTP_IP6=::1 # (o) Local IPv6 address for packet forwarding
#RTP_ADV_IP6=::1 # (o) IPv6 address to "advertise" for packet forwarding
#
# At least one of LISTEN_(TCP|UDP|NG) is required
#LISTEN_TCP=127.0.0.1:2222 # IP address and port combination for TCP
# control
LISTEN_UDP=127.0.0.1:2222 # IP address and port combination for UDP
# control
#LISTEN_NG=127.0.0.1:2223 # IP address and port combination for NG (UDP)
# control
#
#TOS=184 # (o) TOS value to use in outgoing packets
#TIMEOUT=60 # (o) Number of seconds after which a media stream is
# considered dead if there is no traffic.
# Default: 60
#SILENT_TIMEOUT=3600 # (o) Number of seconds after which a muted or inactive
# stream is considered dead. Default: 3600
#PORT_MIN=30000 # (o) Lowest port in the local port range for media
# traffic. Default: 30000
#PORT_MAX=40000 # (o) Highest port in the local port range for media
# traffic. Default: 40000
#
#LOG_LEVEL=6 # Log level to use
# The following items are for use with NGCP
#REDIS=127.0.0.1:6379
#REDIS_DB=0
#B2B_URL=http://127.0.0.1:8080/xmlrpc

@ -1,5 +1,14 @@
CFLAGS = -O2 -Wall -shared -fPIC
CFLAGS += -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\""
ifneq ($(MEDIAPROXY_VERSION),)
CFLAGS += -DMEDIAPROXY_VERSION="\"$(MEDIAPROXY_VERSION)\""
else
DPKG_PRSCHNGLG= $(shell which dpkg-parsechangelog 2>/dev/null)
ifneq ($(DPKG_PRSCHNGLG),)
CFLAGS += -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\""
else
CFLAGS += -DMEDIAPROXY_VERSION="\"undefined\""
endif
endif
XTABLES = $(shell test -e /usr/include/xtables.h && echo 1)
IPTABLES = $(shell test -e /usr/include/iptables.h && echo 1)

@ -1,11 +1,18 @@
PWD := $(shell pwd)
KSRC ?= /lib/modules/$(shell uname -r)/build
KBUILD := $(KSRC)
ifeq ($(origin MEDIAPROXY_VERSION), undefined)
MEDIAPROXY_VERSION := $(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')
export MEDIAPROXY_VERSION
ifneq ($(MEDIAPROXY_VERSION),)
EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"$(MEDIAPROXY_VERSION)\""
else
DPKG_PRSCHNGLG= $(shell which dpkg-parsechangelog 2>/dev/null)
ifneq ($(DPKG_PRSCHNGLG),)
EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"$(shell dpkg-parsechangelog -l../debian/changelog | awk '/^Version: / {print $$2}')\""
else
EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"undefined\""
endif
endif
EXTRA_CFLAGS += -DMEDIAPROXY_VERSION="\"$(MEDIAPROXY_VERSION)\"" -D__MP_EXTERNAL
EXTRA_CFLAGS += -D__MP_EXTERNAL
obj-m += xt_MEDIAPROXY.o

Loading…
Cancel
Save