mirror of https://github.com/ipxe/ipxe.git
[cmdline] Expose "iflinkwait" as a command
Signed-off-by: Michael Brown <mcb30@ipxe.org>pull/224/head
parent
ade4d2b4fe
commit
42db0bd041
|
@ -250,6 +250,58 @@ int ifconf_exec ( int argc, char **argv ) {
|
||||||
return ifcommon_exec ( argc, argv, &ifconf_cmd );
|
return ifcommon_exec ( argc, argv, &ifconf_cmd );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/** "iflinkwait" option list */
|
||||||
|
struct iflinkwait_options {
|
||||||
|
/** Link timeout */
|
||||||
|
unsigned long timeout;
|
||||||
|
};
|
||||||
|
|
||||||
|
/** "iflinkwait" option list */
|
||||||
|
static struct option_descriptor iflinkwait_opts[] = {
|
||||||
|
OPTION_DESC ( "timeout", 't', required_argument,
|
||||||
|
struct iflinkwait_options, timeout, parse_timeout ),
|
||||||
|
};
|
||||||
|
|
||||||
|
/**
|
||||||
|
* "iflinkwait" payload
|
||||||
|
*
|
||||||
|
* @v netdev Network device
|
||||||
|
* @v opts Command options
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
static int iflinkwait_payload ( struct net_device *netdev,
|
||||||
|
struct iflinkwait_options *opts ) {
|
||||||
|
int rc;
|
||||||
|
|
||||||
|
/* Wait for link-up */
|
||||||
|
if ( ( rc = iflinkwait ( netdev, opts->timeout, 1 ) ) != 0 ) {
|
||||||
|
|
||||||
|
/* Close device on failure, to avoid memory exhaustion */
|
||||||
|
netdev_close ( netdev );
|
||||||
|
|
||||||
|
return rc;
|
||||||
|
}
|
||||||
|
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
/** "iflinkwait" command descriptor */
|
||||||
|
static struct ifcommon_command_descriptor iflinkwait_cmd =
|
||||||
|
IFCOMMON_COMMAND_DESC ( struct iflinkwait_options, iflinkwait_opts,
|
||||||
|
0, MAX_ARGUMENTS, "[<interface>...]",
|
||||||
|
iflinkwait_payload, 1 );
|
||||||
|
|
||||||
|
/**
|
||||||
|
* The "iflinkwait" command
|
||||||
|
*
|
||||||
|
* @v argc Argument count
|
||||||
|
* @v argv Argument list
|
||||||
|
* @ret rc Return status code
|
||||||
|
*/
|
||||||
|
static int iflinkwait_exec ( int argc, char **argv ) {
|
||||||
|
return ifcommon_exec ( argc, argv, &iflinkwait_cmd );
|
||||||
|
}
|
||||||
|
|
||||||
/** Interface management commands */
|
/** Interface management commands */
|
||||||
struct command ifmgmt_commands[] __command = {
|
struct command ifmgmt_commands[] __command = {
|
||||||
{
|
{
|
||||||
|
@ -268,4 +320,8 @@ struct command ifmgmt_commands[] __command = {
|
||||||
.name = "ifconf",
|
.name = "ifconf",
|
||||||
.exec = ifconf_exec,
|
.exec = ifconf_exec,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
.name = "iflinkwait",
|
||||||
|
.exec = iflinkwait_exec,
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
|
@ -18,6 +18,7 @@ extern int ifconf ( struct net_device *netdev,
|
||||||
unsigned long timeout );
|
unsigned long timeout );
|
||||||
extern void ifclose ( struct net_device *netdev );
|
extern void ifclose ( struct net_device *netdev );
|
||||||
extern void ifstat ( struct net_device *netdev );
|
extern void ifstat ( struct net_device *netdev );
|
||||||
extern int iflinkwait ( struct net_device *netdev, unsigned long timeout );
|
extern int iflinkwait ( struct net_device *netdev, unsigned long timeout,
|
||||||
|
int verbose );
|
||||||
|
|
||||||
#endif /* _USR_IFMGMT_H */
|
#endif /* _USR_IFMGMT_H */
|
||||||
|
|
|
@ -212,17 +212,20 @@ static int iflinkwait_progress ( struct ifpoller *ifpoller ) {
|
||||||
*
|
*
|
||||||
* @v netdev Network device
|
* @v netdev Network device
|
||||||
* @v timeout Timeout period, in ticks
|
* @v timeout Timeout period, in ticks
|
||||||
|
* @v verbose Always display progress message
|
||||||
|
* @ret rc Return status code
|
||||||
*/
|
*/
|
||||||
int iflinkwait ( struct net_device *netdev, unsigned long timeout ) {
|
int iflinkwait ( struct net_device *netdev, unsigned long timeout,
|
||||||
|
int verbose ) {
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Ensure device is open */
|
/* Ensure device is open */
|
||||||
if ( ( rc = ifopen ( netdev ) ) != 0 )
|
if ( ( rc = ifopen ( netdev ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Return immediately if link is already up */
|
/* Return immediately if link is already up, unless being verbose */
|
||||||
netdev_poll ( netdev );
|
netdev_poll ( netdev );
|
||||||
if ( netdev_link_ok ( netdev ) )
|
if ( netdev_link_ok ( netdev ) && ( ! verbose ) )
|
||||||
return 0;
|
return 0;
|
||||||
|
|
||||||
/* Wait for link-up */
|
/* Wait for link-up */
|
||||||
|
@ -273,7 +276,7 @@ int ifconf ( struct net_device *netdev,
|
||||||
int rc;
|
int rc;
|
||||||
|
|
||||||
/* Ensure device is open and link is up */
|
/* Ensure device is open and link is up */
|
||||||
if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT ) ) != 0 )
|
if ( ( rc = iflinkwait ( netdev, LINK_WAIT_TIMEOUT, 0 ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Start configuration */
|
/* Start configuration */
|
||||||
|
|
|
@ -208,9 +208,9 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Wait for link-up */
|
/* Wait for link-up */
|
||||||
if ( ( rc = iflinkwait ( sender, 0 ) ) != 0 )
|
if ( ( rc = iflinkwait ( sender, 0, 0 ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
if ( ( rc = iflinkwait ( receiver, 0 ) ) != 0 )
|
if ( ( rc = iflinkwait ( receiver, 0, 0 ) ) != 0 )
|
||||||
return rc;
|
return rc;
|
||||||
|
|
||||||
/* Allocate data buffer */
|
/* Allocate data buffer */
|
||||||
|
|
Loading…
Reference in New Issue