switched to endpoint @ anytun-config as well
[anytun.git] / src / anytun-config.cpp
blob933a6dc3845080f392c081593c5cca8bb954ee44
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 #include <iostream>
33 #include <poll.h>
35 #include "datatypes.h"
37 #include "log.h"
38 #include "buffer.h"
39 #include "keyDerivation.h"
40 #include "keyDerivationFactory.h"
41 #include "signalController.h"
42 #include "anyConfOptions.h"
43 #include "connectionList.h"
44 #include "routingTable.h"
45 #include "networkAddress.h"
46 #include "packetSource.h"
48 #include "syncQueue.h"
49 #include "syncCommand.h"
53 void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux)
55 SeqWindow * seq = new SeqWindow(seqSize);
56 seq_nr_t seq_nr_ = 0;
57 KeyDerivation * kd = KeyDerivationFactory::create( gOpt.getKdPrf() );
58 kd->init( gOpt.getKey(), gOpt.getSalt() );
59 cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_end;
60 ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_end );
61 cl.addConnection( connparam, mux );
63 std::ostringstream sout;
64 boost::archive::text_oarchive oa( sout );
65 const SyncCommand scom( cl, mux );
67 oa << scom;
68 std::cout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ' << sout.str() << std::endl;
70 RouteList routes = gOpt.getRoutes();
71 RouteList::const_iterator rit;
72 for(rit = routes.begin(); rit != routes.end(); ++rit)
74 NetworkAddress addr( ipv4, rit->net_addr.c_str() );
75 NetworkPrefix prefix( addr, rit->prefix_length );
77 gRoutingTable.addRoute( prefix, mux );
79 std::ostringstream sout2;
80 boost::archive::text_oarchive oa2( sout2 );
81 const SyncCommand scom2( prefix );
83 oa2 << scom2;
84 std::cout << std::setw(5) << std::setfill('0') << sout2.str().size()<< ' ' << sout2.str() << std::endl;
88 int main(int argc, char* argv[])
90 int ret=0;
91 if(!gOpt.parse(argc, argv))
93 gOpt.printUsage();
94 exit(-1);
97 SignalController sig;
98 sig.init();
100 ConnectionList cl;
101 SyncQueue queue;
103 boost::asio::io_service io_service;
104 boost::asio::ip::udp::resolver resolver(io_service);
105 boost::asio::ip::udp::resolver::query query(gOpt.getRemoteAddr(), gOpt.getRemotePort());
106 boost::asio::ip::udp::endpoint endpoint = *resolver.resolve(query);
108 createConnection(endpoint,cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux());
110 return ret;