diff --git a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh index 0bef6a1abb..f6e0690884 100755 --- a/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh +++ b/package/network/config/netifd/files/lib/netifd/proto/dhcp.sh @@ -4,6 +4,7 @@ . /lib/functions.sh . ../netifd-proto.sh +. /lib/config/uci.sh init_proto "$@" proto_dhcp_init_config() { @@ -31,6 +32,18 @@ proto_dhcp_add_sendopts() { [ -n "$1" ] && append "$3" "-x $1" } +proto_dhcp_get_default_clientid() { + [ -z "$1" ] && return + + local iface="$1" + local duid + local iaid="0" + + [ -e "/sys/class/net/$iface/ifindex" ] && iaid="$(cat "/sys/class/net/$iface/ifindex")" + duid="$(uci_get network @globals[0] dhcp_default_duid)" + [ -n "$duid" ] && printf "ff%08x%s" "$iaid" "$duid" +} + proto_dhcp_setup() { local config="$1" local iface="$2" @@ -51,6 +64,7 @@ proto_dhcp_setup() { [ "$defaultreqopts" = 0 ] && defaultreqopts="-o" || defaultreqopts= [ "$broadcast" = 1 ] && broadcast="-B" || broadcast= [ "$norelease" = 1 ] && norelease="" || norelease="-R" + [ -z "$clientid" ] && clientid="$(proto_dhcp_get_default_clientid "$iface")" [ -n "$clientid" ] && clientid="-x 0x3d:${clientid//:/}" [ -n "$iface6rd" ] && proto_export "IFACE6RD=$iface6rd" [ "$iface6rd" != 0 -a -f /lib/netifd/proto/6rd.sh ] && append dhcpopts "-O 212"