X-Git-Url: https://git.stg.codes/ssmd.git/blobdiff_plain/bdbd190aca2ca879b723d0557eca771529363e2f..82a6c22158618bc1e7738bf08bf1b305179935dc:/src/switch.cpp diff --git a/src/switch.cpp b/src/switch.cpp index bf18aa3..f189ba6 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()) { @@ -192,8 +221,10 @@ bool Switch::dropACLsByTable(const CTarget & target, unsigned profileId, const S pdu += vb; } if (int c = _snmp.set(pdu, target) != SNMP_CLASS_SUCCESS) { - logger << "Switch::dropACLsByTable() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'" << std::endl; - return false; + if (c != SNMP_ERROR_TOO_BIG) { + logger << "Switch::dropACLsByTable() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'" << std::endl; + return false; + } } } return true; @@ -202,13 +233,19 @@ bool Switch::dropACLsByTable(const CTarget & target, unsigned profileId, const S bool Switch::createACLs(const CTarget & target) { std::vector::const_iterator it; + size_t pos = 0; for (it = _acls.begin(); it != _acls.end(); ++it) { Pdu pdu; it->appendPdu(pdu); if (int c = _snmp.set(pdu, target) != SNMP_CLASS_SUCCESS) { - logger << "Switch::createACLs() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'" << std::endl; - return false; + if (c != SNMP_ERROR_TOO_BIG) { + logger << "Switch::createACLs() - failed to invoke Snmp::set for the switch '" << _ip << "'. Error message: '" << Snmp::error_msg(c) << "'. Error occured at creation of " << (pos + 1) << " from " << _acls.size() << " ACL's" << std::endl; + logger << "Switch::createACLs() - ACL dump: " << *it << std::endl; + return false; + } } + _aclsCreated = true; + ++pos; } return true; }