Esempio n. 1
0
    def clean_address_range(self):
        address_range = self.cleaned_data.get('address_range')
        try:
            r = resource_range_ip.parse_str(address_range)
            if r.version == 6:
                qs = models.ResourceRangeAddressV6
                version = 'IPv6'
            else:
                qs = models.ResourceRangeAddressV4
                version = 'IPv4'
        except BadIPResource:
            raise forms.ValidationError('invalid IP address range')

        if not qs.objects.filter(cert__conf=self.child.issuer,
                                 prefix_min__lte=r.min,
                                 prefix_max__gte=r.max).exists():
            raise forms.ValidationError(
                'IP address range is not delegated to you')

        # determine if the entered range overlaps with any prefix
        # already allocated to this child
        for n in self.child.address_ranges.filter(version=version):
            rng = n.as_resource_range()
            if r.max >= rng.min and r.min <= rng.max:
                raise forms.ValidationError(
                    'Overlap with previous allocation to this child')

        return str(r)
Esempio n. 2
0
    def clean_address_range(self):
        address_range = self.cleaned_data.get('address_range')
        try:
            r = resource_range_ip.parse_str(address_range)
            if r.version == 6:
                qs = models.ResourceRangeAddressV6
                version = 'IPv6'
            else:
                qs = models.ResourceRangeAddressV4
                version = 'IPv4'
        except BadIPResource:
            raise forms.ValidationError('invalid IP address range')

        if not qs.objects.filter(cert__conf=self.child.issuer,
                                 prefix_min__lte=r.min,
                                 prefix_max__gte=r.max).exists():
            raise forms.ValidationError(
                'IP address range is not delegated to you')

        # determine if the entered range overlaps with any prefix
        # already allocated to this child
        for n in self.child.address_ranges.filter(version=version):
            rng = n.as_resource_range()
            if r.max >= rng.min and r.min <= rng.max:
                raise forms.ValidationError(
                    'Overlap with previous allocation to this child')

        return str(r)
Esempio n. 3
0
 def clean(self):
     try:
         r = resource_range_ip.parse_str(self.cleaned_data.get('prefix'))
         if r.prefixlen() > self.cleaned_data.get('max_prefixlen'):
             raise forms.ValidationError('max length is smaller than mask')
     except BadIPResource:
         pass
     return self.cleaned_data
Esempio n. 4
0
 def clean(self):
     try:
         r = resource_range_ip.parse_str(self.cleaned_data.get('prefix'))
         if r.prefixlen() > self.cleaned_data.get('max_prefixlen'):
             raise forms.ValidationError('max length is smaller than mask')
     except BadIPResource:
         pass
     return self.cleaned_data
Esempio n. 5
0
def search_view(request):
    certs = None
    roas = None

    if request.method == 'POST':
        form = forms.SearchForm2(request.POST, request.FILES)
        if form.is_valid():
            resource = form.cleaned_data.get('resource')
            # try to determine the type of input given
            try:
                r = resource_range_as.parse_str(resource)
                certs = models.Cert.objects.filter(asns__min__gte=r.min,
                                                   asns__max__lte=r.max)
                roas = models.ROA.objects.filter(asid__gte=r.min,
                                                 asid__lte=r.max)
            except:
                try:
                    r = resource_range_ip.parse_str(resource)
                    if r.version == 4:
                        certs = models.Cert.objects.filter(
                            addresses__prefix_min__lte=r.min,
                            addresses__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes__prefix_min__lte=r.min,
                            prefixes__prefix_max__gte=r.max)
                    else:
                        certs = models.Cert.objects.filter(
                            addresses_v6__prefix_min__lte=r.min,
                            addresses_v6__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes_v6__prefix_min__lte=r.min,
                            prefixes_v6__prefix_max__gte=r.max)
                except BadIPResource:
                    pass

    return render(request, 'cacheview/search_result.html', {
        'resource': resource,
        'certs': certs,
        'roas': roas
    })
Esempio n. 6
0
	def _as_resource_range(self):
	    """Convert the prefix in the form to a
	    rpki.resource_set.resource_range_ip object.

	    If there is no mask provided, assume the closest classful mask.

	    """
	    prefix = self.cleaned_data.get('prefix')
	    if '/' not in prefix:
		p = IPAddress(prefix)

		# determine the first nonzero bit starting from the lsb and
		# subtract from the address size to find the closest classful
		# mask that contains this single address
		prefixlen = 0
		while (p != 0) and (p & 1) == 0:
		    prefixlen = prefixlen + 1
		    p = p >> 1
		mask = p.bits - (8 * (prefixlen / 8))
		prefix = prefix + '/' + str(mask)

	    return resource_range_ip.parse_str(prefix)
Esempio n. 7
0
        def _as_resource_range(self):
            """Convert the prefix in the form to a
            rpki.resource_set.resource_range_ip object.

            If there is no mask provided, assume the closest classful mask.

            """
            prefix = self.cleaned_data.get('prefix')
            if '/' not in prefix:
                p = IPAddress(prefix)

                # determine the first nonzero bit starting from the lsb and
                # subtract from the address size to find the closest classful
                # mask that contains this single address
                prefixlen = 0
                while (p != 0) and (p & 1) == 0:
                    prefixlen = prefixlen + 1
                    p = p >> 1
                mask = p.bits - (8 * (prefixlen / 8))
                prefix = prefix + '/' + str(mask)

            return resource_range_ip.parse_str(prefix)
Esempio n. 8
0
def search_view(request):
    certs = None
    roas = None

    if request.method == 'POST':
        form = forms.SearchForm2(request.POST, request.FILES)
        if form.is_valid():
            resource = form.cleaned_data.get('resource')
            # try to determine the type of input given
            try:
                r = resource_range_as.parse_str(resource)
                certs = models.Cert.objects.filter(asns__min__gte=r.min,
                                                   asns__max__lte=r.max)
                roas = models.ROA.objects.filter(asid__gte=r.min,
                                                 asid__lte=r.max)
            except:
                try:
                    r = resource_range_ip.parse_str(resource)
                    if r.version == 4:
                        certs = models.Cert.objects.filter(
                            addresses__prefix_min__lte=r.min,
                            addresses__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes__prefix_min__lte=r.min,
                            prefixes__prefix_max__gte=r.max)
                    else:
                        certs = models.Cert.objects.filter(
                            addresses_v6__prefix_min__lte=r.min,
                            addresses_v6__prefix_max__gte=r.max)
                        roas = models.ROA.objects.filter(
                            prefixes_v6__prefix_min__lte=r.min,
                            prefixes_v6__prefix_max__gte=r.max)
                except BadIPResource:
                    pass

    return render(request, 'cacheview/search_result.html',
                  {'resource': resource, 'certs': certs, 'roas': roas})
Esempio n. 9
0
 def clean_prefix(self):
     try:
         r = resource_range_ip.parse_str(self.cleaned_data.get('prefix'))
     except BadIPResource:
         raise forms.ValidationError('invalid prefix')
     return str(r)
Esempio n. 10
0
 def clean_prefix(self):
     try:
         r = resource_range_ip.parse_str(self.cleaned_data.get('prefix'))
     except BadIPResource:
         raise forms.ValidationError('invalid prefix')
     return str(r)