mirror of
https://github.com/ipxe/ipxe
synced 2025-12-23 21:41:43 +03:00
[cmdline] Allow "if<xxx>" commands to take options
Allow commands implemented using ifcommon_exec() to accept command-specific options. Signed-off-by: Michael Brown <mcb30@ipxe.org>
This commit is contained in:
@@ -34,9 +34,6 @@ FILE_LICENCE ( GPL2_OR_LATER );
|
||||
*
|
||||
*/
|
||||
|
||||
/** "if<xxx>" command options */
|
||||
struct option_descriptor ifcommon_opts[0];
|
||||
|
||||
/**
|
||||
* Execute if<xxx> command
|
||||
*
|
||||
@@ -48,16 +45,15 @@ struct option_descriptor ifcommon_opts[0];
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
int ifcommon_exec ( int argc, char **argv,
|
||||
struct command_descriptor *cmd,
|
||||
int ( * payload ) ( struct net_device * ),
|
||||
int stop_on_first_success ) {
|
||||
struct ifcommon_options opts;
|
||||
struct ifcommon_command_descriptor *ifcmd ) {
|
||||
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 )
|
||||
if ( ( rc = parse_options ( argc, argv, cmd, opts ) ) != 0 )
|
||||
return rc;
|
||||
|
||||
if ( optind != argc ) {
|
||||
@@ -65,8 +61,8 @@ int ifcommon_exec ( int argc, char **argv,
|
||||
for ( i = optind ; i < argc ; i++ ) {
|
||||
if ( ( rc = parse_netdev ( argv[i], &netdev ) ) != 0 )
|
||||
continue;
|
||||
if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
|
||||
stop_on_first_success ) {
|
||||
if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
|
||||
&& ifcmd->stop_on_first_success ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -74,8 +70,8 @@ int ifcommon_exec ( int argc, char **argv,
|
||||
/* Try all interfaces */
|
||||
rc = -ENODEV;
|
||||
for_each_netdev ( netdev ) {
|
||||
if ( ( ( rc = payload ( netdev ) ) == 0 ) &&
|
||||
stop_on_first_success ) {
|
||||
if ( ( ( rc = ifcmd->payload ( netdev, opts ) ) == 0 )
|
||||
&& ifcmd->stop_on_first_success ) {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
@@ -84,21 +80,30 @@ int ifcommon_exec ( int argc, char **argv,
|
||||
return rc;
|
||||
}
|
||||
|
||||
/** "ifopen" command descriptor */
|
||||
static struct command_descriptor ifopen_cmd =
|
||||
COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
|
||||
"[<interface>...]" );
|
||||
/** "ifopen" options */
|
||||
struct ifopen_options {};
|
||||
|
||||
/** "ifopen" option list */
|
||||
static struct option_descriptor ifopen_opts[] = {};
|
||||
|
||||
/**
|
||||
* "ifopen" payload
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v opts Command options
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifopen_payload ( struct net_device *netdev ) {
|
||||
static int ifopen_payload ( struct net_device *netdev,
|
||||
struct ifopen_options *opts __unused ) {
|
||||
return ifopen ( netdev );
|
||||
}
|
||||
|
||||
/** "ifopen" command descriptor */
|
||||
static struct ifcommon_command_descriptor ifopen_cmd =
|
||||
IFCOMMON_COMMAND_DESC ( struct ifopen_options, ifopen_opts,
|
||||
0, MAX_ARGUMENTS, "[<interface>...]",
|
||||
ifopen_payload, 0 );
|
||||
|
||||
/**
|
||||
* The "ifopen" command
|
||||
*
|
||||
@@ -107,25 +112,34 @@ static int ifopen_payload ( struct net_device *netdev ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifopen_exec ( int argc, char **argv ) {
|
||||
return ifcommon_exec ( argc, argv, &ifopen_cmd, ifopen_payload, 0 );
|
||||
return ifcommon_exec ( argc, argv, &ifopen_cmd );
|
||||
}
|
||||
|
||||
/** "ifclose" command descriptor */
|
||||
static struct command_descriptor ifclose_cmd =
|
||||
COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
|
||||
"[<interface>...]" );
|
||||
/** "ifclose" options */
|
||||
struct ifclose_options {};
|
||||
|
||||
/** "ifclose" option list */
|
||||
static struct option_descriptor ifclose_opts[] = {};
|
||||
|
||||
/**
|
||||
* "ifclose" payload
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v opts Command options
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifclose_payload ( struct net_device *netdev ) {
|
||||
static int ifclose_payload ( struct net_device *netdev,
|
||||
struct ifclose_options *opts __unused ) {
|
||||
ifclose ( netdev );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** "ifclose" command descriptor */
|
||||
static struct ifcommon_command_descriptor ifclose_cmd =
|
||||
IFCOMMON_COMMAND_DESC ( struct ifclose_options, ifclose_opts,
|
||||
0, MAX_ARGUMENTS, "[<interface>...]",
|
||||
ifclose_payload, 0 );
|
||||
|
||||
/**
|
||||
* The "ifclose" command
|
||||
*
|
||||
@@ -134,25 +148,34 @@ static int ifclose_payload ( struct net_device *netdev ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifclose_exec ( int argc, char **argv ) {
|
||||
return ifcommon_exec ( argc, argv, &ifclose_cmd, ifclose_payload, 0 );
|
||||
return ifcommon_exec ( argc, argv, &ifclose_cmd );
|
||||
}
|
||||
|
||||
/** "ifstat" command descriptor */
|
||||
static struct command_descriptor ifstat_cmd =
|
||||
COMMAND_DESC ( struct ifcommon_options, ifcommon_opts, 0, MAX_ARGUMENTS,
|
||||
"[<interface>...]" );
|
||||
/** "ifstat" options */
|
||||
struct ifstat_options {};
|
||||
|
||||
/** "ifstat" option list */
|
||||
static struct option_descriptor ifstat_opts[] = {};
|
||||
|
||||
/**
|
||||
* "ifstat" payload
|
||||
*
|
||||
* @v netdev Network device
|
||||
* @v opts Command options
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifstat_payload ( struct net_device *netdev ) {
|
||||
static int ifstat_payload ( struct net_device *netdev,
|
||||
struct ifstat_options *opts __unused ) {
|
||||
ifstat ( netdev );
|
||||
return 0;
|
||||
}
|
||||
|
||||
/** "ifstat" command descriptor */
|
||||
static struct ifcommon_command_descriptor ifstat_cmd =
|
||||
IFCOMMON_COMMAND_DESC ( struct ifstat_options, ifstat_opts,
|
||||
0, MAX_ARGUMENTS, "[<interface>...]",
|
||||
ifstat_payload, 0 );
|
||||
|
||||
/**
|
||||
* The "ifstat" command
|
||||
*
|
||||
@@ -161,7 +184,7 @@ static int ifstat_payload ( struct net_device *netdev ) {
|
||||
* @ret rc Return status code
|
||||
*/
|
||||
static int ifstat_exec ( int argc, char **argv ) {
|
||||
return ifcommon_exec ( argc, argv, &ifstat_cmd, ifstat_payload, 0 );
|
||||
return ifcommon_exec ( argc, argv, &ifstat_cmd );
|
||||
}
|
||||
|
||||
/** Interface management commands */
|
||||
|
||||
Reference in New Issue
Block a user