]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[dhcp] Include session state metadata in packet traces
authorMichael Brown <mcb30@ipxe.org>
Sat, 9 Oct 2010 00:24:18 +0000 (01:24 +0100)
committerMichael Brown <mcb30@ipxe.org>
Sat, 9 Oct 2010 00:24:18 +0000 (01:24 +0100)
(Ab)use the "secs" field in transmitted DHCP packets to convey
metadata about the DHCP session state.  In particular:

  bit 0 represents the receipt of a ProxyDHCPOFFER
  bit 1 represents the receipt of a DHCPOFFER
  bits 2+ represent the transmitted packet sequence number

This allows some relevant information about the internal state of the
DHCP session to be read out from a packet trace from a non-debug build
of iPXE.  It also potentially allows replies to be correlated to their
requests (for servers that copy the "secs" field from request to
reply).

Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/net/udp/dhcp.c

index 9ab93dcf77fee8cc711f8e87c96dfb0e0f55f04c..443ae3aa4b1d26e43b0cddfcd9b52ec319ed466c 100644 (file)
@@ -245,6 +245,8 @@ struct dhcp_session {
 
        /** Retransmission timer */
        struct retry_timer timer;
+       /** Transmission counter */
+       unsigned int count;
        /** Start time of the current state (in ticks) */
        unsigned long start;
 };
@@ -1098,6 +1100,14 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
                goto done;
        }
 
+       /* (Ab)use the "secs" field to convey metadata about the DHCP
+        * session state into packet traces.  Useful for extracting
+        * debug information from non-debug builds.
+        */
+       dhcppkt.dhcphdr->secs = htons ( ( ++(dhcp->count) << 2 ) |
+                                       ( dhcp->offer.s_addr ? 0x02 : 0 ) |
+                                       ( dhcp->proxy_offer ? 0x01 : 0 ) );
+
        /* Fill in packet based on current state */
        if ( ( rc = dhcp->state->tx ( dhcp, &dhcppkt, &peer ) ) != 0 ) {
                DBGC ( dhcp, "DHCP %p could not fill DHCP request: %s\n",