#!/bin/sh

. /lib/functions
. /usr/share/libubox/jshn.sh

lan_guest_if="guest"

json_load "`cat /tmp/cache/systeminfo/sysinfo.info`"
json_get_var orbi_type "orbi_type"
	
[ "$orbi_type" = "Base" ] || exit

json_load "`cat /tmp/cache/systeminfo/ethinfo.info`"
json_get_vars lan_net_section "lan_net_section"

[ "$ACTION" = "ifup" ] || exit

if [ ${INTERFACE} = "$lan_guest_if" ]; then
	echo =======$INTERFACE $ACTION : hotplug reload dhcp guest server ====== >/dev/console
        /usr/sbin/check_guest_lan_ip_conflict.sh
        retval=$?
        [ "$retval" = "1" ] && ubus call network reload
	
	/etc/init.d/guest_dhcpd.init stop
	/etc/init.d/guest_dhcpd.init start
fi


if [ ${INTERFACE} = "$lan_net_section" ]; then
	echo =======$INTERFACE $ACTION : hotplug reload dhcp server ====== >/dev/console
        /usr/sbin/check_guest_lan_ip_conflict.sh
        retval=$?
        [ "$retval" = "1" ] && ubus call network reload
	
	/etc/init.d/dhcpd.init stop
	/etc/init.d/dhcpd.init start
fi
