dhcp inform is not fetching the correct option

S Kalyanasundaram skalyanasundaram at novell.com
Thu May 22 12:38:48 UTC 2008


>>> On 5/22/2008 at 12:33 AM, in message
<a0624080ec45a21e35b26 at simon.thehobsons.co.uk>, Simon Hobson
<dhcp1 at thehobsons.co.uk> wrote:
> S Kalyanasundaram wrote:
> 
>>  >> My configuration file:
>>>
>>>	Your "host { ... }" block doesn't belong inside the "subnet { ... }" 
>>block.
>>>
>>>	I'ld suggest upgrading and correcting your configuration file as
>>>	first steps.
>>
>>IIRC, there was a discussion that the host shouldnt be part of the
>>dynamic range.
> 
> That is correct, but not related to this.
> 
>>or you are mentioning the placement of host should
>>be inside the subnet?
> 
> No, you have it inside the subnet, it should NOT be.
> 
> Try changing :
> 
> subnet 192.168.100.0 netmask 255.255.255.0 {
>    default-lease-time 259200;
>    option domain-name "example.com";
>    option domain-name-servers 192.168.201.1;
>    option nds-tree-name "tree0subnet0";
>    pool {
>      range 192.168.100.10 192.168.100.20;
>        option nds-tree-name "tree1pool1";
>    }
>    host testhost {
>      hardware ethernet 00:14:c2:06:51:74;
>      default-lease-time 2147483647;
>      fixed-address 192.168.100.101;
>      option nds-tree-name "tree2host2";
>    }
> }
> 
> to :
> 
> subnet 192.168.100.0 netmask 255.255.255.0 {
>    default-lease-time 259200;
>    option domain-name "example.com";
>    option domain-name-servers 192.168.201.1;
>    option nds-tree-name "tree0subnet0";
>    pool {
>      range 192.168.100.10 192.168.100.20;
>      option nds-tree-name "tree1pool1";
>    }
> }
> 
> host testhost {
>    hardware ethernet 00:14:c2:06:51:74;
>    default-lease-time 2147483647;
>    fixed-address 192.168.100.101;
>    option nds-tree-name "tree2host2";
> }
> 
> 
> BTW - notice how a little formatting makes the structure a lot easier to read 
> ?

Hi Simon, thanks a lot for your reply. I agree with you, now the configuration looks more readable. 
I have tried the configuration as you have suggested but still it does not read the host's options during dhcpinform and it 
always returns the value from subnet "tree0subnet0" to the client instead of "tree2host2".

I read the code a little bit. in dhcp.c in dhcpinform function, we find the corresponding subnet by using
the packets' data. and do execute_statment_in_scope till to the global that is global->sharned_network->subnet
but it never reads the host's configuration. 

I am not sure why this way it is done. or I may just missed to see the original path.

This following patch actually fixes this issue. After execute_statement_in_scope from subnet, it also tries to find the
corresponding host and read its option and return them to the client.

--- dhcp-3.1.0/server/dhcp.c	2007-05-22 03:43:50.000000000 +0530
+++ /home/kalyan/MyFolder/dhcp/dhcp-3.1.0/server/dhcp.c	2008-05-22 18:18:24.000000000 +0530
@@ -938,6 +938,7 @@
 	int nulltp;
 	struct sockaddr_in to;
 	struct in_addr from;
+	struct host_decl *host = (struct host_decl *)0;
 
 	/* The client should set ciaddr to its IP address, but apparently
 	   it's common for clients not to do this, so we'll use their IP
@@ -1025,6 +1026,56 @@
 					     &global_scope, subnet -> group,
 					     (struct group *)0);
 
+	/* Find out the correct host entry and execute statements in the scope */
+
+	/* Try to find a matching host declaration for this lease.
+	 */
+	if (!host) {
+		struct host_decl *hp = (struct host_decl *)0;
+		struct host_decl *h;
+
+		/* Try to find a host_decl that matches the client
+		   identifier or hardware address on the packet, and
+		   has no fixed IP address.   If there is one, hang
+		   it off the lease so that its option definitions
+		   can be used. */
+		oc = lookup_option (&dhcp_universe, packet -> options,
+				    DHO_DHCP_CLIENT_IDENTIFIER);
+
+		if (oc &&
+		    evaluate_option_cache (&d1, packet, (struct lease *)0,
+					   (struct client_state *)0,
+					   packet -> options, (struct option_state *)0,
+					   (struct option_cache *)0, oc, MDL)) {
+ 			find_hosts_by_uid (&hp, d1.data, d1.len, MDL); 
+ 			data_string_forget (&d1, MDL); 
+			if (hp)
+				host_reference (&host, hp, MDL);
+		}
+ 		if (!host) {
+			find_hosts_by_haddr (&hp,
+					     packet -> raw -> htype,
+					     packet -> raw -> chaddr,
+					     packet -> raw -> hlen,
+					     MDL);
+			if (hp)
+				host_reference (&host, hp, MDL);
+		}
+		if (hp)
+			host_dereference (&hp, MDL);
+ 	} 
+
+	/* If we have a host_decl structure, run the options associated
+	   with its group.  Whether the host decl struct is old or not. */
+	if (host)
+		execute_statements_in_scope ((struct binding_value **)0,
+					     packet, (struct lease*)0,
+					     (struct client_state *)0,
+					     packet -> options, options, 
+					     &global_scope, host -> group,
+					     host->group->next);
+
+
 	/* Execute statements in the class scopes. */
 	for (i = packet -> class_count; i > 0; i--) {
 		execute_statements_in_scope


(I have not tested anything really, except the following configuration. Thought this might set up
some idea for the issue, and sorry for the cross posting too)

My conf file:
ddns-update-style none;
max-lease-time 86400;
authoritative;
option broadcast-address 192.168.100.254;
option domain-name-servers 192.168.201.1;
subnet 192.168.100.0 netmask 255.255.255.0 {
  default-lease-time 259200;
  option domain-name "example.com";
  option domain-name-servers 192.168.201.1;
  option nds-tree-name "tree0subnet0";
  pool {
    range 192.168.100.10 192.168.100.20;
    option nds-tree-name "tree1pool1";
  }
}

host testhost {
hardware ethernet 00:14:c2:06:51:74;
default-lease-time 2147483647;
fixed-address 192.168.100.101;
option nds-tree-name "tree2host2";
}


Thanks in advance,
   -Kalyan



More information about the dhcp-users mailing list