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

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

Detailed Description

Network interface management commands.

Definition in file ifmgmt_cmd.c.


Function Documentation

FILE_LICENCE ( GPL2_OR_LATER_OR_UBDL  )
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.

References ifcommon_command_descriptor::cmd, cmd, ENODEV, for_each_netdev, command_descriptor::len, 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().

                                                                {
        struct command_descriptor *cmd = &ifcmd->cmd;
        uint8_t opts[cmd->len];
        struct net_device *netdev;
        int i;
        int rc;

        /* Parse options */
        if ( ( rc = parse_options ( argc, argv, cmd, opts ) ) != 0 )
                return rc;

        if ( optind != argc ) {
                /* Treat arguments as a list of interfaces to try */
                for ( i = optind ; i < argc ; i++ ) {
                        if ( ( rc = parse_netdev ( argv[i], &netdev ) ) != 0 )
                                continue;
                        if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
                             && ifcmd->stop_on_first_success ) {
                                return 0;
                        }
                }
        } else {
                /* Try all interfaces */
                rc = -ENODEV;
                for_each_netdev ( netdev ) {
                        if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
                             && ifcmd->stop_on_first_success ) {
                                return 0;
                        }
                }
        }

        return rc;
}
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.

References ifopen().

                                                                   {
        return ifopen ( netdev );
}
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.

References ifcommon_exec().

                                                 {
        return ifcommon_exec ( argc, argv, &ifopen_cmd );
}
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.

References ifclose().

                                                                     {
        ifclose ( netdev );
        return 0;
}
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.

References ifcommon_exec().

                                                  {
        return ifcommon_exec ( argc, argv, &ifclose_cmd );
}
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.

References ifstat().

                                                                   {
        ifstat ( netdev );
        return 0;
}
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.

References ifcommon_exec().

                                                 {
        return ifcommon_exec ( argc, argv, &ifstat_cmd );
}
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 214 of file ifmgmt_cmd.c.

References ifconf_options::configurator, ifconf(), netdev_close(), and rc.

                                                          {
        int rc;

        /* Attempt configuration */
        if ( ( rc = ifconf ( netdev, opts->configurator ) ) != 0 ) {

                /* Close device on failure, to avoid memory exhaustion */
                netdev_close ( netdev );

                return rc;
        }

        return 0;
}
int ifconf_exec ( int  argc,
char **  argv 
)

The "ifconf" command.

Parameters:
argcArgument count
argvArgument list
Return values:
rcReturn status code

Definition at line 243 of file ifmgmt_cmd.c.

References ifcommon_exec().

                                          {
        return ifcommon_exec ( argc, argv, &ifconf_cmd );
}

Variable Documentation

struct option_descriptor ifopen_opts[] = {} [static]

"ifopen" option list

Definition at line 91 of file ifmgmt_cmd.c.

Initial value:

"ifopen" command descriptor

Definition at line 106 of file ifmgmt_cmd.c.

struct option_descriptor ifclose_opts[] = {} [static]

"ifclose" option list

Definition at line 126 of file ifmgmt_cmd.c.

Initial value:

"ifclose" command descriptor

Definition at line 142 of file ifmgmt_cmd.c.

struct option_descriptor ifstat_opts[] = {} [static]

"ifstat" option list

Definition at line 162 of file ifmgmt_cmd.c.

Initial value:

"ifstat" command descriptor

Definition at line 178 of file ifmgmt_cmd.c.

struct option_descriptor ifconf_opts[] [static]
Initial value:
 {
        OPTION_DESC ( "configurator", 'c', required_argument,
                      struct ifconf_options, configurator,
                      parse_netdev_configurator ),
}

"ifconf" option list

Definition at line 201 of file ifmgmt_cmd.c.

Initial value:

"ifconf" command descriptor

Definition at line 231 of file ifmgmt_cmd.c.

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,
        },
}

Interface management commands.

Definition at line 248 of file ifmgmt_cmd.c.