]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dhcp] Remove redundant length fields in struct dhcp_packet
authorMichael Brown <mcb30@ipxe.org>
Tue, 30 Nov 2010 00:22:49 +0000 (00:22 +0000)
committerMichael Brown <mcb30@ipxe.org>
Mon, 10 Jan 2011 03:39:26 +0000 (03:39 +0000)
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>
src/include/ipxe/dhcppkt.h
src/net/dhcppkt.c
src/net/udp/dhcp.c

index 5709cc7d1ff2538dfd65c33ad3d4929d29946bb7..b004800d8af1701c11df55331a72a87dee40348a 100644 (file)
@@ -22,10 +22,6 @@ struct dhcp_packet {
        struct refcnt refcnt;
        /** The DHCP packet contents */
        struct dhcphdr *dhcphdr;
-       /** Maximum length of the DHCP packet buffer */
-       size_t max_len;
-       /** Used length of the DHCP packet buffer */
-       size_t len;
        /** DHCP options */
        struct dhcp_options options;
        /** Settings interface */
@@ -54,6 +50,16 @@ dhcppkt_put ( struct dhcp_packet *dhcppkt ) {
        ref_put ( &dhcppkt->refcnt );
 }
 
+/**
+ * Get used length of DHCP packet
+ *
+ * @v dhcppkt          DHCP packet
+ * @ret len            Used length
+ */
+static inline int dhcppkt_len ( struct dhcp_packet *dhcppkt ) {
+       return ( offsetof ( struct dhcphdr, options ) + dhcppkt->options.len );
+}
+
 extern int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
                           const void *data, size_t len );
 extern int dhcppkt_fetch ( struct dhcp_packet *dhcppkt, unsigned int tag,
index b68f4e08d23ac44ff0cc6498eca24b0adff5f92a..e043bb5d4a601417ff62cda3e52a22d06b5d5206 100644 (file)
@@ -147,7 +147,6 @@ int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
                    const void *data, size_t len ) {
        struct dhcp_packet_field *field;
        void *field_data;
-       int rc;
 
        /* If this is a special field, fill it in */
        if ( ( field = find_dhcp_packet_field ( tag ) ) != NULL ) {
@@ -163,13 +162,7 @@ int dhcppkt_store ( struct dhcp_packet *dhcppkt, unsigned int tag,
        }
 
        /* Otherwise, use the generic options block */
-       rc = dhcpopt_store ( &dhcppkt->options, tag, data, len );
-
-       /* Update our used-length field */
-       dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
-                        dhcppkt->options.len );
-
-       return rc;
+       return dhcpopt_store ( &dhcppkt->options, tag, data, len );
 }
 
 /**
@@ -273,11 +266,8 @@ void dhcppkt_init ( struct dhcp_packet *dhcppkt, struct dhcphdr *data,
                    size_t len ) {
        ref_init ( &dhcppkt->refcnt, NULL );
        dhcppkt->dhcphdr = data;
-       dhcppkt->max_len = len;
        dhcpopt_init ( &dhcppkt->options, &dhcppkt->dhcphdr->options,
                       ( len - offsetof ( struct dhcphdr, options ) ) );
-       dhcppkt->len = ( offsetof ( struct dhcphdr, options ) +
-                        dhcppkt->options.len );
        settings_init ( &dhcppkt->settings,
                        &dhcppkt_settings_operations, &dhcppkt->refcnt, 0 );
 }
index 64c49cdd960bcca72651271acb52d7fd61fa5f9a..e6d127ab70cb3ab06eca8e08929e29deb5491300 100644 (file)
@@ -1122,7 +1122,7 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
        }
 
        /* Transmit the packet */
-       iob_put ( iobuf, dhcppkt.len );
+       iob_put ( iobuf, dhcppkt_len ( &dhcppkt ) );
        if ( ( rc = xfer_deliver ( &dhcp->xfer, iob_disown ( iobuf ),
                                   &meta ) ) != 0 ) {
                DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",