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 "threadUtils.hpp"
33 #include "datatypes.h"
34 #include "keyDerivationFactory.h"
36 #include "packetSource.h"
38 #include "connectionList.h"
40 ConnectionList* ConnectionList::inst = NULL;
41 Mutex ConnectionList::instMutex;
42 ConnectionList& gConnectionList = ConnectionList::instance();
45 ConnectionList& ConnectionList::instance()
48 static instanceCleaner c;
50 inst = new ConnectionList();
55 ConnectionList::ConnectionList()
59 ConnectionList::~ConnectionList()
61 // TODO: comment this in as soon as threads @ main get cleaned up properly
63 // ConnectionMap::iterator it;
64 // for(it = connections_.begin(); it != connections_.end(); ++it) {
65 // delete &it->second.kd_;
66 // delete &it->second.seq_window_;
70 void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux )
74 std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn));
77 connections_.erase(ret.first);
78 connections_.insert(ConnectionMap::value_type(mux, conn));
82 const ConnectionMap::iterator ConnectionList::getEnd()
85 return connections_.end();
88 ConnectionMap::iterator ConnectionList::getBeginUnlocked()
90 return connections_.begin();
93 const ConnectionMap::iterator ConnectionList::getBegin()
96 return connections_.begin();
100 ConnectionMap::iterator ConnectionList::getEndUnlocked()
102 return connections_.end();
105 const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux)
108 ConnectionMap::iterator it = connections_.find(mux);
113 ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux)
115 ConnectionMap::iterator it = connections_.find(mux);
116 if(it!=connections_.end())
120 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
121 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
125 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
126 'i', 'j', 'k', 'l', 'm', 'n'
129 SeqWindow * seq= new SeqWindow(0);
131 KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf());
132 kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt)));
133 ConnectionParam conn ((*kd), (*seq), seq_nr_, PacketSourceEndpoint());
134 connections_.insert(ConnectionMap::value_type(mux, conn));
135 it = connections_.find(mux);
139 void ConnectionList::clear()
142 connections_.clear();
145 bool ConnectionList::empty()
148 return connections_.empty();
151 Mutex& ConnectionList::getMutex()