File:  [ELWIX - Embedded LightWeight unIX -] / embedaddon / dnsmasq / contrib / mactable / macscript
Revision 1.1.1.2 (vendor branch): download - view: text, annotated - select for diffs - revision graph
Wed Mar 17 00:56:46 2021 UTC (3 years, 4 months ago) by misho
Branches: elwix, dnsmasq, MAIN
CVS tags: v8_2p1, v2_84, HEAD
dnsmasq 2.84

    1: #!/bin/bash
    2: 
    3: STATUS_FILE="/tmp/dnsmasq-ip-mac.status"
    4: 
    5: # Script for dnsmasq lease-change hook.
    6: # Maintains the above file with an 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.
    9: 
   10: action="$1"
   11: mac="$2"   # IPv4
   12: ip="$3"
   13: 
   14: # ensure it always exists.
   15: 
   16: if [ ! -f "$STATUS_FILE" ]; then
   17:   touch "$STATUS_FILE"
   18: fi
   19: 
   20: if [  -n "$DNSMASQ_IAID" ]; then
   21:     mac="$DNSMASQ_MAC"   # IPv6
   22: fi
   23: 
   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.
   26: 
   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
   30:   
   31:     if [ "$action" = "add" -o "$action" = "old" ]; then
   32:        echo "$ip $mac" >> "$STATUS_FILE".new
   33:     fi
   34:     mv  "$STATUS_FILE".new "$STATUS_FILE" # atomic update.
   35:   fi
   36: fi

FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>