large interface id cause error: DHCPSRV_OPEN_SOCKET_FAIL failed to open socket: the interface eth0 has no usable IPv4 addresses configured
Describe the bug
When the interface id is greater than 65535, kea-dhcp4 issue error "DHCPSRV_OPEN_SOCKET_FAIL failed to open socket: the interface eth0 has no usable IPv4 addresses configured" and does not work.
To Reproduce
Run following shell script test.sh with Dockerfile in root user to reproduce the behavior.
test.sh
#!/bin/bash
docker build -t test .
COUNT=65536
I=0
while [ $I -lt $COUNT ]
do
brctl addbr test
if (( $I % 100 == 0 ))
then
ip link
fi
brctl delbr test
let I++
done
docker run --rm test
Dockerfile
FROM alpine:edge
RUN echo "@testing http://dl-cdn.alpinelinux.org/alpine/edge/testing" >> /etc/apk/repositories &&\
apk add --update --no-cache mariadb-client kea-dhcp4@testing
RUN mkdir /run/kea
RUN sed -i -e 's/"interfaces":.*/"interfaces": [ "*" ]/g' /etc/kea/kea-dhcp4.conf
RUN sed -i -e 's/"output":.*/"output": "stdout"/g' /etc/kea/kea-dhcp4.conf
CMD [ "kea-dhcp4", "-c", "/etc/kea/kea-dhcp4.conf" ]
Expected behavior
kea-dhcp4 server starts without error.
Environment:
- Kea version: Kea DHCPv4 server version 1.7.8 (development)
- OS: alpine(docker container), CentOS/7 with brclt (docker host)
Additional Information
I have found the code that causes this bug.
at https://gitlab.isc.org/isc-projects/kea/-/blob/master/src/lib/dhcp/iface_mgr.h#L212
uint16_t getIndex() const { return ifindex_; }
In, ifindex_ is an int type, but the return value is a uint16_t type. When the value of ifindex_ exceeds 65536, the upper bits are cut off and a different value is returned.
On the other hand, in the code of https://gitlab.isc.org/isc-projects/kea/-/blob/master/src/lib/dhcp/iface_mgr_linux.cc#L289, the return value of getIndex() and ifa_index have been compared and failed to find the interface due to a mismatch.