From 809082c99f22aa6026638110315b9ec9229254e9 Mon Sep 17 00:00:00 2001 From: Alan Conway Date: Mon, 28 May 2012 18:24:21 +0000 Subject: QPID-3603: HA brokers avoid self-connection. HA brokers attempt to avoid self-connection using SystemInfo::isLocalHost(). If a VIP is used then this check won't work. Brokers now check the system-id UUID on incoming connections and reject the connection if it is their own. git-svn-id: https://svn.apache.org/repos/asf/qpid/trunk/qpid@1343349 13f79535-47bb-0310-9956-ffa450edef68 --- cpp/src/qpid/ha/ConnectionExcluder.cpp | 15 ++++++++++----- cpp/src/qpid/ha/ConnectionExcluder.h | 4 +++- cpp/src/qpid/ha/HaBroker.cpp | 2 +- 3 files changed, 14 insertions(+), 7 deletions(-) (limited to 'cpp') diff --git a/cpp/src/qpid/ha/ConnectionExcluder.cpp b/cpp/src/qpid/ha/ConnectionExcluder.cpp index 6c413982f8..18b4432aa1 100644 --- a/cpp/src/qpid/ha/ConnectionExcluder.cpp +++ b/cpp/src/qpid/ha/ConnectionExcluder.cpp @@ -29,8 +29,8 @@ namespace qpid { namespace ha { -ConnectionExcluder::ConnectionExcluder(const LogPrefix& lp) - : logPrefix(lp), backupAllowed(false) {} +ConnectionExcluder::ConnectionExcluder(const LogPrefix& lp, const framing::Uuid& uuid) + : logPrefix(lp), backupAllowed(false), self(uuid) {} void ConnectionExcluder::opened(broker::Connection& connection) { if (connection.isLink()) return; // Allow all outgoing links @@ -42,9 +42,14 @@ void ConnectionExcluder::opened(broker::Connection& connection) { framing::FieldTable ft; if (connection.getClientProperties().getTable(BACKUP_TAG, ft)) { BrokerInfo info(ft); - QPID_LOG(debug, logPrefix << "Backup connection " << info << - (backupAllowed ? " allowed" : " rejected")); - if (backupAllowed) return; + if (info.getSystemId() == self) { + QPID_LOG(debug, logPrefix << "Self connection rejected"); + } + else { + QPID_LOG(debug, logPrefix << "Backup connection " << info << + (backupAllowed ? " allowed" : " rejected")); + if (backupAllowed) return; + } } // Abort the connection. throw Exception( diff --git a/cpp/src/qpid/ha/ConnectionExcluder.h b/cpp/src/qpid/ha/ConnectionExcluder.h index 4a2ebcc127..042544c333 100644 --- a/cpp/src/qpid/ha/ConnectionExcluder.h +++ b/cpp/src/qpid/ha/ConnectionExcluder.h @@ -24,6 +24,7 @@ #include "LogPrefix.h" #include "qpid/broker/ConnectionObserver.h" +#include "qpid/framing/Uuid.h" #include namespace qpid { @@ -45,7 +46,7 @@ class ConnectionExcluder : public broker::ConnectionObserver static const std::string ADMIN_TAG; static const std::string BACKUP_TAG; - ConnectionExcluder(const LogPrefix&); + ConnectionExcluder(const LogPrefix&, const framing::Uuid& self); void opened(broker::Connection& connection); @@ -55,6 +56,7 @@ class ConnectionExcluder : public broker::ConnectionObserver private: LogPrefix logPrefix; bool backupAllowed; + framing::Uuid self; }; }} // namespace qpid::ha diff --git a/cpp/src/qpid/ha/HaBroker.cpp b/cpp/src/qpid/ha/HaBroker.cpp index 32261c560d..71995c1ac2 100644 --- a/cpp/src/qpid/ha/HaBroker.cpp +++ b/cpp/src/qpid/ha/HaBroker.cpp @@ -53,7 +53,7 @@ HaBroker::HaBroker(broker::Broker& b, const Settings& s) settings(s), mgmtObject(0), status(STANDALONE), - excluder(new ConnectionExcluder(logPrefix)), + excluder(new ConnectionExcluder(logPrefix, broker.getSystem()->getSystemId())), brokerInfo(broker.getSystem()->getNodeName(), broker.getSystem()->getSystemId()) -- cgit v1.2.1