Parcourir la 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 il y a 14 ans
Parent
révision
310d46c1ed
4 fichiers modifiés avec 25 ajouts et 24 suppressions
  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 Voir le fichier

@@ -15,10 +15,10 @@ FILE_LICENCE ( GPL2_OR_LATER );
15 15
 struct dhcp_options {
16 16
 	/** Option block raw data */
17 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 24
 extern int dhcpopt_store ( struct dhcp_options *options, unsigned int tag,
@@ -29,6 +29,6 @@ extern int dhcpopt_extensible_store ( struct dhcp_options *options,
29 29
 extern int dhcpopt_fetch ( struct dhcp_options *options, unsigned int tag,
30 30
 			   void *data, size_t len );
31 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 34
 #endif /* _IPXE_DHCPOPTS_H */

+ 2
- 1
src/include/ipxe/dhcppkt.h Voir le fichier

@@ -57,7 +57,8 @@ dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
57 57
  * @ret len		Used length
58 58
  */
59 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 64
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,

+ 1
- 1
src/net/cachedhcp.c Voir le fichier

@@ -58,7 +58,7 @@ void store_cached_dhcpack ( userptr_t data, size_t len ) {
58 58
 	dhcphdr = ( ( ( void * ) dhcppkt ) + sizeof ( * dhcppkt ) );
59 59
 	copy_from_user ( dhcphdr, data, 0, len );
60 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 63
 	/* Register settings on the last opened network device.
64 64
 	 * This will have the effect of registering cached settings

+ 17
- 17
src/net/dhcpopts.c Voir le fichier

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

Chargement…
Annuler
Enregistrer