]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[ipv4] Include network device metadata in packet traces
authorMichael Brown <mcb30@ipxe.org>
Thu, 5 May 2011 17:02:44 +0000 (18:02 +0100)
committerMichael Brown <mcb30@ipxe.org>
Thu, 5 May 2011 17:10:31 +0000 (18:10 +0100)
(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>
src/net/ipv4.c

index b2d51ada42854b24bd6a32ecd904bf74265f3d7d..465df45e0acdf1d90cf7b9480c8c11286976c4fe 100644 (file)
@@ -23,8 +23,8 @@
 
 FILE_LICENCE ( GPL2_OR_LATER );
 
-/* Unique IP datagram identification number */
-static uint16_t next_ident = 0;
+/* Unique IP datagram identification number (high byte) */
+static uint8_t next_ident_high = 0;
 
 /** List of IPv4 miniroutes */
 struct list_head ipv4_miniroutes = LIST_HEAD_INIT ( ipv4_miniroutes );
@@ -314,7 +314,6 @@ static int ipv4_tx ( struct io_buffer *iobuf,
        iphdr->verhdrlen = ( IP_VER | ( sizeof ( *iphdr ) / 4 ) );
        iphdr->service = IP_TOS;
        iphdr->len = htons ( iob_len ( iobuf ) );       
-       iphdr->ident = htons ( ++next_ident );
        iphdr->ttl = IP_TTL;
        iphdr->protocol = tcpip_protocol->tcpip_proto;
        iphdr->dest = sin_dest->sin_addr;
@@ -335,6 +334,14 @@ static int ipv4_tx ( struct io_buffer *iobuf,
                goto err;
        }
 
+       /* (Ab)use the "ident" field to convey metadata about the
+        * network device statistics into packet traces.  Useful for
+        * extracting debug information from non-debug builds.
+        */
+       iphdr->ident = htons ( ( (++next_ident_high) << 8 ) |
+                              ( ( netdev->rx_stats.bad & 0xf ) << 4 ) |
+                              ( ( netdev->rx_stats.good & 0xf ) << 0 ) );
+
        /* Determine link-layer destination address */
        if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
                                   ll_dest ) ) != 0 ) {