Exemple #1
0
static void sock_fmt(int fd, char* buf, int* buf_n, int buf_len)
{
  struct sockaddr_in sa;
  socklen_t sa_len;
  int type;
  bprintf("socket[");
  sa_len = sizeof(type);
  CI_TRY(ci_sys_getsockopt(fd, SOL_SOCKET, SO_TYPE, &type, &sa_len));
  sa_len = sizeof(sa);
  if( ci_sys_getsockname(fd, (struct sockaddr*) &sa, &sa_len) == 0 ) {
    switch( sa.sin_family ) {
    case AF_INET:
      bprintf("%s,"CI_IP_PRINTF_FORMAT":%u", type_to_proto(type),
              CI_IP_PRINTF_ARGS(&sa.sin_addr.s_addr),
              CI_BSWAP_BE16(sa.sin_port));
      break;
    case AF_UNIX:
      bprintf("UNIX,%s", type_to_string(type));
      break;
    default:
      bprintf("%d,%s", sa.sin_family, type_to_string(type));
      break;
    }
    sa_len = sizeof(sa);
    if( sa.sin_family == AF_INET &&
        ci_sys_getpeername(fd, (struct sockaddr*) &sa, &sa_len) == 0 )
      bprintf(","CI_IP_PRINTF_FORMAT":%u",
              CI_IP_PRINTF_ARGS(&sa.sin_addr.s_addr),
              CI_BSWAP_BE16(sa.sin_port));
  }
  bprintf("]");
}
Exemple #2
0
void ci_netif_filter_dump(ci_netif* ni)
{
  int id;
  unsigned i;
  ci_netif_filter_table* tbl;

  ci_assert(ni);
  tbl = ni->filter_table;

  log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
#if CI_CFG_STATS_NETIF
  log(FN_FMT "size=%d n_entries=%i n_slots=%i max=%i mean=%i", FN_PRI_ARGS(ni),
      tbl->table_size_mask + 1, ni->state->stats.table_n_entries,
      ni->state->stats.table_n_slots, ni->state->stats.table_max_hops,
      ni->state->stats.table_mean_hops);
#endif

  for( i = 0; i <= tbl->table_size_mask; ++i ) {
    id = tbl->table[i].id;
    if( CI_LIKELY(id >= 0) ) {
      ci_sock_cmn* s = ID_TO_SOCK(ni, id);
      unsigned laddr = tbl->table[i].laddr;
      int lport = sock_lport_be16(s);
      unsigned raddr = sock_raddr_be32(s);
      int rport = sock_rport_be16(s);
      int protocol = sock_protocol(s);
      unsigned hash1 = tcp_hash1(tbl, laddr, lport, raddr, rport, protocol);
      unsigned hash2 = tcp_hash2(tbl, laddr, lport, raddr, rport, protocol);
      log("%010d id=%-10d rt_ct=%d %s "CI_IP_PRINTF_FORMAT":%d "
          CI_IP_PRINTF_FORMAT":%d %010d:%010d",
	  i, id, tbl->table[i].route_count, CI_IP_PROTOCOL_STR(protocol),
          CI_IP_PRINTF_ARGS(&laddr), CI_BSWAP_BE16(lport),
	  CI_IP_PRINTF_ARGS(&raddr), CI_BSWAP_BE16(rport), hash1, hash2);
    }
  }
  log("++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++");
}