vlib: fix offload flags value reset
[vpp.git] / src / vppinfra / unix-formats.c
index 9198651..678700e 100644 (file)
 
 #ifdef __KERNEL__
 
+#if __linux__
 # include <linux/unistd.h>
 # include <linux/signal.h>
+#endif
 
 #else /* ! __KERNEL__ */
 
+#ifdef __APPLE__
+#define _XOPEN_SOURCE
+#endif
+
 #define _GNU_SOURCE            /* to get REG_* in ucontext.h */
 #include <ucontext.h>
-#undef _GNU_SOURCE
 #undef __USE_GNU
 
 #include <unistd.h>
 #include <math.h>
 
 #include <vppinfra/time.h>
+#if __linux__
+#include <vppinfra/linux/syscall.h>
 
 #ifdef AF_NETLINK
 #include <linux/types.h>
 #include <linux/netlink.h>
 #endif
+#endif
 
 #endif /* ! __KERNEL__ */
 
@@ -231,6 +239,7 @@ u8 * format_sockaddr (u8 * s, va_list * args)
 {
   void * v = va_arg (*args, void *);
   struct sockaddr * sa = v;
+  static u32 local_counter;
 
   switch (sa->sa_family)
     {
@@ -243,6 +252,17 @@ u8 * format_sockaddr (u8 * s, va_list * args)
       }
       break;
 
+    case AF_LOCAL:
+      {
+        /* 
+         * There isn't anything useful to print.
+         * The unix cli world uses the output to make a node name,
+         * so we need to return a unique name. 
+         */
+        s = format (s, "local:%u", local_counter++);
+      }
+      break;
+
 #ifndef __KERNEL__
 #ifdef AF_NETLINK
     case AF_NETLINK:
@@ -264,6 +284,7 @@ u8 * format_sockaddr (u8 * s, va_list * args)
   return s;
 }
 
+#ifndef __APPLE__
 u8 * format_tcp4_packet (u8 * s, va_list * args)
 {
   u8 * p = va_arg (*args, u8 *);
@@ -295,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;
 }
@@ -700,7 +723,7 @@ u8 * format_ethernet_packet (u8 * s, va_list * args)
   struct ethhdr * h = va_arg (*args, struct ethhdr *);
   uword proto = h->h_proto;
   u8 * payload = (void *) (h + 1);
-  uword indent;
+  u32 indent;
 
   /* Check for 802.2/802.3 encapsulation. */
   if (proto < ETH_DATA_LEN)
@@ -790,11 +813,11 @@ u8 * format_timeval (u8 * s, va_list * args)
          break;
        case 'm':
          what = tm->tm_mon + 1;
-         what_fmt = "%2d";
+         what_fmt = "%02d";
          break;
        case 'd':
          what = tm->tm_mday;
-         what_fmt = "%2d";
+         what_fmt = "%02d";
          break;
        case 'H':
          what = tm->tm_hour;
@@ -819,6 +842,7 @@ u8 * format_timeval (u8 * s, va_list * args)
 
   return s;
 }
+#endif
 
 u8 * format_time_float (u8 * s, va_list * args)
 {
@@ -916,7 +940,7 @@ u8 * format_ucontext_pc (u8 * s, va_list * args)
     return format (s, "%p", regs[reg_no]);
 }
 
-uword
+__clib_export uword
 unformat_unix_gid (unformat_input_t * input, va_list * args)
 {
   gid_t *gid = va_arg (*args, gid_t *);