[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



Hi Vlad,

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

    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.

Right, I'll send a v2.

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

Ok, I'll add it to v2.

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