Exemplo n.º 1
0
static void warts_trace_hop_params(const scamper_trace_t *trace,
				   const scamper_trace_hop_t *hop,
				   warts_addrtable_t *table, uint8_t *flags,
				   uint16_t *flags_len, uint16_t *params_len)
{
  scamper_icmpext_t *ie;
  const warts_var_t *var;
  int i, max_id = 0;

  /* unset all the flags possible */
  memset(flags, 0, hop_vars_mfb);
  *params_len = 0;

  for(i=0; i<sizeof(hop_vars)/sizeof(warts_var_t); i++)
    {
      var = &hop_vars[i];

      /* not used any more */
      if(var->id == WARTS_TRACE_HOP_ADDR_GID)
	continue;

      if(var->id == WARTS_TRACE_HOP_ADDR)
	{
	  if(hop->hop_addr == NULL)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_TCP_FLAGS)
	{
	  if(SCAMPER_TRACE_HOP_IS_TCP(hop) == 0)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_ICMP_TC)
	{
	  if(SCAMPER_TRACE_HOP_IS_ICMP(hop) == 0)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_Q_IPLEN)
	{
	  if(SCAMPER_TRACE_HOP_IS_ICMP_Q(hop) == 0)
	    continue;
	  if(hop->hop_icmp_q_ipl == trace->probe_size)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_Q_IPTTL)
	{
	  if(SCAMPER_TRACE_HOP_IS_ICMP_Q(hop) == 0)
	    continue;
	  if(hop->hop_icmp_q_ttl == 1)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_Q_IPTOS)
	{
	  if(SCAMPER_TRACE_HOP_IS_ICMP_Q(hop) == 0)
	    continue;
	  if(hop->hop_addr->type != SCAMPER_ADDR_TYPE_IPV4)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_NHMTU)
	{
	  if(SCAMPER_TRACE_HOP_IS_ICMP_PTB(hop) == 0)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_ICMPEXT)
	{
	  if(hop->hop_icmpext == NULL)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_REPLY_IPID)
	{
	  if(hop->hop_reply_ipid == 0)
	    continue;
	}
      else if(var->id == WARTS_TRACE_HOP_TX)
	{
	  if(hop->hop_tx.tv_sec == 0)
	    continue;
	}

      flag_set(flags, var->id, &max_id);

      if(var->id == WARTS_TRACE_HOP_ADDR)
	{
	  *params_len += warts_addr_size(table, hop->hop_addr);
	}
      else if(var->id == WARTS_TRACE_HOP_ICMPEXT)
	{
	  *params_len += 2;
	  for(ie = hop->hop_icmpext; ie != NULL; ie = ie->ie_next)
	    *params_len += (2 + 1 + 1 + ie->ie_dl);
	}
      else
	{
	  assert(var->size >= 0);
	  *params_len += var->size;
	}
    }

  *flags_len = fold_flags(flags, max_id);
  return;
}
static char *hop_tostr(const scamper_trace_t *trace,
                       scamper_trace_hop_t *hop) {

  char buf[512], tmp[128];
  size_t off = 0;

  string_concat(buf, sizeof(buf), &off, "SCAMPER.%s", SCAMPER_VERSION);

  /* by DEFAULT 0; but can be changed using -U, perhaps a SK unit id */
  string_concat(buf, sizeof(buf), &off, ";%u", trace->userid);
  string_concat(buf, sizeof(buf), &off, ";%u", trace->start.tv_sec);

  /*strftime(tmp, sizeof(tmp), "%Y-%m-%d %H:%M:%S", localtime(&tt));*/
  /*string_concat(buf, sizeof(buf), &off,*/
		/*", \"start\":{\"sec\":%u, \"usec\":%u, \"ftime\":\"%s\"}",*/
		/*trace->start.tv_sec, trace->start.tv_usec, tmp);*/

  string_concat(buf, sizeof(buf), &off, ";%s", scamper_addr_tostr(trace->src,
        tmp, sizeof(tmp)));

  string_concat(buf, sizeof(buf), &off, ";%s", scamper_addr_tostr(trace->dst,
        tmp, sizeof(tmp)));

  const char *ptr;
  if((ptr = scamper_trace_type_tostr(trace)) != NULL)
    string_concat(buf, sizeof(buf), &off, ";%s", ptr);
  else
    string_concat(buf, sizeof(buf), &off, ";%u", trace->type);

  /*if(SCAMPER_TRACE_TYPE_IS_UDP(trace) || SCAMPER_TRACE_TYPE_IS_TCP(trace))*/
    /*string_concat(buf, sizeof(buf), &off, ";%u;%u", trace->sport,*/
        /*trace->dport);*/
  /*else if(trace->flags & SCAMPER_TRACE_FLAG_ICMPCSUMDP)*/
    /*string_concat(buf, sizeof(buf), &off, ";%u", trace->dport);*/

  string_concat(buf, sizeof(buf), &off, ";%s",
      stop_reason_tostr(trace->stop_reason, tmp, sizeof(tmp)));

  /*string_concat(buf, sizeof(buf), &off, "%u", trace->stop_data);*/

  string_concat(buf, sizeof(buf), &off, ";%u", hop->hop_probe_ttl);

  string_concat(buf, sizeof(buf), &off,	";%s",
      scamper_addr_tostr(hop->hop_addr, tmp, sizeof(tmp)));

  /*string_concat(buf, sizeof(buf), &off, ";%u;%u", hop->hop_probe_id,*/
      /*hop->hop_probe_size);*/

  string_concat(buf, sizeof(buf), &off, ";%s", timeval_tostr(&hop->hop_rtt,
        tmp, sizeof(tmp)));

  /*string_concat(buf, sizeof(buf), &off, ";%u;%u;%u", hop->hop_reply_ttl,*/
      /*hop->hop_reply_tos, hop->hop_reply_size);*/

  /*string_concat(buf, sizeof(buf), &off,	";%u", hop->hop_reply_ipid);*/

  if(SCAMPER_TRACE_HOP_IS_ICMP(hop)) {

    /*string_concat(buf, sizeof(buf), &off, ";%u;%u", hop->hop_icmp_type,*/
        /*hop->hop_icmp_code);*/

    if(SCAMPER_TRACE_HOP_IS_ICMP_Q(hop)) {

      /*string_concat(buf, sizeof(buf), &off, ";%u;%u", hop->hop_icmp_q_ttl,*/
          /*hop->hop_icmp_q_ipl);*/

      /*if(SCAMPER_ADDR_TYPE_IS_IPV4(hop->hop_addr))*/
        /*string_concat(buf, sizeof(buf), &off, ";%u", hop->hop_icmp_q_tos);*/
    }

    /*if(SCAMPER_TRACE_HOP_IS_ICMP_PTB(hop))*/
        /*string_concat(buf, sizeof(buf), &off, "%u", hop->hop_icmp_nhmtu);*/
  }
  else {
    /*string_concat(buf, sizeof(buf), &off, ";%u", hop->hop_tcp_flags); */
  }

  /*string_concat(buf, sizeof(buf), &off,*/
		/*", \"hop_count\":%u, \"attempts\":%u, \"hoplimit\":%u",*/
		/*trace->hop_count, trace->attempts, trace->hoplimit);*/

  /*string_concat(buf, sizeof(buf), &off,*/
		/*", \"firsthop\":%u, \"wait\":%u, \"wait_probe\":%u",*/
		/*trace->firsthop, trace->wait, trace->wait_probe);*/

  /*string_concat(buf, sizeof(buf), &off,	", \"tos\":%u, \"probe_size\":%u",*/
		/*trace->tos, trace->probe_size);*/

  string_concat(buf, sizeof(buf), &off,	"\n", NULL);
  return strdup(buf);
}