Ejemplo n.º 1
0
  @Override
  public boolean isInterfaceInPackageRange(
      final InetAddress iface, final org.opennms.netmgt.config.linkd.Package pkg) {
    if (pkg == null) return false;

    //
    // Ensure that the interface is in the specific list or
    // that it is in the include range and is not excluded
    //
    boolean has_specific = false;
    boolean has_range_include = false;
    boolean has_range_exclude = false;

    try {
      getReadLock().lock();
      byte[] addr = iface.getAddress();

      // if there are NO include ranges then treat act as if the user include
      // the range 0.0.0.0 - 255.255.255.255
      has_range_include = pkg.getIncludeRangeCount() == 0 && pkg.getSpecificCount() == 0;

      // Specific wins; if we find one, return immediately.
      for (final String spec : pkg.getSpecificCollection()) {
        final byte[] speca = toIpAddrBytes(spec);
        if (new ByteArrayComparator().compare(addr, speca) == 0) {
          has_specific = true;
          break;
        }
      }
      if (has_specific) return true;

      for (final String url : pkg.getIncludeUrlCollection()) {
        has_specific = isInterfaceInUrl(iface, url);
        if (has_specific) break;
      }
      if (has_specific) return true;

      if (!has_range_include) {
        for (final IncludeRange rng : pkg.getIncludeRangeCollection()) {
          if (isInetAddressInRange(iface.getAddress(), rng.getBegin(), rng.getEnd())) {
            has_range_include = true;
            break;
          }
        }
      }

      for (final ExcludeRange rng : pkg.getExcludeRangeCollection()) {
        if (isInetAddressInRange(iface.getAddress(), rng.getBegin(), rng.getEnd())) {
          has_range_exclude = true;
          break;
        }
      }

      return has_range_include && !has_range_exclude;
    } finally {
      getReadLock().unlock();
    }
  }
Ejemplo n.º 2
0
  protected void updateVlanClassNames() {
    m_oidMask2VlanclassName.clear();
    try {
      getWriteLock().lock();
      final Vlans vlans = m_config.getVlans();
      if (vlans == null) {
        LOG.info("initializeVlanClassNames: no vlans found in config");
      }

      final List<String> excludedOids = new ArrayList<String>();
      for (final Vendor vendor : vlans.getVendorCollection()) {
        final SnmpObjectId curRootSysOid = new SnmpObjectId(vendor.getSysoidRootMask());
        final String curClassName = vendor.getClassName();

        for (final String specific : vendor.getSpecific()) {
          final SnmpObjectId oidMask = new SnmpObjectId(specific);
          oidMask.prepend(curRootSysOid);
          m_oidMask2VlanclassName.put(oidMask.toString(), curClassName);
          LOG.debug("initializeVlanClassNames:  adding class {} for oid {}", curClassName, oidMask);
        }

        for (final ExcludeRange excludeRange : vendor.getExcludeRangeCollection()) {
          final SnmpObjectId snmpBeginOid = new SnmpObjectId(excludeRange.getBegin());
          final SnmpObjectId snmpEndOid = new SnmpObjectId(excludeRange.getEnd());
          final SnmpObjectId snmpRootOid = getRootOid(snmpBeginOid);
          if (snmpBeginOid.getLength() == snmpEndOid.getLength()
              && snmpRootOid.isRootOf(snmpEndOid)) {
            final SnmpObjectId snmpCurOid = new SnmpObjectId(snmpBeginOid);
            while (snmpCurOid.compare(snmpEndOid) <= 0) {
              excludedOids.add(snmpCurOid.toString());
              LOG.debug(
                  "initializeVlanClassNames:  signing excluded class {} for oid {}",
                  curClassName,
                  curRootSysOid.toString().concat(snmpCurOid.toString()));
              int lastCurCipher = snmpCurOid.getLastIdentifier();
              lastCurCipher++;
              int[] identifiers = snmpCurOid.getIdentifiers();
              identifiers[identifiers.length - 1] = lastCurCipher;
              snmpCurOid.setIdentifiers(identifiers);
            }
          }
        }

        for (final IncludeRange includeRange : vendor.getIncludeRangeCollection()) {
          final SnmpObjectId snmpBeginOid = new SnmpObjectId(includeRange.getBegin());
          final SnmpObjectId snmpEndOid = new SnmpObjectId(includeRange.getEnd());
          final SnmpObjectId rootOid = getRootOid(snmpBeginOid);
          if (snmpBeginOid.getLength() == snmpEndOid.getLength() && rootOid.isRootOf(snmpEndOid)) {
            final SnmpObjectId snmpCurOid = new SnmpObjectId(snmpBeginOid);
            while (snmpCurOid.compare(snmpEndOid) <= 0) {
              if (!excludedOids.contains(snmpBeginOid.toString())) {
                final SnmpObjectId oidMask = new SnmpObjectId(snmpBeginOid);
                oidMask.prepend(curRootSysOid);
                m_oidMask2VlanclassName.put(oidMask.toString(), curClassName);
                LOG.debug(
                    "initializeVlanClassNames:  adding class {} for oid {}", curClassName, oidMask);
              }
              int lastCipher = snmpBeginOid.getLastIdentifier();
              lastCipher++;
              int[] identifiers = snmpBeginOid.getIdentifiers();
              identifiers[identifiers.length - 1] = lastCipher;
              snmpCurOid.setIdentifiers(identifiers);
            }
          }
        }
      }
    } finally {
      getWriteLock().unlock();
    }
  }