Browse Source

[dhcp] Remove redundant length fields in struct dhcp_packet

The max_len field is never used, and the len field is used only by
dhcp_tx().  Remove these two fields, and perform the necessary trivial
calculation in dhcp_tx() instead.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 14 years ago
parent
commit
6cee8904d1
3 changed files with 12 additions and 16 deletions
  1. 10
    4
      src/include/ipxe/dhcppkt.h
  2. 1
    11
      src/net/dhcppkt.c
  3. 1
    1
      src/net/udp/dhcp.c

+ 10
- 4
src/include/ipxe/dhcppkt.h View File

22
 	struct refcnt refcnt;
22
 	struct refcnt refcnt;
23
 	/** The DHCP packet contents */
23
 	/** The DHCP packet contents */
24
 	struct dhcphdr *dhcphdr;
24
 	struct dhcphdr *dhcphdr;
25
-	/** Maximum length of the DHCP packet buffer */
26
-	size_t max_len;
27
-	/** Used length of the DHCP packet buffer */
28
-	size_t len;
29
 	/** DHCP options */
25
 	/** DHCP options */
30
 	struct dhcp_options options;
26
 	struct dhcp_options options;
31
 	/** Settings interface */
27
 	/** Settings interface */
54
 	ref_put ( &dhcppkt->refcnt );
50
 	ref_put ( &dhcppkt->refcnt );
55
 }
51
 }
56
 
52
 
53
+/**
54
+ * Get used length of DHCP packet
55
+ *
56
+ * @v dhcppkt		DHCP packet
57
+ * @ret len		Used length
58
+ */
59
+static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
60
+	return ( offsetof ( struct dhcphdr, options ) + dhcppkt->options.len );
61
+}
62
+
57
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
63
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
58
 			   const void *data, size_t len );
64
 			   const void *data, size_t len );
59
 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
65
 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,

+ 1
- 11
src/net/dhcppkt.c View File

147
 		    const void *data, size_t len ) {
147
 		    const void *data, size_t len ) {
148
 	struct dhcp_packet_field *field;
148
 	struct dhcp_packet_field *field;
149
 	void *field_data;
149
 	void *field_data;
150
-	int rc;
151
 
150
 
152
 	/* If this is a special field, fill it in */
151
 	/* If this is a special field, fill it in */
153
 	if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
152
 	if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
163
 	}
162
 	}
164
 
163
 
165
 	/* Otherwise, use the generic options block */
164
 	/* Otherwise, use the generic options block */
166
-	rc = dhcpopt_store ( &dhcppkt->options, tag, data, len );
167
-
168
-	/* Update our used-length field */
169
-	dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
170
-			 dhcppkt->options.len );
171
-
172
-	return rc;
165
+	return dhcpopt_store ( &dhcppkt->options, tag, data, len );
173
 }
166
 }
174
 
167
 
175
 /**
168
 /**
273
 		    size_t len ) {
266
 		    size_t len ) {
274
 	ref_init ( &dhcppkt->refcnt, NULL );
267
 	ref_init ( &dhcppkt->refcnt, NULL );
275
 	dhcppkt->dhcphdr = data;
268
 	dhcppkt->dhcphdr = data;
276
-	dhcppkt->max_len = len;
277
 	dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
269
 	dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
278
 		       ( len - offsetof ( struct dhcphdr, options ) ) );
270
 		       ( len - offsetof ( struct dhcphdr, options ) ) );
279
-	dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
280
-			 dhcppkt->options.len );
281
 	settings_init ( &dhcppkt->settings,
271
 	settings_init ( &dhcppkt->settings,
282
 			&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
272
 			&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
283
 }
273
 }

+ 1
- 1
src/net/udp/dhcp.c View File

1122
 	}
1122
 	}
1123
 
1123
 
1124
 	/* Transmit the packet */
1124
 	/* Transmit the packet */
1125
-	iob_put ( iobuf, dhcppkt.len );
1125
+	iob_put ( iobuf, dhcppkt_len ( &dhcppkt ) );
1126
 	if ( ( rc = xfer_deliver ( &dhcp->xfer, iob_disown ( iobuf ),
1126
 	if ( ( rc = xfer_deliver ( &dhcp->xfer, iob_disown ( iobuf ),
1127
 				   &meta ) ) != 0 ) {
1127
 				   &meta ) ) != 0 ) {
1128
 		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
1128
 		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",

Loading…
Cancel
Save