118 lines
4.0 KiB
Bash
Executable File
118 lines
4.0 KiB
Bash
Executable File
#!/bin/sh
|
|
|
|
[ ${DHCPCLIENT_LIB:-0} = 1 ] && return
|
|
|
|
DHCPCLIENT_LIB=1
|
|
|
|
dhcpclient_config_wan() {
|
|
local cmdline_args
|
|
|
|
local ifname=`cat $WAND/$WANID/ifname`
|
|
local macaddr=`cat $INTFD/$ifname/macaddr`
|
|
|
|
cmdline_args="-t 6 -A 60"
|
|
|
|
local discoverytimeout; eval discoverytimeout=\${$wandev'_WANIPConnection_DHCPDiscoveryTimeout':-5}
|
|
cmdline_args="$cmdline_args -T $discoverytimeout"
|
|
|
|
# DHCP option 12 (hostname)
|
|
local opthn; eval opthn=\${$wandev'_WANIPConnection_DHCPHostname'}
|
|
if [ "$opthn" != '' ]; then
|
|
cmdline_args="$cmdline_args -H \"$opthn\""
|
|
fi
|
|
|
|
# Activate DHCP option 43 (Vendor Class)
|
|
local optclid; eval optclid=\${$wandev'_WANIPConnection_DHCPVendorClass'}
|
|
if [ "$optclid" != '' ]; then
|
|
cmdline_args="$cmdline_args -V \"$optclid\""
|
|
fi
|
|
echo $optclid | grep -e dslforum.org >/dev/null
|
|
if [ $? = 0 ]; then
|
|
touch $WAND/$WANID/ip/dhcp43
|
|
else
|
|
rm -f $WAND/$WANID/ip/dhcp43
|
|
fi
|
|
|
|
# DHCP keepalive with arp pings to the gateway
|
|
local katm; eval katm=\${$wandev'_WANIPConnection_ARPIntervalTimer'}
|
|
local kact; eval kact=\${$wandev'_WANIPConnection_ARPFailureCount'}
|
|
local kaint=''
|
|
local kacnt=''
|
|
if [ "$katm" != '' ] && [ "$katm" -gt 0 ] && [ "$kact" != '' ] && [ "$kact" -gt 0 ]; then
|
|
cmdline_args="$cmdline_args -g $katm -G $kact"
|
|
fi
|
|
|
|
local nodefreq; eval nodefreq=\${$wandev'_WANIPConnection_NoDefaultReqOpt':-0}
|
|
if [ "$nodefreq" = 1 ]; then
|
|
cmdline_args="$cmdline_args -o"
|
|
else
|
|
# DHCP requested options by default are : subnet, router, dns, hostname, domain, and broadcast
|
|
cmdline_args="$cmdline_args -O lease"
|
|
# TODO : Manage renewal and rebinding times
|
|
# cmdline_args="$cmdline_args -O renewal"
|
|
# cmdline_args="$cmdline_args -O rebinding"
|
|
|
|
# DHCP Vendor Class (60) dslforum.org asks for DHCP options 43 (vendor-encapsulated-options)
|
|
if [ -f $WAND/$WANID/ip/dhcp43 ]; then
|
|
cmdline_args="$cmdline_args -O vendorspecific"
|
|
fi
|
|
fi
|
|
|
|
# Additional custom options
|
|
local opts; eval opts=\${$wandev'_WANIPConnection_DHCPCustomOption_List'}
|
|
local opt
|
|
for opt in `strip $opts`; do
|
|
local en; eval en=\${$wandev'_WANIPConnection_DHCPCustomOption_'$opt'_Enable'}
|
|
[ "$en" != 1 ] && continue
|
|
local copt; eval copt=\${$wandev'_WANIPConnection_DHCPCustomOption_'$opt'_Option'}
|
|
local clid="$(echo $copt | cut -d: -f1)"
|
|
if [ "$clid" = 'clientid' ]; then
|
|
local value="$(echo $copt | cut -d: -f2)"
|
|
cmdline_args="$cmdline_args -c \"$value\""
|
|
else
|
|
cmdline_args="$cmdline_args -x \"$copt\""
|
|
fi
|
|
done
|
|
|
|
# Additional requested options
|
|
eval opts=\${$wandev'_WANIPConnection_DHCPRequestedOptions'}
|
|
for opt in `strip $opts`; do
|
|
cmdline_args="$cmdline_args -O $opt"
|
|
done
|
|
|
|
local dbg; eval dbg=\${$wandev'_WANIPConnection_Debug':-0}
|
|
[ "$dbg" != 0 ] && cmdline_args="$cmdline_args -v"
|
|
|
|
echo "$cmdline_args" >$DHCPCLIENTD/$ifname
|
|
}
|
|
|
|
dhcpclient_config_lan() {
|
|
# Optional options can be added in user scripts
|
|
local ifname=`cat $LAND/$LANID/ifname`
|
|
local cmdline_args=""
|
|
|
|
local failuretimeout; eval failuretimeout=\${$landev'_DHCPClientOptions_FailureTimeout':-60}
|
|
cmdline_args="$cmdline_args -A $failuretimeout"
|
|
|
|
local retries; eval retries=\${$landev'_DHCPClientOptions_RetriesCount':-}
|
|
if [ "$retries" != "" ]; then
|
|
cmdline_args="$cmdline_args -t $retries"
|
|
fi
|
|
|
|
local discoverytimeout; eval discoverytimeout=\${$landev'_DHCPClientOptions_DiscoveryTimeout':-}
|
|
if [ "$discoverytimeout" != "" ]; then
|
|
cmdline_args="$cmdline_args -T $discoverytimeout"
|
|
fi
|
|
|
|
# Activate DHCP option 60 (Vendor Class)
|
|
local vendorclass; eval vendorclass=\${$landev'_DHCPClientOptions_VendorClass':-}
|
|
if [ "$vendorclass" != '' ]; then
|
|
cmdline_args="$cmdline_args -V \"$vendorclass\""
|
|
fi
|
|
|
|
local dbg; eval dbg=\${$landev'_DHCPv4_Debug':-0}
|
|
[ "$dbg" != 0 ] && cmdline_args="$cmdline_args -v"
|
|
|
|
echo "$cmdline_args" >$DHCPCLIENTD/$ifname
|
|
}
|