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_SEC(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])); \
121 for(size_t j=0; j < strlen(argv[i+1]); ++j) \
122 argv[i+1][j] = '#'; \
127 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
128 else if(str == SHORT || str == LONG) \
130 if(argc < 1 || argv[i+1][0] == '-') \
132 std::stringstream tmp(argv[i+1]); \
133 /* LIST.clear(); */ \
136 std::string tmp_line; \
137 getline(tmp,tmp_line,','); \
138 LIST.push(tmp_line); \
144 bool Options::parse(int argc
, char* argv
[])
149 std::queue
<std::string
> host_port_queue
;
151 for(int i
=1; argc
> 0; ++i
)
153 std::string
str(argv
[i
]);
156 if(str
== "-h" || str
== "--help")
158 PARSE_BOOL_PARAM("-t","--chroot", chroot_
)
159 PARSE_BOOL_PARAM("-n","--nat", nat_
)
160 PARSE_BOOL_PARAM("-o","--no-nat-once", no_nat_once_
)
161 PARSE_SCALAR_PARAM("-u","--user", username_
)
162 PARSE_SCALAR_PARAM("-c","--chroot-dir", chroot_dir_
)
163 PARSE_INVERSE_BOOL_PARAM("-d","--nodaemonize", daemonize_
)
164 PARSE_STRING_PARAM("-s","--control", control_interface_
)
165 PARSE_SCALAR_PARAM2("-p","--port-range", rtp_start_port_
, rtp_end_port_
)
166 PARSE_CSLIST_PARAM("-M","--sync-hosts", host_port_queue
)
167 PARSE_SCALAR_PARAM("-S","--sync-port", local_sync_port_
)
168 // PARSE_SCALAR_PARAM("-I","--sync-interface", local_sync_addr_)
172 while(!host_port_queue
.empty())
174 std::stringstream
tmp_stream(host_port_queue
.front());
176 getline(tmp_stream
,oct
.host
,':');
177 if(!tmp_stream
.good())
179 tmp_stream
>> oct
.port
;
180 host_port_queue
.pop();
181 connect_to_
.push_back(oct
);
184 return sanityCheck();
187 bool Options::sanityCheck()
189 if(!control_interface_
.port_
) control_interface_
.port_
= 22220;
193 void Options::printUsage()
195 std::cout
<< "USAGE: anyrtpproxy" << std::endl
;
196 std::cout
<< " [-h|--help] prints this..." << std::endl
;
197 std::cout
<< " [-t|--chroot] chroot and drop priviledges" << std::endl
;
198 std::cout
<< " [-u|--username] <username> in case of chroot run as this user" << std::endl
;
199 std::cout
<< " [-c|--chroot-dir] <directory> directory to make a chroot to" << std::endl
;
200 std::cout
<< " [-d|--nodaemonize] don't run in background" << std::endl
;
201 std::cout
<< " [-s|--control] <addr[:port]> the address/port to listen on for control commands" << std::endl
;
202 std::cout
<< " [-p|--port-range] <start> <end> port range used to relay rtp connections" << std::endl
;
203 std::cout
<< " [-n|--nat] enable permantent automatic nat detection(use only with anytun)" << std::endl
;
204 std::cout
<< " [-o|--no-nat-once] disable automatic nat detection for new connections" << std::endl
;
205 // std::cout << " [-I|--sync-interface] <ip-address> local unicast(sync) ip address to bind to" << std::endl;
206 std::cout
<< " [-S|--sync-port] <port> local unicast(sync) port to bind to" << std::endl
;
207 std::cout
<< " [-M|--sync-hosts] <hostname|ip>:<port>[,<hostname|ip>:<port>[...]]"<< std::endl
;
208 std::cout
<< " List of Remote Sync Hosts/Ports"<< std::endl
;
211 void Options::printOptions()
214 std::cout
<< "Options:" << std::endl
;
215 std::cout
<< "chroot='" << chroot_
<< "'" << std::endl
;
216 std::cout
<< "username='" << username_
<< "'" << std::endl
;
217 std::cout
<< "chroot-dir='" << chroot_dir_
<< "'" << std::endl
;
218 std::cout
<< "daemonize='" << daemonize_
<< "'" << std::endl
;
219 std::cout
<< "control-interface='" << control_interface_
.toString() << "'" << std::endl
;
222 std::string
Options::getProgname()
228 bool Options::getChroot()
234 bool Options::getNat()
240 bool Options::getNoNatOnce()
246 std::string
Options::getUsername()
252 std::string
Options::getChrootDir()
258 bool Options::getDaemonize()
264 Host
Options::getControlInterface()
267 return control_interface_
;
270 u_int16_t
Options::getLocalSyncPort()
272 return local_sync_port_
;
275 Options
& Options::setLocalSyncPort(u_int16_t l
)
277 local_sync_port_
= l
;
281 u_int16_t
Options::getRtpStartPort()
283 return rtp_start_port_
;
286 Options
& Options::setRtpStartPort(u_int16_t l
)
292 u_int16_t
Options::getRtpEndPort()
294 return rtp_end_port_
;
297 Options
& Options::setRtpEndPort(u_int16_t l
)
303 ConnectToList
Options::getConnectTo()