added passphrase support to key derivation
[anytun.git] / src / options.h
blob694526ef2215d0ebedc6f46e50fc8749bbb6c517
1 /*
2 * anytun
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/>.
32 #ifndef _OPTIONS_H_
33 #define _OPTIONS_H_
35 #include "datatypes.h"
36 #include "buffer.h"
37 #include "threadUtils.hpp"
38 #include <list>
40 class syntax_error : public std::runtime_error
42 public:
43 syntax_error(std::string t, u_int32_t p) : runtime_error(t), pos(p) {};
44 u_int32_t pos;
46 std::ostream& operator<<(std::ostream& stream, syntax_error const& error);
48 class OptionHost
50 public:
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);
57 std::string addr;
58 std::string port;
60 typedef std::list<OptionHost> HostList;
61 std::istream& operator>>(std::istream& stream, OptionHost& host);
63 class OptionRoute
65 public:
66 OptionRoute() : net_addr(""), prefix_length(0) {};
67 OptionRoute(std::string route) { init(route); };
68 OptionRoute(std::string n, u_int16_t p) : net_addr(n), prefix_length(p) {};
70 void init(std::string route);
72 std::string net_addr;
73 u_int16_t prefix_length;
75 typedef std::list<OptionRoute> RouteList;
76 std::istream& operator>>(std::istream& stream, OptionRoute& route);
78 class Options
80 public:
81 static Options& instance();
83 bool parse(int argc, char* argv[]);
84 void printUsage();
85 void printOptions();
87 std::string getProgname();
88 Options& setProgname(std::string p);
89 bool getDaemonize();
90 Options& setDaemonize(bool d);
91 bool getChroot();
92 Options& setChroot(bool b);
93 std::string getUsername();
94 Options& setUsername(std::string u);
95 std::string getChrootDir();
96 Options& setChrootDir(std::string c);
97 std::string getPidFile();
98 Options& setPidFile(std::string p);
100 std::string getFileName();
101 Options& setFileName(std::string f);
102 std::string getBindToAddr();
103 Options& setBindToAddr(std::string b);
104 std::string getBindToPort();
105 Options& setBindToPort(std::string b);
107 std::string getLocalAddr();
108 Options& setLocalAddr(std::string l);
109 std::string getLocalPort();
110 Options& setLocalPort(std::string l);
111 std::string getRemoteAddr();
112 Options& setRemoteAddr(std::string r);
113 std::string getRemotePort();
114 Options& setRemotePort(std::string r);
116 std::string getLocalSyncAddr();
117 Options& setLocalSyncAddr(std::string l);
118 std::string getLocalSyncPort();
119 Options& setLocalSyncPort(std::string l);
120 HostList getRemoteSyncHosts();
122 std::string getDevName();
123 Options& setDevName(std::string d);
124 std::string getDevType();
125 Options& setDevType(std::string d);
126 std::string getIfconfigParamLocal();
127 Options& setIfconfigParamLocal(std::string i);
128 std::string getIfconfigParamRemoteNetmask();
129 Options& setIfconfigParamRemoteNetmask(std::string i);
130 std::string getPostUpScript();
131 Options& setPostUpScript(std::string p);
132 RouteList getRoutes();
134 sender_id_t getSenderId();
135 Options& setSenderId(sender_id_t s);
136 mux_t getMux();
137 Options& setMux(mux_t m);
138 window_size_t getSeqWindowSize();
139 Options& setSeqWindowSize(window_size_t s);
141 std::string getCipher();
142 Options& setCipher(std::string c);
143 std::string getAuthAlgo();
144 Options& setAuthAlgo(std::string a);
145 std::string getKdPrf();
146 Options& setKdPrf(std::string k);
147 int8_t getLdKdr();
148 Options& setLdKdr(int8_t l);
149 std::string getPassphrase();
150 Options& setPassphrase(std::string p);
151 Options& setKey(std::string k);
152 Buffer getKey();
153 Options& setSalt(std::string s);
154 Buffer getSalt();
157 private:
158 Options();
159 ~Options();
160 Options(const Options &l);
161 void operator=(const Options &l);
163 static Options* inst;
164 static ::Mutex instMutex;
165 class instanceCleaner {
166 public: ~instanceCleaner() {
167 if(Options::inst != 0)
168 delete Options::inst;
171 friend class instanceCleaner;
173 ::SharedMutex mutex;
175 std::string progname_;
176 bool daemonize_;
177 bool chroot_;
178 std::string username_;
179 std::string chroot_dir_;
180 std::string pid_file_;
182 std::string file_name_;
183 OptionHost bind_to_;
185 OptionHost local_;
186 OptionHost remote_;
188 OptionHost local_sync_;
189 HostList remote_sync_hosts_;
191 std::string dev_name_;
192 std::string dev_type_;
193 std::string ifconfig_param_local_;
194 std::string ifconfig_param_remote_netmask_;
195 std::string post_up_script_;
196 RouteList routes_;
198 sender_id_t sender_id_;
199 mux_t mux_;
200 window_size_t seq_window_size_;
202 std::string cipher_;
203 std::string auth_algo_;
204 std::string kd_prf_;
205 int8_t ld_kdr_;
206 std::string passphrase_;
207 Buffer key_;
208 Buffer salt_;
211 extern Options& gOpt;
213 #endif