Bug 997271 - ipcalc does not understand RFC3021
ipcalc does not understand RFC3021
Status: CLOSED ERRATA
Product: Red Hat Enterprise Linux 6
Classification: Red Hat
Component: initscripts (Show other bugs)
6.4
All Linux
unspecified Severity low
: rc
: ---
Assigned To: Lukáš Nykrýn
Jan Ščotka
:
Depends On:
Blocks:
  Show dependency treegraph
 
Reported: 2013-08-15 02:44 EDT by Telford Tendys
Modified: 2016-11-25 07:56 EST (History)
3 users (show)

See Also:
Fixed In Version: initscripts-9.03.47-1.el6
Doc Type: Bug Fix
Doc Text:
Cause: ipcalc did not know about rfc3021 Consequence: Broadcast address was not computed correctly Fix: We have taught ipcalc that rfc3021 exists. Result: Broadcast address should be now correct.
Story Points: ---
Clone Of:
Environment:
Last Closed: 2015-07-22 03:18:18 EDT
Type: Bug
Regression: ---
Mount Type: ---
Documentation: ---
CRM:
Verified Versions:
Category: ---
oVirt Team: ---
RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: ---


Attachments (Terms of Use)

  None (edit)
Description Telford Tendys 2013-08-15 02:44:43 EDT
Description of problem:

Broadcast address is wrong for /31 networks, this will cause misconfiguration of ethernet devices.

Version-Release number of selected component (if applicable):

   initscripts-9.03.38-1.el6.centos.1.i686


How reproducible: Always

Steps to Reproduce:

ipcalc -b 10.10.10.10/31

Actual results:

BROADCAST=10.10.10.11

Expected results:

BROADCAST=255.255.255.255

Additional info:

[root@fmc ~]# cat /etc/sysconfig/network-scripts/ifcfg-eth1
DEVICE="eth1"
BOOTPROTO="static"
HWADDR="00:0C:29:2F:92:7C"
IPV6INIT="no"
MTU="1500"
NM_CONTROLLED="no"
TYPE="Ethernet"
ONBOOT=yes
IPADDR=10.81.81.81
NETMASK=255.255.255.254


Note that "BROADCAST=255.255.255.255" needs to be manually inserted if you want your ethernet configured correctly, actually it should not require that because the correct result is well defined already.

[root@fmc ~]# strace -o /tmp/fff -f  /sbin/ifup  eth1
[root@fmc ~]# fgrep ipcalc /tmp/fff
9100  execve("/bin/ipcalc", ["/bin/ipcalc", "--prefix", "10.81.81.81", "255.255.255.254"], [/* 18 vars */]) = 0
9101  execve("/bin/ipcalc", ["/bin/ipcalc", "--broadcast", "10.81.81.81", "255.255.255.254"], [/* 18 vars */]) = 0
9106  execve("/bin/ipcalc", ["/bin/ipcalc", "--network", "10.81.81.81", "255.255.255.254"], [/* 18 vars */]) = 0


You can see the script depends on ipcalc to get the answer right... and so it should get the answer right.
Comment 1 Telford Tendys 2013-08-15 02:45:54 EDT
http://tools.ietf.org/html/rfc3021
Comment 3 Lukáš Nykrýn 2013-08-26 06:43:48 EDT
Can you please try this patch:
diff --git a/src/ipcalc.c b/src/ipcalc.c
index 7316f05..416180b 100644
--- a/src/ipcalc.c
+++ b/src/ipcalc.c
@@ -141,7 +141,11 @@ struct in_addr calc_broadcast(struct in_addr addr, int prefix)
     struct in_addr broadcast;
 
     memset(&broadcast, 0, sizeof(broadcast));
-    broadcast.s_addr = (addr.s_addr & mask.s_addr) | ~mask.s_addr;
+
+    if (mask.s_addr ==  htonl(0xFFFFFFFE))
+        broadcast.s_addr = htonl(0xFFFFFFFF);
+    else
+        broadcast.s_addr = (addr.s_addr & mask.s_addr) | ~mask.s_addr;
     return broadcast;
 }
Comment 4 Telford Tendys 2013-09-02 01:28:37 EDT
I replied to the Bugzilla email, but does not seem to have updated...

Yes the above patch worked for me (I tested by rebuilding SRPM). May I suggest a one-line comment in the source code mentioning RFC3021 (so people can find a reference explaining why it works that way, also in case anyone in future greps out the code looking for the RFC number) ?
Comment 10 errata-xmlrpc 2015-07-22 03:18:18 EDT
Since the problem described in this bug report should be
resolved in a recent advisory, it has been closed with a
resolution of ERRATA.

For information on the advisory, and where to find the updated
files, follow the link below.

If the solution does not work for you, open a new bug report.

https://rhn.redhat.com/errata/RHBA-2015-1380.html

Note You need to log in before you can comment on or make changes to this bug.