[Dnsmasq-discuss] Reg: Info related to leases file

Lonnie Abelbeck lists at lonnie.abelbeck.com
Fri Sep 27 14:53:36 BST 2013


On Sep 27, 2013, at 6:51 AM, Simon Kelley wrote:
> 
> There's one change which needs to be made to the script. When dnsmasq is restarted, it won't know the MAC addresses for DHCPv6 (because they're not in the leasefile). So at start-up it  will execute "old" script runs on each lease without the DNSMASQ_MAC environment variable set. The script needs to detect when called with "old" and no DNSMASQ_MAC and not delete the relevant line from its file.

Hi Simon,

Does this do what you want ?

=============================
#!/bin/bash

action="$1"
mac="$2"   # IPv4
ip="$3"

STATUS_FILE="/tmp/dnsmasq-ip-mac.status"

if [ -n "$DNSMASQ_IAID" ]; then
  mac="$DNSMASQ_MAC"   # IPv6
fi

if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
  if [ -n "$ip" ]; then
    if [ -n "$mac" -o "$action" = "del" ]; then
      if [ -f "$STATUS_FILE" ]; then
        sed -i "/^${ip//./\.} / d" "$STATUS_FILE"
      fi
      if [ "$action" = "add" -o "$action" = "old" ]; then
        echo "$ip $mac" >> "$STATUS_FILE"
      fi
    fi
  fi
fi
=============================

Lonnie




More information about the Dnsmasq-discuss mailing list