Discussion:
[Dnsmasq-discuss] Assigning leases based on relay agent IP address?
Brian Rak
2014-06-02 21:31:58 UTC
Permalink
How can I use dhcp-match with the 'Relay agent IP address' part of the
packet?


I'm trying to manage DHCP for a bunch of different networks with one
DHCP server. I'd like to determine which network to use based on which
subnet the relay server's IP address is in.

I've got a bunch of lines like this:

dhcp-range=set:SUBNETID124862,10.237.2.65,10.237.2.126,auto,255.255.255.192,2h
dhcp-range=set:SUBNETID124844,10.237.4.1,10.237.4.62,auto,255.255.255.192,2h

However, when a DHCPDISCOVER comes in, dnsmasq just picks a random
network to use. As an example:

dnsmasq-dhcp[31908]: 2740340080 vendor class: udhcp 1.12.0
dnsmasq-dhcp[31908]: 2740340080 DHCPDISCOVER(eth1) 00:25:90:d7:c6:7c
dnsmasq-dhcp[31908]: 2740340080 tags: SUBNETID124844, eth1
dnsmasq-dhcp[31908]: 2740340080 DHCPOFFER(eth1) 10.237.4.39
00:25:90:d7:c6:7c

The initial DHCPDISCOVER came in via 10.237.2.65, but a completely
different subnet was used instead. (Also, is it possible to log the
relay IP address?)

tshark shows this:

Bootstrap Protocol
Message type: Boot Request (1)
...
Bootp flags: 0x0000 (Unicast)
0... .... .... .... = Broadcast flag: Unicast
.000 0000 0000 0000 = Reserved flags: 0x0000
Client IP address: 0.0.0.0 (0.0.0.0)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 0.0.0.0 (0.0.0.0)
Relay agent IP address: 10.237.2.65 (10.237.2.65)
Client MAC address: 00:25:90:d7:c6:7c (00:25:90:d7:c6:7c)


This is with dnsmasq 2.71
Brian Rak
2014-06-03 19:30:55 UTC
Permalink
This seems like a bug.

I modified my config to be this instead:

dhcp-range=set:SUBNETID124862,10.237.2.65,10.237.2.126,255.255.255.192,2h
dhcp-range=set:SUBNETID124844,10.237.4.1,10.237.4.62,255.255.255.192,2h

Looking at the code, I see this in the option parser:

if (k >= 3 && strchr(a[2], '.') &&
((new->netmask.s_addr = inet_addr(a[2])) != (in_addr_t)-1))
{
new->flags |= CONTEXT_NETMASK;
leasepos = 3;
if (!is_same_net(new->start, new->end, new->netmask))
ret_err(_("inconsistent DHCP range"));
}

Perhaps I'm not understanding this, but does this mean that the netmask
value is only used if mode is not specified? That's what seems to be
happening to me.

I added a call to rfc2131.c in the 'guess the netmask for relayed
networks' section, and sure enough dnsmasq was guessing netmasks for all
my defined networks. This would explain why this was happening, since
it was guessing a class A network here.
Post by Brian Rak
How can I use dhcp-match with the 'Relay agent IP address' part of the
packet?
I'm trying to manage DHCP for a bunch of different networks with one
DHCP server. I'd like to determine which network to use based on
which subnet the relay server's IP address is in.
dhcp-range=set:SUBNETID124862,10.237.2.65,10.237.2.126,auto,255.255.255.192,2h
dhcp-range=set:SUBNETID124844,10.237.4.1,10.237.4.62,auto,255.255.255.192,2h
However, when a DHCPDISCOVER comes in, dnsmasq just picks a random
dnsmasq-dhcp[31908]: 2740340080 vendor class: udhcp 1.12.0
dnsmasq-dhcp[31908]: 2740340080 DHCPDISCOVER(eth1) 00:25:90:d7:c6:7c
dnsmasq-dhcp[31908]: 2740340080 tags: SUBNETID124844, eth1
dnsmasq-dhcp[31908]: 2740340080 DHCPOFFER(eth1) 10.237.4.39
00:25:90:d7:c6:7c
The initial DHCPDISCOVER came in via 10.237.2.65, but a completely
different subnet was used instead. (Also, is it possible to log the
relay IP address?)
Bootstrap Protocol
Message type: Boot Request (1)
...
Bootp flags: 0x0000 (Unicast)
0... .... .... .... = Broadcast flag: Unicast
.000 0000 0000 0000 = Reserved flags: 0x0000
Client IP address: 0.0.0.0 (0.0.0.0)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 0.0.0.0 (0.0.0.0)
Relay agent IP address: 10.237.2.65 (10.237.2.65)
Client MAC address: 00:25:90:d7:c6:7c (00:25:90:d7:c6:7c)
This is with dnsmasq 2.71
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Simon Kelley
2014-06-11 20:43:03 UTC
Permalink
Post by Brian Rak
How can I use dhcp-match with the 'Relay agent IP address' part of the
packet?
I'm trying to manage DHCP for a bunch of different networks with one
DHCP server. I'd like to determine which network to use based on which
subnet the relay server's IP address is in.
dhcp-range=set:SUBNETID124862,10.237.2.65,10.237.2.126,auto,255.255.255.192,2h
^^^^^

