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 1573 of file efi_pxe.c.

1573 {
1574 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1576 struct efi_pxe *pxe;
1577 struct in_addr ip;
1578 BOOLEAN use_ipv6;
1579 int leak = 0;
1580 EFI_STATUS efirc;
1581 int rc;
1582
1583 /* Allocate and initialise structure */
1584 pxe = zalloc ( sizeof ( *pxe ) );
1585 if ( ! pxe ) {
1586 rc = -ENOMEM;
1587 goto err_alloc;
1588 }
1589 ref_init ( &pxe->refcnt, efi_pxe_free );
1590 pxe->netdev = netdev_get ( netdev );
1591 pxe->name = netdev->name;
1592 pxe->handle = handle;
1593 memcpy ( &pxe->base, &efi_pxe_base_code_protocol, sizeof ( pxe->base ));
1594 pxe->base.Mode = &pxe->mode;
1596 sizeof ( pxe->apple ) );
1597 intf_init ( &pxe->tftp, &efi_pxe_tftp_desc, &pxe->refcnt );
1598 intf_init ( &pxe->udp, &efi_pxe_udp_desc, &pxe->refcnt );
1599 INIT_LIST_HEAD ( &pxe->queue );
1601 &pxe->refcnt );
1602
1603 /* Crude heuristic: assume that we prefer to use IPv4 if we
1604 * have an IPv4 address for the network device, otherwise
1605 * prefer IPv6 (if available).
1606 */
1608 use_ipv6 = ( ip.s_addr ? FALSE : ( ipv6 != NULL ) );
1609
1610 /* Start base code */
1611 efi_pxe_start ( &pxe->base, use_ipv6 );
1612
1613 /* Install PXE base code protocol */
1614 if ( ( efirc = bs->InstallMultipleProtocolInterfaces (
1615 &handle,
1618 NULL ) ) != 0 ) {
1619 rc = -EEFI ( efirc );
1620 DBGC ( pxe, "PXE %s could not install base code protocol: %s\n",
1621 pxe->name, strerror ( rc ) );
1622 goto err_install_protocol;
1623 }
1624
1625 /* Transfer reference to list and return */
1626 list_add_tail ( &pxe->list, &efi_pxes );
1627 DBGC ( pxe, "PXE %s installed for %s\n",
1628 pxe->name, efi_handle_name ( handle ) );
1629 return 0;
1630
1631 if ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1632 handle,
1635 NULL ) ) != 0 ) {
1636 DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1637 pxe->name, strerror ( -EEFI ( efirc ) ) );
1638 leak = 1;
1639 }
1640 efi_nullify_pxe ( &pxe->base );
1641 efi_nullify_apple ( &pxe->apple );
1642 err_install_protocol:
1643 if ( ! leak )
1644 ref_put ( &pxe->refcnt );
1645 err_alloc:
1646 if ( leak )
1647 DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1648 return rc;
1649}
unsigned char BOOLEAN
Logical Boolean.
#define NULL
NULL pointer (VOID *).
Definition Base.h:321
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:326
EFI_GUID efi_apple_net_boot_protocol_guid
Apple NetBoot protocol GUID.
Definition efi_guid.c:134
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:533
static struct interface_descriptor efi_pxe_tftp_desc
PXE file data transfer interface descriptor.
Definition efi_pxe.c:384
static void efi_pxe_free(struct refcnt *refcnt)
Free PXE base code.
Definition efi_pxe.c:119
static EFI_PXE_BASE_CODE_PROTOCOL efi_pxe_base_code_protocol
PXE base code protocol.
Definition efi_pxe.c:1473
static EFI_STATUS EFIAPI efi_pxe_start(EFI_PXE_BASE_CODE_PROTOCOL *base, BOOLEAN use_ipv6)
Start PXE base code.
Definition efi_pxe.c:720
static struct process_descriptor efi_pxe_process_desc
UDP close process descriptor.
Definition efi_pxe.c:593
static EFI_APPLE_NET_BOOT_PROTOCOL efi_apple_net_boot_protocol
Apple NetBoot protocol.
Definition efi_pxe.c:1554
static struct net_device * netdev
Definition gdbudp.c:53
#define AF_INET6
IPv6 Internet addresses.
Definition socket.h:65
#define DBGC(...)
Definition compiler.h:530
#define ENOMEM
Not enough space.
Definition errno.h:578
#define EEFI(efirc)
Convert an EFI status code to an iPXE status code.
Definition efi.h:181
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:718
static struct net_device * netdev_get(struct net_device *netdev)
Get reference to network device.
Definition netdevice.h:568
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition netdevice.h:590
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:1930
EFI_UNINSTALL_MULTIPLE_PROTOCOL_INTERFACES UninstallMultipleProtocolInterfaces
Definition UefiSpec.h:2010
EFI_INSTALL_MULTIPLE_PROTOCOL_INTERFACES InstallMultipleProtocolInterfaces
Definition UefiSpec.h:2009
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:107
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:109
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:111
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 1656 of file efi_pxe.c.

1656 {
1657 EFI_BOOT_SERVICES *bs = efi_systab->BootServices;
1658 struct efi_pxe *pxe;
1659 int leak = efi_shutdown_in_progress;
1660 EFI_STATUS efirc;
1661
1662 /* Locate PXE base code */
1663 pxe = efi_pxe_find ( handle );
1664 if ( ! pxe ) {
1665 DBG ( "PXE could not find base code for %s\n",
1666 efi_handle_name ( handle ) );
1667 return;
1668 }
1669
1670 /* Stop base code */
1671 efi_pxe_stop ( &pxe->base );
1672
1673 /* Uninstall PXE base code protocol */
1674 if ( ( ! efi_shutdown_in_progress ) &&
1675 ( ( efirc = bs->UninstallMultipleProtocolInterfaces (
1676 handle,
1679 NULL ) ) != 0 ) ) {
1680 DBGC ( pxe, "PXE %s could not uninstall: %s\n",
1681 pxe->name, strerror ( -EEFI ( efirc ) ) );
1682 leak = 1;
1683 }
1684 efi_nullify_pxe ( &pxe->base );
1685 efi_nullify_apple ( &pxe->apple );
1686
1687 /* Remove from list and drop list's reference */
1688 list_del ( &pxe->list );
1689 if ( ! leak )
1690 ref_put ( &pxe->refcnt );
1691
1692 /* Report leakage, if applicable */
1693 if ( leak && ( ! efi_shutdown_in_progress ) )
1694 DBGC ( pxe, "PXE %s nullified and leaked\n", pxe->name );
1695}
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:775
static struct efi_pxe * efi_pxe_find(EFI_HANDLE handle)
Locate PXE base code.
Definition efi_pxe.c:135
#define DBG(...)
Print a debugging message.
Definition compiler.h:523
#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().