├── .gitmodules ├── Dockerfile ├── Dockerfile.centos5 ├── Dockerfile.centos6 ├── Dockerfile.centos7 ├── Dockerfile.debian7 ├── Dockerfile.debian8 ├── Dockerfile.fedora20 ├── Dockerfile.fedora21 ├── Dockerfile.fedora22 ├── Dockerfile.fedora23 ├── Dockerfile.ubuntu12 ├── Dockerfile.ubuntu14 ├── Dockerfile.ubuntu16 ├── Makefile ├── README.md ├── docker-compose.yml └── run.sh /.gitmodules: -------------------------------------------------------------------------------- 1 | [submodule "rtpengine"] 2 | path = rtpengine 3 | url = https://github.com/sipwise/rtpengine.git 4 | -------------------------------------------------------------------------------- /Dockerfile: -------------------------------------------------------------------------------- 1 | Dockerfile.centos7 -------------------------------------------------------------------------------- /Dockerfile.centos5: -------------------------------------------------------------------------------- 1 | FROM centos:5 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | yum -y install epel-release && \ 9 | yum -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.centos6: -------------------------------------------------------------------------------- 1 | FROM centos:6 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | yum -y install epel-release && \ 9 | yum -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.centos7: -------------------------------------------------------------------------------- 1 | FROM centos:7 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | yum -y install epel-release && \ 9 | yum -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.debian7: -------------------------------------------------------------------------------- 1 | #wheezy 2 | FROM debian:7 3 | MAINTAINER Ian Blenke 4 | 5 | ADD rtpengine/ /rtpengine 6 | WORKDIR /rtpengine 7 | 8 | RUN export DEBIAN_FRONTEND=noninteractive && \ 9 | apt-get update -qqy && \ 10 | touch ./debian/flavors/no_ngcp && \ 11 | apt-get install -qqy dpkg-dev debhelper iptables-dev libcurl4-openssl-dev libglib2.0-dev libhiredis-dev libpcre3-dev libssl-dev libxmlrpc-core-c3-dev markdown zlib1g-dev module-assistant dkms gettext && \ 12 | dpkg-checkbuilddeps && \ 13 | dpkg-buildpackage -b -us -uc && \ 14 | dpkg -i /*.deb && \ 15 | ( ( apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) && \ 16 | module-assistant update && \ 17 | module-assistant auto-install ngcp-rtpengine-kernel-source ) || true ) 18 | 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /run.sh 21 | 22 | CMD /run.sh 23 | 24 | -------------------------------------------------------------------------------- /Dockerfile.debian8: -------------------------------------------------------------------------------- 1 | #jessie 2 | FROM debian:8 3 | MAINTAINER Ian Blenke 4 | 5 | ADD rtpengine/ /rtpengine 6 | WORKDIR /rtpengine 7 | 8 | RUN export DEBIAN_FRONTEND=noninteractive && \ 9 | apt-get update -qqy && \ 10 | touch ./debian/flavors/no_ngcp && \ 11 | apt-get install -qqy dpkg-dev debhelper iptables-dev libcurl4-openssl-dev libglib2.0-dev libhiredis-dev libpcre3-dev libssl-dev libxmlrpc-core-c3-dev markdown zlib1g-dev module-assistant dkms gettext && \ 12 | dpkg-checkbuilddeps && \ 13 | dpkg-buildpackage -b -us -uc && \ 14 | dpkg -i /*.deb && \ 15 | ( ( apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) && \ 16 | module-assistant update && \ 17 | module-assistant auto-install ngcp-rtpengine-kernel-source ) || true ) 18 | 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /run.sh 21 | 22 | CMD /run.sh 23 | 24 | -------------------------------------------------------------------------------- /Dockerfile.fedora20: -------------------------------------------------------------------------------- 1 | FROM fedora:20 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | dnf -y install epel-release && \ 9 | dnf -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.fedora21: -------------------------------------------------------------------------------- 1 | FROM fedora:21 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | dnf -y install epel-release && \ 9 | dnf -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.fedora22: -------------------------------------------------------------------------------- 1 | FROM fedora:22 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | dnf -y install epel-release && \ 9 | dnf -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.fedora23: -------------------------------------------------------------------------------- 1 | FROM fedora:23 2 | MAINTAINER Ian Blenke 3 | 4 | ADD rtpengine/ /rtpengine 5 | WORKDIR /rtpengine 6 | 7 | RUN touch ./debian/flavors/no_ngcp && \ 8 | dnf -y install epel-release && \ 9 | dnf -y install git glib2 glib2-devel gcc zlib zlib-devel openssl openssl-devel pcre pcre-devel libcurl libcurl-devel xmlrpc-c xmlrpc-c-devel hiredis-devel iptables-devel kernel kernel-devel && \ 10 | cd /rtpengine/daemon && \ 11 | make && \ 12 | cp -u rtpengine /usr/local/bin/ && \ 13 | cd /rtpengine/iptables-extension && \ 14 | make && \ 15 | cp -u libxt_RTPENGINE.so /lib64/xtables && \ 16 | if [ ! -d "/usr/lib/modules/$(uname -r)/build" ]; then \ 17 | echo "Could Not Find the Kernel Headers For The current Kernel.\n"; \ 18 | exit 0 ; \ 19 | fi && \ 20 | cd "/rtpengine/kernel-module" && \ 21 | make && \ 22 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" && \ 23 | depmod -a 24 | 25 | ADD run.sh /run.sh 26 | RUN chmod 755 /run.sh 27 | 28 | CMD /run.sh 29 | -------------------------------------------------------------------------------- /Dockerfile.ubuntu12: -------------------------------------------------------------------------------- 1 | #precise 2 | FROM ubuntu:12.04 3 | MAINTAINER Ian Blenke 4 | 5 | ADD rtpengine/ /rtpengine 6 | WORKDIR /rtpengine 7 | 8 | RUN export DEBIAN_FRONTEND=noninteractive && \ 9 | apt-get update -qqy && \ 10 | touch ./debian/flavors/no_ngcp && \ 11 | apt-get install -qqy dpkg-dev debhelper iptables-dev libcurl4-openssl-dev libglib2.0-dev libhiredis-dev libpcre3-dev libssl-dev libxmlrpc-core-c3-dev markdown zlib1g-dev module-assistant dkms gettext && \ 12 | dpkg-checkbuilddeps && \ 13 | dpkg-buildpackage -b -us -uc && \ 14 | dpkg -i /*.deb && \ 15 | ( ( apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) && \ 16 | module-assistant update && \ 17 | module-assistant auto-install ngcp-rtpengine-kernel-source ) || true ) 18 | 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /run.sh 21 | 22 | CMD /run.sh 23 | 24 | -------------------------------------------------------------------------------- /Dockerfile.ubuntu14: -------------------------------------------------------------------------------- 1 | #trusty 2 | FROM ubuntu:14.04 3 | MAINTAINER Ian Blenke 4 | 5 | ADD rtpengine/ /rtpengine 6 | WORKDIR /rtpengine 7 | 8 | RUN export DEBIAN_FRONTEND=noninteractive && \ 9 | apt-get update -qqy && \ 10 | touch ./debian/flavors/no_ngcp && \ 11 | apt-get install -qqy dpkg-dev debhelper iptables-dev libcurl4-openssl-dev libglib2.0-dev libhiredis-dev libpcre3-dev libssl-dev libxmlrpc-core-c3-dev markdown zlib1g-dev module-assistant dkms gettext && \ 12 | dpkg-checkbuilddeps && \ 13 | dpkg-buildpackage -b -us -uc && \ 14 | dpkg -i /*.deb && \ 15 | ( ( apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) && \ 16 | module-assistant update && \ 17 | module-assistant auto-install ngcp-rtpengine-kernel-source ) || true ) 18 | 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /run.sh 21 | 22 | CMD /run.sh 23 | 24 | -------------------------------------------------------------------------------- /Dockerfile.ubuntu16: -------------------------------------------------------------------------------- 1 | #xenial 2 | FROM ubuntu:16.04 3 | MAINTAINER Ian Blenke 4 | 5 | ADD rtpengine/ /rtpengine 6 | WORKDIR /rtpengine 7 | 8 | RUN export DEBIAN_FRONTEND=noninteractive && \ 9 | apt-get update -qqy && \ 10 | touch ./debian/flavors/no_ngcp && \ 11 | apt-get install -qqy dpkg-dev debhelper iptables-dev libcurl4-openssl-dev libglib2.0-dev libhiredis-dev libpcre3-dev libssl-dev libxmlrpc-core-c3-dev markdown zlib1g-dev module-assistant dkms gettext && \ 12 | dpkg-checkbuilddeps && \ 13 | dpkg-buildpackage -b -us -uc && \ 14 | dpkg -i /*.deb && \ 15 | ( ( apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) && \ 16 | module-assistant update && \ 17 | module-assistant auto-install ngcp-rtpengine-kernel-source ) || true ) 18 | 19 | ADD run.sh /run.sh 20 | RUN chmod 755 /run.sh 21 | 22 | CMD /run.sh 23 | 24 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | docker-compose build 3 | docker-compose up --force-recreate 4 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # docker-rtpengine 2 | 3 | This is SIPWise rtpengine (previously: rtpproxy-ng, and before that: mediaproxy-ng) properly dockerified as a first-class citizen under the upstream project's preferred linux variant. 4 | 5 | Parts of this project were borrowed in part from Binan/rtpengine-docker 6 | 7 | ## Files 8 | 9 | - `Dockerfile*` properly builds a first-class rtpengine runtime from source 10 | - `Makefile` merely calls `docker-compose build` and `docker-compose up` for local iteration convenience. 11 | - `README.md` is the file you are reading right now. 12 | - `docker-compose.yml` is a v2 config example, with some pre-defined defaults and a list of environment variables. 13 | - `rtpengine/` submodule tree that is currently pointing at the master branch which just recently had PR #77 applied. 14 | - `run.sh` script converts these environment variables into rtpengine daemon command-line options. 15 | 16 | ## Note: 17 | 18 | This repository assumes that the resultant docker container will be run as privileged with host network stack and will be responsible for building and running the kernel module as well as the iptables rules. 19 | 20 | ## Build and Run 21 | 22 | First, initialize the git submodules: 23 | 24 | git submodule update --init --recursive 25 | 26 | If you are running an Ubuntu, Debian, Centos, or Fedora docker host, you should now be able to: 27 | 28 | docker-compose up 29 | 30 | After this first build, though, you'll want to do subsequent updated builds using: 31 | 32 | docker-compose build 33 | docker-compose up --force-recreate 34 | 35 | If you are running any other linux flavor as your docker host, this repository is not going to work for you as-is. 36 | 37 | Why? There are two docker phases to be concerned with here. 38 | 39 | - "build" time includes the `Dockerfile` and whatever is included in the docker image 40 | - "run" time includes the build image above, and the `run.sh` script that is included inside that image. 41 | 42 | Both the `Dockerfile` and the `run.sh` script will attempt to build a DKMS kernel module for rtpengine based on `uname -r`. 43 | 44 | ## At build time 45 | 46 | Whatever the `uname -r` is at "build" time, the kernel version headers and kernel module for whatever docker host was used to build this image will try and use that version. 47 | 48 | The `FROM` line of the `Dockerfile` in this project is `centos7`, which means that any build host that is not also Centos7 will silently skip including that as part of the docker build (see the "`|| true`" in the `Dockerfile` for that step). 49 | 50 | All this is really doing is pre-building a kernel module for you to use at docker run time. This is a time-saver, but is not necessary. 51 | 52 | ## At run time 53 | 54 | Regardless of the linux docker host flavor you _build_ this on, you should still be able to _run_ this on any same Ubuntu or Debian flavor derivative host version, and it should properly build the DKMS kernel before loading it and running the rtpengine daemon. This does take a little time. 55 | 56 | Because the `Dockerfile` and `run.sh` script assume Ubuntu/Debian tooling, this will not work for any other linux docker host flavor. 57 | 58 | 59 | -------------------------------------------------------------------------------- /docker-compose.yml: -------------------------------------------------------------------------------- 1 | # This requires docker-compose 1.6.0 or later 2 | version: '2' 3 | services: 4 | rtpengine: 5 | privileged: true 6 | build: 7 | context: . 8 | dockerfile: Dockerfile.centos7 9 | network_mode: host 10 | environment: 11 | # Comment the variables that you don't want to be used for the configuration 12 | RUN_RTPENGINE: "yes" 13 | #LISTEN_TCP: 25060 14 | #LISTEN_UDP: 12222 15 | LISTEN_NG: 127.0.0.1:60000 16 | LISTEN_CLI: 127.0.0.1:60001 17 | # INTERFACES: "internal/12.23.34.45 external/23.34.45.54" 18 | # INTERFACES: "12.23.34.45!23.34.45.56" 19 | TIMEOUT: 60 20 | SILENT_TIMEOUT: 3600 21 | FORK: "no" 22 | # TOS: 184 23 | TABLE: 40 24 | NO_FALLBACK: "yes" 25 | PORT_MIN: 10000 26 | PORT_MAX: 19999 27 | # REDIS: 127.0.0.1:6379 28 | # REDIS_DB: 1 29 | # REDIS_READ: 127.0.0.1:6379 30 | # REDIS_READ_DB: 1 31 | # REDIS_WRITE: 127.0.0.1:6379 32 | # REDIS_WRITE_DB: 1 33 | # B2B_URL: http://127.0.0.1:8090/ 34 | LOG_LEVEL: 6 35 | LOG_FACILITY: local1 36 | # LOG_FACILITY_CDR: daemon 37 | # LOG_FACILITY_RTCP: daemon 38 | # NUM_THREADS: 5 39 | # DELETE_DELAY: 30 40 | # GRAPHITE: 9006 41 | # GRAPHITE_INTERVAL: 60 42 | # GRAPHITE_PREFIX: myownprefix 43 | # MAX_SESSIONS: 5000 44 | 45 | -------------------------------------------------------------------------------- /run.sh: -------------------------------------------------------------------------------- 1 | #! /bin/sh 2 | set -x 3 | RUNTIME=${1:-rtpengine} 4 | 5 | if [ -n "${FLUSH_IPTABLES}" ] ; then 6 | iptables -P INPUT ACCEPT 7 | iptables -P FORWARD ACCEPT 8 | iptables -P OUTPUT ACCEPT 9 | iptables -t nat -F 10 | iptables -t mangle -F 11 | iptables -F 12 | iptables -X 13 | fi 14 | 15 | if [ -n "${UNLOAD_MODULE}" ] ; then 16 | rmmod xt_RTPENGINE 17 | fi 18 | 19 | if lsmod | grep xt_RTPENGINE || modprobe xt_RTPENGINE; then 20 | echo "rtpengine kernel module already loaded." 21 | else 22 | if which apt-get ; then 23 | # Build the kernel module for the docker run host 24 | apt-get update -y 25 | export DEBIAN_FRONTEND=noninteractive 26 | apt-get install -y linux-headers-$(uname -r) linux-image-$(uname -r) 27 | 28 | module-assistant update 29 | module-assistant auto-install ngcp-rtpengine-kernel-source 30 | modprobe xt_RTPENGINE 31 | else 32 | if which dnf || which yum ; then 33 | cd /rtpengine/daemon 34 | make 35 | cp -u rtpengine /usr/local/bin/ 36 | cd /rtpengine/iptables-extension 37 | make 38 | cp -u libxt_RTPENGINE.so /lib64/xtables 39 | cd /rtpengine/kernel-module 40 | make 41 | cp -u xt_RTPENGINE.ko "/lib/modules/$(uname -r)/extra" 42 | depmod -a 43 | else 44 | echo "This script is not running on debian/ubuntu/centus/fedora, cannot attempt to build kernel module" 45 | exit 1 46 | fi 47 | fi 48 | fi 49 | 50 | # Gradually fill the options of the command rtpengine which starts the RTPEngine daemon 51 | # The variables used are sourced from the configuration file rtpengine-conf 52 | 53 | OPTIONS="" 54 | 55 | if [ -z "$INTERFACES" ]; then 56 | 57 | # Discover public and private IP for this instance 58 | export PRIVATE_IPV4="${PRIVATE_IPV4:-$(ip addr show eth0 | grep 'inet ' | awk '{print $2}' | cut -d/ -f1)}" 59 | [ -n "$PUBLIC_IPV4" ] || \ 60 | PUBLIC_IPV4="$(curl --fail -qs whatismyip.akamai.com)" 61 | # PUBLIC_IPV4="$(curl --fail -qsH 'Metadata-Flavor: Google' http://169.254.169.254/computeMetadata/v1/instance/network-interfaces/0/access-configs/0/external-ip)}" 62 | # PUBLIC_IPV4="$(curl --fail -qs http://169.254.169.254/2014-11-05/meta-data/public-ipv4)" 63 | # PUBLIC_IPV4="$(curl --fail -qs ipinfo.io/ip)" 64 | # PUBLIC_IPV4="$(curl --fail -qs ipecho.net/plain)" 65 | export PUBLIC_IPV4 66 | 67 | export PUBLIC_IPV6="${PUBLIC_IPV6:-$(ip -6 addr show $(ip -6 route show default | grep -e '^default' | awk '{print $5}') | grep inet6 | grep global | awk '{print $2}' | grep -v -e '^::' | cut -d/ -f1)}" 68 | 69 | INTERFACES="${PRIVATE_IPV4}!${PUBLIC_IPV4} ${PUBLIC_IPV6}" 70 | fi 71 | 72 | for interface in $INTERFACES; do 73 | OPTIONS="$OPTIONS --interface=$interface" 74 | done 75 | 76 | mkdir -p /etc/default 77 | if [ ! -z "$TABLE" ]; then 78 | echo "TABLE=$TABLE" > /etc/default/rtpengine-table 79 | fi 80 | 81 | [ -z "$LISTEN_TCP" ] || OPTIONS="$OPTIONS --listen-tcp=$LISTEN_TCP" 82 | [ -z "$LISTEN_UDP" ] || OPTIONS="$OPTIONS --listen-udp=$LISTEN_UDP" 83 | [ -z "$LISTEN_NG" ] || OPTIONS="$OPTIONS --listen-ng=$LISTEN_NG" 84 | [ -z "$LISTEN_CLI" ] || OPTIONS="$OPTIONS --listen-cli=$LISTEN_CLI" 85 | [ -z "$TIMEOUT" ] || OPTIONS="$OPTIONS --timeout=$TIMEOUT" 86 | [ -z "$SILENT_TIMEOUT" ] || OPTIONS="$OPTIONS --silent-timeout=$SILENT_TIMEOUT" 87 | [ -z "$PIDFILE" ] || OPTIONS="$OPTIONS --pidfile=$PIDFILE" 88 | [ -z "$TOS" ] || OPTIONS="$OPTIONS --tos=$TOS" 89 | [ -z "$PORT_MIN" ] || OPTIONS="$OPTIONS --port-min=$PORT_MIN" 90 | [ -z "$PORT_MAX" ] || OPTIONS="$OPTIONS --port-max=$PORT_MAX" 91 | [ -z "$REDIS" ] || OPTIONS="$OPTIONS --redis=$REDIS" 92 | [ -z "$REDIS_DB" ] || OPTIONS="$OPTIONS --redis-db=$REDIS_DB" 93 | [ -z "$REDIS_READ" ] || OPTIONS="$OPTIONS --redis-read=$REDIS_READ" 94 | [ -z "$REDIS_READ_DB" ] || OPTIONS="$OPTIONS --redis-read-db=$REDIS_READ_DB" 95 | [ -z "$REDIS_WRITE" ] || OPTIONS="$OPTIONS --redis-write=$REDIS_WRITE" 96 | [ -z "$REDIS_WRITE_DB" ] || OPTIONS="$OPTIONS --redis-write-db=$REDIS_WRITE_DB" 97 | [ -z "$B2B_URL" ] || OPTIONS="$OPTIONS --b2b-url=$B2B_URL" 98 | [ -z "$NO_FALLBACK" -o \( "$NO_FALLBACK" != "1" -a "$NO_FALLBACK" != "yes" \) ] || OPTIONS="$OPTIONS --no-fallback" 99 | OPTIONS="$OPTIONS --table=$TABLE" 100 | [ -z "$LOG_LEVEL" ] || OPTIONS="$OPTIONS --log-level=$LOG_LEVEL" 101 | [ -z "$LOG_FACILITY" ] || OPTIONS="$OPTIONS --log-facility=$LOG_FACILITY" 102 | [ -z "$LOG_FACILITY_CDR" ] || OPTIONS="$OPTIONS --log-facility-cdr=$LOG_FACILITY_CDR" 103 | [ -z "$LOG_FACILITY_RTCP" ] || OPTIONS="$OPTIONS --log-facility-rtcp=$LOG_FACILITY_RTCP" 104 | [ -z "$NUM_THREADS" ] || OPTIONS="$OPTIONS --num-threads=$NUM_THREADS" 105 | [ -z "$DELETE_DELAY" ] || OPTIONS="$OPTIONS --delete-delay=$DELETE_DELAY" 106 | [ -z "$GRAPHITE" ] || OPTIONS="$OPTIONS --graphite=$GRAPHITE" 107 | [ -z "$GRAPHITE_INTERVAL" ] || OPTIONS="$OPTIONS --graphite-interval=$GRAPHITE_INTERVAL" 108 | [ -z "$GRAPHITE_PREFIX" ] || OPTIONS="$OPTIONS --graphite-prefix=$GRAPHITE_PREFIX" 109 | [ -z "$MAX_SESSIONS" ] || OPTIONS="$OPTIONS --max-sessions=$MAX_SESSIONS" 110 | 111 | if test "$FORK" = "no" ; then 112 | OPTIONS="$OPTIONS --foreground" 113 | fi 114 | 115 | set +e 116 | if [ -e /proc/rtpengine/control ]; then 117 | echo "del $TABLE" > /proc/rtpengine/control 2>/dev/null 118 | fi 119 | # Freshly add the iptables rules to forward the udp packets to the iptables-extension "RTPEngine": 120 | # Remember iptables table = chains, rules stored in the chains 121 | # -N (create a new chain with the name rtpengine) 122 | iptables -N rtpengine 2> /dev/null 123 | 124 | # -D: Delete the rule for the target "rtpengine" if exists. -j (target): chain name or extension name 125 | # from the table "filter" (the default -without the option '-t') 126 | iptables -D INPUT -j rtpengine 2> /dev/null 127 | # Add the rule again so the packets will go to rtpengine chain after the (filter-INPUT) hook point. 128 | iptables -I INPUT -j rtpengine 129 | # Delete and Insert a rule in the rtpengine chain to forward the UDP traffic 130 | iptables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null 131 | iptables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" 132 | iptables-save > /etc/iptables.rules 133 | 134 | # The same for IPv6 135 | ip6tables -N rtpengine 2> /dev/null 136 | ip6tables -D INPUT -j rtpengine 2> /dev/null 137 | ip6tables -I INPUT -j rtpengine 138 | ip6tables -D rtpengine -p udp -j RTPENGINE --id "$TABLE" 2>/dev/null 139 | ip6tables -I rtpengine -p udp -j RTPENGINE --id "$TABLE" 140 | ip6tables-save > /etc/ip6tables.rules 141 | 142 | set -x 143 | 144 | exec $RUNTIME $OPTIONS 145 | --------------------------------------------------------------------------------