Re: [Dnsmasq-discuss] Dnsmasq MySQL back-end

2014-02-09 Thread Michael Rack

Hi audiotec69,

i use a combination of DNSMASQ and PHP to store the leases in database.

I've attached a PHP-Script that will do the job. You need to install 
CreoleDB (Database Abstraction Layer).


You have to give the script executable bits (chmod 775 )

In your DNSMASQ-Configuration enable the dhcp-script option and point it 
absolute to the script-path. Restart your DNSMASQ and your leases will 
be stored in database.


BTW: A native MySQL-Backend-Driver will be the best solution an 
recommend. But my skills in programming C are not the best to accomplish 
the goals.


Liebe Grüße aus Freilassing,

Michael Rack
RSM Freilassing
--
RSM Freilassing Tel.: +49 8654 607110
Nocksteinstr. 13Fax.: +49 8654 670438
D-83395 Freilassingwww.rsm-freilassing.de

Am 10.02.2014 06:31, schrieb audiotec69:
So apparently back in 2005 there was a patch created for dnsmasq 
version 2.20 
(http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2005q1/000163.html)
to use a MySQL back-end for leases. Could this still be possible? If 
so where might I find documentation on such a configuration. If this 
is not possible, perhaps someone could send me in the right direction. 
I am working on a project that needs the ability to store leases in a 
database.


Ideally I would like to be able to capture the time the lease was 
issued and the time it expired.


Thanks.

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


#!/usr/bin/php
getMessage());
exit( 11 );
}
}
}

$now = date('Y-m-d H:i:s');
switch( strtolower($params[0]) )
{
// Add Lease
case 'add':
if( strlen($params[1]) < 17 ) $params[1] = '00:'. 
$params[1];
$strQuery = 'INSERT INTO `dhcp_leases` (`mac_address`, 
`ip_address`, `dhcp_relay`, `hostname`, `lease_end`)'.
' VALUES ('
.chr(39). 
mysql_escape_string($params[1]) .chr(39)
.', INET_ATON('.chr(39). 
mysql_escape_string($params[2]) .chr(39).')'
.', '. ( ( 
array_key_exists('DNSMASQ_RELAY_ADDRESS', $_ENV)
   AND 
empty($_ENV['DNSMASQ_RELAY_ADDRESS']) === false
 )
 ? 'INET_ATON('. chr(39). 
mysql_escape_string($_ENV['DNSMASQ_RELAY_ADDRESS']) . chr(39) .')'
 : 'NULL'
   )
.', '. ( ( 
array_key_exists('DNSMASQ_SUPPLIED_HOSTNAME', $_ENV)
   AND 
$_ENV['DNSMASQ_SUPPLIED_HOSTNAME'] !== ''
 )
 ? chr(39). 
mysql_escape_string($_ENV['DNSMASQ_SUPPLIED_HOSTNAME']) . chr(39)
 : 'NULL'
   )
.', '.chr(39). 
mysql_escape_string(date('Y-m-d H:i:s', (int)$_ENV['DNSMASQ_LEASE_EXPIRES'])) 
.chr(39)
.')';
write_log( $strQuery );
if( $conn->ExecuteUpdate( $strQuery ) > 0 )
{
printLine( sprintf('OK: Lease for ip-address %s 
added', $params[2]) );
}
else
{
printLine( sprintf('ERR: Failed to add lease 
for %s', $params[2]) );
exit( 32 );
}
exit( 0 );
break;

// Renew Lease
case 'old':
if( strlen($params[1]) < 17 ) $params[1] = '00:'. 
$params[1];
$strQuery = 'UPDATE `dhcp_leases`'.
' SET `lease_end`='.chr(39). 
mysql_escape_string(date('Y-m-d H:i:s', (int)$_ENV['DNSMASQ_LEASE_EXPIRES'])) 
.chr(39).
' WHERE `mac_address`='.chr(39). 
mysql_escape_string($params[1]) .chr(39).
' AND `ip_address`=INET_ATON('.chr(39). 
mysql_escape_string($params[2]) .chr(39).')'.
' AND `lease_end` >= \''. $now .'\'';
write_log( $strQuery );
if( $conn->ExecuteUpdate( $strQuery ) === 0 )
{
$strQuery = 'INSERT INTO `dhcp_leases` 
(`mac_address`, `ip_

[Dnsmasq-discuss] Dnsmasq MySQL back-end

2014-02-09 Thread audiotec69
So apparently back in 2005 there was a patch created for dnsmasq version 
2.20 
(http://lists.thekelleys.org.uk/pipermail/dnsmasq-discuss/2005q1/000163.html)
to use a MySQL back-end for leases. Could this still be possible? If so 
where might I find documentation on such a configuration. If this is not 
possible, perhaps someone could send me in the right direction. I am 
working on a project that needs the ability to store leases in a database.


Ideally I would like to be able to capture the time the lease was issued 
and the time it expired.


Thanks.

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


Re: [Dnsmasq-discuss] Dnsmasq wont recieve DHCP request messaegs

2014-02-09 Thread Simon Kelley

On 09/02/14 07:25, Kiazada Dany-GVN438 wrote:

Hi,

I’m using the program as a DHCP server for a Linux machine. The server
needs to toggle between two different subnets, with different GW (on the
same interface – ‘br0’), and assign an IP for a windows PC.

So for example upon power up the DHCP will assign an IP to the PC
(connected via Ethernet), with subnet ‘A’.

After a while, the DHCP will need to assign a different IP, on a
different subnet ‘B’.
The way I implemented it is running dnsmasq on the Linux machine :

  -C /etc/dnsmasq.conf/sbin/dnsmasq -d --clear-on-rel

With The following  dnsmask.conf file (subnet ‘A’) :

dhcp-range=27.187.20.14,27.187.20.14,255.255.255.0,3600

interface=br0

dhcp-option=3,27.187.20.1

dhcp-option=6,27.187.20.1

dhcp-leasefile=/etc/dnsmasq.leases

dhcp-lease-max=253

log-dhcp

After I receive an indication to change the subnet, I kill the dnsmasq
server, and run it again the same way only with the second subnet ‘B’.
I noticed that the dnsmasq.leases is empty, and there are no connected
clients after the second power up. The PC is sending DHCPINFORM messages
(with no response) and

In order to have the PC ask for a new IP, I cut the power to the
Ethernet Iface. This causing the PC to send DHCPREQUEST messages (with
no DISCOVER messages before).
The dnsmasq is not responding to the REQUEST messages although it’s a
broadcast message, and I can see at tcpdump that they arrive to the
Linux machine…

I can see in the app logs that the dnsmask is receiving the INFORM
messages, but I cannot see the REQUEST messages (in the app logs).

The thing is the PC remembers the first IP it was assigned (subnet ‘A’),
  and although the DHCP server has a different IP range configuration,
the PC is still showing the old IP.

So my goal is to have the PC assigned a new IP (without any PC
involvement, meaning no ipconfig renew\release commands). from a
different pool, different subnet and GW, after the dnsmasq is restarted.



Try adding

dhcp-authoritative

to your configuration.


Cheers,

Simon.



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