UniFi AP DHCP adoption with URL

UniFi APs can automatically annonce themselves to a controller for adoption via either a DHCP option (43) or the unifi DNS name. But sadly both options don't officially allow you to configure a URL instead of just an IP address. If the controller is not hosted locally this is quite annoying as its IP might change and you cannot use non-standard ports.

Luckily there is an undocumented DHCP option code hidden in UniFi's firmware which allows passing the full URL to the inform endpoint. The standard IP-based provisioning uses option 43 code 1 containing an IP address in binary format. But there is also code 2 which takes a full URL in text format. Sadly configuration of these vendor-specific options is very dependant on the used DHCP server, I can only give an example for ISC dhcpd.

option space ubnt;
option ubnt.unifi-address code 1 = ip-address;
# The undocumented URL option
option ubnt.unifi-url code 2 = text;

# Define Ubiquiti vendor class with option space
class "ubnt" {
	match if substring (option vendor-class-identifier , 0, 4) = "ubnt";
	option vendor-class-identifier "ubnt";
	vendor-option-space ubnt;
}

shared-network testing {
	subnet 192.0.2.0 netmask 255.255.255.0 {
		option ubnt.unifi-url "http://unifi.example.com/inform";
        # ...
	}
}
Example configuration for ISC dhcpd

With this configured, all unconfigured UniFi APs in the network will send an adoption request to the given inform endpoint.

Since this option is undocumented by Ubiquiti, it could theoretically go away at any time, but it has been there for at least a few years and three major firmware revisions (4, 5 and 6) so it seems like Ubiquiti has no interest in removing it.