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.
14 * Copyright (C) 2007-2014 Markus Grüneis, 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 as published by
21 * the Free Software Foundation, either version 3 of the License, or
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.
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/>.
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
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.
50 #include "datatypes.h"
53 #include "signalController.h"
57 #include "syncServer.h"
58 #if !defined(_MSC_VER) && !defined(MINGW)
59 # include "daemonService.h"
61 # include "nullDaemon.h"
65 std::list<std::string> config_;
67 void syncOnConnect(SyncTcpConnection* connptr)
69 for(std::list<std::string>::const_iterator it=config_.begin(); it!=config_.end(); ++it) {
76 boost::asio::io_service io_service;
78 SyncServer server(gOpt.getBindToAddr(), gOpt.getBindToPort(), boost::bind(syncOnConnect, _1));
80 } catch(std::runtime_error& e) {
81 cLog.msg(Log::PRIO_ERROR) << "sync listener thread died due to an uncaught runtime_error: " << e.what();
82 } catch(std::exception& e) {
83 cLog.msg(Log::PRIO_ERROR) << "sync listener thread died due to an uncaught exception: " << e.what();
87 int main(int argc, char* argv[])
89 DaemonService service;
92 if(!gOpt.parse(argc, argv)) {
96 StringList targets = gOpt.getLogTargets();
97 for(StringList::const_iterator it = targets.begin(); it != targets.end(); ++it) {
100 } catch(syntax_error& e) {
101 std::cerr << e << std::endl;
106 cLog.msg(Log::PRIO_NOTICE) << "anytun-controld started...";
107 gOpt.parse_post(); // print warnings
110 std::ifstream file(gOpt.getFileName().c_str());
115 config_.push_back(line);
119 std::cout << "ERROR: unable to open file!" << std::endl;
123 service.initPrivs(gOpt.getUsername(), gOpt.getGroupname());
124 if(gOpt.getDaemonize()) {
128 if(gOpt.getChrootDir() != "") {
129 service.chroot(gOpt.getChrootDir());
133 gSignalController.init(service);
136 boost::thread* syncListenerThread;
137 syncListenerThread = new boost::thread(boost::bind(syncListener));
138 if(syncListenerThread) syncListenerThread->detach();
140 int ret = gSignalController.run();
143 } catch(std::runtime_error& e) {
144 if(service.isDaemonized()) {
145 cLog.msg(Log::PRIO_ERROR) << "uncaught runtime error, exiting: " << e.what();
147 std::cout << "uncaught runtime error, exiting: " << e.what() << std::endl;
149 } catch(std::exception& e) {
150 if(service.isDaemonized()) {
151 cLog.msg(Log::PRIO_ERROR) << "uncaught exception, exiting: " << e.what();
153 std::cout << "uncaught exception, exiting: " << e.what() << std::endl;