Re: [Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Simon Kelley
On 27/06/14 21:43, Nehal J Wani wrote:
> On Sat, Jun 28, 2014 at 12:58 AM, Simon Kelley  
> wrote:
>> On 27/06/14 19:40, Nehal J Wani wrote:
 An "old" event is not generated when a lease is _renewed_ (ie when the
 only thing that changes is the expiration time) unless the option
 leasefile-ro is set. Note that setting leasefile-ro has a bunch of other
 effects too.

 When a lease _expires_ (ie the end time of the lease is reached without
 it being renewed) then a a "del" event is generated.
>>>
>>> So, if I understand correctly, there is no way to maintain the leases
>>> file database *and* have my own script catch all events? Why does
>>> dnsmasq put such restrictions?
>>
>> That's correct. The reason for the behaviour is mainly historical. At
>> first, the script received just the events needed to log the existance
>> of leases.  Later, the ability to use the script to maintain the lease
>> database was added, and for that, changes to the expiration time had to
>> be noted. THe old behaviour (when leasefile-ro is not set) stayed for
>> backwards compatibility.
>>
>>> It would be cool to have both
>>> concurrently.
>>
>> As a pragmatic approach, the patch to get the behaviour you want is very
>> small.
>>
> 
> Recently, an API for querying leases info guest machines was pushed in
> libvirt and will most likely be available in 1.2.6. Since this library
> is used by many people around the world, and we have our custom lease
> file helper, which maintains a separate database for leases in JSON
> format, if we just enable leasefile-ro, then we will loose the lease
> file generated by dnsmasq, and we don't want that. Hence, sending a
> patch is fine by me, but will you be willing to have this option
> available in dnsmasq?

Yes. For that application, you clearly don't want a third-party patch.
At very least I'd be willing to add a boolean option to dnsmasq which
enables "old" events when the lease expiry time changes, independent of
leasefile-ro.

> 
>>>
>>> Another question, not very much related to dnsmasq, is that when a
>>> machine receives a lease for a particular period, when should it query
>>> the DHCP again for a new lease? Is it bound to do so, by some RFC? Or
>>> is a matter of choice by the developer?
>>
>> The server can include the information in the lease. There are three
>> options which it can include. The length of the lease is mandatory, and
>> there are two options called T1 and T2. T1 is the time after which the
>> client should renew the lease by doing unicast to the server which gave
>> it the lease. T2 is the time after which the client should try
>> broadcasting if it fails to renew the lease, to give the other half of a
>> failover pair a chance to reply. T1 defaults to half of the lease time,
>> and T2 to 7/8ths of the leasetime. In practise it's very rare to use
>> other values for these. Dnsmasq always send T1 as half lease time and T2
>> as 7/8th the lease time. It doesn't allow them to be configured
>> differently. The RFC the details this is RFC 2131.
>>
> 
> Thanks for all this info.
> Query1: If the lease time is say, 10 minutes, then T1 will be 5
> minutes. Then according to the RFC, the machine should ask for a
> renewal of the lease from the DHCP server using the unicast method? In
> this case, no event will be generated?

The primary key of the lease database is the IP address. Everything else
about a lease can change as long as the IP address remains. Think of an
"old" event as saying "The lease for this IP address has changed in some
way". The change could be to the associated hostname, or client-ID or
MAC address. "old" events are generated for all existing leases when
dnsmasq starts, just to synchronise things. Or it could be that new
information about the lease has become available* When leasefile-ro is
set then the expiry time of the lease is included in this. When the
expiry time changes because the client renewed the lease, then the "old"
method gets called. Without leasefile-ro, them changes _just_ to the
expiry time don't count as changes to the lease.

* There are lots of things supplied to the script that aren't stored in
the lease database, for instance vendor-class and user-class, and relay
options such at circuit-id. When dnsmasq starts, these aren't known, so
the "old" method is invoked without them. Once the client makes a DHCP
transaction, they become known and the "old" method could be invoked
again with the extra information.

>  But you said that, "The old
> behaviour (when leasefile-ro is not set) stayed for backwards
> compatibility."

> Query2: What does dnsmasq do if the machine sends no request for
> renewal at all? Will it just delete the lease?

Once the lease reaches its expiry time, it will be deleted, and a "del"
event sent to the script.

Cheers,

Simon.

> 


___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mail

Re: [Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Nehal J Wani
On Sat, Jun 28, 2014 at 12:58 AM, Simon Kelley  wrote:
> On 27/06/14 19:40, Nehal J Wani wrote:
>>> An "old" event is not generated when a lease is _renewed_ (ie when the
>>> only thing that changes is the expiration time) unless the option
>>> leasefile-ro is set. Note that setting leasefile-ro has a bunch of other
>>> effects too.
>>>
>>> When a lease _expires_ (ie the end time of the lease is reached without
>>> it being renewed) then a a "del" event is generated.
>>
>> So, if I understand correctly, there is no way to maintain the leases
>> file database *and* have my own script catch all events? Why does
>> dnsmasq put such restrictions?
>
> That's correct. The reason for the behaviour is mainly historical. At
> first, the script received just the events needed to log the existance
> of leases.  Later, the ability to use the script to maintain the lease
> database was added, and for that, changes to the expiration time had to
> be noted. THe old behaviour (when leasefile-ro is not set) stayed for
> backwards compatibility.
>
>> It would be cool to have both
>> concurrently.
>
> As a pragmatic approach, the patch to get the behaviour you want is very
> small.
>

Recently, an API for querying leases info guest machines was pushed in
libvirt and will most likely be available in 1.2.6. Since this library
is used by many people around the world, and we have our custom lease
file helper, which maintains a separate database for leases in JSON
format, if we just enable leasefile-ro, then we will loose the lease
file generated by dnsmasq, and we don't want that. Hence, sending a
patch is fine by me, but will you be willing to have this option
available in dnsmasq?

>>
>> Another question, not very much related to dnsmasq, is that when a
>> machine receives a lease for a particular period, when should it query
>> the DHCP again for a new lease? Is it bound to do so, by some RFC? Or
>> is a matter of choice by the developer?
>
> The server can include the information in the lease. There are three
> options which it can include. The length of the lease is mandatory, and
> there are two options called T1 and T2. T1 is the time after which the
> client should renew the lease by doing unicast to the server which gave
> it the lease. T2 is the time after which the client should try
> broadcasting if it fails to renew the lease, to give the other half of a
> failover pair a chance to reply. T1 defaults to half of the lease time,
> and T2 to 7/8ths of the leasetime. In practise it's very rare to use
> other values for these. Dnsmasq always send T1 as half lease time and T2
> as 7/8th the lease time. It doesn't allow them to be configured
> differently. The RFC the details this is RFC 2131.
>

Thanks for all this info.
Query1: If the lease time is say, 10 minutes, then T1 will be 5
minutes. Then according to the RFC, the machine should ask for a
renewal of the lease from the DHCP server using the unicast method? In
this case, no event will be generated?  But you said that, "The old
behaviour (when leasefile-ro is not set) stayed for backwards
compatibility."
Query2: What does dnsmasq do if the machine sends no request for
renewal at all? Will it just delete the lease?

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


Re: [Dnsmasq-discuss] VLANs and multiple IP addresses for one mac address

2014-06-27 Thread David Joslin
>
> Ok, pulling back a level or two in the discussion tree since I'd
>  gonethe wrong path, I have now tried the following:
>
> dhcp-range=,...
> dhcp-range=tag:,,...
> dhcp-host=,,,
> dhcp-host=,,,
>
> I deleted the dnsmasq lease file in /var, ran dnsmasq -d, and from the
> host with given eth (or wlan) addr, did a dhclient on the main interface
> and on the VLAN-ed one. Each interface got its own IP as specified in
> the dhcp-host for the IP range corresponding to the interface, and both
> names got registered in DNS with the right IP address.
>
> It appears no tag is needed, and the right dhcp-option is found based
> on the subnet where the static IP belongs.
>
> Does this fulfill your requirements?
>
> I did not try with IPv6 and especially with auto-addition of SLAAC
> IPv6 addresses to the DNS zone, though.
>

​Bonjour Albert.

Well what do you know! It works! I had assumed that some sort of tag
matching was needed to get the right address for the right VLAN/interface.
But I followed what you suggested and included multiple dhcp-host lines,
all with the same mac address, but with different IPs from the different
subnets and the right addresses got allocated. It must be a bit of dhcp
magic in Simon's code!

Thanks for all your help.

David


>
> > Thanks for your help.
> >
> > David
>
> Amicalement,
> --
> Albert.
>
___
Dnsmasq-discuss mailing list
Dnsmasq-discuss@lists.thekelleys.org.uk
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss


Re: [Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Simon Kelley
On 27/06/14 19:40, Nehal J Wani wrote:
>> An "old" event is not generated when a lease is _renewed_ (ie when the
>> only thing that changes is the expiration time) unless the option
>> leasefile-ro is set. Note that setting leasefile-ro has a bunch of other
>> effects too.
>>
>> When a lease _expires_ (ie the end time of the lease is reached without
>> it being renewed) then a a "del" event is generated.
> 
> So, if I understand correctly, there is no way to maintain the leases
> file database *and* have my own script catch all events? Why does
> dnsmasq put such restrictions? 

That's correct. The reason for the behaviour is mainly historical. At
first, the script received just the events needed to log the existance
of leases.  Later, the ability to use the script to maintain the lease
database was added, and for that, changes to the expiration time had to
be noted. THe old behaviour (when leasefile-ro is not set) stayed for
backwards compatibility.

> It would be cool to have both
> concurrently.

As a pragmatic approach, the patch to get the behaviour you want is very
small.


> 
> Another question, not very much related to dnsmasq, is that when a
> machine receives a lease for a particular period, when should it query
> the DHCP again for a new lease? Is it bound to do so, by some RFC? Or
> is a matter of choice by the developer?

The server can include the information in the lease. There are three
options which it can include. The length of the lease is mandatory, and
there are two options called T1 and T2. T1 is the time after which the
client should renew the lease by doing unicast to the server which gave
it the lease. T2 is the time after which the client should try
broadcasting if it fails to renew the lease, to give the other half of a
failover pair a chance to reply. T1 defaults to half of the lease time,
and T2 to 7/8ths of the leasetime. In practise it's very rare to use
other values for these. Dnsmasq always send T1 as half lease time and T2
as 7/8th the lease time. It doesn't allow them to be configured
differently. The RFC the details this is RFC 2131.


Cheers,

Simon.


> 


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


Re: [Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Albert ARIBAUD
Hi Nehal,

Le Sat, 28 Jun 2014 00:10:32 +0530, Nehal J Wani
 a écrit :

> Another question, not very much related to dnsmasq, is that when a
> machine receives a lease for a particular period, when should it query
> the DHCP again for a new lease? Is it bound to do so, by some RFC? Or
> is a matter of choice by the developer?

As you suspect, this matter (along with many others related to DHCP)
is dealt with by an RFC, namely RFC 2131. See in particular section
4.4.5, "Reacquisition and expiration".



Amicalement,
-- 
Albert.

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


Re: [Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Nehal J Wani
> An "old" event is not generated when a lease is _renewed_ (ie when the
> only thing that changes is the expiration time) unless the option
> leasefile-ro is set. Note that setting leasefile-ro has a bunch of other
> effects too.
>
> When a lease _expires_ (ie the end time of the lease is reached without
> it being renewed) then a a "del" event is generated.

So, if I understand correctly, there is no way to maintain the leases
file database *and* have my own script catch all events? Why does
dnsmasq put such restrictions? It would be cool to have both
concurrently.

Another question, not very much related to dnsmasq, is that when a
machine receives a lease for a particular period, when should it query
the DHCP again for a new lease? Is it bound to do so, by some RFC? Or
is a matter of choice by the developer?

-- 
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] old event to dhcp-script on lease expiry

2014-06-27 Thread Simon Kelley
On 27/06/14 08:27, Nehal J Wani wrote:
> Hi!
> 
> I am trying to understand whether an 'old' event is generated or not
> when a lease expires. To experiment this, I used
> Dnsmasq version 2.72test3-5-gcdb755c
> I launch dnsmasq like this:
> sudo /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default6.conf
> --dhcp-script=/tmp/script.sh
> 
> Contents of script:
> #!/bin/bash echo $@ >> /tmp/out
> env >> /tmp/out
> echo "" >> /tmp/out
> 
> Contents of default6.conf:
> strict-order pid-file=/var/run/libvirt/network/default6.pid
> except-interface=lo bind-dynamic interface=virbr3
> dhcp-range=192.168.150.128,192.168.150.254,2m
> dhcp-no-override
> dhcp-range=2001:db8:ca2:2:1::10,2001:db8:ca2:2:1::ff,2m
> dhcp-leasefile=/var/lib/libvirt/dnsmasq/default6.leases
> dhcp-lease-max=367
> dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default6.hostsfile
> addn-hosts=/var/lib/libvirt/dnsmasq/default6.addnhosts enable-ra
> 
> When I run 'service network restart' inside my guest machine, I see
> that the script is exec'ed with 'old' event. Now, I see that the lease
> file /var/lib/libvirt/dnsmasq/default6.leases keeps getting updated
> after every 2 minutes, since the lease expires, but the script
> /tmp/script.sh doesn't get invoked when the lease gets renewed. Is
> this expected? I don't see any 'old' event for the renewed lease.
> 
> Regards,
> Nehal J Wani
> 


An "old" event is not generated when a lease is _renewed_ (ie when the
only thing that changes is the expiration time) unless the option
leasefile-ro is set. Note that setting leasefile-ro has a bunch of other
effects too.

When a lease _expires_ (ie the end time of the lease is reached without
it being renewed) then a a "del" event is generated.

Cheers,

Simon.


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


[Dnsmasq-discuss] old event to dhcp-script on lease expiry

2014-06-27 Thread Nehal J Wani
Hi!

I am trying to understand whether an 'old' event is generated or not
when a lease expires. To experiment this, I used
Dnsmasq version 2.72test3-5-gcdb755c
I launch dnsmasq like this:
sudo /sbin/dnsmasq --conf-file=/var/lib/libvirt/dnsmasq/default6.conf
--dhcp-script=/tmp/script.sh

Contents of script:
#!/bin/bash echo $@ >> /tmp/out
env >> /tmp/out
echo "" >> /tmp/out

Contents of default6.conf:
strict-order pid-file=/var/run/libvirt/network/default6.pid
except-interface=lo bind-dynamic interface=virbr3
dhcp-range=192.168.150.128,192.168.150.254,2m
dhcp-no-override
dhcp-range=2001:db8:ca2:2:1::10,2001:db8:ca2:2:1::ff,2m
dhcp-leasefile=/var/lib/libvirt/dnsmasq/default6.leases
dhcp-lease-max=367
dhcp-hostsfile=/var/lib/libvirt/dnsmasq/default6.hostsfile
addn-hosts=/var/lib/libvirt/dnsmasq/default6.addnhosts enable-ra

When I run 'service network restart' inside my guest machine, I see
that the script is exec'ed with 'old' event. Now, I see that the lease
file /var/lib/libvirt/dnsmasq/default6.leases keeps getting updated
after every 2 minutes, since the lease expires, but the script
/tmp/script.sh doesn't get invoked when the lease gets renewed. Is
this expected? I don't see any 'old' event for the renewed lease.

Regards,
Nehal J Wani

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