3 STATUS_FILE
="/tmp/dnsmasq-ip-mac.status"
5 # Script for dnsmasq lease-change hook.
6 # Maintains the above file with a IP address/MAC address pairs,
7 # one lease per line. Works with IPv4 and IPv6 leases, file is
8 # atomically updated, so no races for users of the data.
14 # ensure it always exists.
16 if [ ! -f "$STATUS_FILE" ]; then
20 if [ -n "$DNSMASQ_IAID" ]; then
21 mac
="$DNSMASQ_MAC" # IPv6
24 # worry about an add or old action when the MAC address is not known:
25 # leave any old one in place in that case.
27 if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
28 if [ -n "$mac" -o "$action" = "del" ]; then
29 sed "/^${ip//./\.} / d" "$STATUS_FILE" > "$STATUS_FILE".new
31 if [ "$action" = "add" -o "$action" = "old" ]; then
32 echo "$ip $mac" >> "$STATUS_FILE".new
34 mv "$STATUS_FILE".new
"$STATUS_FILE" # atomic update.