Browse Source

Improved debugging

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
835d35749f
1 changed files with 24 additions and 15 deletions
  1. 24
    15
      src/net/udp/dhcp.c

+ 24
- 15
src/net/udp/dhcp.c View File

387
 /**
387
 /**
388
  * Parse DHCP packet and construct DHCP options block
388
  * Parse DHCP packet and construct DHCP options block
389
  *
389
  *
390
+ * @v dhcp		DHCP session
390
  * @v dhcphdr		DHCP packet
391
  * @v dhcphdr		DHCP packet
391
  * @v len		Length of DHCP packet
392
  * @v len		Length of DHCP packet
392
  * @ret options		DHCP options block, or NULL
393
  * @ret options		DHCP options block, or NULL
406
  * options block; it is the responsibility of the caller to eventually
407
  * options block; it is the responsibility of the caller to eventually
407
  * free this memory.
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
 					       size_t len ) {
412
 					       size_t len ) {
411
 	struct dhcp_option_block *options;
413
 	struct dhcp_option_block *options;
412
 	size_t options_len;
414
 	size_t options_len;
441
 	/* Allocate empty options block of required size */
443
 	/* Allocate empty options block of required size */
442
 	options = alloc_dhcp_options ( options_len );
444
 	options = alloc_dhcp_options ( options_len );
443
 	if ( ! options ) {
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
 		return NULL;
448
 		return NULL;
447
 	}
449
 	}
448
 	
450
 	
546
 	struct dhcp_packet dhcppkt;
548
 	struct dhcp_packet dhcppkt;
547
 	int rc;
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
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
554
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
552
 		 ( dhcp->state == DHCPREQUEST ) );
555
 		 ( dhcp->state == DHCPREQUEST ) );
554
 	/* Create DHCP packet in temporary buffer */
557
 	/* Create DHCP packet in temporary buffer */
555
 	if ( ( rc = create_dhcp_packet ( dhcp->netdev, dhcp->state, buf, len,
558
 	if ( ( rc = create_dhcp_packet ( dhcp->netdev, dhcp->state, buf, len,
556
 					 &dhcppkt ) ) != 0 ) {
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
 		return rc;
562
 		return rc;
559
 	}
563
 	}
560
 
564
 
561
 	/* Copy in options common to all requests */
565
 	/* Copy in options common to all requests */
562
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
566
 	if ( ( rc = copy_dhcp_packet_options ( &dhcppkt,
563
 					       &dhcp_request_options ) ) != 0){
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
 		return rc;
570
 		return rc;
566
 	}
571
 	}
567
 
572
 
570
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
575
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
571
 					    DHCP_SERVER_IDENTIFIER,
576
 					    DHCP_SERVER_IDENTIFIER,
572
 					    DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
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
 			return rc;
580
 			return rc;
575
 		}
581
 		}
576
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
582
 		if ( ( rc = copy_dhcp_packet_option ( &dhcppkt, dhcp->options,
577
 					    DHCP_EB_YIADDR,
583
 					    DHCP_EB_YIADDR,
578
 					    DHCP_REQUESTED_ADDRESS ) ) != 0 ) {
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
 			return rc;
587
 			return rc;
581
 		}
588
 		}
582
 	}
589
 	}
584
 	/* Transmit the packet */
591
 	/* Transmit the packet */
585
 	if ( ( rc = udp_sendto_via ( conn, &sa_dhcp_server.st, dhcp->netdev,
592
 	if ( ( rc = udp_sendto_via ( conn, &sa_dhcp_server.st, dhcp->netdev,
586
 				     dhcppkt.dhcphdr, dhcppkt.len ) ) != 0 ) {
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
 		return rc;
596
 		return rc;
589
 	}
597
 	}
590
 
598
 
637
 
645
 
638
 	/* Check for matching transaction ID */
646
 	/* Check for matching transaction ID */
639
 	if ( dhcphdr->xid != dhcp_xid ( dhcp->netdev ) ) {
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
 		return 0;
651
 		return 0;
644
 	};
652
 	};
645
 
653
 
646
 	/* Parse packet and create options structure */
654
 	/* Parse packet and create options structure */
647
-	options = dhcp_parse ( dhcphdr, len );
655
+	options = dhcp_parse ( dhcp, dhcphdr, len );
648
 	if ( ! options ) {
656
 	if ( ! options ) {
649
-		DBG ( "Could not parse DHCP packet\n" );
657
+		DBGC ( dhcp, "DHCP %p could not parse DHCP packet\n", dhcp );
650
 		return -EINVAL;
658
 		return -EINVAL;
651
 	}
659
 	}
652
 
660
 
653
 	/* Determine message type */
661
 	/* Determine message type */
654
 	msgtype = find_dhcp_num_option ( options, DHCP_MESSAGE_TYPE );
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
 	/* Handle DHCP reply */
666
 	/* Handle DHCP reply */
658
 	switch ( dhcp->state ) {
667
 	switch ( dhcp->state ) {

Loading…
Cancel
Save