|
@@ -255,20 +255,34 @@ static int create_dhcp_request ( struct dhcp_packet *dhcppkt,
|
255
|
255
|
|
256
|
256
|
/* Copy any required options from previous server repsonse */
|
257
|
257
|
if ( dhcpoffer ) {
|
258
|
|
- if ( ( rc = copy_setting ( &dhcppkt->settings,
|
259
|
|
- DHCP_SERVER_IDENTIFIER,
|
260
|
|
- &dhcpoffer->settings,
|
261
|
|
- DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
|
262
|
|
- DBG ( "DHCP could not set server identifier "
|
263
|
|
- "option: %s\n", strerror ( rc ) );
|
|
258
|
+ struct in_addr server_id;
|
|
259
|
+ struct in_addr requested_ip;
|
|
260
|
+
|
|
261
|
+ if ( ( rc = fetch_ipv4_setting ( &dhcpoffer->settings,
|
|
262
|
+ DHCP_SERVER_IDENTIFIER,
|
|
263
|
+ &server_id ) ) < 0 ) {
|
|
264
|
+ DBG ( "DHCP offer missing server identifier\n" );
|
|
265
|
+ return -EINVAL;
|
|
266
|
+ }
|
|
267
|
+ if ( ( rc = fetch_ipv4_setting ( &dhcpoffer->settings,
|
|
268
|
+ DHCP_EB_YIADDR,
|
|
269
|
+ &requested_ip ) ) < 0 ) {
|
|
270
|
+ DBG ( "DHCP offer missing IP address\n" );
|
|
271
|
+ return -EINVAL;
|
|
272
|
+ }
|
|
273
|
+ if ( ( rc = store_setting ( &dhcppkt->settings,
|
|
274
|
+ DHCP_SERVER_IDENTIFIER, &server_id,
|
|
275
|
+ sizeof ( server_id ) ) ) != 0 ) {
|
|
276
|
+ DBG ( "DHCP could not set server identifier: %s\n ",
|
|
277
|
+ strerror ( rc ) );
|
264
|
278
|
return rc;
|
265
|
279
|
}
|
266
|
|
- if ( ( rc = copy_setting ( &dhcppkt->settings,
|
267
|
|
- DHCP_REQUESTED_ADDRESS,
|
268
|
|
- &dhcpoffer->settings,
|
269
|
|
- DHCP_EB_YIADDR ) ) != 0 ) {
|
270
|
|
- DBG ( "DHCP could not set requested address "
|
271
|
|
- "option: %s\n", strerror ( rc ) );
|
|
280
|
+ if ( ( rc = store_setting ( &dhcppkt->settings,
|
|
281
|
+ DHCP_REQUESTED_ADDRESS,
|
|
282
|
+ &requested_ip,
|
|
283
|
+ sizeof ( requested_ip ) ) ) != 0 ){
|
|
284
|
+ DBG ( "DHCP could not set requested address: %s\n",
|
|
285
|
+ strerror ( rc ) );
|
272
|
286
|
return rc;
|
273
|
287
|
}
|
274
|
288
|
}
|
|
@@ -335,8 +349,16 @@ static int create_dhcp_request ( struct dhcp_packet *dhcppkt,
|
335
|
349
|
int create_dhcpdiscover ( struct net_device *netdev,
|
336
|
350
|
void *data, size_t max_len ) {
|
337
|
351
|
struct dhcp_packet dhcppkt;
|
|
352
|
+ int rc;
|
|
353
|
+
|
|
354
|
+ if ( ( rc = create_dhcp_request ( &dhcppkt, netdev, NULL, data,
|
|
355
|
+ max_len ) ) != 0 ) {
|
|
356
|
+ DBG ( "Could not create DHCPDISCOVER: %s\n",
|
|
357
|
+ strerror ( rc ) );
|
|
358
|
+ return rc;
|
|
359
|
+ }
|
338
|
360
|
|
339
|
|
- return create_dhcp_request ( &dhcppkt, netdev, NULL, data, max_len );
|
|
361
|
+ return 0;
|
340
|
362
|
}
|
341
|
363
|
|
342
|
364
|
/**
|
|
@@ -356,18 +378,26 @@ int create_dhcpack ( struct net_device *netdev,
|
356
|
378
|
|
357
|
379
|
/* Create base DHCPACK packet */
|
358
|
380
|
if ( ( rc = create_dhcp_packet ( &dhcppkt, netdev, DHCPACK, NULL,
|
359
|
|
- data, max_len ) ) != 0 )
|
|
381
|
+ data, max_len ) ) != 0 ) {
|
|
382
|
+ DBG ( "Could not create DHCPACK: %s\n", strerror ( rc ) );
|
360
|
383
|
return rc;
|
|
384
|
+ }
|
361
|
385
|
|
362
|
386
|
/* Merge in globally-scoped settings, then netdev-specific
|
363
|
387
|
* settings. Do it in this order so that netdev-specific
|
364
|
388
|
* settings take precedence regardless of stated priorities.
|
365
|
389
|
*/
|
366
|
|
- if ( ( rc = copy_settings ( &dhcppkt.settings, NULL ) ) != 0 )
|
|
390
|
+ if ( ( rc = copy_settings ( &dhcppkt.settings, NULL ) ) != 0 ) {
|
|
391
|
+ DBG ( "Could not set DHCPACK global settings: %s\n",
|
|
392
|
+ strerror ( rc ) );
|
367
|
393
|
return rc;
|
|
394
|
+ }
|
368
|
395
|
if ( ( rc = copy_settings ( &dhcppkt.settings,
|
369
|
|
- netdev_settings ( netdev ) ) ) != 0 )
|
|
396
|
+ netdev_settings ( netdev ) ) ) != 0 ) {
|
|
397
|
+ DBG ( "Could not set DHCPACK netdev settings: %s\n",
|
|
398
|
+ strerror ( rc ) );
|
370
|
399
|
return rc;
|
|
400
|
+ }
|
371
|
401
|
|
372
|
402
|
return 0;
|
373
|
403
|
}
|
|
@@ -399,12 +429,18 @@ int create_proxydhcpack ( struct net_device *netdev,
|
399
|
429
|
|
400
|
430
|
/* Create base DHCPACK packet */
|
401
|
431
|
if ( ( rc = create_dhcp_packet ( &dhcppkt, netdev, DHCPACK, NULL,
|
402
|
|
- data, max_len ) ) != 0 )
|
|
432
|
+ data, max_len ) ) != 0 ) {
|
|
433
|
+ DBG ( "Could not create ProxyDHCPACK: %s\n",
|
|
434
|
+ strerror ( rc ) );
|
403
|
435
|
return rc;
|
|
436
|
+ }
|
404
|
437
|
|
405
|
438
|
/* Merge in ProxyDHCP options */
|
406
|
|
- if ( ( rc = copy_settings ( &dhcppkt.settings, settings ) ) != 0 )
|
|
439
|
+ if ( ( rc = copy_settings ( &dhcppkt.settings, settings ) ) != 0 ) {
|
|
440
|
+ DBG ( "Could not set ProxyDHCPACK settings: %s\n",
|
|
441
|
+ strerror ( rc ) );
|
407
|
442
|
return rc;
|
|
443
|
+ }
|
408
|
444
|
|
409
|
445
|
return 0;
|
410
|
446
|
}
|