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