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/>.
33 #include "threadUtils.hpp"
34 #include "datatypes.h"
35 #include "keyDerivationFactory.h"
37 #include "packetSource.h"
39 #include "connectionList.h"
41 ConnectionList* ConnectionList::inst = NULL;
42 Mutex ConnectionList::instMutex;
43 ConnectionList& gConnectionList = ConnectionList::instance();
46 ConnectionList& ConnectionList::instance()
49 static instanceCleaner c;
51 inst = new ConnectionList();
56 ConnectionList::ConnectionList()
60 ConnectionList::~ConnectionList()
62 // TODO: comment this in as soon as threads @ main get cleaned up properly
64 // ConnectionMap::iterator it;
65 // for(it = connections_.begin(); it != connections_.end(); ++it) {
66 // delete &it->second.kd_;
67 // delete &it->second.seq_window_;
71 void ConnectionList::addConnection(ConnectionParam &conn, u_int16_t mux )
75 std::pair<ConnectionMap::iterator, bool> ret = connections_.insert(ConnectionMap::value_type(mux, conn));
78 connections_.erase(ret.first);
79 connections_.insert(ConnectionMap::value_type(mux, conn));
83 const ConnectionMap::iterator ConnectionList::getEnd()
86 return connections_.end();
89 ConnectionMap::iterator ConnectionList::getBeginUnlocked()
91 return connections_.begin();
94 const ConnectionMap::iterator ConnectionList::getBegin()
97 return connections_.begin();
101 ConnectionMap::iterator ConnectionList::getEndUnlocked()
103 return connections_.end();
106 const ConnectionMap::iterator ConnectionList::getConnection(u_int16_t mux)
109 ConnectionMap::iterator it = connections_.find(mux);
114 ConnectionParam & ConnectionList::getOrNewConnectionUnlocked(u_int16_t mux)
116 ConnectionMap::iterator it = connections_.find(mux);
117 if(it!=connections_.end())
121 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
122 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p'
126 'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h',
127 'i', 'j', 'k', 'l', 'm', 'n'
130 SeqWindow * seq= new SeqWindow(0);
132 KeyDerivation * kd = KeyDerivationFactory::create(gOpt.getKdPrf());
133 kd->init(Buffer(key, sizeof(key)), Buffer(salt, sizeof(salt)));
134 ConnectionParam conn ((*kd), (*seq), seq_nr_, PacketSourceEndpoint());
135 connections_.insert(ConnectionMap::value_type(mux, conn));
136 it = connections_.find(mux);
140 void ConnectionList::clear()
143 connections_.clear();
146 bool ConnectionList::empty()
149 return connections_.empty();
152 Mutex& ConnectionList::getMutex()