Browse Source

[dhcp] Rename length fields for DHCP options

Rename "len" to "used_len" and "max_len" to "alloc_len".

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
310d46c1ed
4 changed files with 25 additions and 24 deletions
  1. 5
    5
      src/include/ipxe/dhcpopts.h
  2. 2
    1
      src/include/ipxe/dhcppkt.h
  3. 1
    1
      src/net/cachedhcp.c
  4. 17
    17
      src/net/dhcpopts.c

+ 5
- 5
src/include/ipxe/dhcpopts.h View File

15
 struct dhcp_options {
15
 struct dhcp_options {
16
 	/** Option block raw data */
16
 	/** Option block raw data */
17
 	void *data;
17
 	void *data;
18
-	/** Option block length */
19
-	size_t len;
20
-	/** Option block maximum length */
21
-	size_t max_len;
18
+	/** Option block used length */
19
+	size_t used_len;
20
+	/** Option block allocated length */
21
+	size_t alloc_len;
22
 };
22
 };
23
 
23
 
24
 extern int dhcpopt_store ( struct dhcp_options *options, unsigned int tag,
24
 extern int dhcpopt_store ( struct dhcp_options *options, unsigned int tag,
29
 extern int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag,
29
 extern int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag,
30
 			   void *data, size_t len );
30
 			   void *data, size_t len );
31
 extern void dhcpopt_init ( struct dhcp_options *options,
31
 extern void dhcpopt_init ( struct dhcp_options *options,
32
-			   void *data, size_t max_len );
32
+			   void *data, size_t alloc_len );
33
 
33
 
34
 #endif /* _IPXE_DHCPOPTS_H */
34
 #endif /* _IPXE_DHCPOPTS_H */

+ 2
- 1
src/include/ipxe/dhcppkt.h View File

57
  * @ret len		Used length
57
  * @ret len		Used length
58
  */
58
  */
59
 static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
59
 static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
60
-	return ( offsetof ( struct dhcphdr, options ) + dhcppkt->options.len );
60
+	return ( offsetof ( struct dhcphdr, options ) +
61
+		 dhcppkt->options.used_len );
61
 }
62
 }
62
 
63
 
63
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
64
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,

+ 1
- 1
src/net/cachedhcp.c View File

58
 	dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
58
 	dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
59
 	copy_from_user ( dhcphdr, data, 0, len );
59
 	copy_from_user ( dhcphdr, data, 0, len );
60
 	dhcppkt_init ( dhcppkt, dhcphdr, len );
60
 	dhcppkt_init ( dhcppkt, dhcphdr, len );
61
-	DBG_HD ( dhcppkt->options.data, dhcppkt->options.len );
61
+	DBG_HD ( dhcppkt->options.data, dhcppkt->options.used_len );
62
 
62
 
63
 	/* Register settings on the last opened network device.
63
 	/* Register settings on the last opened network device.
64
 	 * This will have the effect of registering cached settings
64
 	 * This will have the effect of registering cached settings

+ 17
- 17
src/net/dhcpopts.c View File

117
 	unsigned int original_tag __attribute__ (( unused )) = tag;
117
 	unsigned int original_tag __attribute__ (( unused )) = tag;
118
 	struct dhcp_option *option;
118
 	struct dhcp_option *option;
119
 	int offset = 0;
119
 	int offset = 0;
120
-	ssize_t remaining = options->len;
120
+	ssize_t remaining = options->used_len;
121
 	unsigned int option_len;
121
 	unsigned int option_len;
122
 
122
 
123
 	/* Sanity check */
123
 	/* Sanity check */
199
 		DBGC ( options, "DHCPOPT %p overlength option\n", options );
199
 		DBGC ( options, "DHCPOPT %p overlength option\n", options );
200
 		return -ENOSPC;
200
 		return -ENOSPC;
201
 	}
201
 	}
202
-	new_options_len = ( options->len + delta );
203
-	if ( new_options_len > options->max_len ) {
202
+	new_options_len = ( options->used_len + delta );
203
+	if ( new_options_len > options->alloc_len ) {
204
 		/* Reallocate options block if allowed to do so. */
204
 		/* Reallocate options block if allowed to do so. */
205
 		if ( can_realloc ) {
205
 		if ( can_realloc ) {
206
 			new_data = realloc ( options->data, new_options_len );
206
 			new_data = realloc ( options->data, new_options_len );
211
 				return -ENOMEM;
211
 				return -ENOMEM;
212
 			}
212
 			}
213
 			options->data = new_data;
213
 			options->data = new_data;
214
-			options->max_len = new_options_len;
214
+			options->alloc_len = new_options_len;
215
 		} else {
215
 		} else {
216
 			DBGC ( options, "DHCPOPT %p out of space\n", options );
216
 			DBGC ( options, "DHCPOPT %p out of space\n", options );
217
 			return -ENOMEM;
217
 			return -ENOMEM;
227
 		}
227
 		}
