Browse Source

Improve debugging

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
1a1fc23417
1 changed files with 45 additions and 29 deletions
  1. 45
    29
      src/net/ipv4.c

+ 45
- 29
src/net/ipv4.c View File

47
 						    struct in_addr gateway ) {
47
 						    struct in_addr gateway ) {
48
 	struct ipv4_miniroute *miniroute;
48
 	struct ipv4_miniroute *miniroute;
49
 
49
 
50
+	DBG ( "IPv4 add %s", inet_ntoa ( address ) );
51
+	DBG ( "/%s ", inet_ntoa ( netmask ) );
52
+	if ( gateway.s_addr != INADDR_NONE )
53
+		DBG ( "gw %s ", inet_ntoa ( gateway ) );
54
+	DBG ( "via %s\n", netdev->name );
55
+
50
 	/* Allocate and populate miniroute structure */
56
 	/* Allocate and populate miniroute structure */
51
 	miniroute = malloc ( sizeof ( *miniroute ) );
57
 	miniroute = malloc ( sizeof ( *miniroute ) );
52
-	if ( miniroute ) {
53
-
54
-		DBG ( "IPv4 add %s", inet_ntoa ( address ) );
55
-		DBG ( "/%s ", inet_ntoa ( netmask ) );
56
-		if ( gateway.s_addr != INADDR_NONE )
57
-			DBG ( "gw %s ", inet_ntoa ( gateway ) );
58
-		DBG ( "via %s\n", netdev->name );
59
-
60
-		/* Record routing information */
61
-		miniroute->netdev = netdev;
62
-		miniroute->address = address;
63
-		miniroute->netmask = netmask;
64
-		miniroute->gateway = gateway;
65
-		
66
-		/* Add to end of list if we have a gateway, otherwise
67
-		 * to start of list.
68
-		 */
69
-		if ( gateway.s_addr != INADDR_NONE ) {
70
-			list_add_tail ( &miniroute->list, &ipv4_miniroutes );
71
-		} else {
72
-			list_add ( &miniroute->list, &ipv4_miniroutes );
73
-		}
58
+	if ( ! miniroute ) {
59
+		DBG ( "IPv4 could not add miniroute\n" );
60
+		return NULL;
61
+	}
74
 
62
 
75
-		/* Record reference to net_device */
76
-		miniroute->netdev_ref.forget = ipv4_forget_netdev;
77
-		ref_add ( &miniroute->netdev_ref, &netdev->references );
63
+	/* Record routing information */
64
+	miniroute->netdev = netdev;
65
+	miniroute->address = address;
66
+	miniroute->netmask = netmask;
67
+	miniroute->gateway = gateway;
68
+		
69
+	/* Add to end of list if we have a gateway, otherwise
70
+	 * to start of list.
71
+	 */
72
+	if ( gateway.s_addr != INADDR_NONE ) {
73
+		list_add_tail ( &miniroute->list, &ipv4_miniroutes );
74
+	} else {
75
+		list_add ( &miniroute->list, &ipv4_miniroutes );
78
 	}
76
 	}
79
 
77
 
78
+	/* Record reference to net_device */
79
+	miniroute->netdev_ref.forget = ipv4_forget_netdev;
80
+	ref_add ( &miniroute->netdev_ref, &netdev->references );
81
+
80
 	return miniroute;
82
 	return miniroute;
81
 }
83
 }
82
 
84
 
391
 	/* Determine link-layer destination address */
393
 	/* Determine link-layer destination address */
392
 	if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
394
 	if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
393
 				   ll_dest ) ) != 0 ) {
395
 				   ll_dest ) ) != 0 ) {
394
-		DBG ( "IPv4 has no link-layer address for %s\n",
395
-		      inet_ntoa ( iphdr->dest ) );
396
+		DBG ( "IPv4 has no link-layer address for %s: %s\n",
397
+		      inet_ntoa ( iphdr->dest ), strerror ( rc ) );
396
 		goto err;
398
 		goto err;
397
 	}
399
 	}
398
 
400
 
408
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
410
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
409
 
411
 
410
 	/* Hand off to link layer */
412
 	/* Hand off to link layer */
411
-	return net_tx ( pkb, netdev, &ipv4_protocol, ll_dest );
413
+	if ( ( rc = net_tx ( pkb, netdev, &ipv4_protocol, ll_dest ) ) != 0 ) {
414
+		DBG ( "IPv4 could not transmit packet via %s: %s\n",
415
+		      netdev->name, strerror ( rc ) );
416
+		return rc;
417
+	}
418
+
419
+	return 0;
412
 
420
 
413
  err:
421
  err:
414
 	free_pkb ( pkb );
422
 	free_pkb ( pkb );
436
 	} src, dest;
444
 	} src, dest;
437
 	uint16_t csum;
445
 	uint16_t csum;
438
 	uint16_t pshdr_csum;
446
 	uint16_t pshdr_csum;
447
+	int rc;
439
 
448
 
440
 	/* Sanity check the IPv4 header */
449
 	/* Sanity check the IPv4 header */
441
 	if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) {
450
 	if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) {
506
 	memset ( &dest, 0, sizeof ( dest ) );
515
 	memset ( &dest, 0, sizeof ( dest ) );
507
 	dest.sin.sin_family = AF_INET;
516
 	dest.sin.sin_family = AF_INET;
508
 	dest.sin.sin_addr = iphdr->dest;
517
 	dest.sin.sin_addr = iphdr->dest;
509
-	return tcpip_rx ( pkb, iphdr->protocol, &src.st, &dest.st, pshdr_csum);
518
+	if ( ( rc = tcpip_rx ( pkb, iphdr->protocol, &src.st,
519
+			       &dest.st, pshdr_csum ) ) != 0 ) {
520
+		DBG ( "IPv4 received packet rejected by stack: %s\n",
521
+		      strerror ( rc ) );
522
+		return rc;
523
+	}
524
+
525
+	return 0;
510
 
526
 
511
  err:
527
  err:
512
 	free_pkb ( pkb );
528
 	free_pkb ( pkb );

Loading…
Cancel
Save