iPXE
Functions | Variables
guestinfo.c File Reference

VMware GuestInfo settings. More...

#include <stdint.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>
#include <ipxe/init.h>
#include <ipxe/settings.h>
#include <ipxe/netdevice.h>
#include <ipxe/guestrpc.h>

Go to the source code of this file.

Functions

 FILE_LICENCE (GPL2_OR_LATER)
 
static int guestinfo_fetch_type (struct settings *settings, struct setting *setting, const struct setting_type *type, void *data, size_t len, int *found)
 Fetch value of typed GuestInfo setting. More...
 
static int guestinfo_fetch (struct settings *settings, struct setting *setting, void *data, size_t len)
 Fetch value of GuestInfo setting. More...
 
static void guestinfo_init (void)
 Initialise GuestInfo settings. More...
 
struct init_fn guestinfo_init_fn __init_fn (INIT_NORMAL)
 GuestInfo settings initialiser. More...
 
static int guestinfo_net_probe (struct net_device *netdev)
 Create per-netdevice GuestInfo settings. More...
 
static void guestinfo_net_remove (struct net_device *netdev)
 Remove per-netdevice GuestInfo settings. More...
 

Variables

static int guestinfo_channel
 GuestInfo GuestRPC channel. More...
 
static struct settings_operations guestinfo_settings_operations
 GuestInfo settings operations. More...
 
static struct settings guestinfo_settings
 GuestInfo settings. More...
 
struct net_driver guestinfo_net_driver __net_driver
 GuestInfo per-netdevice driver. More...
 

Detailed Description

VMware GuestInfo settings.

Definition in file guestinfo.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER  )

◆ guestinfo_fetch_type()

static int guestinfo_fetch_type ( struct settings settings,
struct setting setting,
const struct setting_type type,
void *  data,
size_t  len,
int *  found 
)
static

Fetch value of typed GuestInfo setting.

Parameters
settingsSettings block
settingSetting to fetch
typeSetting type to attempt (or NULL for default)
dataBuffer to fill with setting data
lenLength of buffer
Return values
foundSetting found in GuestInfo
lenLength of setting data, or negative error

Definition at line 52 of file guestinfo.c.

