static scamper_firewall_rule_t *firewall_rule_dup(scamper_firewall_rule_t *sfw) { scamper_firewall_rule_t *dup; if((dup = memdup(sfw, sizeof(scamper_firewall_rule_t))) == NULL) return NULL; scamper_addr_use(dup->sfw_5tuple_src); if(dup->sfw_5tuple_dst != NULL) scamper_addr_use(dup->sfw_5tuple_dst); return dup; }
static addr2mac_t *addr2mac_alloc(const int ifindex, scamper_addr_t *ip, scamper_addr_t *mac, time_t expire) { addr2mac_t *addr2mac; if((addr2mac = malloc_zero(sizeof(addr2mac_t))) == NULL) { printerror(errno, strerror, __func__, "could not malloc addr2mac"); return NULL; } addr2mac->ifindex = ifindex; addr2mac->ip = ip != NULL ? scamper_addr_use(ip) : NULL; addr2mac->mac = mac != NULL ? scamper_addr_use(mac) : NULL; addr2mac->expire = expire; return addr2mac; }
static void probe_route_cb(scamper_route_t *rt) { scamper_fd_t *fd = NULL; scamper_dl_t *dl = NULL; probe_t *pr = rt->param; if(rt->error != 0 || rt->ifindex < 0) { pr->error = rt->error; goto err; } if((fd = scamper_task_fd_dl(pr->task, rt->ifindex)) == NULL) { pr->error = errno; goto err; } if((pr->dlhdr = scamper_dlhdr_alloc()) == NULL) { pr->error = errno; goto err; } dl = scamper_fd_dl_get(fd); pr->dlhdr->dst = scamper_addr_use(rt->dst); pr->dlhdr->gw = rt->gw != NULL ? scamper_addr_use(rt->gw) : NULL; pr->dlhdr->ifindex = rt->ifindex; pr->dlhdr->txtype = scamper_dl_tx_type(dl); pr->dlhdr->param = pr; pr->dlhdr->cb = probe_dlhdr_cb; pr->mode = PROBE_MODE_DL; if(scamper_dlhdr_get(pr->dlhdr) != 0) { pr->error = pr->dlhdr->error; goto err; } return; err: pr->mode = PROBE_MODE_ERR; if(pr->anc != NULL) probe_free(pr); return; }
scamper_route_t *scamper_route_alloc(scamper_addr_t *dst, void *param, void (*cb)(scamper_route_t *rt)) { scamper_route_t *route; if((route = malloc_zero(sizeof(scamper_route_t))) == NULL) return NULL; route->dst = scamper_addr_use(dst); route->param = param; route->cb = cb; return route; }
int scamper_dealias_prefixscan_probedef_add(scamper_dealias_t *dealias, scamper_dealias_probedef_t *def) { scamper_dealias_prefixscan_t *prefixscan = dealias->data; size_t size; /* make the probedef array one bigger */ size = sizeof(scamper_dealias_probedef_t) * (prefixscan->probedefc+1); if(realloc_wrap((void **)&prefixscan->probedefs, size) != 0) return -1; /* add the probedef to the array */ memcpy(&prefixscan->probedefs[prefixscan->probedefc], def, sizeof(scamper_dealias_probedef_t)); /* update the probedef with an id, and get references to the addresses */ def = &prefixscan->probedefs[prefixscan->probedefc]; def->id = prefixscan->probedefc++; scamper_addr_use(def->src); scamper_addr_use(def->dst); return 0; }
int scamper_dealias_prefixscan_xs_add(scamper_dealias_t *dealias, scamper_addr_t *addr) { scamper_dealias_prefixscan_t *prefixscan = dealias->data; int tmp; if(array_find((void **)prefixscan->xs, prefixscan->xc, addr, (array_cmp_t)scamper_addr_cmp) != NULL) return 0; if((tmp = prefixscan->xc) == 65535) return -1; if(array_insert((void ***)&prefixscan->xs, &tmp, addr, (array_cmp_t)scamper_addr_cmp) != 0) return -1; scamper_addr_use(addr); prefixscan->xc++; return 0; }