iPXE
Macros | Functions | Variables
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. More...
 

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. More...
 

Variables

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

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.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ http_format_metadata_flavor()

static 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 }
const char * host
Server host name.
Definition: http.h:218
int strcasecmp(const char *first, const char *second)
Compare case-insensitive strings.
Definition: string.c:192
#define GCE_METADATA_HOST_NAME
Metadata host name.
Definition: httpgce.c:45
struct http_request request
Request.
Definition: http.h:436
uint32_t len
Length.
Definition: ena.h:14
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382

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.