~ubuntu-branches/ubuntu/lucid/anytun/lucid

« back to all changes in this revision

Viewing changes to src/options.h

  • Committer: Bazaar Package Importer
  • Author(s): Michael Prokop
  • Date: 2009-12-14 02:08:25 UTC
  • Revision ID: james.westby@ubuntu.com-20091214020825-ntyi58y4wvsaglhi
Tags: upstream-0.3.2
ImportĀ upstreamĀ versionĀ 0.3.2

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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 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.
 
12
 *
 
13
 *
 
14
 *  Copyright (C) 2007-2009 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
 
 
33
#ifndef ANYTUN_options_h_INCLUDED
 
34
#define ANYTUN_options_h_INCLUDED
 
35
 
 
36
#include "datatypes.h"
 
37
#include "buffer.h"
 
38
#include "threadUtils.hpp"
 
39
#include <list>
 
40
 
 
41
class syntax_error : public std::runtime_error
 
42
{
 
43
public:
 
44
  syntax_error(std::string t, int32_t p) : runtime_error(t), pos(p) {};
 
45
  int32_t pos;
 
46
};
 
47
std::ostream& operator<<(std::ostream& stream, syntax_error const& error);
 
48
 
 
49
class OptionHost
 
50
{
 
51
public:
 
52
  OptionHost() : addr(""), port("") {};
 
53
  OptionHost(std::string addrPort) { init(addrPort); };
 
54
  OptionHost(std::string a, std::string p) : addr(a), port(p) {};
 
55
 
 
56
  void init(std::string addrPort);
 
57
 
 
58
  std::string addr;
 
59
        std::string port;
 
60
};
 
61
typedef std::list<OptionHost> HostList;
 
62
std::istream& operator>>(std::istream& stream, OptionHost& host);
 
63
 
 
64
class OptionNetwork
 
65
{
 
66
public:
 
67
  OptionNetwork() : net_addr(""), prefix_length(0) {};
 
68
  OptionNetwork(std::string network) { init(network); };
 
69
  OptionNetwork(std::string n, u_int16_t p) : net_addr(n), prefix_length(p) {};
 
70
 
 
71
  void init(std::string network);
 
72
 
 
73
  std::string net_addr;
 
74
  u_int16_t prefix_length;
 
75
};
 
76
typedef std::list<OptionNetwork> NetworkList;
 
77
std::istream& operator>>(std::istream& stream, OptionNetwork& network);
 
78
 
 
79
typedef std::list<std::string> StringList;
 
80
 
 
81
typedef enum { ROLE_LEFT, ROLE_RIGHT } role_t;
 
82
std::ostream& operator<<(std::ostream& stream, role_t const& role);
 
83
 
 
84
class Options
 