228
 		encapsulator->len = new_encapsulator_len;
228
 		encapsulator->len = new_encapsulator_len;
229
 	}
229
 	}
230
-	options->len = new_options_len;
230
+	options->used_len = new_options_len;
231
 
231
 
232
 	/* Move remainder of option data */
232
 	/* Move remainder of option data */
233
 	option = dhcp_option ( options, offset );
233
 	option = dhcp_option ( options, offset );
234
 	source = ( ( ( void * ) option ) + old_len );
234
 	source = ( ( ( void * ) option ) + old_len );
235
 	dest = ( ( ( void * ) option ) + new_len );
235
 	dest = ( ( ( void * ) option ) + new_len );
236
-	end = ( options->data + options->max_len );
236
+	end = ( options->data + options->alloc_len );
237
 	memmove ( dest, source, ( end - dest ) );
237
 	memmove ( dest, source, ( end - dest ) );
238
 
238
 
239
 	return 0;
239
 	return 0;
277
 	creation_offset = find_dhcp_option_with_encap ( options, DHCP_END,
277
 	creation_offset = find_dhcp_option_with_encap ( options, DHCP_END,
278
 							NULL );
278
 							NULL );
279
 	if ( creation_offset < 0 )
279
 	if ( creation_offset < 0 )
280
-		creation_offset = options->len;
280
+		creation_offset = options->used_len;
281
 	/* Find old instance of this option, if any */
281
 	/* Find old instance of this option, if any */
282
 	offset = find_dhcp_option_with_encap ( options, tag, &encap_offset );
282
 	offset = find_dhcp_option_with_encap ( options, tag, &encap_offset );
283
 	if ( offset >= 0 ) {
283
 	if ( offset >= 0 ) {
402
  * The "used length" field will be updated based on scanning through
402
  * The "used length" field will be updated based on scanning through
403
  * the block to find the end of the options.
403
  * the block to find the end of the options.
404
  */
404
  */
405
-static void dhcpopt_update_len ( struct dhcp_options *options ) {
405
+static void dhcpopt_update_used_len ( struct dhcp_options *options ) {
406
 	struct dhcp_option *option;
406
 	struct dhcp_option *option;
407
 	int offset = 0;
407
 	int offset = 0;
408
-	ssize_t remaining = options->max_len;
408
+	ssize_t remaining = options->alloc_len;
409
 	unsigned int option_len;
409
 	unsigned int option_len;
410
 
410
 
411
 	/* Find last non-pad option */
411
 	/* Find last non-pad option */
412
-	options->len = 0;
412
+	options->used_len = 0;
413
 	while ( remaining ) {
413
 	while ( remaining ) {
414
 		option = dhcp_option ( options, offset );
414
 		option = dhcp_option ( options, offset );
415
 		option_len = dhcp_option_len ( option );
415
 		option_len = dhcp_option_len ( option );
418
 			break;
418
 			break;
419
 		offset += option_len;
419
 		offset += option_len;
420
 		if ( option->tag != DHCP_PAD )
420
 		if ( option->tag != DHCP_PAD )
421
-			options->len = offset;
421
+			options->used_len = offset;
422
 	}
422
 	}
423
 }
423
 }
424
 
424
 
427
  *
427
  *
428
  * @v options		Uninitialised DHCP option block
428
  * @v options		Uninitialised DHCP option block
429
  * @v data		Memory for DHCP option data
429
  * @v data		Memory for DHCP option data
430
- * @v max_len		Length of memory for DHCP option data
430
+ * @v alloc_len		Length of memory for DHCP option data
431
  *
431
  *
432
  * The memory content must already be filled with valid DHCP options.
432
  * The memory content must already be filled with valid DHCP options.
433
  * A zeroed block counts as a block of valid DHCP options.
433
  * A zeroed block counts as a block of valid DHCP options.
434
  */
434
  */
435
 void dhcpopt_init ( struct dhcp_options *options, void *data,
435
 void dhcpopt_init ( struct dhcp_options *options, void *data,
436
-		    size_t max_len ) {
436
+		    size_t alloc_len ) {
437
 
437
 
438
 	/* Fill in fields */
438
 	/* Fill in fields */
439
 	options->data = data;
439
 	options->data = data;
440
-	options->max_len = max_len;
440
+	options->alloc_len = alloc_len;
441
 
441
 
442
 	/* Update length */
442
 	/* Update length */
443
-	dhcpopt_update_len ( options );
443
+	dhcpopt_update_used_len ( options );
444
 
444
 
445
-	DBGC ( options, "DHCPOPT %p created (data %p len %#zx max_len %#zx)\n",
446
-	       options, options->data, options->len, options->max_len );
445
+	DBGC ( options, "DHCPOPT %p created (data %p lengths %#zx,%#zx)\n",
446
+	       options, options->data, options->used_len, options->alloc_len );
447
 }
447
 }

Loading…
Cancel
Save