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/>.
35 #include "datatypes.h"
37 #include "threadUtils.hpp"
40 class syntax_error : public std::runtime_error
43 syntax_error(std::string t, int32_t p) : runtime_error(t), pos(p) {};
46 std::ostream& operator<<(std::ostream& stream, syntax_error const& error);
51 OptionHost() : addr(""), port("") {};
52 OptionHost(std::string addrPort) { init(addrPort); };
53 OptionHost(std::string a, std::string p) : addr(a), port(p) {};
55 void init(std::string addrPort);
60 typedef std::list<OptionHost> HostList;
61 std::istream& operator>>(std::istream& stream, OptionHost& host);
66 OptionNetwork() : net_addr(""), prefix_length(0) {};
67 OptionNetwork(std::string network) { init(network); };
68 OptionNetwork(std::string n, u_int16_t p) : net_addr(n), prefix_length(p) {};
70 void init(std::string network);
73 u_int16_t prefix_length;
75 typedef std::list<OptionNetwork> NetworkList;
76 std::istream& operator>>(std::istream& stream, OptionNetwork& network);
78 typedef std::list<std::string> StringList;
80 typedef enum { ROLE_LEFT, ROLE_RIGHT } role_t;
81 std::ostream& operator<<(std::ostream& stream, role_t const& role);
86 static Options& instance();
88 bool parse(int argc, char* argv[]);
93 std::string getProgname();
94 Options& setProgname(std::string p);
96 Options& setDaemonize(bool d);
97 std::string getUsername();
98 Options& setUsername(std::string u);
99 std::string getGroupname();
100 Options& setGroupname(std::string g);
101 std::string getChrootDir();
102 Options& setChrootDir(std::string c);
103 std::string getPidFile();
104 Options& setPidFile(std::string p);
106 StringList getLogTargets();
108 std::string getFileName();
109 Options& setFileName(std::string f);
110 std::string getBindToAddr();
111 Options& setBindToAddr(std::string b);
112 std::string getBindToPort();
113 Options& setBindToPort(std::string b);
115 ResolvAddrType getResolvAddrType();
116 Options& setResolvAddrType(ResolvAddrType r);
117 std::string getLocalAddr();
118 Options& setLocalAddr(std::string l);
119 std::string getLocalPort();
120 Options& setLocalPort(std::string l);
121 std::string getRemoteAddr();
122 Options& setRemoteAddr(std::string r);
123 std::string getRemotePort();
124 Options& setRemotePort(std::string r);
126 std::string getLocalSyncAddr();
127 Options& setLocalSyncAddr(std::string l);
128 std::string getLocalSyncPort();
129 Options& setLocalSyncPort(std::string l);
130 HostList getRemoteSyncHosts();
132 std::string getDevName();
133 Options& setDevName(std::string d);
134 std::string getDevType();
135 Options& setDevType(std::string d);
136 OptionNetwork getIfconfigParam();
137 Options& setIfconfigParam(OptionNetwork i);
138 std::string getPostUpScript();
139 Options& setPostUpScript(std::string p);
140 NetworkList getRoutes();
142 sender_id_t getSenderId();
143 Options& setSenderId(sender_id_t s);
145 Options& setMux(mux_t m);
146 window_size_t getSeqWindowSize();
147 Options& setSeqWindowSize(window_size_t s);
149 std::string getCipher();
150 Options& setCipher(std::string c);
151 std::string getAuthAlgo();
152 Options& setAuthAlgo(std::string a);
153 u_int32_t getAuthTagLength();
154 Options& setAuthTagLength(u_int32_t a);
155 std::string getKdPrf();
156 Options& setKdPrf(std::string k);
158 Options& setRole(role_t r);
159 std::string getPassphrase();
160 Options& setPassphrase(std::string p);
161 Options& setKey(std::string k);
163 Options& setSalt(std::string s);
170 Options(const Options &l);
171 void operator=(const Options &l);
173 static Options* inst;
174 static ::Mutex instMutex;
175 class instanceCleaner {
176 public: ~instanceCleaner() {
177 if(Options::inst != 0)
178 delete Options::inst;
181 friend class instanceCleaner;
187 bool connection_opts;
189 std::string progname_;
191 std::string username_;
192 std::string groupname_;
193 std::string chroot_dir_;
194 std::string pid_file_;
196 StringList log_targets_;
198 std::string file_name_;
201 ResolvAddrType resolv_addr_type_;
205 OptionHost local_sync_;
206 HostList remote_sync_hosts_;
208 std::string dev_name_;
209 std::string dev_type_;
210 OptionNetwork ifconfig_param_;
211 std::string post_up_script_;
214 sender_id_t sender_id_;
216 window_size_t seq_window_size_;
219 std::string auth_algo_;
220 u_int32_t auth_tag_length_;
223 std::string passphrase_;
228 extern Options& gOpt;