Need help with LEASEQUERY..

Pat Winn ptwinn at cimtel.net
Fri Jun 11 16:33:14 UTC 2010


All,
I have *finally* managed to send a DHCPLEASEQUERY packet to
dhcpd and get a DHCPLEASEACTIVE or DHCPLEASEUNKNOWN packet
back...and am parsing it out to something useful.

I fully intend on sharing this (PHP) code with everyone as
soon as I clean it up a tad.  :-)

Now comes the next question..
Now that I have a packet coming back, it has a default subset
of info in it which doesn't quite meet my needs (sigh).
Some of what I need to capture is coming back in that packet,
and some of it seems accessible only via omshell or by
parsing the leases file. Things like start/end times rather
than just the current time left on the lease, etc.

I tried adding options fields to the lease query packet after
browsing through the rfc's..thinking it would send back the
fields I'm inquiring about. Alas..I still only get the same
info back as before I added the extra options. Using a sniffer,
(Wireshark), I see that the packets are no different with or
without the extra options in the lease query packet.

I've not yet tried to dig in the C code for dhcpd..and am wondering.
Am I not passing something correctly, or is this just "all you are
going to get back..period" given the way the dhcpd code is written?

Thought I'd ask to see if anyone knew before I spend time digging.

Thanks!

-- 
Patrick T. Winn
Senior Systems Engineer
Cimarron Telephone Co.
(918) 865-3311 x280 - office
(918) 606-6602 - cell




While counting 0's and 1's, roger murray said:
> Hey,
>
> This code works for me to query a CNR DHCP server (Cisco's DHCP), I
> haven't tested it with ISC, but might have the opportunity next week.
> I use it too loop through 3 servers to find out which server a client
> is on. 99% of the code is based on:
> http://search.cpan.org/~shadinger/Net-DHCP-0.66/lib/Net/DHCP/Packet.pm
> and the example Sending a LEASEQUERY (provided by John A. Murphy).
> Hopefully it will be a little help.
>
> Best regards,
>
> Roger Murray
>
>   #!/usr/bin/perl
>   # Simple DHCP client - send a LeaseQuery (by mac and receive the IP)
> and receive the response
>   use strict;
>   use warnings;
>   use IO::Socket::INET;
>   use Net::DHCP::Packet;
>   use Net::DHCP::Constants;
>
>   my $usage = "usage: $0 DHCP_CLIENT_MAC\n"; $ARGV[0] || die $usage;
>
>  # loop through cnr-A-F looking for the client.
> my $cnr;
> #foreach $cnr (qw/ 1 2 3 4 5 6 /) {
> foreach $cnr (qw/ 1 3 5 /) {
>         my $cnrip = "10.125.$cnr.11";
>   # create a socket
>         my $handle = IO::Socket::INET->new(Proto => 'udp',
>                                   Broadcast => 1,
>                                   PeerPort => '67',
>                                   LocalPort => '67',
>                                   Timeout => '1',
>                                   PeerAddr => $cnrip)
>                 or die "socket: $@";     # yes, it uses $@ here
>
>   # create DHCP Packet
>         my $inform = Net::DHCP::Packet->new(
>                       op => BOOTREQUEST(),
>                       Htype  => '0',
>                       Hlen   => '6',
>                       Ciaddr => '0',
>                       Chaddr => $ARGV[0],
>                       Giaddr => $handle->sockhost(),
>                       Xid => int(rand(0xFFFFFFFF)),     # random xid
>                       DHO_DHCP_MESSAGE_TYPE() => DHCPLEASEQUERY
>                       );
>
>   # send request
>         $handle->send($inform->serialize()) or die "Error sending
> LeaseQuery: $!\n";
>
>   #receive response
>         $handle->recv(my $newmsg, 1024) or die;
>         my $packet = Net::DHCP::Packet->new($newmsg);
>   # this will print out the entire packet
>         # print $packet->toString();
> # this will take the return packet and tell you which cnr it is on.
>         my $package = $packet->toString();
>                 if ( $package =~ /ciaddr = 0.0.0.0/ ){
>                         #print "not on $cnrip \n";
>                 }elsif ( $package =~ /ciaddr =
> ([\d]+)\.([\d]+)\.([\d]+)\.([\d]+)/) {
>                         print "$ARGV[0] has ip $1\.$2\.$3\.$4 and is
> on $cnrip \n"
>                 }
> }
>
>
>
> On Fri, May 21, 2010 at 3:37 PM, Jiri Popelka <jpopelka at redhat.com> wrote:
>> On 05/20/2010 06:04 PM, Pat Winn wrote:
>>>
>>> Matt,
>>> That codebase is (rather ironically) what I stumbled across
>>> and was using for a baseline when I started hacking away at this.
>>>
>>> I'm in the same boat as you...wanting to pull lease info from the
>>> running daemon rather than looking at what is in the leases file.
>>>
>>
>> Same here.
>> If you find (or succeed in writing) some working
>> LEASEQUERY sending piece of software (in whatever language)
>> I would very much appreciate to see it, because I'm also in need of it.
>> Thanks
>>>
>>> We are an isp and are in the process of switching from using radius
>>> with user authentication for our dialup and dsl customers to DHCP.
>>> As such, I need all the info I can glean for each session/lease for
>>> logging purposes and some of the info we need isn't in the leases
>>> file..so it's down to pulling from the running daemon.
>>>
>>> I've tried forking an omshell process to talk to the daemon and
>>> pull the lease info back into PHP. It worked fine except that every
>>> so often the omshell process hangs while connected to the daemon
>>> and won't disconnect. When that happens, the daemon stops responding
>>> to any new requests. Guessing it puts a lock on it's internal lease
>>> objects while omshell is connected since it can alter things and
>>> simply won't work until it disconnects...so that becomes an unusable
>>> option (short of patching ISC's code which I'd rather not tamper with).
>>>
>>> I've considered writing my own version of omshell in php but then
>>> figured out I could send a leasequery packet to the running daemon
>>> and get the same info back...without being connected to it like
>>> omshell. So now it's down to...create a PHP class which can send and
>>> receive a packet to get the info back that way and be able to re-use
>>> said class in whatever php code I want to use it in.
>>>
>>> That is...IF..I can ever get dhcpd to acknowledge that it received
>>> a lease query packet and actually respond to it.  :-(
>>>
>>> I'm totally open for suggestions at this point, and open to working
>>> in a collaborative fashion as well. Perhaps we could both benefit
>>> from it.  ;-)
>>>
>>> Thanks for your time and response!
>>>
>>>
>>
>> _______________________________________________
>> dhcp-hackers mailing list
>> dhcp-hackers at lists.isc.org
>> https://lists.isc.org/mailman/listinfo/dhcp-hackers
>>
>





More information about the dhcp-hackers mailing list