static void warts_tbit_null_params(const scamper_tbit_t *tbit, warts_tbit_null_t *state) { scamper_tbit_null_t *null = tbit->data; const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, tbit_null_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tbit_null_vars)/sizeof(warts_var_t); i++) { var = &tbit_null_vars[i]; if(var->id == WARTS_TBIT_NULL_OPTIONS && null->options == 0) continue; if(var->id == WARTS_TBIT_NULL_RESULTS && null->results == 0) continue; flag_set(state->flags, var->id, &max_id); assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); state->len = state->flags_len + state->params_len; if(state->params_len != 0) state->len += 2; return; }
static void warts_dealias_params(const scamper_dealias_t *dealias, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { int max_id = 0; memset(flags, 0, dealias_vars_mfb); *params_len = 0; flag_set(flags, WARTS_DEALIAS_LIST_ID, &max_id); *params_len += 4; flag_set(flags, WARTS_DEALIAS_CYCLE_ID, &max_id); *params_len += 4; flag_set(flags, WARTS_DEALIAS_START, &max_id); *params_len += 8; flag_set(flags, WARTS_DEALIAS_METHOD, &max_id); *params_len += 1; flag_set(flags, WARTS_DEALIAS_RESULT, &max_id); *params_len += 1; flag_set(flags, WARTS_DEALIAS_PROBEC, &max_id); *params_len += 4; if(dealias->userid != 0) { flag_set(flags, WARTS_DEALIAS_USERID, &max_id); *params_len += 4; } *flags_len = fold_flags(flags, max_id); return; }
static int warts_trace_dtree_params(const scamper_file_t *sf, const scamper_trace_t *trace, warts_addrtable_t *table, warts_trace_dtree_t *state) { scamper_trace_dtree_t *dtree = trace->dtree; const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, trace_dtree_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(trace_dtree_vars)/sizeof(warts_var_t); i++) { var = &trace_dtree_vars[i]; /* not used any more */ if(var->id == WARTS_TRACE_DTREE_LSS_STOP_GID || var->id == WARTS_TRACE_DTREE_GSS_STOP_GID) continue; if((var->id == WARTS_TRACE_DTREE_LSS_STOP && dtree->lss_stop == NULL) || (var->id == WARTS_TRACE_DTREE_LSS_NAME && dtree->lss == NULL) || (var->id == WARTS_TRACE_DTREE_GSS_STOP && dtree->gss_stop == NULL) || (var->id == WARTS_TRACE_DTREE_FLAGS && dtree->flags == 0)) continue; flag_set(state->flags, var->id, &max_id); /* variables that don't have a fixed size */ if(var->id == WARTS_TRACE_DTREE_LSS_STOP) { state->params_len += warts_addr_size(table, dtree->lss_stop); continue; } else if(var->id == WARTS_TRACE_DTREE_LSS_NAME) { state->params_len += warts_str_size(dtree->lss); continue; } else if(var->id == WARTS_TRACE_DTREE_GSS_STOP) { state->params_len += warts_addr_size(table, dtree->gss_stop); continue; } assert(var->size != -1); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); state->len = state->flags_len + state->params_len; if(state->params_len != 0) state->len += 2 ; return 0; }
static void warts_neighbourdisc_params(const scamper_neighbourdisc_t *nd, warts_addrtable_t *table, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { int i, max_id = 0; const warts_var_t *var; memset(flags, 0, neighbourdisc_vars_mfb); *params_len = 0; for(i=0; i<sizeof(neighbourdisc_vars)/sizeof(warts_var_t); i++) { var = &neighbourdisc_vars[i]; if(var->id == WARTS_NEIGHBOURDISC_LIST && nd->list == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_CYCLE && nd->cycle == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_USERID && nd->userid == 0) continue; else if(var->id == WARTS_NEIGHBOURDISC_IFNAME && nd->ifname == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_SRC_IP && nd->src_ip == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_SRC_MAC && nd->src_mac == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_DST_IP && nd->dst_ip == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_DST_MAC && nd->dst_mac == NULL) continue; else if(var->id == WARTS_NEIGHBOURDISC_PROBEC && nd->probec == 0) continue; flag_set(flags, var->id, &max_id); if(var->size < 0) { if(var->id == WARTS_NEIGHBOURDISC_SRC_IP) *params_len += warts_addr_size(table, nd->src_ip); else if(var->id == WARTS_NEIGHBOURDISC_SRC_MAC) *params_len += warts_addr_size(table, nd->src_mac); else if(var->id == WARTS_NEIGHBOURDISC_DST_IP) *params_len += warts_addr_size(table, nd->dst_ip); else if(var->id == WARTS_NEIGHBOURDISC_DST_MAC) *params_len += warts_addr_size(table, nd->dst_mac); else if(var->id == WARTS_NEIGHBOURDISC_IFNAME) *params_len += warts_str_size(nd->ifname); continue; } assert(var->size >= 0); *params_len += var->size; } *flags_len = fold_flags(flags, max_id); return; }
static void warts_trace_params(const scamper_trace_t *trace, warts_addrtable_t *table, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { int max_id = 0; const warts_var_t *var; size_t i; /* unset all the flags possible */ memset(flags, 0, trace_vars_mfb); *params_len = 0; for(i=0; i<sizeof(trace_vars)/sizeof(warts_var_t); i++) { var = &trace_vars[i]; if(var->id == WARTS_TRACE_ADDR_SRC_GID || var->id == WARTS_TRACE_ADDR_DST_GID) { continue; } if(var->id == WARTS_TRACE_USERID) { if(trace->userid == 0) continue; } if(var->id == WARTS_TRACE_OFFSET) { if(trace->offset == 0) continue; } flag_set(flags, var->id, &max_id); if(var->id == WARTS_TRACE_ADDR_SRC) { *params_len += warts_addr_size(table, trace->src); continue; } else if(var->id == WARTS_TRACE_ADDR_DST) { *params_len += warts_addr_size(table, trace->dst); continue; } assert(var->size >= 0); *params_len += var->size; } *flags_len = fold_flags(flags, max_id); return; }
static int warts_dealias_radargun_state(const scamper_file_t *sf, const void *data, warts_dealias_data_t *state, warts_addrtable_t *table, uint32_t *len) { const scamper_dealias_radargun_t *rg = data; const warts_var_t *var; int max_id = 0; size_t size; uint32_t i; if(rg->probedefc == 0) return -1; size = rg->probedefc * sizeof(warts_dealias_probedef_t); if((state->probedefs = malloc_zero(size)) == NULL) return -1; memset(state->flags, 0, dealias_radargun_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(dealias_radargun_vars)/sizeof(warts_var_t); i++) { var = &dealias_radargun_vars[i]; if(var->id == WARTS_DEALIAS_RADARGUN_FLAGS) { if(rg->flags == 0) continue; } flag_set(state->flags, var->id, &max_id); assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); for(i=0; i<rg->probedefc; i++) { if(warts_dealias_probedef_params(sf, &rg->probedefs[i], &state->probedefs[i], table, len) != 0) { return -1; } } /* increase length required for the radargun record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static void warts_tbit_params(const scamper_tbit_t *tbit, warts_addrtable_t *table, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { const warts_var_t *var; int i, max_id = 0; /* Unset all flags */ memset(flags, 0, tbit_vars_mfb); *params_len = 0; for(i=0; i<sizeof(tbit_vars)/sizeof(warts_var_t); i++) { var = &tbit_vars[i]; /* Skip the variables for which we have no data */ if(var->id == WARTS_TBIT_PKTC16) continue; else if(var->id == WARTS_TBIT_LIST && tbit->list == NULL) continue; else if(var->id == WARTS_TBIT_CYCLE && tbit->cycle == NULL) continue; else if(var->id == WARTS_TBIT_USERID && tbit->userid == 0) continue; else if(var->id == WARTS_TBIT_SRC && tbit->src == NULL) continue; else if(var->id == WARTS_TBIT_DST && tbit->dst == NULL) continue; /* Set the flag for the rest of the variables */ flag_set(flags, var->id, &max_id); /* Variables that don't have a fixed size */ if(var->id == WARTS_TBIT_SRC) { *params_len += warts_addr_size(table, tbit->src); continue; } else if(var->id == WARTS_TBIT_DST) { *params_len += warts_addr_size(table, tbit->dst); continue; } /* The rest of the variables have a fixed size */ *params_len += var->size; } *flags_len = fold_flags(flags, max_id); return; }
static int warts_tracelb_node_state(const scamper_file_t *sf, const scamper_tracelb_node_t *node, warts_addrtable_t *table, warts_tracelb_node_t *state, uint32_t *len) { const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, tracelb_node_vars_mfb); state->params_len = 0; /* for now, we include the base data items */ for(i=0; i<sizeof(tracelb_node_vars)/sizeof(warts_var_t); i++) { var = &tracelb_node_vars[i]; if(var->id == WARTS_TRACELB_NODE_ADDR_GID) { continue; } else if(var->id == WARTS_TRACELB_NODE_QTTL) { /* don't include the qttl field if it isn't used */ if(SCAMPER_TRACELB_NODE_QTTL(node) == 0) continue; } if(var->id == WARTS_TRACELB_NODE_ADDR) { if(node->addr != NULL) { flag_set(state->flags, var->id, &max_id); state->params_len += warts_addr_size(table, node->addr); } continue; } assert(var->size >= 0); flag_set(state->flags, var->id, &max_id); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_dealias_probedef_params(const scamper_file_t *sf, const scamper_dealias_probedef_t *p, warts_dealias_probedef_t *state, warts_addrtable_t *table, uint32_t *len) { int max_id = 0; memset(state->flags, 0, dealias_probedef_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_DST, &max_id); state->params_len += warts_addr_size(table, p->dst); flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_SRC, &max_id); state->params_len += warts_addr_size(table, p->src); flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_ID, &max_id); state->params_len += 4; flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_METHOD, &max_id); state->params_len += 1; flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_TTL, &max_id); state->params_len += 1; flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_TOS, &max_id); state->params_len += 1; /* always include the first 4 bytes of the IP payload */ flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_4BYTES, &max_id); state->params_len += 4; /* sometimes include icmp id/sequence number */ if(SCAMPER_DEALIAS_PROBEDEF_PROTO_IS_ICMP(p)) { flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_ICMP_ID, &max_id); state->params_len += 2; } /* sometimes include tcp flags */ if(SCAMPER_DEALIAS_PROBEDEF_PROTO_IS_TCP(p)) { flag_set(state->flags, WARTS_DEALIAS_PROBEDEF_TCP_FLAGS, &max_id); state->params_len += 1; } state->flags_len = fold_flags(state->flags, max_id); /* increase length for the probedef record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_dealias_probe_state(const scamper_file_t *sf, const scamper_dealias_probe_t *probe, warts_dealias_probe_t *state, warts_addrtable_t *table, uint32_t *len) { int i = 0; size_t size; memset(state->flags, 0, dealias_probe_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_DEALIAS_PROBE_DEF, &i); state->params_len += 4; flag_set(state->flags, WARTS_DEALIAS_PROBE_TX, &i); state->params_len += 8; flag_set(state->flags, WARTS_DEALIAS_PROBE_REPLYC, &i); state->params_len += 2; flag_set(state->flags, WARTS_DEALIAS_PROBE_IPID, &i); state->params_len += 2; flag_set(state->flags, WARTS_DEALIAS_PROBE_SEQ, &i); state->params_len += 4; state->flags_len = fold_flags(state->flags, i); state->replies = NULL; if(probe->replyc > 0) { size = sizeof(warts_dealias_reply_t) * probe->replyc; if((state->replies = malloc_zero(size)) == NULL) return -1; for(i=0; i<probe->replyc; i++) { if(warts_dealias_reply_state(probe->replies[i], &state->replies[i], sf, table, len) != 0) { free(state->replies); state->replies = NULL; return -1; } } } /* increase length required for the probe record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static void warts_trace_pmtud_n_params(const scamper_trace_pmtud_t *pmtud, const scamper_trace_pmtud_n_t *n, warts_trace_pmtud_n_t *state) { const scamper_trace_hop_t *hop; const warts_var_t *var; uint16_t u16; int i, max_id = 0; memset(state->flags, 0, pmtud_n_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(pmtud_n_vars)/sizeof(warts_var_t); i++) { var = &pmtud_n_vars[i]; if(var->id == WARTS_TRACE_PMTUD_N_TYPE) { if(n->type == 0) continue; } else if(var->id == WARTS_TRACE_PMTUD_N_NHMTU) { if(n->nhmtu == 0) continue; } else if(var->id == WARTS_TRACE_PMTUD_N_HOP) { if(n->hop == NULL) continue; u16 = 0; for(hop = pmtud->hops; hop != NULL; hop = hop->hop_next) { if(hop == n->hop) break; u16++; } assert(hop != NULL); state->hop = u16; } flag_set(state->flags, var->id, &max_id); assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); return; }
static int warts_dealias_ally_state(const scamper_file_t *sf, const void *data, warts_dealias_data_t *state, warts_addrtable_t *table, uint32_t *len) { const scamper_dealias_ally_t *ally = data; int max_id = 0; size_t size = sizeof(warts_dealias_probedef_t) * 2; if((state->probedefs = malloc_zero(size)) == NULL) return -1; memset(state->flags, 0, dealias_ally_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_DEALIAS_ALLY_WAIT_PROBE, &max_id); state->params_len += 2; flag_set(state->flags, WARTS_DEALIAS_ALLY_WAIT_TIMEOUT, &max_id); state->params_len += 1; flag_set(state->flags, WARTS_DEALIAS_ALLY_ATTEMPTS, &max_id); state->params_len += 1; flag_set(state->flags, WARTS_DEALIAS_ALLY_FUDGE, &max_id); state->params_len += 2; if(ally->flags != 0) { flag_set(state->flags, WARTS_DEALIAS_ALLY_FLAGS, &max_id); state->params_len += 1; } state->flags_len = fold_flags(state->flags, max_id); if(warts_dealias_probedef_params(sf, &ally->probedefs[0], &state->probedefs[0], table, len) != 0 || warts_dealias_probedef_params(sf, &ally->probedefs[1], &state->probedefs[1], table, len) != 0) { return -1; } /* increase length required for the ally record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_tracelb_probeset_state(const scamper_file_t *sf, const scamper_tracelb_probeset_t *set, warts_tracelb_probeset_t *state, warts_addrtable_t *table, uint32_t *len) { const warts_var_t *var; int i, max_id = 0; size_t size; state->probec = set->probec; memset(state->flags, 0, tracelb_probeset_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tracelb_probeset_vars)/sizeof(warts_var_t); i++) { var = &tracelb_probeset_vars[i]; flag_set(state->flags, var->id, &max_id); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; if(set->probec > 0) { size = sizeof(warts_tracelb_probe_t) * set->probec; if((state->probes = malloc_zero(size)) == NULL) { return -1; } for(i=0; i<set->probec; i++) { if(warts_tracelb_probe_state(sf, set->probes[i], &state->probes[i], table, len) != 0) return -1; } } return 0; }
static void warts_tbit_pmtud_params(const scamper_tbit_t *tbit, warts_addrtable_t *table, warts_tbit_pmtud_t *state) { scamper_tbit_pmtud_t *pmtud = tbit->data; const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, tbit_pmtud_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tbit_pmtud_vars)/sizeof(warts_var_t); i++) { var = &tbit_pmtud_vars[i]; if(var->id == WARTS_TBIT_PMTUD_MTU && pmtud->mtu == 0) continue; if(var->id == WARTS_TBIT_PMTUD_PTBRETX && pmtud->ptb_retx == 0) continue; if(var->id == WARTS_TBIT_PMTUD_OPTIONS && pmtud->options == 0) continue; if(var->id == WARTS_TBIT_PMTUD_PTBSRC && pmtud->ptbsrc == NULL) continue; flag_set(state->flags, var->id, &max_id); if(var->id == WARTS_TBIT_PMTUD_PTBSRC) { state->params_len += warts_addr_size(table, pmtud->ptbsrc); continue; } assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); state->len = state->flags_len + state->params_len; if(state->params_len != 0) state->len += 2; return; }
static int warts_neighbourdisc_probe_state(const scamper_file_t *sf, scamper_neighbourdisc_probe_t *probe, warts_neighbourdisc_probe_t *state, warts_addrtable_t *table, uint32_t *len) { int i = 0; size_t size; memset(state->flags, 0, neighbourdisc_probe_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_NEIGHBOURDISC_PROBE_TX, &i); state->params_len += 8; flag_set(state->flags, WARTS_NEIGHBOURDISC_PROBE_RXC, &i); state->params_len += 2; state->flags_len = fold_flags(state->flags, i); state->rxs = NULL; if(probe->rxc > 0) { size = sizeof(warts_neighbourdisc_reply_t) * probe->rxc; if((state->rxs = malloc_zero(size)) == NULL) return -1; for(i=0; i<probe->rxc; i++) { if(warts_neighbourdisc_reply_state(probe->rxs[i], &state->rxs[i], table, len) != 0) { free(state->rxs); state->rxs = NULL; return -1; } } } /* increase length required for the probe record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static void warts_trace_pmtud_params(const scamper_trace_t *trace, warts_trace_pmtud_t *state) { const scamper_trace_pmtud_t *pmtud = trace->pmtud; const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, pmtud_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(pmtud_vars)/sizeof(warts_var_t); i++) { var = &pmtud_vars[i]; if(var->id == WARTS_TRACE_PMTUD_IFMTU) { if(pmtud->ifmtu == 0) continue; } else if(var->id == WARTS_TRACE_PMTUD_PMTU) { if(pmtud->pmtu == 0) continue; } else if(var->id == WARTS_TRACE_PMTUD_OUTMTU) { if(pmtud->outmtu == 0) continue; } else if(var->id == WARTS_TRACE_PMTUD_NOTEC) { if(pmtud->notec == 0) continue; } flag_set(state->flags, var->id, &max_id); assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); return; }
static void warts_tbit_app_http_params(const scamper_tbit_t *tbit, warts_tbit_app_http_t *state) { scamper_tbit_app_http_t *http = tbit->app_data; const warts_var_t *var; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, tbit_app_http_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tbit_app_http_vars)/sizeof(warts_var_t); i++) { var = &tbit_app_http_vars[i]; if(var->id == WARTS_TBIT_APP_HTTP_HOST && http->host == NULL) continue; if(var->id == WARTS_TBIT_APP_HTTP_FILE && http->file == NULL) continue; flag_set(state->flags, var->id, &max_id); if(var->size < 0) { if(var->id == WARTS_TBIT_APP_HTTP_HOST) state->params_len += warts_str_size(http->host); else if(var->id == WARTS_TBIT_APP_HTTP_FILE) state->params_len += warts_str_size(http->file); continue; } assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); state->len = state->flags_len + state->params_len; if(state->params_len != 0) state->len += 2; return; }
static int warts_neighbourdisc_reply_state(scamper_neighbourdisc_reply_t *reply, warts_neighbourdisc_reply_t *state, warts_addrtable_t *table, uint32_t *len) { int i = 0; memset(state->flags, 0, neighbourdisc_reply_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_NEIGHBOURDISC_REPLY_RX, &i); state->params_len += 8; flag_set(state->flags, WARTS_NEIGHBOURDISC_REPLY_MAC, &i); state->params_len += warts_addr_size(table, reply->mac); state->flags_len = fold_flags(state->flags, i); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_dealias_bump_state(const scamper_file_t *sf, const void *data, warts_dealias_data_t *state, warts_addrtable_t *table, uint32_t *len) { const scamper_dealias_bump_t *bump = data; const warts_var_t *var; int i, max_id = 0; size_t size = sizeof(warts_dealias_probedef_t) * 2; if((state->probedefs = malloc_zero(size)) == NULL) return -1; memset(state->flags, 0, dealias_bump_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(dealias_bump_vars)/sizeof(warts_var_t); i++) { var = &dealias_bump_vars[i]; flag_set(state->flags, var->id, &max_id); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); if(warts_dealias_probedef_params(sf, &bump->probedefs[0], &state->probedefs[0], table, len) != 0 || warts_dealias_probedef_params(sf, &bump->probedefs[1], &state->probedefs[1], table, len) != 0) { return -1; } /* increase length required for the ally record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static void warts_tbit_pkt_params(const scamper_tbit_pkt_t *pkt, warts_tbit_pkt_t *state, uint32_t *len) { const warts_var_t *var; int max_id = 0; uint16_t i; memset(state->flags, 0, tbit_pkt_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tbit_pkt_vars) / sizeof(warts_var_t); i++) { var = &tbit_pkt_vars[i]; if(var->id == WARTS_TBIT_PKT_DATA) { if(pkt->len == 0) continue; state->params_len += pkt->len; flag_set(state->flags, var->id, &max_id); continue; } assert(var->size >= 0); state->params_len += var->size; flag_set(state->flags, var->id, &max_id); } state->flags_len = fold_flags(state->flags, max_id); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return; }
static int warts_dealias_mercator_state(const scamper_file_t *sf, const void *data, warts_dealias_data_t *state, warts_addrtable_t *table,uint32_t *len) { const scamper_dealias_mercator_t *m = data; int max_id = 0; size_t size = sizeof(warts_dealias_probedef_t); if((state->probedefs = malloc_zero(size)) == NULL) return -1; assert(sizeof(state->flags) >= dealias_mercator_vars_mfb); memset(state->flags, 0, dealias_mercator_vars_mfb); state->params_len = 0; flag_set(state->flags, WARTS_DEALIAS_MERCATOR_ATTEMPTS, &max_id); state->params_len += 1; flag_set(state->flags, WARTS_DEALIAS_MERCATOR_WAIT_TIMEOUT, &max_id); state->params_len += 1; state->flags_len = fold_flags(state->flags, max_id); if(warts_dealias_probedef_params(sf, &m->probedef, &state->probedefs[0], table, len) != 0) { return -1; } /* increase length required for the mercator record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_dealias_prefixscan_state(const scamper_file_t *sf, const void *data, warts_dealias_data_t *state, warts_addrtable_t *table, uint32_t *len) { const scamper_dealias_prefixscan_t *p = data; const warts_var_t *var; int max_id = 0; uint16_t i, j; size_t size; if(p->probedefc > 0) { size = p->probedefc * sizeof(warts_dealias_probedef_t); if((state->probedefs = malloc_zero(size)) == NULL) return -1; } memset(state->flags, 0, dealias_prefixscan_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(dealias_prefixscan_vars)/sizeof(warts_var_t); i++) { var = &dealias_prefixscan_vars[i]; if(var->id == WARTS_DEALIAS_PREFIXSCAN_A) { if(p->a != NULL) { flag_set(state->flags, var->id, &max_id); state->params_len += warts_addr_size(table, p->a); } continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_B) { if(p->b != NULL) { flag_set(state->flags, var->id, &max_id); state->params_len += warts_addr_size(table, p->b); } continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_AB) { if(p->ab != NULL) { flag_set(state->flags, var->id, &max_id); state->params_len += warts_addr_size(table, p->ab); } continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_XS) { if(p->xc > 0) { flag_set(state->flags, var->id, &max_id); state->params_len += 2; for(j=0; j<p->xc; j++) state->params_len += warts_addr_size(table, p->xs[j]); } continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_PROBEDEFC) { if(p->probedefc == 0) continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_FLAGS) { if(p->flags == 0) continue; } else if(var->id == WARTS_DEALIAS_PREFIXSCAN_REPLYC) { if(p->replyc == 5) continue; } flag_set(state->flags, var->id, &max_id); assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); for(i=0; i<p->probedefc; i++) { if(warts_dealias_probedef_params(sf, &p->probedefs[i], &state->probedefs[i], table, len) != 0) { return -1; } } *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 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 int warts_dealias_reply_state(const scamper_dealias_reply_t *reply, warts_dealias_reply_t *state, const scamper_file_t *sf, warts_addrtable_t *table, uint32_t *len) { const warts_var_t *var; scamper_icmpext_t *ie; int i, max_id = 0; memset(state->flags, 0, dealias_reply_vars_mfb); state->params_len = 0; /* encode any icmp extensions included */ if(SCAMPER_DEALIAS_REPLY_IS_ICMP(reply) && reply->icmp_ext != NULL) { flag_set(state->flags, WARTS_DEALIAS_REPLY_ICMP_EXT, &max_id); state->params_len += 2; for(ie = reply->icmp_ext; ie != NULL; ie = ie->ie_next) { state->params_len += (2 + 1 + 1 + ie->ie_dl); } } for(i=0; i<sizeof(dealias_reply_vars)/sizeof(warts_var_t); i++) { var = &dealias_reply_vars[i]; if(var->id == WARTS_DEALIAS_REPLY_SRC_GID) { continue; } else if(var->id == WARTS_DEALIAS_REPLY_ICMP_TC) { if(SCAMPER_DEALIAS_REPLY_IS_ICMP(reply) == 0) continue; } else if(var->id == WARTS_DEALIAS_REPLY_ICMP_Q_TTL) { if(SCAMPER_DEALIAS_REPLY_IS_ICMP(reply) == 0) continue; } else if(var->id == WARTS_DEALIAS_REPLY_ICMP_EXT) { continue; } else if(var->id == WARTS_DEALIAS_REPLY_PROTO) { if(SCAMPER_DEALIAS_REPLY_IS_ICMP(reply)) continue; } else if(var->id == WARTS_DEALIAS_REPLY_TCP_FLAGS) { if(SCAMPER_DEALIAS_REPLY_IS_TCP(reply) == 0) continue; } flag_set(state->flags, var->id, &max_id); if(var->id == WARTS_DEALIAS_REPLY_SRC) { state->params_len += warts_addr_size(table, reply->src); continue; } assert(var->size >= 0); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); /* increase length required for the dealias reply record */ *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }
static int warts_tracelb_link_state(const scamper_file_t *sf, const scamper_tracelb_t *trace, const scamper_tracelb_link_t *link, warts_tracelb_link_t *state, warts_addrtable_t *table, uint32_t *len) { const warts_var_t *var; size_t size; int i, j, max_id = 0; uint8_t s; state->hopc = link->hopc; /* * get the index into the nodes array for each of the nodes represented * in the link. the loop finishes when j reaches 2, i.e. both nodes have * been identified. */ for(i=0, j=0; i<trace->nodec; i++) { if(link->from == trace->nodes[i]) { state->from = i; j++; } if(link->to == trace->nodes[i]) { state->to = i; j++; } if(j == 2 || (link->to == NULL && j == 1)) break; } /* unset all the flags possible */ memset(state->flags, 0, tracelb_link_vars_mfb); state->params_len = 0; for(i=0; i<sizeof(tracelb_link_vars)/sizeof(warts_var_t); i++) { var = &tracelb_link_vars[i]; /* if the link does not include a `to' node, skip it */ if(var->id == WARTS_TRACELB_LINK_TO && link->to == NULL) continue; flag_set(state->flags, var->id, &max_id); state->params_len += var->size; } state->flags_len = fold_flags(state->flags, max_id); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; if(link->hopc > 0) { size = sizeof(warts_tracelb_probeset_t) * link->hopc; if((state->sets = malloc_zero(size)) == NULL) { return -1; } for(s=0; s<link->hopc; s++) { if(warts_tracelb_probeset_state(sf, link->sets[s], &state->sets[s], table, len) != 0) return -1; } } return 0; }
static void warts_ping_reply_params(const scamper_ping_t *ping, const scamper_ping_reply_t *reply, warts_addrtable_t *table, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { const warts_var_t *var; int i, j, max_id = 0; /* unset all the flags possible */ memset(flags, 0, ping_reply_vars_mfb); *params_len = 0; for(i=0; i<sizeof(ping_reply_vars)/sizeof(warts_var_t); i++) { var = &ping_reply_vars[i]; if(var->id == WARTS_PING_REPLY_ADDR_GID || (var->id == WARTS_PING_REPLY_ADDR && reply->addr == NULL) || (var->id == WARTS_PING_REPLY_FLAGS && reply->flags == 0) || (var->id == WARTS_PING_REPLY_REPLY_PROTO && SCAMPER_PING_METHOD_IS_ICMP(ping)) || (var->id == WARTS_PING_REPLY_REPLY_TTL && (reply->flags & SCAMPER_PING_REPLY_FLAG_REPLY_TTL) == 0) || (var->id == WARTS_PING_REPLY_REPLY_IPID && SCAMPER_ADDR_TYPE_IS_IPV4(ping->dst) && (reply->flags & SCAMPER_PING_REPLY_FLAG_REPLY_IPID) == 0) || (var->id == WARTS_PING_REPLY_REPLY_IPID32 && SCAMPER_ADDR_TYPE_IS_IPV6(ping->dst) && (reply->flags & SCAMPER_PING_REPLY_FLAG_REPLY_IPID) == 0) || (var->id == WARTS_PING_REPLY_PROBE_IPID && SCAMPER_ADDR_TYPE_IS_IPV4(ping->dst) && (reply->flags & SCAMPER_PING_REPLY_FLAG_PROBE_IPID) == 0) || (var->id == WARTS_PING_REPLY_ICMP_TC && SCAMPER_PING_REPLY_IS_ICMP(reply) == 0) || (var->id == WARTS_PING_REPLY_TCP_FLAGS && SCAMPER_PING_REPLY_IS_TCP(reply) == 0) || (var->id == WARTS_PING_REPLY_V4RR && reply->v4rr == NULL) || (var->id == WARTS_PING_REPLY_V4TS && reply->v4ts == NULL) || (var->id == WARTS_PING_REPLY_TX && reply->tx.tv_sec == 0) || (var->id == WARTS_PING_REPLY_TSREPLY && reply->tsreply == NULL)) { continue; } flag_set(flags, var->id, &max_id); if(var->id == WARTS_PING_REPLY_ADDR) { *params_len += warts_addr_size(table, reply->addr); } else if(var->id == WARTS_PING_REPLY_V4RR) { *params_len += 1; for(j=0; j<reply->v4rr->rrc; j++) *params_len += warts_addr_size(table, reply->v4rr->rr[j]); } else if(var->id == WARTS_PING_REPLY_V4TS) { assert(reply->v4ts != NULL); *params_len += 2; /* one byte tsc, one byte count of v4ts->ips */ *params_len += (reply->v4ts->tsc * 4); if(reply->v4ts->ips != NULL) for(j=0; j<reply->v4ts->tsc; j++) *params_len += warts_addr_size(table, reply->v4ts->ips[j]); } else { assert(var->size >= 0); *params_len += var->size; } } *flags_len = fold_flags(flags, max_id); return; }
static void warts_ping_params(const scamper_ping_t *ping, warts_addrtable_t *table, uint8_t *flags, uint16_t *flags_len, uint16_t *params_len) { const warts_var_t *var; int i, j, max_id = 0; /* unset all the flags possible */ memset(flags, 0, ping_vars_mfb); *params_len = 0; for(i=0; i<sizeof(ping_vars)/sizeof(warts_var_t); i++) { var = &ping_vars[i]; if(var->id == WARTS_PING_ADDR_SRC_GID || var->id == WARTS_PING_ADDR_DST_GID || (var->id == WARTS_PING_ADDR_SRC && ping->src == NULL) || (var->id == WARTS_PING_ADDR_DST && ping->dst == NULL) || (var->id == WARTS_PING_LIST_ID && ping->list == NULL) || (var->id == WARTS_PING_CYCLE_ID && ping->cycle == NULL) || (var->id == WARTS_PING_USERID && ping->userid == 0) || (var->id == WARTS_PING_DATA_LEN && ping->probe_datalen == 0) || (var->id == WARTS_PING_PROBE_METHOD && ping->probe_method == 0) || (var->id == WARTS_PING_PROBE_TOS && ping->probe_tos == 0) || (var->id == WARTS_PING_PROBE_SPORT && ping->probe_sport == 0) || (var->id == WARTS_PING_PROBE_DPORT && ping->probe_dport == 0) || (var->id == WARTS_PING_FLAGS && ping->flags == 0) || (var->id == WARTS_PING_REPLY_PMTU && ping->reply_pmtu == 0) || (var->id == WARTS_PING_PROBE_TIMEOUT && ping->probe_timeout == ping->probe_wait)) { continue; } if(var->id == WARTS_PING_PROBE_ICMPSUM) { if(ping->probe_icmpsum == 0 || (ping->flags & SCAMPER_PING_FLAG_ICMPSUM) == 0) continue; } if(var->id == WARTS_PING_DATA_BYTES) { if(ping->probe_datalen != 0) { flag_set(flags, WARTS_PING_DATA_BYTES, &max_id); *params_len += ping->probe_datalen; } continue; } if(var->id == WARTS_PING_PROBE_TSPS) { if(ping->probe_tsps != NULL) { flag_set(flags, WARTS_PING_PROBE_TSPS, &max_id); *params_len += 1; for(j=0; j<ping->probe_tsps->ipc; j++) *params_len += warts_addr_size(table,ping->probe_tsps->ips[j]); } continue; } flag_set(flags, var->id, &max_id); if(var->id == WARTS_PING_ADDR_SRC) { *params_len += warts_addr_size(table, ping->src); continue; } else if(var->id == WARTS_PING_ADDR_DST) { *params_len += warts_addr_size(table, ping->dst); continue; } assert(var->size >= 0); *params_len += var->size; } *flags_len = fold_flags(flags, max_id); return; }
static int warts_tracelb_reply_state(const scamper_file_t *sf, const scamper_tracelb_reply_t *reply, warts_tracelb_reply_t *state, warts_addrtable_t *table, uint32_t *len) { const warts_var_t *var; scamper_icmpext_t *ie; int i, max_id = 0; /* unset all the flags possible */ memset(state->flags, 0, tracelb_reply_vars_mfb); state->params_len = 0; /* figure out what to include */ for(i=0; i<sizeof(tracelb_reply_vars)/sizeof(warts_var_t); i++) { var = &tracelb_reply_vars[i]; if(var->id == WARTS_TRACELB_REPLY_FROM_GID) { continue; } else if(var->id == WARTS_TRACELB_REPLY_TTL) { if((reply->reply_flags & SCAMPER_TRACELB_REPLY_FLAG_REPLY_TTL) == 0) continue; } else if(var->id == WARTS_TRACELB_REPLY_ICMP_TC || var->id == WARTS_TRACELB_REPLY_ICMP_Q_TTL || var->id == WARTS_TRACELB_REPLY_ICMP_Q_TOS) { if((reply->reply_flags & SCAMPER_TRACELB_REPLY_FLAG_TCP) != 0) continue; } else if(var->id == WARTS_TRACELB_REPLY_TCP_FLAGS) { if((reply->reply_flags & SCAMPER_TRACELB_REPLY_FLAG_TCP) == 0) continue; } else if(var->id == WARTS_TRACELB_REPLY_ICMP_EXT) { if((reply->reply_flags & SCAMPER_TRACELB_REPLY_FLAG_TCP) != 0 || reply->reply_icmp_ext == NULL) continue; state->params_len += 2; for(ie = reply->reply_icmp_ext; ie != NULL; ie = ie->ie_next) { state->params_len += (2 + 1 + 1 + ie->ie_dl); } } else if(var->id == WARTS_TRACELB_REPLY_FROM) { state->params_len += warts_addr_size(table, reply->reply_from); } flag_set(state->flags, var->id, &max_id); if(var->size > 0) { state->params_len += var->size; } } state->flags_len = fold_flags(state->flags, max_id); *len += state->flags_len + state->params_len; if(state->params_len != 0) *len += 2; return 0; }