55  {
56  const char *parent_name = settings->parent->name;
57  char command[ 24 /* "info-get guestinfo.ipxe." */ +
58  strlen ( parent_name ) + 1 /* "." */ +
59  strlen ( setting->name ) + 1 /* "." */ +
60  ( type ? strlen ( type->name ) : 0 ) + 1 /* NUL */ ];
61  struct setting *predefined;
62  char *info;
63  int info_len;
64  int check_len;
65  int ret;
66 
67  /* Construct info-get command */
68  snprintf ( command, sizeof ( command ),
69  "info-get guestinfo.ipxe.%s%s%s%s%s",
70  parent_name, ( parent_name[0] ? "." : "" ), setting->name,
71  ( type ? "." : "" ), ( type ? type->name : "" ) );
72 
73  /* Check for existence and obtain length of GuestInfo value */
75  if ( info_len < 0 ) {
76  ret = info_len;
77  goto err_get_info_len;
78  }
79 
80  /* Mark as found */
81  *found = 1;
82 
83  /* Determine default type if necessary */
84  if ( ! type ) {
85  predefined = find_setting ( setting->name );
86  type = ( predefined ? predefined->type : &setting_type_string );
87  }
88  assert ( type != NULL );
89 
90  /* Allocate temporary block to hold GuestInfo value */
91  info = zalloc ( info_len + 1 /* NUL */ );
92  if ( ! info ) {
93  DBGC ( settings, "GuestInfo %p could not allocate %d bytes\n",
94  settings, info_len );
95  ret = -ENOMEM;
96  goto err_alloc;
97  }
98  info[info_len] = '\0';
99 
100  /* Fetch GuestInfo value */
102  info, info_len );
103  if ( check_len < 0 ) {
104  ret = check_len;
105  goto err_get_info;
106  }
107  if ( check_len != info_len ) {
108  DBGC ( settings, "GuestInfo %p length mismatch (expected %d, "
109  "got %d)\n", settings, info_len, check_len );
110  ret = -EIO;
111  goto err_get_info;
112  }
113  DBGC2 ( settings, "GuestInfo %p found %s = \"%s\"\n",
114  settings, &command[9] /* Skip "info-get " */, info );
115 
116  /* Parse GuestInfo value according to type */
117  ret = setting_parse ( type, info, data, len );
118  if ( ret < 0 ) {
119  DBGC ( settings, "GuestInfo %p could not parse \"%s\" as %s: "
120  "%s\n", settings, info, type->name, strerror ( ret ) );
121  goto err_parse;
122  }
123 
124  err_parse:
125  err_get_info:
126  free ( info );
127  err_alloc:
128  err_get_info_len:
129  return ret;
130 }
u32 info
Definition: ar9003_mac.h:67
struct settings * parent
Parent settings block.
Definition: settings.h:138
A command-line command.
Definition: command.h:9
uint8_t type
Type.
Definition: ena.h:16
#define DBGC(...)
Definition: compiler.h:505
static int guestinfo_channel
GuestInfo GuestRPC channel.
Definition: guestinfo.c:39
const char * name
Name.
Definition: settings.h:28
#define ENOMEM
Not enough space.
Definition: errno.h:534
assert((readw(&hdr->flags) &(GTF_reading|GTF_writing))==0)
uint8_t info_len
Reject information length.
Definition: ib_mad.h:18
const struct setting_type * type
Setting type.
Definition: settings.h:36
int guestrpc_command(int channel, const char *command, char *reply, size_t reply_len)
Issue GuestRPC command.
Definition: guestrpc.c:242
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
size_t strlen(const char *src)
Get length of string.
Definition: string.c:228
A settings block.
Definition: settings.h:132
const char * name
Name.
Definition: settings.h:136
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
#define DBGC2(...)
Definition: compiler.h:522
#define EIO
Input/output error.
Definition: errno.h:433
int snprintf(char *buf, size_t size, const char *fmt,...)
Write a formatted string to a buffer.
Definition: vsprintf.c:382
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
struct setting * find_setting(const char *name)
Find predefined setting.
Definition: settings.c:1470
int setting_parse(const struct setting_type *type, const char *value, void *buf, size_t len)
Parse formatted string to setting value.
Definition: settings.c:1174
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References assert(), data, DBGC, DBGC2, EIO, ENOMEM, find_setting(), free, guestinfo_channel, guestrpc_command(), info, info_len, len, setting::name, settings::name, NULL, settings::parent, setting_parse(), snprintf(), strerror(), strlen(), type, setting::type, and zalloc().

Referenced by guestinfo_fetch().

◆ guestinfo_fetch()

static int guestinfo_fetch ( struct settings settings,
struct setting setting,
void *  data,
size_t  len 
)
static

Fetch value of GuestInfo setting.

Parameters
settingsSettings block
settingSetting to fetch
dataBuffer to fill with setting data
lenLength of buffer
Return values
lenLength of setting data, or negative error

Definition at line 141 of file guestinfo.c.

143  {
144  struct setting_type *type;
145  int found = 0;
146  int ret;
147 
148  /* Try default type first */
150  data, len, &found );
151  if ( found )
152  return ret;
153 
154  /* Otherwise, try all possible types */
157  data, len, &found );
158  if ( found )
159  return ret;
160  }
161 
162  /* Not found */
163  return -ENOENT;
164 }
uint8_t type
Type.
Definition: ena.h:16
#define ENOENT
No such file or directory.
Definition: errno.h:514
static int guestinfo_fetch_type(struct settings *settings, struct setting *setting, const struct setting_type *type, void *data, size_t len, int *found)
Fetch value of typed GuestInfo setting.
Definition: guestinfo.c:52
#define for_each_table_entry(pointer, table)
Iterate through all entries within a linker table.
Definition: tables.h:358
A settings block.
Definition: settings.h:132
A setting.
Definition: settings.h:23
uint32_t len
Length.
Definition: ena.h:14
struct arbelprm_port_state_change_st data
Message.
Definition: arbel.h:12
#define SETTING_TYPES
Configuration setting type table.
Definition: settings.h:242
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362
A setting type.
Definition: settings.h:191

