Browse Source

Use monojob and dhcp_configure_netdev().

tags/v0.9.3
Michael Brown 17 years ago
parent
commit
7d6e4aab6f
1 changed files with 19 additions and 68 deletions
  1. 19
    68
      src/usr/dhcpmgmt.c

+ 19
- 68
src/usr/dhcpmgmt.c View File

@@ -19,13 +19,10 @@
19 19
 #include <string.h>
20 20
 #include <stdio.h>
21 21
 #include <errno.h>
22
-#include <byteswap.h>
23
-#include <gpxe/in.h>
24
-#include <gpxe/ip.h>
25
-#include <gpxe/dhcp.h>
26
-#include <gpxe/async.h>
27 22
 #include <gpxe/netdevice.h>
28
-#include <gpxe/dns.h>
23
+#include <gpxe/dhcp.h>
24
+#include <gpxe/monojob.h>
25
+#include <gpxe/process.h>
29 26
 #include <usr/ifmgmt.h>
30 27
 #include <usr/dhcpmgmt.h>
31 28
 
@@ -35,85 +32,39 @@
35 32
  *
36 33
  */
37 34
 
38
-int dhcp ( struct net_device *netdev ) {
39
-	return -ENOTSUP;
40
-}
41
-
42
-#if 0
35
+static struct dhcp_option_block *dhcp_options = NULL;
43 36
 
44
-/* Avoid dragging in dns.o */
45
-struct sockaddr_tcpip nameserver;
46
-
47
-/* Avoid dragging in syslog.o */
48
-struct in_addr syslogserver;
37
+static int dhcp_success ( struct net_device *netdev,
38
+			  struct dhcp_option_block *options ) {
39
+	dhcp_options = dhcpopt_get ( options );
40
+	register_dhcp_options ( options );
41
+	return dhcp_configure_netdev ( netdev, options );
42
+}
49 43
 
50
-/**
51
- * Configure network device via DHCP
52
- *
53
- * @v netdev		Network device
54
- * @ret rc		Return status code
55
- */
56 44
 int dhcp ( struct net_device *netdev ) {
57
-	static struct dhcp_option_block *dhcp_options = NULL;
58
-	struct dhcp_session dhcp;
59
-	struct in_addr address = { 0 };
60
-	struct in_addr netmask = { 0 };
61
-	struct in_addr gateway = { INADDR_NONE };
62
-	struct sockaddr_in *sin_nameserver;
63
-	struct async async;
64 45
 	int rc;
65 46
 
66 47
 	/* Check we can open the interface first */
67 48
 	if ( ( rc = ifopen ( netdev ) ) != 0 )
68 49
 		return rc;
69 50
 
70
-	/* Free up any previously-acquired options */
51
+	/* Unregister any previously acquired options */
71 52
 	if ( dhcp_options ) {
72 53
 		unregister_dhcp_options ( dhcp_options );
73 54
 		dhcpopt_put ( dhcp_options );
74 55
 		dhcp_options = NULL;
75 56
 	}
76 57
 
77
-	/* Clear any existing routing table entry */
78
-	del_ipv4_address ( netdev );
79
-
80
-	/* Issue DHCP request */
58
+	/* Perform DHCP */
81 59
 	printf ( "DHCP (%s %s)...", netdev->name, netdev_hwaddr ( netdev ) );
82
-	memset ( &dhcp, 0, sizeof ( dhcp ) );
83
-	dhcp.netdev = netdev;
84
-	if ( ( rc = async_block ( &async,
85
-				  start_dhcp ( &dhcp, &async ) ) ) != 0 ) {
86
-		printf ( "failed (%s)\n", strerror ( rc ) );
87
-		return rc;
88
-	}
89
-	printf ( "done\n" );
90
-
91
-	/* Store and register options */
92
-	dhcp_options = dhcp.options;
93
-	register_dhcp_options ( dhcp_options );
94
-
95
-	/* Retrieve IP address configuration */
96
-	find_dhcp_ipv4_option ( dhcp_options, DHCP_EB_YIADDR, &address );
97
-	find_dhcp_ipv4_option ( dhcp_options, DHCP_SUBNET_MASK, &netmask );
98
-	find_dhcp_ipv4_option ( dhcp_options, DHCP_ROUTERS, &gateway );
60
+	if ( ( rc = start_dhcp ( &monojob, netdev, dhcp_success ) ) == 0 )
61
+		rc = monojob_wait();
99 62
 
100
-	/* Set up new IP address configuration */
101
-	if ( ( rc = add_ipv4_address ( netdev, address, netmask,
102
-				       gateway ) ) != 0 ) {
103
-		printf ( "Could not configure %s with DHCP results: %s\n",
104
-			 netdev->name, strerror ( rc ) );
105
-		return rc;
63
+	if ( rc == 0 ) {
64
+		printf ( "done\n" );
65
+	} else {
66
+		printf ( "failed (%s)\n", strerror ( rc ) );
106 67
 	}
107 68
 
108
-	/* Retrieve other DHCP options that we care about */
109
-	sin_nameserver = ( struct sockaddr_in * ) &nameserver;
110
-	sin_nameserver->sin_family = AF_INET;
111
-	find_dhcp_ipv4_option ( dhcp_options, DHCP_DNS_SERVERS,
112
-				&sin_nameserver->sin_addr );
113
-	find_dhcp_ipv4_option ( dhcp_options, DHCP_LOG_SERVERS,
114
-				&syslogserver );
115
-
116
-	return 0;
69
+	return rc;
117 70
 }
118
-
119
-#endif

Loading…
Cancel
Save