Imported Upstream version 0.3.5
[anytun.git] / src / options.h
1 /*
2  *  anytun
3  *
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 methods 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.
12  *
13  *
14  *  Copyright (C) 2007-2014 Markus Grüneis, Othmar Gsenger, Erwin Nindl,
15  *                          Christian Pointner <satp@wirdorange.org>
16  *
17  *  This file is part of Anytun.
18  *
19  *  Anytun is free software: you can redistribute it and/or modify
20  *  it under the terms of the GNU General Public License as published by
21  *  the Free Software Foundation, either version 3 of the License, or
22  *  any later version.
23  *
24  *  Anytun is distributed in the hope that it will be useful,
25  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
26  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
27  *  GNU General Public License for more details.
28  *
29  *  You should have received a copy of the GNU General Public License
30  *  along with Anytun.  If not, see <http://www.gnu.org/licenses/>.
31  *
32  *  In addition, as a special exception, the copyright holders give
33  *  permission to link the code of portions of this program with the
34  *  OpenSSL library under certain conditions as described in each
35  *  individual source file, and distribute linked combinations
36  *  including the two.
37  *  You must obey the GNU General Public License in all respects
38  *  for all of the code used other than OpenSSL.  If you modify
39  *  file(s) with this exception, you may extend this exception to your
40  *  version of the file(s), but you are not obligated to do so.  If you
41  *  do not wish to do so, delete this exception statement from your
42  *  version.  If you delete this exception statement from all source
43  *  files in the program, then also delete it here.
44  */
45
46 #ifndef ANYTUN_options_h_INCLUDED
47 #define ANYTUN_options_h_INCLUDED
48
49 #include "datatypes.h"
50 #include "buffer.h"
51 #include "threadUtils.hpp"
52 #include <list>
53
54 class syntax_error : public std::runtime_error
55 {
56 public:
57   syntax_error(std::string t, int32_t p) : runtime_error(t), pos(p) {};
58   int32_t pos;
59 };
60 std::ostream& operator<<(std::ostream& stream, syntax_error const& error);
61
62 class OptionHost
63 {
64 public:
65   OptionHost() : addr(""), port("") {};
66   OptionHost(std::string addrPort) { init(addrPort); };
67   OptionHost(std::string a, std::string p) : addr(a), port(p) {};
68
69   void init(std::string addrPort);
70
71   std::string addr;
72   std::string port;
73 };
74 typedef std::list<OptionHost> HostList;
75 std::istream& operator>>(std::istream& stream, OptionHost& host);
76
77 class OptionNetwork
78 {
79 public:
80   OptionNetwork() : net_addr(""), prefix_length(0) {};
81   OptionNetwork(std::string network) { init(network); };
82   OptionNetwork(std::string n, uint16_t p) : net_addr(n), prefix_length(p) {};
83
84   void init(std::string network);
85
86   std::string net_addr;
87   uint16_t prefix_length;
88 };
89 typedef std::list<OptionNetwork> NetworkList;
90 std::istream& operator>>(std::istream& stream, OptionNetwork& network);
91
92 typedef std::list<std::string> StringList;
93
94 typedef enum { ROLE_LEFT, ROLE_RIGHT } role_t;
95 std::ostream& operator<<(std::ostream& stream, role_t const& role);
96
97 class Options
98 {
99 public:
100   static Options& instance();
101
102   bool parse(int argc, char* argv[]);
103   void parse_post();
104   void printVersion();
105   void printUsage();
106   void printOptions();
107
108   std::string getProgname();
109   Options& setProgname(std::string p);
110   bool getDaemonize();
111   Options& setDaemonize(bool d);
112   std::string getUsername();
113   Options& setUsername(std::string u);
114   std::string getGroupname();
115   Options& setGroupname(std::string g);
116   std::string getChrootDir();
117   Options& setChrootDir(std::string c);
118   std::string getPidFile();
119   Options& setPidFile(std::string p);
120
121   StringList getLogTargets();
122   bool getDebug();
123   Options& setDebug(bool d);
124
125   std::string getFileName();
126   Options& setFileName(std::string f);
127   std::string getBindToAddr();
128   Options& setBindToAddr(std::string b);
129   std::string getBindToPort();
130   Options& setBindToPort(std::string b);
131
132   ResolvAddrType getResolvAddrType();
133   Options& setResolvAddrType(ResolvAddrType r);
134   std::string getLocalAddr();
135   Options& setLocalAddr(std::string l);
136   std::string getLocalPort();
137   Options& setLocalPort(std::string l);
138   std::string getRemoteAddr();
139   Options& setRemoteAddr(std::string r);
140   std::string getRemotePort();
141   Options& setRemotePort(std::string r);
142
143   std::string getLocalSyncAddr();
144   Options& setLocalSyncAddr(std::string l);
145   std::string getLocalSyncPort();
146   Options& setLocalSyncPort(std::string l);
147   HostList getRemoteSyncHosts();
148
149   std::string getDevName();
150   Options& setDevName(std::string d);
151   std::string getDevType();
152   Options& setDevType(std::string d);
153   OptionNetwork getIfconfigParam();
154   Options& setIfconfigParam(OptionNetwork i);
155   std::string getPostUpScript();
156   Options& setPostUpScript(std::string p);
157   NetworkList getRoutes();
158
159   sender_id_t getSenderId();
160   Options& setSenderId(sender_id_t s);
161   mux_t getMux();
162   Options& setMux(mux_t m);
163   window_size_t getSeqWindowSize();
164   Options& setSeqWindowSize(window_size_t s);
165
166   std::string getCipher();
167   Options& setCipher(std::string c);
168   std::string getAuthAlgo();
169   Options& setAuthAlgo(std::string a);
170   uint32_t getAuthTagLength();
171   Options& setAuthTagLength(uint32_t a);
172   std::string getKdPrf();
173   Options& setKdPrf(std::string k);
174   role_t getRole();
175   Options& setRole(role_t r);
176   std::string getPassphrase();
177   Options& setPassphrase(std::string p);
178   Options& setKey(std::string k);
179   Buffer getKey();
180   Options& setSalt(std::string s);
181   Buffer getSalt();
182
183
184 private:
185   Options();
186   ~Options();
187   Options(const Options& l);
188   void operator=(const Options& l);
189
190   ::SharedMutex mutex;
191
192   bool cluster_opts;
193   bool connection_opts;
194
195   std::string progname_;
196   bool daemonize_;
197   std::string username_;
198   std::string groupname_;
199   std::string chroot_dir_;
200   std::string pid_file_;
201
202   StringList log_targets_;
203   bool debug_;
204
205   std::string file_name_;
206   OptionHost bind_to_;
207
208   ResolvAddrType resolv_addr_type_;
209   OptionHost local_;
210   OptionHost remote_;
211
212   OptionHost local_sync_;
213   HostList remote_sync_hosts_;
214
215   std::string dev_name_;
216   std::string dev_type_;
217   OptionNetwork ifconfig_param_;
218   std::string post_up_script_;
219   NetworkList routes_;
220
221   sender_id_t sender_id_;
222   mux_t mux_;
223   window_size_t seq_window_size_;
224
225   std::string cipher_;
226   std::string auth_algo_;
227   uint32_t auth_tag_length_;
228   std::string kd_prf_;
229   role_t role_;
230   std::string passphrase_;
231   Buffer key_;
232   Buffer salt_;
233 };
234
235 extern Options& gOpt;
236
237 #endif