> > So we can get the MAC addr if we use the '--dhcp-script' parameter to > make dnsmasq invoke a helper program we create, to save the lease > details we need. > > > Incidentally, I see our XML format is actually wrong, because it says > the 'mac' attribute is forbidden for <host> elements using IPv6. dnsmasq > actually allows you to specify either mac addr or IAID identifiers for > IPv6 dhcp host entries. > 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 So, I think it is OK to parse the custom generated file: dnsmasq-ip-mac.status (after deciding its exact format). But the only issue right now is that the variable DNSMASQ_MAC for DHCPv6 is set only in the case of latest dnsmasq code (I don't think it is even available in the tarballs yet) -- Nehal J Wani -- libvir-list mailing list libvir-list@xxxxxxxxxx https://www.redhat.com/mailman/listinfo/libvir-list