1
0
This repository has been archived on 2025-01-10. You can view files and clone it. You cannot open issues or pull requests or push a commit.
Files
Anderson Luiz Alves 0464e230c1 stock 103961
2017-07-30 16:48:04 -03:00

132 lines
3.8 KiB
Bash
Executable File

#!/bin/sh
[ ${DHCP6SERVER_LIB:-0} = 1 ] && return
DHCP6SERVER_LIB=1
dhcp6server_config_wan() {
echo " " >$DHCP6D/${ifname}.conf
}
dhcp6server_config_lan() {
local dhcpconf=$landev'_HostConfig6_DHCPServer'
local pltime; eval pltime=\${$dhcpconf'_PreferredTime':-}
local vltime; eval vltime=\${$dhcpconf'_ValidTime':-}
[ "$pltime" = '' ] && pltime=86400
[ "$vltime" = '' ] && vltime=$pltime
# Now, both pltime and vltime are ints
# Ensure that pltime <= vltime even if one is 0
[ "$pltime" = '0' ] || [ "$vltime" != '0' -a "$vltime" -lt "$pltime" ] && vltime=$pltime
# 0 => infinity
[ "$pltime" = '0' ] && pltime='infinity'
[ "$vltime" = '0' ] && vltime='infinity'
cat >$DHCP6D/${ifname}.conf <<EOF
interface $ifname {
EOF
local min; eval min=\${$dhcpconf'_MinAddress'}
local max; eval max=\${$dhcpconf'_MaxAddress'}
if [ "${prefix:-}" != '' -a "$min" != '' -a "$max" != '' ]; then
local addrmin=`addipv6addr ${prefix%%/*} $min`
local addrmax=`addipv6addr ${prefix%%/*} $max`
if [ "$addrmin" != '' -a "$addrmax" != '' ]; then
cat >>$DHCP6D/${ifname}.conf <<EOF
address-pool lanpool $pltime $vltime;
};
pool lanpool {
range $addrmin to $addrmax;
EOF
fi
fi
cat >>$DHCP6D/${ifname}.conf <<EOF
};
EOF
#local routers; eval routers=\${$dhcpconf'_IPRouters'}
local dnsen; eval dnsen=\${$dhcpconf'_DNS_Enable':-1}
if [ "$dnsen" = 1 ]; then
local servers; eval servers=\${$dhcpconf'_DNS_Servers'}
local proxy; eval proxy=\${$dhcpconf'_DNS_Proxy':-0}
local domain; eval domain=\${$dhcpconf'_DomainName'}
#[ "$routers" = '' ] && routers=$ipaddr
if [ "$proxy" != 1 ]; then
[ "$servers" = '' ] && [ -f $LAND/$LANID/ip6/servers ] && servers=`cat $LAND/$LANID/ip6/servers`
[ "$servers" = '' ] && servers=$lladdr
else
servers=$lladdr
fi
[ "$domain" = '' ] && domain=$Device_Domain
cat >>$DHCP6D/${ifname}.conf <<EOF
option domain-name-servers $servers;
option domain-name "$domain";
EOF
fi
local list; eval list=\${$dhcpconf'_Options_List'}
for i in `strip $list`; do
local en; eval en=\${$dhcpconf'_Options_'$i'_Enable'}
[ "$en" != 1 ] && continue
local name; eval name=\${$dhcpconf'_Options_'$i'_Name'}
local force; eval force=\${$dhcpconf'_Options_'$i'_Forced':-0}
local option=$name
local alpha="`echo $name | tr -d 0-9`"
if [ "$alpha" = '' ]; then
option="opt-num $name"
fi
local value; eval value=\${$dhcpconf'_Options_'$i'_Value'}
if [ "$force" = 0 ]; then
cat >>$DHCP6D/${ifname}.conf <<EOF
option $option "$value";
EOF
else
cat >>$DHCP6D/${ifname}.conf <<EOF
force option $option "$value";
EOF
fi
done
local useren; eval useren=\${$dhcpconf'_UserEnable':-1}
eval list=\${$dhcpconf'_ClientTable_List'}
for i in `strip $list`; do
local host; eval host=\${$dhcpconf'_ClientTable_'$i'_Hostname':-}
local mac; eval mac=\${$dhcpconf'_ClientTable_'$i'_MACAddress':-}
local ip; eval ip=\${$dhcpconf'_ClientTable_'$i'_IPAddress':-}
local prefix; eval prefix=\${$dhcpconf'_ClientTable_'$i'_Prefix':-}/\${$dhcpconf'_ClientTable_'$i'_PrefixLen':-128}
[ "$host" = '' ] || [ "$mac" = '' ] && continue
local user; eval user=\${$dhcpconf'_ClientTable_'$i'_User'}
# If user configuration has been disabled, then skip all User entries
[ "$useren" = 0 ] && [ "$user" != 0 ] && continue
cat >>$DHCP6D/${ifname}.conf <<EOF
host $host {
duid $mac;
EOF
# TODO: what happens if ip contains a prefix and delegated prefix changed ?
ip=`addipv6addr ${prefix%%/*} $ip`
[ "$ip" != '' ] && cat >>$DHCP6D/${ifname}.conf <<EOF
address $ip $pltime $vltime;
EOF
[ "$prefix" != '/128' ] && cat >>$DHCP6D/${ifname}.conf <<EOF
prefix $prefix $pltime $vltime;
EOF
cat >>$DHCP6D/${ifname}.conf <<EOF
};
EOF
done
create_duid $ifname $DHCP6D/${ifname}.duid
}