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

Re: [Minios-devel] [UNIKRAFT/LIBLWIP PATCH v2 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, 28 Oct 2019 13:24:02 +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=zVMYGcxhA8qpWxz/3MYgaQ+qEP6AjZtYyfhG9wMXAqM=; b=mm7eACFDXRlM5NZ/Lt7GalC8uVgWm1MFfYy67bKFmVyUQlfchJOtpehoLxzpCnm4No5Kv4b1qAC3OkH319Xw4jRp7SRhJSS1/Jvxf+B3UnyiWSNfebslbqAq2/wQFJm5ZXW4Trd4D71CTKQrNSODd2pCXxRcwfZU7jZ5SIWZp9IVLYkOD80rEmozhnUvskuiwDY1wBEAQXXbhqI8//JLN02CQ30WPvtiQsjvlnBZxcbM9RoufdfJQOICYh4wgHBZAI5LZNl0UTrdlQxcKSZQqr4+8crm8NVqe9Bo9VZB9QnACLL9SFTFFPorFxrmHen+uh7jOT+UrPLAegAuck5LTA==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NbAJyJADnJTjGq2g0bxm4V3K2/fqquIDmuJPEjl/N/Tiorwxa3ZwuN1BwYeLa5iXFgU+zOooT2XbU1NnZFIdym1MoEpKspJK4NyYFpUJ3FP5/rKi4O22c66XBiQ+42od/C45e7DhcT7Izc8X1ixqvOcCf1nh2U6cGCulo63S20sY/y/rCMOw/MNzEr7OKwUYIU3YCIHcnyow7VT9ZdfqY6R94xIAARZ+yLpfjyOo7ko3BmWxuO/ngGLPs+qCDX29UqR5xhqC9AmD3JD//wix770QPm6OvkxU9Zs+YyiEbQybhEV7NxW30+vUv+WTdpuDJucDQmgF+0PBd6rHxrMAAA==
  • Authentication-results: spf=none (sender IP is ) smtp.mailfrom=vlad_andrei.badoiu@xxxxxxxxxxxxxxx;
  • Delivery-date: Mon, 28 Oct 2019 13:24:11 +0000
  • List-id: Mini-os development list <minios-devel.lists.xenproject.org>
  • Thread-index: AQHViBX+Gu8SoKdpg0e3RumHk/xTm6dwFb4A
  • Thread-topic: [Minios-devel] [UNIKRAFT/LIBLWIP PATCH v2 2/2] Add getservbyport_r and if_indextoname

Hey Felipe,

This patch looks all right. There are several checkpath errors that may 
be solved during the upstreaming.

One comment, since we have musl right around the corner this 
implementation might have to be moved quite soon.

Thanks,

Vlad

Reviewed-by: Vlad-Andrei Badoiu <vlad_andrei.badoiu@xxxxxxxxxxxxxxx>

On 21.10.2019 16:46, 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 +
>   ifname.c         | 39 +++++++++++++++++++++++++++++++++
>   include/net/if.h |  2 ++
>   include/netdb.h  |  8 +++++++
>   serv.c           | 56 ++++++++++++++++++++++++++++++++++++++++++++++++
>   5 files changed, 106 insertions(+)
>   create mode 100644 ifname.c
>
> diff --git a/Makefile.uk b/Makefile.uk
> index 79a6dc6..6983a9d 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/ifname.c b/ifname.c
> new file mode 100644
> index 0000000..f622a3f
> --- /dev/null
> +++ b/ifname.c
> @@ -0,0 +1,39 @@
> +/* SPDX-License-Identifier: BSD-3-Clause */
> +/*
> + * Copyright (c) 2019, NEC Laboratories Europe GmbH, NEC Corporation.
> + *                     All rights reserved.
> + *
> + * Redistribution and use in source and binary forms, with or without
> + * modification, are permitted provided that the following conditions
> + * are met:
> + *
> + * 1. Redistributions of source code must retain the above copyright
> + *    notice, this list of conditions and the following disclaimer.
> + * 2. Redistributions in binary form must reproduce the above copyright
> + *    notice, this list of conditions and the following disclaimer in the
> + *    documentation and/or other materials provided with the distribution.
> + * 3. Neither the name of the copyright holder nor the names of its
> + *    contributors may be used to endorse or promote products derived from
> + *    this software without specific prior written permission.
> + *
> + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS 
> IS"
> + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
> + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
> + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
> + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
> + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
> + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
> + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
> + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
> + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
> + * POSSIBILITY OF SUCH DAMAGE.
> + *
> + * THIS HEADER MAY NOT BE EXTRACTED OR MODIFIED IN ANY WAY.
> + */
> +
> +#include <net/if.h>
> +
> +char *if_indextoname(unsigned index, char *name)
> +{
> +  return 0;
> +}
> 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®.