]> git.ipfire.org Git - thirdparty/ipxe.git/commitdiff
[cmdline] Expose "iflinkwait" as a command 224/head
authorMichael Brown <mcb30@ipxe.org>
Tue, 26 Jan 2021 15:44:59 +0000 (15:44 +0000)
committerMichael Brown <mcb30@ipxe.org>
Tue, 26 Jan 2021 17:07:52 +0000 (17:07 +0000)
Signed-off-by: Michael Brown <mcb30@ipxe.org>
src/hci/commands/ifmgmt_cmd.c
src/include/usr/ifmgmt.h
src/usr/ifmgmt.c
src/usr/lotest.c

index 2e976d3fbb3791d61c52b0bd883b2f23c093531d..591cb3da8727e9a316bba43e5fff9873a1d4bd56 100644 (file)
@@ -250,6 +250,58 @@ int ifconf_exec ( int argc, char **argv ) {
        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 */
 struct command ifmgmt_commands[] __command = {
        {
@@ -268,4 +320,8 @@ struct command ifmgmt_commands[] __command = {
                .name = "ifconf",
                .exec = ifconf_exec,
        },
+       {
+               .name = "iflinkwait",
+               .exec = iflinkwait_exec,
+       },
 };
index 52f88f9577a49e60d138e30115c94d085d43f41b..8d8a6bb56a5b8c53654ac4e5d717a8343e27814b 100644 (file)
@@ -18,6 +18,7 @@ extern int ifconf ( struct net_device *netdev,
                    unsigned long timeout );
 extern void ifclose ( 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 */
index f1172bafb3ca63e2d7ed01606d85b96bb0481afd..2150bfff7cc044988475fb7ebd3d1f1f26e4d210 100644 (file)
@@ -212,17 +212,20 @@ static int iflinkwait_progress ( struct ifpoller *ifpoller ) {
  *
  * @v netdev           Network device
  * @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;
 
        /* Ensure device is open */
        if ( ( rc = ifopen ( netdev ) ) != 0 )
                return rc;
 
-       /* Return immediately if link is already up */
+       /* Return immediately if link is already up, unless being verbose */
        netdev_poll ( netdev );
-       if ( netdev_link_ok ( netdev ) )
+       if ( netdev_link_ok ( netdev ) && ( ! verbose ) )
                return 0;
 
        /* Wait for link-up */
@@ -273,7 +276,7 @@ int ifconf ( struct net_device *netdev,
        int rc;
 
        /* 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;
 
        /* Start configuration */
index 6b75b5048af81d63b0d652efbba0a4b950b28752..5b88ef27e000af4734937b16d97ecd7df39470e8 100644 (file)
@@ -208,9 +208,9 @@ int loopback_test ( struct net_device *sender, struct net_device *receiver,
                return rc;
 
        /* Wait for link-up */
-       if ( ( rc = iflinkwait ( sender, 0 ) ) != 0 )
+       if ( ( rc = iflinkwait ( sender, 0, 0 ) ) != 0 )
                return rc;
-       if ( ( rc = iflinkwait ( receiver, 0 ) ) != 0 )
+       if ( ( rc = iflinkwait ( receiver, 0, 0 ) ) != 0 )
                return rc;
 
        /* Allocate data buffer */