iPXE
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.
static int ifopen_payload (struct net_device *netdev, struct ifopen_options *opts __unused)
 "ifopen" payload
static int ifopen_exec (int argc, char **argv)
 The "ifopen" command.
static int ifclose_payload (struct net_device *netdev, struct ifclose_options *opts __unused)
 "ifclose" payload
static int ifclose_exec (int argc, char **argv)
 The "ifclose" command.
static int ifstat_payload (struct net_device *netdev, struct ifstat_options *opts __unused)
 "ifstat" payload
static int ifstat_exec (int argc, char **argv)
 The "ifstat" command.
static int ifconf_payload (struct net_device *netdev, struct ifconf_options *opts)
 "ifconf" payload
int ifconf_exec (int argc, char **argv)
 The "ifconf" command.
static int iflinkwait_payload (struct net_device *netdev, struct iflinkwait_options *opts)
 "iflinkwait" payload
static int iflinkwait_exec (int argc, char **argv)
 The "iflinkwait" command.
 COMMAND (ifopen, ifopen_exec)
 Interface management commands.
 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
static struct ifcommon_command_descriptor ifopen_cmd
 "ifopen" command descriptor
static struct option_descriptor ifclose_opts [] = {}
 "ifclose" option list
static struct ifcommon_command_descriptor ifclose_cmd
 "ifclose" command descriptor
static struct option_descriptor ifstat_opts [] = {}
 "ifstat" option list
static struct ifcommon_command_descriptor ifstat_cmd
 "ifstat" command descriptor
static struct option_descriptor ifconf_opts []
 "ifconf" option list
static struct ifcommon_command_descriptor ifconf_cmd
 "ifconf" command descriptor
static struct option_descriptor iflinkwait_opts []
 "iflinkwait" option list
static struct ifcommon_command_descriptor iflinkwait_cmd
 "iflinkwait" command descriptor

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 golan_eqe_cmd cmd
Definition CIB_PRM.h:1
struct arbelprm_rc_send_wqe rc
Definition arbel.h:3
unsigned char uint8_t
Definition stdint.h:10
static union @024010030001061367220137227263210031030210157031 opts
"cert<xxx>" option list
static struct net_device * netdev
Definition gdbudp.c:53
int optind
Current option index.
Definition getopt.c:52
#define ENODEV
No such device.
Definition errno.h:510
#define for_each_netdev(netdev)
Iterate over all network devices.
Definition netdevice.h:547
int parse_netdev(char *text, struct net_device **netdev)
Parse network device name.
Definition parseopt.c:159
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
int(* payload)(struct net_device *netdev, void *opts)
Payload.
Definition ifmgmt_cmd.h:44
struct command_descriptor cmd
Command descriptor.
Definition ifmgmt_cmd.h:37
int stop_on_first_success
Stop on first success.
Definition ifmgmt_cmd.h:46
A network device.
Definition netdevice.h:353

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

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}
int ifopen(struct net_device *netdev)
Open network device.
Definition ifmgmt.c:66

References __unused, ifopen(), netdev, and opts.

◆ ifopen_exec()

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}
int ifcommon_exec(int argc, char **argv, struct ifcommon_command_descriptor *ifcmd)
Execute if<xxx> command.
Definition ifmgmt_cmd.c:52
static struct ifcommon_command_descriptor ifopen_cmd
"ifopen" command descriptor
Definition ifmgmt_cmd.c:107

References ifcommon_exec(), and ifopen_cmd.

Referenced by COMMAND().

◆ ifclose_payload()

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

References __unused, ifclose(), netdev, and opts.

◆ ifclose_exec()

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

References ifclose_cmd, and ifcommon_exec().

Referenced by COMMAND().

◆ ifstat_payload()

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}
void ifstat(struct net_device *netdev)
Print status of network device.
Definition ifmgmt.c:111

References __unused, ifstat(), netdev, and opts.

◆ ifstat_exec()

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

References ifcommon_exec(), and ifstat_cmd.

Referenced by COMMAND().

