iPXE
httpgce.c File Reference

Google Compute Engine (GCE) metadata retrieval. More...

#include <strings.h>
#include <stdio.h>
#include <ipxe/http.h>

Go to the source code of this file.

Macros

#define GCE_METADATA_HOST_NAME   "metadata.google.internal"
 Metadata host name.

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
static int http_format_metadata_flavor (struct http_transaction *http, char *buf, size_t len)
 Construct HTTP "Metadata-Flavor" header.

Variables

struct http_request_header http_request_metadata_flavor __http_request_header
 HTTP "Metadata-Flavor" header.

Detailed Description

Google Compute Engine (GCE) metadata retrieval.

For some unspecified "security" reason, the Google Compute Engine metadata server will refuse any requests that do not include the non-standard HTTP header "Metadata-Flavor: Google".

Definition in file httpgce.c.

Macro Definition Documentation

◆ GCE_METADATA_HOST_NAME

#define GCE_METADATA_HOST_NAME   "metadata.google.internal"

Metadata host name.

This is used to identify metadata requests, in the absence of any more robust mechanism.

Definition at line 45 of file httpgce.c.

Referenced by http_format_metadata_flavor().

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL )

◆ http_format_metadata_flavor()

int http_format_metadata_flavor ( struct http_transaction * http,
char * buf,
size_t len )
static

Construct HTTP "Metadata-Flavor" header.

Parameters
httpHTTP transaction
bufBuffer
lenLength of buffer
Return values
lenLength of header value, or negative error

Definition at line 55 of file httpgce.c.

56 {
57
58 /* Do nothing unless this appears to be a Google Compute
59 * Engine metadata request.
60 */
61 if ( strcasecmp ( http->request.host, GCE_METADATA_HOST_NAME ) != 0 )
62 return 0;
63
64 /* Construct host URI */
65 return snprintf ( buf, len, "Google" );
66}
ring len
Length.
Definition dwmac.h:226
#define GCE_METADATA_HOST_NAME
Metadata host name.
Definition httpgce.c:45
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition string.c:209
const char * host
Server host name.
Definition http.h:217
struct http_request request
Request.
Definition http.h:437
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition vsprintf.c:383

References GCE_METADATA_HOST_NAME, http_request::host, len, http_transaction::request, snprintf(), and strcasecmp().

Variable Documentation

◆ __http_request_header

struct http_request_header http_request_metadata_flavor __http_request_header
Initial value:
={
.name = "Metadata-Flavor",
}
static int http_format_metadata_flavor(struct http_transaction *http, char *buf, size_t len)
Construct HTTP "Metadata-Flavor" header.
Definition httpgce.c:55

HTTP "Metadata-Flavor" header.

Definition at line 69 of file httpgce.c.

69 {
70 .name = "Metadata-Flavor",
72};