[libvirt] [PATCH] 2/3 Store the range size when adding a DHCP range

Daniel P. Berrange berrange at redhat.com
Wed Oct 14 09:57:43 UTC 2009


On Tue, Oct 13, 2009 at 04:14:00PM +0200, Daniel Veillard wrote:
> +
> +        /*
> +         * check at least the 2 first IP match i.e on same class C subnet
> +         */
> +        for (i = 0; i < 2;i++) {
> +            if (ip4s[i] != ip4e[i]) {
> +                virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
> +                   _("start and end of DHCP range do not match '%s' and '%s'"),
> +                                      start, end);
> +                return(-1);
> +            }
> +        }

Shouldn't we be comparing each of DHCP addresses against the 'netmask'
field we have in virNetworkDef instead. It'd be nice to have a separate
function for this like

    virSocketAddrInNetwork(struct sockaddr_storage *address,
                           struct sockaddr_storage *netmask);

since there's a couple of other places we ought todo this kind of
validation.

> +        ret = ip4e[3] - ip4s[3] + 256 * (ip4e[2] - ip4s[2]);

It would be nice to have this in a callable function too

     int virSocketAddrRange(struct sockaddr_storage *start,
                            struct sockaddr_storage *end);

> +
> +        /*
> +         * a bit of sanity checking on the range
> +         * Should we complain for a range of more than 10,000 ?
> +         */

Its probably sufficient to leave dnsmasq to do validation.

> +        if (ret < 0) {
> +            virNetworkReportError(conn, VIR_ERR_INTERNAL_ERROR,
> +               _("start and end of DHCP range swapped '%s' and '%s'"),
> +                                  start, end);
> +            return(-1);
> +        }
> +
> +        /* include the boundaries */
> +        ret++;

> diff --git a/src/conf/network_conf.h b/src/conf/network_conf.h
> index e983a01..2960e8b 100644
> --- a/src/conf/network_conf.h
> +++ b/src/conf/network_conf.h
> @@ -45,6 +45,7 @@ typedef virNetworkDHCPRangeDef *virNetworkDHCPRangeDefPtr;
>  struct _virNetworkDHCPRangeDef {
>      char *start;
>      char *end;
> +    int size;
>  };

Regards,x
Daniel
-- 
|: Red Hat, Engineering, London   -o-   http://people.redhat.com/berrange/ :|
|: http://libvirt.org  -o-  http://virt-manager.org  -o-  http://ovirt.org :|
|: http://autobuild.org       -o-         http://search.cpan.org/~danberr/ :|
|: GnuPG: 7D3B9505  -o-  F3C9 553F A1DA 4AC2 5648 23C1 B3DF F742 7D3B 9505 :|




More information about the libvir-list mailing list