Generate the correct prefix value for IPv4 netmasks 0.0.0.0
When the netmask is assigned the value 0.0.0.0 the prefix is 0, not
33. The algorithm generated an incorrect prefix value when the netmask
was set to 0.0.0.0.
Tested:
ipmitool lan set 3 ipsrc static
ipmitool lan set 3 ipaddr 192.168.20.12
Setting LAN IP Address to 192.168.20.12
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 52:3b:aa:7b:0d:d5 brd ff:ff:ff:ff:ff:ff
inet 192.168.20.12/32 scope global eth0
valid_lft forever preferred_lft forever
inet6 fe80::503b:aaff:fe7b:dd5/64 scope link
valid_lft forever preferred_lft forever
ipmitool lan set 3 netmask 0.0.0.0
Setting LAN Subnet Mask to 0.0.0.0
LAN Parameter Data does not match! Write may have failed.
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 52:3b:aa:7b:0d:d5 brd ff:ff:ff:ff:ff:ff
inet 169.254.51.116/16 brd 169.254.255.255 scope link eth0
valid_lft forever preferred_lft forever
inet6 fe80::503b:aaff:fe7b:dd5/64 scope link
valid_lft forever preferred_lft forever
ipmitool lan set 3 ipaddr 192.168.20.12
Setting LAN IP Address to 192.168.20.12
ipmitool raw 0xc 1 3 6 0 0 0 0
Unable to send RAW command (channel=0x0 netfn=0xc lun=0x0 cmd=0x1 rsp=0xff): Unspecified error
2: eth0: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc pfifo_fast qlen 1000
link/ether 52:3b:aa:7b:0d:d5 brd ff:ff:ff:ff:ff:ff
inet 169.254.51.116/16 brd 169.254.255.255 scope link eth0
valid_lft forever preferred_lft forever
inet6 fe80::503b:aaff:fe7b:dd5/64 scope link
valid_lft forever preferred_lft forever
Change-Id: I94cc02971bf21dabf1f1e22ad078d879393133b8
Signed-off-by: Johnathan Mantey <johnathanx.mantey@intel.com>
diff --git a/transporthandler.cpp b/transporthandler.cpp
index 74d1817..fbd127f 100644
--- a/transporthandler.cpp
+++ b/transporthandler.cpp
@@ -1041,7 +1041,9 @@
log<level::ERR>("Invalid netmask", entry("NETMASK=%s", maskStr));
elog<InternalFailure>();
}
- return 32 - __builtin_ctz(x);
+ return static_cast<bool>(x)
+ ? AddrFamily<AF_INET>::defaultPrefix - __builtin_ctz(x)
+ : 0;
}
// We need to store this value so it can be returned to the client