Browse Source

Added some debug messages and DHCP test code

tags/v0.9.3
Michael Brown 18 years ago
parent
commit
6d9d48537e
3 changed files with 39 additions and 1 deletions
  1. 2
    0
      src/include/gpxe/dhcp.h
  2. 27
    1
      src/net/udp/dhcp.c
  3. 10
    0
      src/tests/dhcptest.c

+ 2
- 0
src/include/gpxe/dhcp.h View File

433
 extern void delete_dhcp_option ( struct dhcp_option_block *options,
433
 extern void delete_dhcp_option ( struct dhcp_option_block *options,
434
 				 unsigned int tag );
434
 				 unsigned int tag );
435
 
435
 
436
+extern struct async_operation * start_dhcp ( struct dhcp_session *dhcp );
437
+
436
 #endif /* _GPXE_DHCP_H */
438
 #endif /* _GPXE_DHCP_H */

+ 27
- 1
src/net/udp/dhcp.c View File

58
 	DHCP_END
58
 	DHCP_END
59
 };
59
 };
60
 
60
 
61
+/**
62
+ * Name a DHCP packet type
63
+ *
64
+ * @v msgtype		DHCP message type
65
+ * @ret string		DHCP mesasge type name
66
+ */
67
+static inline const char * dhcp_message_type_name ( unsigned int msgtype ) {
68
+	switch ( msgtype ) {
69
+	case DHCPDISCOVER:	return "DHCPDISCOVER";
70
+	case DHCPOFFER:		return "DHCPOFFER";
71
+	case DHCPREQUEST:	return "DHCPREQUEST";
72
+	case DHCPDECLINE:	return "DHCPDECLINE";
73
+	case DHCPACK:		return "DHCPACK";
74
+	case DHCPNAK:		return "DHCPNAK";
75
+	case DHCPRELEASE:	return "DHCPRELEASE";
76
+	case DHCPINFORM:	return "DHCPINFORM";
77
+	default:		return "DHCP<invalid>";
78
+	}
79
+}
80
+
61
 /** Options common to all DHCP requests */
81
 /** Options common to all DHCP requests */
62
 static struct dhcp_option_block dhcp_request_options = {
82
 static struct dhcp_option_block dhcp_request_options = {
63
 	.data = dhcp_request_options_data,
83
 	.data = dhcp_request_options_data,
419
 	struct dhcp_packet dhcppkt;
439
 	struct dhcp_packet dhcppkt;
420
 	int rc;
440
 	int rc;
421
 	
441
 	
442
+	DBG ( "Transmitting %s\n", dhcp_message_type_name ( dhcp->state ) );
443
+
422
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
444
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
423
 		 ( dhcp->state == DHCPREQUEST ) );
445
 		 ( dhcp->state == DHCPREQUEST ) );
424
 
446
 
455
 
477
 
456
 	/* Check for matching transaction ID */
478
 	/* Check for matching transaction ID */
457
 	if ( dhcphdr->xid != dhcp->xid ) {
479
 	if ( dhcphdr->xid != dhcp->xid ) {
458
-		DBG ( "DHCP wrong transaction ID (wanted %08x, got %08x)\n",
480
+		DBG ( "DHCP wrong transaction ID (wanted %08lx, got %08lx)\n",
459
 		      ntohl ( dhcphdr->xid ), ntohl ( dhcp->xid ) );
481
 		      ntohl ( dhcphdr->xid ), ntohl ( dhcp->xid ) );
460
 		return;
482
 		return;
461
 	};
483
 	};
467
 		return;
489
 		return;
468
 	}
490
 	}
469
 
491
 
492
+	DBG ( "Received %s\n",
493
+	      dhcp_message_type_name ( find_dhcp_num_option ( options,
494
+						       DHCP_MESSAGE_TYPE ) ) );
495
+
470
 	/* Proof of concept: just dump out the parsed options */
496
 	/* Proof of concept: just dump out the parsed options */
471
 	hex_dump ( options->data, options->len );
497
 	hex_dump ( options->data, options->len );
472
 	free_dhcp_options ( options );
498
 	free_dhcp_options ( options );

+ 10
- 0
src/tests/dhcptest.c View File

1
+#include <string.h>
2
+#include <gpxe/dhcp.h>
3
+
4
+int test_dhcp ( struct net_device *netdev ) {
5
+	struct dhcp_session dhcp;
6
+
7
+	memset ( &dhcp, 0, sizeof ( dhcp ) );
8
+	dhcp.netdev = netdev;
9
+	return async_wait ( start_dhcp ( &dhcp ) );
10
+}

Loading…
Cancel
Save