iPXE
Data Structures | Functions | Variables
ifmgmt_cmd.c File Reference

Network interface management commands. More...

#include <stdio.h>
#include <errno.h>
#include <getopt.h>
#include <ipxe/netdevice.h>
#include <ipxe/command.h>
#include <ipxe/parseopt.h>
#include <usr/ifmgmt.h>
#include <hci/ifmgmt_cmd.h>

Go to the source code of this file.

Data Structures

struct  ifopen_options
 "ifopen" options More...
 
struct  ifclose_options
 "ifclose" options More...
 
struct  ifstat_options
 "ifstat" options More...
 
struct  ifconf_options
 "ifconf" options More...
 
struct  iflinkwait_options
 "iflinkwait" option list More...
 

Functions

 FILE_LICENCE (GPL2_OR_LATER_OR_UBDL)
 
 FILE_SECBOOT (PERMITTED)
 
int ifcommon_exec (int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
 Execute if<xxx> command. More...
 
static int ifopen_payload (struct net_device *netdev, struct ifopen_options *opts __unused)
 "ifopen" payload More...
 
static int ifopen_exec (int argc, char **argv)
 The "ifopen" command. More...
 
static int ifclose_payload (struct net_device *netdev, struct ifclose_options *opts __unused)
 "ifclose" payload More...
 
static int ifclose_exec (int argc, char **argv)
 The "ifclose" command. More...
 
static int ifstat_payload (struct net_device *netdev, struct ifstat_options *opts __unused)
 "ifstat" payload More...
 
static int ifstat_exec (int argc, char **argv)
 The "ifstat" command. More...
 
static int ifconf_payload (struct net_device *netdev, struct ifconf_options *opts)
 "ifconf" payload More...
 
int ifconf_exec (int argc, char **argv)
 The "ifconf" command. More...
 
static int iflinkwait_payload (struct net_device *netdev, struct iflinkwait_options *opts)
 "iflinkwait" payload More...
 
static int iflinkwait_exec (int argc, char **argv)
 The "iflinkwait" command. More...
 
 COMMAND (ifopen, ifopen_exec)
 Interface management commands. More...
 
 COMMAND (ifclose, ifclose_exec)
 
 COMMAND (ifstat, ifstat_exec)
 
 COMMAND (ifconf, ifconf_exec)
 
 COMMAND (iflinkwait, iflinkwait_exec)
 

Variables

static struct option_descriptor ifopen_opts [] = {}
 "ifopen" option list More...
 
static struct ifcommon_command_descriptor ifopen_cmd
 "ifopen" command descriptor More...
 
static struct option_descriptor ifclose_opts [] = {}
 "ifclose" option list More...
 
static struct ifcommon_command_descriptor ifclose_cmd
 "ifclose" command descriptor More...
 
static struct option_descriptor ifstat_opts [] = {}
 "ifstat" option list More...
 
static struct ifcommon_command_descriptor ifstat_cmd
 "ifstat" command descriptor More...
 
static struct option_descriptor ifconf_opts []
 "ifconf" option list More...
 
static struct ifcommon_command_descriptor ifconf_cmd
 "ifconf" command descriptor More...
 
static struct option_descriptor iflinkwait_opts []
 "iflinkwait" option list More...
 
static struct ifcommon_command_descriptor iflinkwait_cmd
 "iflinkwait" command descriptor More...
 

Detailed Description

Network interface management commands.

Definition in file ifmgmt_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ FILE_SECBOOT()

FILE_SECBOOT ( PERMITTED  )

◆ ifcommon_exec()

int ifcommon_exec ( int  argc,
char **  argv,
struct ifcommon_command_descriptor ifcmd 
)

Execute if<xxx> command.

Parameters
argcArgument count
argvArgument list
cmdCommand descriptor
payloadCommand to execute
verbVerb describing the action of the command
Return values
rcReturn status code

Definition at line 52 of file ifmgmt_cmd.c.

53  {
54  struct command_descriptor *cmd = &ifcmd->cmd;
55  uint8_t opts[cmd->len];
56  struct net_device *netdev;
57  int i;
58  int rc;
59 
60  /* Parse options */
61  if ( ( rc = parse_options ( argc, argv, cmd, opts ) ) != 0 )
62  return rc;
63 
64  if ( optind != argc ) {
65  /* Treat arguments as a list of interfaces to try */
66  for ( i = optind ; i < argc ; i++ ) {
67  if ( ( rc = parse_netdev ( argv[i], &netdev ) ) != 0 )
68  continue;
69  if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
70  && ifcmd->stop_on_first_success ) {
71  return 0;
72  }
73  }
74  } else {
75  /* Try all interfaces */
76  rc = -ENODEV;
78  if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
79  && ifcmd->stop_on_first_success ) {
80  return 0;
81  }
82  }
83  }
84 
85  return rc;
86 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int optind
Current option index.
Definition: getopt.c:52
int(* payload)(struct net_device *netdev, void *opts)
Payload.
Definition: ifmgmt_cmd.h:44
int parse_options(int argc, char **argv, struct command_descriptor *cmd, void *opts)
Parse command-line options.
Definition: parseopt.c:485
A command descriptor.
Definition: parseopt.h:78
static struct net_device * netdev
Definition: gdbudp.c:52
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:547
A network device.
Definition: netdevice.h:353
#define ENODEV
No such device.
Definition: errno.h:510
unsigned char uint8_t
Definition: stdint.h:10
static union @447 opts
"cert<xxx>" option list
int stop_on_first_success
Stop on first success.
Definition: ifmgmt_cmd.h:46
struct golan_eqe_cmd cmd
Definition: CIB_PRM.h:29
struct command_descriptor cmd
Command descriptor.
Definition: ifmgmt_cmd.h:37
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition: parseopt.c:159

