Skip to content

Commit

Permalink
Implement Uri device path
Browse files Browse the repository at this point in the history
efidp_make_uri() implements Uri device path used when generating a IPv4
device path.
efi_generate_ipv4_device_path() being public hence not modifiable, a new
version called efi_generate_ipv4_device_path_with_uri() enables to
specify the Uri.

Signed-off-by: Renaud Métrich <[email protected]>
  • Loading branch information
rmetrich committed May 17, 2022
1 parent 90f2d19 commit 3cc2eaa
Show file tree
Hide file tree
Showing 4 changed files with 74 additions and 10 deletions.
48 changes: 38 additions & 10 deletions src/creator.c
Original file line number Diff line number Diff line change
Expand Up @@ -458,16 +458,17 @@ make_ipv4_path(uint8_t *buf, ssize_t size,
}

ssize_t NONNULL(3, 4, 5, 6, 7) PUBLIC
efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
const char * const ifname,
const char * const local_addr,
const char * const remote_addr,
const char * const gateway_addr,
const char * const netmask,
uint16_t local_port,
uint16_t remote_port,
uint16_t protocol,
uint8_t addr_origin)
efi_generate_ipv4_device_path_with_uri(uint8_t *buf, ssize_t size,
const char * const ifname,
const char * const local_addr,
const char * const remote_addr,
const char * const gateway_addr,
const char * const netmask,
uint16_t local_port,
uint16_t remote_port,
uint16_t protocol,
uint8_t addr_origin,
const char * const uri)
{
ssize_t off = 0;
ssize_t sz;
Expand All @@ -488,6 +489,15 @@ efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
}
off += sz;

if (uri) {
sz = efidp_make_uri(buf+off, size?size-off:0, uri);
if (sz < 0) {
efi_error("could not make URI DP node");
return -1;
}
off += sz;
}

sz = efidp_make_end_entire(buf+off, size?size-off:0);
if (sz < 0) {
efi_error("could not make EndEntire DP node");
Expand All @@ -498,6 +508,24 @@ efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
return off;
}

ssize_t NONNULL(3, 4, 5, 6, 7) PUBLIC
efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
const char * const ifname,
const char * const local_addr,
const char * const remote_addr,
const char * const gateway_addr,
const char * const netmask,
uint16_t local_port,
uint16_t remote_port,
uint16_t protocol,
uint8_t addr_origin)
{
return efi_generate_ipv4_device_path_with_uri(buf, size, ifname,
local_addr, remote_addr, gateway_addr, netmask,
local_port, remote_port, protocol, addr_origin,
NULL);
}

uint32_t PUBLIC
efi_get_libefiboot_version(void)
{
Expand Down
19 changes: 19 additions & 0 deletions src/dp-message.c
Original file line number Diff line number Diff line change
Expand Up @@ -638,6 +638,25 @@ efidp_make_mac_addr(uint8_t *buf, ssize_t size, uint8_t if_type,
return sz;
}

ssize_t NONNULL(3) PUBLIC
efidp_make_uri(uint8_t *buf, ssize_t size, const char * const uristring)
{
efidp_uri *uri = (efidp_uri *)buf;
size_t urilen = strlen(uristring);
ssize_t req = offsetof(efidp_uri, uri) + urilen;

ssize_t sz = efidp_make_generic(buf, size, EFIDP_MESSAGE_TYPE,
EFIDP_MSG_URI, req);
if (size && sz == req) {
memcpy(uri->uri, (uint8_t *)uristring, urilen);
}

if (sz < 0)
efi_error("efidp_make_generic failed");

return sz;
}

ssize_t PUBLIC
efidp_make_ipv4(uint8_t *buf, ssize_t size, uint32_t local, uint32_t remote,
uint32_t gateway, uint32_t netmask,
Expand Down
15 changes: 15 additions & 0 deletions src/include/efivar/efiboot-creator.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,21 @@ extern ssize_t efi_generate_ipv4_device_path(uint8_t *buf, ssize_t size,
__attribute__((__nonnull__ (3,4,5,6,7)))
__attribute__((__visibility__ ("default")));

extern ssize_t efi_generate_ipv4_device_path_with_uri(
uint8_t *buf, ssize_t size,
const char * const ifname,
const char * const local_addr,
const char * const remote_addr,
const char * const gateway_addr,
const char * const netmask,
uint16_t local_port,
uint16_t remote_port,
uint16_t protocol,
uint8_t addr_origin,
const char * const uri)
__attribute__((__nonnull__ (3,4,5,6,7)))
__attribute__((__visibility__ ("default")));

#ifdef __cplusplus
} /* extern "C" */
#endif
Expand Down
2 changes: 2 additions & 0 deletions src/include/efivar/efivar-dp.h
Original file line number Diff line number Diff line change
Expand Up @@ -651,6 +651,8 @@ typedef struct {
efidp_header header;
uint8_t uri[];
} EFIVAR_PACKED efidp_uri;
extern ssize_t efidp_make_uri(uint8_t *buf, ssize_t size,
const char * const uristring);

#define EFIDP_MSG_UFS 0x19
typedef struct {
Expand Down

0 comments on commit 3cc2eaa

Please sign in to comment.