ソースを参照

Added some debug messages and DHCP test code

tags/v0.9.3
Michael Brown 18年前
コミット
6d9d48537e
3個のファイルの変更39行の追加1行の削除
  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 ファイルの表示

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

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

@@ -58,6 +58,26 @@ static uint8_t dhcp_request_options_data[] = {
58 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 81
 /** Options common to all DHCP requests */
62 82
 static struct dhcp_option_block dhcp_request_options = {
63 83
 	.data = dhcp_request_options_data,
@@ -419,6 +439,8 @@ static void dhcp_senddata ( struct udp_connection *conn,
419 439
 	struct dhcp_packet dhcppkt;
420 440
 	int rc;
421 441
 	
442
+	DBG ( "Transmitting %s\n", dhcp_message_type_name ( dhcp->state ) );
443
+
422 444
 	assert ( ( dhcp->state == DHCPDISCOVER ) ||
423 445
 		 ( dhcp->state == DHCPREQUEST ) );
424 446
 
@@ -455,7 +477,7 @@ static void dhcp_newdata ( struct udp_connection *conn,
455 477
 
456 478
 	/* Check for matching transaction ID */
457 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 481
 		      ntohl ( dhcphdr->xid ), ntohl ( dhcp->xid ) );
460 482
 		return;
461 483
 	};
@@ -467,6 +489,10 @@ static void dhcp_newdata ( struct udp_connection *conn,
467 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 496
 	/* Proof of concept: just dump out the parsed options */
471 497
 	hex_dump ( options->data, options->len );
472 498
 	free_dhcp_options ( options );

+ 10
- 0
src/tests/dhcptest.c ファイルの表示

@@ -0,0 +1,10 @@
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
+}

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