References cmd, ifcommon_command_descriptor::cmd, ENODEV, for_each_netdev, netdev, optind, opts, parse_netdev(), parse_options(), ifcommon_command_descriptor::payload, rc, and ifcommon_command_descriptor::stop_on_first_success.

Referenced by autoboot_exec(), ifclose_exec(), ifconf_exec(), iflinkwait_exec(), ifopen_exec(), ifstat_exec(), iwlist_exec(), iwstat_exec(), and startpxe_exec().

◆ ifopen_payload()

static int ifopen_payload ( struct net_device netdev,
struct ifopen_options *opts  __unused 
)
static

"ifopen" payload

Parameters
netdevNetwork device
optsCommand options
Return values
rcReturn status code

Definition at line 101 of file ifmgmt_cmd.c.

102  {
103  return ifopen ( netdev );
104 }
static struct net_device * netdev
Definition: gdbudp.c:52
int ifopen(struct net_device *netdev)
Open network device.
Definition: ifmgmt.c:66

References ifopen(), and netdev.

◆ ifopen_exec()

static int ifopen_exec ( int  argc,
char **  argv 
)
static

The "ifopen" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 119 of file ifmgmt_cmd.c.

119  {
120  return ifcommon_exec ( argc, argv, &ifopen_cmd );
121 }
static struct ifcommon_command_descriptor ifopen_cmd
"ifopen" command descriptor
Definition: ifmgmt_cmd.c:107
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:52

References ifcommon_exec(), and ifopen_cmd.

◆ ifclose_payload()

static int ifclose_payload ( struct net_device netdev,
struct ifclose_options *opts  __unused 
)
static

"ifclose" payload

Parameters
netdevNetwork device
optsCommand options
Return values
rcReturn status code

Definition at line 136 of file ifmgmt_cmd.c.

137  {
138  ifclose ( netdev );
139  return 0;
140 }
void ifclose(struct net_device *netdev)
Close network device.
Definition: ifmgmt.c:83
static struct net_device * netdev
Definition: gdbudp.c:52

References ifclose(), and netdev.

◆ ifclose_exec()

static int ifclose_exec ( int  argc,
char **  argv 
)
static

The "ifclose" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 155 of file ifmgmt_cmd.c.

155  {
156  return ifcommon_exec ( argc, argv, &ifclose_cmd );
157 }
static struct ifcommon_command_descriptor ifclose_cmd
"ifclose" command descriptor
Definition: ifmgmt_cmd.c:143
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:52

References ifclose_cmd, and ifcommon_exec().

◆ ifstat_payload()

static int ifstat_payload ( struct net_device netdev,
struct ifstat_options *opts  __unused 
)
static

"ifstat" payload

Parameters
netdevNetwork device
optsCommand options
Return values
rcReturn status code

Definition at line 172 of file ifmgmt_cmd.c.

173  {
174  ifstat ( netdev );
175  return 0;
176 }
static struct net_device * netdev
Definition: gdbudp.c:52
void ifstat(struct net_device *netdev)
Print status of network device.
Definition: ifmgmt.c:111

