Bug 498568

Summary: ipcalc could allow recombining netmask and offset to derive host address
Product: [Fedora] Fedora Reporter: Philip Prindeville <philipp>
Component: initscriptsAssignee: Bill Nottingham <notting>
Status: CLOSED WONTFIX QA Contact: Fedora Extras Quality Assurance <extras-qa>
Severity: low Docs Contact:
Priority: low    
Version: rawhideCC: dspaldin, iarlyy, notting, philipp, rvokal
Target Milestone: ---   
Target Release: ---   
Hardware: All   
OS: Linux   
Whiteboard:
Fixed In Version: Doc Type: Bug Fix
Doc Text:
Story Points: ---
Clone Of: Environment:
Last Closed: 2009-06-02 01:21:57 UTC Type: ---
Regression: --- Mount Type: ---
Documentation: --- CRM:
Verified Versions: Category: ---
oVirt Team: --- RHEL 7.3 requirements from Atomic Host:
Cloudforms Team: --- Target Upstream Version:
Embargoed:

Description Philip Prindeville 2009-05-01 07:07:40 UTC
Description of problem:

Sometimes it's useful to have a base address (such as the beginning of a DHCP pool) and be able to synthesize addresses offset from that address.  Ipcalc would be the best tool to do this, but it lacks that capability.

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

8.76.4-1

How reproducible:

n/a

Steps to Reproduce:
1. n/a
2.
3.
  
Actual results:

Expected results:

I'm proposing a '-o' option, such that:

    ipcalc -o 192.168.1.32 50

would output:

    ADDRESS=192.168.1.82

for example.

Additional info:

Comment 1 Bill Nottingham 2009-05-01 13:37:43 UTC
I'm not sure of the usecase for this - is this for static assignment on the client? Or just as a shortcut for doing the math?

Comment 2 Philip Prindeville 2009-05-01 20:15:11 UTC
(In reply to comment #1)
> I'm not sure of the usecase for this - is this for static assignment on the
> client? Or just as a shortcut for doing the math?  

Yes, doing math for assigning devices to subordinate pool devices (like printers, VoIP phones, security cameras, etc) when you need to pre-populate a DHCP database from an init script...

Comment 3 iarly selbir 2009-06-01 23:59:47 UTC
I'm not sure if this is the right component for this report, because is dhclient ( from package dhclient ) that set address ip to interfaces and initscripts only call them, afaik.

Bill, what you think?

Thanks for your report Philipp

Keeping it as NEW.

Comment 4 Bill Nottingham 2009-06-02 01:21:57 UTC
It's the correct component, but I'm not convinced it's a necessary fix.

Heck, you can do the simple math in bash:

BASE=50
for offset in 1 2 3 4 5 6 7 ; do
   echo "IPADDR=192.168.1.$((BASE+offset))"
done

Comment 5 Philip Prindeville 2009-06-02 01:25:59 UTC
(In reply to comment #4)
> It's the correct component, but I'm not convinced it's a necessary fix.
> 
> Heck, you can do the simple math in bash:
> 
> BASE=50
> for offset in 1 2 3 4 5 6 7 ; do
>    echo "IPADDR=192.168.1.$((BASE+offset))"
> done  

Ok, and what if my netmask is not a multiple of 8?

What if I have a really large DHCP pool, say 192.168.2.2-192.168.3.63?

There are other ipcalc features I've been thinking of, as well...  various address relation operators.  "lt", "in", "overlaps", etc.

The fact of the matter is that IP addresses *can't* be handled as 4 unrelated small integers...  it doesn't make sense.

The only other possible fix is to add a built-in operator to bash's $(( ... )) that does dotted-quad to unsigned int and unsigned int to dotted-quad conversion so that then one could do arithmetic, comparisons, etc.