From 6b235fa5a6fd3b514febe5b1328f97df14fb10bc Mon Sep 17 00:00:00 2001 From: Maxim Mamontov Date: Mon, 28 Nov 2011 11:32:03 +0200 Subject: [PATCH] Sync with working version --- src/switch.cpp | 34 ++++++++++++++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/src/switch.cpp b/src/switch.cpp index bf18aa3..db8a1be 100644 --- a/src/switch.cpp +++ b/src/switch.cpp @@ -26,7 +26,8 @@ Switch::Switch(const Settings & settings, _writeCommunity(writeCommunity), _uplinkPort(uplinkPort), _nextUpACL(1), - _nextDownACL(1) + _nextDownACL(1), + _aclsCreated(false) { } @@ -39,12 +40,38 @@ Switch::Switch(const Switch & rvalue) _uplinkPort(rvalue._uplinkPort), _nextUpACL(rvalue._nextUpACL), _nextDownACL(rvalue._nextDownACL), - _acls(rvalue._acls) + _acls(rvalue._acls), + _aclsCreated(rvalue._aclsCreated) { } Switch::~Switch() { + if (_aclsCreated) { + IpAddress addr(_ip.c_str()); + if (!addr.valid()) { + logger << "Switch::~Switch() - ivalid switch ip: '" << _ip << "'" << std::endl; + return; + } + + CTarget target(addr, _readCommunity.c_str(), _writeCommunity.c_str()); + if (!target.valid()) { + logger << "Switch::~Switch() - failed to create target for the switch '" << _ip << "'" << std::endl; + return; + } + + target.set_version(version2c); + + if (!checkProfiles(target)) { + logger << "Switch::~Switch() - no upload and download profiles defined for the switch '" << _ip << "'" << std::endl; + return; + } + + if (!dropACLs(target)) { + logger << "Switch::~Switch() - failed to drop ACLs for the switch '" << _ip << "'" << std::endl; + return; + } + } } Switch & Switch::operator=(const Switch & rvalue) @@ -56,6 +83,7 @@ Switch & Switch::operator=(const Switch & rvalue) _nextUpACL = rvalue._nextUpACL; _nextDownACL = rvalue._nextDownACL; _acls = rvalue._acls; + _aclsCreated = rvalue._aclsCreated; return *this; } @@ -106,6 +134,7 @@ void Switch::sync() if (!createACLs(target)) { logger << "Switch::sync() - failed to create ACLs for the switch '" << _ip << "'" << std::endl; + return; } if (_settings.isDebug()) { @@ -209,6 +238,7 @@ bool Switch::createACLs(const CTarget & target) logger << "Switch::createACLs() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'" << std::endl; return false; } + _aclsCreated = true; } return true; } -- 2.43.2