2 * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of the
7 * License, or any later version.
9 * This program is distributed in the hope that it will be useful, but
10 * WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program; if not, write to the Free Software
16 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
25 #include <gpxe/if_ether.h>
26 #include <gpxe/netdevice.h>
27 #include <gpxe/device.h>
28 #include <gpxe/xfer.h>
29 #include <gpxe/open.h>
31 #include <gpxe/retry.h>
32 #include <gpxe/tcpip.h>
34 #include <gpxe/uuid.h>
35 #include <gpxe/dhcp.h>
36 #include <gpxe/timer.h>
37 #include <gpxe/settings.h>
38 #include <gpxe/dhcp.h>
39 #include <gpxe/dhcpopts.h>
40 #include <gpxe/dhcppkt.h>
44 * Dynamic Host Configuration Protocol
49 * DHCP operation types
51 * This table maps from DHCP message types (i.e. values of the @c
52 * DHCP_MESSAGE_TYPE option) to values of the "op" field within a DHCP
55 static const uint8_t dhcp_op[] = {
56 [DHCPDISCOVER] = BOOTP_REQUEST,
57 [DHCPOFFER] = BOOTP_REPLY,
58 [DHCPREQUEST] = BOOTP_REQUEST,
59 [DHCPDECLINE] = BOOTP_REQUEST,
60 [DHCPACK] = BOOTP_REPLY,
61 [DHCPNAK] = BOOTP_REPLY,
62 [DHCPRELEASE] = BOOTP_REQUEST,
63 [DHCPINFORM] = BOOTP_REQUEST,
66 /** Raw option data for options common to all DHCP requests */
67 static uint8_t dhcp_request_options_data[] = {
68 DHCP_MAX_MESSAGE_SIZE, DHCP_WORD ( ETH_MAX_MTU ),
70 DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':',
71 'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '0', ':',
72 'U', 'N', 'D', 'I', ':', '0', '0', '2', '0', '0', '1' ),
73 DHCP_CLIENT_ARCHITECTURE, DHCP_WORD ( 0 ),
74 DHCP_CLIENT_NDI, DHCP_OPTION ( 1 /* UNDI */ , 2, 1 /* v2.1 */ ),
75 DHCP_PARAMETER_REQUEST_LIST,
76 DHCP_OPTION ( DHCP_SUBNET_MASK, DHCP_ROUTERS, DHCP_DNS_SERVERS,
77 DHCP_LOG_SERVERS, DHCP_HOST_NAME, DHCP_DOMAIN_NAME,
78 DHCP_ROOT_PATH, DHCP_VENDOR_ENCAP, DHCP_VENDOR_CLASS_ID,
79 DHCP_TFTP_SERVER_NAME, DHCP_BOOTFILE_NAME,
80 DHCP_EB_ENCAP, DHCP_ISCSI_INITIATOR_IQN ),
84 /** Options common to all DHCP requests */
85 static struct dhcp_options dhcp_request_options = {
86 .data = dhcp_request_options_data,
87 .max_len = sizeof ( dhcp_request_options_data ),
88 .len = sizeof ( dhcp_request_options_data ),
91 /** DHCP feature codes */
92 static uint8_t dhcp_features[0] __table_start ( uint8_t, dhcp_features );
93 static uint8_t dhcp_features_end[0] __table_end ( uint8_t, dhcp_features );
96 * Name a DHCP packet type
98 * @v msgtype DHCP message type
99 * @ret string DHCP mesasge type name
101 static inline const char * dhcp_msgtype_name ( unsigned int msgtype ) {
103 case 0: return "BOOTP"; /* Non-DHCP packet */
104 case DHCPDISCOVER: return "DHCPDISCOVER";
105 case DHCPOFFER: return "DHCPOFFER";
106 case DHCPREQUEST: return "DHCPREQUEST";
107 case DHCPDECLINE: return "DHCPDECLINE";
108 case DHCPACK: return "DHCPACK";
109 case DHCPNAK: return "DHCPNAK";
110 case DHCPRELEASE: return "DHCPRELEASE";
111 case DHCPINFORM: return "DHCPINFORM";
112 default: return "DHCP<invalid>";
117 * Calculate DHCP transaction ID for a network device
119 * @v netdev Network device
122 * Extract the least significant bits of the hardware address for use
123 * as the transaction ID.
125 static uint32_t dhcp_xid ( struct net_device *netdev ) {
128 memcpy ( &xid, ( netdev->ll_addr + netdev->ll_protocol->ll_addr_len
129 - sizeof ( xid ) ), sizeof ( xid ) );
134 * Create a DHCP packet
136 * @v dhcppkt DHCP packet structure to fill in
137 * @v netdev Network device
138 * @v msgtype DHCP message type
139 * @v options Initial options to include (or NULL)
140 * @v data Buffer for DHCP packet
141 * @v max_len Size of DHCP packet buffer
142 * @ret rc Return status code
144 * Creates a DHCP packet in the specified buffer, and fills out a @c
145 * dhcp_packet structure that can be passed to
146 * set_dhcp_packet_option() or copy_dhcp_packet_options().
148 static int create_dhcp_packet ( struct dhcp_packet *dhcppkt,
149 struct net_device *netdev, uint8_t msgtype,
150 struct dhcp_options *options,
151 void *data, size_t max_len ) {
152 struct dhcphdr *dhcphdr = data;
158 options_len = ( options ? options->len : 0 );
159 if ( max_len < ( sizeof ( *dhcphdr ) + options_len ) )
162 /* Initialise DHCP packet content */
164 /* FIXME: wrong place to fix this. */
165 memset ( dhcppkt, 0, sizeof ( *dhcppkt ) );
167 memset ( dhcphdr, 0, max_len );
168 dhcphdr->xid = dhcp_xid ( netdev );
169 dhcphdr->magic = htonl ( DHCP_MAGIC_COOKIE );
170 dhcphdr->htype = ntohs ( netdev->ll_protocol->ll_proto );
171 dhcphdr->op = dhcp_op[msgtype];
172 /* If hardware length exceeds the chaddr field length, don't
173 * use the chaddr field. This is as per RFC4390.
175 hlen = netdev->ll_protocol->ll_addr_len;
176 if ( hlen > sizeof ( dhcphdr->chaddr ) ) {
178 dhcphdr->flags = htons ( BOOTP_FL_BROADCAST );
180 dhcphdr->hlen = hlen;
181 memcpy ( dhcphdr->chaddr, netdev->ll_addr, hlen );
182 memcpy ( dhcphdr->options, options->data, options_len );
184 /* Initialise DHCP packet structure and settings interface */
185 dhcppkt_init ( dhcppkt, NULL, data, max_len );
187 /* Set DHCP_MESSAGE_TYPE option */
188 if ( ( rc = store_setting ( &dhcppkt->settings, DHCP_MESSAGE_TYPE,
189 &msgtype, sizeof ( msgtype ) ) ) != 0 )
195 /** DHCP network device descriptor */
196 struct dhcp_netdev_desc {
203 } __attribute__ (( packed ));
205 /** DHCP client identifier */
206 struct dhcp_client_id {
207 /** Link-layer protocol */
209 /** Link-layer address */
210 uint8_t ll_addr[MAX_LL_ADDR_LEN];
211 } __attribute__ (( packed ));
213 /** DHCP client UUID */
214 struct dhcp_client_uuid {
215 /** Identifier type */
219 } __attribute__ (( packed ));
221 #define DHCP_CLIENT_UUID_TYPE 0
224 * Create DHCP request
226 * @v dhcppkt DHCP packet structure to fill in
227 * @v netdev Network device
228 * @v msgtype DHCP message type
229 * @v offer_settings Settings received in DHCPOFFER, or NULL
230 * @v data Buffer for DHCP packet
231 * @v max_len Size of DHCP packet buffer
232 * @ret rc Return status code
234 int create_dhcp_request ( struct dhcp_packet *dhcppkt,
235 struct net_device *netdev, int msgtype,
236 struct settings *offer_settings,
237 void *data, size_t max_len ) {
238 struct device_description *desc = &netdev->dev->desc;
239 struct dhcp_netdev_desc dhcp_desc;
240 struct dhcp_client_id client_id;
241 struct dhcp_client_uuid client_uuid;
242 size_t dhcp_features_len;
246 /* Create DHCP packet */
247 if ( ( rc = create_dhcp_packet ( dhcppkt, netdev, msgtype,
248 &dhcp_request_options, data,
250 DBG ( "DHCP could not create DHCP packet: %s\n",
255 /* Copy any required options from previous server repsonse */
256 if ( offer_settings ) {
257 if ( ( rc = copy_setting ( &dhcppkt->settings,
258 DHCP_SERVER_IDENTIFIER,
260 DHCP_SERVER_IDENTIFIER ) ) != 0 ) {
261 DBG ( "DHCP could not set server identifier "
262 "option: %s\n", strerror ( rc ) );
265 if ( ( rc = copy_setting ( &dhcppkt->settings,
266 DHCP_REQUESTED_ADDRESS,
268 DHCP_EB_YIADDR ) ) != 0 ) {
269 DBG ( "DHCP could not set requested address "
270 "option: %s\n", strerror ( rc ) );
275 /* Add options to identify the feature list */
276 dhcp_features_len = ( dhcp_features_end - dhcp_features );
277 if ( ( rc = store_setting ( &dhcppkt->settings, DHCP_EB_ENCAP,
278 dhcp_features, dhcp_features_len ) ) !=0 ){
279 DBG ( "DHCP could not set features list option: %s\n",
284 /* Add options to identify the network device */
285 dhcp_desc.type = desc->bus_type;
286 dhcp_desc.vendor = htons ( desc->vendor );
287 dhcp_desc.device = htons ( desc->device );
288 if ( ( rc = store_setting ( &dhcppkt->settings, DHCP_EB_BUS_ID,
289 &dhcp_desc, sizeof ( dhcp_desc ) ) ) !=0 ){
290 DBG ( "DHCP could not set bus ID option: %s\n",
295 /* Add DHCP client identifier. Required for Infiniband, and
296 * doesn't hurt other link layers.
298 client_id.ll_proto = ntohs ( netdev->ll_protocol->ll_proto );
299 ll_addr_len = netdev->ll_protocol->ll_addr_len;
300 assert ( ll_addr_len <= sizeof ( client_id.ll_addr ) );
301 memcpy ( client_id.ll_addr, netdev->ll_addr, ll_addr_len );
302 if ( ( rc = store_setting ( &dhcppkt->settings, DHCP_CLIENT_ID,
303 &client_id, ( ll_addr_len + 1 ) ) ) != 0 ){
304 DBG ( "DHCP could not set client ID: %s\n",
309 /* Add client UUID, if we have one. Required for PXE. */
310 client_uuid.type = DHCP_CLIENT_UUID_TYPE;
311 if ( ( rc = get_uuid ( &client_uuid.uuid ) ) == 0 ) {
312 if ( ( rc = store_setting ( &dhcppkt->settings,
313 DHCP_CLIENT_UUID, &client_uuid,
314 sizeof ( client_uuid ) ) ) != 0 ) {
315 DBG ( "DHCP could not set client UUID: %s\n",
325 * Create DHCP response
327 * @v dhcppkt DHCP packet structure to fill in
328 * @v netdev Network device
329 * @v msgtype DHCP message type
330 * @v settings Settings to include, or NULL
331 * @v data Buffer for DHCP packet
332 * @v max_len Size of DHCP packet buffer
333 * @ret rc Return status code
335 int create_dhcp_response ( struct dhcp_packet *dhcppkt,
336 struct net_device *netdev, int msgtype,
337 struct settings *settings,
338 void *data, size_t max_len ) {
341 /* Create packet and copy in options */
342 if ( ( rc = create_dhcp_packet ( dhcppkt, netdev, msgtype, NULL,
343 data, max_len ) ) != 0 )
345 if ( ( rc = copy_settings ( &dhcppkt->settings, settings ) ) != 0 )
351 /****************************************************************************
353 * DHCP packets contained in I/O buffers
357 /** A DHCP packet contained in an I/O buffer */
358 struct dhcp_iobuf_packet {
359 /** Reference counter */
360 struct refcnt refcnt;
362 struct dhcp_packet dhcppkt;
363 /** Containing I/O buffer */
364 struct io_buffer *iobuf;
368 * Free DHCP packet contained in an I/O buffer
370 * @v refcnt Reference counter
372 static void dhcpiob_free ( struct refcnt *refcnt ) {
373 struct dhcp_iobuf_packet *dhcpiob =
374 container_of ( refcnt, struct dhcp_iobuf_packet, refcnt );
376 free_iob ( dhcpiob->iobuf );
381 * Create DHCP packet from I/O buffer
383 * @v iobuf I/O buffer
384 * @ret dhcpiob DHCP packet contained in I/O buffer
386 * This function takes ownership of the I/O buffer. Future accesses
387 * must be via the @c dhcpiob data structure.
389 static struct dhcp_iobuf_packet * dhcpiob_create ( struct io_buffer *iobuf ) {
390 struct dhcp_iobuf_packet *dhcpiob;
392 dhcpiob = zalloc ( sizeof ( *dhcpiob ) );
394 dhcpiob->refcnt.free = dhcpiob_free;
395 dhcpiob->iobuf = iobuf;
396 dhcppkt_init ( &dhcpiob->dhcppkt, &dhcpiob->refcnt,
397 iobuf->data, iob_len ( iobuf ) );
402 static void dhcpiob_put ( struct dhcp_iobuf_packet *dhcpiob ) {
404 ref_put ( &dhcpiob->refcnt );
407 /****************************************************************************
409 * DHCP to UDP interface
413 /** A DHCP session */
414 struct dhcp_session {
415 /** Reference counter */
416 struct refcnt refcnt;
417 /** Job control interface */
418 struct job_interface job;
419 /** Data transfer interface */
420 struct xfer_interface xfer;
422 /** Network device being configured */
423 struct net_device *netdev;
425 /** State of the session
427 * This is a value for the @c DHCP_MESSAGE_TYPE option
428 * (e.g. @c DHCPDISCOVER).
431 /** Response obtained from DHCP server */
432 struct dhcp_iobuf_packet *response;
433 /** Response obtained from ProxyDHCP server */
434 struct dhcp_iobuf_packet *proxy_response;
435 /** Retransmission timer */
436 struct retry_timer timer;
437 /** Session start time (in ticks) */
444 * @v refcnt Reference counter
446 static void dhcp_free ( struct refcnt *refcnt ) {
447 struct dhcp_session *dhcp =
448 container_of ( refcnt, struct dhcp_session, refcnt );
450 netdev_put ( dhcp->netdev );
451 dhcpiob_put ( dhcp->response );
452 dhcpiob_put ( dhcp->proxy_response );
457 * Mark DHCP session as complete
459 * @v dhcp DHCP session
460 * @v rc Return status code
462 static void dhcp_finished ( struct dhcp_session *dhcp, int rc ) {
464 /* Block futher incoming messages */
465 job_nullify ( &dhcp->job );
466 xfer_nullify ( &dhcp->xfer );
468 /* Stop retry timer */
469 stop_timer ( &dhcp->timer );
471 /* Free resources and close interfaces */
472 xfer_close ( &dhcp->xfer, rc );
473 job_done ( &dhcp->job, rc );
477 * Register options received via DHCP
479 * @v dhcp DHCP session
480 * @ret rc Return status code
482 static int dhcp_register_settings ( struct dhcp_session *dhcp ) {
483 struct settings *settings;
484 struct settings *parent;
487 if ( dhcp->proxy_response ) {
488 settings = &dhcp->proxy_response->dhcppkt.settings;
489 if ( ( rc = register_settings ( settings, NULL ) ) != 0 )
493 settings = &dhcp->response->dhcppkt.settings;
494 parent = netdev_settings ( dhcp->netdev );
495 if ( ( rc = register_settings ( settings, parent ) ) != 0 )
501 /****************************************************************************
503 * Data transfer interface
508 * Transmit DHCP request
510 * @v dhcp DHCP session
511 * @ret rc Return status code
513 static int dhcp_send_request ( struct dhcp_session *dhcp ) {
514 struct xfer_metadata meta = {
515 .netdev = dhcp->netdev,
517 struct settings *offer_settings = NULL;
518 struct io_buffer *iobuf;
519 struct dhcp_packet dhcppkt;
522 DBGC ( dhcp, "DHCP %p transmitting %s\n",
523 dhcp, dhcp_msgtype_name ( dhcp->state ) );
525 assert ( ( dhcp->state == DHCPDISCOVER ) ||
526 ( dhcp->state == DHCPREQUEST ) );
528 /* Start retry timer. Do this first so that failures to
529 * transmit will be retried.
531 start_timer ( &dhcp->timer );
533 /* Allocate buffer for packet */
534 iobuf = xfer_alloc_iob ( &dhcp->xfer, DHCP_MIN_LEN );
538 /* Create DHCP packet in temporary buffer */
539 if ( dhcp->response )
540 offer_settings = &dhcp->response->dhcppkt.settings;
541 if ( ( rc = create_dhcp_request ( &dhcppkt, dhcp->netdev, dhcp->state,
542 offer_settings, iobuf->data,
543 iob_tailroom ( iobuf ) ) ) != 0 ) {
544 DBGC ( dhcp, "DHCP %p could not construct DHCP request: %s\n",
545 dhcp, strerror ( rc ) );
549 /* Transmit the packet */
550 iob_put ( iobuf, dhcppkt.len );
551 rc = xfer_deliver_iob_meta ( &dhcp->xfer, iobuf, &meta );
554 DBGC ( dhcp, "DHCP %p could not transmit UDP packet: %s\n",
555 dhcp, strerror ( rc ) );
565 * Handle DHCP retry timer expiry
567 * @v timer DHCP retry timer
568 * @v fail Failure indicator
570 static void dhcp_timer_expired ( struct retry_timer *timer, int fail ) {
571 struct dhcp_session *dhcp =
572 container_of ( timer, struct dhcp_session, timer );
575 dhcp_finished ( dhcp, -ETIMEDOUT );
577 dhcp_send_request ( dhcp );
584 * @v xfer Data transfer interface
585 * @v iobuf I/O buffer
586 * @v data Received data
587 * @v len Length of received data
588 * @ret rc Return status code
590 static int dhcp_deliver_iob ( struct xfer_interface *xfer,
591 struct io_buffer *iobuf,
592 struct xfer_metadata *meta __unused ) {
593 struct dhcp_session *dhcp =
594 container_of ( xfer, struct dhcp_session, xfer );
595 struct dhcp_iobuf_packet *response;
596 struct dhcp_iobuf_packet **store_response;
597 struct dhcphdr *dhcphdr;
598 struct settings *settings;
599 unsigned int msgtype;
600 unsigned long elapsed;
605 /* Convert packet into a DHCP-packet-in-iobuf */
606 response = dhcpiob_create ( iobuf );
608 DBGC ( dhcp, "DHCP %p could not store DHCP packet\n", dhcp );
611 dhcphdr = response->dhcppkt.dhcphdr;
612 settings = &response->dhcppkt.settings;
614 /* Check for matching transaction ID */
615 if ( dhcphdr->xid != dhcp_xid ( dhcp->netdev ) ) {
616 DBGC ( dhcp, "DHCP %p wrong transaction ID (wanted %08lx, "
617 "got %08lx)\n", dhcp, ntohl ( dhcphdr->xid ),
618 ntohl ( dhcp_xid ( dhcp->netdev ) ) );
622 /* Determine and verify message type */
623 is_proxy = ( dhcphdr->yiaddr.s_addr == 0 );
624 msgtype = fetch_uintz_setting ( settings, DHCP_MESSAGE_TYPE );
625 DBGC ( dhcp, "DHCP %p received %s%s\n", dhcp,
626 ( is_proxy ? "Proxy" : "" ), dhcp_msgtype_name ( msgtype ) );
627 if ( ( ( dhcp->state != DHCPDISCOVER ) || ( msgtype != DHCPOFFER ) ) &&
628 ( ( dhcp->state != DHCPREQUEST ) || ( msgtype != DHCPACK ) ) ) {
629 DBGC ( dhcp, "DHCP %p discarding %s while in %s state\n",
630 dhcp, dhcp_msgtype_name ( msgtype ),
631 dhcp_msgtype_name ( dhcp->state ) );
635 /* Update stored standard/ProxyDHCP options, if the new
636 * options have equal or higher priority than the
637 * currently-stored options.
639 store_response = ( is_proxy ? &dhcp->proxy_response : &dhcp->response);
640 if ( ( ! *store_response ) ||
641 ( fetch_uintz_setting ( settings, DHCP_EB_PRIORITY ) >=
642 fetch_uintz_setting ( &(*store_response)->dhcppkt.settings,
643 DHCP_EB_PRIORITY ) ) ) {
644 dhcpiob_put ( *store_response );
645 *store_response = response;
647 dhcpiob_put ( response );
650 /* If we don't yet have a standard DHCP response (i.e. one
651 * with an IP address), then just leave the timer running.
653 if ( ! dhcp->response )
656 /* Handle DHCP response */
657 ignore_proxy = fetch_uintz_setting ( &dhcp->response->dhcppkt.settings,
658 DHCP_EB_NO_PROXYDHCP );
659 switch ( dhcp->state ) {
661 /* If we have allowed sufficient time for ProxyDHCP
662 * reponses, then transition to making the DHCPREQUEST.
664 elapsed = ( currticks() - dhcp->start );
665 if ( ignore_proxy || ( elapsed > PROXYDHCP_WAIT_TIME ) ) {
666 stop_timer ( &dhcp->timer );
667 dhcp->state = DHCPREQUEST;
668 dhcp_send_request ( dhcp );
672 /* DHCP finished; register options and exit */
673 if ( ignore_proxy && dhcp->proxy_response ) {
674 dhcpiob_put ( dhcp->proxy_response );
675 dhcp->proxy_response = NULL;
677 if ( ( rc = dhcp_register_settings ( dhcp ) ) != 0 ) {
678 dhcp_finished ( dhcp, rc );
681 dhcp_finished ( dhcp, 0 );
691 dhcpiob_put ( response );
695 /** DHCP data transfer interface operations */
696 static struct xfer_interface_operations dhcp_xfer_operations = {
697 .close = ignore_xfer_close,
698 .vredirect = xfer_vopen,
699 .window = unlimited_xfer_window,
700 .alloc_iob = default_xfer_alloc_iob,
701 .deliver_iob = dhcp_deliver_iob,
702 .deliver_raw = xfer_deliver_as_iob,
705 /****************************************************************************
707 * Job control interface
712 * Handle kill() event received via job control interface
714 * @v job DHCP job control interface
716 static void dhcp_job_kill ( struct job_interface *job ) {
717 struct dhcp_session *dhcp =
718 container_of ( job, struct dhcp_session, job );
720 /* Terminate DHCP session */
721 dhcp_finished ( dhcp, -ECANCELED );
724 /** DHCP job control interface operations */
725 static struct job_interface_operations dhcp_job_operations = {
726 .done = ignore_job_done,
727 .kill = dhcp_job_kill,
728 .progress = ignore_job_progress,
731 /****************************************************************************
738 * Start DHCP on a network device
740 * @v job Job control interface
741 * @v netdev Network device
742 * @v register_options DHCP option block registration routine
743 * @ret rc Return status code
745 * Starts DHCP on the specified network device. If successful, the @c
746 * register_options() routine will be called with the acquired
749 int start_dhcp ( struct job_interface *job, struct net_device *netdev ) {
750 static struct sockaddr_in server = {
751 .sin_family = AF_INET,
752 .sin_addr.s_addr = INADDR_BROADCAST,
753 .sin_port = htons ( BOOTPS_PORT ),
755 static struct sockaddr_in client = {
756 .sin_family = AF_INET,
757 .sin_port = htons ( BOOTPC_PORT ),
759 struct dhcp_session *dhcp;
762 /* Allocate and initialise structure */
763 dhcp = zalloc ( sizeof ( *dhcp ) );
766 dhcp->refcnt.free = dhcp_free;
767 job_init ( &dhcp->job, &dhcp_job_operations, &dhcp->refcnt );
768 xfer_init ( &dhcp->xfer, &dhcp_xfer_operations, &dhcp->refcnt );
769 dhcp->netdev = netdev_get ( netdev );
770 dhcp->timer.expired = dhcp_timer_expired;
771 dhcp->state = DHCPDISCOVER;
772 dhcp->start = currticks();
774 /* Instantiate child objects and attach to our interfaces */
775 if ( ( rc = xfer_open_socket ( &dhcp->xfer, SOCK_DGRAM,
776 ( struct sockaddr * ) &server,
777 ( struct sockaddr * ) &client ) ) != 0 )
780 /* Start timer to initiate initial DHCPREQUEST */
781 start_timer_nodelay ( &dhcp->timer );
783 /* Attach parent interface, mortalise self, and return */
784 job_plug_plug ( &dhcp->job, job );
785 ref_put ( &dhcp->refcnt );
789 dhcp_finished ( dhcp, rc );
790 ref_put ( &dhcp->refcnt );