소스 검색

[dhcp] Include session state metadata in packet traces

(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>
tags/v1.20.1
Michael Brown 14 년 전
부모
커밋
6d11229e83
1개의 변경된 파일10개의 추가작업 그리고 0개의 파일을 삭제
  1. 10
    0
      src/net/udp/dhcp.c

+ 10
- 0
src/net/udp/dhcp.c 파일 보기

@@ -245,6 +245,8 @@ struct dhcp_session {
245 245
 
246 246
 	/** Retransmission timer */
247 247
 	struct retry_timer timer;
248
+	/** Transmission counter */
249
+	unsigned int count;
248 250
 	/** Start time of the current state (in ticks) */
249 251
 	unsigned long start;
250 252
 };
@@ -1098,6 +1100,14 @@ static int dhcp_tx ( struct dhcp_session *dhcp ) {
1098 1100
 		goto done;
1099 1101
 	}
1100 1102
 
1103
+	/* (Ab)use the "secs" field to convey metadata about the DHCP
1104
+	 * session state into packet traces.  Useful for extracting
1105
+	 * debug information from non-debug builds.
1106
+	 */
1107
+	dhcppkt.dhcphdr->secs = htons ( ( ++(dhcp->count) << 2 ) |
1108
+					( dhcp->offer.s_addr ? 0x02 : 0 ) |
1109
+					( dhcp->proxy_offer ? 0x01 : 0 ) );
1110
+
1101 1111
 	/* Fill in packet based on current state */
1102 1112
 	if ( ( rc = dhcp->state->tx ( dhcp, &dhcppkt, &peer ) ) != 0 ) {
1103 1113
 		DBGC ( dhcp, "DHCP %p could not fill DHCP request: %s\n",

Loading…
취소
저장