From 45c4d68df26b5a509d8ce7b0783aacda7afe0ca5 Mon Sep 17 00:00:00 2001 From: Othmar Gsenger Date: Mon, 17 Mar 2008 19:51:49 +0000 Subject: added port window and port range options --- anyrtpproxy/Makefile | 4 +++ anyrtpproxy/options.cpp | 26 ++++++++++++++ anyrtpproxy/options.h | 6 ++++ anyrtpproxy/portWindow.cpp | 85 ++++++++++++++++++++++++++++++++++++++++++++++ anyrtpproxy/portWindow.h | 63 ++++++++++++++++++++++++++++++++++ 5 files changed, 184 insertions(+) create mode 100644 anyrtpproxy/portWindow.cpp create mode 100644 anyrtpproxy/portWindow.h 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 to make a chroot to" << std::endl; std::cout << " [-d|--nodaemonize] don't run in background" << std::endl; std::cout << " [-s|--control] the address/port to listen on for control commands" << std::endl; + std::cout << " [-p|--port-range] 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 + * + * 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_) + 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 + * + * 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 +#include "../threadUtils.hpp" +#include "../datatypes.h" + +class PortWindow +{ +public: + typedef std::set 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 -- cgit v1.2.3