OVN dhcp ranges

Is there anyway to set a DHCP range for an OVN network. I looked at the documentation and find no option. Searching the internet for a bit I found that you can exclude ip a range from the dhcp pool, which is ideal if you want to set some static ips. The command below effectively achieve the desired effect but it would have to be managed outside of incus.

ovn-nbctl set logical_switch net0 \
  other_config:subnet="10.0.0.0/24" \
  other_config:exclude_ips="10.0.0.1..10.0.0.10"

That’s not currently supported. We’d want to have our usual ipv4.dhcp.ranges so the allowed range will need to be turned into exclude ranges internally.

I did some testing setting the excluded IPs and it seem to work. Assuming I have the 3 vm below. the next logical IPs would be 2 and 6.

 inc list -c n,4
+-------+-------------------+
| NAME  |       IPV4        |
+-------+-------------------+
| dns00 | 10.100.0.4 (eth0) |
+-------+-------------------+
| dns01 | 10.100.0.5 (eth0) |
+-------+-------------------+
| dns02 | 10.100.0.3 (eth0) |
+-------+-------------------+

For testing purposes, I ran the command below on the OVN switch that incus created.

sudo ovn-nbctl set logical_switch \
 incus-net46-ls-int other_config:exclude_ips="10.100.0.6"

Looking at the DB, I see the constraint was added correctly.

name                : incus-net46-ls-int
other_config        : {exclude_ips="10.100.0.6", subnet="10.100.0.0/24"}
ports               : [6f2cdbeb-872e-4128-9ba5-218341d94fd5,...]

I spun up two additional instances and got the expected results.

inc launch images:alpine/3.20/cloud tst00
inc launch images:alpine/3.20/cloud tst01

inc list -c n,4
+-------+-------------------+
| NAME  |       IPV4        |
+-------+-------------------+
| dns00 | 10.100.0.4 (eth0) |
+-------+-------------------+
| dns01 | 10.100.0.5 (eth0) |
+-------+-------------------+
| dns02 | 10.100.0.3 (eth0) |
+-------+-------------------+
| tst00 | 10.100.0.2 (eth0) |
+-------+-------------------+
| tst01 | 10.100.0.7 (eth0) |
+-------+-------------------+

As we can see it added 2 and skipped 6.

That’s good to know. So we basically “just” need logic to convert a ipv4.dhcp.ranges into their negative for that subnet. So look at the subnet and determine the ranges which we won’t be providing DHCP for and then put that as the exclusion.

I opened Add support for `ipv4.dhcp.ranges` on OVN · Issue #1097 · lxc/incus · GitHub for tracking

Thanks, @stgraber for adding this to the feature list.

For I temporary solution, I ended up reserving the first 50 IPs.

sudo ovn-nbctl set logical_switch incus-net46-ls-int \ 
  other_config:exclude_ips="10.100.0.1..10.100.0.49"

In my case this works out fine - since, I want to reserve the first continuous set of IPs from the gateway IP 10.100.0.1 to 10.100.0.49. However, If you wanted to reserve the last 50 or so IPs for example (10.100.0.200…10.100.0.254).

Maybe, you would need to exclude the gateway as well.

sudo ovn-nbctl set logical_switch incus-net46-ls-int \ 
  other_config:exclude_ips="10.100.0.1 10.100.0.200..10.100.0.254"

Either way the syntax on the command is space delimited if you need add multiple entires.

ovn-nbctl list logical_switch 7c6cc28c-29a4-4024-8972-6a8c4dda1d28
name                : incus-net46-ls-int
other_config        : {exclude_ips="10.100.0.1 10.100.0.200..10.100.0.254", subnet="10.100.0.0/24"}

Update, there seems to be logic in the code would already exclude_ips if you set them to static.

incus launch images:alpine/3.20/cloud test00 \
  --networkt ovn0 --device eth0,ipv4.address=10.100.0.10

Note: It would clobber any custom settings you might have set manually.

sudo ovn-nbctl list logical_switch
other_config        : {exclude_ips="10.100.0.1 10.100.0.12 10.100.0.10 10.100.0.11", subnet="10.100.0.0/24"}

So, until the code base is updated to support ranges, you won’t be able to manually set a range—unless you don’t ever plan to set the ips using the device switch.

Either way, having a good time experimenting with incus and ovn.

Ah yeah, I noticed that we were already excluding the gateway IP, but it makes sense that we would also exclude static IP assignments.