/* * firewall_entry_free * * this function is not ipfw specific, its just that there is no other * code path that currently uses it. */ static void firewall_entry_free(scamper_firewall_entry_t *entry) { if(entry->node != NULL) splaytree_remove_node(entries, entry->node); firewall_rule_free(entry->rule); free(entry); return; }
static void s2t_free(s2t_t *s2t) { scamper_task_sig_t *sig = s2t->sig; if(s2t == NULL) return; if(s2t->node != NULL) { if(sig->sig_type == SCAMPER_TASK_SIG_TYPE_TX_IP) splaytree_remove_node(tx_ip, s2t->node); else if(sig->sig_type == SCAMPER_TASK_SIG_TYPE_TX_ND) splaytree_remove_node(tx_nd, s2t->node); else if(sig->sig_type == SCAMPER_TASK_SIG_TYPE_SNIFF) dlist_node_pop(sniff, s2t->node); } free(s2t); return; }
/* * fd_free * * free up memory allocated to scamper's monitoring of the file descriptor. */ static void fd_free(scamper_fd_t *fdn) { scamper_debug(__func__, "fd %d type %s", fdn->fd, fd_tostr(fdn)); if(fdn->fd >= 0 && fdn->fd < fd_array_s && fd_array != NULL) fd_array[fdn->fd] = NULL; if(fdn->read.node != NULL) dlist_node_pop(fdn->read.list, fdn->read.node); if(fdn->write.node != NULL) dlist_node_pop(fdn->write.list, fdn->write.node); if(fdn->rc0 != NULL) dlist_node_pop(refcnt_0, fdn->rc0); if(fdn->fd_tree_node != NULL) splaytree_remove_node(fd_tree, fdn->fd_tree_node); if(fdn->fd_list_node != NULL) dlist_node_pop(fd_list, fdn->fd_list_node); if(SCAMPER_FD_TYPE_IS_ICMP(fdn)) { if(fdn->fd_icmp_addr != NULL) free(fdn->fd_icmp_addr); } else if(SCAMPER_FD_TYPE_IS_UDP(fdn)) { if(fdn->fd_udp_addr != NULL) free(fdn->fd_udp_addr); } else if(SCAMPER_FD_TYPE_IS_TCP(fdn)) { if(fdn->fd_tcp_addr != NULL) free(fdn->fd_tcp_addr); } else if(SCAMPER_FD_TYPE_IS_DL(fdn)) { if(fdn->fd_dl_dl != NULL) scamper_dl_state_free(fdn->fd_dl_dl); } free(fdn); return; }
void scamper_firewall_entry_free(scamper_firewall_entry_t *entry) { entry->refcnt--; if(entry->refcnt > 0) { return; } /* remove the entry from the tree */ splaytree_remove_node(entries, entry->node); entry->node = NULL; /* * if the entry is still loaded in the firewall, remove it now. * note that this code is to handle the case that scamper_firewall_cleanup * is called before this function is called. */ if(entry->slot >= 0) { firewall_rule_delete(entry); } return; }
int main(int argc, char *argv[]) { scamper_file_t *file[2]; scamper_file_filter_t *filter; scamper_trace_t *trace; tracepair_t *pair, fm; uint16_t type = SCAMPER_FILE_OBJ_TRACE; char buf[256]; int i, filec_open; #ifdef _WIN32 WSADATA wsaData; WSAStartup(MAKEWORD(2,2), &wsaData); #endif if(check_options(argc, argv) != 0) goto err; if((filter = scamper_file_filter_alloc(&type, 1)) == NULL) { fprintf(stderr, "could not allocate filter\n"); goto err; } memset(file, 0, sizeof(file)); for(i=0; i<filec; i++) { if((file[i] = scamper_file_open(files[i], 'r', NULL)) == NULL) { fprintf(stderr, "could not open %s\n", files[i]); goto err; } } filec_open = filec; if((pairs = splaytree_alloc(tracepair_cmp)) == NULL) { fprintf(stderr, "could not alloc tracepair tree\n"); goto err; } splaytree_onremove(pairs, (splaytree_onremove_t)tracepair_onremove); while(filec_open != 0) { for(i=0; i<filec; i++) { if(file[i] == NULL) continue; if(scamper_file_read(file[i], filter, &type, (void *)&trace) != 0) { fprintf(stderr, "could not read from %s\n", files[i]); goto err; } if(trace == NULL) { filec_open--; scamper_file_close(file[i]); continue; } assert(type == SCAMPER_FILE_OBJ_TRACE); fm.tracec = 1; fm.traces[0] = trace; if((pair = splaytree_find(pairs, &fm)) == NULL) { if((pair = malloc_zero(sizeof(tracepair_t))) == NULL) goto err; pair->traces[i] = trace; pair->tracec = 1; if((pair->node = splaytree_insert(pairs, pair)) == NULL) goto err; } else { if(pair->traces[i] != NULL) { fprintf(stderr, "repeated trace for %s\n", scamper_addr_tostr(trace->dst, buf, sizeof(buf))); goto err; } pair->traces[i] = trace; pair->tracec++; } if(pair->tracec != filec) continue; splaytree_remove_node(pairs, pair->node); tracepair_process(pair); tracepair_free(pair); } } return 0; err: return -1; }