@Override public boolean equals(Object obj) { if (!(obj instanceof NetworkVO)) { return false; } NetworkVO that = (NetworkVO)obj; if (trafficType != that.trafficType) { return false; } if ((cidr == null && that.cidr != null) || (cidr != null && that.cidr == null)) { return false; } if (cidr == null && that.cidr == null) { return true; } return NetUtils.isNetworkAWithinNetworkB(cidr, that.cidr); }
public static boolean validateGuestCidr(final String cidr) { // RFC 1918 - The Internet Assigned Numbers Authority (IANA) has reserved the // following three blocks of the IP address space for private internets: // 10.0.0.0 - 10.255.255.255 (10/8 prefix) // 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) // 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) // RFC 6598 - The IETF detailed shared address space for use in ISP CGN // deployments and NAT devices that can handle the same addresses occurring both on inbound and outbound interfaces. // ARIN returned space to the IANA as needed for this allocation. // The allocated address block is 100.64.0.0/10 final String[] allowedNetBlocks = {"10.0.0.0/8", "172.16.0.0/12", "192.168.0.0/16", "100.64.0.0/10"}; if (!isValidIp4Cidr(cidr)) { s_logger.warn("Cidr " + cidr + " is not valid"); return false; } for (String block: allowedNetBlocks) { if (isNetworkAWithinNetworkB(cidr, block)) { return true; } } // not in allowedNetBlocks - return false s_logger.warn("cidr " + cidr + " is not RFC 1918 or 6598 compliant"); return false; }
@Test public void testIsNetworkAWithinNetworkB() { assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/23")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/22")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/23", "192.168.30.0/24")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/22", "192.168.30.0/24")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/23")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/22")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/23", "192.168.28.0/24")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/22", "192.168.28.0/24")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.28.0/22")); }
@Test public void testIsNetworkAWithinNetworkBWithEmptyValues() { assertEquals(false, NetUtils.isNetworkAWithinNetworkB("", null)); }
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
inSameSubnet = NetUtils.isNetworkAWithinNetworkB(destIpOrCidr, NetUtils.ipAndNetMaskToCidr(eth1ip, eth1mask));
if (!NetUtils.isNetworkAWithinNetworkB(cidr, vpc.getCidr())) { throw new InvalidParameterValueException("Network cidr " + cidr + " is not within vpc " + vpc + " cidr"); assert cidr != null : "Why the network cidr is null when it belongs to vpc?"; if (NetUtils.isNetworkAWithinNetworkB(ntwk.getCidr(), cidr) || NetUtils.isNetworkAWithinNetworkB(cidr, ntwk.getCidr())) { throw new InvalidParameterValueException("Network cidr " + cidr + " crosses other network cidr " + ntwk + " belonging to the same vpc " + vpc);
continue; if (!NetUtils.isNetworkAWithinNetworkB(cidr, guestCidr)) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, cidr + " is not within the guest cidr " + guestCidr);
public static boolean validateGuestCidr(final String cidr) { // RFC 1918 - The Internet Assigned Numbers Authority (IANA) has reserved the // following three blocks of the IP address space for private internets: // 10.0.0.0 - 10.255.255.255 (10/8 prefix) // 172.16.0.0 - 172.31.255.255 (172.16/12 prefix) // 192.168.0.0 - 192.168.255.255 (192.168/16 prefix) final String cidr1 = "10.0.0.0/8"; final String cidr2 = "172.16.0.0/12"; final String cidr3 = "192.168.0.0/16"; if (!isValidIp4Cidr(cidr)) { s_logger.warn("Cidr " + cidr + " is not valid"); return false; } if (isNetworkAWithinNetworkB(cidr, cidr1) || isNetworkAWithinNetworkB(cidr, cidr2) || isNetworkAWithinNetworkB(cidr, cidr3)) { return true; } else { s_logger.warn("cidr " + cidr + " is not RFC 1918 compliant"); return false; } }
if (!NetUtils.isNetworkAWithinNetworkB(guestVmCidr, networkCidr)) { throw new InvalidParameterValueException("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : " + networkCidr); if (!NetUtils.isNetworkAWithinNetworkB(guestVmCidr, network.getCidr())) { throw new InvalidParameterValueException("Invalid value of Guest VM CIDR. For IP Reservation, Guest VM CIDR should be a subset of network CIDR : " + network.getCidr()); if (NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr())) { s_logger.warn( "Existing IP reservation will become ineffective for the network with id = " + networkId + " You need to reapply reservation after network reimplementation.");
if ((network.getCidr() != null) && (NetUtils.isNetworkAWithinNetworkB(network.getCidr(), network.getNetworkCidr()))) { String[] guestVmCidrPair = network.getCidr().split("\\/"); String[] guestCidrPair = network.getNetworkCidr().split("\\/");
@Test public void testIsNetworkAWithinNetworkB() { assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/23")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.30.0/22")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/23", "192.168.30.0/24")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/22", "192.168.30.0/24")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/23")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/24", "192.168.28.0/22")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/23", "192.168.28.0/24")); assertFalse(NetUtils.isNetworkAWithinNetworkB("192.168.28.0/22", "192.168.28.0/24")); assertTrue(NetUtils.isNetworkAWithinNetworkB("192.168.30.0/24", "192.168.28.0/22")); }
@Test public void testIsNetworkAWithinNetworkBWithEmptyValues() { assertEquals(false, NetUtils.isNetworkAWithinNetworkB("", null)); }
continue; if (!NetUtils.isNetworkAWithinNetworkB(cidr, guestCidr)) { throw new ServerApiException(ApiErrorCode.PARAM_ERROR, cidr + " is not within the guest cidr " + guestCidr);