[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



Hi Vlad,

On 28.10.19, 14:24, "Minios-devel on behalf of Vlad-Andrei BĂDOIU (78692)" 
<minios-devel-bounces@xxxxxxxxxxxxxxxxxxxx on behalf of 
vlad_andrei.badoiu@xxxxxxxxxxxxxxx> wrote:

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

Ok, I'll have a look.
    
    One comment, since we have musl right around the corner this 
    implementation might have to be moved quite soon.

Yes, agree.

Thanks,

-- Felipe

    
    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

_______________________________________________
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®.