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

Simon Kelley simon at thekelleys.org.uk
Fri Sep 27 15:10:47 BST 2013


On 27/09/13 14:53, Lonnie Abelbeck wrote:
>
> 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
>
>


Yes. I just added contrib/mactable/macscript to the git repo, which is 
your previous script slightly less elegantly modified by me for this 
circumstance. I also put back the "make new file then atomically rename" 
behaviour since that means anything using this file doesn't risk a race 
condition leading to a half-written file.


Cheers,

Simon.




More information about the Dnsmasq-discuss mailing list