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-2008 Othmar Gsenger, Erwin Nindl,
15 * Christian Pointner <satp@wirdorange.org>
17 * This file is part of Anytun.
19 * Anytun is free software: you can redistribute it and/or modify
20 * it under the terms of the GNU General Public License version 3 as
21 * published by the Free Software Foundation.
23 * Anytun is distributed in the hope that it will be useful,
24 * but WITHOUT ANY WARRANTY; without even the implied warranty of
25 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
26 * GNU General Public License for more details.
28 * You should have received a copy of the GNU General Public License
29 * along with anytun. If not, see <http://www.gnu.org/licenses/>.
37 #include "datatypes.h"
38 #include "anyCtrOptions.h"
40 Options
* Options::inst
= NULL
;
41 Mutex
Options::instMutex
;
42 Options
& gOpt
= Options::instance();
44 Options
& Options::instance()
47 static instanceCleaner c
;
56 progname_
= "anytun-controld";
61 chroot_dir_
= "/var/run/anytun-controld";
63 bind_to_addr_
= "127.0.0.1";
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_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \
106 else if(str == SHORT || str == LONG) \
108 if(argc < 1 || argv[i+1][0] == '-') \
110 VALUE = Buffer(std::string(argv[i+1])); \
111 for(size_t j=0; j < strlen(argv[i+1]); ++j) \
112 argv[i+1][j] = '#'; \
117 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
118 else if(str == SHORT || str == LONG) \
120 if(argc < 1 || argv[i+1][0] == '-') \
122 std::stringstream tmp(argv[i+1]); \
125 std::string tmp_line; \
126 getline(tmp,tmp_line,','); \
127 LIST.push(tmp_line); \
133 bool Options::parse(int argc
, char* argv
[])
140 std::string
control_host("");
141 for(int i
=1; argc
> 0; ++i
)
143 std::string
str(argv
[i
]);
146 if(str
== "-h" || str
== "--help")
148 PARSE_SCALAR_PARAM("-f","--file", file_name_
)
149 PARSE_INVERSE_BOOL_PARAM("-D","--nodaemonize", daemonize_
)
150 PARSE_BOOL_PARAM("-C","--chroot", chroot_
)
151 PARSE_SCALAR_PARAM("-u","--username", username_
)
152 PARSE_SCALAR_PARAM("-H","--chroot-dir", chroot_dir_
)
153 PARSE_SCALAR_PARAM("-P","--write-pid", pid_file_
)
154 PARSE_SCALAR_PARAM("-X","--control-host", control_host
)
159 if(control_host
!= "") {
160 std::stringstream
tmp_stream(control_host
);
161 getline(tmp_stream
,bind_to_addr_
,':');
162 if(!tmp_stream
.good())
164 tmp_stream
>> bind_to_port_
;
170 void Options::printUsage()
172 std::cout
<< "USAGE:" << std::endl
;
173 std::cout
<< "anytun-controld [-h|--help] prints this..." << std::endl
;
174 std::cout
<< " [-D|--nodaemonize] don't run in background" << std::endl
;
175 std::cout
<< " [-C|--chroot] chroot and drop privileges" << std::endl
;
176 std::cout
<< " [-u|--username] <username> if chroot change to this user" << std::endl
;
177 std::cout
<< " [-H|--chroot-dir] <path> chroot to this directory" << std::endl
;
178 std::cout
<< " [-P|--write-pid] <path> write pid to this file" << std::endl
;
179 std::cout
<< " [-f|--file] <path> path to file" << std::endl
;
180 std::cout
<< " [-X|--control-host] <host:port> local tcp port to bind to" << std::endl
;
184 void Options::printOptions()
187 std::cout
<< "Options:" << std::endl
;
188 std::cout
<< "daemonize=" << daemonize_
<< std::endl
;
189 std::cout
<< "chroot=" << chroot_
<< std::endl
;
190 std::cout
<< "username='" << username_
<< "'" << std::endl
;
191 std::cout
<< "chroot_dir='" << chroot_dir_
<< "'" << std::endl
;
192 std::cout
<< "pid_file='" << pid_file_
<< "'" << std::endl
;
195 std::string
Options::getProgname()
202 Options
& Options::setProgname(std::string p
)
209 bool Options::getDaemonize()
214 Options
& Options::setDaemonize(bool d
)
220 bool Options::getChroot()
225 Options
& Options::setChroot(bool c
)
231 std::string
Options::getUsername()
237 Options
& Options::setUsername(std::string u
)
244 std::string
Options::getChrootDir()
250 Options
& Options::setChrootDir(std::string c
)
257 std::string
Options::getPidFile()
263 Options
& Options::setPidFile(std::string p
)
270 std::string
Options::getFileName()
276 Options
& Options::setFileName(std::string f
)
283 std::string
Options::getBindToAddr()
286 return bind_to_addr_
;
289 Options
& Options::setBindToAddr(std::string b
)
296 uint16_t Options::getBindToPort()
298 return bind_to_port_
;
301 Options
& Options::setBindToPort(uint16_t b
)