/** * This method is used to determine if the named interface is included in the passed package * definition. If the interface belongs to the package then a value of true is returned. If the * interface does not belong to the package a false value is returned. * * <p><strong>Note: </strong>Evaluation of the interface against a package filter will only work * if the IP is already in the database. * * @param iface The interface to test against the package. * @param pkg The package to check for the inclusion of the interface. * @return True if the interface is included in the package, false otherwise. */ public synchronized boolean interfaceInPackage(String iface, Package pkg) { final InetAddress ifaceAddr = addr(iface); ThreadCategory log = log(); boolean filterPassed = false; // get list of IPs in this package List<InetAddress> ipList = m_pkgIpMap.get(pkg); if (ipList != null && ipList.size() > 0) { filterPassed = ipList.contains(ifaceAddr); } if (log.isDebugEnabled()) log.debug( "interfaceInPackage: Interface " + iface + " passed filter for package " + pkg.getName() + "?: " + filterPassed); if (!filterPassed) 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; // 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; for (IncludeRange rng : pkg.getIncludeRangeCollection()) { if (isInetAddressInRange(iface, rng.getBegin(), rng.getEnd())) { has_range_include = true; break; } } byte[] addr = toIpAddrBytes(iface); for (String spec : pkg.getSpecificCollection()) { byte[] speca = toIpAddrBytes(spec); if (new ByteArrayComparator().compare(speca, addr) == 0) { has_specific = true; break; } } Enumeration<String> eurl = pkg.enumerateIncludeUrl(); while (!has_specific && eurl.hasMoreElements()) { has_specific = interfaceInUrl(iface, eurl.nextElement()); } for (ExcludeRange rng : pkg.getExcludeRangeCollection()) { if (isInetAddressInRange(iface, rng.getBegin(), rng.getEnd())) { has_range_exclude = true; break; } } return has_specific || (has_range_include && !has_range_exclude); }