## The Issue
The `src/conf_mode/service_dhcp-server.py` script exhibits significant performance degradation when configured with multiple shared networks/subnets. The slowdown becomes noticeable with dozens of entries and can become severe (dozens of minutes) with hundreds.
## How to reproduce
The config that triggers the issue can be generated by the script:
```
#!/usr/bin/env bash
NUM=500 # how many VLANs/interfaces to generate
START_VLAN=3001 # first VLAN ID to use
for ((i=0; i<NUM; i++)); do
vlan=$((START_VLAN + i))
# Map i -> network 10.o2.o3.0/24
# i = 0..999 gives you:
# 10.0.0.0/24, 10.0.1.0/24, ... up to 10.3.231.0/24
o2=$((i / 256))
o3=$((i % 256))
subnet="10.$o2.$o3.0/24"
router="10.$o2.$o3.1"
range_start="10.$o2.$o3.10"
range_stop="10.$o2.$o3.200"
cat <<EOF
set interfaces ethernet eth3 vif $vlan address '$router/24'
set interfaces ethernet eth3 vif $vlan description 'LAN VLAN $vlan'
set service dhcp-server shared-network-name VLAN$vlan subnet $subnet option default-router '$router'
set service dhcp-server shared-network-name VLAN$vlan subnet $subnet option name-server '$router'
set service dhcp-server shared-network-name VLAN$vlan subnet $subnet range 0 start '$range_start'
set service dhcp-server shared-network-name VLAN$vlan subnet $subnet range 0 stop '$range_stop'
set service dhcp-server shared-network-name VLAN$vlan subnet $subnet subnet-id '$vlan'
set service dhcp-server shared-network-name VLAN$vlan authoritative
set service dns forwarding allow-from '$subnet'
EOF
done
```
## Reasons
There are a lot of them (probably only a surface):
- iterates through all system interfaces for each `listen-address`
- repeated interface enumeration for each subnet to check if an address is connected to the system
- O(n²) subnet overlap detection logic
## Solution
The logic of the script needs to be re-implemented to avoid unnecessary work.