Improve debugging

pull/1/head
Michael Brown 2007-01-16 03:29:15 +00:00
parent bcdb6fad3e
commit 1a1fc23417
1 changed files with 46 additions and 30 deletions

View File

@ -47,16 +47,19 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
struct in_addr gateway ) { struct in_addr gateway ) {
struct ipv4_miniroute *miniroute; struct ipv4_miniroute *miniroute;
/* Allocate and populate miniroute structure */
miniroute = malloc ( sizeof ( *miniroute ) );
if ( miniroute ) {
DBG ( "IPv4 add %s", inet_ntoa ( address ) ); DBG ( "IPv4 add %s", inet_ntoa ( address ) );
DBG ( "/%s ", inet_ntoa ( netmask ) ); DBG ( "/%s ", inet_ntoa ( netmask ) );
if ( gateway.s_addr != INADDR_NONE ) if ( gateway.s_addr != INADDR_NONE )
DBG ( "gw %s ", inet_ntoa ( gateway ) ); DBG ( "gw %s ", inet_ntoa ( gateway ) );
DBG ( "via %s\n", netdev->name ); DBG ( "via %s\n", netdev->name );
/* Allocate and populate miniroute structure */
miniroute = malloc ( sizeof ( *miniroute ) );
if ( ! miniroute ) {
DBG ( "IPv4 could not add miniroute\n" );
return NULL;
}
/* Record routing information */ /* Record routing information */
miniroute->netdev = netdev; miniroute->netdev = netdev;
miniroute->address = address; miniroute->address = address;
@ -75,7 +78,6 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
/* Record reference to net_device */ /* Record reference to net_device */
miniroute->netdev_ref.forget = ipv4_forget_netdev; miniroute->netdev_ref.forget = ipv4_forget_netdev;
ref_add ( &miniroute->netdev_ref, &netdev->references ); ref_add ( &miniroute->netdev_ref, &netdev->references );
}
return miniroute; return miniroute;
} }
@ -391,8 +393,8 @@ static int ipv4_tx ( struct pk_buff *pkb,
/* Determine link-layer destination address */ /* Determine link-layer destination address */
if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev, if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
ll_dest ) ) != 0 ) { ll_dest ) ) != 0 ) {
DBG ( "IPv4 has no link-layer address for %s\n", DBG ( "IPv4 has no link-layer address for %s: %s\n",
inet_ntoa ( iphdr->dest ) ); inet_ntoa ( iphdr->dest ), strerror ( rc ) );
goto err; goto err;
} }
@ -408,7 +410,13 @@ static int ipv4_tx ( struct pk_buff *pkb,
ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) ); ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
/* Hand off to link layer */ /* Hand off to link layer */
return net_tx ( pkb, netdev, &ipv4_protocol, ll_dest ); if ( ( rc = net_tx ( pkb, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
DBG ( "IPv4 could not transmit packet via %s: %s\n",
netdev->name, strerror ( rc ) );
return rc;
}
return 0;
err: err:
free_pkb ( pkb ); free_pkb ( pkb );
@ -436,6 +444,7 @@ static int ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
} src, dest; } src, dest;
uint16_t csum; uint16_t csum;
uint16_t pshdr_csum; uint16_t pshdr_csum;
int rc;
/* Sanity check the IPv4 header */ /* Sanity check the IPv4 header */
if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) { if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) {
@ -506,7 +515,14 @@ static int ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
memset ( &dest, 0, sizeof ( dest ) ); memset ( &dest, 0, sizeof ( dest ) );
dest.sin.sin_family = AF_INET; dest.sin.sin_family = AF_INET;
dest.sin.sin_addr = iphdr->dest; dest.sin.sin_addr = iphdr->dest;
return tcpip_rx ( pkb, iphdr->protocol, &src.st, &dest.st, pshdr_csum); if ( ( rc = tcpip_rx ( pkb, iphdr->protocol, &src.st,
&dest.st, pshdr_csum ) ) != 0 ) {
DBG ( "IPv4 received packet rejected by stack: %s\n",
strerror ( rc ) );
return rc;
}
return 0;
err: err:
free_pkb ( pkb ); free_pkb ( pkb );