]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
init: Option to fail boot without netifs
authorSimon Kuenzer <simon@unikraft.io>
Fri, 2 Feb 2024 12:57:22 +0000 (13:57 +0100)
committerRazvan Deaconescu <razvan.deaconescu@upb.ro>
Fri, 9 Feb 2024 20:31:10 +0000 (22:31 +0200)
This commit introduces the option to fail booting if no network
interface was found and can be used by lwip.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
Reviewed-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #47

Config.uk
init.c

index 89de16c13626445bcf7e72551c1d9d7f5a77d86c..d18ce35b576ba5636642a909582525dd3546afd2 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -100,6 +100,10 @@ config LWIP_AUTOIFACE
                Automatically attach found network devices to the stack
                during initialization.
 
+config LWIP_FAILNOIFACE
+       bool "Fail boot without netifs"
+       depends on LWIP_AUTOIFACE
+
 choice
        prompt "Operation mode"
        default LWIP_THREADS
diff --git a/init.c b/init.c
index 5aaf2fd44db5d85a402bf4815eb5d5356172d82f..763146da5755243817254c8662ddea555a9b2a58 100644 (file)
--- a/init.c
+++ b/init.c
@@ -44,6 +44,7 @@
 #else /* CONFIG_LWIP_NOTHREADS */
 #include <uk/semaphore.h>
 #endif /* CONFIG_LWIP_NOTHREADS */
+#include <errno.h>
 #include <uk/netdev_core.h>
 #include "netif/uknetdev.h"
 #include <uk/init.h>
@@ -128,6 +129,8 @@ static void _lwip_init_done(void *arg __unused)
 }
 #endif /* !CONFIG_LWIP_NOTHREADS */
 
+static unsigned int lwip_netif_attached = 0;
+
 /*
  * This function initializing the lwip network stack
  */
@@ -317,6 +320,7 @@ no_conf:
                                  devid);
                        continue;
                }
+               lwip_netif_attached += 1;
 
                /* Print hardware address */
                if (nf->hwaddr_len == 6) {
@@ -422,6 +426,15 @@ dns_done:
                }
 #endif /* LWIP_IPV4 && LWIP_DHCP */
        }
+
+       if (lwip_netif_attached == 0) {
+#if !CONFIG_LWIP_FAILNOIFACE
+               uk_pr_warn("No network interface attached!\n");
+#else /* CONFIG_LWIP_FAILNOIFACE */
+               uk_pr_crit("No network interface attached!\n");
+               return -ETIMEDOUT;
+#endif  /* CONFIG_LWIP_FAILNOIFACE */
+       }
 #endif /* CONFIG_LWIP_UKNETDEV && CONFIG_LWIP_AUTOIFACE */
        return 0;
 }