Просмотр исходного кода

[ipv4] Include network device metadata in packet traces

(Ab)use the "ident" field in transmitted IPv4 packets to convey
metadata about the network device.  In particular:

    bits 0-3 represent the low bits of the "RX" good packet counter
    bits 4-7 represent the low bits of the "RXE" bad packet counter
    bits 8-15 represent the transmitted packet sequence number

This allows some relevant information about the internal state of the
network device to be read out from a packet trace from a non-debug
build of iPXE.  In particular, it allows a packet trace containing
packets transmitted by iPXE to indicate whether or not any packets
have been received by iPXE.

Signed-off-by: Michael Brown <mcb30@ipxe.org>
tags/v1.20.1
Michael Brown 13 лет назад
Родитель
Сommit
c1cc769ef4
1 измененных файлов: 10 добавлений и 3 удалений
  1. 10
    3
      src/net/ipv4.c

+ 10
- 3
src/net/ipv4.c Просмотреть файл

23
 
23
 
24
 FILE_LICENCE ( GPL2_OR_LATER );
24
 FILE_LICENCE ( GPL2_OR_LATER );
25
 
25
 
26
-/* Unique IP datagram identification number */
27
-static uint16_t next_ident = 0;
26
+/* Unique IP datagram identification number (high byte) */
27
+static uint8_t next_ident_high = 0;
28
 
28
 
29
 /** List of IPv4 miniroutes */
29
 /** List of IPv4 miniroutes */
30
 struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
30
 struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
314
 	iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
314
 	iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
315
 	iphdr->service = IP_TOS;
315
 	iphdr->service = IP_TOS;
316
 	iphdr->len = htons ( iob_len ( iobuf ) );	
316
 	iphdr->len = htons ( iob_len ( iobuf ) );	
317
-	iphdr->ident = htons ( ++next_ident );
318
 	iphdr->ttl = IP_TTL;
317
 	iphdr->ttl = IP_TTL;
319
 	iphdr->protocol = tcpip_protocol->tcpip_proto;
318
 	iphdr->protocol = tcpip_protocol->tcpip_proto;
320
 	iphdr->dest = sin_dest->sin_addr;
319
 	iphdr->dest = sin_dest->sin_addr;
335
 		goto err;
334
 		goto err;
336
 	}
335
 	}
337
 
336
 
337
+	/* (Ab)use the "ident" field to convey metadata about the
338
+	 * network device statistics into packet traces.  Useful for
339
+	 * extracting debug information from non-debug builds.
340
+	 */
341
+	iphdr->ident = htons ( ( (++next_ident_high) << 8 ) |
342
+			       ( ( netdev->rx_stats.bad & 0xf ) << 4 ) |
343
+			       ( ( netdev->rx_stats.good & 0xf ) << 0 ) );
344
+
338
 	/* Determine link-layer destination address */
345
 	/* Determine link-layer destination address */
339
 	if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
346
 	if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
340
 				   ll_dest ) ) != 0 ) {
347
 				   ll_dest ) ) != 0 ) {

Загрузка…
Отмена
Сохранить