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
36 #include "datatypes.h"
37 #include "anyctrOptions.h"
39 Options
* Options::inst
= NULL
;
40 Mutex
Options::instMutex
;
41 Options
& gOpt
= Options::instance();
43 Options
& Options::instance()
46 static instanceCleaner c
;
53 Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0))
55 progname_
= "anytun-config";
58 ifconfig_param_remote_netmask_
= "255.255.255.0";
59 seq_window_size_
= 100;
62 network_prefix_length_
= 32;
69 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
70 else if(str == SHORT || str == LONG) \
73 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
74 else if(str == SHORT || str == LONG) \
77 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
78 else if(str == SHORT || str == LONG) \
80 if(argc < 1 || argv[i+1][0] == '-') \
82 std::stringstream tmp; \
89 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
90 else if(str == SHORT || str == LONG) \
93 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
95 std::stringstream tmp; \
96 tmp << argv[i+1] << " " << argv[i+2]; \
103 #define PARSE_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \
104 else if(str == SHORT || str == LONG) \
106 if(argc < 1 || argv[i+1][0] == '-') \
108 VALUE = Buffer(std::string(argv[i+1])); \
109 for(size_t j=0; j < strlen(argv[i+1]); ++j) \
110 argv[i+1][j] = '#'; \
115 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
116 else if(str == SHORT || str == LONG) \
118 if(argc < 1 || argv[i+1][0] == '-') \
120 std::stringstream tmp(argv[i+1]); \
123 std::string tmp_line; \
124 getline(tmp,tmp_line,','); \
125 LIST.push(tmp_line); \
131 bool Options::parse(int argc
, char* argv
[])
137 std::queue
<std::string
> host_port_queue
;
138 for(int i
=1; argc
> 0; ++i
)
140 std::string
str(argv
[i
]);
143 if(str
== "-h" || str
== "--help")
145 PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_
)
146 PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_
)
147 PARSE_SCALAR_PARAM("-n","--prefix", ifconfig_param_remote_netmask_
)
148 PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_
)
149 PARSE_SCALAR_PARAM("-m","--mux", mux_
)
150 PARSE_SCALAR_PARAM("-l","--prefix-len", network_prefix_length_
)
151 PARSE_HEXSTRING_PARAM_SEC("-K","--key", key_
)
152 PARSE_HEXSTRING_PARAM_SEC("-A","--salt", salt_
)
153 PARSE_SCALAR_PARAM("-k","--kd-prf", kd_prf_
)
158 while(!host_port_queue
.empty())
160 std::stringstream
tmp_stream(host_port_queue
.front());
162 getline(tmp_stream
,oct
.host
,':');
163 if(!tmp_stream
.good())
165 tmp_stream
>> oct
.port
;
166 host_port_queue
.pop();
167 connect_to_
.push_back(oct
);
172 void Options::printUsage()
174 std::cout
<< "USAGE:" << std::endl
;
175 std::cout
<< "anytun-config" << std::endl
;
176 std::cout
<< " [-h|--help] prints this..." << std::endl
;
177 std::cout
<< " [-r|--remote-host] <hostname|ip> remote host" << std::endl
;
178 std::cout
<< " [-o|--remote-port] <port> remote port" << std::endl
;
179 std::cout
<< " [-n|--prefix] <remote net> remote subnet for route" << std::endl
;
180 std::cout
<< " [-w|--window-size] <window size> seqence number window size" << std::endl
;
181 std::cout
<< " [-m|--mux] <mux-id> the multiplex id to use" << std::endl
;
182 std::cout
<< " [-l|--prefix-len] <prefix length> network prefix length" << std::endl
;
183 std::cout
<< " [-K|--key] <master key> master key to use for encryption" << std::endl
;
184 std::cout
<< " [-A|--salt] <master salt> master salt to use for encryption" << std::endl
;
185 std::cout
<< " [-k|--kd-prf] <kd-prf type> key derivation pseudo random function" << std::endl
;
188 void Options::printOptions()
191 std::cout
<< "Options:" << std::endl
;
192 std::cout
<< "remote_addr='" << remote_addr_
<< "'" << std::endl
;
193 std::cout
<< "remote_port='" << remote_port_
<< "'" << std::endl
;
194 std::cout
<< "ifconfig_param_local='" << ifconfig_param_local_
<< "'" << std::endl
;
195 std::cout
<< "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_
<< "'" << std::endl
;
196 std::cout
<< "seq_window_size='" << seq_window_size_
<< "'" << std::endl
;
197 std::cout
<< "mux_id='" << mux_
<< "'" << std::endl
;
198 std::cout
<< "network_prefix_length='" << network_prefix_length_
<< "'" << std::endl
;
199 std::cout
<< "key=" << key_
.getHexDumpOneLine() << std::endl
;
200 std::cout
<< "salt=" << salt_
.getHexDumpOneLine() << std::endl
;
201 std::cout
<< "kd_prf='" << kd_prf_
<< "'" << std::endl
;
204 std::string
Options::getProgname()
211 Options
& Options::setProgname(std::string p
)
219 std::string
Options::getRemoteAddr()
225 Options
& Options::setRemoteAddr(std::string r
)
232 u_int16_t
Options::getRemotePort()
237 Options
& Options::setRemotePort(u_int16_t r
)
243 Options
& Options::setRemoteAddrPort(std::string addr
, u_int16_t port
)
251 std::string
Options::getIfconfigParamRemoteNetmask()
254 return ifconfig_param_remote_netmask_
;
257 Options
& Options::setIfconfigParamRemoteNetmask(std::string i
)
260 ifconfig_param_remote_netmask_
= i
;
264 window_size_t
Options::getSeqWindowSize()
266 return seq_window_size_
;
269 Options
& Options::setSeqWindowSize(window_size_t s
)
271 seq_window_size_
= s
;
276 std::string
Options::getKdPrf()
282 Options
& Options::setKdPrf(std::string k
)
289 u_int16_t
Options::getMux()
295 Options
& Options::setMux(u_int16_t m
)
302 u_int16_t
Options::getNetworkPrefixLength()
305 return network_prefix_length_
;
308 Options
& Options::setNetworkPrefixLength(u_int16_t l
)
311 network_prefix_length_
= l
;
315 Buffer
Options::getKey()
321 Options
& Options::setKey(std::string k
)
328 Buffer
Options::getSalt()
334 Options
& Options::setSalt(std::string s
)