@@ -41,11 +41,14 @@ typedef struct {
41
41
uint8_t libDhcp_instance ;
42
42
int8_t interface ;
43
43
bool renew_uses_solicit : 1 ;
44
+ bool one_instance_interface : 1 ;
45
+ bool no_address_hint : 1 ;
44
46
} dhcp_client_class_t ;
45
47
46
48
static dhcp_client_class_t dhcp_client ;
47
49
48
50
void dhcpv6_client_set_address (int8_t interface_id , dhcpv6_client_server_data_t * srv_data_ptr );
51
+ void dhcpv6_renew (protocol_interface_info_entry_t * interface , if_address_entry_t * addr , if_address_callback_t reason );
49
52
50
53
51
54
void dhcp_client_init (int8_t interface )
@@ -57,14 +60,19 @@ void dhcp_client_init(int8_t interface)
57
60
dhcp_client .sol_timeout = 0 ;
58
61
dhcp_client .sol_max_rt = 0 ;
59
62
dhcp_client .sol_max_rc = 0 ;
63
+ dhcp_client .renew_uses_solicit = false;
64
+ dhcp_client .one_instance_interface = false;
65
+ dhcp_client .no_address_hint = false;
60
66
61
67
return ;
62
68
}
63
- void dhcp_client_configure (int8_t interface , bool renew_uses_solicit )
69
+ void dhcp_client_configure (int8_t interface , bool renew_uses_solicit , bool one_client_for_this_interface , bool no_address_hint )
64
70
{
65
71
// Set true if RENEW is not used and SOLICIT sent instead.
66
72
(void )interface ;
67
73
dhcp_client .renew_uses_solicit = renew_uses_solicit ;
74
+ dhcp_client .one_instance_interface = one_client_for_this_interface ;
75
+ dhcp_client .no_address_hint = no_address_hint ;
68
76
}
69
77
70
78
void dhcp_client_solicit_timeout_set (int8_t interface , uint16_t timeout , uint16_t max_rt , uint8_t max_rc )
@@ -170,6 +178,19 @@ int dhcp_solicit_resp_cb(uint16_t instance_id, void *ptr, uint8_t msg_name, uin
170
178
goto error_exit ;
171
179
}
172
180
181
+ if (dhcp_client .one_instance_interface && memcmp (srv_data_ptr -> iaNontemporalAddress .addressPrefix , dhcp_ia_non_temporal_params .nonTemporalAddress , 16 )) {
182
+
183
+ protocol_interface_info_entry_t * cur = protocol_stack_interface_info_get_by_id (dhcp_client .interface );
184
+ if (cur ) {
185
+ ns_list_foreach (if_address_entry_t , e , & cur -> ip_addresses ) {
186
+ if (memcmp (e -> address , srv_data_ptr -> iaNontemporalAddress .addressPrefix , 16 ) == 0 ) {
187
+ tr_debug ("Depreacate address %s" , trace_ipv6 (srv_data_ptr -> iaNontemporalAddress .addressPrefix ));
188
+ addr_prefix_lifetime_update (cur , e , 0 , 0 , 30 * 60 ); //Accept max 30 min lifetime
189
+ }
190
+ }
191
+ }
192
+ }
193
+
173
194
memcpy (srv_data_ptr -> iaNontemporalAddress .addressPrefix , dhcp_ia_non_temporal_params .nonTemporalAddress , 16 );
174
195
srv_data_ptr -> iaNontemporalAddress .preferredTime = dhcp_ia_non_temporal_params .preferredValidLifeTime ;
175
196
srv_data_ptr -> iaNontemporalAddress .validLifetime = dhcp_ia_non_temporal_params .validLifeTime ;
@@ -198,16 +219,25 @@ int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16
198
219
uint8_t * payload_ptr ;
199
220
uint32_t payload_len ;
200
221
dhcpv6_client_server_data_t * srv_data_ptr ;
222
+ bool add_prefix ;
201
223
202
224
if (mac64 == NULL || dhcp_addr == NULL ) {
203
225
tr_error ("Invalid parameters" );
204
226
return -1 ;
205
227
}
206
228
207
- if (!prefix ) {
229
+ if (!prefix || dhcp_client . one_instance_interface ) {
208
230
//NULL Definition will only check That Interface is not generated
209
- if (libdhcpv6_nonTemporal_entry_get_by_instance (dhcp_client .libDhcp_instance )) {
231
+ srv_data_ptr = libdhcpv6_nonTemporal_entry_get_by_instance (dhcp_client .libDhcp_instance );
232
+ if (srv_data_ptr ) {
210
233
//Already Created to same interface
234
+ if (dhcp_client .one_instance_interface && prefix ) {
235
+ if (srv_data_ptr -> iaNonTemporalStructValid ) {
236
+ srv_data_ptr -> iaNonTemporalStructValid = false;
237
+ dhcpv6_renew (protocol_stack_interface_info_get_by_id (interface ), NULL , ADDR_CALLBACK_TIMER );
238
+ return 0 ;
239
+ }
240
+ }
211
241
return -1 ;
212
242
}
213
243
} else if (libdhcpv6_nonTemporal_entry_get_by_prefix (interface , prefix )) {
@@ -224,7 +254,15 @@ int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16
224
254
return -1 ;
225
255
}
226
256
227
- payload_len = libdhcpv6_solication_message_length (link_type , prefix != NULL , 0 );
257
+
258
+ if (!prefix || dhcp_client .no_address_hint ) {
259
+ add_prefix = false;
260
+ } else {
261
+ add_prefix = prefix != NULL ;
262
+ }
263
+
264
+ payload_len = libdhcpv6_solication_message_length (link_type , add_prefix , 0 );
265
+
228
266
229
267
payload_ptr = ns_dyn_mem_temporary_alloc (payload_len );
230
268
if (!payload_ptr ) {
@@ -243,7 +281,7 @@ int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16
243
281
solPacket .transActionId = libdhcpv6_txid_get ();
244
282
/*Non Temporal Address */
245
283
246
- if (prefix ) {
284
+ if (prefix && ! dhcp_client . no_address_hint ) {
247
285
dhcpv6_ia_non_temporal_address_s nonTemporalAddress = {0 };
248
286
nonTemporalAddress .requestedAddress = prefix ;
249
287
libdhcpv6_generic_nontemporal_address_message_write (payload_ptr , & solPacket , & nonTemporalAddress , NULL );
@@ -258,6 +296,7 @@ int dhcp_client_get_global_address(int8_t interface, uint8_t dhcp_addr[static 16
258
296
libdhcvp6_nontemporalAddress_server_data_free (srv_data_ptr );
259
297
return -1 ;
260
298
}
299
+ srv_data_ptr -> iaNonTemporalStructValid = false;
261
300
if (dhcp_client .sol_timeout != 0 ) {
262
301
// Default retry values are modified from specification update to message
263
302
dhcp_service_set_retry_timers (srv_data_ptr -> transActionId , dhcp_client .sol_timeout , dhcp_client .sol_max_rt , dhcp_client .sol_max_rc );
@@ -299,14 +338,18 @@ void dhcp_client_global_address_delete(int8_t interface, uint8_t *dhcp_addr, uin
299
338
300
339
void dhcpv6_renew (protocol_interface_info_entry_t * interface , if_address_entry_t * addr , if_address_callback_t reason )
301
340
{
302
- dhcpv6_ia_non_temporal_address_s nonTemporalAddress = { 0 };
341
+
303
342
dhcp_link_options_params_t serverLink ;
304
343
uint8_t * payload_ptr ;
305
344
uint32_t payload_len ;
306
- dhcpv6_client_server_data_t * srv_data_ptr = libdhcpv6_nonTemporal_entry_get_by_prefix (interface -> id , addr -> address );
345
+ dhcpv6_client_server_data_t * srv_data_ptr ;
346
+ if (addr ) {
347
+ srv_data_ptr = libdhcpv6_nonTemporal_entry_get_by_prefix (interface -> id , addr -> address );
348
+ } else {
349
+ srv_data_ptr = libdhcpv6_nonTemporal_entry_get_by_instance (dhcp_client .libDhcp_instance );
350
+ }
307
351
308
352
if (srv_data_ptr == NULL ) {
309
- tr_warn ("Dhcp address lost" );
310
353
return ;
311
354
}
312
355
if (reason == ADDR_CALLBACK_INVALIDATED ) {
@@ -320,7 +363,7 @@ void dhcpv6_renew(protocol_interface_info_entry_t *interface, if_address_entry_t
320
363
return ;
321
364
}
322
365
323
- payload_len = libdhcpv6_address_request_message_len (srv_data_ptr -> clientLinkIdType , srv_data_ptr -> serverLinkType , 0 );
366
+ payload_len = libdhcpv6_address_request_message_len (srv_data_ptr -> clientLinkIdType , srv_data_ptr -> serverLinkType , 0 , ! dhcp_client . no_address_hint );
324
367
payload_ptr = ns_dyn_mem_temporary_alloc (payload_len );
325
368
if (payload_ptr == NULL ) {
326
369
addr -> state_timer = 200 ; //Retry after 20 seconds
@@ -342,13 +385,21 @@ void dhcpv6_renew(protocol_interface_info_entry_t *interface, if_address_entry_t
342
385
packetReq .messageType = DHCPV6_SOLICATION_TYPE ;
343
386
}
344
387
345
- // Set Address information
346
- nonTemporalAddress .requestedAddress = srv_data_ptr -> iaNontemporalAddress .addressPrefix ;
347
- nonTemporalAddress .preferredLifeTime = srv_data_ptr -> iaNontemporalAddress .preferredTime ;
348
- nonTemporalAddress .validLifeTime = srv_data_ptr -> iaNontemporalAddress .validLifetime ;
388
+
349
389
serverLink .linkID = srv_data_ptr -> serverLinkId ;
350
390
serverLink .linkType = srv_data_ptr -> serverLinkType ;
351
- libdhcpv6_generic_nontemporal_address_message_write (payload_ptr , & packetReq , & nonTemporalAddress , & serverLink );
391
+ if (dhcp_client .no_address_hint && dhcp_client .renew_uses_solicit ) {
392
+ packetReq .timerT0 = 0 ;
393
+ packetReq .timerT1 = 0 ;
394
+ libdhcpv6_generic_nontemporal_address_message_write (payload_ptr , & packetReq , NULL , & serverLink );
395
+ } else {
396
+ // Set Address information
397
+ dhcpv6_ia_non_temporal_address_s nonTemporalAddress = {0 };
398
+ nonTemporalAddress .requestedAddress = srv_data_ptr -> iaNontemporalAddress .addressPrefix ;
399
+ nonTemporalAddress .preferredLifeTime = srv_data_ptr -> iaNontemporalAddress .preferredTime ;
400
+ nonTemporalAddress .validLifeTime = srv_data_ptr -> iaNontemporalAddress .validLifetime ;
401
+ libdhcpv6_generic_nontemporal_address_message_write (payload_ptr , & packetReq , & nonTemporalAddress , & serverLink );
402
+ }
352
403
// send solicit
353
404
uint8_t * server_address = dhcp_service_relay_global_addres_get (dhcp_client .relay_instance );
354
405
if (!server_address ) {
0 commit comments