diff options
author | Simon Kelley <simon@thekelleys.org.uk> | 2013-09-27 14:38:45 +0100 |
---|---|---|
committer | Simon Kelley <simon@thekelleys.org.uk> | 2013-09-27 14:38:45 +0100 |
commit | 42b44a591b95d5cfc066f103888b974b1187ee3f (patch) | |
tree | a1c2e1725c3c9cf524bc2d701be7b6d1161d2ff9 /contrib | |
parent | a810559b243560d26a9ccde7330aadafeb7d4cbe (diff) | |
download | dnsmasq-42b44a591b95d5cfc066f103888b974b1187ee3f.tar.gz |
Add contrib/mactable
Diffstat (limited to 'contrib')
-rwxr-xr-x | contrib/mactable/macscript | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/contrib/mactable/macscript b/contrib/mactable/macscript new file mode 100755 index 0000000..8d807c5 --- /dev/null +++ b/contrib/mactable/macscript @@ -0,0 +1,30 @@ +#!/bin/bash + +STATUS_FILE="/tmp/dnsmasq-ip-mac.status" + +# Script for dnsmasq lease-change hook. +# Maintains the above file with a IP address/MAC address pairs, +# one lease per line. Works with IPv4 and IPv6 leases, file is +# atomically updated, so no races for users of the data. + +action="$1" +mac="$2" # IPv4 +ip="$3" + +if [ -n "$DNSMASQ_IAID" ]; then + if [ -z "$DNSMASQ_MAC" -a "$action" = "old" ]; then + # MAC not known by dnsmasq, probably due to restart. + exit 0; + fi + mac="$DNSMASQ_MAC" # IPv6 +fi + +if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then + if [ -f "$STATUS_FILE" ]; then + sed "/^${ip//./\.} / d" "$STATUS_FILE" > "$STATUS_FILE".new + fi + if [ "$action" = "add" -o "$action" = "old" ]; then + echo "$ip $mac" >> "$STATUS_FILE".new + fi + mv "$STATUS_FILE".new "$STATUS_FILE" # atomic update. +fi |