From 88b4d03d05a996514a229728aee2de8a2faeb04b Mon Sep 17 00:00:00 2001 From: Feten Besbes Date: Mon, 12 Jan 2015 13:10:36 +0100 Subject: [PATCH 1/2] Bugg #5804: Enabled DHCP on guest WLAN does not show up in TR-69 Signed-off-by: Feten Besbes --- scripts/functions/lan_device | 51 ++++++++++++++++++++++-------------- 1 file changed, 32 insertions(+), 19 deletions(-) diff --git a/scripts/functions/lan_device b/scripts/functions/lan_device index 451f486..9be9f08 100644 --- a/scripts/functions/lan_device +++ b/scripts/functions/lan_device @@ -796,7 +796,8 @@ set_lan_dns() { get_lan_dhcp_server_configurable() { local lan_name=$1 - if [ "`$UCI_GET dhcp.$lan_name`" = "" ];then echo 0; else echo 1; fi + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name"` + if [ "$dface" = "" ];then echo 0; else echo 1; fi } set_lan_dhcp_server_configurable() { @@ -804,7 +805,8 @@ set_lan_dhcp_server_configurable() { local val="$2" val=`echo $val|tr '[A-Z]' '[a-z]'` if [ "$val" = "true" -o "$val" = "1" ]; then - if [ "`$UCI_GET dhcp.$lan_name`" = "" ];then + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name" | cut -f2 -d'.'` + if [ "$dface" = "" ];then $UCI_SET dhcp.$lan_name=dhcp $UCI_SET dhcp.$lan_name.interface=$lan_name $UCI_SET dhcp.$lan_name.start=100 @@ -812,7 +814,7 @@ set_lan_dhcp_server_configurable() { $UCI_SET dhcp.$lan_name.leasetime=12h fi elif [ "$val" = "false" -o "$val" = "0" ]; then - $UCI_SET dhcp.$lan_name= + $UCI_SET dhcp.$dface= else return fi @@ -822,21 +824,23 @@ set_lan_dhcp_server_configurable() { get_lan_dhcp_server_enable() { local lan_name=$1 - if [ "`$UCI_GET dhcp.$lan_name`" = "" ]; then + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name" | cut -f2 -d'.'` + if [ "$dface" = "" ]; then echo 0 else - if [ "`$UCI_GET dhcp.$lan_name.ignore`" = "" ]; then echo 1; else echo 0; fi + if [ "`$UCI_GET dhcp.$dface.ignore`" = "" ]; then echo 1; else echo 0; fi fi } set_lan_dhcp_server_enable() { local lan_name=$1 local val="$2" + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name" | cut -f2 -d'.'` val=`echo $val|tr '[A-Z]' '[a-z]'` if [ "$val" = "true" -o "$val" = "1" ]; then - $UCI_SET dhcp.$lan_name.ignore= + $UCI_SET dhcp.$dface.ignore= elif [ "$val" = "false" -o "$val" = "0" ]; then - $UCI_SET dhcp.$lan_name.ignore=1 + $UCI_SET dhcp.$dface.ignore=1 else return fi @@ -937,8 +941,9 @@ update_instance_landevice_dhcpstaticaddress() { get_lan_dhcp_interval_address() { local opt="$1" local nlan="$2" - local start=`$UCI_GET dhcp.$nlan.start` - local limit=`$UCI_GET dhcp.$nlan.limit` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + local start=`$UCI_GET dhcp.$dface.start` + local limit=`$UCI_GET dhcp.$dface.limit` [ "$start" = "" -o "$limit" = "" ] && return local ipaddr=`$UCI_GET network.$nlan.ipaddr` if [ "$ipaddr" = "" ]; then @@ -964,6 +969,7 @@ set_lan_dhcp_address_start() { local nlan="$1" local val="$2" local ipaddr=`$UCI_GET network.$nlan.ipaddr` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` if [ "$ipaddr" = "" ]; then json_load "$(ifstatus $nlan)" json_select "ipv4-address" @@ -985,7 +991,7 @@ set_lan_dhcp_address_start() { ipaddr=`ip_to_int $ipaddr` val=$((naddr-(mask&ipaddr))) [ $val -lt 0 ] && val=0 - `$UCI_SET dhcp.$nlan.start=$val` + `$UCI_SET dhcp.$dface.start=$val` delay_service reload "network" "1" delay_service reload "dnsmasq" "1" } @@ -993,6 +999,7 @@ set_lan_dhcp_address_start() { set_lan_dhcp_address_end() { local nlan="$1" local val="$2" + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` local start=`get_lan_dhcp_interval_address START $nlan` [ "$start" = "" ] && return start=`ip_to_int $start` @@ -1000,7 +1007,7 @@ set_lan_dhcp_address_end() { val=$((val-start)) [ $val -lt 0 ] && val=0 - `$UCI_SET dhcp.$nlan.limit=$val` + `$UCI_SET dhcp.$dface.limit=$val` delay_service reload "network" "1" delay_service reload "dnsmasq" "1" } @@ -1061,7 +1068,8 @@ set_lan_dhcp_reserved_addresses() { get_lan_dhcp_subnetmask() { local nlan="$1" - local mask=`$UCI_GET dhcp.$nlan.netmask` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + local mask=`$UCI_GET dhcp.$dface.netmask` if [ "$mask" = "" ]; then mask=`$UCI_GET network.$nlan.netmask` fi @@ -1078,7 +1086,8 @@ get_lan_dhcp_subnetmask() { set_lan_dhcp_subnetmask() { local nlan="$1" local val="$2" - $UCI_SET dhcp.$nlan.netmask=$val + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + $UCI_SET dhcp.$dface.netmask=$val delay_service reload "network" "1" delay_service restart "dnsmasq" "1" } @@ -1102,7 +1111,8 @@ set_lan_dhcp_iprouters() { get_lan_dhcp_leasetime() { local nlan="$1" - local ltime=`$UCI_GET dhcp.$nlan.leasetime` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + local ltime=`$UCI_GET dhcp.$dface.leasetime` if [ "$ltime" = "" ]; then echo -1 return @@ -1120,15 +1130,17 @@ get_lan_dhcp_leasetime() { set_lan_dhcp_leasetime() { local nlan="$1" local val="$2" + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` val=$((val/60)) - $UCI_SET dhcp.$nlan.leasetime="$val"m + $UCI_SET dhcp.$dface.leasetime="$val"m delay_service reload "network" "1" delay_service restart "dnsmasq" "1" } get_lan_dhcp_domainname() { local nlan="$1" - local dop dhcp_options=`$UCI_GET dhcp.$nlan.dhcp_option` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + local dop dhcp_options=`$UCI_GET dhcp.$dface.dhcp_option` for dop in $dhcp_options; do local dn=${dop/15,/} [ "$dn" = "$dop" ] && continue @@ -1140,13 +1152,14 @@ get_lan_dhcp_domainname() { set_lan_dhcp_domainname() { local nlan="$1" local val="$2" - local dop dhcp_options=`$UCI_GET dhcp.$nlan.dhcp_option` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($nlan\|@dhcp\[[0-9]\+\]\).interface=$nlan" | cut -f2 -d'.'` + local dop dhcp_options=`$UCI_GET dhcp.$dface.dhcp_option` for dop in $dhcp_options; do local dn=${dop/15,/} [ "$dn" = "$dop" ] && continue - $UCI_DEL_LIST dhcp.$nlan.dhcp_option=$dop + $UCI_DEL_LIST dhcp.$dface.dhcp_option=$dop done - $UCI_ADD_LIST dhcp.$nlan.dhcp_option="15,$val" + $UCI_ADD_LIST dhcp.$dface.dhcp_option="15,$val" delay_service reload "network" "1" delay_service restart "dnsmasq" "1" } From fbae825ed537b23fe311b5bbed221593354c7b61 Mon Sep 17 00:00:00 2001 From: Feten Besbes Date: Tue, 13 Jan 2015 12:49:11 +0100 Subject: [PATCH 2/2] Fix delete from dhcp configuration Signed-off-by: Feten Besbes --- scripts/functions/lan_device | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/scripts/functions/lan_device b/scripts/functions/lan_device index 9be9f08..ee1974a 100644 --- a/scripts/functions/lan_device +++ b/scripts/functions/lan_device @@ -804,8 +804,8 @@ set_lan_dhcp_server_configurable() { local lan_name=$1 local val="$2" val=`echo $val|tr '[A-Z]' '[a-z]'` + local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name" | cut -f2 -d'.'` if [ "$val" = "true" -o "$val" = "1" ]; then - local dface=`$UCI_SHOW dhcp | grep "dhcp\.\($lan_name\|@dhcp\[[0-9]\+\]\).interface=$lan_name" | cut -f2 -d'.'` if [ "$dface" = "" ];then $UCI_SET dhcp.$lan_name=dhcp $UCI_SET dhcp.$lan_name.interface=$lan_name @@ -814,7 +814,11 @@ set_lan_dhcp_server_configurable() { $UCI_SET dhcp.$lan_name.leasetime=12h fi elif [ "$val" = "false" -o "$val" = "0" ]; then - $UCI_SET dhcp.$dface= + local list=`$UCI_SHOW -X dhcp |grep "dhcp\..*\.interface=$lan_name" | cut -f2 -d'.'` + for dface in $list;do + [ "`$UCI_GET dhcp.$dface`" = "dhcp" ] && break + done + $UCI_DELETE dhcp.$dface else return fi