Merge Lean's source

This commit is contained in:
CN_SZTL 2020-02-15 00:03:49 +08:00
commit 6d9691e1a6
No known key found for this signature in database
GPG Key ID: 6850B6345C862176

View File

@ -19,7 +19,7 @@ BASEDHCPSTAMPFILE="/var/run/dnsmasq"
DHCPBOGUSHOSTNAMEFILE="/usr/share/dnsmasq/dhcpbogushostname.conf"
RFC6761FILE="/usr/share/dnsmasq/rfc6761.conf"
DHCPSCRIPT="/usr/lib/dnsmasq/dhcp-script.sh"
CONFIGFILE_COMMENTS="/tmp/dhcp_comments.conf"
DNSMASQ_DHCP_VER=4
xappend() {
@ -28,6 +28,12 @@ xappend() {
echo "${value#--}" >> $CONFIGFILE_TMP
}
cappend() {
local value="$1"
echo "${value#--}" >> $CONFIGFILE_COMMENTS
}
hex_to_hostid() {
local var="$1"
local hex="${2#0x}" # strip optional "0x" prefix
@ -277,7 +283,8 @@ dhcp_match_add() {
dhcp_host_add() {
local cfg="$1"
local hosttag nametime addrs duids macs tags
local hosttag nametime addrs duids macs tags
local comment_mac comment_ip
config_get_bool force "$cfg" force 0
@ -288,10 +295,17 @@ dhcp_host_add() {
[ "$enable" = "0" ] && return 0
config_get name "$cfg" name
config_get comments "$cfg" comments
config_get ip "$cfg" ip
config_get hostid "$cfg" hostid
[ -n "$ip" -o -n "$name" -o -n "$hostid" ] || return 0
if [ -z "$ip" -a -z "$name" -a -z "$hostid" ]; then
[ -n "$comments" ] || return 0
config_get mac "$cfg" mac
[ -n "$ip" ] || ip="-"
cappend "$comments $mac $ip"
return 0
fi
config_get_bool dns "$cfg" dns 0
[ "$dns" = "1" -a -n "$ip" -a -n "$name" ] && {
@ -307,6 +321,7 @@ dhcp_host_add() {
# many MAC are possible to track a laptop ON/OFF dock
for m in $mac; do append macs "$m" ","; done
fi
if [ $DNSMASQ_DHCP_VER -eq 6 -a -n "$duid" ]; then
# --dhcp-host=id:00:03:00:01:12:00:00:01:02:03,[::beef],lap
@ -336,12 +351,27 @@ dhcp_host_add() {
hosttag="${networkid:+,set:${networkid}}${tags:+,set:${tags}}$broadcast"
nametime="${name:+,$name}${leasetime:+,$leasetime}"
[ -n "$comments" ] || comments="-"
if [ -n "$macs" ]; then
comment_mac=$mac
else
comment_mac="-"
fi
if [ -n "$ip" ]; then
comment_ip=${ip:+$ip}
else
comment_ip="-"
fi
if [ $DNSMASQ_DHCP_VER -eq 6 ]; then
addrs="${ip:+,$ip}${hostid:+,[::$hostid]}"
xappend "--dhcp-host=$macs${duids:+,$duids}$hosttag$addrs$nametime"
else
xappend "--dhcp-host=$macs$hosttag${ip:+,$ip}$nametime"
cappend "$comments $comment_mac $comment_ip"
fi
}
@ -753,6 +783,7 @@ dnsmasq_start()
chown dnsmasq:dnsmasq /var/run/dnsmasq
echo "# auto-generated config file from /etc/config/dhcp" > $CONFIGFILE_TMP
rm $CONFIGFILE_COMMENTS
echo "# auto-generated config file from /etc/config/dhcp" > $HOSTFILE_TMP
local dnsmasqconffile="/etc/dnsmasq.${cfg}.conf"