dnsmasq: daemon->icmp6fd is always valid when doing DHCPv6 now.
[tomato.git] / release / src / router / dnsmasq / contrib / mactable / macscript
blob44a447727fee3e33691f6ebaa23466c3bd3c5ff5
1 #!/bin/bash
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.
10 action="$1"
11 mac="$2" # IPv4
12 ip="$3"
14 # ensure it always exists.
16 if [ ! -f "$STATUS_FILE" ]; then
17 touch "$STATUS_FILE"
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.