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

Re: [Minios-devel] [UNIKRAFT/LIBLWIP PATCH 2/2] Add getservbyport_r and if_indextoname


  • To: "minios-devel@xxxxxxxxxxxxxxxxxxxx" <minios-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Vlad-Andrei BĂDOIU (78692) <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>
  • Date: Mon, 21 Oct 2019 11:49:44 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=stud.acs.upb.ro; dmarc=pass action=none header.from=stud.acs.upb.ro; dkim=pass header.d=stud.acs.upb.ro; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=yfd+qROfqtVqRdgDlZIokGCbHL07VS60v9PQHuNM1/E=; b=JOz6uVHYX2xlrFCwLs0DWj+yxaylbGBkRQ2riQd4o5hasQZFoIyTX3q51nXZ7zNDR21qXKEac411AO/fuoYkZKx+SjnWqP7lFLcN7fxgjmHdlqh1wO02uOJZzk0bXK55zZZyM6cRadUfOfJd717fdZIlvEBS/EkF3vJZeqDPU964A2j3LLO2EDZQTHZR1ZQbUJbc7DM0q2dEPhRMNde3CMkhVL1mW8TrrYnNOShB16tfDREl6X2RgGDYQxdsJYm+T7H/YjrNzZp9nQrQhdzR10rBMbaH/5HAfTK8tZR8rLZPBI8Njd9991CrrizJLVP9KQeZ/PKLLgUWGwI9j0dcGw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=Irf7ssMOR49lFnAyWdDgRmtIaYV5QBkebzgZcPpL/GI0THjF0TcW7By8ltuJnra+VBwCgDGsb24XYRqn0PNr27A+uJK0aq8qR/kL7BuZA3YcIbA3voMxjCkNVzQpKxFR+ExKt72nkn0pTLmn0Y34tioWv8pwGAWUGkb7gfZT+yqqK7fq13kWiATx3scp+2JPsto6+o5p9Hq+ofw2iFuhdpwl4Rmnhv/0M/z0EwCOoJhP4K7NKxC2NL4UlPHYCWoEC1gdd0AzXf8Gm531NaGhYbKluyJ5vaGy0EoG/39MqHM1GX++y5POeGpYQepY2IvXAgBYlb7xY84/Qp6MReATkg==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Delivery-date: Mon, 21 Oct 2019 11:49:52 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHVbUl0Ftv+9nyVZUKzNXdTHqJMpadlMK6A
  • Thread-topic: [Minios-devel] [UNIKRAFT/LIBLWIP PATCH 2/2] Add getservbyport_r and if_indextoname

Hey Felipe,

Please see my comments inline.

