40 # include <linux/unistd.h> 41 # include <linux/signal.h> 54 #include <sys/socket.h> 61 #include <linux/types.h> 62 #include <linux/netlink.h> 69 # include <linux/socket.h> 70 # include <linux/in.h> 71 # include <linux/ip.h> 72 # include <linux/tcp.h> 73 # include <linux/udp.h> 74 # include <linux/icmp.h> 75 # include <linux/if_ether.h> 76 # include <linux/if_arp.h> 79 # include <netinet/in.h> 80 # include <netinet/ip.h> 81 # include <netinet/tcp.h> 82 # include <netinet/udp.h> 83 # include <netinet/ip_icmp.h> 84 # include <netinet/if_ether.h> 95 u8 * t = (
u8 *)
"UNKNOWN";
98 #define _(x) case PF_##x: t = (u8 *) #x; break 164 vec_add (s, t, strlen ((
char *) t));
174 struct protoent * p = getprotobynumber (protocol);
176 ASSERT (family == AF_INET);
178 return format (s,
"%s", p->p_name);
180 return format (s,
"%d", protocol);
182 return format (s,
"%d/%d", family, protocol);
192 struct servent * p = getservbyport (port, proto == IPPROTO_UDP ?
"udp" :
"tcp");
195 return format (s,
"%s", p->s_name);
197 return format (s,
"%d", port);
199 return format (s,
"%s/%d", proto == IPPROTO_UDP ?
"udp" :
"tcp", port);
213 s =
format (s,
"%d.%d.%d.%d", addr[0], addr[1], addr[2], addr[3]);
218 s =
format (s,
"%02x:%02x:%02x:%02x:%02x:%02x",
219 addr[0], addr[1], addr[2], addr[3], addr[4], addr[5]);
223 clib_error (
"unsupported address family %d", family);
231 void *
v = va_arg (*args,
void *);
232 struct sockaddr * sa =
v;
234 switch (sa->sa_family)
238 struct sockaddr_in *
i =
v;
249 struct sockaddr_nl * n =
v;
250 s =
format (s,
"KERNEL-NETLINK");
252 s =
format (s,
" (groups 0x%x)", n->nl_groups);
259 s =
format (s,
"sockaddr family %d", sa->sa_family);
268 u8 * p = va_arg (*args,
u8 *);
269 struct iphdr * ip = (
void *) p;
270 struct tcphdr * tcp = (
void *) (ip + 1);
272 s =
format (s,
"tcp %U:%U -> %U:%U",
278 s =
format (s,
", seq 0x%08x -> 0x%08x", tcp->seq, tcp->ack_seq);
279 #define _(f) if (tcp->f) s = format (s, ", " #f); 280 _ (syn); _ (ack); _ (fin); _ (rst); _ (psh); _ (urg);
284 s =
format (s,
", window 0x%04x", tcp->window);
286 s =
format (s,
", urg 0x%04x", tcp->urg_ptr);
293 u8 * p = va_arg (*args,
u8 *);
294 struct iphdr * ip = (
void *) p;
295 struct udphdr * udp = (
void *) (ip + 1);
297 s =
format (s,
"udp %U:%U -> %U:%U",
313 #define _(f,str) case ICMP_##f: s = format (s, str); break; 314 _ (ECHOREPLY,
"echo reply");
315 _ (DEST_UNREACH,
"unreachable");
316 _ (SOURCE_QUENCH,
"source quench");
317 _ (REDIRECT,
"redirect");
318 _ (ECHO,
"echo request");
319 _ (TIME_EXCEEDED,
"time exceeded");
320 _ (PARAMETERPROB,
"parameter problem");
321 _ (TIMESTAMP,
"timestamp request");
322 _ (TIMESTAMPREPLY,
"timestamp reply");
323 _ (INFO_REQUEST,
"information request");
324 _ (INFO_REPLY,
"information reply");
325 _ (ADDRESS,
"address mask request");
326 _ (ADDRESSREPLY,
"address mask reply");
329 s =
format (s,
"unknown type 0x%x", icmp_type);
332 if (icmp_type == ICMP_DEST_UNREACH)
336 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 337 _ (NET_UNREACH,
"network");
338 _ (HOST_UNREACH,
"host");
339 _ (PROT_UNREACH,
"protocol");
340 _ (PORT_UNREACH,
"port");
341 _ (FRAG_NEEDED,
": fragmentation needed/DF set");
342 _ (SR_FAILED,
"source route failed");
343 _ (NET_UNKNOWN,
"network unknown");
344 _ (HOST_UNKNOWN,
"host unknown");
345 _ (HOST_ISOLATED,
"host isolated");
346 _ (NET_ANO,
"network: admin. prohibited");
347 _ (HOST_ANO,
"host: admin. prohibited");
348 _ (NET_UNR_TOS,
"network for type-of-service");
349 _ (HOST_UNR_TOS,
"host for type-of-service");
350 _ (PKT_FILTERED,
": packet filtered");
351 _ (PREC_VIOLATION,
"precedence violation");
352 _ (PREC_CUTOFF,
"precedence cut off");
355 s =
format (s,
"unknown code 0x%x", icmp_code);
358 else if (icmp_type == ICMP_REDIRECT)
362 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 363 _ (REDIR_NET,
"network");
364 _ (REDIR_HOST,
"host");
365 _ (REDIR_NETTOS,
"network for type-of-service");
366 _ (REDIR_HOSTTOS,
"host for type-of-service");
369 s =
format (s,
"unknown code 0x%x", icmp_code);
372 else if (icmp_type == ICMP_TIME_EXCEEDED)
376 #define _(f,str) case ICMP_##f: s = format (s, " " # str); break; 377 _ (EXC_TTL,
"time-to-live zero in transit");
378 _ (EXC_FRAGTIME,
"time-to-live zero during reassembly");
381 s =
format (s,
"unknown code 0x%x", icmp_code);
396 u8 * p = va_arg (*args,
u8 *);
397 struct iphdr * ip = (
void *) p;
398 icmp4_t * icmp = (
void *) (ip + 1);
399 s =
format (s,
"icmp %U %U -> %U",
411 if (tos & IPTOS_LOWDELAY)
412 s =
format (s,
"minimize-delay, ");
413 if (tos & IPTOS_MINCOST)
414 s =
format (s,
"minimize-cost, ");
415 if (tos & IPTOS_THROUGHPUT)
416 s =
format (s,
"maximize-throughput, ");
417 if (tos & IPTOS_RELIABILITY)
418 s =
format (s,
"maximize-reliability, ");
420 switch (IPTOS_PREC (tos))
422 #define _(x,y) case IPTOS_PREC_##x: s = format (s, y); break 423 _ (NETCONTROL,
"network");
424 _ (INTERNETCONTROL,
"internet");
425 _ (CRITIC_ECP,
"critical");
427 _ (FLASHOVERRIDE,
"flash-override");
428 _ (IMMEDIATE,
"immediate");
429 _ (PRIORITY,
"priority");
430 _ (ROUTINE,
"routine");
439 u8 * p = va_arg (*args,
u8 *);
440 struct iphdr * ip = (
void *) p;
444 if (! f[IPPROTO_TCP])
452 return format (s,
"%U", f[ip->protocol], p);
454 s =
format (s,
"%U: %U -> %U",
462 #define foreach_unix_arphrd_type \ 512 _ (IEEE802_TR, 800) \ 514 _ (IEEE80211_PRISM, 802) \ 515 _ (IEEE80211_RADIOTAP, 803) \ 522 u32 x = va_arg (*args,
u32);
526 #define _(f,n) case ARPHRD_##f: t = #f; break; 537 s =
format (s,
"unknown 0x%x", x);
542 #define foreach_unix_interface_flag \ 571 u32 x = va_arg (*args,
u32);
580 s =
format (s,
"unknown %d", i);
602 char * op =
"unknown";
604 if (a->
ar_pro != ETH_P_IP ||
605 a->
ar_hrd != ARPHRD_ETHER)
610 #define _(f) case ARPOP_##f: op = #f; break; 618 s =
format (s,
"%s %U %U -> %U %U",
634 case 0: t =
"BPDU";
break;
635 #define _(f) case ETH_P_##f: t = #f; break; 662 #ifdef ETH_P_PPP_DISC 693 s =
format (s,
"ether-type 0x%x", type);
699 struct ethhdr * h = va_arg (*args,
struct ethhdr *);
700 uword proto = h->h_proto;
701 u8 * payload = (
void *) (h + 1);
705 if (proto < ETH_DATA_LEN)
708 u8 dsap, ssap, control;
712 ethhdr_802_t * h1 = (
void *) (h + 1);
714 payload = (
void *) (h1 + 1);
719 s =
format (s,
"%U: %U -> %U",
741 if (gethostname (b,
sizeof (buffer)) < 0)
743 return format (s,
"%s", b);
750 char * fmt = va_arg (*args,
char *);
751 struct timeval * tv = va_arg (*args,
struct timeval *);
757 fmt =
"y/m/d H:M:S:F";
761 static struct timeval now;
762 gettimeofday (&now, 0);
768 { msec = 0; tv->tv_sec++; }
771 time_t t = tv->tv_sec;
775 for (f = fmt; *f; f++)
778 char * what_fmt =
"%d";
787 what = 1900 + tm->tm_year;
791 what = tm->tm_mon + 1;
816 s =
format (s, what_fmt, what);
824 u8 * fmt = va_arg (*args,
u8 *);
825 f64 t = va_arg (*args,
f64);
830 tv.tv_usec = 1e6*(t - tv.tv_sec);
840 #define _(x) case x: t = #x; break; 878 return format (s,
"unknown %d", signum);
887 ucontext_t * uc __attribute__((unused));
888 unsigned long * regs = 0;
891 uc = va_arg (*args, ucontext_t *);
893 #if defined (powerpc) 894 regs = &uc->uc_mcontext.uc_regs->gregs[0];
895 #elif defined (powerpc64) 896 regs = &uc->uc_mcontext.uc_regs->gp_regs[0];
897 #elif defined (i386) || defined (__x86_64__) 898 regs = (
void *) &uc->uc_mcontext.gregs[0];
901 #
if defined (powerpc) || defined (powerpc64)
905 #elif defined (__x86_64__) 913 return format (s,
"unsupported");
915 return format (s,
"%p", regs[reg_no]);
sll srl srl sll sra u16x4 i
bad routing header type(not 4)") sr_error (NO_MORE_SEGMENTS
#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)
static word flt_round_nearest(f64 x)