Exemple #1
0
 @Test
 public void ipv4_dash() {
   final Domain domain = Domain.parse("0-127.10.10.10.in-addr.arpa");
   assertThat(domain.getValue(), is(ciString("0-127.10.10.10.in-addr.arpa")));
   assertThat((Ipv4Resource) domain.getReverseIp(), is(Ipv4Resource.parse("10.10.10.0/25")));
   assertThat(domain.getType(), is(Domain.Type.INADDR));
 }
  private void prepareAuthoritativeResourceData(
      final String name,
      final List<String> autNums,
      final List<String> ipv4Resources,
      final List<String> ipv6Resources) {
    final AuthoritativeResource authoritativeResource = mock(AuthoritativeResource.class);
    when(authoritativeResource.getAutNums()).thenReturn(ciSet(autNums));

    final IntervalMap<Ipv4Resource, Ipv4Resource> ipv4Map = new NestedIntervalMap<>();
    for (final String ipv4Resource : ipv4Resources) {
      final Ipv4Resource resource = Ipv4Resource.parse(ipv4Resource);
      ipv4Map.put(resource, resource);
    }
    when(authoritativeResource.getInetRanges()).thenReturn(ipv4Map);

    final IntervalMap<Ipv6Resource, Ipv6Resource> ipv6Map = new NestedIntervalMap<>();
    for (final String ipv6Resource : ipv6Resources) {
      final Ipv6Resource resource = Ipv6Resource.parse(ipv6Resource);
      ipv6Map.put(resource, resource);
    }
    when(authoritativeResource.getInet6Ranges()).thenReturn(ipv6Map);

    when(authoritativeResourceData.getAuthoritativeResource(ciString(name)))
        .thenReturn(authoritativeResource);
  }
Exemple #3
0
 @Test
 public void valid_ipv4() {
   final Domain domain = Domain.parse("200.193.193.in-addr.arpa");
   assertThat(domain.getValue(), is(ciString("200.193.193.in-addr.arpa")));
   assertThat((Ipv4Resource) domain.getReverseIp(), is(Ipv4Resource.parse("193.193.200/24")));
   assertThat(domain.getType(), is(Domain.Type.INADDR));
 }
Exemple #4
0
 public static void validateIpv4(final String yytext) {
   try {
     Ipv4Resource.parse(yytext);
   } catch (IllegalArgumentException e) {
     syntaxError("IP address " + yytext + " contains an invalid octet");
   }
 }
 private int addObject(final RpslObject rpslObject) {
   databaseHelper.addObject(
       "inet-rtr: " + rpslObject.findAttribute(AttributeType.INET_RTR).getValue());
   final int objectId = getObjectId(rpslObject);
   final long ifAddr = Ipv4Resource.parse(getIfAddrAttributeAsString(rpslObject)).begin();
   whoisTemplate.update("INSERT INTO ifaddr (object_id, ifaddr) VALUES (?, ?)", objectId, ifAddr);
   return objectId;
 }
Exemple #6
0
 @Test
 public void ipv4_dash_non_prefix_range() {
   final Domain domain = Domain.parse("1-2.10.10.10.in-addr.arpa");
   assertThat(domain.getValue(), is(ciString("1-2.10.10.10.in-addr.arpa")));
   assertThat(
       (Ipv4Resource) domain.getReverseIp(), is(Ipv4Resource.parse("10.10.10.1-10.10.10.2")));
   assertThat(domain.getType(), is(Domain.Type.INADDR));
 }
Exemple #7
0
  /**
   * check each number of 1.2.3.4/5 in prefix is valid
   *
   * @param yytext
   */
  public static void validateIpv4Prefix(final String yytext) {
    final int slash = yytext.indexOf('/');
    try {
      Ipv4Resource.parse(yytext.substring(0, slash));
    } catch (IllegalArgumentException e) {
      syntaxError("IP prefix " + yytext + " contains an invalid octet");
    }

    final int length = Integer.valueOf(yytext.substring(slash + 1));
    if (length > MAX_BIT_LENGTH_IPV4) {
      syntaxError("IP prefix " + yytext + " contains an invalid prefix length");
    }
  }
Exemple #8
0
  /**
   * check each number of 1.2.3.4/5 in prefix is valid, as well as any bit ranges specified
   *
   * @param yytext
   */
  public static void validateIpv4PrefixRange(final String yytext) {
    Matcher m = ADDRESS_PREFIX_RANGE_PATTERN.matcher(yytext);
    if (m.matches()) {
      try {
        Ipv4Resource.parse(m.group(1));
      } catch (IllegalArgumentException e) {
        syntaxError("IP prefix " + yytext + " contains an invalid octet");
      }

      int prefix = Integer.valueOf(m.group(2));
      if (prefix > MAX_BIT_LENGTH_IPV4) {
        syntaxError("IP prefix range " + yytext + " contains an invalid prefix length");
      }

      String fromString = m.group(3);
      int from = 0;
      if (fromString != null) {
        from = Integer.valueOf(fromString);
        if (from > MAX_BIT_LENGTH_IPV4) {
          syntaxError("IP prefix range " + yytext + " contains an invalid range");
        }
      }

      String toString = m.group(4);
      if (toString != null) {
        int to = Integer.valueOf(toString);
        if (to > MAX_BIT_LENGTH_IPV4) {
          syntaxError("IP prefix range " + yytext + " contains an invalid range");
        }

        if (to < from) {
          syntaxError("IP prefix " + yytext + " range end is less than range start");
        }
      }
    }
  }