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 */
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,
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 ) {
}
/* 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 );
}
/**
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 );
}
}
/* 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",