References data, ENOENT, for_each_table_entry, guestinfo_fetch_type(), len, NULL, SETTING_TYPES, and type.

◆ guestinfo_init()

static void guestinfo_init ( void  )
static

Initialise GuestInfo settings.

Definition at line 180 of file guestinfo.c.

180  {
181  int rc;
182 
183  /* Open GuestRPC channel */
185  if ( guestinfo_channel < 0 ) {
187  DBG ( "GuestInfo could not open channel: %s\n",
188  strerror ( rc ) );
189  return;
190  }
191 
192  /* Register root GuestInfo settings */
194  "vmware" ) ) != 0 ) {
195  DBG ( "GuestInfo could not register settings: %s\n",
196  strerror ( rc ) );
197  return;
198  }
199 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int guestrpc_open(void)
Open GuestRPC channel.
Definition: guestrpc.c:67
static int guestinfo_channel
GuestInfo GuestRPC channel.
Definition: guestinfo.c:39
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static struct settings guestinfo_settings
GuestInfo settings.
Definition: guestinfo.c:172
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:478
#define DBG(...)
Print a debugging message.
Definition: compiler.h:498
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBG, guestinfo_channel, guestinfo_settings, guestrpc_open(), NULL, rc, register_settings(), and strerror().

◆ __init_fn()

struct init_fn guestinfo_init_fn __init_fn ( INIT_NORMAL  )

GuestInfo settings initialiser.

◆ guestinfo_net_probe()

static int guestinfo_net_probe ( struct net_device netdev)
static

Create per-netdevice GuestInfo settings.

Parameters
netdevNetwork device
Return values
rcReturn status code

Definition at line 212 of file guestinfo.c.

212  {
213  struct settings *settings;
214  int rc;
215 
216  /* Do nothing unless we have a GuestInfo channel available */
217  if ( guestinfo_channel < 0 )
218  return 0;
219 
220  /* Allocate and initialise settings block */
221  settings = zalloc ( sizeof ( *settings ) );
222  if ( ! settings ) {
223  rc = -ENOMEM;
224  goto err_alloc;
225  }
227 
228  /* Register settings */
230  "vmware" ) ) != 0 ) {
231  DBGC ( settings, "GuestInfo %p could not register for %s: %s\n",
232  settings, netdev->name, strerror ( rc ) );
233  goto err_register;
234  }
235  DBGC ( settings, "GuestInfo %p registered for %s\n",
236  settings, netdev->name );
237 
238  return 0;
239 
240  err_register:
241  free ( settings );
242  err_alloc:
243  return rc;
244 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
#define DBGC(...)
Definition: compiler.h:505
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
static void settings_init(struct settings *settings, struct settings_operations *op, struct refcnt *refcnt, const struct settings_scope *default_scope)
Initialise a settings block.
Definition: settings.h:495
static int guestinfo_channel
GuestInfo GuestRPC channel.
Definition: guestinfo.c:39
#define ENOMEM
Not enough space.
Definition: errno.h:534
static struct net_device * netdev
Definition: gdbudp.c:52
char * strerror(int errno)
Retrieve string representation of error number.
Definition: strerror.c:78
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
void * zalloc(size_t size)
Allocate cleared memory.
Definition: malloc.c:624
A settings block.
Definition: settings.h:132
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
static struct settings_operations guestinfo_settings_operations
GuestInfo settings operations.
Definition: guestinfo.c:167
int register_settings(struct settings *settings, struct settings *parent, const char *name)
Register settings block.
Definition: settings.c:478
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

