From: Simon Kuenzer Date: Fri, 8 Dec 2023 00:02:48 +0000 (+0100) Subject: init: Support setting interface hostname (`UK_NETDEV_IPV4_HOSTNAME`) X-Git-Tag: RELEASE-0.16.2~9 X-Git-Url: http://xenbits.xensource.com/gitweb?a=commitdiff_plain;h=9110830303d40284486d4d748276fed4a985226a;p=unikraft%2Flibs%2Flwip.git init: Support setting interface hostname (`UK_NETDEV_IPV4_HOSTNAME`) 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 Reviewed-by: Stefan Jumarea Approved-by: Razvan Deaconescu GitHub-Closes: #42 --- diff --git a/include/lwipopts.h b/include/lwipopts.h index 608d6a7..54d802b 100644 --- a/include/lwipopts.h +++ b/include/lwipopts.h @@ -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 diff --git a/include/netif/uknetdev.h b/include/netif/uknetdev.h index 8607b70..9b452c0 100644 --- a/include/netif/uknetdev.h +++ b/include/netif/uknetdev.h @@ -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 49eb04c..7d9b13d 100644 --- 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", diff --git a/uknetdev.c b/uknetdev.c index 9cf2fdf..67a63bf 100644 --- a/uknetdev.c +++ b/uknetdev.c @@ -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; }