On 30/06/14 10:39, Nehal J Wani wrote:
> Hi!
> 
> The man page of dnsmasq (under the section "-9, --leasefile-ro"), states:
> When called like this the script should write the saved state of the
> lease database, in dnsmasq leasefile format, to stdout and exit with
> zero exit code.
> 
> Q1. What is the purpose of printing to stdout? I guess it is for
> dnsmasq to know the information of previous leases, but I am not sure.


Exactly that. Dnsmasq keeps a working copy of the lease database in
memory, and it calls the lease script whenever this changes so that the
lease-script can maintain the external copy in whatever non-volatile
storage it wants (a database, disk file, NVRAM, etc). When dnsmasq first
starts it has to copy the state of the lease database from the
non-volatile storage to the in-memory copy. It does this by running the
lease-script with the "init" method and the lease-script should dump the
contents of the database. The reason the format is exactly the same as
the lease-file and to stdout is that the whole thing can be done simply
by replacing 'fopen(leasefile)' with 'popen(lease-script, "init")', the
rest of the code is unchanged.

> Q2. What all information do I need to print in 'dnsmasq leasefile
> format' ? What is the exact format? Is there an example for this (like
> the example file macscript)?

The file starts with IPv4 leases, one per line. There are five fields on
each line, seperated by spaces.

Expiry time - decimal number, seconds since start of epoch

MAC address - a hex "ARP type", followed by '-' followed by zero to 16
hex bytes, separated by ':'. If the ARP type is 1, for ethernet (this is
most common) then the ARP type is skipped, UNLESS the MAC address in
zero length. So

99-00:11:22:33:44:55:66:77:88:99:aa:bb:cc:dd:ee:ff
01-
00:11:22:33:44:55

are valid strings.

IP address in dotted-quad format.

Hostname, as specified in RFC 1123, para 2.1, or '*' if no hostname known.

Client-id, up to 255 hex bytes separated by ':', or * if no client-id
known.


Next, if DHCPv6 is in use there may be a single line

duid 00:11:22:33

which records the DUID used by the server. Max length of a duid is not
specified in the standards, I think. dnsmasq limits it to 85 bytes. The
longest defined DUID format is currently about 28 bytes, I think.

If the duid line exists, then it will be followed by the DHCPv6 leases,
one per line, five fields as for IPv4. The fields are different.

Expiry time - same definition as for IPv4.

IP address - in standard hex-and-colons format

IAID Unsigned 32-bit decimal number, possibly preceded by "T" for a
temporary lease.

Hostname - same as IPv4

Client DUID - same representation as IPv4 client-ID.


> Q3. Apart from the leases, dnsmasq also prints some extra information
> like "duid 00:01:00:01:1b:40:8d:94:00:25:64:8b:e4:2c" in the lease
> file. Is this also mandatory to print to stdout in case I use
> leasefile-ro ?

If you don't want to support DHCPv6, then you don't need the duid and
the DHCPv6 lease format. It would be a pity not to support DHPCv6 though.



Cheers,

Simon.

> 
> Thanking You,

Happy to help with any of this.


> Nehal J Wani
> 


_______________________________________________
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss

Reply via email to