added ipv6 routing support
[anytun.git] / src / anytun-config.cpp
blob3f21d0ee872368cbe803a8a693f93afa5106959c
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 "anyConfOptions.h"
42 #include "connectionList.h"
43 #include "routingTable.h"
44 #include "networkAddress.h"
45 #include "packetSource.h"
47 #include "syncQueue.h"
48 #include "syncCommand.h"
52 void createConnection(const PacketSourceEndpoint & remote_end, ConnectionList & cl, u_int16_t seqSize, SyncQueue & queue, mux_t mux)
54 SeqWindow * seq = new SeqWindow(seqSize);
55 seq_nr_t seq_nr_ = 0;
56 KeyDerivation * kd = KeyDerivationFactory::create( gOpt.getKdPrf() );
57 kd->init( gOpt.getKey(), gOpt.getSalt() );
58 cLog.msg(Log::PRIO_NOTICE) << "added connection remote host " << remote_end;
59 ConnectionParam connparam ( (*kd), (*seq), seq_nr_, remote_end );
60 cl.addConnection( connparam, mux );
62 std::ostringstream sout;
63 boost::archive::text_oarchive oa( sout );
64 const SyncCommand scom( cl, mux );
66 oa << scom;
67 std::cout << std::setw(5) << std::setfill('0') << sout.str().size()<< ' ' << sout.str() << std::endl;
69 RouteList routes = gOpt.getRoutes();
70 RouteList::const_iterator rit;
71 for(rit = routes.begin(); rit != routes.end(); ++rit)
73 NetworkAddress addr( rit->net_addr.c_str() );
74 NetworkPrefix prefix( addr, rit->prefix_length );
76 gRoutingTable.addRoute( prefix, mux );
78 std::ostringstream sout2;
79 boost::archive::text_oarchive oa2( sout2 );
80 const SyncCommand scom2( prefix );
82 oa2 << scom2;
83 std::cout << std::setw(5) << std::setfill('0') << sout2.str().size()<< ' ' << sout2.str() << std::endl;
87 int main(int argc, char* argv[])
89 int ret=0;
90 if(!gOpt.parse(argc, argv))
92 gOpt.printUsage();
93 exit(-1);
96 ConnectionList cl;
97 SyncQueue queue;
99 UDPPacketSource::proto::endpoint endpoint;
100 if (gOpt.getRemoteAddr()!="" && gOpt.getRemotePort()!="")
102 boost::asio::io_service io_service;
103 UDPPacketSource::proto::resolver resolver(io_service);
104 UDPPacketSource::proto::resolver::query query(gOpt.getRemoteAddr(), gOpt.getRemotePort());
105 endpoint = *resolver.resolve(query);
107 createConnection(endpoint,cl,gOpt.getSeqWindowSize(), queue, gOpt.getMux());
109 return ret;