This may be confusing the parser and leading to problems.
Post by Brian Rak
dhcp-range=set:SUBNETID124844,10.237.4.1,10.237.4.62,auto,255.255.255.192,2h
However, when a DHCPDISCOVER comes in, dnsmasq just picks a random
dnsmasq-dhcp[31908]: 2740340080 vendor class: udhcp 1.12.0
dnsmasq-dhcp[31908]: 2740340080 DHCPDISCOVER(eth1) 00:25:90:d7:c6:7c
dnsmasq-dhcp[31908]: 2740340080 tags: SUBNETID124844, eth1
dnsmasq-dhcp[31908]: 2740340080 DHCPOFFER(eth1) 10.237.4.39
00:25:90:d7:c6:7c
The initial DHCPDISCOVER came in via 10.237.2.65, but a completely
different subnet was used instead. (Also, is it possible to log the
relay IP address?)
Bootstrap Protocol
Message type: Boot Request (1)
...
Bootp flags: 0x0000 (Unicast)
0... .... .... .... = Broadcast flag: Unicast
.000 0000 0000 0000 = Reserved flags: 0x0000
Client IP address: 0.0.0.0 (0.0.0.0)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 0.0.0.0 (0.0.0.0)
Relay agent IP address: 10.237.2.65 (10.237.2.65)
Client MAC address: 00:25:90:d7:c6:7c (00:25:90:d7:c6:7c)
This is with dnsmasq 2.71
What you're asking for should be standard mode of operation. Check the
dhcp-range lines, as shown above. I assume you have log-dhcp in your
config? If so it should log the available subnets for each DHCP transaction.

Cheers,

Simon.
Brian Rak
2014-06-12 14:44:09 UTC
Permalink
Post by Simon Kelley
Post by Brian Rak
How can I use dhcp-match with the 'Relay agent IP address' part of the
packet?
I'm trying to manage DHCP for a bunch of different networks with one
DHCP server. I'd like to determine which network to use based on which
subnet the relay server's IP address is in.
dhcp-range=set:SUBNETID124862,10.237.2.65,10.237.2.126,auto,255.255.255.192,2h
^^^^^
This may be confusing the parser and leading to problems.
Yep, that was exactly the cause of the issues. The 'auto' was confusing
it, so it was guessing a netmask for the subnets. It was guessing
255.0.0.0, so all the networks seemed to be available.

Once I removed 'auto', everything is working correctly. I'm not even
sure where I got that, I don't see it in the documentation.
Post by Simon Kelley
Post by Brian Rak
dhcp-range=set:SUBNETID124844,10.237.4.1,10.237.4.62,auto,255.255.255.192,2h
However, when a DHCPDISCOVER comes in, dnsmasq just picks a random
dnsmasq-dhcp[31908]: 2740340080 vendor class: udhcp 1.12.0
dnsmasq-dhcp[31908]: 2740340080 DHCPDISCOVER(eth1) 00:25:90:d7:c6:7c
dnsmasq-dhcp[31908]: 2740340080 tags: SUBNETID124844, eth1
dnsmasq-dhcp[31908]: 2740340080 DHCPOFFER(eth1) 10.237.4.39
00:25:90:d7:c6:7c
The initial DHCPDISCOVER came in via 10.237.2.65, but a completely
different subnet was used instead. (Also, is it possible to log the
relay IP address?)
Bootstrap Protocol
Message type: Boot Request (1)
...
Bootp flags: 0x0000 (Unicast)
0... .... .... .... = Broadcast flag: Unicast
.000 0000 0000 0000 = Reserved flags: 0x0000
Client IP address: 0.0.0.0 (0.0.0.0)
Your (client) IP address: 0.0.0.0 (0.0.0.0)
Next server IP address: 0.0.0.0 (0.0.0.0)
Relay agent IP address: 10.237.2.65 (10.237.2.65)
Client MAC address: 00:25:90:d7:c6:7c (00:25:90:d7:c6:7c)
This is with dnsmasq 2.71
What you're asking for should be standard mode of operation. Check the
dhcp-range lines, as shown above. I assume you have log-dhcp in your
config? If so it should log the available subnets for each DHCP transaction.
Cheers,
Simon.
_______________________________________________
Dnsmasq-discuss mailing list
http://lists.thekelleys.org.uk/mailman/listinfo/dnsmasq-discuss
Continue reading on narkive:
Loading...