References DBGC, ENOMEM, free, guestinfo_channel, guestinfo_settings_operations, net_device::name, netdev, netdev_settings(), NULL, rc, register_settings(), settings_init(), strerror(), and zalloc().

◆ guestinfo_net_remove()

static void guestinfo_net_remove ( struct net_device netdev)
static

Remove per-netdevice GuestInfo settings.

Parameters
netdevNetwork device

Definition at line 251 of file guestinfo.c.

251  {
252  struct settings *parent = netdev_settings ( netdev );
253  struct settings *settings;
254 
257  DBGC ( settings, "GuestInfo %p unregistered for %s\n",
258  settings, netdev->name );
260  free ( settings );
261  return;
262  }
263  }
264 }
void unregister_settings(struct settings *settings)
Unregister settings block.
Definition: settings.c:517
struct settings * parent
Parent settings block.
Definition: settings.h:138
#define DBGC(...)
Definition: compiler.h:505
struct settings_operations * op
Settings block operations.
Definition: settings.h:144
static struct settings * netdev_settings(struct net_device *netdev)
Get per-netdevice configuration settings block.
Definition: netdevice.h:577
#define list_for_each_entry(pos, head, member)
Iterate over entries in a list.
Definition: list.h:420
static struct net_device * netdev
Definition: gdbudp.c:52
static void(* free)(struct refcnt *refcnt))
Definition: refcnt.h:54
A settings block.
Definition: settings.h:132
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
char name[NETDEV_NAME_LEN]
Name of this network device.
Definition: netdevice.h:358
static struct settings_operations guestinfo_settings_operations
GuestInfo settings operations.
Definition: guestinfo.c:167
struct list_head children
Child settings blocks.
Definition: settings.h:142

References settings::children, DBGC, free, guestinfo_settings_operations, list_for_each_entry, net_device::name, netdev, netdev_settings(), settings::op, settings::parent, settings::siblings, and unregister_settings().

Variable Documentation

◆ guestinfo_channel

int guestinfo_channel
static

GuestInfo GuestRPC channel.

Definition at line 39 of file guestinfo.c.

Referenced by guestinfo_fetch_type(), guestinfo_init(), and guestinfo_net_probe().

◆ guestinfo_settings_operations

struct settings_operations guestinfo_settings_operations
static
Initial value:
= {
.fetch = guestinfo_fetch,
}
static int guestinfo_fetch(struct settings *settings, struct setting *setting, void *data, size_t len)
Fetch value of GuestInfo setting.
Definition: guestinfo.c:141

GuestInfo settings operations.

Definition at line 167 of file guestinfo.c.

Referenced by guestinfo_net_probe(), and guestinfo_net_remove().

◆ guestinfo_settings

struct settings guestinfo_settings
static
Initial value:
= {
.refcnt = NULL,
}
struct list_head siblings
Sibling settings blocks.
Definition: settings.h:140
static struct settings guestinfo_settings
GuestInfo settings.
Definition: guestinfo.c:172
static struct settings_operations guestinfo_settings_operations
GuestInfo settings operations.
Definition: guestinfo.c:167
struct list_head children
Child settings blocks.
Definition: settings.h:142
#define LIST_HEAD_INIT(list)
Initialise a static list head.
Definition: list.h:30
#define NULL
NULL pointer (VOID *)
Definition: Base.h:362

GuestInfo settings.

Definition at line 172 of file guestinfo.c.

Referenced by guestinfo_init().

◆ __net_driver

struct net_driver guestinfo_net_driver __net_driver
Initial value:
= {
.name = "GuestInfo",
}
static int guestinfo_net_probe(struct net_device *netdev)
Create per-netdevice GuestInfo settings.
Definition: guestinfo.c:212
static void guestinfo_net_remove(struct net_device *netdev)
Remove per-netdevice GuestInfo settings.
Definition: guestinfo.c:251

GuestInfo per-netdevice driver.

Definition at line 267 of file guestinfo.c.