From: Simon Kuenzer Date: Fri, 2 Feb 2024 12:57:22 +0000 (+0100) Subject: init: Option to fail boot without netifs X-Git-Tag: RELEASE-0.16.2~1 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=2a14d16d3aef1f541057d2de966456ccb78aa5fd;p=unikraft%2Flibs%2Flwip.git init: Option to fail boot without netifs 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 Approved-by: Razvan Deaconescu Reviewed-by: Razvan Deaconescu GitHub-Closes: #47 --- diff --git a/Config.uk b/Config.uk index 89de16c..d18ce35 100644 --- 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 5aaf2fd..763146d 100644 --- a/init.c +++ b/init.c @@ -44,6 +44,7 @@ #else /* CONFIG_LWIP_NOTHREADS */ #include #endif /* CONFIG_LWIP_NOTHREADS */ +#include #include #include "netif/uknetdev.h" #include @@ -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; }