[pve-devel] [RFC series pve-network/pve-cluster/qemu-server] DHCP

Alexandre Derumier aderumier at odiso.com
Mon Nov 13 11:04:04 CET 2023

Here my current work, based on wip2 Stefan Hanreich


I have removed dhcp.cfg extra file, and now we can simply define dhcptype in the zone

So, we'll have 1 dhcp server for each zone, could be in different vrf with same subnet reuse.


simple: simpve
        dhcp dnsmasq
        ipam pve

simple: netbox
        dhcp dnsmasq
        ipam netbox


vnet: vnetpve
        zone simpve

vnet: vnetbox
        zone netbox


subnet: simple-
        vnet netbox
        dhcp-range start-address=,end-address=
        dnszoneprefix odiso.net

subnet: simpve-
        vnet vnetpve
        dhcp-range start-address=,end-address=
        dhcp-range start-address=,end-address=

subnet: netbox-
        vnet vnetbox
        dhcp-range start-address=,end-address=

subnet: netbox-2a05:71c0::-120
        vnet vnetbox
        dhcp-range start-address=2a05:71c0::10,end-address=2a05:71c0::20

I have implement netbox plugin to find a new ip in dhcp range (Don't seem possible
with phpipam, but we could define a full range with all ips).

I have splitted the ipam add|del , from the dhcp lease reservation.

The ipam add|del ip is done when creating|deleting vm, or add|del a vm nic

The dhcp reservation is done at vm start.

The delete of dhcp reservation is done at vm destroy.

(This can be easily extend for ephemeral ip)

At vm start, we search ip associated with mac address.

To avoid to call ipam each time, I have implemented an extra macs.db file, with a
mac-ip hash for fast lookup. This cache is populated with adding an ip in ipam (at vm creation, nic add),
it can also be populated at vm_start if mac is not yet cached.  (for example, if ip is pre-reserved manually in external ipam)

I have reused/improve my previous ipam code, so ipv6 is supported && dns plugin is also used if defined.

I have only implemented calls in qemu-server for now


Alexandre Derumier (9):
  define dhcpplugin in zone
  dhcp : add|del_ip_mapping: only add|del dhcp reservervation
  vnet|subnet: add_next_free_ip : implement dhcprange ipam search
  ipam : add macs.db for fast mac lookup
  ipam : add get_ips_from_mac
  vnets: rename del|add|update_cidr to ip
  vnets: add del_ips_from_mac
  ipams : pveplugin: remove del_dhcp_ip
  dhcp : dnsmasq: add_mapping: remove old mac,ip before append

 src/PVE/API2/Network/SDN/Zones.pm          |   1 +
 src/PVE/Network/SDN.pm                     |   4 +-
 src/PVE/Network/SDN/Dhcp.pm                | 166 ++++++---------------
 src/PVE/Network/SDN/Dhcp/Dnsmasq.pm        |  50 ++++---
 src/PVE/Network/SDN/Dhcp/Plugin.pm         |  28 +---
 src/PVE/Network/SDN/Ipams.pm               |  80 +++++++++-
 src/PVE/Network/SDN/Ipams/NetboxPlugin.pm  |  61 ++++++++
 src/PVE/Network/SDN/Ipams/PVEPlugin.pm     |  80 +++++-----
 src/PVE/Network/SDN/Ipams/PhpIpamPlugin.pm |  29 ++++
 src/PVE/Network/SDN/Ipams/Plugin.pm        |  13 ++
 src/PVE/Network/SDN/SubnetPlugin.pm        |   4 -
 src/PVE/Network/SDN/Subnets.pm             |  37 +++--
 src/PVE/Network/SDN/Vnets.pm               |  88 ++++++-----
 src/PVE/Network/SDN/Zones/SimplePlugin.pm  |   7 +-
 src/test/run_test_subnets.pl               |   8 +-
 src/test/run_test_vnets.pl                 |   4 +-
 16 files changed, 393 insertions(+), 267 deletions(-)


Alexandre Derumier (1):
  add priv/macs.db

 src/PVE/Cluster.pm  | 1 +
 src/pmxcfs/status.c | 1 +
 2 files changed, 2 insertions(+)


Alexandre Derumier (5):
  don't remove dhcp mapping on stop
  vmnic add|remove : add|del ip in ipam
  vm_start : vm-network-scripts: get ip from ipam and add dhcp
  api2: create|restore|clone: add_free_ip
  vm_destroy: delete ip from ipam && dhcp

 PVE/API2/Qemu.pm                  |  6 +++
 PVE/QemuServer.pm                 | 72 +++++++++++++++++++++++++++++++
 vm-network-scripts/pve-bridge     |  4 +-
 vm-network-scripts/pve-bridgedown | 19 --------
 4 files changed, 81 insertions(+), 20 deletions(-)


More information about the pve-devel mailing list