85
{
 
86
public:
 
87
  static Options& instance();
 
88
 
 
89
  bool parse(int argc, char* argv[]);
 
90
  void parse_post();
 
91
  void printUsage();
 
92
  void printOptions();
 
93
 
 
94
  std::string getProgname();
 
95
  Options& setProgname(std::string p);
 
96
  bool getDaemonize();
 
97
  Options& setDaemonize(bool d);
 
98
  std::string getUsername();
 
99
  Options& setUsername(std::string u);
 
100
  std::string getGroupname();
 
101
  Options& setGroupname(std::string g);
 
102
  std::string getChrootDir();
 
103
  Options& setChrootDir(std::string c);
 
104
  std::string getPidFile();
 
105
  Options& setPidFile(std::string p);
 
106
 
 
107
  StringList getLogTargets();
 
108
 
 
109
  std::string getFileName();
 
110
  Options& setFileName(std::string f);
 
111
  std::string getBindToAddr();
 
112
  Options& setBindToAddr(std::string b);
 
113
  std::string getBindToPort();
 
114
  Options& setBindToPort(std::string b);
 
115
 
 
116
  ResolvAddrType getResolvAddrType();
 
117
  Options& setResolvAddrType(ResolvAddrType r);
 
118
  std::string getLocalAddr();
 
119
  Options& setLocalAddr(std::string l);
 
120
  std::string getLocalPort();
 
121
  Options& setLocalPort(std::string l);
 
122
  std::string getRemoteAddr();
 
123
  Options& setRemoteAddr(std::string r);
 
124
  std::string getRemotePort();
 
125
  Options& setRemotePort(std::string r);
 
126
 
 
127
  std::string getLocalSyncAddr();
 
128
  Options& setLocalSyncAddr(std::string l);
 
129
  std::string getLocalSyncPort();
 
130
  Options& setLocalSyncPort(std::string l);
 
131
        HostList getRemoteSyncHosts();
 
132
 
 
133
  std::string getDevName();
 
134
  Options& setDevName(std::string d);
 
135
  std::string getDevType();
 
136
  Options& setDevType(std::string d);
 
137
  OptionNetwork getIfconfigParam();
 
138
  Options& setIfconfigParam(OptionNetwork i);
 
139
  std::string getPostUpScript();
 
140
  Options& setPostUpScript(std::string p);
 
141
  NetworkList getRoutes();
 
142
 
 
143
  sender_id_t getSenderId();
 
144
  Options& setSenderId(sender_id_t s);
 
145
  mux_t getMux();
 
146
  Options& setMux(mux_t m);
 
147
  window_size_t getSeqWindowSize();
 
148
  Options& setSeqWindowSize(window_size_t s);
 
149
 
 
150
  std::string getCipher();
 
151
  Options& setCipher(std::string c);
 
152
  std::string getAuthAlgo();
 
153
  Options& setAuthAlgo(std::string a);
 
154
  u_int32_t getAuthTagLength();
 
155
  Options& setAuthTagLength(u_int32_t a);
 
156
  std::string getKdPrf();
 
157
  Options& setKdPrf(std::string k);
 
158
  role_t getRole();
 
159
  Options& setRole(role_t r);
 
160
  std::string getPassphrase();
 
161
  Options& setPassphrase(std::string p);
 
162
  Options& setKey(std::string k);
 
163
  Buffer getKey();
 
164
  Options& setSalt(std::string s);
 
165
  Buffer getSalt();
 
166
 
 
167
 
 
168
private:
 
169
  Options();
 
170
  ~Options();
 
171
  Options(const Options &l);
 
172
  void operator=(const Options &l);
 
173
 
 
174
  static Options* inst;
 
175
  static ::Mutex instMutex;
 
176
  class instanceCleaner {
 
177
    public: ~instanceCleaner() {
 
178
      if(Options::inst != 0)
 
179
        delete Options::inst;
 
180
    }
 
181
  };
 
182
  friend class instanceCleaner;
 
183
 
 
184
  ::SharedMutex mutex;
 
185
 
 
186
 
 
187
  bool cluster_opts;
 
188
  bool connection_opts;
 
189
 
 
190
  std::string progname_;
 
191
  bool daemonize_;
 
192
  std::string username_;
 
193
  std::string groupname_;
 
194
  std::string chroot_dir_;
 
195
  std::string pid_file_;
 
196
 
 
197
  StringList log_targets_;
 
198
 
 
199
  std::string file_name_;
 
200
  OptionHost bind_to_;
 
201
 
 
202
  ResolvAddrType resolv_addr_type_;
 
203
  OptionHost local_;
 
204
  OptionHost remote_;
 
205
 
 
206
  OptionHost local_sync_;
 
207
        HostList remote_sync_hosts_;
 
208
 
 
209
  std::string dev_name_;
 
210
  std::string dev_type_;
 
211
  OptionNetwork ifconfig_param_;
 
212
  std::string post_up_script_;
 
213
  NetworkList routes_;
 
214
 
 
215
  sender_id_t sender_id_;
 
216
  mux_t mux_;
 
217
  window_size_t seq_window_size_;
 
218
 
 
219
  std::string cipher_;
 
220
  std::string auth_algo_;
 
221
  u_int32_t auth_tag_length_;
 
222
  std::string kd_prf_;
 
223
  role_t role_;
 
224
  std::string passphrase_;
 
225
  Buffer key_;
 
226
  Buffer salt_;
 
227
};
 
228
 
 
229
extern Options& gOpt;
 
230
 
 
231
#endif