瀏覽代碼

[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 年之前
父節點
當前提交
6cee8904d1
共有 3 個檔案被更改,包括 12 行新增16 行删除
  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 查看文件

@@ -22,10 +22,6 @@ struct dhcp_packet {
22 22
 	struct refcnt refcnt;
23 23
 	/** The DHCP packet contents */
24 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 25
 	/** DHCP options */
30 26
 	struct dhcp_options options;
31 27
 	/** Settings interface */
@@ -54,6 +50,16 @@ dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
54 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 63
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
58 64
 			   const void *data, size_t len );
59 65
 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,

+ 1
- 11
src/net/dhcppkt.c 查看文件

@@ -147,7 +147,6 @@ int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
147 147
 		    const void *data, size_t len ) {
148 148
 	struct dhcp_packet_field *field;
149 149
 	void *field_data;
150
-	int rc;
151 150
 
152 151
 	/* If this is a special field, fill it in */
153 152
 	if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
@@ -163,13 +162,7 @@ int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
163 162
 	}
164 163
 
165 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,11 +266,8 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
273 266
 		    size_t len ) {
274 267
 	ref_init ( &dhcppkt->refcnt, NULL );
275 268
 	dhcppkt->dhcphdr = data;
276
-	dhcppkt->max_len = len;
277 269
 	dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
278 270
 		       ( len - offsetof ( struct dhcphdr, options ) ) );
279
-	dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
280
-			 dhcppkt->options.len );
281 271
 	settings_init ( &dhcppkt->settings,
282 272
 			&dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
283 273
 }

+ 1
- 1
src/net/udp/dhcp.c 查看文件

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

Loading…
取消
儲存