ソースを参照

Improved debugging

tags/v0.9.3
Michael Brown 17年前
コミット
835d35749f
1個のファイルの変更24行の追加15行の削除
  1. 24
    15
      src/net/udp/dhcp.c

+ 24
- 15
src/net/udp/dhcp.c ファイルの表示

@@ -387,6 +387,7 @@ static void merge_dhcp_field ( struct dhcp_option_block *options,
387 387
 /**
388 388
  * Parse DHCP packet and construct DHCP options block
389 389
  *
390
+ * @v dhcp		DHCP session
390 391
  * @v dhcphdr		DHCP packet
391 392
  * @v len		Length of DHCP packet
392 393
  * @ret options		DHCP options block, or NULL
@@ -406,7 +407,8 @@ static void merge_dhcp_field ( struct dhcp_option_block *options,
406 407
  * options block; it is the responsibility of the caller to eventually
407 408
  * free this memory.
408 409
  */
409
-static struct dhcp_option_block * dhcp_parse ( struct dhcphdr *dhcphdr,
410
+static struct dhcp_option_block * dhcp_parse ( struct dhcp_session *dhcp,
411
+					       struct dhcphdr *dhcphdr,
410 412
 					       size_t len ) {
411 413
 	struct dhcp_option_block *options;
412 414
 	size_t options_len;
@@ -441,8 +443,8 @@ static struct dhcp_option_block * dhcp_parse ( struct dhcphdr *dhcphdr,
441 443
 	/* Allocate empty options block of required size */
442 444
 	options = alloc_dhcp_options ( options_len );
443 445
 	if ( ! options ) {
444
-		DBG ( "DHCP could not allocate %d-byte option block\n",
445
-		      options_len );
446
+		DBGC ( dhcp, "DHCP %p could not allocate %d-byte option "
447
+		       "block\n", dhcp, options_len );
446 448
 		return NULL;
447 449
 	}
448 450
 	
@@ -546,7 +548,8 @@ static int dhcp_senddata ( struct udp_connection *conn,
546 548
 	struct dhcp_packet dhcppkt;
547 549
 	int rc;
548 550
 	
549
-	DBG ( "Transmitting %s\n", dhcp_msgtype_name ( dhcp->state ) );
551
+	DBGC ( dhcp, "DHCP %p transmitting %s\n",
552
+	       dhcp, dhcp_msgtype_name ( dhcp->state ) );
550 553
 
551 554
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
552 555
 		 ( dhcp->state == DHCPREQUEST ) );
@@ -554,14 +557,16 @@ static int dhcp_senddata ( struct udp_connection *conn,
554 557
 	/* Create DHCP packet in temporary buffer */
555 558
 	if ( ( rc = create_dhcp_packet ( dhcp->netdev, dhcp->state, buf, len,
556 559
 					 &dhcppkt ) ) != 0 ) {
557
-		DBG ( "Could not create DHCP packet\n" );
560
+		DBGC ( dhcp, "DHCP %p could not create DHCP packet: %s\n",
561
+		       dhcp, strerror ( rc ) );
558 562
 		return rc;
559 563
 	}
560 564
 
561 565
 	/* Copy in options common to all requests */
562 566
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
563 567
 					       &dhcp_request_options ) ) != 0){
564
-		DBG ( "Could not set common DHCP options\n" );
568
+		DBGC ( dhcp, "DHCP %p could not set common DHCP options: %s\n",
569
+		       dhcp, strerror ( rc ) );
565 570
 		return rc;
566 571
 	}
567 572
 
@@ -570,13 +575,15 @@ static int dhcp_senddata ( struct udp_connection *conn,
570 575
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
571 576
 					    DHCP_SERVER_IDENTIFIER,
572 577
 					    DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
573
-			DBG ( "Could not set server identifier option\n" );
578
+			DBGC ( dhcp, "DHCP %p could not set server identifier "
579
+			       "option: %s\n", dhcp, strerror ( rc ) );
574 580
 			return rc;
575 581
 		}
576 582
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
577 583
 					    DHCP_EB_YIADDR,
578 584
 					    DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
579
-			DBG ( "Could not set requested address option\n" );
585
+			DBGC ( dhcp, "DHCP %p could not set requested address "
586
+			       "option: %s\n", dhcp, strerror ( rc ) );
580 587
 			return rc;
581 588
 		}
582 589
 	}
@@ -584,7 +591,8 @@ static int dhcp_senddata ( struct udp_connection *conn,
584 591
 	/* Transmit the packet */
585 592
 	if ( ( rc = udp_sendto_via ( conn, &sa_dhcp_server.st, dhcp->netdev,
586 593
 				     dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
587
-		DBG ( "Could not transmit UDP packet\n" );
594
+		DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
595
+		       dhcp, strerror ( rc ) );
588 596
 		return rc;
589 597
 	}
590 598
 
@@ -637,22 +645,23 @@ static int dhcp_newdata ( struct udp_connection *conn, void *data, size_t len,
637 645
 
638 646
 	/* Check for matching transaction ID */
639 647
 	if ( dhcphdr->xid != dhcp_xid ( dhcp->netdev ) ) {
640
-		DBG ( "DHCP wrong transaction ID (wanted %08lx, got %08lx)\n",
641
-		      ntohl ( dhcphdr->xid ),
642
-		      ntohl ( dhcp_xid ( dhcp->netdev ) ) );
648
+		DBGC ( dhcp, "DHCP %p wrong transaction ID (wanted %08lx, "
649
+			"got %08lx)\n", dhcp, ntohl ( dhcphdr->xid ),
650
+			ntohl ( dhcp_xid ( dhcp->netdev ) ) );
643 651
 		return 0;
644 652
 	};
645 653
 
646 654
 	/* Parse packet and create options structure */
647
-	options = dhcp_parse ( dhcphdr, len );
655
+	options = dhcp_parse ( dhcp, dhcphdr, len );
648 656
 	if ( ! options ) {
649
-		DBG ( "Could not parse DHCP packet\n" );
657
+		DBGC ( dhcp, "DHCP %p could not parse DHCP packet\n", dhcp );
650 658
 		return -EINVAL;
651 659
 	}
652 660
 
653 661
 	/* Determine message type */
654 662
 	msgtype = find_dhcp_num_option ( options, DHCP_MESSAGE_TYPE );
655
-	DBG ( "Received %s\n", dhcp_msgtype_name ( msgtype ) );
663
+	DBGC ( dhcp, "DHCP %p received %s\n",
664
+	       dhcp, dhcp_msgtype_name ( msgtype ) );
656 665
 
657 666
 	/* Handle DHCP reply */
658 667
 	switch ( dhcp->state ) {

読み込み中…
キャンセル
保存