iPXE
efi_pxe.h File Reference

EFI PXE base code protocol. More...

#include <ipxe/efi/efi.h>
#include <ipxe/netdevice.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 FILE_SECBOOT (PERMITTED)
int efi_pxe_install (EFI_HANDLE handle, struct net_device *netdev)
 Install PXE base code protocol.
void efi_pxe_uninstall (EFI_HANDLE handle)
 Uninstall PXE base code protocol.

Detailed Description

EFI PXE base code protocol.

Definition in file efi_pxe.h.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED )

References EFI_HANDLE, handle, and netdev.

◆ efi_pxe_install()

int efi_pxe_install ( EFI_HANDLE handle,
struct net_device * netdev )
extern

Install PXE base code protocol.

Parameters
handleEFI handle
netdevUnderlying network device
Return values
rcReturn status code

Definition at line 1549 of file efi_pxe.c.

1549 {
1550 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1552 struct efi_pxe *pxe;
1553 struct in_addr ip;
1554 BOOLEAN use_ipv6;
1555 int leak = 0;
1556 EFI_STATUS efirc;
1557 int rc;
1558
1559 /* Allocate and initialise structure */
1560 pxe = zalloc ( sizeof ( *pxe ) );
1561 if ( ! pxe ) {
1562 rc = -ENOMEM;
1563 goto err_alloc;
1564 }
1565 ref_init ( &pxe->refcnt, efi_pxe_free );
1566 pxe->netdev = netdev_get ( netdev );
1567 pxe->name = netdev->name;
1568 pxe->handle = handle;
1569 memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1570 pxe->base.Mode = &pxe->mode;
1572 sizeof ( pxe->apple ) );
1573 intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1574 intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
1575 INIT_LIST_HEAD ( &pxe->queue );
1577 &pxe->refcnt );
1578
1579 /* Crude heuristic: assume that we prefer to use IPv4 if we
1580 * have an IPv4 address for the network device, otherwise
1581 * prefer IPv6 (if available).
1582 */
1584 use_ipv6 = ( ip.s_addr ? FALSE : ( ipv6 != NULL ) );
1585
1586 /* Start base code */
1587 efi_pxe_start ( &pxe->base, use_ipv6 );
1588
1589 /* Install PXE base code protocol */
1590 if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1591 &handle,
1594 NULL ) ) != 0 ) {
1595 rc = -EEFI ( efirc );
1596 DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
1597 pxe->name, strerror ( rc ) );
1598 goto err_install_protocol;
1599 }
1600
1601 /* Transfer reference to list and return */
1602 list_add_tail ( &pxe->list, &efi_pxes );
1603 DBGC ( pxe, "PXE %s installed for %s\n",
1604 pxe->name, efi_handle_name ( handle ) );
1605 return 0;
1606
1607 if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1608 handle,
1611 NULL ) ) != 0 ) {
1612 DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1613 pxe->name, strerror ( -EEFI ( efirc ) ) );
1614 leak = 1;
1615 }
1616 efi_nullify_pxe ( &pxe->base );
1617 efi_nullify_apple ( &pxe->apple );
1618 err_install_protocol:
1619 if ( ! leak )
1620 ref_put ( &pxe->refcnt );
1621 err_alloc:
1622 if ( leak )
1623 DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1624 return rc;
1625}
unsigned char BOOLEAN
Logical Boolean.
#define NULL
NULL pointer (VOID *)
Definition Base.h:322
RETURN_STATUS EFI_STATUS
Function return status for EFI API.
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
const char * efi_handle_name(EFI_HANDLE handle)
Get name of an EFI handle.
Definition efi_debug.c:652
EFI_GUID efi_pxe_base_code_protocol_guid
PXE base code protocol GUID.
Definition efi_guid.c:321
EFI_GUID efi_apple_net_boot_protocol_guid
Apple NetBoot protocol GUID.
Definition efi_guid.c:133
void efi_nullify_pxe(EFI_PXE_BASE_CODE_PROTOCOL *pxe)
Nullify PXE base code protocol.
Definition efi_null.c:537
void efi_nullify_apple(EFI_APPLE_NET_BOOT_PROTOCOL *apple)
Nullify Apple Net Boot protocol.
Definition efi_null.c:572
const struct setting ip_setting
static struct interface_descriptor efi_pxe_udp_desc
PXE UDP interface descriptor.
Definition efi_pxe.c:523
static struct interface_descriptor efi_pxe_tftp_desc
PXE file data transfer interface descriptor.
Definition efi_pxe.c:374
static void efi_pxe_free(struct refcnt *refcnt)
Free PXE base code.
Definition efi_pxe.c:117
static EFI_PXE_BASE_CODE_PROTOCOL efi_pxe_base_code_protocol
PXE base code protocol.
Definition efi_pxe.c:1449
static EFI_STATUS EFIAPI efi_pxe_start(EFI_PXE_BASE_CODE_PROTOCOL *base, BOOLEAN use_ipv6)
Start PXE base code.
Definition efi_pxe.c:710
static struct process_descriptor efi_pxe_process_desc
UDP close process descriptor.
Definition efi_pxe.c:583
static EFI_APPLE_NET_BOOT_PROTOCOL efi_apple_net_boot_protocol
Apple NetBoot protocol.
Definition efi_pxe.c:1530
static struct net_device * netdev
Definition gdbudp.c:53
#define AF_INET6
IPv6 Internet addresses.
Definition socket.h:65
#define DBGC(...)
Definition compiler.h:505
#define ENOMEM
Not enough space.
Definition errno.h:535
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:175
EFI_SYSTEM_TABLE * efi_systab
uint16_t handle
Handle.
Definition smbios.h:5
void * memcpy(void *dest, const void *src, size_t len) __nonnull
static void intf_init(struct interface *intf, struct interface_descriptor *desc, struct refcnt *refcnt)
Initialise an object interface.
Definition interface.h:204
#define list_add_tail(new, head)
Add a new entry to the tail of a list.
Definition list.h:94
#define INIT_LIST_HEAD(list)
Initialise a list head.
Definition list.h:46
void * zalloc(size_t size)
Allocate cleared memory.
Definition malloc.c:662
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:565
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:587
static void process_init_stopped(struct process *process, struct process_descriptor *desc, struct refcnt *refcnt)
Initialise process without adding to process list.
Definition process.h:146
IP4_t ip
Destination IP address.
Definition pxe_api.h:1
#define ref_put(refcnt)
Drop reference to object.
Definition refcnt.h:107
#define ref_init(refcnt, free)
Initialise a reference counter.
Definition refcnt.h:65
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
char * strerror(int errno)
Retrieve string representation of error number.
Definition strerror.c:79
EFI Boot Services Table.
Definition UefiSpec.h:1931
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition UefiSpec.h:2011
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition UefiSpec.h:2010
EFI_PXE_BASE_CODE_MODE * Mode
The pointer to the EFI_PXE_BASE_CODE_MODE data for this device.
A PXE base code.
Definition efi_pxe.c:70
struct interface udp
UDP interface.
Definition efi_pxe.c:105
struct net_device * netdev
Underlying network device.
Definition efi_pxe.c:74
struct list_head list
List of PXE base codes.
Definition efi_pxe.c:78
EFI_PXE_BASE_CODE_PROTOCOL base
PXE base code protocol.
Definition efi_pxe.c:83
struct list_head queue
List of received UDP packets.
Definition efi_pxe.c:107
struct interface tftp
(M)TFTP download interface
Definition efi_pxe.c:98
EFI_PXE_BASE_CODE_MODE mode
PXE base code mode.
Definition efi_pxe.c:85
EFI_APPLE_NET_BOOT_PROTOCOL apple
Apple NetBoot protocol.
Definition efi_pxe.c:87
struct refcnt refcnt
Reference count.
Definition efi_pxe.c:72
const char * name
Name.
Definition efi_pxe.c:76
EFI_HANDLE handle
Installed handle.
Definition efi_pxe.c:81
struct process process
UDP interface closer process.
Definition efi_pxe.c:109
IP address structure.
Definition in.h:42
A network-layer protocol of the TCP/IP stack (eg.
Definition tcpip.h:141
struct tcpip_net_protocol * tcpip_net_protocol(sa_family_t sa_family)
Find TCP/IP network-layer protocol.
Definition tcpip.c:69
#define FALSE
Definition tlan.h:45

References AF_INET6, efi_pxe::apple, efi_pxe::base, DBGC, EEFI, efi_apple_net_boot_protocol, efi_apple_net_boot_protocol_guid, EFI_HANDLE, efi_handle_name(), efi_nullify_apple(), efi_nullify_pxe(), efi_pxe_base_code_protocol, efi_pxe_base_code_protocol_guid, efi_pxe_free(), efi_pxe_process_desc, efi_pxe_start(), efi_pxe_tftp_desc, efi_pxe_udp_desc, efi_systab, ENOMEM, FALSE, fetch_ipv4_setting(), efi_pxe::handle, handle, INIT_LIST_HEAD, EFI_BOOT_SERVICES::InstallMultipleProtocolInterfaces, intf_init(), ip, ip_setting, efi_pxe::list, list_add_tail, memcpy(), _EFI_PXE_BASE_CODE_PROTOCOL::Mode, efi_pxe::mode, efi_pxe::name, efi_pxe::netdev, netdev, netdev_get(), netdev_settings(), NULL, efi_pxe::process, process_init_stopped(), efi_pxe::queue, rc, ref_init, ref_put, efi_pxe::refcnt, strerror(), tcpip_net_protocol(), efi_pxe::tftp, efi_pxe::udp, EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces, and zalloc().

Referenced by efi_image_exec().

◆ efi_pxe_uninstall()

void efi_pxe_uninstall ( EFI_HANDLE handle)
extern

Uninstall PXE base code protocol.

Parameters
handleEFI handle

Definition at line 1632 of file efi_pxe.c.

1632 {
1633 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1634 struct efi_pxe *pxe;
1635 int leak = efi_shutdown_in_progress;
1636 EFI_STATUS efirc;
1637
1638 /* Locate PXE base code */
1639 pxe = efi_pxe_find ( handle );
1640 if ( ! pxe ) {
1641 DBG ( "PXE could not find base code for %s\n",
1642 efi_handle_name ( handle ) );
1643 return;
1644 }
1645
1646 /* Stop base code */
1647 efi_pxe_stop ( &pxe->base );
1648
1649 /* Uninstall PXE base code protocol */
1650 if ( ( ! efi_shutdown_in_progress ) &&
1651 ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1652 handle,
1655 NULL ) ) != 0 ) ) {
1656 DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1657 pxe->name, strerror ( -EEFI ( efirc ) ) );
1658 leak = 1;
1659 }
1660 efi_nullify_pxe ( &pxe->base );
1661 efi_nullify_apple ( &pxe->apple );
1662
1663 /* Remove from list and drop list's reference */
1664 list_del ( &pxe->list );
1665 if ( ! leak )
1666 ref_put ( &pxe->refcnt );
1667
1668 /* Report leakage, if applicable */
1669 if ( leak && ( ! efi_shutdown_in_progress ) )
1670 DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1671}
int efi_shutdown_in_progress
EFI shutdown is in progress.
Definition efi_init.c:60
static EFI_STATUS EFIAPI efi_pxe_stop(EFI_PXE_BASE_CODE_PROTOCOL *base)
Stop PXE base code.
Definition efi_pxe.c:765
static struct efi_pxe * efi_pxe_find(EFI_HANDLE handle)
Locate PXE base code.
Definition efi_pxe.c:133
#define DBG(...)
Print a debugging message.
Definition compiler.h:498
#define list_del(list)
Delete an entry from a list.
Definition list.h:120

References efi_pxe::apple, efi_pxe::base, DBG, DBGC, EEFI, efi_apple_net_boot_protocol_guid, EFI_HANDLE, efi_handle_name(), efi_nullify_apple(), efi_nullify_pxe(), efi_pxe_base_code_protocol_guid, efi_pxe_find(), efi_pxe_stop(), efi_shutdown_in_progress, efi_systab, handle, efi_pxe::list, list_del, efi_pxe::name, NULL, ref_put, efi_pxe::refcnt, strerror(), and EFI_BOOT_SERVICES::UninstallMultipleProtocolInterfaces.

Referenced by efi_image_exec().