mirror of
https://github.com/ipxe/ipxe
synced 2025-12-22 13:00:39 +03:00
[ipv4] Improve debugging
Use autocolourisation to improve legibility, and move per-packet messages to DBG2(). Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -50,16 +50,16 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
|
|||||||
struct in_addr netmask, struct in_addr gateway ) {
|
struct in_addr netmask, struct in_addr gateway ) {
|
||||||
struct ipv4_miniroute *miniroute;
|
struct ipv4_miniroute *miniroute;
|
||||||
|
|
||||||
DBG ( "IPv4 add %s", inet_ntoa ( address ) );
|
DBGC ( netdev, "IPv4 add %s", inet_ntoa ( address ) );
|
||||||
DBG ( "/%s ", inet_ntoa ( netmask ) );
|
DBGC ( netdev, "/%s ", inet_ntoa ( netmask ) );
|
||||||
if ( gateway.s_addr )
|
if ( gateway.s_addr )
|
||||||
DBG ( "gw %s ", inet_ntoa ( gateway ) );
|
DBGC ( netdev, "gw %s ", inet_ntoa ( gateway ) );
|
||||||
DBG ( "via %s\n", netdev->name );
|
DBGC ( netdev, "via %s\n", netdev->name );
|
||||||
|
|
||||||
/* Allocate and populate miniroute structure */
|
/* Allocate and populate miniroute structure */
|
||||||
miniroute = malloc ( sizeof ( *miniroute ) );
|
miniroute = malloc ( sizeof ( *miniroute ) );
|
||||||
if ( ! miniroute ) {
|
if ( ! miniroute ) {
|
||||||
DBG ( "IPv4 could not add miniroute\n" );
|
DBGC ( netdev, "IPv4 could not add miniroute\n" );
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -87,12 +87,13 @@ add_ipv4_miniroute ( struct net_device *netdev, struct in_addr address,
|
|||||||
* @v miniroute Routing table entry
|
* @v miniroute Routing table entry
|
||||||
*/
|
*/
|
||||||
static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
|
static void del_ipv4_miniroute ( struct ipv4_miniroute *miniroute ) {
|
||||||
|
struct net_device *netdev = miniroute->netdev;
|
||||||
|
|
||||||
DBG ( "IPv4 del %s", inet_ntoa ( miniroute->address ) );
|
DBGC ( netdev, "IPv4 del %s", inet_ntoa ( miniroute->address ) );
|
||||||
DBG ( "/%s ", inet_ntoa ( miniroute->netmask ) );
|
DBGC ( netdev, "/%s ", inet_ntoa ( miniroute->netmask ) );
|
||||||
if ( miniroute->gateway.s_addr )
|
if ( miniroute->gateway.s_addr )
|
||||||
DBG ( "gw %s ", inet_ntoa ( miniroute->gateway ) );
|
DBGC ( netdev, "gw %s ", inet_ntoa ( miniroute->gateway ) );
|
||||||
DBG ( "via %s\n", miniroute->netdev->name );
|
DBGC ( netdev, "via %s\n", miniroute->netdev->name );
|
||||||
|
|
||||||
netdev_put ( miniroute->netdev );
|
netdev_put ( miniroute->netdev );
|
||||||
list_del ( &miniroute->list );
|
list_del ( &miniroute->list );
|
||||||
@@ -143,7 +144,8 @@ static void ipv4_fragment_expired ( struct retry_timer *timer,
|
|||||||
container_of ( timer, struct ipv4_fragment, timer );
|
container_of ( timer, struct ipv4_fragment, timer );
|
||||||
struct iphdr *iphdr = frag->iobuf->data;
|
struct iphdr *iphdr = frag->iobuf->data;
|
||||||
|
|
||||||
DBG ( "IPv4 fragment %04x expired\n", ntohs ( iphdr->ident ) );
|
DBGC ( iphdr->src, "IPv4 fragment %04x expired\n",
|
||||||
|
ntohs ( iphdr->ident ) );
|
||||||
free_iob ( frag->iobuf );
|
free_iob ( frag->iobuf );
|
||||||
list_del ( &frag->list );
|
list_del ( &frag->list );
|
||||||
free ( frag );
|
free ( frag );
|
||||||
@@ -192,8 +194,9 @@ static struct io_buffer * ipv4_reassemble ( struct io_buffer *iobuf ) {
|
|||||||
/* Drop out-of-order fragments */
|
/* Drop out-of-order fragments */
|
||||||
expected_offset = ( frag ? frag->offset : 0 );
|
expected_offset = ( frag ? frag->offset : 0 );
|
||||||
if ( offset != expected_offset ) {
|
if ( offset != expected_offset ) {
|
||||||
DBG ( "IPv4 dropping out-of-sequence fragment %04x (%zd+%zd, "
|
DBGC ( iphdr->src, "IPv4 dropping out-of-sequence fragment "
|
||||||
"expected %zd)\n", ntohs ( iphdr->ident ), offset,
|
"%04x (%zd+%zd, expected %zd)\n",
|
||||||
|
ntohs ( iphdr->ident ), offset,
|
||||||
( iob_len ( iobuf ) - hdrlen ), expected_offset );
|
( iob_len ( iobuf ) - hdrlen ), expected_offset );
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
@@ -217,9 +220,9 @@ static struct io_buffer * ipv4_reassemble ( struct io_buffer *iobuf ) {
|
|||||||
new_iobuf = alloc_iob ( iob_len ( frag->iobuf ) +
|
new_iobuf = alloc_iob ( iob_len ( frag->iobuf ) +
|
||||||
iob_len ( iobuf ) );
|
iob_len ( iobuf ) );
|
||||||
if ( ! new_iobuf ) {
|
if ( ! new_iobuf ) {
|
||||||
DBG ( "IPv4 could not extend reassembly buffer to "
|
DBGC ( iphdr->src, "IPv4 could not extend reassembly "
|
||||||
"%zd bytes\n",
|
"buffer to %zd bytes\n",
|
||||||
( iob_len ( frag->iobuf ) + iob_len ( iobuf ) ) );
|
iob_len ( frag->iobuf ) + iob_len ( iobuf ) );
|
||||||
goto drop;
|
goto drop;
|
||||||
}
|
}
|
||||||
memcpy ( iob_put ( new_iobuf, iob_len ( frag->iobuf ) ),
|
memcpy ( iob_put ( new_iobuf, iob_len ( frag->iobuf ) ),
|
||||||
@@ -356,7 +359,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
|||||||
netdev = miniroute->netdev;
|
netdev = miniroute->netdev;
|
||||||
}
|
}
|
||||||
if ( ! netdev ) {
|
if ( ! netdev ) {
|
||||||
DBG ( "IPv4 has no route to %s\n", inet_ntoa ( iphdr->dest ) );
|
DBGC ( sin_dest->sin_addr, "IPv4 has no route to %s\n",
|
||||||
|
inet_ntoa ( iphdr->dest ) );
|
||||||
rc = -ENETUNREACH;
|
rc = -ENETUNREACH;
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -372,8 +376,8 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
|||||||
/* Determine link-layer destination address */
|
/* Determine link-layer destination address */
|
||||||
if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netmask, netdev,
|
if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netmask, netdev,
|
||||||
ll_dest ) ) != 0 ) {
|
ll_dest ) ) != 0 ) {
|
||||||
DBG ( "IPv4 has no link-layer address for %s: %s\n",
|
DBGC ( sin_dest->sin_addr, "IPv4 has no link-layer address for "
|
||||||
inet_ntoa ( next_hop ), strerror ( rc ) );
|
"%s: %s\n", inet_ntoa ( next_hop ), strerror ( rc ) );
|
||||||
/* Record error for diagnosis */
|
/* Record error for diagnosis */
|
||||||
netdev_tx_err ( netdev, iob_disown ( iobuf ), rc );
|
netdev_tx_err ( netdev, iob_disown ( iobuf ), rc );
|
||||||
goto err;
|
goto err;
|
||||||
@@ -385,16 +389,17 @@ static int ipv4_tx ( struct io_buffer *iobuf,
|
|||||||
iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
|
iphdr->chksum = tcpip_chksum ( iphdr, sizeof ( *iphdr ) );
|
||||||
|
|
||||||
/* Print IP4 header for debugging */
|
/* Print IP4 header for debugging */
|
||||||
DBG ( "IPv4 TX %s->", inet_ntoa ( iphdr->src ) );
|
DBGC2 ( sin_dest->sin_addr, "IPv4 TX %s->", inet_ntoa ( iphdr->src ) );
|
||||||
DBG ( "%s len %d proto %d id %04x csum %04x\n",
|
DBGC2 ( sin_dest->sin_addr, "%s len %d proto %d id %04x csum %04x\n",
|
||||||
inet_ntoa ( iphdr->dest ), ntohs ( iphdr->len ), iphdr->protocol,
|
inet_ntoa ( iphdr->dest ), ntohs ( iphdr->len ),
|
||||||
ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
iphdr->protocol, ntohs ( iphdr->ident ),
|
||||||
|
ntohs ( iphdr->chksum ) );
|
||||||
|
|
||||||
/* Hand off to link layer */
|
/* Hand off to link layer */
|
||||||
if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest,
|
if ( ( rc = net_tx ( iobuf, netdev, &ipv4_protocol, ll_dest,
|
||||||
netdev->ll_addr ) ) != 0 ) {
|
netdev->ll_addr ) ) != 0 ) {
|
||||||
DBG ( "IPv4 could not transmit packet via %s: %s\n",
|
DBGC ( sin_dest->sin_addr, "IPv4 could not transmit packet "
|
||||||
netdev->name, strerror ( rc ) );
|
"via %s: %s\n", netdev->name, strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -472,38 +477,39 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
|||||||
|
|
||||||
/* Sanity check the IPv4 header */
|
/* Sanity check the IPv4 header */
|
||||||
if ( iob_len ( iobuf ) < sizeof ( *iphdr ) ) {
|
if ( iob_len ( iobuf ) < sizeof ( *iphdr ) ) {
|
||||||
DBG ( "IPv4 packet too short at %zd bytes (min %zd bytes)\n",
|
DBGC ( iphdr->src, "IPv4 packet too short at %zd bytes (min "
|
||||||
iob_len ( iobuf ), sizeof ( *iphdr ) );
|
"%zd bytes)\n", iob_len ( iobuf ), sizeof ( *iphdr ) );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if ( ( iphdr->verhdrlen & IP_MASK_VER ) != IP_VER ) {
|
if ( ( iphdr->verhdrlen & IP_MASK_VER ) != IP_VER ) {
|
||||||
DBG ( "IPv4 version %#02x not supported\n", iphdr->verhdrlen );
|
DBGC ( iphdr->src, "IPv4 version %#02x not supported\n",
|
||||||
|
iphdr->verhdrlen );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
hdrlen = ( ( iphdr->verhdrlen & IP_MASK_HLEN ) * 4 );
|
hdrlen = ( ( iphdr->verhdrlen & IP_MASK_HLEN ) * 4 );
|
||||||
if ( hdrlen < sizeof ( *iphdr ) ) {
|
if ( hdrlen < sizeof ( *iphdr ) ) {
|
||||||
DBG ( "IPv4 header too short at %zd bytes (min %zd bytes)\n",
|
DBGC ( iphdr->src, "IPv4 header too short at %zd bytes (min "
|
||||||
hdrlen, sizeof ( *iphdr ) );
|
"%zd bytes)\n", hdrlen, sizeof ( *iphdr ) );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if ( hdrlen > iob_len ( iobuf ) ) {
|
if ( hdrlen > iob_len ( iobuf ) ) {
|
||||||
DBG ( "IPv4 header too long at %zd bytes "
|
DBGC ( iphdr->src, "IPv4 header too long at %zd bytes "
|
||||||
"(packet is %zd bytes)\n", hdrlen, iob_len ( iobuf ) );
|
"(packet is %zd bytes)\n", hdrlen, iob_len ( iobuf ) );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if ( ( csum = tcpip_chksum ( iphdr, hdrlen ) ) != 0 ) {
|
if ( ( csum = tcpip_chksum ( iphdr, hdrlen ) ) != 0 ) {
|
||||||
DBG ( "IPv4 checksum incorrect (is %04x including checksum "
|
DBGC ( iphdr->src, "IPv4 checksum incorrect (is %04x "
|
||||||
"field, should be 0000)\n", csum );
|
"including checksum field, should be 0000)\n", csum );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
len = ntohs ( iphdr->len );
|
len = ntohs ( iphdr->len );
|
||||||
if ( len < hdrlen ) {
|
if ( len < hdrlen ) {
|
||||||
DBG ( "IPv4 length too short at %zd bytes "
|
DBGC ( iphdr->src, "IPv4 length too short at %zd bytes "
|
||||||
"(header is %zd bytes)\n", len, hdrlen );
|
"(header is %zd bytes)\n", len, hdrlen );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
if ( len > iob_len ( iobuf ) ) {
|
if ( len > iob_len ( iobuf ) ) {
|
||||||
DBG ( "IPv4 length too long at %zd bytes "
|
DBGC ( iphdr->src, "IPv4 length too long at %zd bytes "
|
||||||
"(packet is %zd bytes)\n", len, iob_len ( iobuf ) );
|
"(packet is %zd bytes)\n", len, iob_len ( iobuf ) );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
@@ -512,8 +518,8 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
|||||||
iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
|
iob_unput ( iobuf, ( iob_len ( iobuf ) - len ) );
|
||||||
|
|
||||||
/* Print IPv4 header for debugging */
|
/* Print IPv4 header for debugging */
|
||||||
DBG ( "IPv4 RX %s<-", inet_ntoa ( iphdr->dest ) );
|
DBGC2 ( iphdr->src, "IPv4 RX %s<-", inet_ntoa ( iphdr->dest ) );
|
||||||
DBG ( "%s len %d proto %d id %04x csum %04x\n",
|
DBGC2 ( iphdr->src, "%s len %d proto %d id %04x csum %04x\n",
|
||||||
inet_ntoa ( iphdr->src ), ntohs ( iphdr->len ), iphdr->protocol,
|
inet_ntoa ( iphdr->src ), ntohs ( iphdr->len ), iphdr->protocol,
|
||||||
ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
|
||||||
|
|
||||||
@@ -521,8 +527,8 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
|||||||
if ( ( ! ( flags & LL_MULTICAST ) ) &&
|
if ( ( ! ( flags & LL_MULTICAST ) ) &&
|
||||||
ipv4_has_any_addr ( netdev ) &&
|
ipv4_has_any_addr ( netdev ) &&
|
||||||
( ! ipv4_has_addr ( netdev, iphdr->dest ) ) ) {
|
( ! ipv4_has_addr ( netdev, iphdr->dest ) ) ) {
|
||||||
DBG ( "IPv4 discarding non-local unicast packet for %s\n",
|
DBGC ( iphdr->src, "IPv4 discarding non-local unicast packet "
|
||||||
inet_ntoa ( iphdr->dest ) );
|
"for %s\n", inet_ntoa ( iphdr->dest ) );
|
||||||
goto err;
|
goto err;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -551,8 +557,8 @@ static int ipv4_rx ( struct io_buffer *iobuf,
|
|||||||
iob_pull ( iobuf, hdrlen );
|
iob_pull ( iobuf, hdrlen );
|
||||||
if ( ( rc = tcpip_rx ( iobuf, iphdr->protocol, &src.st,
|
if ( ( rc = tcpip_rx ( iobuf, iphdr->protocol, &src.st,
|
||||||
&dest.st, pshdr_csum ) ) != 0 ) {
|
&dest.st, pshdr_csum ) ) != 0 ) {
|
||||||
DBG ( "IPv4 received packet rejected by stack: %s\n",
|
DBGC ( src.sin.sin_addr, "IPv4 received packet rejected by "
|
||||||
strerror ( rc ) );
|
"stack: %s\n", strerror ( rc ) );
|
||||||
return rc;
|
return rc;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user