[pve-devel] [PATCH] Added check_ipv4_settings function to verify if given address and mask makes a valid host address

damien piquet piqudam at gmail.com
Mon Feb 25 21:40:02 CET 2013


Hi,

Here is the patch to check if given address is a valid host IP
depending on the netmask.

With this additionnal check, we are sure that the ip parameters
entered via the interface are OK.



2013/2/25 root <piqudam at gmail.com>:
>
> Signed-off-by: root <root at pyrit>
> ---
>  PVE/API2/Network.pm |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
> index 979063c..7b3969b 100644
> --- a/PVE/API2/Network.pm
> +++ b/PVE/API2/Network.pm
> @@ -12,6 +12,7 @@ use PVE::RPCEnvironment;
>  use PVE::JSONSchema qw(get_standard_option);
>  use PVE::AccessControl;
>  use IO::File;
> +use Net::IP qw(:PROC);
>
>  use base qw(PVE::RESTHandler);
>
> @@ -159,6 +160,15 @@ my $check_duplicate_gateway = sub {
>      }
>  };
>
> +my $check_ipv4_settings = sub {
> +    my $param = $_[0];
> +
> +    my $binip = Net::IP::ip_iptobin($param->{address}, 4);
> +    my $binmask = Net::IP::ip_iptobin($param->{netmask}, 4);
> +
> +    raise_param_exc({ address => "$param->{address} is not a valid host ip address." })
> +        if(($binip | $binmask) eq $binmask);
> +};
>
>  __PACKAGE__->register_method({
>      name => 'create_network',
> @@ -192,6 +202,8 @@ __PACKAGE__->register_method({
>             &$check_duplicate_gateway($config, $iface)
>                 if $param->{gateway};
>
> +           &$check_ipv4_settings($param);
> +
>             $param->{method} = $param->{address} ? 'static' : 'manual';
>
>             $config->{$iface} = $param;
> @@ -247,6 +259,8 @@ __PACKAGE__->register_method({
>             &$check_duplicate_gateway($config, $iface)
>                 if $param->{gateway};
>
> +           &$check_ipv4_settings($param);
> +
>             $param->{method} = $param->{address} ? 'static' : 'manual';
>
>             foreach my $k (keys %$param) {
> --
> 1.7.10.4
>


2013/2/25 root <piqudam at gmail.com>:
>
> Signed-off-by: root <root at pyrit>
> ---
>  PVE/API2/Network.pm |   14 ++++++++++++++
>  1 file changed, 14 insertions(+)
>
> diff --git a/PVE/API2/Network.pm b/PVE/API2/Network.pm
> index 979063c..7b3969b 100644
> --- a/PVE/API2/Network.pm
> +++ b/PVE/API2/Network.pm
> @@ -12,6 +12,7 @@ use PVE::RPCEnvironment;
>  use PVE::JSONSchema qw(get_standard_option);
>  use PVE::AccessControl;
>  use IO::File;
> +use Net::IP qw(:PROC);
>
>  use base qw(PVE::RESTHandler);
>
> @@ -159,6 +160,15 @@ my $check_duplicate_gateway = sub {
>      }
>  };
>
> +my $check_ipv4_settings = sub {
> +    my $param = $_[0];
> +
> +    my $binip = Net::IP::ip_iptobin($param->{address}, 4);
> +    my $binmask = Net::IP::ip_iptobin($param->{netmask}, 4);
> +
> +    raise_param_exc({ address => "$param->{address} is not a valid host ip address." })
> +        if(($binip | $binmask) eq $binmask);
> +};
>
>  __PACKAGE__->register_method({
>      name => 'create_network',
> @@ -192,6 +202,8 @@ __PACKAGE__->register_method({
>             &$check_duplicate_gateway($config, $iface)
>                 if $param->{gateway};
>
> +           &$check_ipv4_settings($param);
> +
>             $param->{method} = $param->{address} ? 'static' : 'manual';
>
>             $config->{$iface} = $param;
> @@ -247,6 +259,8 @@ __PACKAGE__->register_method({
>             &$check_duplicate_gateway($config, $iface)
>                 if $param->{gateway};
>
> +           &$check_ipv4_settings($param);
> +
>             $param->{method} = $param->{address} ? 'static' : 'manual';
>
>             foreach my $k (keys %$param) {
> --
> 1.7.10.4
>



More information about the pve-devel mailing list