vppinfra: ensure _GNU_SOURCE is present 90/30790/8
authorNathan Moos <nmoos@cisco.com>
Sat, 16 Jan 2021 00:45:14 +0000 (16:45 -0800)
committerDamjan Marion <dmarion@me.com>
Thu, 21 Jan 2021 13:08:57 +0000 (13:08 +0000)
Type: fix

When building with musl, _GNU_SOURCE is required to be defined in more
places. This patch defines it in those required places. Additionally,
this patch changes the udphdr field names to the standard names.

Change-Id: I0fec54214ccc8458289176488afb4218761e9d51
Signed-off-by: Nathan Moos <nmoos@cisco.com>
src/vppinfra/socket.c
src/vppinfra/unix-formats.c

index 3226061..3271393 100644 (file)
@@ -38,6 +38,7 @@
 #include <stdio.h>
 #include <string.h>            /* strchr */
 #define __USE_GNU
+#define _GNU_SOURCE
 #include <sys/types.h>
 #include <sys/socket.h>
 #include <sys/un.h>
 #include <vppinfra/format.h>
 #include <vppinfra/error.h>
 
+#ifndef __GLIBC__
+/* IPPORT_USERRESERVED is not part of musl libc. */
+#define IPPORT_USERRESERVED 5000
+#endif
+
 __clib_export void
 clib_socket_tx_add_formatted (clib_socket_t * s, char *fmt, ...)
 {
index fd0539c..678700e 100644 (file)
@@ -50,7 +50,6 @@
 
 #define _GNU_SOURCE            /* to get REG_* in ucontext.h */
 #include <ucontext.h>
-#undef _GNU_SOURCE
 #undef __USE_GNU
 
 #include <unistd.h>
@@ -317,11 +316,13 @@ u8 * format_udp4_packet (u8 * s, va_list * args)
   struct iphdr * ip = (void *) p;
   struct udphdr * udp = (void *) (ip + 1);
 
-  s = format (s, "udp %U:%U -> %U:%U",
-             format_network_address, AF_INET,  &ip->saddr,
-             format_network_port, IPPROTO_UDP, ntohs (udp->source),
-             format_network_address, AF_INET,  &ip->daddr,
-             format_network_port, IPPROTO_UDP, ntohs (udp->dest));
+  u16 source = udp->uh_sport;
+  u16 dest = udp->uh_dport;
+
+  s = format (s, "udp %U:%U -> %U:%U", format_network_address, AF_INET,
+             &ip->saddr, format_network_port, IPPROTO_UDP, ntohs (source),
+             format_network_address, AF_INET, &ip->daddr, format_network_port,
+             IPPROTO_UDP, ntohs (dest));
 
   return s;
 }