]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
Netif status print callback
authorSimon Kuenzer <simon.kuenzer@neclab.eu>
Thu, 7 Feb 2019 23:00:35 +0000 (00:00 +0100)
committerSimon Kuenzer <simon.kuenzer@neclab.eu>
Mon, 11 Feb 2019 18:21:53 +0000 (19:21 +0100)
Introduce a status print hook to all netifs operated by the lwIP
stack. State changes (e.g., assigning of an IP, bringing device up or
down) are printed to the standard console. Because the stack is not
printing any message to the console with the default configuration, we
enable this print hook as default.

Signed-off-by: Simon Kuenzer <simon.kuenzer@neclab.eu>
Reviewed-by: Sharan Santhanam <sharan.santhanam@neclab.eu>
Config.uk
include/lwipopts.h
init.c

index acfe3ef5fc43792ca2aa26ff170e5aea4b3148ae..a0db41dd0a623c60b58ef6b97edf3968d5134c9f 100644 (file)
--- a/Config.uk
+++ b/Config.uk
@@ -67,6 +67,19 @@ config LWIP_HEAP
 #      bool "Memory pools"
 endchoice
 
+config LWIP_NETIF_EXT_STATUS_CALLBACK
+       bool "Netif extended status callback API"
+       default y
+       help
+               Support extended status callbacks to netif related events.
+
+config LWIP_NETIF_STATUS_PRINT
+       bool "Print netif status updates"
+       depends on LWIP_NETIF_EXT_STATUS_CALLBACK
+       default y
+       help
+               Print netif status changes to standard console
+
 config LWIP_IPV4
        bool "IPv4 support"
        default y
index 749b2a90c682d54edc933c91a1d4b4cf3d60a16d..c94c23df8e50ab6ef7362764e3ace1f4ec7c7d6d 100644 (file)
@@ -89,6 +89,12 @@ void sys_free(void *ptr);
 #define LWIP_TIMEVAL_PRIVATE 0
 #define LWIP_NETIF_STATUS_CALLBACK 1
 
+#if CONFIG_LWIP_NETIF_EXT_STATUS_CALLBACK
+#define LWIP_NETIF_EXT_STATUS_CALLBACK 1
+#else
+#define LWIP_NETIF_EXT_STATUS_CALLBACK 0
+#endif /* CONFIG_LWIP_NETIF_EXT_STATUS_CALLBACK */
+
 /**
  * ARP options
  */
diff --git a/init.c b/init.c
index 65d56b61cdf35dc0de856e1f43b09a28161b5975..a5854b83d0d966cd19bcb235c4659366f364db61 100644 (file)
--- a/init.c
+++ b/init.c
 #endif /* CONFIG_LWIP_NOTHREADS */
 #include "netif/uknetdev.h"
 
+#if LWIP_NETIF_EXT_STATUS_CALLBACK && CONFIG_LWIP_NETIF_STATUS_PRINT
+#include <stdio.h>
+
+static void _netif_status_print(struct netif *nf, netif_nsc_reason_t reason,
+                               const netif_ext_callback_args_t *args)
+{
+       if (reason & LWIP_NSC_NETIF_ADDED)
+               printf("%c%c%u: Added\n",
+                      nf->name[0], nf->name[1], nf->num);
+       if (reason & LWIP_NSC_NETIF_REMOVED)
+               printf("%c%c%u: Removed\n",
+                      nf->name[0], nf->name[1], nf->num);
+       if (reason & LWIP_NSC_LINK_CHANGED)
+               printf("%c%c%u: Link is %s\n",
+                      nf->name[0], nf->name[1], nf->num,
+                      args->link_changed.state ? "up" : "down");
+       if (reason & LWIP_NSC_STATUS_CHANGED)
+               printf("%c%c%u: Interface is %s\n",
+                      nf->name[0], nf->name[1], nf->num,
+                      args->status_changed.state ? "up" : "down");
+
+#if LWIP_IPV4
+       if ((reason & LWIP_NSC_IPV4_SETTINGS_CHANGED)
+           || (reason & LWIP_NSC_IPV4_ADDRESS_CHANGED)
+           || (reason & LWIP_NSC_IPV4_NETMASK_CHANGED)
+           || (reason & LWIP_NSC_IPV4_GATEWAY_CHANGED)) {
+               char str_ip4_addr[17];
+               char str_ip4_mask[17];
+               char str_ip4_gw[17];
+
+               ipaddr_ntoa_r(&nf->ip_addr, str_ip4_addr, sizeof(str_ip4_addr));
+               ipaddr_ntoa_r(&nf->netmask, str_ip4_mask, sizeof(str_ip4_mask));
+               ipaddr_ntoa_r(&nf->gw,      str_ip4_gw,   sizeof(str_ip4_gw));
+
+               printf("%c%c%u: Set IPv4 address %s mask %s gw %s\n",
+                      nf->name[0], nf->name[1], nf->num,
+                      str_ip4_addr, str_ip4_mask, str_ip4_gw);
+       }
+#endif /* LWIP_IPV4 */
+
+#if LWIP_IPV6
+       if (reason & LWIP_NSC_IPV6_SET)
+               printf("%c%c%u: Set IPv6 address %"__PRIs8": %s (state %"__PRIu8")\n",
+                      nf->name[0], nf->name[1], nf->num,
+                      args->ipv6_set.addr_index,
+                      ipaddr_ntoa(&nf->ip6_addr[args->ipv6_set.addr_index]),
+                      nf->ip6_addr_state[args->ipv6_set.addr_index]);
+       if (reason & LWIP_NSC_IPV6_ADDR_STATE_CHANGED)
+               printf("%c%c%u: Set IPv6 address %"__PRIs8": %s (state %"__PRIu8")\n",
+                      nf->name[0], nf->name[1], nf->num,
+                      args->ipv6_set.addr_index,
+                      ipaddr_ntoa(&nf->ip6_addr[
+                                    args->ipv6_addr_state_changed.addr_index]),
+                      nf->ip6_addr_state[
+                                    args->ipv6_addr_state_changed.addr_index]);
+#endif /* LWIP_IPV6 */
+}
+
+NETIF_DECLARE_EXT_CALLBACK(netif_status_print)
+#endif /* LWIP_NETIF_EXT_STATUS_CALLBACK && CONFIG_LWIP_NETIF_STATUS_PRINT */
+
 void sys_init(void)
 {
        /*
@@ -99,6 +160,11 @@ int liblwip_init(void)
        uk_semaphore_down(&_lwip_init_sem);
 #endif /* CONFIG_LWIP_NOTHREADS */
 
+#if LWIP_NETIF_EXT_STATUS_CALLBACK && CONFIG_LWIP_NETIF_STATUS_PRINT
+       /* Add print callback for netif state changes */
+       netif_add_ext_callback(&netif_status_print, _netif_status_print);
+#endif /* LWIP_NETIF_EXT_STATUS_CALLBACK && CONFIG_LWIP_NETIF_STATUS_PRINT */
+
 #if CONFIG_LWIP_UKNETDEV && CONFIG_LWIP_AUTOIFACE
        is_first_nf = 1;