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

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

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...
 
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
static union @424 opts
"cert<xxx>" option list
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:447
A command descriptor.
Definition: parseopt.h:76
static struct net_device * netdev
Definition: gdbudp.c:52
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition: netdevice.h:526
A network device.
Definition: netdevice.h:348
#define ENODEV
No such device.
Definition: errno.h:509
unsigned char uint8_t
Definition: stdint.h:10
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:132

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(), 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:270
static union @424 opts
"cert<xxx>" option list
static struct net_device * netdev
Definition: gdbudp.c:52
void netdev_close(struct net_device *netdev)
Close network device.
Definition: netdevice.c:801

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.

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:96
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:96
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:96
#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:154
int parse_timeout(char *text, unsigned long *value)
Parse timeout value (in ms)
Definition: parseopt.c:111
"ifconf" options
Definition: ifmgmt_cmd.c:195
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition: parseopt.h:66
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:96
"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().

◆ __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,
},
}
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 ifclose_exec(int argc, char **argv)
The "ifclose" command.
Definition: ifmgmt_cmd.c:154

Interface management commands.

Definition at line 254 of file ifmgmt_cmd.c.