[Kea-users] Is KEA trying to do some smart caching?

Ola Thoresen ola at nytt.no
Tue Apr 19 14:44:51 UTC 2016


... or am I doing something stupid?

Sorry for the long mail, hopefully it will explain the issue thoroughly.


I am trying to develop a plugin (hook) that will replace certain 
config-"variables" based on the incoming DHCP-request.

The plugin lives here: https://github.com/Olen/kea_hooks
And the relevant part is in pk4_send.cc

When the server receives a DHCP-request with Option82.2 set, it will 
send back a DHCP-reply with Option43.1 set to the same value.
But for some reason, the Reply is sent back to the client with the 
_wrong_ content.

The request comes in:

options:
   type=050, len=004: 172.19.12.130 (ipv4-address)
   type=053, len=001: 3 (uint8)
   type=054, len=004: 172.29.148.250 (ipv4-address)
   type=082, len=023:,
options:
     type=001, len=010: 67:65:2d:30:2f:30:2f:34:3a:31
     type=002, len=009: 74:65:73:74:2d:63:70:65:34

Option82.002 equals "test-cpe4" (hex encoded)

The server then replies with:

options:
   type=001, len=004: 4294967040 (uint32)
   type=003, len=004: 172.19.12.1
   type=006, len=008: 172.29.131.100 172.29.131.200
   type=042, len=004: 172.19.8.3
   type=043, len=037:,
options:
     type=001, len=009: "test-cpe2" (string)

- "test-cpe2" was the _first_ test i ran after restarting Kea.  No 
matter what I put in Option82, it will always reply with "test-cpe2".

My config file contains the following:

  "name": "config-file-name",
  "code": 1,
  "space": "vendor-encapsulated-options-space",
  "csv-format": true,
  "data": "@OPTION_82_2@"




So I look in my code, and in pkt4_send I try to do the following:
(Only the relevant parts of the code is quoted)

I get the packet-pointer:

         Pkt4Ptr response4_ptr;
         handle.getArgument("response4", response4_ptr);

I try to read the contents of Option43.1:

	OptionPtr opt_ptr = response4_ptr->getOption(opt_code);
	OptionPtr sub_ptr = opt_ptr->getOption(sub_code);

	option_data = sub_ptr->toString();
	debug("Returning data: " << option_data << "\n")					<------- A

Then I try to replace the "variable" with the correct value:

	string placeholder = "@OPTION_82_2@";
	string replace_with = <data from Option82_2>

	option_data.replace(option_data.find(placeholder), placeholder.size(), 
replace_with);

I have added a lot of debug to the code, and the first time after a 
restart, I see the following:


in: @OPTION_82_2@ = test-cpe2
Getting writable option 43.1
Getting option: 43.1
Returning data: cpe/config?hostname=@OPTION_82_2@						<------ B
Replacing @OPTION_82_2@ with test-cpe2 in option 
cpe/config?hostname=@OPTION_82_2@
New option-value: cpe/config?hostname=test-cpe2
Adding option-value: cpe/config?hostname=test-cpe2 in 43.1
Option added

And everything works fine.

But any later DHCP-request will give the following:

in: @OPTION_82_2@ = test-cpe4
Getting writable option 43.1
Getting option: 43.1
Returning data: cpe/config?hostname=test-cpe2							<------ C



A is the debug line resulting it the two outputs B and C
B is first run - the response4_ptr->getOption returns the Option-value 
from the config-file
C is the second run.  Now response4_ptr is _not_ fresh from the config, 
but contains values from the previous dhcp-reply.

What do I need to do to make sure respones4_ptr contains a "fresh" 
packet, without any left overs from the old packets?



/Ola (T)


More information about the Kea-users mailing list