[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Minios-devel] [UNIKRAFT/LIBLWIP PATCH 5/5] Netif status print callback



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@xxxxxxxxx>
---
 Config.uk          | 13 +++++++++
 include/lwipopts.h |  6 +++++
 init.c             | 66 ++++++++++++++++++++++++++++++++++++++++++++++
 3 files changed, 85 insertions(+)

diff --git a/Config.uk b/Config.uk
index acfe3ef..a0db41d 100644
--- 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
diff --git a/include/lwipopts.h b/include/lwipopts.h
index 749b2a9..c94c23d 100644
--- a/include/lwipopts.h
+++ b/include/lwipopts.h
@@ -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 65d56b6..a5854b8 100644
--- a/init.c
+++ b/init.c
@@ -45,6 +45,67 @@
 #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;
 
-- 
2.20.1


_______________________________________________
Minios-devel mailing list
Minios-devel@xxxxxxxxxxxxxxxxxxxx
https://lists.xenproject.org/mailman/listinfo/minios-devel

 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.