On 17.09.2019 14:16, Felipe Huici wrote:
> Add stub for if_indextoname and full definition, taken from musl, for
> getservbyport_r . if_indextoname's stub returns 0 (i.e., interface 0),
> which should be good enough for our purposes.
>
> Signed-off-by: Felipe Huici <felipe.huici@xxxxxxxxx>
> ---
>   Makefile.uk      |  1 +
>   exportsyms.uk    |  2 ++
>   ifname.c         |  6 ++++++
>   include/net/if.h |  2 ++
>   include/netdb.h  |  8 ++++++++
>   serv.c           | 56 
> ++++++++++++++++++++++++++++++++++++++++++++++++++++++++
>   6 files changed, 75 insertions(+)
>   create mode 100644 ifname.c
>
> diff --git a/Makefile.uk b/Makefile.uk
> index 2292cb4..2916a00 100644
> --- a/Makefile.uk
> +++ b/Makefile.uk
> @@ -82,6 +82,7 @@ LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += 
> $(LIBLWIP_BASE)/mutex.c|unikraft
>   LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/semaphore.c|unikraft
>   LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/mailbox.c|unikraft
>   LIBLWIP_SRCS-$(CONFIG_LWIP_THREADS) += $(LIBLWIP_BASE)/threads.c|unikraft
> +LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/ifname.c|unikraft
>   LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/init.c|unikraft
>   LIBLWIP_SRCS-y += $(LIBLWIP_BASE)/time.c|unikraft
>   LIBLWIP_SRCS-$(CONFIG_LWIP_SOCKET) += $(LIBLWIP_BASE)/sockets.c|unikraft
> diff --git a/exportsyms.uk b/exportsyms.uk
> index a315dff..be92bb6 100644
> --- a/exportsyms.uk
> +++ b/exportsyms.uk
> @@ -16,9 +16,11 @@ getprotobynumber
>   getprotoent
>   getservbyname
>   getservbyport
> +getservbyport_r
The patch no longer applies since we have removed exportsysm.uk in a 
previous patch.
>   getsockname
>   getsockopt
>   h_errno
> +if_indextoname
>   igmp_joingroup
>   inet_ntop
>   inet_pton
> diff --git a/ifname.c b/ifname.c
> new file mode 100644
> index 0000000..fe64967
> --- /dev/null
> +++ b/ifname.c
> @@ -0,0 +1,6 @@
> +#include <net/if.h>
> +
> +char *if_indextoname(unsigned index, char *name)
> +{
> +  return 0;
> +}
This file is missing the license.
> diff --git a/include/net/if.h b/include/net/if.h
> index 3fbfdec..9bb3c87 100644
> --- a/include/net/if.h
> +++ b/include/net/if.h
> @@ -1 +1,3 @@
>   #include <compat/posix/net/if.h>
> +
> +char *if_indextoname (unsigned int, char *);
> diff --git a/include/netdb.h b/include/netdb.h
> index b100136..948a2e7 100644
> --- a/include/netdb.h
> +++ b/include/netdb.h
> @@ -17,6 +17,7 @@ int getaddrinfo(const char *node, const char *service,
>               struct addrinfo **res);
>   void freeaddrinfo(struct addrinfo *res);
>   
> +
>   #endif /* LWIP_DNS && LWIP_SOCKET && !(LWIP_COMPAT_SOCKETS) */
>   
>   const char *gai_strerror(int errcode);
> @@ -57,6 +58,10 @@ void setprotoent(int stayopen);
>   #define NI_DGRAM        0x10
>   #define NI_NUMERICSCOPE 0x20
>   
> +/* Error value for getservbyport_r not defined by lwip/netdb.h */
> +/* Imported from musl */
> +#define EAI_SYSTEM     11
> +
>   /* Error values for getaddrinfo() not defined by lwip/netdb.h */
>   #define EAI_OVERFLOW    205      /* Argument buffer overflow.  */
>   
> @@ -66,3 +71,6 @@ int getnameinfo(const struct sockaddr *addr, socklen_t 
> addrlen,
>   
>   struct servent *getservbyname(const char *name, const char *proto);
>   struct servent *getservbyport(int port, const char *proto);
> +int getservbyport_r(int port, const char *prots, struct servent *se,
> +                 char *buf, size_t buflen, struct servent **res);
> +
> diff --git a/serv.c b/serv.c
> index b273def..b08ffa4 100644
> --- a/serv.c
> +++ b/serv.c
> @@ -32,7 +32,12 @@
>    */
>   
>   #include <sys/socket.h>
> +#include <netinet/in.h>
>   #include <netdb.h>
> +#include <inttypes.h>
> +#include <errno.h>
> +#include <string.h>
> +#include <stdlib.h>
>   
>   struct servent *getservbyname(const char *name __unused,
>       const char *proto __unused)
> @@ -45,3 +50,54 @@ struct servent *getservbyport(int port __unused,
>   {
>       return NULL;
>   }
> +
> +int getservbyport_r(int port, const char *prots, struct servent *se, char 
> *buf, size_t buflen, struct servent **res)
> +{
> +  int i;
> +  struct sockaddr_in sin = {
> +    .sin_family = AF_INET,
> +    .sin_port = port,
> +  };
> +
> +  if (!prots) {
> +    int r = getservbyport_r(port, "tcp", se, buf, buflen, res);
> +    if (r) r = getservbyport_r(port, "udp", se, buf, buflen, res);
> +    return r;
> +  }
> +  *res = 0;
> +
> +  /* Align buffer */
> +  i = (uintptr_t)buf & (sizeof(char *)-1);
> +  if (!i) i = sizeof(char *);
> +  if (buflen < 3*sizeof(char *)-i)
> +    return ERANGE;
> +  buf += sizeof(char *)-i;
> +  buflen -= sizeof(char *)-i;
> +
> +  if (strcmp(prots, "tcp") && strcmp(prots, "udp")) return EINVAL;
> +
> +  se->s_port = port;
> +  se->s_proto = (char *)prots;
> +  se->s_aliases = (void *)buf;
> +  buf += 2*sizeof(char *);
> +  buflen -= 2*sizeof(char *);
> +  se->s_aliases[1] = 0;
> +  se->s_aliases[0] = se->s_name = buf;
> +
> +  switch (getnameinfo((void *)&sin, sizeof sin, 0, 0, buf, buflen,
> +                   strcmp(prots, "udp") ? 0 : NI_DGRAM)) {
> +  case EAI_MEMORY:
> +  case EAI_SYSTEM:
> +    return ENOMEM;
> +  default:
> +    return ENOENT;
> +  case 0:
> +    break;
> +  }
> +
> +  /* A numeric port string is not a service record. */
> +  if (strtol(buf, 0, 10)==ntohs(port)) return ENOENT;
> +
> +  *res = se;
> +  return 0;
> +}
_______________________________________________
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®.