]> xenbits.xensource.com Git - unikraft/libs/lwip.git/commitdiff
init: Support setting interface hostname (`UK_NETDEV_IPV4_HOSTNAME`)
authorSimon Kuenzer <simon@unikraft.io>
Fri, 8 Dec 2023 00:02:48 +0000 (01:02 +0100)
committerRazvan Deaconescu <razvan.deaconescu@upb.ro>
Tue, 16 Jan 2024 18:16:01 +0000 (20:16 +0200)
This commit introduces support for setting an interface hostname to the
name found on uknetdev's extended information field
`UK_NETDEV_IPV4_HOSTNAME`.

Signed-off-by: Simon Kuenzer <simon@unikraft.io>
Reviewed-by: Stefan Jumarea <stefanjumarea02@gmail.com>
Approved-by: Razvan Deaconescu <razvand@unikraft.io>
GitHub-Closes: #42

include/lwipopts.h
include/netif/uknetdev.h
init.c
uknetdev.c

index 608d6a7c5f51f0fa20cbd053a2ff8ce6d151247a..54d802bbe3be6b28e91357c61bbe2d068163601c 100644 (file)
@@ -86,6 +86,7 @@ void sys_free(void *ptr);
 #define LWIP_NETIF_REMOVE_CALLBACK 1
 #define LWIP_TIMEVAL_PRIVATE 0
 #define LWIP_NETIF_STATUS_CALLBACK 1
+#define LWIP_NETIF_HOSTNAME 1
 
 #if CONFIG_LWIP_NETIF_EXT_STATUS_CALLBACK
 #define LWIP_NETIF_EXT_STATUS_CALLBACK 1
index 8607b70fec9837c59c7c5a26775785eb169c9a8a..9b452c03631e43ea90d1dc678a45a849520ba990 100644 (file)
@@ -66,8 +66,9 @@ struct netif *uknetdev_addif(struct uk_netdev *n
                             ,
                             const ip4_addr_t *ipaddr,
                             const ip4_addr_t *netmask,
-                            const ip4_addr_t *gw
+                            const ip4_addr_t *gw,
 #endif /* LWIP_IPV4 */
+                            const char *hostname
        );
 
 #ifdef __cplusplus
diff --git a/init.c b/init.c
index 49eb04ce5ebda36bd7aa009a517abadf367a44ae..7d9b13d18a09a96d65ef5f4cc8baebe4616b80c3 100644 (file)
--- a/init.c
+++ b/init.c
@@ -147,6 +147,7 @@ static int liblwip_init(struct uk_init_ctx *ictx __unused)
        ip4_addr_t *mask4_arg;
        ip4_addr_t gw4;
        ip4_addr_t *gw4_arg;
+       const char *hostname_arg;
 #endif /* LWIP_IPV4 */
 #endif /* CONFIG_LWIP_UKNETDEV && CONFIG_LWIP_AUTOIFACE */
 
@@ -199,9 +200,10 @@ static int liblwip_init(struct uk_init_ctx *ictx __unused)
                           devid);
 
 #if LWIP_IPV4
-               ip4_arg   = NULL;
-               mask4_arg = NULL;
-               gw4_arg   = NULL;
+               ip4_arg      = NULL;
+               mask4_arg    = NULL;
+               gw4_arg      = NULL;
+               hostname_arg = NULL;
 
                /* CIDR (IP and mask) */
                strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_CIDR);
@@ -288,15 +290,22 @@ ipv4_gw:
                        }
                        gw4_arg = &gw4;
                }
+
 no_conf:
-               nf = uknetdev_addif(dev, ip4_arg, mask4_arg, gw4_arg);
+               /* hostname */
+               strcfg = uk_netdev_einfo_get(dev, UK_NETDEV_IPV4_HOSTNAME);
+               if (strcfg)
+                       hostname_arg = strcfg;
+
+               nf = uknetdev_addif(dev, ip4_arg, mask4_arg, gw4_arg,
+                                   hostname_arg);
 #else /* LWIP_IPV4 */
                /*
                 * TODO: Add support for IPv6 device configuration from
                 * netdev's econf interface
                 */
 
-               nf = uknetdev_addif(dev);
+               nf = uknetdev_addif(dev, NULL);
 #endif /* LWIP_IPV4 */
                if (!nf) {
                        uk_pr_err("Failed to attach network device %u to lwIP\n",
index 9cf2fdf9648430108ec3b0e48de3068f733b1aea..67a63bf5ea749babcb4c26a1be1101fa831b1352 100644 (file)
@@ -662,8 +662,9 @@ struct netif *uknetdev_addif(struct uk_netdev *n
                             ,
                             const ip4_addr_t *ipaddr,
                             const ip4_addr_t *netmask,
-                            const ip4_addr_t *gw
+                            const ip4_addr_t *gw,
 #endif /* LWIP_IPV4 */
+                            const char *hostname
        )
 {
        /*
@@ -698,5 +699,8 @@ struct netif *uknetdev_addif(struct uk_netdev *n
                return NULL;
        }
 
+       if (hostname)
+               netif_set_hostname(nf, hostname);
+
        return ret;
 }