Feature #535

DHCP reservation validation

Added by Giacomo Sanchietti almost 10 years ago. Updated over 8 years ago.

Status:CLOSEDStart date:10/03/2011
Priority:NormalDue date:
Assignee:-% Done:

100%

Category:nethserver-dnsmasq
Target version:DEV4
Resolution: NEEDINFO:

Description

The module for Nethgui must permit the creation of host-ip association.
IP can be local, remote or self (the server).

Possibile ip validation:

sub not_in_dhcp_range
{
    my $self = shift;
    my $address = shift;
    my $status = $db->get('dhcpd')->prop('status') || "disabled";
    return "OK" unless $status eq "enabled";
    my $start = $db->get('dhcpd')->prop('start');
    my $end = $db->get('dhcpd')->prop('end');
    return (esmith::util::IPquadToAddr($start)
        <= esmith::util::IPquadToAddr($address)
        &&
        esmith::util::IPquadToAddr($address)
        <= esmith::util::IPquadToAddr($end)) ?
        "ADDR_IN_DHCP_RANGE" :
        "OK";
}

sub not_taken
{
    my $self = shift;
    my $q = $self->{cgi};
    my $localip = $q->param('local_ip');

    my $server_localip = $db->get_value('LocalIP') || '';
    my $server_gateway = $db->get_value('GatewayIP') || '';
    my $server_extip = $db->get_value('ExternalIP') || '';

    $self->debug_msg("\$localip is $localip");
    $self->debug_msg("\$server_localip is $server_localip");
    $self->debug_msg("\$server_gateway is $server_gateway");
    $self->debug_msg("\$server_extip is $server_extip");

    if ($localip eq $server_localip)
    {
        return 'ERR_IP_IS_LOCAL_OR_GATEWAY';
    }
    elsif ($localip eq $server_gateway)
    {
        return 'ERR_IP_IS_LOCAL_OR_GATEWAY';
    }
    elsif (($db->get_value('SystemMode') ne 'serveronly') &&
           ($server_extip eq $localip))
    {
        return 'ERR_IP_IS_LOCAL_OR_GATEWAY';
    }
    elsif ($localip eq '127.0.0.1')
    {
        return 'ERR_IP_IS_LOCAL_OR_GATEWAY';
    }
    else
    {
        return 'OK';
    }
}

sub must_be_local
{
    my $self = shift;
    my $q = $self->{cgi};
    my $localip = $q->param('local_ip');

    # Make sure that the IP is indeed local.
    my $ndb = esmith::NetworksDB->open_ro;
    my @local_list = $ndb->local_access_spec;

    foreach my $spec (@local_list)
    {
        next if $spec eq '127.0.0.1';
        if (Net::IPv4Addr::ipv4_in_network($spec, $localip))
        {
            return 'OK';
        }
    }
    # Not OK. The IP is not on any of our local networks.
    return 'ERR_IP_NOT_LOCAL';
}


Related issues

Related to Nethgui - Feature #1052: Hostname with/without domain part validator CLOSED 04/18/2012
Related to NethServer 6 - Feature #1057: dhcp reservation validator: check IP address in use CLOSED 05/22/2012 05/22/2012
Related to Nethgui - Feature #1058: Platform validator: localizable messages CLOSED 05/23/2012 05/24/2012

Associated revisions

Revision 395ba4c5
Added by Davide Principi over 9 years ago

Hosts UI: changed validator of hostname field to HOSTNAME_SIMPLE. Refs #535 - DHCP reservation validation

Revision a3f7691c
Added by Davide Principi over 9 years ago

Hosts UI module. Closes #535 - Dhcp reservation validation

History

#1 Updated by Giacomo Sanchietti almost 10 years ago

  • Project changed from 33 to 9

#2 Updated by Giacomo Sanchietti almost 10 years ago

  • Status changed from NEW to ON_DEV
  • % Done changed from 0 to 50

Gui is ready.

Tests and some validation are still needed.

#3 Updated by Giacomo Sanchietti almost 10 years ago

  • Subject changed from Add module for NethGUI to Add Hosts module for NethGUI

#4 Updated by Giacomo Sanchietti over 9 years ago

  • Subject changed from Add Hosts module for NethGUI to Hosts module validation

#5 Updated by Giacomo Sanchietti over 9 years ago

  • Subject changed from Hosts module validation to DHCP reservation validation

#6 Updated by Davide Principi over 9 years ago

  • Target version set to DEV2

#7 Updated by Davide Principi over 9 years ago

  • Target version changed from DEV2 to DEV3

#8 Updated by Davide Principi over 9 years ago

  • Target version changed from DEV3 to DEV4

#9 Updated by Davide Principi over 9 years ago

  • Status changed from ON_DEV to MODIFIED
  • % Done changed from 50 to 100

Applied in changeset commit:a3f7691c4001ff41b5863d1515bd8f50d7d7941c.

#10 Updated by Davide Principi over 9 years ago

  • Assignee set to Davide Principi

#11 Updated by Davide Principi over 8 years ago

  • Project changed from 9 to NethServer 6

Also available in: Atom PDF