iPXE
autoboot.c
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2006 Michael Brown <mbrown@fensystems.co.uk>.
3  *
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.
8  *
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.
13  *
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., 51 Franklin Street, Fifth Floor, Boston, MA
17  * 02110-1301, USA.
18  *
19  * You can also choose to distribute this program under the terms of
20  * the Unmodified Binary Distribution Licence (as given in the file
21  * COPYING.UBDL), provided that you have satisfied its requirements.
22  */
23 
24 FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL );
25 
26 #include <string.h>
27 #include <stdio.h>
28 #include <errno.h>
29 #include <ipxe/netdevice.h>
30 #include <ipxe/vlan.h>
31 #include <ipxe/dhcp.h>
32 #include <ipxe/settings.h>
33 #include <ipxe/image.h>
34 #include <ipxe/sanboot.h>
35 #include <ipxe/uri.h>
36 #include <ipxe/open.h>
37 #include <ipxe/init.h>
38 #include <ipxe/keys.h>
39 #include <ipxe/version.h>
40 #include <ipxe/shell.h>
41 #include <ipxe/features.h>
42 #include <ipxe/image.h>
43 #include <ipxe/timer.h>
44 #include <usr/ifmgmt.h>
45 #include <usr/route.h>
46 #include <usr/imgmgmt.h>
47 #include <usr/prompt.h>
48 #include <usr/autoboot.h>
49 #include <config/general.h>
50 #include <config/branding.h>
51 
52 /** @file
53  *
54  * Automatic booting
55  *
56  */
57 
58 /** Link-layer address of preferred autoboot device, if known */
60 
61 /** VLAN tag of preferred autoboot device, if known */
62 static unsigned int autoboot_vlan;
63 
64 /** Device location of preferred autoboot device, if known */
66 
67 /** Autoboot device tester */
68 static int ( * is_autoboot_device ) ( struct net_device *netdev );
69 
70 /* Disambiguate the various error causes */
71 #define ENOENT_BOOT __einfo_error ( EINFO_ENOENT_BOOT )
72 #define EINFO_ENOENT_BOOT \
73  __einfo_uniqify ( EINFO_ENOENT, 0x01, "Nothing to boot" )
74 
75 #define NORMAL "\033[0m"
76 #define BOLD "\033[1m"
77 #define CYAN "\033[36m"
78 
79 /** The "scriptlet" setting */
80 const struct setting scriptlet_setting __setting ( SETTING_MISC, scriptlet ) = {
81  .name = "scriptlet",
82  .description = "Boot scriptlet",
83  .tag = DHCP_EB_SCRIPTLET,
84  .type = &setting_type_string,
85 };
86 
87 /**
88  * Perform PXE menu boot when PXE stack is not available
89  */
91  return -ENOTSUP;
92 }
93 
94 /** The "keep-san" setting */
95 const struct setting keep_san_setting __setting ( SETTING_SANBOOT_EXTRA,
96  keep-san ) = {
97  .name = "keep-san",
98  .description = "Preserve SAN connection",
99  .tag = DHCP_EB_KEEP_SAN,
100  .type = &setting_type_int8,
101 };
102 
103 /** The "skip-san-boot" setting */
104 const struct setting skip_san_boot_setting __setting ( SETTING_SANBOOT_EXTRA,
105  skip-san-boot ) = {
106  .name = "skip-san-boot",
107  .description = "Do not boot from SAN device",
108  .tag = DHCP_EB_SKIP_SAN_BOOT,
109  .type = &setting_type_int8,
110 };
111 
112 /**
113  * Boot from filename and root-path URIs
114  *
115  * @v filename Filename
116  * @v root_paths Root path(s)
117  * @v root_path_count Number of root paths
118  * @v drive SAN drive (if applicable)
119  * @v san_config SAN boot configuration parameters
120  * @v flags Boot action flags
121  * @ret rc Return status code
122  *
123  * The somewhat tortuous flow of control in this function exists in
124  * order to ensure that the "sanboot" command remains identical in
125  * function to a SAN boot via a DHCP-specified root path, and to
126  * provide backwards compatibility for the "keep-san" and
127  * "skip-san-boot" options.
128  */
129 int uriboot ( struct uri *filename, struct uri **root_paths,
130  unsigned int root_path_count, int drive,
131  struct san_boot_config *san_config, unsigned int flags ) {
132  struct image *image;
133  const char *san_filename;
134  int rc;
135 
136  /* Hook SAN device, if applicable */
137  if ( root_path_count ) {
138  drive = san_hook ( drive, root_paths, root_path_count,
140  SAN_NO_DESCRIBE : 0 ) );
141  if ( drive < 0 ) {
142  rc = drive;
143  printf ( "Could not open SAN device: %s\n",
144  strerror ( rc ) );
145  goto err_san_hook;
146  }
147  printf ( "Registered SAN device %#02x\n", drive );
148  }
149 
150  /* Describe SAN device, if applicable */
151  if ( ! ( flags & URIBOOT_NO_SAN_DESCRIBE ) ) {
152  if ( ( rc = san_describe() ) != 0 ) {
153  printf ( "Could not describe SAN devices: %s\n",
154  strerror ( rc ) );
155  goto err_san_describe;
156  }
157  }
158 
159  /* Allow a root-path-only boot with skip-san enabled to succeed */
160  rc = 0;
161 
162  /* Attempt filename boot if applicable */
163  if ( filename ) {
164  if ( ( rc = imgdownload ( filename, 0, &image ) ) != 0 )
165  goto err_download;
166  imgstat ( image );
168  if ( ( rc = image_exec ( image ) ) != 0 ) {
169  printf ( "Could not boot image: %s\n",
170  strerror ( rc ) );
171  /* Fall through to (possibly) attempt a SAN boot
172  * as a fallback. If no SAN boot is attempted,
173  * our status will become the return status.
174  */
175  } else {
176  /* Always print an extra newline, because we
177  * don't know where the NBP may have left the
178  * cursor.
179  */
180  printf ( "\n" );
181  }
182  }
183 
184  /* Attempt SAN boot if applicable */
185  if ( ! ( flags & URIBOOT_NO_SAN_BOOT ) ) {
186  san_filename = san_config->filename;
187  if ( fetch_intz_setting ( NULL, &skip_san_boot_setting) == 0 ) {
188  printf ( "Booting%s%s from SAN device %#02x\n",
189  ( san_filename ? " " : "" ),
190  ( san_filename ? san_filename : "" ), drive );
191  rc = san_boot ( drive, san_config );
192  printf ( "Boot from SAN device %#02x failed: %s\n",
193  drive, strerror ( rc ) );
194  } else {
195  printf ( "Skipping boot from SAN device %#02x\n",
196  drive );
197  /* Avoid overwriting a possible failure status
198  * from a filename boot.
199  */
200  }
201  }
202 
203  err_download:
204  err_san_describe:
205  /* Unhook SAN device, if applicable */
206  if ( ! ( flags & URIBOOT_NO_SAN_UNHOOK ) ) {
207  if ( fetch_intz_setting ( NULL, &keep_san_setting ) == 0 ) {
208  san_unhook ( drive );
209  printf ( "Unregistered SAN device %#02x\n", drive );
210  } else {
211  printf ( "Preserving SAN device %#02x\n", drive );
212  }
213  }
214  err_san_hook:
215  return rc;
216 }
217 
218 /**
219  * Close all but one network device
220  *
221  * Called before a fresh boot attempt in order to free up memory. We
222  * don't just close the device immediately after the boot fails,
223  * because there may still be TCP connections in the process of
224  * closing.
225  */
226 static void close_other_netdevs ( struct net_device *netdev ) {
227  struct net_device *other;
228 
229  for_each_netdev ( other ) {
230  if ( other != netdev )
231  ifclose ( other );
232  }
233 }
234 
235 /**
236  * Fetch next-server and filename settings into a URI
237  *
238  * @v settings Settings block
239  * @ret uri URI, or NULL on failure
240  */
242  union {
243  struct sockaddr sa;
244  struct sockaddr_in sin;
245  } next_server;
246  char *raw_filename = NULL;
247  struct uri *uri = NULL;
248  char *filename;
249 
250  /* Initialise server address */
251  memset ( &next_server, 0, sizeof ( next_server ) );
252 
253  /* If we have a filename, fetch it along with the next-server
254  * setting from the same settings block.
255  */
256  if ( fetch_setting ( settings, &filename_setting, &settings,
257  NULL, NULL, 0 ) >= 0 ) {
258  fetch_string_setting_copy ( settings, &filename_setting,
259  &raw_filename );
260  fetch_ipv4_setting ( settings, &next_server_setting,
261  &next_server.sin.sin_addr );
262  }
263  if ( ! raw_filename )
264  goto err_fetch;
265 
266  /* Populate server address */
267  if ( next_server.sin.sin_addr.s_addr ) {
268  next_server.sin.sin_family = AF_INET;
269  printf ( "Next server: %s\n",
270  inet_ntoa ( next_server.sin.sin_addr ) );
271  }
272 
273  /* Expand filename setting */
274  filename = expand_settings ( raw_filename );
275  if ( ! filename )
276  goto err_expand;
277  if ( filename[0] )
278  printf ( "Filename: %s\n", filename );
279 
280  /* Construct URI */
281  uri = pxe_uri ( &next_server.sa, filename );
282  if ( ! uri )
283  goto err_parse;
284 
285  err_parse:
286  free ( filename );
287  err_expand:
288  free ( raw_filename );
289  err_fetch:
290  return uri;
291 }
292 
293 /**
294  * Fetch root-path setting into a URI
295  *
296  * @v settings Settings block
297  * @ret uri URI, or NULL on failure
298  */
299 static struct uri * fetch_root_path ( struct settings *settings ) {
300  struct uri *uri = NULL;
301  char *raw_root_path;
302  char *root_path;
303 
304  /* Fetch root-path setting */
305  fetch_string_setting_copy ( settings, &root_path_setting,
306  &raw_root_path );
307  if ( ! raw_root_path )
308  goto err_fetch;
309 
310  /* Expand filename setting */
311  root_path = expand_settings ( raw_root_path );
312  if ( ! root_path )
313  goto err_expand;
314  if ( root_path[0] )
315  printf ( "Root path: %s\n", root_path );
316 
317  /* Parse root path */
318  uri = parse_uri ( root_path );
319  if ( ! uri )
320  goto err_parse;
321 
322  err_parse:
323  free ( root_path );
324  err_expand:
325  free ( raw_root_path );
326  err_fetch:
327  return uri;
328 }
329 
330 /**
331  * Fetch san-filename setting
332  *
333  * @v settings Settings block
334  * @ret san_filename SAN filename, or NULL on failure
335  */
336 static char * fetch_san_filename ( struct settings *settings ) {
337  char *raw_san_filename;
338  char *san_filename = NULL;
339 
340  /* Fetch san-filename setting */
341  fetch_string_setting_copy ( settings, &san_filename_setting,
342  &raw_san_filename );
343  if ( ! raw_san_filename )
344  goto err_fetch;
345 
346  /* Expand san-filename setting */
347  san_filename = expand_settings ( raw_san_filename );
348  if ( ! san_filename )
349  goto err_expand;
350  if ( san_filename[0] )
351  printf ( "SAN filename: %s\n", san_filename );
352 
353  err_expand:
354  free ( raw_san_filename );
355  err_fetch:
356  return san_filename;
357 }
358 
359 /**
360  * Check whether or not we have a usable PXE menu
361  *
362  * @ret have_menu A usable PXE menu is present
363  */
364 static int have_pxe_menu ( void ) {
365  struct setting vendor_class_id_setting
366  = { .tag = DHCP_VENDOR_CLASS_ID };
367  struct setting pxe_discovery_control_setting
369  struct setting pxe_boot_menu_setting
370  = { .tag = DHCP_PXE_BOOT_MENU };
371  char buf[ 10 /* "PXEClient" + NUL */ ];
372  unsigned int pxe_discovery_control;
373 
374  fetch_string_setting ( NULL, &vendor_class_id_setting,
375  buf, sizeof ( buf ) );
376  pxe_discovery_control =
377  fetch_uintz_setting ( NULL, &pxe_discovery_control_setting );
378 
379  return ( ( strcmp ( buf, "PXEClient" ) == 0 ) &&
380  setting_exists ( NULL, &pxe_boot_menu_setting ) &&
381  ( ! ( ( pxe_discovery_control & PXEBS_SKIP ) &&
382  setting_exists ( NULL, &filename_setting ) ) ) );
383 }
384 
385 /**
386  * Boot from a network device
387  *
388  * @v netdev Network device
389  * @ret rc Return status code
390  */
391 int netboot ( struct net_device *netdev ) {
392  struct san_boot_config san_config;
393  struct uri *filename;
394  struct uri *root_path;
395  char *san_filename;
396  int rc;
397 
398  /* Close all other network devices */
400 
401  /* Open device and display device status */
402  if ( ( rc = ifopen ( netdev ) ) != 0 )
403  goto err_ifopen;
404  ifstat ( netdev );
405 
406  /* Configure device */
407  if ( ( rc = ifconf ( netdev, NULL, 0 ) ) != 0 )
408  goto err_dhcp;
409  route();
410 
411  /* Try PXE menu boot, if applicable */
412  if ( have_pxe_menu() ) {
413  printf ( "Booting from PXE menu\n" );
414  rc = pxe_menu_boot ( netdev );
415  goto err_pxe_menu_boot;
416  }
417 
418  /* Fetch next server and filename (if any) */
419  filename = fetch_next_server_and_filename ( NULL );
420 
421  /* Fetch root path (if any) */
422  root_path = fetch_root_path ( NULL );
423 
424  /* Fetch SAN filename (if any) */
425  san_filename = fetch_san_filename ( NULL );
426 
427  /* Construct SAN boot configuration parameters */
428  memset ( &san_config, 0, sizeof ( san_config ) );
429  san_config.filename = san_filename;
430 
431  /* If we have both a filename and a root path, ignore an
432  * unsupported or missing URI scheme in the root path, since
433  * it may represent an NFS root.
434  */
435  if ( filename && root_path &&
436  ( ( ! uri_is_absolute ( root_path ) ) ||
437  ( xfer_uri_opener ( root_path->scheme ) == NULL ) ) ) {
438  printf ( "Ignoring unsupported root path\n" );
439  uri_put ( root_path );
440  root_path = NULL;
441  }
442 
443  /* Check that we have something to boot */
444  if ( ! ( filename || root_path ) ) {
445  rc = -ENOENT_BOOT;
446  printf ( "Nothing to boot: %s\n", strerror ( rc ) );
447  goto err_no_boot;
448  }
449 
450  /* Boot using next server, filename and root path */
451  if ( ( rc = uriboot ( filename, &root_path, ( root_path ? 1 : 0 ),
452  san_default_drive(), &san_config,
453  ( root_path ? 0 : URIBOOT_NO_SAN ) ) ) != 0 )
454  goto err_uriboot;
455 
456  err_uriboot:
457  err_no_boot:
458  free ( san_filename );
459  uri_put ( root_path );
460  uri_put ( filename );
461  err_pxe_menu_boot:
462  err_dhcp:
463  err_ifopen:
464  return rc;
465 }
466 
467 /**
468  * Test if network device matches the autoboot device bus type and location
469  *
470  * @v netdev Network device
471  * @ret is_autoboot Network device matches the autoboot device
472  */
473 static int is_autoboot_busloc ( struct net_device *netdev ) {
474  struct device *dev;
475 
476  for ( dev = netdev->dev ; dev ; dev = dev->parent ) {
477  if ( ( dev->desc.bus_type == autoboot_desc.bus_type ) &&
478  ( dev->desc.location == autoboot_desc.location ) )
479  return 1;
480  }
481  return 0;
482 }
483 
484 /**
485  * Identify autoboot device by bus type and location
486  *
487  * @v bus_type Bus type
488  * @v location Location
489  */
490 void set_autoboot_busloc ( unsigned int bus_type, unsigned int location ) {
491 
492  /* Record autoboot device description */
493  autoboot_desc.bus_type = bus_type;
494  autoboot_desc.location = location;
495 
496  /* Mark autoboot device as present */
498 }
499 
500 /**
501  * Test if network device matches the autoboot device link-layer address
502  *
503  * @v netdev Network device
504  * @ret is_autoboot Network device matches the autoboot device
505  */
506 static int is_autoboot_ll_addr ( struct net_device *netdev ) {
507 
508  return ( ( memcmp ( netdev->ll_addr, autoboot_ll_addr,
509  netdev->ll_protocol->ll_addr_len ) == 0 ) &&
510  ( vlan_tag ( netdev ) == autoboot_vlan ) );
511 }
512 
513 /**
514  * Identify autoboot device by link-layer address
515  *
516  * @v ll_addr Link-layer address
517  * @v len Length of link-layer address
518  * @v vlan VLAN tag
519  */
520 void set_autoboot_ll_addr ( const void *ll_addr, size_t len,
521  unsigned int vlan ) {
522 
523  /* Record autoboot link-layer address (truncated if necessary) */
524  if ( len > sizeof ( autoboot_ll_addr ) )
525  len = sizeof ( autoboot_ll_addr );
526  memcpy ( autoboot_ll_addr, ll_addr, len );
527 
528  /* Record autoboot VLAN tag */
529  autoboot_vlan = vlan;
530 
531  /* Mark autoboot device as present */
533 }
534 
535 /**
536  * Boot the system
537  */
538 static int autoboot ( void ) {
539  struct net_device *netdev;
540  int rc = -ENODEV;
541 
542  /* Try booting from each network device. If we have a
543  * specified autoboot device location, then use only devices
544  * matching that location.
545  */
546  for_each_netdev ( netdev ) {
547 
548  /* Skip any non-matching devices, if applicable */
549  if ( is_autoboot_device && ( ! is_autoboot_device ( netdev ) ) )
550  continue;
551 
552  /* Attempt booting from this device */
553  rc = netboot ( netdev );
554  }
555 
556  printf ( "No more network devices\n" );
557  return rc;
558 }
559 
560 /**
561  * Prompt for shell entry
562  *
563  * @ret enter_shell User wants to enter shell
564  */
565 static int shell_banner ( void ) {
566 
567  /* Skip prompt if timeout is zero */
568  if ( BANNER_TIMEOUT <= 0 )
569  return 0;
570 
571  /* Prompt user */
572  printf ( "\n" );
573  return ( prompt ( "Press Ctrl-B for the " PRODUCT_SHORT_NAME
574  " command line...",
575  ( ( BANNER_TIMEOUT * TICKS_PER_SEC ) / 10 ),
576  CTRL_B ) == 0 );
577 }
578 
579 /**
580  * Main iPXE flow of execution
581  *
582  * @v netdev Network device, or NULL
583  * @ret rc Return status code
584  */
585 int ipxe ( struct net_device *netdev ) {
586  struct feature *feature;
587  struct image *image;
588  char *scriptlet;
589  int rc;
590 
591  /*
592  * Print welcome banner
593  *
594  *
595  * If you wish to brand this build of iPXE, please do so by
596  * defining the string PRODUCT_NAME in config/branding.h.
597  *
598  * While nothing in the GPL prevents you from removing all
599  * references to iPXE or https://ipxe.org, we prefer you not
600  * to do so.
601  *
602  */
603  printf ( NORMAL "\n\n" PRODUCT_NAME "\n" BOLD PRODUCT_SHORT_NAME " %s"
604  NORMAL " -- " PRODUCT_TAG_LINE " -- "
605  CYAN PRODUCT_URI NORMAL "\nFeatures:", product_version );
607  printf ( " %s", feature->name );
608  printf ( "\n" );
609 
610  /* Boot system */
611  if ( ( image = first_image() ) != NULL ) {
612  /* We have an embedded image; execute it */
613  return image_exec ( image );
614  } else if ( shell_banner() ) {
615  /* User wants shell; just give them a shell */
616  return shell();
617  } else {
618  fetch_string_setting_copy ( NULL, &scriptlet_setting,
619  &scriptlet );
620  if ( scriptlet ) {
621  /* User has defined a scriptlet; execute it */
622  rc = system ( scriptlet );
623  free ( scriptlet );
624  return rc;
625  } else {
626  /* Try booting. If booting fails, offer the
627  * user another chance to enter the shell.
628  */
629  if ( netdev ) {
630  rc = netboot ( netdev );
631  } else {
632  rc = autoboot();
633  }
634  if ( shell_banner() )
635  rc = shell();
636  return rc;
637  }
638  }
639 }
#define CTRL_B
Definition: keys.h:19
static unsigned int autoboot_vlan
VLAN tag of preferred autoboot device, if known.
Definition: autoboot.c:62
int uriboot(struct uri *filename, struct uri **root_paths, unsigned int root_path_count, int drive, struct san_boot_config *san_config, unsigned int flags)
Boot from filename and root-path URIs.
Definition: autoboot.c:129
long fetch_intz_setting(struct settings *settings, const struct setting *setting)
Fetch value of signed integer setting, or zero.
Definition: settings.c:1053
unsigned int flags
Flags.
Definition: image.h:36
#define URIBOOT_NO_SAN
Definition: autoboot.h:26
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int ifconf(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout)
Perform network device configuration.
Definition: ifmgmt.c:274
char * name
Feature name.
Definition: features.h:80
Dynamic Host Configuration Protocol.
#define TICKS_PER_SEC
Number of ticks per second.
Definition: timer.h:15
#define PRODUCT_SHORT_NAME
Definition: branding.h:28
#define SETTING_SANBOOT_EXTRA
SAN boot additional settings.
Definition: settings.h:74
int printf(const char *fmt,...)
Write a formatted string to the console.
Definition: vsprintf.c:464
void set_autoboot_busloc(unsigned int bus_type, unsigned int location)
Identify autoboot device by bus type and location.
Definition: autoboot.c:490
FILE_LICENCE(GPL2_OR_LATER_OR_UBDL)
static void uri_put(struct uri *uri)
Decrement URI reference count.
Definition: uri.h:205
Minimal command shell.
uint8_t ll_addr_len
Link-layer address length.
Definition: netdevice.h:198
int san_describe(void)
Describe SAN devices for SAN-booted operating system.
static void close_other_netdevs(struct net_device *netdev)
Close all but one network device.
Definition: autoboot.c:226
int san_hook(unsigned int drive, struct uri **uris, unsigned int count, unsigned int flags)
Hook SAN device.
static int uri_is_absolute(const struct uri *uri)
URI is an absolute URI.
Definition: uri.h:135
#define FEATURES
Named feature table.
Definition: features.h:84
int netboot(struct net_device *netdev)
Boot from a network device.
Definition: autoboot.c:391
#define NORMAL
Definition: autoboot.c:75
Error codes.
int fetch_ipv4_setting(struct settings *settings, const struct setting *setting, struct in_addr *inp)
Fetch value of IPv4 address setting.
Definition: settings.c:912
struct uri * pxe_uri(struct sockaddr *sa_server, const char *filename)
Construct URI from server address and filename.
Definition: uri.c:808
#define PRODUCT_URI
Definition: branding.h:29
int san_boot(unsigned int drive, struct san_boot_config *config)
Attempt to boot from a SAN device.
static uint8_t autoboot_ll_addr[MAX_LL_ADDR_LEN]
Link-layer address of preferred autoboot device, if known.
Definition: autoboot.c:59
unsigned int san_default_drive(void)
Get default SAN drive number.
Definition: sanboot.c:970
int shell(void)
Start command shell.
Definition: shell.c:84
Branding configuration.
Prompt for keypress.
iPXE timers
#define SETTING_MISC
Miscellaneous settings.
Definition: settings.h:80
IPv4 socket address.
Definition: in.h:84
An executable image.
Definition: image.h:24
char * expand_settings(const char *string)
Expand variables within string.
Definition: settings.c:2330
uint8_t drive
Drive number.
Definition: int13.h:16
Automatic booting.
#define DHCP_EB_SCRIPTLET
Scriptlet.
Definition: dhcp.h:408
Uniform Resource Identifiers.
struct device * parent
Bus device.
Definition: device.h:85
Routing management.
#define IMAGE_AUTO_UNREGISTER
Image will be automatically unregistered after execution.
Definition: image.h:70
void ifclose(struct net_device *netdev)
Close network device.
Definition: ifmgmt.c:82
#define ENOTSUP
Operation not supported.
Definition: errno.h:589
static int is_autoboot_ll_addr(struct net_device *netdev)
Test if network device matches the autoboot device link-layer address.
Definition: autoboot.c:506
A hardware device description.
Definition: device.h:19
union ena_feature feature
Feature.
Definition: ena.h:14
#define CYAN
Definition: autoboot.c:77
#define BANNER_TIMEOUT
Definition: general.h:29
int ipxe(struct net_device *netdev)
Main iPXE flow of execution.
Definition: autoboot.c:585
int image_exec(struct image *image)
Execute image.
Definition: image.c:378
const char * name
Name.
Definition: settings.h:28
#define DHCP_EB_SKIP_SAN_BOOT
Skip booting from SAN drive.
Definition: dhcp.h:396
static int(* is_autoboot_device)(struct net_device *netdev)
Autoboot device tester.
Definition: autoboot.c:68
uint64_t tag
Setting tag, if applicable.
Definition: settings.h:43
A hardware device.
Definition: device.h:73
const char * scheme
Scheme.
Definition: uri.h:68
void * memcpy(void *dest, const void *src, size_t len) __nonnull
#define __unused
Declare a variable or data structure as unused.
Definition: compiler.h:573
#define MAX_LL_ADDR_LEN
Maximum length of a link-layer address.
Definition: netdevice.h:36
struct uri * fetch_next_server_and_filename(struct settings *settings)
Fetch next-server and filename settings into a URI.
Definition: autoboot.c:241
Executable images.
SAN boot configuration parameters.
Definition: sanboot.h:110
void imgstat(struct image *image)
Display status of an image.
Definition: imgmgmt.c:158
static struct net_device * netdev
Definition: gdbudp.c:52
struct sockaddr sa
Definition: syslog.c:55
void route(void)
Print routing table.
Definition: route.c:39
const char * filename
Boot filename (or NULL to use default)
Definition: sanboot.h:112
Feature list.
int fetch_string_setting(struct settings *settings, const struct setting *setting, char *data, size_t len)
Fetch value of string setting.
Definition: settings.c:841
int fetch_string_setting_copy(struct settings *settings, const struct setting *setting, char **data)
Fetch value of string setting.
Definition: settings.c:873
unsigned int location
Location.
Definition: device.h:29
const struct setting scriptlet_setting __setting(SETTING_MISC, scriptlet)
The "scriptlet" setting.
static struct image * first_image(void)
Retrieve first image.
Definition: image.h:184
Configuration settings.
Generalized socket address structure.
Definition: socket.h:96
int fetch_setting(struct settings *settings, const struct setting *setting, struct settings **origin, struct setting *fetched, void *data, size_t len)
Fetch setting.
Definition: settings.c:666
uint8_t flags
Flags.
Definition: ena.h:18
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:543
static struct uri * fetch_root_path(struct settings *settings)
Fetch root-path setting into a URI.
Definition: autoboot.c:299
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:385
A network device.
Definition: netdevice.h:352
#define ENODEV
No such device.
Definition: errno.h:509
char * inet_ntoa(struct in_addr in)
Convert IPv4 address to dotted-quad notation.
Definition: ipv4.c:668
A settings block.
Definition: settings.h:132
const char product_version[]
Product version string.
Definition: version.c:70
void set_autoboot_ll_addr(const void *ll_addr, size_t len, unsigned int vlan)
Identify autoboot device by link-layer address.
Definition: autoboot.c:520
unsigned char uint8_t
Definition: stdint.h:10
Data transfer interface opening.
Device should not be included in description tables.
Definition: sanboot.h:106
unsigned long fetch_uintz_setting(struct settings *settings, const struct setting *setting)
Fetch value of unsigned integer setting, or zero.
Definition: settings.c:1068
int prompt(const char *text, unsigned long timeout, int key)
Prompt for keypress.
Definition: prompt.c:48
#define DHCP_PXE_BOOT_MENU
PXE boot menu.
Definition: dhcp.h:127
static char * fetch_san_filename(struct settings *settings)
Fetch san-filename setting.
Definition: autoboot.c:336
Version number.
#define DHCP_EB_KEEP_SAN
Keep SAN drive registered.
Definition: dhcp.h:387
static int autoboot(void)
Boot the system.
Definition: autoboot.c:538
__weak int pxe_menu_boot(struct net_device *netdev __unused)
Perform PXE menu boot when PXE stack is not available.
Definition: autoboot.c:90
A setting.
Definition: settings.h:23
int ifopen(struct net_device *netdev)
Open network device.
Definition: ifmgmt.c:65
struct device * dev
Underlying hardware device.
Definition: netdevice.h:364
Network device management.
#define PRODUCT_TAG_LINE
Definition: branding.h:38
static int setting_exists(struct settings *settings, const struct setting *setting)
Check existence of predefined setting.
Definition: settings.h:543
A named feature.
Definition: features.h:78
#define DHCP_VENDOR_CLASS_ID
Vendor class identifier.
Definition: dhcp.h:217
void san_unhook(unsigned int drive)
Unhook SAN device.
static int shell_banner(void)
Prompt for shell entry.
Definition: autoboot.c:565
#define PRODUCT_NAME
Definition: branding.h:27
Skip discovery if filename present.
Definition: dhcp.h:107
unsigned int bus_type
Bus type.
Definition: device.h:24
General configuration.
#define BOLD
Definition: autoboot.c:76
Image management.
int strcmp(const char *first, const char *second)
Compare strings.
Definition: string.c:173
static int have_pxe_menu(void)
Check whether or not we have a usable PXE menu.
Definition: autoboot.c:364
Key definitions.
static struct device_description autoboot_desc
Device location of preferred autoboot device, if known.
Definition: autoboot.c:65
Virtual LANs.
struct device_description desc
Device description.
Definition: device.h:79
#define __weak
Declare a function as weak (use before the definition)
Definition: compiler.h:219
A Uniform Resource Identifier.
Definition: uri.h:64
int imgdownload(struct uri *uri, unsigned long timeout, struct image **image)
Download a new image.
Definition: imgmgmt.c:51
Network interface management.
struct uri_opener * xfer_uri_opener(const char *scheme)
Find opener for URI scheme.
Definition: open.c:47
void ifstat(struct net_device *netdev)
Print status of network device.
Definition: ifmgmt.c:110
struct sockaddr_in sin
Definition: syslog.c:57
#define DHCP_PXE_DISCOVERY_CONTROL
PXE boot server discovery control.
Definition: dhcp.h:96
uint8_t ll_addr[MAX_LL_ADDR_LEN]
Link-layer address.
Definition: netdevice.h:387
#define ENOENT_BOOT
Definition: autoboot.c:71
static unsigned int vlan_tag(struct net_device *netdev)
Get the VLAN tag.
Definition: vlan.h:73
iPXE sanboot API
int memcmp(const void *first, const void *second, size_t len)
Compare memory regions.
Definition: string.c:114
uint32_t len
Length.
Definition: ena.h:14
#define NULL
NULL pointer (VOID *)
Definition: Base.h:321
String functions.
static int is_autoboot_busloc(struct net_device *netdev)
Test if network device matches the autoboot device bus type and location.
Definition: autoboot.c:473
#define AF_INET
IPv4 Internet addresses.
Definition: socket.h:63
struct ll_protocol * ll_protocol
Link-layer protocol.
Definition: netdevice.h:372
uint8_t system[ETH_ALEN]
System identifier.
Definition: eth_slow.h:24
struct uri * parse_uri(const char *uri_string)
Parse URI.
Definition: uri.c:296
void * memset(void *dest, int character, size_t len) __nonnull