Pārlūkot izejas kodu

Improve debugging

tags/v0.9.3
Michael Brown 18 gadus atpakaļ
vecāks
revīzija
1a1fc23417
1 mainītis faili ar 45 papildinājumiem un 29 dzēšanām
  1. 45
    29
      src/net/ipv4.c

+ 45
- 29
src/net/ipv4.c Parādīt failu

@@ -47,36 +47,38 @@ static struct ipv4_miniroute * add_ipv4_miniroute ( struct net_device *netdev,
47 47
 						    struct in_addr gateway ) {
48 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 56
 	/* Allocate and populate miniroute structure */
51 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 82
 	return miniroute;
81 83
 }
82 84
 
@@ -391,8 +393,8 @@ static int ipv4_tx ( struct pk_buff *pkb,
391 393
 	/* Determine link-layer destination address */
392 394
 	if ( ( rc = ipv4_ll_addr ( next_hop, iphdr->src, netdev,
393 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 398
 		goto err;
397 399
 	}
398 400
 
@@ -408,7 +410,13 @@ static int ipv4_tx ( struct pk_buff *pkb,
408 410
 	      ntohs ( iphdr->ident ), ntohs ( iphdr->chksum ) );
409 411
 
410 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 421
  err:
414 422
 	free_pkb ( pkb );
@@ -436,6 +444,7 @@ static int ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
436 444
 	} src, dest;
437 445
 	uint16_t csum;
438 446
 	uint16_t pshdr_csum;
447
+	int rc;
439 448
 
440 449
 	/* Sanity check the IPv4 header */
441 450
 	if ( pkb_len ( pkb ) < sizeof ( *iphdr ) ) {
@@ -506,7 +515,14 @@ static int ipv4_rx ( struct pk_buff *pkb, struct net_device *netdev __unused,
506 515
 	memset ( &dest, 0, sizeof ( dest ) );
507 516
 	dest.sin.sin_family = AF_INET;
508 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 527
  err:
512 528
 	free_pkb ( pkb );

Notiek ielāde…
Atcelt
Saglabāt