voxpupuli / puppet-network

Types and providers to manage network interfaces
https://forge.puppet.com/puppet/network
Apache License 2.0
66 stars 109 forks source link

Unable to set correct netmask for IPv6 #267

Closed mkoe closed 1 year ago

mkoe commented 4 years ago

Affected Puppet, Ruby, OS and module versions/distributions

Tested with both moduleversions

How to reproduce (e.g Puppet code you use)

issues:

  1. cannot set a netmask like 64 128 or any other value for ipv6 addresses
  2. you can set a ipv4 netmask for a ipv6 addresse

how to reproduce issues:

  1. set as ipaddress parameter a ipv6 ip and as a netmask parameter 64
  2. set a ipv6 ip and as a netmask parameter a valid ipv4 netmask eg. 255.255.255.0

What are you seeing

issue 1: Config:

eth0:0:
    ensure: present
    ipaddress: XXXX:XXXX:XXXX:114::6
    netmask: 64
    family: 'inet6'
    method: 'static'
    onboot: true
    hotplug: true

Result error:

Error: Failed to apply catalog: Parameter netmask failed on Network_config[eth0:0]: Puppet::Type::Network_config::Netmask requires a valid netmask for the netmask property at

issue 2: Config:

eth0:0:
    ensure: present
    ipaddress: XXXX:XXXX:XXXX:114::6
    netmask: 255.255.255.0
    family: 'inet6'
    method: 'static'
    onboot: true
    hotplug: true

Result /etc/network/interfaces:

iface eth2:0 inet6 static
address XXXX:XXXX:XXXX:114::6
netmask 255.0.0.0

What behaviour did you expect instead

Setting a correct IPv6 netmask like netmask 64 Not able to apply a IPv4 netmask to a IPv6 ip

Output log

Any additional information you'd like to impart

As a quick, dirty and incorrect fix:

--- a/lib/puppet/type/network_config.rb
+++ b/lib/puppet/type/network_config.rb
@@ -43,7 +43,7 @@ Puppet::Type.newtype(:network_config) do
     desc 'The subnet mask to apply to the interface'
     if defined? IPAddress
       validate do |value|
-        raise ArgumentError, "#{self.class} requires a valid netmask for the netmask property" unless IPAddress.valid_ipv4_netmask? value
+        raise ArgumentError, "#{self.class} requires a valid netmask ( #{value} ) for the netmask property" unless ( IPAddress.valid_ipv4_netmask? value or ( value >= 0 && value.to_i <= 128 ) )
         # provider.validate
       end
     end

This quickfix, dirtyfix and incorrectfix, would allow now to set a invalid ipv4 netmask too, but would also allow to set a correct ipv6 netmask. It would:

  1. still allow to set a ipv4 netmask for ipv6 adresses
  2. allow to set a ipv6 netmask for ipv4 adresses

For clean fix for this, would result in a rewrite of the type, to check:

  1. which iptype
  2. check if netmask fits for that iptype
ajurjevi commented 2 years ago

Can someone address this issue?