References ifstat(), and netdev.

◆ ifstat_exec()

static int ifstat_exec ( int  argc,
char **  argv 
)
static

The "ifstat" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 191 of file ifmgmt_cmd.c.

191  {
192  return ifcommon_exec ( argc, argv, &ifstat_cmd );
193 }
static struct ifcommon_command_descriptor ifstat_cmd
"ifstat" command descriptor
Definition: ifmgmt_cmd.c:179
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:52

References ifcommon_exec(), and ifstat_cmd.

◆ ifconf_payload()

static int ifconf_payload ( struct net_device netdev,
struct ifconf_options opts 
)
static

"ifconf" payload

Parameters
netdevNetwork device
optsCommand options
Return values
rcReturn status code

Definition at line 220 of file ifmgmt_cmd.c.

221  {
222  int rc;
223 
224  /* Attempt configuration */
225  if ( ( rc = ifconf ( netdev, opts->configurator,
226  opts->timeout ) ) != 0 ) {
227 
228  /* Close device on failure, to avoid memory exhaustion */
229  netdev_close ( netdev );
230 
231  return rc;
232  }
233 
234  return 0;
235 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int ifconf(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout)
Perform network device configuration.
Definition: ifmgmt.c:275
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:896
static union @447 opts
"cert<xxx>" option list

References ifconf(), netdev, netdev_close(), opts, and rc.

◆ ifconf_exec()

int ifconf_exec ( int  argc,
char **  argv 
)

The "ifconf" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 250 of file ifmgmt_cmd.c.

250  {
251  return ifcommon_exec ( argc, argv, &ifconf_cmd );
252 }
static struct ifcommon_command_descriptor ifconf_cmd
"ifconf" command descriptor
Definition: ifmgmt_cmd.c:238
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:52

References ifcommon_exec(), and ifconf_cmd.

◆ iflinkwait_payload()

static int iflinkwait_payload ( struct net_device netdev,
struct iflinkwait_options opts 
)
static

"iflinkwait" payload

Parameters
netdevNetwork device
optsCommand options
Return values
rcReturn status code

Definition at line 273 of file ifmgmt_cmd.c.

274  {
275  int rc;
276 
277  /* Wait for link-up */
278  if ( ( rc = iflinkwait ( netdev, opts->timeout, 1 ) ) != 0 ) {
279 
280  /* Close device on failure, to avoid memory exhaustion */
281  netdev_close ( netdev );
282 
283  return rc;
284  }
285 
286  return 0;
287 }
struct arbelprm_rc_send_wqe rc
Definition: arbel.h:14
int iflinkwait(struct net_device *netdev, unsigned long timeout, int verbose)
Wait for link-up, with status indication.
Definition: ifmgmt.c:220
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:896
static union @447 opts
"cert<xxx>" option list

References iflinkwait(), netdev, netdev_close(), opts, and rc.

◆ iflinkwait_exec()

static int iflinkwait_exec ( int  argc,
char **  argv 
)
static

The "iflinkwait" command.

Parameters
argcArgument count
argvArgument list
Return values
rcReturn status code

Definition at line 302 of file ifmgmt_cmd.c.

302  {
303  return ifcommon_exec ( argc, argv, &iflinkwait_cmd );
304 }
static struct ifcommon_command_descriptor iflinkwait_cmd
"iflinkwait" command descriptor
Definition: ifmgmt_cmd.c:290
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition: ifmgmt_cmd.c:52

References ifcommon_exec(), and iflinkwait_cmd.

◆ COMMAND() [1/5]

COMMAND ( ifopen  ,
ifopen_exec   
)

Interface management commands.

◆ COMMAND() [2/5]

COMMAND ( ifclose  ,
ifclose_exec   
)

◆ COMMAND() [3/5]

COMMAND ( ifstat  ,
ifstat_exec   
)

◆ COMMAND() [4/5]

COMMAND ( ifconf  ,
ifconf_exec   
)

◆ COMMAND() [5/5]

COMMAND ( iflinkwait  ,
iflinkwait_exec   
)

Variable Documentation

◆ ifopen_opts

struct option_descriptor ifopen_opts[] = {}
static

"ifopen" option list

Definition at line 92 of file ifmgmt_cmd.c.

◆ ifopen_cmd

struct ifcommon_command_descriptor ifopen_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
"ifopen" options
Definition: ifmgmt_cmd.c:89
static int ifopen_payload(struct net_device *netdev, struct ifopen_options *opts __unused)
"ifopen" payload
Definition: ifmgmt_cmd.c:101
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
static struct option_descriptor ifopen_opts[]
"ifopen" option list
Definition: ifmgmt_cmd.c:92
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:58

"ifopen" command descriptor

Definition at line 107 of file ifmgmt_cmd.c.

Referenced by ifopen_exec().

◆ ifclose_opts

struct option_descriptor ifclose_opts[] = {}
static

"ifclose" option list

Definition at line 127 of file ifmgmt_cmd.c.

◆ ifclose_cmd

struct ifcommon_command_descriptor ifclose_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
"ifclose" options
Definition: ifmgmt_cmd.c:124
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
static struct option_descriptor ifclose_opts[]
"ifclose" option list
Definition: ifmgmt_cmd.c:127
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:58
static int ifclose_payload(struct net_device *netdev, struct ifclose_options *opts __unused)
"ifclose" payload
Definition: ifmgmt_cmd.c:136

"ifclose" command descriptor

Definition at line 143 of file ifmgmt_cmd.c.

Referenced by ifclose_exec().

◆ ifstat_opts

struct option_descriptor ifstat_opts[] = {}
static

"ifstat" option list

Definition at line 163 of file ifmgmt_cmd.c.

◆ ifstat_cmd

struct ifcommon_command_descriptor ifstat_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
static struct option_descriptor ifstat_opts[]
"ifstat" option list
Definition: ifmgmt_cmd.c:163
"ifstat" options
Definition: ifmgmt_cmd.c:160
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:58
static int ifstat_payload(struct net_device *netdev, struct ifstat_options *opts __unused)
"ifstat" payload
Definition: ifmgmt_cmd.c:172

"ifstat" command descriptor

Definition at line 179 of file ifmgmt_cmd.c.

Referenced by ifstat_exec().

◆ ifconf_opts

struct option_descriptor ifconf_opts[]
static
Initial value:
= {
OPTION_DESC ( "configurator", 'c', required_argument,
struct ifconf_options, configurator,
OPTION_DESC ( "timeout", 't', required_argument,
}
int parse_netdev_configurator(char *text, struct net_device_configurator **configurator)
Parse network device configurator name.
Definition: parseopt.c:181
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:115
"ifconf" options
Definition: ifmgmt_cmd.c:196
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
void timeout(int)

"ifconf" option list

Definition at line 204 of file ifmgmt_cmd.c.

◆ ifconf_cmd

struct ifcommon_command_descriptor ifconf_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
static struct option_descriptor ifconf_opts[]
"ifconf" option list
Definition: ifmgmt_cmd.c:204
static int ifconf_payload(struct net_device *netdev, struct ifconf_options *opts)
"ifconf" payload
Definition: ifmgmt_cmd.c:220
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
"ifconf" options
Definition: ifmgmt_cmd.c:196
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:58

"ifconf" command descriptor

Definition at line 238 of file ifmgmt_cmd.c.

Referenced by ifconf_exec().

◆ iflinkwait_opts

struct option_descriptor iflinkwait_opts[]
static
Initial value:
= {
OPTION_DESC ( "timeout", 't', required_argument,
}
"iflinkwait" option list
Definition: ifmgmt_cmd.c:255
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:115
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:68
Option requires an argument.
Definition: getopt.h:19
void timeout(int)

"iflinkwait" option list

Definition at line 261 of file ifmgmt_cmd.c.

◆ iflinkwait_cmd

struct ifcommon_command_descriptor iflinkwait_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
"iflinkwait" option list
Definition: ifmgmt_cmd.c:255
static struct option_descriptor iflinkwait_opts[]
"iflinkwait" option list
Definition: ifmgmt_cmd.c:261
static int iflinkwait_payload(struct net_device *netdev, struct iflinkwait_options *opts)
"iflinkwait" payload
Definition: ifmgmt_cmd.c:273
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:98
#define IFCOMMON_COMMAND_DESC(_struct, _options, _min_args, _max_args, _usage, _payload, _stop_on_first_success)
Construct "if<xxx>" command descriptor.
Definition: ifmgmt_cmd.h:58

"iflinkwait" command descriptor

Definition at line 290 of file ifmgmt_cmd.c.

Referenced by iflinkwait_exec().