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

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...
 
struct command ifmgmt_commands [] __command
 Interface management commands. More...
 

Detailed Description

Network interface management commands.

Definition in file ifmgmt_cmd.c.

Function Documentation

◆ FILE_LICENCE()

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )

◆ 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 51 of file ifmgmt_cmd.c.

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

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 100 of file ifmgmt_cmd.c.

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

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 118 of file ifmgmt_cmd.c.

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

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 135 of file ifmgmt_cmd.c.

136  {
137  ifclose ( netdev );
138  return 0;
139 }
void ifclose(struct net_device *netdev)
Close network device.
Definition: ifmgmt.c:82
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 154 of file ifmgmt_cmd.c.

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

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 171 of file ifmgmt_cmd.c.

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

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 190 of file ifmgmt_cmd.c.

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

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 219 of file ifmgmt_cmd.c.

220  {
221  int rc;
222 
223  /* Attempt configuration */
224  if ( ( rc = ifconf ( netdev, opts->configurator,
225  opts->timeout ) ) != 0 ) {
226 
227  /* Close device on failure, to avoid memory exhaustion */
228  netdev_close ( netdev );
229 
230  return rc;
231  }
232 
233  return 0;
234 }
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:274
static struct net_device * netdev
Definition: gdbudp.c:52
static union @437 opts
"cert<xxx>" option list
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895

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 249 of file ifmgmt_cmd.c.

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

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 272 of file ifmgmt_cmd.c.

273  {
274  int rc;
275 
276  /* Wait for link-up */
277  if ( ( rc = iflinkwait ( netdev, opts->timeout, 1 ) ) != 0 ) {
278 
279  /* Close device on failure, to avoid memory exhaustion */
280  netdev_close ( netdev );
281 
282  return rc;
283  }
284 
285  return 0;
286 }
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:219
static struct net_device * netdev
Definition: gdbudp.c:52
static union @437 opts
"cert<xxx>" option list
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:895

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 301 of file ifmgmt_cmd.c.

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

References ifcommon_exec(), and iflinkwait_cmd.

Variable Documentation

◆ ifopen_opts

struct option_descriptor ifopen_opts[] = {}
static

"ifopen" option list

Definition at line 91 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:88
static int ifopen_payload(struct net_device *netdev, struct ifopen_options *opts __unused)
"ifopen" payload
Definition: ifmgmt_cmd.c:100
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
static struct option_descriptor ifopen_opts[]
"ifopen" option list
Definition: ifmgmt_cmd.c:91
#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:57

"ifopen" command descriptor

Definition at line 106 of file ifmgmt_cmd.c.

Referenced by ifopen_exec().

◆ ifclose_opts

struct option_descriptor ifclose_opts[] = {}
static

"ifclose" option list

Definition at line 126 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:123
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
static struct option_descriptor ifclose_opts[]
"ifclose" option list
Definition: ifmgmt_cmd.c:126
#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:57
static int ifclose_payload(struct net_device *netdev, struct ifclose_options *opts __unused)
"ifclose" payload
Definition: ifmgmt_cmd.c:135

"ifclose" command descriptor

Definition at line 142 of file ifmgmt_cmd.c.

Referenced by ifclose_exec().

◆ ifstat_opts

struct option_descriptor ifstat_opts[] = {}
static

"ifstat" option list

Definition at line 162 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:162
"ifstat" options
Definition: ifmgmt_cmd.c:159
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
#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:57
static int ifstat_payload(struct net_device *netdev, struct ifstat_options *opts __unused)
"ifstat" payload
Definition: ifmgmt_cmd.c:171

"ifstat" command descriptor

Definition at line 178 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:180
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
"ifconf" options
Definition: ifmgmt_cmd.c:195
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
void timeout(int)

"ifconf" option list

Definition at line 203 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:203
static int ifconf_payload(struct net_device *netdev, struct ifconf_options *opts)
"ifconf" payload
Definition: ifmgmt_cmd.c:219
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
"ifconf" options
Definition: ifmgmt_cmd.c:195
#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:57

"ifconf" command descriptor

Definition at line 237 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:254
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:114
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:67
Option requires an argument.
Definition: getopt.h:18
void timeout(int)

"iflinkwait" option list

Definition at line 260 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:254
static struct option_descriptor iflinkwait_opts[]
"iflinkwait" option list
Definition: ifmgmt_cmd.c:260
static int iflinkwait_payload(struct net_device *netdev, struct iflinkwait_options *opts)
"iflinkwait" payload
Definition: ifmgmt_cmd.c:272
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition: parseopt.h:97
#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:57

"iflinkwait" command descriptor

Definition at line 289 of file ifmgmt_cmd.c.

Referenced by iflinkwait_exec().

◆ __command

struct command ifmgmt_commands [] __command
Initial value:
= {
{
.name = "ifopen",
.exec = ifopen_exec,
},
{
.name = "ifclose",
.exec = ifclose_exec,
},
{
.name = "ifstat",
.exec = ifstat_exec,
},
{
.name = "ifconf",
.exec = ifconf_exec,
},
{
.name = "iflinkwait",
.exec = iflinkwait_exec,
},
}
static int ifopen_exec(int argc, char **argv)
The "ifopen" command.
Definition: ifmgmt_cmd.c:118
int ifconf_exec(int argc, char **argv)
The "ifconf" command.
Definition: ifmgmt_cmd.c:249
static int ifstat_exec(int argc, char **argv)
The "ifstat" command.
Definition: ifmgmt_cmd.c:190
static int iflinkwait_exec(int argc, char **argv)
The "iflinkwait" command.
Definition: ifmgmt_cmd.c:301
static int ifclose_exec(int argc, char **argv)
The "ifclose" command.
Definition: ifmgmt_cmd.c:154

Interface management commands.

Definition at line 306 of file ifmgmt_cmd.c.