4 * The secure anycast tunneling protocol (satp) defines a protocol used
5 * for communication between any combination of unicast and anycast
6 * tunnel endpoints. It has less protocol overhead than IPSec in Tunnel
7 * mode and allows tunneling of every ETHER TYPE protocol (e.g.
8 * ethernet, ip, arp ...). satp directly includes cryptography and
9 * message authentication based on the methodes used by SRTP. It is
10 * intended to deliver a generic, scaleable and secure solution for
11 * tunneling and relaying of packets of any protocol.
14 * Copyright (C) 2007 anytun.org <satp@wirdorange.org>
16 * This program is free software; you can redistribute it and/or modify
17 * it under the terms of the GNU General Public License version 2
18 * as published by the Free Software Foundation.
20 * This program is distributed in the hope that it will be useful,
21 * but WITHOUT ANY WARRANTY; without even the implied warranty of
22 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
23 * GNU General Public License for more details.
25 * You should have received a copy of the GNU General Public License
26 * along with this program (see the file COPYING included with this
27 * distribution); if not, write to the Free Software Foundation, Inc.,
28 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
38 Options
* Options::inst
= NULL
;
39 Mutex
Options::instMutex
;
40 Options
& gOpt
= Options::instance();
42 Options
& Options::instance()
45 static instanceCleaner c
;
52 Options::Options() : control_interface_("0.0.0.0", 22222)
55 progname_
= "anyrtpproxy";
58 chroot_dir_
= "/var/run";
61 rtp_start_port_
= 34000;
62 rtp_end_port_
= 35000;
71 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
72 else if(str == SHORT || str == LONG) \
75 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
76 else if(str == SHORT || str == LONG) \
79 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
80 else if(str == SHORT || str == LONG) \
82 if(argc < 1 || argv[i+1][0] == '-') \
84 std::stringstream tmp; \
91 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
92 else if(str == SHORT || str == LONG) \
95 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
97 std::stringstream tmp; \
98 tmp << argv[i+1] << " " << argv[i+2]; \
105 #define PARSE_STRING_PARAM(SHORT, LONG, VALUE) \
106 else if(str == SHORT || str == LONG) \
108 if(argc < 1 || argv[i+1][0] == '-') \
110 VALUE = std::string(argv[i+1]); \
115 #define PARSE_HEXSTRING_PARAM(SHORT, LONG, VALUE) \
116 else if(str == SHORT || str == LONG) \
118 if(argc < 1 || argv[i+1][0] == '-') \
120 VALUE = Buffer(std::string(argv[i+1])); \
126 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
127 else if(str == SHORT || str == LONG) \
129 if(argc < 1 || argv[i+1][0] == '-') \
131 std::stringstream tmp(argv[i+1]); \
132 /* LIST.clear(); */ \
135 std::string tmp_line; \
136 getline(tmp,tmp_line,','); \
137 LIST.push(tmp_line); \
143 bool Options::parse(int argc
, char* argv
[])
148 std::queue
<std::string
> host_port_queue
;
150 for(int i
=1; argc
> 0; ++i
)
152 std::string
str(argv
[i
]);
155 if(str
== "-h" || str
== "--help")
157 PARSE_BOOL_PARAM("-t","--chroot", chroot_
)
158 PARSE_BOOL_PARAM("-n","--nat", nat_
)
159 PARSE_BOOL_PARAM("-o","--no-nat-once", no_nat_once_
)
160 PARSE_SCALAR_PARAM("-u","--user", username_
)
161 PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_
)
162 PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_
)
163 PARSE_STRING_PARAM("-s","--control", control_interface_
)
164 PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_
, rtp_end_port_
)
165 PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue
)
166 PARSE_SCALAR_PARAM("-S","--sync-port", local_sync_port_
)
167 // PARSE_SCALAR_PARAM("-I","--sync-interface", local_sync_addr_)
171 while(!host_port_queue
.empty())
173 std::stringstream
tmp_stream(host_port_queue
.front());
175 getline(tmp_stream
,oct
.host
,':');
176 if(!tmp_stream
.good())
178 tmp_stream
>> oct
.port
;
179 host_port_queue
.pop();
180 connect_to_
.push_back(oct
);
183 return sanityCheck();
186 bool Options::sanityCheck()
188 if(!control_interface_
.port_
) control_interface_
.port_
= 22220;
192 void Options::printUsage()
194 std::cout
<< "USAGE: anyrtpproxy" << std::endl
;
195 std::cout
<< " [-h|--help] prints this..." << std::endl
;
196 std::cout
<< " [-t|--chroot] chroot and drop priviledges" << std::endl
;
197 std::cout
<< " [-u|--username] <username> in case of chroot run as this user" << std::endl
;
198 std::cout
<< " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl
;
199 std::cout
<< " [-d|--nodaemonize] don't run in background" << std::endl
;
200 std::cout
<< " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl
;
201 std::cout
<< " [-p|--port-range] <start> <end> port range used to relay rtp connections" << std::endl
;
202 std::cout
<< " [-n|--nat] enable permantent automatic nat detection(use only with anytun)" << std::endl
;
203 std::cout
<< " [-o|--no-nat-once] disable automatic nat detection for new connections" << std::endl
;
204 // std::cout << " [-I|--sync-interface] <ip-address> local unicast(sync) ip address to bind to" << std::endl;
205 std::cout
<< " [-S|--sync-port] <port> local unicast(sync) port to bind to" << std::endl
;
206 std::cout
<< " [-M|--sync-hosts] <hostname|ip>:<port>[,<hostname|ip>:<port>[...]]"<< std::endl
;
207 std::cout
<< " List of Remote Sync Hosts/Ports"<< std::endl
;
210 void Options::printOptions()
213 std::cout
<< "Options:" << std::endl
;
214 std::cout
<< "chroot='" << chroot_
<< "'" << std::endl
;
215 std::cout
<< "username='" << username_
<< "'" << std::endl
;
216 std::cout
<< "chroot-dir='" << chroot_dir_
<< "'" << std::endl
;
217 std::cout
<< "daemonize='" << daemonize_
<< "'" << std::endl
;
218 std::cout
<< "control-interface='" << control_interface_
.toString() << "'" << std::endl
;
221 std::string
Options::getProgname()
227 bool Options::getChroot()
233 bool Options::getNat()
239 bool Options::getNoNatOnce()
245 std::string
Options::getUsername()
251 std::string
Options::getChrootDir()
257 bool Options::getDaemonize()
263 Host
Options::getControlInterface()
266 return control_interface_
;
269 u_int16_t
Options::getLocalSyncPort()
271 return local_sync_port_
;
274 Options
& Options::setLocalSyncPort(u_int16_t l
)
276 local_sync_port_
= l
;
280 u_int16_t
Options::getRtpStartPort()
282 return rtp_start_port_
;
285 Options
& Options::setRtpStartPort(u_int16_t l
)
291 u_int16_t
Options::getRtpEndPort()
293 return rtp_end_port_
;
296 Options
& Options::setRtpEndPort(u_int16_t l
)
302 ConnectToList
Options::getConnectTo()