41 # include <linux/unistd.h> 42 # include <linux/signal.h> 61 #include <sys/socket.h> 70 #include <linux/types.h> 71 #include <linux/netlink.h> 79 # include <linux/socket.h> 80 # include <linux/in.h> 81 # include <linux/ip.h> 82 # include <linux/tcp.h> 83 # include <linux/udp.h> 84 # include <linux/icmp.h> 85 # include <linux/if_ether.h> 86 # include <linux/if_arp.h> 89 # include <netinet/in.h> 90 # include <netinet/ip.h> 91 # include <netinet/tcp.h> 92 # include <netinet/udp.h> 93 # include <netinet/ip_icmp.h> 94 # include <netinet/if_ether.h> 105 u8 * t = (
u8 *)
"UNKNOWN";
108 #define _(x) case PF_##x: t = (u8 *) #x; break 174 vec_add (s, t, strlen ((
char *) t));
184 struct protoent * p = getprotobynumber (protocol);
186 ASSERT (family == AF_INET);
188 return format (s,
"%s", p->p_name);
190 return format (s,
"%d", protocol);
192 return format (s,
"%d/%d", family, protocol);
202 struct servent * p = getservbyport (port, proto == IPPROTO_UDP ?
"udp" :
"tcp");
205 return format (s,
"%s", p->s_name);
207 return format (s,
"%d", port);
209 return format (s,
"%s/%d", proto == IPPROTO_UDP ?
"udp" :
"tcp", port);
223 s =
format (s,
"%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
228 s =
format (s,
"%02x:%02x:%02x:%02x:%02x:%02x",
229 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
233 clib_error (
"unsupported address family %d", family);
241 void * v = va_arg (*args,
void *);
242 struct sockaddr * sa = v;
243 static u32 local_counter;
245 switch (sa->sa_family)
249 struct sockaddr_in *
i = v;
263 s =
format (s,
"local:%u", local_counter++);
271 struct sockaddr_nl * n = v;
272 s =
format (s,
"KERNEL-NETLINK");
274 s =
format (s,
" (groups 0x%x)", n->nl_groups);
281 s =
format (s,
"sockaddr family %d", sa->sa_family);
291 u8 * p = va_arg (*args,
u8 *);
292 struct iphdr *
ip = (
void *) p;
293 struct tcphdr * tcp = (
void *) (ip + 1);
295 s =
format (s,
"tcp %U:%U -> %U:%U",
301 s =
format (s,
", seq 0x%08x -> 0x%08x", tcp->seq, tcp->ack_seq);
302 #define _(f) if (tcp->f) s = format (s, ", " #f); 303 _ (syn); _ (ack); _ (fin); _ (rst); _ (psh); _ (urg);
307 s =
format (s,
", window 0x%04x", tcp->window);
309 s =
format (s,
", urg 0x%04x", tcp->urg_ptr);
316 u8 * p = va_arg (*args,
u8 *);
317 struct iphdr *
ip = (
void *) p;
318 struct udphdr * udp = (
void *) (ip + 1);
320 s =
format (s,
"udp %U:%U -> %U:%U",
336 #define _(f,str) case ICMP_##f: s = format (s, str); break; 337 _ (ECHOREPLY,
"echo reply");
338 _ (DEST_UNREACH,
"unreachable");
339 _ (SOURCE_QUENCH,
"source quench");
340 _ (REDIRECT,
"redirect");
341 _ (ECHO,
"echo request");
342 _ (TIME_EXCEEDED,
"time exceeded");
343 _ (PARAMETERPROB,
"parameter problem");
344 _ (TIMESTAMP,
"timestamp request");
345 _ (TIMESTAMPREPLY,
"timestamp reply");
346 _ (INFO_REQUEST,
"information request");
347 _ (INFO_REPLY,
"information reply");
348 _ (ADDRESS,
"address mask request");
349 _ (ADDRESSREPLY,
"address mask reply");
352 s =
format (s,
"unknown type 0x%x", icmp_type);
355 if (icmp_type == ICMP_DEST_UNREACH)
359 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 360 _ (NET_UNREACH,
"network");
361 _ (HOST_UNREACH,
"host");
362 _ (PROT_UNREACH,
"protocol");
363 _ (PORT_UNREACH,
"port");
364 _ (FRAG_NEEDED,
": fragmentation needed/DF set");
365 _ (SR_FAILED,
"source route failed");
366 _ (NET_UNKNOWN,
"network unknown");
367 _ (HOST_UNKNOWN,
"host unknown");
368 _ (HOST_ISOLATED,
"host isolated");
369 _ (NET_ANO,
"network: admin. prohibited");
370 _ (HOST_ANO,
"host: admin. prohibited");
371 _ (NET_UNR_TOS,
"network for type-of-service");
372 _ (HOST_UNR_TOS,
"host for type-of-service");
373 _ (PKT_FILTERED,
": packet filtered");
374 _ (PREC_VIOLATION,
"precedence violation");
375 _ (PREC_CUTOFF,
"precedence cut off");
378 s =
format (s,
"unknown code 0x%x", icmp_code);
381 else if (icmp_type == ICMP_REDIRECT)
385 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 386 _ (REDIR_NET,
"network");
387 _ (REDIR_HOST,
"host");
388 _ (REDIR_NETTOS,
"network for type-of-service");
389 _ (REDIR_HOSTTOS,
"host for type-of-service");
392 s =
format (s,
"unknown code 0x%x", icmp_code);
395 else if (icmp_type == ICMP_TIME_EXCEEDED)
399 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 400 _ (EXC_TTL,
"time-to-live zero in transit");
401 _ (EXC_FRAGTIME,
"time-to-live zero during reassembly");
404 s =
format (s,
"unknown code 0x%x", icmp_code);
419 u8 * p = va_arg (*args,
u8 *);
420 struct iphdr *
ip = (
void *) p;
422 s =
format (s,
"icmp %U %U -> %U",
434 if (tos & IPTOS_LOWDELAY)
435 s =
format (s,
"minimize-delay, ");
436 if (tos & IPTOS_MINCOST)
437 s =
format (s,
"minimize-cost, ");
438 if (tos & IPTOS_THROUGHPUT)
439 s =
format (s,
"maximize-throughput, ");
440 if (tos & IPTOS_RELIABILITY)
441 s =
format (s,
"maximize-reliability, ");
443 switch (IPTOS_PREC (tos))
445 #define _(x,y) case IPTOS_PREC_##x: s = format (s, y); break 446 _ (NETCONTROL,
"network");
447 _ (INTERNETCONTROL,
"internet");
448 _ (CRITIC_ECP,
"critical");
450 _ (FLASHOVERRIDE,
"flash-override");
451 _ (IMMEDIATE,
"immediate");
452 _ (PRIORITY,
"priority");
453 _ (ROUTINE,
"routine");
462 u8 * p = va_arg (*args,
u8 *);
463 struct iphdr *
ip = (
void *) p;
467 if (! f[IPPROTO_TCP])
475 return format (s,
"%U", f[ip->protocol], p);
477 s =
format (s,
"%U: %U -> %U",
485 #define foreach_unix_arphrd_type \ 535 _ (IEEE802_TR, 800) \ 537 _ (IEEE80211_PRISM, 802) \ 538 _ (IEEE80211_RADIOTAP, 803) \ 545 u32 x = va_arg (*args,
u32);
549 #define _(f,n) case ARPHRD_##f: t = #f; break; 560 s =
format (s,
"unknown 0x%x", x);
565 #define foreach_unix_interface_flag \ 594 u32 x = va_arg (*args,
u32);
603 s =
format (s,
"unknown %d", i);
625 char * op =
"unknown";
627 if (a->
ar_pro != ETH_P_IP ||
628 a->
ar_hrd != ARPHRD_ETHER)
633 #define _(f) case ARPOP_##f: op = #f; break; 641 s =
format (s,
"%s %U %U -> %U %U",
657 case 0: t =
"BPDU";
break;
658 #define _(f) case ETH_P_##f: t = #f; break; 685 #ifdef ETH_P_PPP_DISC 716 s =
format (s,
"ether-type 0x%x", type);
722 struct ethhdr *
h = va_arg (*args,
struct ethhdr *);
724 u8 * payload = (
void *) (h + 1);
728 if (proto < ETH_DATA_LEN)
731 u8 dsap, ssap, control;
735 ethhdr_802_t * h1 = (
void *) (h + 1);
737 payload = (
void *) (h1 + 1);
742 s =
format (s,
"%U: %U -> %U",
764 if (gethostname (b,
sizeof (buffer)) < 0)
766 return format (s,
"%s", b);
773 char *
fmt = va_arg (*args,
char *);
774 struct timeval * tv = va_arg (*args,
struct timeval *);
780 fmt =
"y/m/d H:M:S:F";
784 static struct timeval now;
785 gettimeofday (&now, 0);
791 { msec = 0; tv->tv_sec++; }
794 time_t t = tv->tv_sec;
798 for (f = fmt; *f; f++)
801 char * what_fmt =
"%d";
810 what = 1900 + tm->tm_year;
814 what = tm->tm_mon + 1;
839 s =
format (s, what_fmt, what);
848 u8 *
fmt = va_arg (*args,
u8 *);
849 f64 t = va_arg (*args,
f64);
854 tv.tv_usec = 1e6*(t - tv.tv_sec);
864 #define _(x) case x: t = #x; break; 902 return format (s,
"unknown %d", signum);
911 ucontext_t * uc __attribute__((unused));
912 unsigned long *
regs = 0;
915 uc = va_arg (*args, ucontext_t *);
917 #if defined (powerpc) 918 regs = &uc->uc_mcontext.uc_regs->gregs[0];
919 #elif defined (powerpc64) 920 regs = &uc->uc_mcontext.uc_regs->gp_regs[0];
921 #elif defined (i386) || defined (__x86_64__) 922 regs = (
void *) &uc->uc_mcontext.gregs[0];
925 #
if defined (powerpc) || defined (powerpc64)
929 #elif defined (__x86_64__) 937 return format (s,
"unsupported");
939 return format (s,
"%p", regs[reg_no]);
945 gid_t *gid = va_arg (*args, gid_t *);
946 struct group *grp = 0;
954 else if (
unformat (input,
"%s", &s))
956 grp = getgrnam ((
char *) s);
#define clib_error(format, args...)
vl_api_ip_proto_t protocol
#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 vnet_feature_upd_registration_t * regs
description fragment has unexpected format
static f64 unix_time_now(void)
vl_api_fib_path_type_t type
sll srl srl sll sra u16x4 i
#define vec_free(V)
Free vector's memory (no header).
static word flt_round_nearest(f64 x)