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

Simon Kelley simon at thekelleys.org.uk
Thu Oct 3 14:51:00 BST 2013


On 03/10/13 14:05, Nehal J Wani wrote:
>> 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.
>>
>
> I gave a try to the --dhcp-script option of dnsmasq. Following are the findings:
>
> Script used: (a little modified version of
> http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=blob_plain;f=contrib/mactable/macscript;hb=HEAD):
>
> #!/bin/bash
>
> STATUS_FILE="/var/lib/libvirt/
> dnsmasq/dnsmasq-ip-mac.status"
>
> # Script for dnsmasq lease-change hook.
> # Maintains the above file with a IP address/MAC address pairs,
> # one lease per line. Works with IPv4 and IPv6 leases, file is
> # atomically updated, so no races for users of the data.
>
> action="$1"
> mac="$2"   # IPv4
> ip="$3"
>
> expirytime="$DNSMASQ_LEASE_EXPIRES"
> hostname="$DNSMASQ_SUPPLIED_HOSTNAME"
> clientid="$DNSMASQ_CLIENT_ID"
>
> # ensure it always exists.
>
> if [ ! -f "$STATUS_FILE" ]; then
>    touch "$STATUS_FILE"
> fi
>
> if [  -n "$DNSMASQ_IAID" ]; then
>      mac="$DNSMASQ_MAC"   # IPv6
>      clientid="$2"
> fi
>
> # worry about an add or old action when the MAC address is not known:
> # leave any old one in place in that case.
>
> if [ "$action" = "add" -o "$action" = "old" -o "$action" = "del" ]; then
>    if [ -n "$mac" -o "$action" = "del" ]; then
>      sed "/^${ip//./\.} / d" "$STATUS_FILE">  "$STATUS_FILE".new
>
>      if [ "$action" = "add" -o "$action" = "old" ]; then
>         echo "$expirytime $mac $ip $hostname $clientid">>  "$STATUS_FILE".new
>      fi
>      mv  "$STATUS_FILE".new "$STATUS_FILE" # atomic update.
>    fi
> fi
>
>
>
> Changes made to libvirt code:
>
> diff --git a/src/network/bridge_driver.c b/src/network/bridge_driver.c
> index 8787bdb..7f9a74f 100644
> --- a/src/network/bridge_driver.c
> +++ b/src/network/bridge_driver.c
> @@ -1058,6 +1058,7 @@
> networkBuildDhcpDaemonCommandLine(virNetworkObjPtr network,
>
>       cmd = virCommandNew(dnsmasqCapsGetBinaryPath(caps));
>       virCommandAddArgFormat(cmd, "--conf-file=%s", configfile);
> +    virCommandAddArgFormat(cmd, "--dhcp-script=%s",
> "/var/lib/libvirt/dnsmasq/macscript.sh");
>       *cmdout = cmd;
>       ret = 0;
>   cleanup:
>
>
> In dnsmasq version 2.65 (latest on f18 repos), useful variables that were set:
> In the case of ipv4:
> $1=add $2=52:54:00:95:41:5d $3=192.168.100.128
> DNSMASQ_INTERFACE=virbr0
> DNSMASQ_TAGS=virbr0
> DNSMASQ_TIME_REMAINING=3600
> DNSMASQ_LEASE_EXPIRES=1380745674
>
> In the case of ipv6:
> $1=add $2=00:01:00:01:19:df:2e:19:52:54:00:24:13:15 $3=2001:db8:ca2:2:1::45
> DNSMASQ_INTERFACE=virbr3
> DNSMASQ_TAGS=dhcpv6 virbr3
> DNSMASQ_SERVER_DUID=00:01:00:01:19:df:29:7e:f0:4d:a2:8c:14:51
> DNSMASQ_IAID=2364181
> DNSMASQ_TIME_REMAINING=3600
> DNSMASQ_LEASE_EXPIRES=1380745131
>
>
> In the latest dnsmasq version 2.67rc2-3-g889d8a1 (built after cloning
> from git://thekelleys.org.uk/dnsmasq.git), useful variables that were
> set:
> In the case of ipv4:
> add 52:54:00:1a:a1:55 192.168.100.204
> DNSMASQ_INTERFACE=virbr0
> DNSMASQ_LEASE_EXPIRES=1380749702
> DNSMASQ_TAGS=virbr0
> DNSMASQ_TIME_REMAINING=3600
>
>
> In the case of ipv6:
> add 00:01:00:01:19:df:3a:8e:52:54:00:7d:49:25 2001:db8:ca2:2:1::f5
> DNSMASQ_IAID=8210725
> DNSMASQ_INTERFACE=virbr3
> DNSMASQ_LEASE_EXPIRES=1380748320
> DNSMASQ_MAC=52:54:00:7d:49:25
> DNSMASQ_SERVER_DUID=
> DNSMASQ_TAGS=dhcpv6 virbr3
> DNSMASQ_TIME_REMAINING=3600
>
>
> So, in case of latest dnsmasq code, output in dnsmasq-ip-mac.status:
> 1380747917 52:54:00:82:5e:09 2001:db8:ca2:2:1::79
> 1380747943 52:54:00:61:bd:d8 2001:db8:ca2:2:1::88
> 1380748110 52:54:00:15:1e:05 192.168.100.180
> 1380748320 52:54:00:7d:49:25 2001:db8:ca2:2:1::f5
> 00:01:00:01:19:df:3a:8e:52:54:00:7d:49:25
> 1380749702 52:54:00:1a:a1:55 192.168.100.204
> 1380749877 52:54:00:73:0a:27 192.168.100.190
> 1380749879 52:54:00:b7:87:3e 2001:db8:ca2:2:1::3e
> 00:01:00:01:19:df:40:a6:52:54:00:b7:87:3e
> 1380749880 52:54:00:bc:55:df 2001:db8:ca2:2:1::8f
> 00:01:00:01:19:df:40:a6:52:54:00:bc:55:df
> 1380749880 52:54:00:b7:87:3e 2001:db8:ca2:2:1::3e
> 00:01:00:01:19:df:40:a6:52:54:00:b7:87:3e
>
>
> Apologies for the long message.
>
> Queries:
> (i) Why is DNSMASQ_SERVER_DUID blank in case of ipv6 (dnsmasq
> 2.67rc2-3-g889d8a1) ? Is it an issue with libvirt code or dnsmasq?

I don't know. It's working fine for me in a fairly standard dnsmasq 
installation, which is some evidence that it's a libvirt thing, but not 
strong evidence. On the other hand, the code that deals with that has 
been touched, so the difference between 2.65 and the latest code is 
suspicious. I'd be interested in any clues you can find about what's 
going on.

> (ii) When will be dnsmasq version 2.67rc2-3-g889d8a1 be out as tarball
> and when will it be available in the fedora repositories? (I don't
> know who maintains the package buildings, but a tentative date would
> be fine)
>

You can get a tarball of any state of the git repository, including the 
latest, from http://thekelleys.org.uk/gitweb/?p=dnsmasq.git;a=summary
The "snapshot" links on the right allow you to download tarballs.


dnsmasq-2.67 is in the process of release. I anticipate a final release 
soon, probably later next week.


Cheers,

Simon.





More information about the Dnsmasq-discuss mailing list