40 # include <linux/unistd.h> 41 # include <linux/signal.h> 55 #include <sys/socket.h> 63 #include <linux/types.h> 64 #include <linux/netlink.h> 71 # include <linux/socket.h> 72 # include <linux/in.h> 73 # include <linux/ip.h> 74 # include <linux/tcp.h> 75 # include <linux/udp.h> 76 # include <linux/icmp.h> 77 # include <linux/if_ether.h> 78 # include <linux/if_arp.h> 81 # include <netinet/in.h> 82 # include <netinet/ip.h> 83 # include <netinet/tcp.h> 84 # include <netinet/udp.h> 85 # include <netinet/ip_icmp.h> 86 # include <netinet/if_ether.h> 97 u8 * t = (
u8 *)
"UNKNOWN";
100 #define _(x) case PF_##x: t = (u8 *) #x; break 166 vec_add (s, t, strlen ((
char *) t));
176 struct protoent * p = getprotobynumber (protocol);
178 ASSERT (family == AF_INET);
180 return format (s,
"%s", p->p_name);
182 return format (s,
"%d", protocol);
184 return format (s,
"%d/%d", family, protocol);
194 struct servent * p = getservbyport (port, proto == IPPROTO_UDP ?
"udp" :
"tcp");
197 return format (s,
"%s", p->s_name);
199 return format (s,
"%d", port);
201 return format (s,
"%s/%d", proto == IPPROTO_UDP ?
"udp" :
"tcp", port);
215 s =
format (s,
"%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
220 s =
format (s,
"%02x:%02x:%02x:%02x:%02x:%02x",
221 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
225 clib_error (
"unsupported address family %d", family);
233 void *
v = va_arg (*args,
void *);
234 struct sockaddr * sa =
v;
235 static u32 local_counter;
237 switch (sa->sa_family)
241 struct sockaddr_in *
i =
v;
255 s =
format (s,
"local:%u", local_counter++);
263 struct sockaddr_nl * n =
v;
264 s =
format (s,
"KERNEL-NETLINK");
266 s =
format (s,
" (groups 0x%x)", n->nl_groups);
273 s =
format (s,
"sockaddr family %d", sa->sa_family);
282 u8 * p = va_arg (*args,
u8 *);
283 struct iphdr * ip = (
void *) p;
284 struct tcphdr * tcp = (
void *) (ip + 1);
286 s =
format (s,
"tcp %U:%U -> %U:%U",
292 s =
format (s,
", seq 0x%08x -> 0x%08x", tcp->seq, tcp->ack_seq);
293 #define _(f) if (tcp->f) s = format (s, ", " #f); 294 _ (syn); _ (ack); _ (fin); _ (rst); _ (psh); _ (urg);
298 s =
format (s,
", window 0x%04x", tcp->window);
300 s =
format (s,
", urg 0x%04x", tcp->urg_ptr);
307 u8 * p = va_arg (*args,
u8 *);
308 struct iphdr * ip = (
void *) p;
309 struct udphdr * udp = (
void *) (ip + 1);
311 s =
format (s,
"udp %U:%U -> %U:%U",
327 #define _(f,str) case ICMP_##f: s = format (s, str); break; 328 _ (ECHOREPLY,
"echo reply");
329 _ (DEST_UNREACH,
"unreachable");
330 _ (SOURCE_QUENCH,
"source quench");
331 _ (REDIRECT,
"redirect");
332 _ (ECHO,
"echo request");
333 _ (TIME_EXCEEDED,
"time exceeded");
334 _ (PARAMETERPROB,
"parameter problem");
335 _ (TIMESTAMP,
"timestamp request");
336 _ (TIMESTAMPREPLY,
"timestamp reply");
337 _ (INFO_REQUEST,
"information request");
338 _ (INFO_REPLY,
"information reply");
339 _ (ADDRESS,
"address mask request");
340 _ (ADDRESSREPLY,
"address mask reply");
343 s =
format (s,
"unknown type 0x%x", icmp_type);
346 if (icmp_type == ICMP_DEST_UNREACH)
350 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 351 _ (NET_UNREACH,
"network");
352 _ (HOST_UNREACH,
"host");
353 _ (PROT_UNREACH,
"protocol");
354 _ (PORT_UNREACH,
"port");
355 _ (FRAG_NEEDED,
": fragmentation needed/DF set");
356 _ (SR_FAILED,
"source route failed");
357 _ (NET_UNKNOWN,
"network unknown");
358 _ (HOST_UNKNOWN,
"host unknown");
359 _ (HOST_ISOLATED,
"host isolated");
360 _ (NET_ANO,
"network: admin. prohibited");
361 _ (HOST_ANO,
"host: admin. prohibited");
362 _ (NET_UNR_TOS,
"network for type-of-service");
363 _ (HOST_UNR_TOS,
"host for type-of-service");
364 _ (PKT_FILTERED,
": packet filtered");
365 _ (PREC_VIOLATION,
"precedence violation");
366 _ (PREC_CUTOFF,
"precedence cut off");
369 s =
format (s,
"unknown code 0x%x", icmp_code);
372 else if (icmp_type == ICMP_REDIRECT)
376 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 377 _ (REDIR_NET,
"network");
378 _ (REDIR_HOST,
"host");
379 _ (REDIR_NETTOS,
"network for type-of-service");
380 _ (REDIR_HOSTTOS,
"host for type-of-service");
383 s =
format (s,
"unknown code 0x%x", icmp_code);
386 else if (icmp_type == ICMP_TIME_EXCEEDED)
390 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 391 _ (EXC_TTL,
"time-to-live zero in transit");
392 _ (EXC_FRAGTIME,
"time-to-live zero during reassembly");
395 s =
format (s,
"unknown code 0x%x", icmp_code);
410 u8 * p = va_arg (*args,
u8 *);
411 struct iphdr * ip = (
void *) p;
412 icmp4_t * icmp = (
void *) (ip + 1);
413 s =
format (s,
"icmp %U %U -> %U",
425 if (tos & IPTOS_LOWDELAY)
426 s =
format (s,
"minimize-delay, ");
427 if (tos & IPTOS_MINCOST)
428 s =
format (s,
"minimize-cost, ");
429 if (tos & IPTOS_THROUGHPUT)
430 s =
format (s,
"maximize-throughput, ");
431 if (tos & IPTOS_RELIABILITY)
432 s =
format (s,
"maximize-reliability, ");
434 switch (IPTOS_PREC (tos))
436 #define _(x,y) case IPTOS_PREC_##x: s = format (s, y); break 437 _ (NETCONTROL,
"network");
438 _ (INTERNETCONTROL,
"internet");
439 _ (CRITIC_ECP,
"critical");
441 _ (FLASHOVERRIDE,
"flash-override");
442 _ (IMMEDIATE,
"immediate");
443 _ (PRIORITY,
"priority");
444 _ (ROUTINE,
"routine");
453 u8 * p = va_arg (*args,
u8 *);
454 struct iphdr * ip = (
void *) p;
458 if (! f[IPPROTO_TCP])
466 return format (s,
"%U", f[ip->protocol], p);
468 s =
format (s,
"%U: %U -> %U",
476 #define foreach_unix_arphrd_type \ 526 _ (IEEE802_TR, 800) \ 528 _ (IEEE80211_PRISM, 802) \ 529 _ (IEEE80211_RADIOTAP, 803) \ 536 u32 x = va_arg (*args,
u32);
540 #define _(f,n) case ARPHRD_##f: t = #f; break; 551 s =
format (s,
"unknown 0x%x", x);
556 #define foreach_unix_interface_flag \ 585 u32 x = va_arg (*args,
u32);
594 s =
format (s,
"unknown %d", i);
616 char * op =
"unknown";
618 if (a->
ar_pro != ETH_P_IP ||
619 a->
ar_hrd != ARPHRD_ETHER)
624 #define _(f) case ARPOP_##f: op = #f; break; 632 s =
format (s,
"%s %U %U -> %U %U",
648 case 0: t =
"BPDU";
break;
649 #define _(f) case ETH_P_##f: t = #f; break; 676 #ifdef ETH_P_PPP_DISC 707 s =
format (s,
"ether-type 0x%x", type);
713 struct ethhdr *
h = va_arg (*args,
struct ethhdr *);
714 uword proto = h->h_proto;
715 u8 * payload = (
void *) (h + 1);
719 if (proto < ETH_DATA_LEN)
722 u8 dsap, ssap, control;
726 ethhdr_802_t * h1 = (
void *) (h + 1);
728 payload = (
void *) (h1 + 1);
733 s =
format (s,
"%U: %U -> %U",
755 if (gethostname (b,
sizeof (buffer)) < 0)
757 return format (s,
"%s", b);
764 char * fmt = va_arg (*args,
char *);
765 struct timeval * tv = va_arg (*args,
struct timeval *);
771 fmt =
"y/m/d H:M:S:F";
775 static struct timeval now;
776 gettimeofday (&now, 0);
782 { msec = 0; tv->tv_sec++; }
785 time_t t = tv->tv_sec;
789 for (f = fmt; *f; f++)
792 char * what_fmt =
"%d";
801 what = 1900 + tm->tm_year;
805 what = tm->tm_mon + 1;
830 s =
format (s, what_fmt, what);
838 u8 * fmt = va_arg (*args,
u8 *);
839 f64 t = va_arg (*args,
f64);
844 tv.tv_usec = 1e6*(t - tv.tv_sec);
854 #define _(x) case x: t = #x; break; 892 return format (s,
"unknown %d", signum);
901 ucontext_t * uc __attribute__((unused));
902 unsigned long * regs = 0;
905 uc = va_arg (*args, ucontext_t *);
907 #if defined (powerpc) 908 regs = &uc->uc_mcontext.uc_regs->gregs[0];
909 #elif defined (powerpc64) 910 regs = &uc->uc_mcontext.uc_regs->gp_regs[0];
911 #elif defined (i386) || defined (__x86_64__) 912 regs = (
void *) &uc->uc_mcontext.gregs[0];
915 #
if defined (powerpc) || defined (powerpc64)
919 #elif defined (__x86_64__) 927 return format (s,
"unsupported");
929 return format (s,
"%p", regs[reg_no]);
935 gid_t *gid = va_arg (*args, gid_t *);
936 struct group *grp = 0;
944 else if (
unformat (input,
"%s", &s))
946 grp = getgrnam ((
char *) s);
957 #define MAX_NUMNODES 16 965 uword n_pages = size / page_size;
967 uword pages_not_mapped = 0;
968 uword pages_unknown = 0;
973 s =
format (s,
"virtual memory start 0x%llx, size %lluk, %u pages, " 974 "page size %uk", va, size / 1024, n_pages, page_size / 1024);
979 for (i = 0; i < n_pages; i++)
982 if (
move_pages (0, n_pages, ptr, 0, status, 0) != 0)
984 s =
format (s,
"\n%Upage information not available (errno %u)",
989 for (i = 0; i < n_pages; i++)
992 pages_per_numa[status[
i]]++;
993 else if (status[i] == -EFAULT)
1000 if (pages_per_numa[i])
1002 indent + 2, i, pages_per_numa[i], pages_per_numa[i] *
1006 indent + 2, pages_not_mapped, pages_not_mapped *
1011 indent + 2, pages_unknown, pages_unknown * page_size / 1024);
#define vec_validate(V, I)
Make sure vector is long enough for given index (no header, unspecified alignment) ...
#define clib_error(format, args...)
#define vec_add1(V, E)
Add 1 element to end of vector (unspecified alignment).
#define foreach_set_bit(var, mask, body)
#define vec_add(V, E, N)
Add N elements to end of vector V (no header, unspecified alignment)
static f64 unix_time_now(void)
#define vec_free(V)
Free vector's memory (no header).
#define uword_to_pointer(u, type)
static word flt_round_nearest(f64 x)
static long move_pages(int pid, unsigned long count, void **pages, const int *nodes, int *status, int flags)
uword clib_mem_get_page_size(void)