summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorDaniil Baturin <daniil@baturin.org>2019-09-30 19:19:26 +0700
committerGitHub <noreply@github.com>2019-09-30 19:19:26 +0700
commit0df4e2c4133b9cb623ef881bfa697da6d5324f2d (patch)
tree30db320d5af800dc4d1fb7d4db8619aaf36b39bf /src
parent75020e248bcea9759eac5e9ef3769dddad704787 (diff)
parenta1ed1bf1db1eb23455a3555a6fc0842104efdeb6 (diff)
downloadvyos-1x-0df4e2c4133b9cb623ef881bfa697da6d5324f2d.tar.gz
vyos-1x-0df4e2c4133b9cb623ef881bfa697da6d5324f2d.zip
Merge pull request #137 from DmitriyEshenko/hostname-dhcp
[dhcp hostfile-update] T1678 migrate to vyos-hostsd-client
Diffstat (limited to 'src')
-rwxr-xr-xsrc/system/on-dhcp-event.sh42
1 files changed, 5 insertions, 37 deletions
diff --git a/src/system/on-dhcp-event.sh b/src/system/on-dhcp-event.sh
index 02bbd4c3c..70a563d4c 100755
--- a/src/system/on-dhcp-event.sh
+++ b/src/system/on-dhcp-event.sh
@@ -37,50 +37,18 @@ fi
case "$action" in
commit) # add mapping for new lease
- echo "- new lease event, setting static mapping for host "\
- "$client_fqdn_name (MAC=$client_mac, IP=$client_ip)"
- #
- # grep fails miserably with \t in the search expression.
- # In the following line one <Ctrl-V> <TAB> is used after $client_search_expr
- # followed by a single space
- grep -q " $client_search_expr #on-dhcp-event " $file
- if [ $? == 0 ]; then
- echo pattern found, removing
- wc1=`cat $file | wc -l`
- sudo sed -i "/ $client_search_expr\t #on-dhcp-event /d" $file
- wc2=`cat $file | wc -l`
- if [ "$wc1" -eq "$wc2" ]; then
- echo No change
- fi
- else
- echo pattern NOT found
- fi
-
- # check if hostname already exists (e.g. a static host mapping)
- # if so don't overwrite
- grep -q " $client_search_expr " $file
+ grep -q " $client_search_expr " $file
if [ $? == 0 ]; then
echo host $client_fqdn_name already exists, exiting
exit 1
fi
-
- line="$client_ip\t $client_fqdn_name\t #on-dhcp-event $client_mac"
- sudo sh -c "echo -e '$line' >> $file"
- ((changes++))
- echo Entry was added
+ # add host
+ /usr/bin/vyos-hostsd-client --add-hosts --tag "DHCP-$client_ip" --host "$client_fqdn_name,$client_ip"
;;
release) # delete mapping for released address
- echo "- lease release event, deleting static mapping for host $client_fqdn_name"
- wc1=`cat $file | wc -l`
- sudo sed -i "/ $client_search_expr\t #on-dhcp-event /d" $file
- wc2=`cat $file | wc -l`
- if [ "$wc1" -eq "$wc2" ]; then
- echo No change
- else
- echo Entry was removed
- ((changes++))
- fi
+ # delete host
+ /usr/bin/vyos-hostsd-client --delete-hosts --tag "DHCP-$client_ip"
;;
*)