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 "anyConfOptions.h"
40 Options
* Options::inst
= NULL
;
41 Mutex
Options::instMutex
;
42 Options
& gOpt
= Options::instance();
44 Options
& Options::instance()
47 static instanceCleaner c
;
54 Options::Options() : key_(u_int32_t(0)), salt_(u_int32_t(0))
56 progname_
= "anytun-config";
59 seq_window_size_
= 100;
68 #define PARSE_BOOL_PARAM(SHORT, LONG, VALUE) \
69 else if(str == SHORT || str == LONG) \
72 #define PARSE_INVERSE_BOOL_PARAM(SHORT, LONG, VALUE) \
73 else if(str == SHORT || str == LONG) \
76 #define PARSE_SCALAR_PARAM(SHORT, LONG, VALUE) \
77 else if(str == SHORT || str == LONG) \
79 if(argc < 1 || argv[i+1][0] == '-') \
81 std::stringstream tmp; \
88 #define PARSE_SCALAR_PARAM2(SHORT, LONG, VALUE1, VALUE2) \
89 else if(str == SHORT || str == LONG) \
92 argv[i+1][0] == '-' || argv[i+2][0] == '-') \
94 std::stringstream tmp; \
95 tmp << argv[i+1] << " " << argv[i+2]; \
102 #define PARSE_HEXSTRING_PARAM_SEC(SHORT, LONG, VALUE) \
103 else if(str == SHORT || str == LONG) \
105 if(argc < 1 || argv[i+1][0] == '-') \
107 VALUE = Buffer(std::string(argv[i+1])); \
108 for(size_t j=0; j < strlen(argv[i+1]); ++j) \
109 argv[i+1][j] = '#'; \
114 #define PARSE_CSLIST_PARAM(SHORT, LONG, LIST) \
115 else if(str == SHORT || str == LONG) \
117 if(argc < 1 || argv[i+1][0] == '-') \
119 std::stringstream tmp(argv[i+1]); \
122 std::string tmp_line; \
123 getline(tmp,tmp_line,','); \
124 LIST.push(tmp_line); \
130 bool Options::parse(int argc
, char* argv
[])
136 std::queue
<std::string
> route_queue
;
137 for(int i
=1; argc
> 0; ++i
)
139 std::string
str(argv
[i
]);
142 if(str
== "-h" || str
== "--help")
144 PARSE_SCALAR_PARAM("-r","--remote-host", remote_addr_
)
145 PARSE_SCALAR_PARAM("-o","--remote-port", remote_port_
)
146 PARSE_SCALAR_PARAM("-w","--window-size", seq_window_size_
)
147 PARSE_SCALAR_PARAM("-m","--mux", mux_
)
148 PARSE_HEXSTRING_PARAM_SEC("-K","--key", key_
)
149 PARSE_HEXSTRING_PARAM_SEC("-A","--salt", salt_
)
150 PARSE_SCALAR_PARAM("-k","--kd-prf", kd_prf_
)
151 PARSE_CSLIST_PARAM("-R","--route", route_queue
)
156 while(!route_queue
.empty())
158 std::stringstream
tmp_stream(route_queue
.front());
160 getline(tmp_stream
,rt
.net_addr
,'/');
161 if(!tmp_stream
.good())
163 tmp_stream
>> rt
.prefix_length
;
165 routes_
.push_back(rt
);
170 void Options::printUsage()
172 std::cout
<< "USAGE:" << std::endl
;
173 std::cout
<< "anytun-config [-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
<< " [-w|--window-size] <window size> seqence number window size" << std::endl
;
177 std::cout
<< " [-m|--mux] <mux-id> the multiplex id to use" << std::endl
;
178 std::cout
<< " [-K|--key] <master key> master key to use for encryption" << std::endl
;
179 std::cout
<< " [-A|--salt] <master salt> master salt to use for encryption" << std::endl
;
180 // std::cout << " [-k|--kd-prf] <kd-prf type> key derivation pseudo random function" << std::endl;
181 std::cout
<< " [-R|--route] <net>/<prefix length> add a route to connection, can be invoked several times" << std::endl
;
184 void Options::printOptions()
187 std::cout
<< "Options:" << std::endl
;
188 std::cout
<< "remote_addr='" << remote_addr_
<< "'" << std::endl
;
189 std::cout
<< "remote_port='" << remote_port_
<< "'" << std::endl
;
190 std::cout
<< "seq_window_size='" << seq_window_size_
<< "'" << std::endl
;
191 std::cout
<< "mux_id='" << mux_
<< "'" << std::endl
;
192 std::cout
<< "key=" << key_
.getHexDumpOneLine() << std::endl
;
193 std::cout
<< "salt=" << salt_
.getHexDumpOneLine() << std::endl
;
194 std::cout
<< "kd_prf='" << kd_prf_
<< "'" << std::endl
;
196 std::cout
<< "routes:" << std::endl
;
197 RouteList::const_iterator rit
;
198 for(rit
= routes_
.begin(); rit
!= routes_
.end(); ++rit
)
199 std::cout
<< " " << rit
->net_addr
<< "/" << rit
->prefix_length
<< std::endl
;
202 std::string
Options::getProgname()
209 Options
& Options::setProgname(std::string p
)
217 std::string
Options::getRemoteAddr()
223 Options
& Options::setRemoteAddr(std::string r
)
230 u_int16_t
Options::getRemotePort()
235 Options
& Options::setRemotePort(u_int16_t r
)
241 Options
& Options::setRemoteAddrPort(std::string addr
, u_int16_t port
)
249 window_size_t
Options::getSeqWindowSize()
251 return seq_window_size_
;
254 Options
& Options::setSeqWindowSize(window_size_t s
)
256 seq_window_size_
= s
;
261 std::string
Options::getKdPrf()
267 Options
& Options::setKdPrf(std::string k
)
274 u_int16_t
Options::getMux()
280 Options
& Options::setMux(u_int16_t m
)
287 Buffer
Options::getKey()
293 Options
& Options::setKey(std::string k
)
300 Buffer
Options::getSalt()
306 Options
& Options::setSalt(std::string s
)
313 RouteList
Options::getRoutes()