Assign ip from ipv4/ipv6 scope

Hi,
What is the best way to store a ipv4 and ipv6 scope/pool (and lease info) in a database and then select a free ip from one of the scopes?

//Mathias

In Go, you can use a net.IPNet to represent a network with a mask and test for membership in it. If you need non-netmask ranges you could use a pair of net.IP and do the range checks manually. Your database might have IP types that are useful for sorting and selecting on networks directly in the database. Worst case, strings work. It’s hard to be more specific without a more specific question. :slight_smile:

Thanks,
I guess that i can verify that the adress fits the submet that way.

Im looking for a good way to return a free IP from a scope/pool stored in a
database.

Let’s say if a request comes in and the rules says it should be assigned an
address from subnet A.

I could then start from the lowest walking up in the scope to look for a
not already leased adresse.

Storing subnet as strings and ips as int.

I’m not sure if this is a good way to do it.

Let’s say we add 3 more dhcp servers and alot of trafic… might be to slow
to make that request each time? Or the same address gets selected.

It sounds reasonable on the face of it. A typical approach when you have multiple DHCP servers serving the same subnet is to have them assign addresses from separate chunks of the subnet, to avoid having to coordinate between themselves. You will still need some coordination to decide who should answer the client; based on health checks, some factor of the client itself (i.e. one server answering even MAC addresses etc) or by looking at the responses (server A responding directly, server B answering if it does not see an answer from A, etc). But this is all DHCP stuff, not Go as such.

Yeah. It’s more about design than Go but I will write it in Go and I
thought this forum might have some brilliant minds to help with some
thought about the design. :slight_smile:

This topic was automatically closed 90 days after the last reply. New replies are no longer allowed.