◆ ifconf_payload()

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 */
230
231 return rc;
232 }
233
234 return 0;
235}
int ifconf(struct net_device *netdev, struct net_device_configurator *configurator, unsigned long timeout)
Perform network device configuration.
Definition ifmgmt.c:275
void netdev_close(struct net_device *netdev)
Close network device.
Definition netdevice.c:896

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

References ifcommon_exec(), and ifconf_cmd.

Referenced by COMMAND(), and COMMAND().

◆ iflinkwait_payload()

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 */
282
283 return rc;
284 }
285
286 return 0;
287}
int iflinkwait(struct net_device *netdev, unsigned long timeout, int verbose)
Wait for link-up, with status indication.
Definition ifmgmt.c:220

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

◆ iflinkwait_exec()

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

References ifcommon_exec(), and iflinkwait_cmd.

Referenced by COMMAND().

◆ COMMAND() [1/5]

COMMAND ( ifopen ,
ifopen_exec  )

Interface management commands.

References ifopen(), and ifopen_exec().

◆ COMMAND() [2/5]

COMMAND ( ifclose ,
ifclose_exec  )

References ifclose(), and ifclose_exec().

◆ COMMAND() [3/5]

COMMAND ( ifstat ,
ifstat_exec  )

References ifstat(), and ifstat_exec().

◆ COMMAND() [4/5]

COMMAND ( ifconf ,
ifconf_exec  )

References ifconf(), and ifconf_exec().

◆ COMMAND() [5/5]

COMMAND ( iflinkwait ,
iflinkwait_exec  )

References iflinkwait(), and iflinkwait_exec().

Variable Documentation

◆ ifopen_opts

struct option_descriptor ifopen_opts[] = {}
static

"ifopen" option list

Definition at line 92 of file ifmgmt_cmd.c.

92{};

◆ ifopen_cmd

struct ifcommon_command_descriptor ifopen_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
static struct option_descriptor ifopen_opts[]
"ifopen" option list
Definition ifmgmt_cmd.c:92
static int ifopen_payload(struct net_device *netdev, struct ifopen_options *opts __unused)
"ifopen" payload
Definition ifmgmt_cmd.c:101
#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
#define MAX_ARGUMENTS
No maximum number of arguments.
Definition parseopt.h:98
"ifopen" options
Definition ifmgmt_cmd.c:89

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

127{};

◆ ifclose_cmd

struct ifcommon_command_descriptor ifclose_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
static struct option_descriptor ifclose_opts[]
"ifclose" option list
Definition ifmgmt_cmd.c:127
static int ifclose_payload(struct net_device *netdev, struct ifclose_options *opts __unused)
"ifclose" payload
Definition ifmgmt_cmd.c:136
"ifclose" options
Definition ifmgmt_cmd.c:124

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

163{};

◆ 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
static int ifstat_payload(struct net_device *netdev, struct ifstat_options *opts __unused)
"ifstat" payload
Definition ifmgmt_cmd.c:172
"ifstat" options
Definition ifmgmt_cmd.c:160

"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,
}
void timeout(int)
@ required_argument
Option requires an argument.
Definition getopt.h:19
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
#define OPTION_DESC(_longopt, _shortopt, _has_arg, _struct, _field, _parse)
Construct option descriptor.
Definition parseopt.h:68
"ifconf" options
Definition ifmgmt_cmd.c:196

"ifconf" option list

Definition at line 204 of file ifmgmt_cmd.c.

204 {
205 OPTION_DESC ( "configurator", 'c', required_argument,
206 struct ifconf_options, configurator,
208 OPTION_DESC ( "timeout", 't', required_argument,
209 struct ifconf_options, timeout,
211};

◆ 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

"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

"iflinkwait" option list

Definition at line 261 of file ifmgmt_cmd.c.

261 {
262 OPTION_DESC ( "timeout", 't', required_argument,
264};

◆ iflinkwait_cmd

struct ifcommon_command_descriptor iflinkwait_cmd
static
Initial value:
=
0, MAX_ARGUMENTS, "[<interface>...]",
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

"iflinkwait" command descriptor

Definition at line 290 of file ifmgmt_cmd.c.

Referenced by iflinkwait_exec().