mirror of
https://github.com/openwrt/openwrt.git
synced 2025-01-08 14:03:06 +00:00
36f309af05
dnsmasq passes a limited amount of information via DHCP script arguments. Much more information is available through environment variables starting with DNSMASQ_, such as DNSMASQ_INTERFACE. However, when the dhcp-script builds its JSON environment and passes it to hotplug, all of this information is discarded since it is not copied to the JSON environment. Personally, I have a custom-made set of DDNS scripts and rely on environment variables such as DNSMASQ_INTERFACE in order to determine which DNS zones to update. So, not being able to access these variables was detrimental to me. I patched in a quick copy of all DNSMASQ_ variables to the JSON environment so that they can be used in hotplug scripts. In order to do so I also copied /usr/bin/env into dnsmasq's chroot jail. Signed-off-by: Chuck R <github@chuck.cloud> Link: https://github.com/openwrt/openwrt/pull/16354 Signed-off-by: John Crispin <john@phrozen.org>
63 lines
1.1 KiB
Bash
Executable File
63 lines
1.1 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
[ -f "$USER_DHCPSCRIPT" ] && . "$USER_DHCPSCRIPT" "$@"
|
|
|
|
. /usr/share/libubox/jshn.sh
|
|
|
|
json_init
|
|
json_add_array env
|
|
hotplugobj=""
|
|
|
|
oldIFS=$IFS
|
|
IFS=$'\n'
|
|
for var in $(env); do
|
|
if [ "${var}" != "${var#DNSMASQ_}" ]; then
|
|
json_add_string "" "${var%%=*}=${var#*=}"
|
|
fi
|
|
done
|
|
IFS=$oldIFS
|
|
|
|
case "$1" in
|
|
add | del | old | arp-add | arp-del)
|
|
json_add_string "" "MACADDR=$2"
|
|
json_add_string "" "IPADDR=$3"
|
|
;;
|
|
esac
|
|
|
|
case "$1" in
|
|
add)
|
|
json_add_string "" "ACTION=add"
|
|
json_add_string "" "HOSTNAME=$4"
|
|
hotplugobj="dhcp"
|
|
;;
|
|
del)
|
|
json_add_string "" "ACTION=remove"
|
|
json_add_string "" "HOSTNAME=$4"
|
|
hotplugobj="dhcp"
|
|
;;
|
|
old)
|
|
json_add_string "" "ACTION=update"
|
|
json_add_string "" "HOSTNAME=$4"
|
|
hotplugobj="dhcp"
|
|
;;
|
|
arp-add)
|
|
json_add_string "" "ACTION=add"
|
|
hotplugobj="neigh"
|
|
;;
|
|
arp-del)
|
|
json_add_string "" "ACTION=remove"
|
|
hotplugobj="neigh"
|
|
;;
|
|
tftp)
|
|
json_add_string "" "ACTION=add"
|
|
json_add_string "" "TFTP_SIZE=$2"
|
|
json_add_string "" "TFTP_ADDR=$3"
|
|
json_add_string "" "TFTP_PATH=$4"
|
|
hotplugobj="tftp"
|
|
;;
|
|
esac
|
|
|
|
json_close_array env
|
|
|
|
[ -n "$hotplugobj" ] && ubus call hotplug.${hotplugobj} call "$(json_dump)"
|