Re: [Dnsmasq-discuss] Query regarding --leasefile-ro
On 01/07/14 13:33, Nehal J Wani wrote: >> That looks sensible. I guess from these questions that you're thinking >> about storing the lease database just in the custom format, and using >> --leasefile-ro > > Right now, libvirt stores all leases for each interface in separate > files. That is, one lease database per dnsmasq instance, it does so, > on the basis of the environment variable DNSMASQ_INTERFACE (I know > that it is not set in case of del events everytime). The trouble is, > when it gets the argument 'init', how will my helper program know > which database it has to read and print to stdout? Suppose if we have > only one lease database for all dnsmasq instances, how will the leases > helper program distinguish between different interfaces (that is, for > which interface should I print info, if I get 'init' as argument)? How > does it happen by default, when none of --dhcp-script and > --leasefile-ro are provided? > The default method has only one instance of dnsmasq handling multiple instances, and the interface associated with a lease isn't really important information, that's handled by looking at subnets and such. I think libvirt spins up a dnsmasq instance for each virtual interface. Is that correct? If so you need to keep the lease databases for each instance separate. The most obvious nasty hack to make this work would be to have a set of filesystem links to the real lease-change script, each with a different name, and configure each dnsmasq to call a unique link. The script then checks argv[0] to find the name it was called by and then transforms that into the name of the corresponding database file. So we have something like scripts/interface1 is a link to /lib/libvirt/lease-change-script scripts/interface2 is a link to /lib/libvirt/lease-change-script and start dnsmasq with dnsmasq --interface=interface1 --dhcp-script=scripts/interface1 and the script finds the basename of argv[0[: scripts/interface1 -> interface1 and prepends the directory where the lease files are interface1 ->leasefiles/interface1 That works in the absence on the DNSMASQ_INTERFACE variable. Cheers, Simon. ___ Dnsmasq-discuss mailing list Dnsmasq-discuss@lists.thekelleys.org.uk http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Re: [Dnsmasq-discuss] Query regarding --leasefile-ro
> That looks sensible. I guess from these questions that you're thinking > about storing the lease database just in the custom format, and using > --leasefile-ro Right now, libvirt stores all leases for each interface in separate files. That is, one lease database per dnsmasq instance, it does so, on the basis of the environment variable DNSMASQ_INTERFACE (I know that it is not set in case of del events everytime). The trouble is, when it gets the argument 'init', how will my helper program know which database it has to read and print to stdout? Suppose if we have only one lease database for all dnsmasq instances, how will the leases helper program distinguish between different interfaces (that is, for which interface should I print info, if I get 'init' as argument)? How does it happen by default, when none of --dhcp-script and --leasefile-ro are provided? Thanking You, Nehal J Wani ___ Dnsmasq-discuss mailing list Dnsmasq-discuss@lists.thekelleys.org.uk http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Re: [Dnsmasq-discuss] Query regarding --leasefile-ro
On 30/06/14 20:46, Nehal J Wani wrote: > On Tue, Jul 1, 2014 at 12:27 AM, Simon Kelley wrote: >> 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. >> > > That explains almost everything. > Yes, libvirt wants to support DHCPv6. Right now, the leases helper > program of ours takes in whatever useful information is available and > dumps it to a JSON formatted database. > > Example of our custom leases file content: > [ > { > "iaid": "1221229", > "ip-address": "2001:db8:ca2:2:1::95", > "mac-address": "52:54:00:12:a2:6d", > "hostname": "Fedora20", > "client-id": > "00:04:1a:c1:d9:6b:5a:0a:e2:bc:f8:4b:1e:37:2e:38:22:55" > , > "expiry-time": 1393244216 > }, > { > "ip-address": "192.168.150.208", > "mac-address": "52:54:00:11:56:b3", > "hostname": "Wani-PC", > "client-id": "01:52:54:00:11:56:b3", > "expiry-time": 1393244248 > } > ] > > Q1. The libvirt leases helper script/program takes in whatever > variable value it receives and stores it unmodified. So, my question > is, is it safe to just print the content of each lease in the > field-format that you specified just by copying these values which I > received earlier as either argument or environment variable (so that > my code doesn't have to worry about the details about ARP type, etc)? Yes, completely. The only think you have to worry about the distinction between ipv4 and ipv6 leases. The second field of a lease line can is either the MAC address (IPv4) or the IAID, so you need to copy either argv[2] or the contents of $DNSMASQ_IAID there, depending on the flavour of the lease. Similary, the fifth field is either the client-id for I
Re: [Dnsmasq-discuss] Query regarding --leasefile-ro
On Tue, Jul 1, 2014 at 12:27 AM, Simon Kelley wrote: > 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. > That explains almost everything. Yes, libvirt wants to support DHCPv6. Right now, the leases helper program of ours takes in whatever useful information is available and dumps it to a JSON formatted database. Example of our custom leases file content: [ { "iaid": "1221229", "ip-address": "2001:db8:ca2:2:1::95", "mac-address": "52:54:00:12:a2:6d", "hostname": "Fedora20", "client-id": "00:04:1a:c1:d9:6b:5a:0a:e2:bc:f8:4b:1e:37:2e:38:22:55" , "expiry-time": 1393244216 }, { "ip-address": "192.168.150.208", "mac-address": "52:54:00:11:56:b3", "hostname": "Wani-PC", "client-id": "01:52:54:00:11:56:b3", "expiry-time": 1393244248 } ] Q1. The libvirt leases helper script/program takes in whatever variable value it receives and stores it unmodified. So, my question is, is it safe to just print the content of each lease in the field-format that you specified just by copying these values which I received earlier as either argument or environment variable (so that my code doesn't have to worry about the details about ARP type, etc)? Q1. What harm will we encounter in case we don't store the server DUID and not print out when the 'init' argument is received? Take a sneakpeak at our leasehelper program: http://libvirt.org/git/?p=libvirt.git;a=blob;f=src/network/leaseshelper.c Thanking You, Nehal J Wani ___ Dnsmasq-discuss mailing list Dnsmasq-discuss@lists.thekelleys.org.uk http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Re: [Dnsmasq-discuss] Query regarding --leasefile-ro
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
[Dnsmasq-discuss] Query regarding --leasefile-ro
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. 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)? 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 ? Thanking You, Nehal J Wani ___ Dnsmasq-discuss mailing list Dnsmasq-discuss@lists.thekelleys.org.uk http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss