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))
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(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])); \
113 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
114 else if(str == SHORT || str == LONG) \
116 if(argc < 1 || argv[i+1][0] == '-') \
118 std::stringstream tmp(argv[i+1]); \
121 std::string tmp_line; \
122 getline(tmp,tmp_line,','); \
123 LIST.push(tmp_line); \
129 bool Options::parse(int argc
, char* argv
[])
135 std::queue
<std::string
> host_port_queue
;
136 for(int i
=1; argc
> 0; ++i
)
138 std::string
str(argv
[i
]);
141 if(str
== "-h" || str
== "--help")
143 PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_
)
144 PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_
)
145 PARSE_SCALAR_PARAM("-n","--prefix", ifconfig_param_remote_netmask_
)
146 PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_
)
147 PARSE_SCALAR_PARAM("-m","--mux", mux_
)
148 PARSE_SCALAR_PARAM("-l","--prefix-len", network_prefix_length_
)
149 PARSE_HEXSTRING_PARAM("-K","--key", key_
)
150 PARSE_HEXSTRING_PARAM("-A","--salt", salt_
)
151 PARSE_SCALAR_PARAM("-k","--kd-prf", kd_prf_
)
156 while(!host_port_queue
.empty())
158 std::stringstream
tmp_stream(host_port_queue
.front());
160 getline(tmp_stream
,oct
.host
,':');
161 if(!tmp_stream
.good())
163 tmp_stream
>> oct
.port
;
164 host_port_queue
.pop();
165 connect_to_
.push_back(oct
);
170 void Options::printUsage()
172 std::cout
<< "USAGE:" << std::endl
;
173 std::cout
<< "anyctr [-h|--help] prints this..." << std::endl
;
174 std::cout
<< " [-r|--remote-host] <hostname|ip> remote host" << std::endl
;
175 std::cout
<< " [-o|--remote-port] <port> remote port" << std::endl
;
176 std::cout
<< " [-n|--prefix] <remote net> remote subnet for route" << std::endl
;
177 std::cout
<< " [-w|--window-size] <window size> seqence number window size" << std::endl
;
178 std::cout
<< " [-m|--mux] <mux-id> the multiplex id to use" << std::endl
;
179 std::cout
<< " [-l|--prefix-len] <prefix length> network prefix length" << std::endl
;
180 std::cout
<< " [-K|--key] <master key> master key to use for encryption" << std::endl
;
181 std::cout
<< " [-A|--salt] <master salt> master salt to use for encryption" << std::endl
;
182 std::cout
<< " [-k|--kd-prf] <kd-prf type> key derivation pseudo random function" << std::endl
;
185 void Options::printOptions()
188 std::cout
<< "Options:" << std::endl
;
189 std::cout
<< "remote_addr='" << remote_addr_
<< "'" << std::endl
;
190 std::cout
<< "remote_port='" << remote_port_
<< "'" << std::endl
;
191 std::cout
<< "ifconfig_param_local='" << ifconfig_param_local_
<< "'" << std::endl
;
192 std::cout
<< "ifconfig_param_remote_netmask='" << ifconfig_param_remote_netmask_
<< "'" << std::endl
;
193 std::cout
<< "seq_window_size='" << seq_window_size_
<< "'" << std::endl
;
194 std::cout
<< "mux_id='" << mux_
<< "'" << std::endl
;
195 std::cout
<< "network_prefix_length='" << network_prefix_length_
<< "'" << std::endl
;
196 std::cout
<< "key=" << key_
.getHexDumpOneLine() << std::endl
;
197 std::cout
<< "salt=" << salt_
.getHexDumpOneLine() << std::endl
;
198 std::cout
<< "kd_prf='" << kd_prf_
<< "'" << std::endl
;
201 std::string
Options::getProgname()
208 Options
& Options::setProgname(std::string p
)
216 std::string
Options::getRemoteAddr()
222 Options
& Options::setRemoteAddr(std::string r
)
229 u_int16_t
Options::getRemotePort()
234 Options
& Options::setRemotePort(u_int16_t r
)
240 Options
& Options::setRemoteAddrPort(std::string addr
, u_int16_t port
)
248 std::string
Options::getIfconfigParamRemoteNetmask()
251 return ifconfig_param_remote_netmask_
;
254 Options
& Options::setIfconfigParamRemoteNetmask(std::string i
)
257 ifconfig_param_remote_netmask_
= i
;
261 window_size_t
Options::getSeqWindowSize()
263 return seq_window_size_
;
266 Options
& Options::setSeqWindowSize(window_size_t s
)
268 seq_window_size_
= s
;
273 std::string
Options::getKdPrf()
279 Options
& Options::setKdPrf(std::string k
)
286 u_int16_t
Options::getMux()
292 Options
& Options::setMux(u_int16_t m
)
299 u_int16_t
Options::getNetworkPrefixLength()
302 return network_prefix_length_
;
305 Options
& Options::setNetworkPrefixLength(u_int16_t l
)
308 network_prefix_length_
= l
;
312 Buffer
Options::getKey()
318 Options
& Options::setKey(std::string k
)
325 Buffer
Options::getSalt()
331 Options
& Options::setSalt(std::string s
)