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-2009 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/>.
36 #include "datatypes.h"
40 #include "keyDerivation.h"
41 #include "keyDerivationFactory.h"
43 #include "connectionList.h"
44 #include "routingTable.h"
45 #include "networkAddress.h"
46 #include "packetSource.h"
49 #include "syncQueue.h"
50 #include "syncCommand.h"
54 void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux, Semaphore& sem)
56 SeqWindow * seq = new SeqWindow(seqSize);
58 KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf());
59 kd->init(gOpt.getKey(), gOpt.getSalt(), gOpt.getPassphrase());
60 kd->setRole(gOpt.getRole());
61 cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_end;
62 ConnectionParam connparam ((*kd), (*seq), seq_nr_, remote_end);
63 cl.addConnection(connparam, mux);
65 std::ostringstream sout;
66 boost::archive::text_oarchive oa(sout);
67 const SyncCommand scom(cl, mux);
70 std::cout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ' << sout.str() << std::endl;
72 NetworkList routes = gOpt.getRoutes();
73 NetworkList::const_iterator rit;
74 for(rit = routes.begin(); rit != routes.end(); ++rit)
76 NetworkAddress addr(rit->net_addr.c_str());
77 NetworkPrefix prefix(addr, rit->prefix_length);
79 gRoutingTable.addRoute(prefix, mux);
81 std::ostringstream sout2;
82 boost::archive::text_oarchive oa2(sout2);
83 const SyncCommand scom2(prefix);
86 std::cout << std::setw(5) << std::setfill('0') << sout2.str().size()<< ' ' << sout2.str() << std::endl;
91 void createConnectionError(const std::exception& e, Semaphore& sem, int& ret)
93 cLog.msg(Log::PRIO_ERROR) << "uncaught runtime error: " << e.what();
98 int main(int argc, char* argv[])
102 bool result = gOpt.parse(argc, argv);
107 StringList targets = gOpt.getLogTargets();
108 if(targets.empty()) {
109 cLog.addTarget("stderr:2");
112 StringList::const_iterator it;
113 for(it = targets.begin();it != targets.end(); ++it)
117 catch(syntax_error& e)
119 std::cerr << e << std::endl;
124 gOpt.parse_post(); // print warnings
133 UDPPacketSource::proto::endpoint endpoint;
134 // allow emtpy endpoint!!!
135 gResolver.resolveUdp(gOpt.getRemoteAddr(), gOpt.getRemotePort(),
136 boost::bind(createConnection, _1, boost::ref(cl), gOpt.getSeqWindowSize(), boost::ref(queue), gOpt.getMux(), boost::ref(sem)),
137 boost::bind(createConnectionError, _1, boost::ref(sem), boost::ref(ret)),
138 gOpt.getResolvAddrType());