summaryrefslogtreecommitdiff
path: root/anyrtpproxy
diff options
context:
space:
mode:
authorOthmar Gsenger <otti@anytun.org>2008-03-17 19:51:49 +0000
committerOthmar Gsenger <otti@anytun.org>2008-03-17 19:51:49 +0000
commit45c4d68df26b5a509d8ce7b0783aacda7afe0ca5 (patch)
tree5afd8d5a56046ed10886b26c4200e9f250e28c28 /anyrtpproxy
parentfinally added callIdQueue (sorry) (diff)
added port window and port range options
Diffstat (limited to 'anyrtpproxy')
-rw-r--r--anyrtpproxy/Makefile4
-rw-r--r--anyrtpproxy/options.cpp26
-rw-r--r--anyrtpproxy/options.h6
-rw-r--r--anyrtpproxy/portWindow.cpp85
-rw-r--r--anyrtpproxy/portWindow.h63
5 files changed, 184 insertions, 0 deletions
diff --git a/anyrtpproxy/Makefile b/anyrtpproxy/Makefile
index 7e3475f..948a4c8 100644
--- a/anyrtpproxy/Makefile
+++ b/anyrtpproxy/Makefile
@@ -33,6 +33,7 @@ OBJS = anyrtpproxy.o \
../networkPrefix.o \
../Sockets/libSockets.a \
commandHandler.o \
+ portWindow.o \
callIdQueue.o \
options.o
@@ -46,6 +47,9 @@ anyrtpproxy: $(OBJS)
options.o: options.cpp options.h
$(C++) $(CCFLAGS) $< -c
+portWindow.o: portWindow.cpp portWindow.h
+ $(C++) $(CCFLAGS) $< -c
+
connectionList.o: connectionList.cpp connectionList.h
$(C++) $(CCFLAGS) $< -c
diff --git a/anyrtpproxy/options.cpp b/anyrtpproxy/options.cpp
index b81f348..ecd7556 100644
--- a/anyrtpproxy/options.cpp
+++ b/anyrtpproxy/options.cpp
@@ -58,6 +58,8 @@ Options::Options() : control_interface_("0.0.0.0", 22222)
chroot_dir_ = "/var/run";
daemonize_ = true;
local_sync_port_ = 2023;
+ rtp_start_port_ = 34000;
+ rtp_end_port_ = 35000;
}
Options::~Options()
@@ -154,6 +156,7 @@ bool Options::parse(int argc, char* argv[])
PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_)
PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_)
PARSE_STRING_PARAM("-s","--control", control_interface_)
+ PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_, rtp_end_port_)
else
return false;
}
@@ -176,6 +179,7 @@ void Options::printUsage()
std::cout << " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl;
std::cout << " [-d|--nodaemonize] don't run in background" << std::endl;
std::cout << " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl;
+ std::cout << " [-p|--port-range] <start port> <end port> port range used to relay rtp connections" << std::endl;
}
void Options::printOptions()
@@ -236,6 +240,28 @@ Options& Options::setLocalSyncPort(u_int16_t l)
return *this;
}
+u_int16_t Options::getRtpStartPort()
+{
+ return rtp_start_port_;
+}
+
+Options& Options::setRtpStartPort(u_int16_t l)
+{
+ rtp_start_port_ = l;
+ return *this;
+}
+
+u_int16_t Options::getRtpEndPort()
+{
+ return rtp_end_port_;
+}
+
+Options& Options::setRtpEndPort(u_int16_t l)
+{
+ rtp_end_port_ = l;
+ return *this;
+}
+
ConnectToList Options::getConnectTo()
{
Lock lock(mutex);
diff --git a/anyrtpproxy/options.h b/anyrtpproxy/options.h
index e47a013..55f3264 100644
--- a/anyrtpproxy/options.h
+++ b/anyrtpproxy/options.h
@@ -83,6 +83,10 @@ public:
Host getControlInterface();
u_int16_t getLocalSyncPort();
Options& setLocalSyncPort(u_int16_t l);
+ u_int16_t getRtpStartPort();
+ Options& setRtpStartPort(u_int16_t l);
+ u_int16_t getRtpEndPort();
+ Options& setRtpEndPort(u_int16_t l);
ConnectToList getConnectTo();
private:
@@ -110,6 +114,8 @@ private:
std::string chroot_dir_;
bool daemonize_;
u_int16_t local_sync_port_;
+ u_int16_t rtp_start_port_;
+ u_int16_t rtp_end_port_;
ConnectToList connect_to_;
Host control_interface_;
};
diff --git a/anyrtpproxy/portWindow.cpp b/anyrtpproxy/portWindow.cpp
new file mode 100644
index 0000000..3d96a06
--- /dev/null
+++ b/anyrtpproxy/portWindow.cpp
@@ -0,0 +1,85 @@
+/*
+ * anytun
+ *
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING included with this
+ * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#include "portWindow.h"
+
+PortWindow::PortWindow(u_int16_t start, u_int16_t end) : start_port_(start), end_port_(end)
+{
+}
+
+PortWindow::~PortWindow()
+{
+}
+
+PortWindow::PortSet::size_type PortWindow::getLength()
+{
+ Lock lock(mutex_);
+ return ports_.size();
+}
+
+bool PortWindow::hasPort(u_int16_t port)
+{
+ Lock lock(mutex_);
+
+ PortSet::const_iterator it=ports_.find(port);
+ if(it == ports_.end())
+ return false;
+ return true;
+}
+
+bool PortWindow::freePort(u_int16_t port)
+{
+ Lock lock(mutex_);
+
+ PortSet::iterator it=ports_.find(port);
+ if(it == ports_.end())
+ return false;
+ ports_.erase(it);
+ return true;
+}
+
+u_int16_t PortWindow::newPort()
+{
+ Lock lock(mutex_);
+ u_int16_t port= start_port_;
+ while (port<end_port_ && ports_.find(port) !=ports_.end())
+ port++;
+ if (port>=end_port_)
+ return 0;
+ ports_.insert(port);
+ return port;
+}
+
+void PortWindow::clear()
+{
+ Lock lock(mutex_);
+ ports_.clear();
+}
+
diff --git a/anyrtpproxy/portWindow.h b/anyrtpproxy/portWindow.h
new file mode 100644
index 0000000..85867ff
--- /dev/null
+++ b/anyrtpproxy/portWindow.h
@@ -0,0 +1,63 @@
+/*
+ * anytun
+ *
+ * The secure anycast tunneling protocol (satp) defines a protocol used
+ * for communication between any combination of unicast and anycast
+ * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
+ * mode and allows tunneling of every ETHER TYPE protocol (e.g.
+ * ethernet, ip, arp ...). satp directly includes cryptography and
+ * message authentication based on the methodes used by SRTP. It is
+ * intended to deliver a generic, scaleable and secure solution for
+ * tunneling and relaying of packets of any protocol.
+ *
+ *
+ * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License version 2
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program (see the file COPYING included with this
+ * distribution); if not, write to the Free Software Foundation, Inc.,
+ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
+ */
+
+#ifndef _PORT_WINDOW_H_
+#define _PORT_WINDOW_H_
+
+#include <set>
+#include "../threadUtils.hpp"
+#include "../datatypes.h"
+
+class PortWindow
+{
+public:
+ typedef std::set<u_int16_t> PortSet;
+
+ PortWindow(u_int16_t,u_int16_t);
+ ~PortWindow();
+
+ PortSet::size_type getLength();
+ bool hasPort(u_int16_t);
+ bool freePort(u_int16_t);
+ u_int16_t newPort();
+ void clear();
+
+
+private:
+ u_int16_t start_port_;
+ u_int16_t end_port_;
+ Mutex mutex_;
+ PortSet ports_;
+
+ PortWindow(const PortWindow &s);
+ void operator=(const PortWindow &s);
+};
+
+#endif