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.
19 FILE_LICENCE ( GPL2_OR_LATER
);
28 #include <gpxe/if_ether.h>
29 #include <gpxe/netdevice.h>
30 #include <gpxe/device.h>
31 #include <gpxe/xfer.h>
32 #include <gpxe/open.h>
34 #include <gpxe/retry.h>
35 #include <gpxe/tcpip.h>
37 #include <gpxe/uuid.h>
38 #include <gpxe/timer.h>
39 #include <gpxe/settings.h>
40 #include <gpxe/dhcp.h>
41 #include <gpxe/dhcpopts.h>
42 #include <gpxe/dhcppkt.h>
43 #include <gpxe/features.h>
47 * Dynamic Host Configuration Protocol
52 static int dhcp_tx ( struct dhcp_session
*dhcp
);
55 * DHCP operation types
57 * This table maps from DHCP message types (i.e. values of the @c
58 * DHCP_MESSAGE_TYPE option) to values of the "op" field within a DHCP
61 static const uint8_t dhcp_op
[] = {
62 [DHCPDISCOVER
] = BOOTP_REQUEST
,
63 [DHCPOFFER
] = BOOTP_REPLY
,
64 [DHCPREQUEST
] = BOOTP_REQUEST
,
65 [DHCPDECLINE
] = BOOTP_REQUEST
,
66 [DHCPACK
] = BOOTP_REPLY
,
67 [DHCPNAK
] = BOOTP_REPLY
,
68 [DHCPRELEASE
] = BOOTP_REQUEST
,
69 [DHCPINFORM
] = BOOTP_REQUEST
,
72 /** Raw option data for options common to all DHCP requests */
73 static uint8_t dhcp_request_options_data
[] = {
74 DHCP_MAX_MESSAGE_SIZE
,
75 DHCP_WORD ( ETH_MAX_MTU
- 20 /* IP header */ - 8 /* UDP header */ ),
76 DHCP_CLIENT_ARCHITECTURE
, DHCP_WORD ( 0 ),
77 DHCP_CLIENT_NDI
, DHCP_OPTION ( 1 /* UNDI */ , 2, 1 /* v2.1 */ ),
79 DHCP_STRING ( 'P', 'X', 'E', 'C', 'l', 'i', 'e', 'n', 't', ':',
80 'A', 'r', 'c', 'h', ':', '0', '0', '0', '0', '0', ':',
81 'U', 'N', 'D', 'I', ':', '0', '0', '2', '0', '0', '1' ),
83 DHCP_STRING ( 'g', 'P', 'X', 'E' ),
84 DHCP_PARAMETER_REQUEST_LIST
,
85 DHCP_OPTION ( DHCP_SUBNET_MASK
, DHCP_ROUTERS
, DHCP_DNS_SERVERS
,
86 DHCP_LOG_SERVERS
, DHCP_HOST_NAME
, DHCP_DOMAIN_NAME
,
87 DHCP_ROOT_PATH
, DHCP_VENDOR_ENCAP
, DHCP_VENDOR_CLASS_ID
,
88 DHCP_TFTP_SERVER_NAME
, DHCP_BOOTFILE_NAME
,
89 DHCP_EB_ENCAP
, DHCP_ISCSI_INITIATOR_IQN
),
93 /** Version number feature */
94 FEATURE_VERSION ( VERSION_MAJOR
, VERSION_MINOR
, VERSION_PATCH
);
96 /** DHCP server address setting */
97 struct setting dhcp_server_setting __setting
= {
98 .name
= "dhcp-server",
99 .description
= "DHCP server address",
100 .tag
= DHCP_SERVER_IDENTIFIER
,
101 .type
= &setting_type_ipv4
,
104 /** DHCP user class setting */
105 struct setting user_class_setting __setting
= {
106 .name
= "user-class",
107 .description
= "User class identifier",
108 .tag
= DHCP_USER_CLASS_ID
,
109 .type
= &setting_type_string
,
113 * Name a DHCP packet type
115 * @v msgtype DHCP message type
116 * @ret string DHCP mesasge type name
118 static inline const char * dhcp_msgtype_name ( unsigned int msgtype
) {
120 case DHCPNONE
: return "BOOTP"; /* Non-DHCP packet */
121 case DHCPDISCOVER
: return "DHCPDISCOVER";
122 case DHCPOFFER
: return "DHCPOFFER";
123 case DHCPREQUEST
: return "DHCPREQUEST";
124 case DHCPDECLINE
: return "DHCPDECLINE";
125 case DHCPACK
: return "DHCPACK";
126 case DHCPNAK
: return "DHCPNAK";
127 case DHCPRELEASE
: return "DHCPRELEASE";
128 case DHCPINFORM
: return "DHCPINFORM";
129 default: return "DHCP<invalid>";
134 * Calculate DHCP transaction ID for a network device
136 * @v netdev Network device
139 * Extract the least significant bits of the hardware address for use
140 * as the transaction ID.
142 static uint32_t dhcp_xid ( struct net_device
*netdev
) {
145 memcpy ( &xid
, ( netdev
->ll_addr
+ netdev
->ll_protocol
->ll_addr_len
146 - sizeof ( xid
) ), sizeof ( xid
) );
150 /****************************************************************************
158 /** DHCP session state operations */
159 struct dhcp_session_state
{
163 * Construct transmitted packet
165 * @v dhcp DHCP session
166 * @v dhcppkt DHCP packet
167 * @v peer Destination address
169 int ( * tx
) ( struct dhcp_session
*dhcp
,
170 struct dhcp_packet
*dhcppkt
,
171 struct sockaddr_in
*peer
);
172 /** Handle received packet
174 * @v dhcp DHCP session
175 * @v dhcppkt DHCP packet
176 * @v peer DHCP server address
177 * @v msgtype DHCP message type
178 * @v server_id DHCP server ID
180 void ( * rx
) ( struct dhcp_session
*dhcp
,
181 struct dhcp_packet
*dhcppkt
,
182 struct sockaddr_in
*peer
,
183 uint8_t msgtype
, struct in_addr server_id
);
184 /** Handle timer expiry
186 * @v dhcp DHCP session
188 void ( * expired
) ( struct dhcp_session
*dhcp
);
189 /** Transmitted message type */
191 /** Apply minimum timeout */
192 uint8_t apply_min_timeout
;
195 static struct dhcp_session_state dhcp_state_discover
;
196 static struct dhcp_session_state dhcp_state_request
;
197 static struct dhcp_session_state dhcp_state_proxy
;
198 static struct dhcp_session_state dhcp_state_pxebs
;
200 /** A DHCP session */
201 struct dhcp_session
{
202 /** Reference counter */
203 struct refcnt refcnt
;
204 /** Job control interface */
205 struct job_interface job
;
206 /** Data transfer interface */
207 struct xfer_interface xfer
;
209 /** Network device being configured */
210 struct net_device
*netdev
;
211 /** Local socket address */
212 struct sockaddr_in local
;
213 /** State of the session */
214 struct dhcp_session_state
*state
;
216 /** Offered IP address */
217 struct in_addr offer
;
219 struct in_addr server
;
220 /** DHCP offer priority */
223 /** ProxyDHCP protocol extensions should be ignored */
225 /** ProxyDHCP server */
226 struct in_addr proxy_server
;
227 /** ProxyDHCP port */
229 /** ProxyDHCP server priority */
232 /** PXE Boot Server type */
234 /** List of PXE Boot Servers to attempt */
235 struct in_addr
*pxe_attempt
;
236 /** List of PXE Boot Servers to accept */
237 struct in_addr
*pxe_accept
;
239 /** Retransmission timer */
240 struct retry_timer timer
;
241 /** Start time of the current state (in ticks) */
248 * @v refcnt Reference counter
250 static void dhcp_free ( struct refcnt
*refcnt
) {
251 struct dhcp_session
*dhcp
=
252 container_of ( refcnt
, struct dhcp_session
, refcnt
);
254 netdev_put ( dhcp
->netdev
);
259 * Mark DHCP session as complete
261 * @v dhcp DHCP session
262 * @v rc Return status code
264 static void dhcp_finished ( struct dhcp_session
*dhcp
, int rc
) {
266 /* Block futher incoming messages */
267 job_nullify ( &dhcp
->job
);
268 xfer_nullify ( &dhcp
->xfer
);
270 /* Stop retry timer */
271 stop_timer ( &dhcp
->timer
);
273 /* Free resources and close interfaces */
274 xfer_close ( &dhcp
->xfer
, rc
);
275 job_done ( &dhcp
->job
, rc
);
279 * Transition to new DHCP session state
281 * @v dhcp DHCP session
282 * @v state New session state
284 static void dhcp_set_state ( struct dhcp_session
*dhcp
,
285 struct dhcp_session_state
*state
) {
287 DBGC ( dhcp
, "DHCP %p entering %s state\n", dhcp
, state
->name
);
289 dhcp
->start
= currticks();
290 stop_timer ( &dhcp
->timer
);
291 dhcp
->timer
.min_timeout
=
292 ( state
->apply_min_timeout
? DHCP_MIN_TIMEOUT
: 0 );
293 dhcp
->timer
.max_timeout
= DHCP_MAX_TIMEOUT
;
294 start_timer_nodelay ( &dhcp
->timer
);
297 /****************************************************************************
304 * Construct transmitted packet for DHCP discovery
306 * @v dhcp DHCP session
307 * @v dhcppkt DHCP packet
308 * @v peer Destination address
310 static int dhcp_discovery_tx ( struct dhcp_session
*dhcp
,
311 struct dhcp_packet
*dhcppkt __unused
,
312 struct sockaddr_in
*peer
) {
314 DBGC ( dhcp
, "DHCP %p DHCPDISCOVER\n", dhcp
);
316 /* Set server address */
317 peer
->sin_addr
.s_addr
= INADDR_BROADCAST
;
318 peer
->sin_port
= htons ( BOOTPS_PORT
);
324 * Handle received packet during DHCP discovery
326 * @v dhcp DHCP session
327 * @v dhcppkt DHCP packet
328 * @v peer DHCP server address
329 * @v msgtype DHCP message type
330 * @v server_id DHCP server ID
332 static void dhcp_discovery_rx ( struct dhcp_session
*dhcp
,
333 struct dhcp_packet
*dhcppkt
,
334 struct sockaddr_in
*peer
, uint8_t msgtype
,
335 struct in_addr server_id
) {
337 char vci
[9]; /* "PXEClient" */
343 uint8_t no_pxedhcp
= 0;
344 unsigned long elapsed
;
346 DBGC ( dhcp
, "DHCP %p %s from %s:%d", dhcp
,
347 dhcp_msgtype_name ( msgtype
), inet_ntoa ( peer
->sin_addr
),
348 ntohs ( peer
->sin_port
) );
349 if ( server_id
.s_addr
!= peer
->sin_addr
.s_addr
)
350 DBGC ( dhcp
, " (%s)", inet_ntoa ( server_id
) );
352 /* Identify offered IP address */
353 ip
= dhcppkt
->dhcphdr
->yiaddr
;
355 DBGC ( dhcp
, " for %s", inet_ntoa ( ip
) );
357 /* Identify "PXEClient" vendor class */
358 vci_len
= dhcppkt_fetch ( dhcppkt
, DHCP_VENDOR_CLASS_ID
,
359 vci
, sizeof ( vci
) );
360 has_pxeclient
= ( ( vci_len
>= ( int ) sizeof ( vci
) ) &&
361 ( strncmp ( "PXEClient", vci
, sizeof (vci
) ) == 0 ));
363 /* Identify presence of vendor-specific options */
364 pxeopts_len
= dhcppkt_fetch ( dhcppkt
, DHCP_VENDOR_ENCAP
, NULL
, 0 );
365 has_pxeopts
= ( pxeopts_len
>= 0 );
367 DBGC ( dhcp
, "%s", ( has_pxeopts
? " pxe" : " proxy" ) );
369 /* Identify priority */
370 dhcppkt_fetch ( dhcppkt
, DHCP_EB_PRIORITY
, &priority
,
371 sizeof ( priority
) );
373 DBGC ( dhcp
, " pri %d", priority
);
375 /* Identify ignore-PXE flag */
376 dhcppkt_fetch ( dhcppkt
, DHCP_EB_NO_PXEDHCP
, &no_pxedhcp
,
377 sizeof ( no_pxedhcp
) );
379 DBGC ( dhcp
, " nopxe" );
382 /* Select as DHCP offer, if applicable */
383 if ( ip
.s_addr
&& ( peer
->sin_port
== htons ( BOOTPS_PORT
) ) &&
384 ( ( msgtype
== DHCPOFFER
) || ( ! msgtype
/* BOOTP */ ) ) &&
385 ( priority
>= dhcp
->priority
) ) {
387 dhcp
->server
= server_id
;
388 dhcp
->priority
= priority
;
389 dhcp
->no_pxedhcp
= no_pxedhcp
;
392 /* Select as ProxyDHCP offer, if applicable */
393 if ( has_pxeclient
&& ( msgtype
== DHCPOFFER
) &&
394 ( priority
>= dhcp
->proxy_priority
) ) {
395 /* If the offer already includes the PXE options, then
396 * assume that we can send the ProxyDHCPREQUEST to
397 * port 67 (since the DHCPDISCOVER that triggered this
398 * ProxyDHCPOFFER was sent to port 67). Otherwise,
399 * send the ProxyDHCPREQUEST to port 4011.
401 dhcp
->proxy_server
= server_id
;
402 dhcp
->proxy_port
= ( has_pxeopts
? htons ( BOOTPS_PORT
)
403 : htons ( PXE_PORT
) );
404 dhcp
->proxy_priority
= priority
;
407 /* We can exit the discovery state when we have a valid
408 * DHCPOFFER, and either:
410 * o The DHCPOFFER instructs us to ignore ProxyDHCPOFFERs, or
411 * o We have a valid ProxyDHCPOFFER, or
412 * o We have allowed sufficient time for ProxyDHCPOFFERs.
415 /* If we don't yet have a DHCPOFFER, do nothing */
416 if ( ! dhcp
->offer
.s_addr
)
419 /* If we can't yet transition to DHCPREQUEST, do nothing */
420 elapsed
= ( currticks() - dhcp
->start
);
421 if ( ! ( dhcp
->no_pxedhcp
|| dhcp
->proxy_server
.s_addr
||
422 ( elapsed
> PROXYDHCP_MAX_TIMEOUT
) ) )
425 /* Transition to DHCPREQUEST */
426 dhcp_set_state ( dhcp
, &dhcp_state_request
);
430 * Handle timer expiry during DHCP discovery
432 * @v dhcp DHCP session
434 static void dhcp_discovery_expired ( struct dhcp_session
*dhcp
) {
435 unsigned long elapsed
= ( currticks() - dhcp
->start
);
437 /* Give up waiting for ProxyDHCP before we reach the failure point */
438 if ( dhcp
->offer
.s_addr
&& ( elapsed
> PROXYDHCP_MAX_TIMEOUT
) ) {
439 dhcp_set_state ( dhcp
, &dhcp_state_request
);
443 /* Otherwise, retransmit current packet */
447 /** DHCP discovery state operations */
448 static struct dhcp_session_state dhcp_state_discover
= {
450 .tx
= dhcp_discovery_tx
,
451 .rx
= dhcp_discovery_rx
,
452 .expired
= dhcp_discovery_expired
,
453 .tx_msgtype
= DHCPDISCOVER
,
454 .apply_min_timeout
= 1,
458 * Construct transmitted packet for DHCP request
460 * @v dhcp DHCP session
461 * @v dhcppkt DHCP packet
462 * @v peer Destination address
464 static int dhcp_request_tx ( struct dhcp_session
*dhcp
,
465 struct dhcp_packet
*dhcppkt
,
466 struct sockaddr_in
*peer
) {
469 DBGC ( dhcp
, "DHCP %p DHCPREQUEST to %s:%d",
470 dhcp
, inet_ntoa ( dhcp
->server
), BOOTPS_PORT
);
471 DBGC ( dhcp
, " for %s\n", inet_ntoa ( dhcp
->offer
) );
474 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_SERVER_IDENTIFIER
,
476 sizeof ( dhcp
->server
) ) ) != 0 )
479 /* Set requested IP address */
480 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_REQUESTED_ADDRESS
,
482 sizeof ( dhcp
->offer
) ) ) != 0 )
485 /* Set server address */
486 peer
->sin_addr
.s_addr
= INADDR_BROADCAST
;
487 peer
->sin_port
= htons ( BOOTPS_PORT
);
493 * Handle received packet during DHCP request
495 * @v dhcp DHCP session
496 * @v dhcppkt DHCP packet
497 * @v peer DHCP server address
498 * @v msgtype DHCP message type
499 * @v server_id DHCP server ID
501 static void dhcp_request_rx ( struct dhcp_session
*dhcp
,
502 struct dhcp_packet
*dhcppkt
,
503 struct sockaddr_in
*peer
, uint8_t msgtype
,
504 struct in_addr server_id
) {
506 struct settings
*parent
;
509 DBGC ( dhcp
, "DHCP %p %s from %s:%d", dhcp
,
510 dhcp_msgtype_name ( msgtype
), inet_ntoa ( peer
->sin_addr
),
511 ntohs ( peer
->sin_port
) );
512 if ( server_id
.s_addr
!= peer
->sin_addr
.s_addr
)
513 DBGC ( dhcp
, " (%s)", inet_ntoa ( server_id
) );
515 /* Identify leased IP address */
516 ip
= dhcppkt
->dhcphdr
->yiaddr
;
518 DBGC ( dhcp
, " for %s", inet_ntoa ( ip
) );
521 /* Filter out unacceptable responses */
522 if ( peer
->sin_port
!= htons ( BOOTPS_PORT
) )
524 if ( msgtype
/* BOOTP */ && ( msgtype
!= DHCPACK
) )
526 if ( server_id
.s_addr
!= dhcp
->server
.s_addr
)
529 /* Record assigned address */
530 dhcp
->local
.sin_addr
= ip
;
532 /* Register settings */
533 parent
= netdev_settings ( dhcp
->netdev
);
534 if ( ( rc
= register_settings ( &dhcppkt
->settings
, parent
) ) != 0 ){
535 DBGC ( dhcp
, "DHCP %p could not register settings: %s\n",
536 dhcp
, strerror ( rc
) );
537 dhcp_finished ( dhcp
, rc
);
541 /* Start ProxyDHCPREQUEST if applicable */
542 if ( dhcp
->proxy_server
.s_addr
/* Have ProxyDHCP server */ &&
543 ( ! dhcp
->no_pxedhcp
) /* ProxyDHCP not disabled */ &&
544 ( /* ProxyDHCP server is not just the DHCP server itself */
545 ( dhcp
->proxy_server
.s_addr
!= dhcp
->server
.s_addr
) ||
546 ( dhcp
->proxy_port
!= htons ( BOOTPS_PORT
) ) ) ) {
547 dhcp_set_state ( dhcp
, &dhcp_state_proxy
);
552 dhcp_finished ( dhcp
, 0 );
556 * Handle timer expiry during DHCP discovery
558 * @v dhcp DHCP session
560 static void dhcp_request_expired ( struct dhcp_session
*dhcp
) {
562 /* Retransmit current packet */
566 /** DHCP request state operations */
567 static struct dhcp_session_state dhcp_state_request
= {
569 .tx
= dhcp_request_tx
,
570 .rx
= dhcp_request_rx
,
571 .expired
= dhcp_request_expired
,
572 .tx_msgtype
= DHCPREQUEST
,
573 .apply_min_timeout
= 0,
577 * Construct transmitted packet for ProxyDHCP request
579 * @v dhcp DHCP session
580 * @v dhcppkt DHCP packet
581 * @v peer Destination address
583 static int dhcp_proxy_tx ( struct dhcp_session
*dhcp
,
584 struct dhcp_packet
*dhcppkt
,
585 struct sockaddr_in
*peer
) {
588 DBGC ( dhcp
, "DHCP %p ProxyDHCP REQUEST to %s:%d\n", dhcp
,
589 inet_ntoa ( dhcp
->proxy_server
), ntohs ( dhcp
->proxy_port
) );
592 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_SERVER_IDENTIFIER
,
594 sizeof ( dhcp
->proxy_server
) ) ) != 0 )
597 /* Set server address */
598 peer
->sin_addr
= dhcp
->proxy_server
;
599 peer
->sin_port
= dhcp
->proxy_port
;
605 * Handle received packet during ProxyDHCP request
607 * @v dhcp DHCP session
608 * @v dhcppkt DHCP packet
609 * @v peer DHCP server address
610 * @v msgtype DHCP message type
611 * @v server_id DHCP server ID
613 static void dhcp_proxy_rx ( struct dhcp_session
*dhcp
,
614 struct dhcp_packet
*dhcppkt
,
615 struct sockaddr_in
*peer
, uint8_t msgtype
,
616 struct in_addr server_id
) {
619 DBGC ( dhcp
, "DHCP %p %s from %s:%d", dhcp
,
620 dhcp_msgtype_name ( msgtype
), inet_ntoa ( peer
->sin_addr
),
621 ntohs ( peer
->sin_port
) );
622 if ( server_id
.s_addr
!= peer
->sin_addr
.s_addr
)
623 DBGC ( dhcp
, " (%s)", inet_ntoa ( server_id
) );
626 /* Filter out unacceptable responses */
627 if ( peer
->sin_port
!= dhcp
->proxy_port
)
629 if ( msgtype
!= DHCPACK
)
631 if ( server_id
.s_addr
/* Linux PXE server omits server ID */ &&
632 ( server_id
.s_addr
!= dhcp
->proxy_server
.s_addr
) )
635 /* Register settings */
636 dhcppkt
->settings
.name
= PROXYDHCP_SETTINGS_NAME
;
637 if ( ( rc
= register_settings ( &dhcppkt
->settings
, NULL
) ) != 0 ) {
638 DBGC ( dhcp
, "DHCP %p could not register settings: %s\n",
639 dhcp
, strerror ( rc
) );
640 dhcp_finished ( dhcp
, rc
);
645 dhcp_finished ( dhcp
, 0 );
649 * Handle timer expiry during ProxyDHCP request
651 * @v dhcp DHCP session
653 static void dhcp_proxy_expired ( struct dhcp_session
*dhcp
) {
654 unsigned long elapsed
= ( currticks() - dhcp
->start
);
656 /* Give up waiting for ProxyDHCP before we reach the failure point */
657 if ( elapsed
> PROXYDHCP_MAX_TIMEOUT
) {
658 dhcp_finished ( dhcp
, 0 );
662 /* Retransmit current packet */
666 /** ProxyDHCP request state operations */
667 static struct dhcp_session_state dhcp_state_proxy
= {
671 .expired
= dhcp_proxy_expired
,
672 .tx_msgtype
= DHCPREQUEST
,
673 .apply_min_timeout
= 0,
677 * Construct transmitted packet for PXE Boot Server Discovery
679 * @v dhcp DHCP session
680 * @v dhcppkt DHCP packet
681 * @v peer Destination address
683 static int dhcp_pxebs_tx ( struct dhcp_session
*dhcp
,
684 struct dhcp_packet
*dhcppkt
,
685 struct sockaddr_in
*peer
) {
686 struct dhcp_pxe_boot_menu_item menu_item
= { 0, 0 };
689 /* Set server address */
690 peer
->sin_addr
= *(dhcp
->pxe_attempt
);
691 peer
->sin_port
= ( ( peer
->sin_addr
.s_addr
== INADDR_BROADCAST
) ?
692 htons ( BOOTPS_PORT
) : htons ( PXE_PORT
) );
694 DBGC ( dhcp
, "DHCP %p PXEBS REQUEST to %s:%d for type %d\n",
695 dhcp
, inet_ntoa ( peer
->sin_addr
), ntohs ( peer
->sin_port
),
696 ntohs ( dhcp
->pxe_type
) );
698 /* Set boot menu item */
699 menu_item
.type
= dhcp
->pxe_type
;
700 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_PXE_BOOT_MENU_ITEM
,
701 &menu_item
, sizeof ( menu_item
) ) ) != 0 )
708 * Check to see if PXE Boot Server address is acceptable
710 * @v dhcp DHCP session
711 * @v bs Boot Server address
712 * @ret accept Boot Server is acceptable
714 static int dhcp_pxebs_accept ( struct dhcp_session
*dhcp
,
715 struct in_addr bs
) {
716 struct in_addr
*accept
;
718 /* Accept if we have no acceptance filter */
719 if ( ! dhcp
->pxe_accept
)
722 /* Scan through acceptance list */
723 for ( accept
= dhcp
->pxe_accept
; accept
->s_addr
; accept
++ ) {
724 if ( accept
->s_addr
== bs
.s_addr
)
728 DBGC ( dhcp
, "DHCP %p rejecting server %s\n",
729 dhcp
, inet_ntoa ( bs
) );
734 * Handle received packet during PXE Boot Server Discovery
736 * @v dhcp DHCP session
737 * @v dhcppkt DHCP packet
738 * @v peer DHCP server address
739 * @v msgtype DHCP message type
740 * @v server_id DHCP server ID
742 static void dhcp_pxebs_rx ( struct dhcp_session
*dhcp
,
743 struct dhcp_packet
*dhcppkt
,
744 struct sockaddr_in
*peer
, uint8_t msgtype
,
745 struct in_addr server_id
) {
746 struct dhcp_pxe_boot_menu_item menu_item
= { 0, 0 };
749 DBGC ( dhcp
, "DHCP %p %s from %s:%d", dhcp
,
750 dhcp_msgtype_name ( msgtype
), inet_ntoa ( peer
->sin_addr
),
751 ntohs ( peer
->sin_port
) );
752 if ( server_id
.s_addr
!= peer
->sin_addr
.s_addr
)
753 DBGC ( dhcp
, " (%s)", inet_ntoa ( server_id
) );
755 /* Identify boot menu item */
756 dhcppkt_fetch ( dhcppkt
, DHCP_PXE_BOOT_MENU_ITEM
,
757 &menu_item
, sizeof ( menu_item
) );
758 if ( menu_item
.type
)
759 DBGC ( dhcp
, " for type %d", ntohs ( menu_item
.type
) );
762 /* Filter out unacceptable responses */
763 if ( ( peer
->sin_port
!= htons ( BOOTPS_PORT
) ) &&
764 ( peer
->sin_port
!= htons ( PXE_PORT
) ) )
766 if ( msgtype
!= DHCPACK
)
768 if ( menu_item
.type
!= dhcp
->pxe_type
)
770 if ( ! dhcp_pxebs_accept ( dhcp
, ( server_id
.s_addr
?
771 server_id
: peer
->sin_addr
) ) )
774 /* Register settings */
775 dhcppkt
->settings
.name
= PXEBS_SETTINGS_NAME
;
776 if ( ( rc
= register_settings ( &dhcppkt
->settings
, NULL
) ) != 0 ) {
777 DBGC ( dhcp
, "DHCP %p could not register settings: %s\n",
778 dhcp
, strerror ( rc
) );
779 dhcp_finished ( dhcp
, rc
);
784 dhcp_finished ( dhcp
, 0 );
788 * Handle timer expiry during PXE Boot Server Discovery
790 * @v dhcp DHCP session
792 static void dhcp_pxebs_expired ( struct dhcp_session
*dhcp
) {
793 unsigned long elapsed
= ( currticks() - dhcp
->start
);
795 /* Give up waiting before we reach the failure point, and fail
796 * over to the next server in the attempt list
798 if ( elapsed
> PXEBS_MAX_TIMEOUT
) {
800 if ( dhcp
->pxe_attempt
->s_addr
) {
801 dhcp_set_state ( dhcp
, &dhcp_state_pxebs
);
804 dhcp_finished ( dhcp
, -ETIMEDOUT
);
809 /* Retransmit current packet */
813 /** PXE Boot Server Discovery state operations */
814 static struct dhcp_session_state dhcp_state_pxebs
= {
818 .expired
= dhcp_pxebs_expired
,
819 .tx_msgtype
= DHCPREQUEST
,
820 .apply_min_timeout
= 1,
823 /****************************************************************************
825 * Packet construction
830 * Construct DHCP client hardware address field and broadcast flag
832 * @v netdev Network device
833 * @v hlen DHCP hardware address length to fill in
834 * @v flags DHCP flags to fill in
835 * @ret chaddr DHCP client hardware address
837 void * dhcp_chaddr ( struct net_device
*netdev
, uint8_t *hlen
,
839 struct ll_protocol
*ll_protocol
= netdev
->ll_protocol
;
840 typeof ( ( ( struct dhcphdr
* ) NULL
)->chaddr
) chaddr
;
842 /* If the link-layer address cannot fit into the chaddr field
843 * (as is the case for IPoIB) then try using the hardware
844 * address instead. If we do this, set the broadcast flag,
845 * since chaddr then does not represent a valid link-layer
846 * address for the return path.
848 * If even the hardware address is too large, use an empty
849 * chaddr field and set the broadcast flag.
851 * This goes against RFC4390, but RFC4390 mandates that we use
852 * a DHCP client identifier that conforms with RFC4361, which
853 * we cannot do without either persistent (NIC-independent)
854 * storage, or by eliminating the hardware address completely
855 * from the DHCP packet, which seems unfriendly to users.
857 if ( ( *hlen
= ll_protocol
->ll_addr_len
) <= sizeof ( chaddr
) ) {
858 return netdev
->ll_addr
;
860 *flags
= htons ( BOOTP_FL_BROADCAST
);
861 if ( ( *hlen
= ll_protocol
->hw_addr_len
) <= sizeof ( chaddr
) ) {
862 return netdev
->hw_addr
;
870 * Create a DHCP packet
872 * @v dhcppkt DHCP packet structure to fill in
873 * @v netdev Network device
874 * @v msgtype DHCP message type
875 * @v options Initial options to include (or NULL)
876 * @v options_len Length of initial options
877 * @v data Buffer for DHCP packet
878 * @v max_len Size of DHCP packet buffer
879 * @ret rc Return status code
881 * Creates a DHCP packet in the specified buffer, and initialise a
882 * DHCP packet structure.
884 int dhcp_create_packet ( struct dhcp_packet
*dhcppkt
,
885 struct net_device
*netdev
, uint8_t msgtype
,
886 const void *options
, size_t options_len
,
887 void *data
, size_t max_len
) {
888 struct dhcphdr
*dhcphdr
= data
;
893 if ( max_len
< ( sizeof ( *dhcphdr
) + options_len
) )
896 /* Initialise DHCP packet content */
897 memset ( dhcphdr
, 0, max_len
);
898 dhcphdr
->xid
= dhcp_xid ( netdev
);
899 dhcphdr
->magic
= htonl ( DHCP_MAGIC_COOKIE
);
900 dhcphdr
->htype
= ntohs ( netdev
->ll_protocol
->ll_proto
);
901 dhcphdr
->op
= dhcp_op
[msgtype
];
902 chaddr
= dhcp_chaddr ( netdev
, &dhcphdr
->hlen
, &dhcphdr
->flags
);
903 memcpy ( dhcphdr
->chaddr
, chaddr
, dhcphdr
->hlen
);
904 memcpy ( dhcphdr
->options
, options
, options_len
);
906 /* Initialise DHCP packet structure */
907 memset ( dhcppkt
, 0, sizeof ( *dhcppkt
) );
908 dhcppkt_init ( dhcppkt
, data
, max_len
);
910 /* Set DHCP_MESSAGE_TYPE option */
911 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_MESSAGE_TYPE
,
912 &msgtype
, sizeof ( msgtype
) ) ) != 0 )
919 * Create DHCP request packet
921 * @v dhcppkt DHCP packet structure to fill in
922 * @v netdev Network device
923 * @v msgtype DHCP message type
924 * @v ciaddr Client IP address
925 * @v data Buffer for DHCP packet
926 * @v max_len Size of DHCP packet buffer
927 * @ret rc Return status code
929 * Creates a DHCP request packet in the specified buffer, and
930 * initialise a DHCP packet structure.
932 int dhcp_create_request ( struct dhcp_packet
*dhcppkt
,
933 struct net_device
*netdev
, unsigned int msgtype
,
934 struct in_addr ciaddr
, void *data
, size_t max_len
) {
935 struct device_description
*desc
= &netdev
->dev
->desc
;
936 struct dhcp_netdev_desc dhcp_desc
;
937 struct dhcp_client_id client_id
;
938 struct dhcp_client_uuid client_uuid
;
939 uint8_t *dhcp_features
;
940 size_t dhcp_features_len
;
945 /* Create DHCP packet */
946 if ( ( rc
= dhcp_create_packet ( dhcppkt
, netdev
, msgtype
,
947 dhcp_request_options_data
,
948 sizeof ( dhcp_request_options_data
),
949 data
, max_len
) ) != 0 ) {
950 DBG ( "DHCP could not create DHCP packet: %s\n",
955 /* Set client IP address */
956 dhcppkt
->dhcphdr
->ciaddr
= ciaddr
;
958 /* Add options to identify the feature list */
960 dhcp_features
= table_start ( DHCP_FEATURES
);
961 dhcp_features_len
= table_num_entries ( DHCP_FEATURES
);
962 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_EB_ENCAP
, dhcp_features
,
963 dhcp_features_len
) ) != 0 ) {
964 DBG ( "DHCP could not set features list option: %s\n",
970 /* Add options to identify the network device */
971 dhcp_desc
.type
= desc
->bus_type
;
972 dhcp_desc
.vendor
= htons ( desc
->vendor
);
973 dhcp_desc
.device
= htons ( desc
->device
);
974 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_EB_BUS_ID
, &dhcp_desc
,
975 sizeof ( dhcp_desc
) ) ) != 0 ) {
976 DBG ( "DHCP could not set bus ID option: %s\n",
981 /* Add DHCP client identifier. Required for Infiniband, and
982 * doesn't hurt other link layers.
984 client_id
.ll_proto
= ntohs ( netdev
->ll_protocol
->ll_proto
);
985 ll_addr_len
= netdev
->ll_protocol
->ll_addr_len
;
986 assert ( ll_addr_len
<= sizeof ( client_id
.ll_addr
) );
987 memcpy ( client_id
.ll_addr
, netdev
->ll_addr
, ll_addr_len
);
988 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_CLIENT_ID
, &client_id
,
989 ( ll_addr_len
+ 1 ) ) ) != 0 ) {
990 DBG ( "DHCP could not set client ID: %s\n",
996 /* Add client UUID, if we have one. Required for PXE. */
997 client_uuid
.type
= DHCP_CLIENT_UUID_TYPE
;
998 if ( ( len
= fetch_uuid_setting ( NULL
, &uuid_setting
,
999 &client_uuid
.uuid
) ) >= 0 ) {
1000 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_CLIENT_UUID
,
1002 sizeof ( client_uuid
) ) ) != 0 ) {
1003 DBG ( "DHCP could not set client UUID: %s\n",
1010 /* Add user class, if we have one. */
1011 if ( ( len
= fetch_setting_len ( NULL
, &user_class_setting
) ) >= 0 ) {
1012 char user_class
[len
];
1013 fetch_setting ( NULL
, &user_class_setting
, user_class
,
1014 sizeof ( user_class
) );
1015 if ( ( rc
= dhcppkt_store ( dhcppkt
, DHCP_USER_CLASS_ID
,
1017 sizeof ( user_class
) ) ) != 0 ) {
1018 DBG ( "DHCP could not set user class: %s\n",
1027 /****************************************************************************
1029 * Data transfer interface
1034 * Transmit DHCP request
1036 * @v dhcp DHCP session
1037 * @ret rc Return status code
1039 static int dhcp_tx ( struct dhcp_session
*dhcp
) {
1040 static struct sockaddr_in peer
= {
1041 .sin_family
= AF_INET
,
1043 struct xfer_metadata meta
= {
1044 .netdev
= dhcp
->netdev
,
1045 .src
= ( struct sockaddr
* ) &dhcp
->local
,
1046 .dest
= ( struct sockaddr
* ) &peer
,
1048 struct io_buffer
*iobuf
;
1049 uint8_t msgtype
= dhcp
->state
->tx_msgtype
;
1050 struct dhcp_packet dhcppkt
;
1053 /* Start retry timer. Do this first so that failures to
1054 * transmit will be retried.
1056 start_timer ( &dhcp
->timer
);
1058 /* Allocate buffer for packet */
1059 iobuf
= xfer_alloc_iob ( &dhcp
->xfer
, DHCP_MIN_LEN
);
1063 /* Create basic DHCP packet in temporary buffer */
1064 if ( ( rc
= dhcp_create_request ( &dhcppkt
, dhcp
->netdev
, msgtype
,
1065 dhcp
->local
.sin_addr
, iobuf
->data
,
1066 iob_tailroom ( iobuf
) ) ) != 0 ) {
1067 DBGC ( dhcp
, "DHCP %p could not construct DHCP request: %s\n",
1068 dhcp
, strerror ( rc
) );
1072 /* Fill in packet based on current state */
1073 if ( ( rc
= dhcp
->state
->tx ( dhcp
, &dhcppkt
, &peer
) ) != 0 ) {
1074 DBGC ( dhcp
, "DHCP %p could not fill DHCP request: %s\n",
1075 dhcp
, strerror ( rc
) );
1079 /* Transmit the packet */
1080 iob_put ( iobuf
, dhcppkt
.len
);
1081 if ( ( rc
= xfer_deliver_iob_meta ( &dhcp
->xfer
, iob_disown ( iobuf
),
1083 DBGC ( dhcp
, "DHCP %p could not transmit UDP packet: %s\n",
1084 dhcp
, strerror ( rc
) );
1096 * @v xfer Data transfer interface
1097 * @v iobuf I/O buffer
1098 * @v meta Transfer metadata
1099 * @ret rc Return status code
1101 static int dhcp_deliver_iob ( struct xfer_interface
*xfer
,
1102 struct io_buffer
*iobuf
,
1103 struct xfer_metadata
*meta
) {
1104 struct dhcp_session
*dhcp
=
1105 container_of ( xfer
, struct dhcp_session
, xfer
);
1106 struct sockaddr_in
*peer
;
1108 struct dhcp_packet
*dhcppkt
;
1109 struct dhcphdr
*dhcphdr
;
1110 uint8_t msgtype
= 0;
1111 struct in_addr server_id
= { 0 };
1115 if ( ! meta
->src
) {
1116 DBGC ( dhcp
, "DHCP %p received packet without source port\n",
1121 peer
= ( struct sockaddr_in
* ) meta
->src
;
1123 /* Create a DHCP packet containing the I/O buffer contents.
1124 * Whilst we could just use the original buffer in situ, that
1125 * would waste the unused space in the packet buffer, and also
1126 * waste a relatively scarce fully-aligned I/O buffer.
1128 data_len
= iob_len ( iobuf
);
1129 dhcppkt
= zalloc ( sizeof ( *dhcppkt
) + data_len
);
1132 goto err_alloc_dhcppkt
;
1134 dhcphdr
= ( ( ( void * ) dhcppkt
) + sizeof ( *dhcppkt
) );
1135 memcpy ( dhcphdr
, iobuf
->data
, data_len
);
1136 dhcppkt_init ( dhcppkt
, dhcphdr
, data_len
);
1138 /* Identify message type */
1139 dhcppkt_fetch ( dhcppkt
, DHCP_MESSAGE_TYPE
, &msgtype
,
1140 sizeof ( msgtype
) );
1142 /* Identify server ID */
1143 dhcppkt_fetch ( dhcppkt
, DHCP_SERVER_IDENTIFIER
,
1144 &server_id
, sizeof ( server_id
) );
1146 /* Check for matching transaction ID */
1147 if ( dhcphdr
->xid
!= dhcp_xid ( dhcp
->netdev
) ) {
1148 DBGC ( dhcp
, "DHCP %p %s from %s:%d has bad transaction "
1149 "ID\n", dhcp
, dhcp_msgtype_name ( msgtype
),
1150 inet_ntoa ( peer
->sin_addr
),
1151 ntohs ( peer
->sin_port
) );
1156 /* Handle packet based on current state */
1157 dhcp
->state
->rx ( dhcp
, dhcppkt
, peer
, msgtype
, server_id
);
1160 dhcppkt_put ( dhcppkt
);
1167 /** DHCP data transfer interface operations */
1168 static struct xfer_interface_operations dhcp_xfer_operations
= {
1169 .close
= ignore_xfer_close
,
1170 .vredirect
= xfer_vreopen
,
1171 .window
= unlimited_xfer_window
,
1172 .alloc_iob
= default_xfer_alloc_iob
,
1173 .deliver_iob
= dhcp_deliver_iob
,
1174 .deliver_raw
= xfer_deliver_as_iob
,
1178 * Handle DHCP retry timer expiry
1180 * @v timer DHCP retry timer
1181 * @v fail Failure indicator
1183 static void dhcp_timer_expired ( struct retry_timer
*timer
, int fail
) {
1184 struct dhcp_session
*dhcp
=
1185 container_of ( timer
, struct dhcp_session
, timer
);
1187 /* If we have failed, terminate DHCP */
1189 dhcp_finished ( dhcp
, -ETIMEDOUT
);
1193 /* Handle timer expiry based on current state */
1194 dhcp
->state
->expired ( dhcp
);
1197 /****************************************************************************
1199 * Job control interface
1204 * Handle kill() event received via job control interface
1206 * @v job DHCP job control interface
1208 static void dhcp_job_kill ( struct job_interface
*job
) {
1209 struct dhcp_session
*dhcp
=
1210 container_of ( job
, struct dhcp_session
, job
);
1212 /* Terminate DHCP session */
1213 dhcp_finished ( dhcp
, -ECANCELED
);
1216 /** DHCP job control interface operations */
1217 static struct job_interface_operations dhcp_job_operations
= {
1218 .done
= ignore_job_done
,
1219 .kill
= dhcp_job_kill
,
1220 .progress
= ignore_job_progress
,
1223 /****************************************************************************
1230 * DHCP peer address for socket opening
1232 * This is a dummy address; the only useful portion is the socket
1233 * family (so that we get a UDP connection). The DHCP client will set
1234 * the IP address and source port explicitly on each transmission.
1236 static struct sockaddr dhcp_peer
= {
1237 .sa_family
= AF_INET
,
1241 * Start DHCP state machine on a network device
1243 * @v job Job control interface
1244 * @v netdev Network device
1245 * @ret rc Return status code
1247 * Starts DHCP on the specified network device. If successful, the
1248 * DHCPACK (and ProxyDHCPACK, if applicable) will be registered as
1251 int start_dhcp ( struct job_interface
*job
, struct net_device
*netdev
) {
1252 struct dhcp_session
*dhcp
;
1255 /* Allocate and initialise structure */
1256 dhcp
= zalloc ( sizeof ( *dhcp
) );
1259 dhcp
->refcnt
.free
= dhcp_free
;
1260 job_init ( &dhcp
->job
, &dhcp_job_operations
, &dhcp
->refcnt
);
1261 xfer_init ( &dhcp
->xfer
, &dhcp_xfer_operations
, &dhcp
->refcnt
);
1262 dhcp
->netdev
= netdev_get ( netdev
);
1263 dhcp
->local
.sin_family
= AF_INET
;
1264 dhcp
->local
.sin_port
= htons ( BOOTPC_PORT
);
1265 dhcp
->timer
.expired
= dhcp_timer_expired
;
1267 /* Instantiate child objects and attach to our interfaces */
1268 if ( ( rc
= xfer_open_socket ( &dhcp
->xfer
, SOCK_DGRAM
, &dhcp_peer
,
1269 ( struct sockaddr
* ) &dhcp
->local
) ) != 0 )
1272 /* Enter DHCPDISCOVER state */
1273 dhcp_set_state ( dhcp
, &dhcp_state_discover
);
1275 /* Attach parent interface, mortalise self, and return */
1276 job_plug_plug ( &dhcp
->job
, job
);
1277 ref_put ( &dhcp
->refcnt
);
1281 dhcp_finished ( dhcp
, rc
);
1282 ref_put ( &dhcp
->refcnt
);
1287 * Retrieve list of PXE boot servers for a given server type
1289 * @v dhcp DHCP session
1290 * @v raw DHCP PXE boot server list
1291 * @v raw_len Length of DHCP PXE boot server list
1292 * @v ip IP address list to fill in
1294 * The caller must ensure that the IP address list has sufficient
1297 static void pxebs_list ( struct dhcp_session
*dhcp
, void *raw
,
1298 size_t raw_len
, struct in_addr
*ip
) {
1299 struct dhcp_pxe_boot_server
*server
= raw
;
1304 if ( raw_len
< sizeof ( *server
) ) {
1305 DBGC ( dhcp
, "DHCP %p malformed PXE server list\n",
1309 server_len
= offsetof ( typeof ( *server
),
1310 ip
[ server
->num_ip
] );
1311 if ( raw_len
< server_len
) {
1312 DBGC ( dhcp
, "DHCP %p malformed PXE server list\n",
1316 if ( server
->type
== dhcp
->pxe_type
) {
1317 for ( i
= 0 ; i
< server
->num_ip
; i
++ )
1318 *(ip
++) = server
->ip
[i
];
1320 server
= ( ( ( void * ) server
) + server_len
);
1321 raw_len
-= server_len
;
1326 * Start PXE Boot Server Discovery on a network device
1328 * @v job Job control interface
1329 * @v netdev Network device
1330 * @v pxe_type PXE server type
1331 * @ret rc Return status code
1333 * Starts PXE Boot Server Discovery on the specified network device.
1334 * If successful, the Boot Server ACK will be registered as an option
1337 int start_pxebs ( struct job_interface
*job
, struct net_device
*netdev
,
1338 unsigned int pxe_type
) {
1339 struct setting pxe_discovery_control_setting
=
1340 { .tag
= DHCP_PXE_DISCOVERY_CONTROL
};
1341 struct setting pxe_boot_servers_setting
=
1342 { .tag
= DHCP_PXE_BOOT_SERVERS
};
1343 struct setting pxe_boot_server_mcast_setting
=
1344 { .tag
= DHCP_PXE_BOOT_SERVER_MCAST
};
1345 ssize_t pxebs_list_len
;
1346 struct dhcp_session
*dhcp
;
1348 unsigned int pxe_discovery_control
;
1351 /* Get upper bound for PXE boot server IP address list */
1352 pxebs_list_len
= fetch_setting_len ( NULL
, &pxe_boot_servers_setting
);
1353 if ( pxebs_list_len
< 0 )
1356 /* Allocate and initialise structure */
1357 dhcp
= zalloc ( sizeof ( *dhcp
) + sizeof ( *ip
) /* mcast */ +
1358 sizeof ( *ip
) /* bcast */ + pxebs_list_len
+
1359 sizeof ( *ip
) /* terminator */ );
1362 dhcp
->refcnt
.free
= dhcp_free
;
1363 job_init ( &dhcp
->job
, &dhcp_job_operations
, &dhcp
->refcnt
);
1364 xfer_init ( &dhcp
->xfer
, &dhcp_xfer_operations
, &dhcp
->refcnt
);
1365 dhcp
->netdev
= netdev_get ( netdev
);
1366 dhcp
->local
.sin_family
= AF_INET
;
1367 fetch_ipv4_setting ( netdev_settings ( netdev
), &ip_setting
,
1368 &dhcp
->local
.sin_addr
);
1369 dhcp
->local
.sin_port
= htons ( BOOTPC_PORT
);
1370 dhcp
->pxe_type
= htons ( pxe_type
);
1371 dhcp
->timer
.expired
= dhcp_timer_expired
;
1373 /* Construct PXE boot server IP address lists */
1374 pxe_discovery_control
=
1375 fetch_uintz_setting ( NULL
, &pxe_discovery_control_setting
);
1376 ip
= ( ( ( void * ) dhcp
) + sizeof ( *dhcp
) );
1377 dhcp
->pxe_attempt
= ip
;
1378 if ( ! ( pxe_discovery_control
& PXEBS_NO_MULTICAST
) ) {
1379 fetch_ipv4_setting ( NULL
, &pxe_boot_server_mcast_setting
, ip
);
1383 if ( ! ( pxe_discovery_control
& PXEBS_NO_BROADCAST
) )
1384 (ip
++)->s_addr
= INADDR_BROADCAST
;
1385 if ( pxe_discovery_control
& PXEBS_NO_UNKNOWN_SERVERS
)
1386 dhcp
->pxe_accept
= ip
;
1387 if ( pxebs_list_len
) {
1388 uint8_t buf
[pxebs_list_len
];
1390 fetch_setting ( NULL
, &pxe_boot_servers_setting
,
1391 buf
, sizeof ( buf
) );
1392 pxebs_list ( dhcp
, buf
, sizeof ( buf
), ip
);
1394 if ( ! dhcp
->pxe_attempt
->s_addr
) {
1395 DBGC ( dhcp
, "DHCP %p has no PXE boot servers for type %04x\n",
1401 /* Dump out PXE server lists */
1402 DBGC ( dhcp
, "DHCP %p attempting", dhcp
);
1403 for ( ip
= dhcp
->pxe_attempt
; ip
->s_addr
; ip
++ )
1404 DBGC ( dhcp
, " %s", inet_ntoa ( *ip
) );
1405 DBGC ( dhcp
, "\n" );
1406 if ( dhcp
->pxe_accept
) {
1407 DBGC ( dhcp
, "DHCP %p accepting", dhcp
);
1408 for ( ip
= dhcp
->pxe_accept
; ip
->s_addr
; ip
++ )
1409 DBGC ( dhcp
, " %s", inet_ntoa ( *ip
) );
1410 DBGC ( dhcp
, "\n" );
1413 /* Instantiate child objects and attach to our interfaces */
1414 if ( ( rc
= xfer_open_socket ( &dhcp
->xfer
, SOCK_DGRAM
, &dhcp_peer
,
1415 ( struct sockaddr
* ) &dhcp
->local
) ) != 0 )
1418 /* Enter PXEBS state */
1419 dhcp_set_state ( dhcp
, &dhcp_state_pxebs
);
1421 /* Attach parent interface, mortalise self, and return */
1422 job_plug_plug ( &dhcp
->job
, job
);
1423 ref_put ( &dhcp
->refcnt
);
1427 dhcp_finished ( dhcp
, rc
);
1428 ref_put ( &dhcp
->refcnt
);