static int pipetapfd(struct chan *chan, struct fd_tap *tap, int cmd) { int ret; Pipe *p; int which = 1; uint64_t kludge; p = chan->aux; kludge = (uint64_t)p; #define DEVPIPE_LEGAL_DATA_TAPS (FDTAP_FILT_READABLE | FDTAP_FILT_WRITABLE | \ FDTAP_FILT_HANGUP | FDTAP_FILT_ERROR) switch (NETTYPE(chan->qid.path)) { case Qdata0: which = 0; /* fall through */ case Qdata1: kludge |= which; if (tap->filter & ~DEVPIPE_LEGAL_DATA_TAPS) { set_errno(ENOSYS); set_errstr("Unsupported #%s data tap %p, must be %p", devname(), tap->filter, DEVPIPE_LEGAL_DATA_TAPS); return -1; } spin_lock(&p->tap_lock); switch (cmd) { case (FDTAP_CMD_ADD): if (SLIST_EMPTY(&p->data_taps[which])) qio_set_wake_cb(p->q[which], pipe_wake_cb, (void *)kludge); SLIST_INSERT_HEAD(&p->data_taps[which], tap, link); ret = 0; break; case (FDTAP_CMD_REM): SLIST_REMOVE(&p->data_taps[which], tap, fd_tap, link); if (SLIST_EMPTY(&p->data_taps[which])) qio_set_wake_cb(p->q[which], 0, (void *)kludge); ret = 0; break; default: set_errno(ENOSYS); set_errstr("Unsupported #%s data tap command %p", devname(), cmd); ret = -1; } spin_unlock(&p->tap_lock); return ret; default: set_errno(ENOSYS); set_errstr("Can't tap #%s file type %d", devname(), NETTYPE(chan->qid.path)); return -1; } }
/* * Get a slab. * id is the slabclass the new slab will be linked into. * * We return a slab either from the: * 1. slab pool, if not empty. or, * 2. evict an active slab and return that instead. */ static rstatus_i _slab_get(uint8_t id) { rstatus_i status; struct slab *slab; ASSERT(slabclass[id].next_item_in_slab == NULL); ASSERT(SLIST_EMPTY(&slabclass[id].free_itemq)); slab = _slab_get_new(); if (slab == NULL && (evict_opt & EVICT_CS)) { slab = _slab_evict_lru(id); } if (slab == NULL && (evict_opt & EVICT_RS)) { slab = _slab_evict_rand(); } if (slab != NULL) { _slab_init(slab, id); status = CC_OK; } else { status = CC_ENOMEM; INCR(slab_metrics, slab_req_ex); } INCR(slab_metrics, slab_req); return status; }
/* ARGSUSED */ int poptag(int f, int n) { struct line *dotp; struct tagpos *s; if (SLIST_EMPTY(&shead)) { dobeep(); ewprintf("No previous location for find-tag invocation"); return (FALSE); } s = SLIST_FIRST(&shead); SLIST_REMOVE_HEAD(&shead, entry); if (loadbuffer(s->bname) == FALSE) return (FALSE); curwp->w_dotline = s->dotline; curwp->w_doto = s->doto; /* storing of dotp in tagpos wouldn't work out in cases when * that buffer is killed by user(dangling pointer). Explicitly * traverse till dotline for correct handling. */ dotp = curwp->w_bufp->b_headp; while (s->dotline--) dotp = dotp->l_fp; curwp->w_dotp = dotp; free(s->bname); free(s); return (TRUE); }
static int dos_attack_init(void *dummy) { char dos_addr[MAX_ASCII_ADDR_LEN]; char unused_addr[MAX_ASCII_ADDR_LEN]; struct port_list *p; /* It doesn't work if unoffensive */ if (GBL_OPTIONS->unoffensive) { INSTANT_USER_MSG("dos_attack: plugin doesn't work in UNOFFENSIVE mode\n"); return PLUGIN_FINISHED; } /* don't show packets while operating */ GBL_OPTIONS->quiet = 1; memset(dos_addr, 0, sizeof(dos_addr)); memset(unused_addr, 0, sizeof(dos_addr)); ui_input("Insert victim IP: ", dos_addr, sizeof(dos_addr), NULL); if (ip_addr_pton(dos_addr, &victim_host) == -EINVALID) { INSTANT_USER_MSG("dos_attack: Invalid IP address.\n"); return PLUGIN_FINISHED; } ui_input("Insert unused IP: ", unused_addr, sizeof(unused_addr), NULL); if (ip_addr_pton(unused_addr, &fake_host) == -EINVALID) { INSTANT_USER_MSG("dos_attack: Invalid IP address.\n"); return PLUGIN_FINISHED; } if(victim_host.addr_type != fake_host.addr_type) { INSTANT_USER_MSG("dos_attack: Address' families don't match.\n"); return PLUGIN_FINISHED; } INSTANT_USER_MSG("dos_attack: Starting scan against %s [Fake Host: %s]\n", dos_addr, unused_addr); /* Delete the "open" port list just in case of previous executions */ while (!SLIST_EMPTY(&port_table)) { p = SLIST_FIRST(&port_table); SLIST_REMOVE_HEAD(&port_table, next); SAFE_FREE(p); } /* Add the hook to "create" the fake host */ if(ntohs(fake_host.addr_type) == AF_INET) hook_add(HOOK_PACKET_ARP_RQ, &parse_arp); #ifdef WITH_IPV6 else if(ntohs(fake_host.addr_type) == AF_INET6) hook_add(HOOK_PACKET_ICMP6_NSOL, &parse_icmp6); #endif /* Add the hook for SYN-ACK reply */ hook_add(HOOK_PACKET_TCP, &parse_tcp); /* create the flooding thread */ ec_thread_new("golem", "SYN flooder thread", &syn_flooder, NULL); return PLUGIN_RUNNING; }
void tag_screen(struct screen *s, struct tag *t) { struct client *c; /* Return to the previous tag */ if(t == s->seltag && TAILQ_NEXT(TAILQ_FIRST(&s->tags), next)) t = t->prev; if(!t) t = TAILQ_FIRST(&s->tags); /* Move clients which ignore tags */ SLIST_FOREACH(c, &W->h.client, next) if (c->flags & CLIENT_IGNORE_TAG) tag_client(t, c); t->prev = s->seltag; s->seltag = t; clients_arrange_map(); /* Update focus */ if(!SLIST_EMPTY(&t->clients) && !(W->flags & WMFS_SCAN)) client_focus( client_tab_next(t->sel)); t->flags &= ~TAG_URGENT; infobar_elem_screen_update(s, ElemTag); ewmh_update_wmfs_props(); }
/* * Prepend the source path to a file name. */ char * sourcepath(const char *file) { size_t len; char *cp; struct prefix *pf; pf = SLIST_EMPTY(&prefixes) ? NULL : SLIST_FIRST(&prefixes); if (pf != NULL && *pf->pf_prefix == '/') len = strlen(pf->pf_prefix) + 1 + strlen(file) + 1; else { len = strlen(srcdir) + 1 + strlen(file) + 1; if (pf != NULL) len += strlen(pf->pf_prefix) + 1; } cp = emalloc(len); if (pf != NULL) { if (*pf->pf_prefix == '/') (void) sprintf(cp, "%s/%s", pf->pf_prefix, file); else (void) sprintf(cp, "%s/%s/%s", srcdir, pf->pf_prefix, file); } else (void) sprintf(cp, "%s/%s", srcdir, file); return (cp); }
static int mp_init_block(struct MP_TREE_ENTRY *tree_entry, long size,unsigned int alloc_num) { struct MP_MEM_ENTRY *mem_entry; struct MP_MEM_ENTRY *new_mem_entry; unsigned int i; for (i = 0; i < alloc_num; i++) { new_mem_entry = (struct MP_MEM_ENTRY *)malloc( sizeof(struct MP_MEM_ENTRY) + size); if (new_mem_entry == NULL) { while (!SLIST_EMPTY(&(tree_entry->mem_head))) { mem_entry = SLIST_FIRST(&(tree_entry->mem_head)); SLIST_REMOVE_HEAD(&(tree_entry->mem_head), mem_entries); free(mem_entry); } free(new_mem_entry); return (-1); } new_mem_entry->size = size; SLIST_INSERT_HEAD(&(tree_entry->mem_head), new_mem_entry, mem_entries); tree_entry->total_item++; } return (0); }
int show_direct_depends(const char *pkgarg) { char *pkgname, query[BUFSIZ]; Pkglist *pdp, *mapplist; Plisthead *deptreehead; if (SLIST_EMPTY(&r_plisthead)) { printf("%s\n", MSG_EMPTY_AVAIL_PKGLIST); return EXIT_FAILURE; } if ((pkgname = unique_pkg(pkgarg, REMOTE_PKG)) == NULL) { fprintf(stderr, MSG_PKG_NOT_AVAIL, pkgarg); return EXIT_FAILURE; } deptreehead = init_head(); snprintf(query, BUFSIZ, EXACT_DIRECT_DEPS, pkgname); if (pkgindb_doquery(query, pdb_rec_depends, deptreehead) == PDB_OK) { printf(MSG_DIRECT_DEPS_FOR, pkgname); SLIST_FOREACH(pdp, deptreehead, next) { if (package_version && (mapplist = map_pkg_to_dep(&r_plisthead, pdp->depend)) != NULL) printf("\t%s\n", mapplist->full); else printf("\t%s\n", pdp->depend); } free_pkglist(&deptreehead, DEPTREE); }
void vmeintr_disestablish(u_int vec, struct intrhand *ih) { struct intrhand *intr; intrhand_t *list; list = &vmeintr_handlers[vec]; evcount_detach(&ih->ih_count); SLIST_REMOVE(list, ih, intrhand, ih_link); if (!SLIST_EMPTY(list)) return; /* * Walk the interrupts table to check if this level needs * to be disabled. */ for (vec = 0; vec < NVMEINTR; vec++) { intr = SLIST_FIRST(&vmeintr_handlers[vec]); if (intr != NULL && intr->ih_ipl == ih->ih_ipl) break; } if (vec == NVMEINTR) intsrc_disable(INTSRC_VME(ih->ih_ipl)); }
/* * Destroy all table data. This function can run when there are no * readers on table lists. */ int dm_table_destroy(dm_table_head_t * head, uint8_t table_id) { dm_table_t *tbl; dm_table_entry_t *table_en; uint8_t id; lockmgr(&head->table_mtx, LK_EXCLUSIVE); aprint_debug("dm_Table_destroy called with %d--%d\n", table_id, head->io_cnt); if (table_id == DM_TABLE_ACTIVE) id = head->cur_active_table; else id = 1 - head->cur_active_table; tbl = &head->tables[id]; while (!SLIST_EMPTY(tbl)) { /* List Deletion. */ table_en = SLIST_FIRST(tbl); /* * Remove target specific config data. After successfull * call table_en->target_config must be set to NULL. */ table_en->target->destroy(table_en); SLIST_REMOVE_HEAD(tbl, next); kfree(table_en, M_DM); } lockmgr(&head->table_mtx, LK_RELEASE); return 0; }
/* * "Move" mbuf pkthdr from "from" to "to". * "from" must have M_PKTHDR set, and "to" must be empty. */ void m_move_pkthdr(struct mbuf *to, struct mbuf *from) { #if 0 /* see below for why these are not enabled */ M_ASSERTPKTHDR(to); /* Note: with MAC, this may not be a good assertion. */ KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags), ("m_move_pkthdr: to has tags")); #endif #ifdef MAC /* * XXXMAC: It could be this should also occur for non-MAC? */ if (to->m_flags & M_PKTHDR) m_tag_delete_chain(to, NULL); #endif to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); if ((to->m_flags & M_EXT) == 0) to->m_data = to->m_pktdat; to->m_pkthdr = from->m_pkthdr; /* especially tags */ SLIST_INIT(&from->m_pkthdr.tags); /* purge tags from src */ from->m_flags &= ~M_PKTHDR; }
/* * Duplicate "from"'s mbuf pkthdr in "to". * "from" must have M_PKTHDR set, and "to" must be empty. * In particular, this does a deep copy of the packet tags. */ int m_dup_pkthdr(struct mbuf *to, const struct mbuf *from, int how) { #if 0 /* * The mbuf allocator only initializes the pkthdr * when the mbuf is allocated with m_gethdr(). Many users * (e.g. m_copy*, m_prepend) use m_get() and then * smash the pkthdr as needed causing these * assertions to trip. For now just disable them. */ M_ASSERTPKTHDR(to); /* Note: with MAC, this may not be a good assertion. */ KASSERT(SLIST_EMPTY(&to->m_pkthdr.tags), ("m_dup_pkthdr: to has tags")); #endif MBUF_CHECKSLEEP(how); #ifdef MAC if (to->m_flags & M_PKTHDR) m_tag_delete_chain(to, NULL); #endif to->m_flags = (from->m_flags & M_COPYFLAGS) | (to->m_flags & M_EXT); if ((to->m_flags & M_EXT) == 0) to->m_data = to->m_pktdat; to->m_pkthdr = from->m_pkthdr; SLIST_INIT(&to->m_pkthdr.tags); return (m_tag_copy_chain(to, from, how)); }
static void * mp_alloc(long size) { struct MP_TREE_ENTRY find; struct MP_TREE_ENTRY *cur_tree_entry; struct MP_TREE_ENTRY *new_tree_entry; struct MP_MEM_ENTRY *new_mem_entry; struct MP_MEM_ENTRY *mem_entry; int retval; if (!mp_initialized) return NULL; if (size <= 0) return NULL; find.mem_size = size; cur_tree_entry = RB_FIND(MP_TREE, &mp_tree, &find); if (cur_tree_entry == NULL) { new_tree_entry = (struct MP_TREE_ENTRY *)calloc(1, sizeof(struct MP_TREE_ENTRY)); if (new_tree_entry == NULL) return (NULL); new_tree_entry->mem_size = size; new_tree_entry->total_item = 0; SLIST_INIT(&(new_tree_entry->mem_head)); if (mp_init_block(new_tree_entry, size, g_pre_alloc_num - 1) < 0) return (NULL); RB_INSERT(MP_TREE, &mp_tree, new_tree_entry); } else { if (cur_tree_entry->total_item == 0) { SLIST_INIT(&(cur_tree_entry->mem_head)); retval = mp_init_block(cur_tree_entry, cur_tree_entry->mem_size, g_pre_alloc_num - 1); if (retval < 0) return (NULL); } else { if (!SLIST_EMPTY(&(cur_tree_entry->mem_head))) { mem_entry = SLIST_FIRST(&(cur_tree_entry->mem_head)); SLIST_REMOVE_HEAD(&(cur_tree_entry->mem_head), mem_entries); cur_tree_entry->total_item--; return ((void *)(++mem_entry)); } else { printf("alloc: FATAL ERROR!\n"); return (NULL); } } } new_mem_entry = (struct MP_MEM_ENTRY *)calloc(1, sizeof(struct MP_MEM_ENTRY) + size); if (new_mem_entry == NULL) return (NULL); new_mem_entry->size = size; return ((void *)(++new_mem_entry)); }
void filt_fifowdetach(struct knote *kn) { struct socket *so = (struct socket *)kn->kn_hook; SLIST_REMOVE(&so->so_snd.sb_sel.si_note, kn, knote, kn_selnext); if (SLIST_EMPTY(&so->so_snd.sb_sel.si_note)) so->so_snd.sb_flags &= ~SB_KNOTE; }
static void rmuser(struct user *usr, struct channel *chan) { list_remove(usr, &chan->users); if (SLIST_EMPTY(&chan->users)) { table_del(channels, chan->name, chan->len); free_channel(chan); } }
static void pgt_free_unlocked(struct pgt_cache *pgt_cache, bool save_ctx __unused) { while (!SLIST_EMPTY(pgt_cache)) { struct pgt *p = SLIST_FIRST(pgt_cache); SLIST_REMOVE_HEAD(pgt_cache, link); push_to_free_list(p); } }
static void filt_fifowdetach(struct knote *kn) { struct socket *so; so = (struct socket *)kn->kn_hook; solock(so); SLIST_REMOVE(&so->so_snd.sb_sel.sel_klist, kn, knote, kn_selnext); if (SLIST_EMPTY(&so->so_snd.sb_sel.sel_klist)) so->so_snd.sb_flags &= ~SB_KNOTE; sounlock(so); }
void free_gramlist(void) { struct gram *tmp; while (!SLIST_EMPTY(&grams_head)) { tmp = SLIST_FIRST(&grams_head); SLIST_REMOVE_HEAD(&grams_head, grams); free(tmp->buf); free(tmp); } }
static int mprsas_volume_add(struct mpr_softc *sc, u16 handle) { struct mprsas_softc *sassc; struct mprsas_target *targ; u64 wwid; unsigned int id; int error = 0; struct mprsas_lun *lun; sassc = sc->sassc; mprsas_startup_increment(sassc); /* wwid is endian safe */ mpr_config_get_volume_wwid(sc, handle, &wwid); if (!wwid) { printf("%s: invalid WWID; cannot add volume to mapping table\n", __func__); error = ENXIO; goto out; } id = mpr_mapping_get_raid_id(sc, wwid, handle); if (id == MPR_MAP_BAD_ID) { printf("%s: could not get ID for volume with handle 0x%04x and " "WWID 0x%016llx\n", __func__, handle, (unsigned long long)wwid); error = ENXIO; goto out; } targ = &sassc->targets[id]; targ->tid = id; targ->handle = handle; targ->devname = wwid; TAILQ_INIT(&targ->commands); TAILQ_INIT(&targ->timedout_commands); while (!SLIST_EMPTY(&targ->luns)) { lun = SLIST_FIRST(&targ->luns); SLIST_REMOVE_HEAD(&targ->luns, lun_link); free(lun, M_MPR); } SLIST_INIT(&targ->luns); #if ((__FreeBSD_version >= 1000000) && (__FreeBSD_version < 1000039)) || \ (__FreeBSD_version < 902502) if ((sassc->flags & MPRSAS_IN_STARTUP) == 0) #endif mprsas_rescan_target(sc, targ); mpr_dprint(sc, MPR_MAPPING, "RAID target id %d added (WWID = 0x%jx)\n", targ->tid, wwid); out: mprsas_startup_decrement(sassc); return (error); }
void ignoreclean(void) { struct ignentry *ign; while (!SLIST_EMPTY(&ignores)) { ign = SLIST_FIRST(&ignores); SLIST_REMOVE_HEAD(&ignores, next); free(ign->mask); free(ign); } }
int ext4_block_cache_flush(struct ext4_blockdev *bdev) { while (!SLIST_EMPTY(&bdev->bc->dirty_list)) { int r; struct ext4_buf *buf = SLIST_FIRST(&bdev->bc->dirty_list); ext4_assert(buf); r = ext4_block_flush_buf(bdev, buf); if (r != EOK) return r; } return EOK; }
/* * Cleanup and destroy tree and stack. */ void closetags(void) { struct tagpos *s; while (!SLIST_EMPTY(&shead)) { s = SLIST_FIRST(&shead); SLIST_REMOVE_HEAD(&shead, entry); free(s->bname); free(s); } unloadtags(); free(tagsfn); }
void screen_free(void) { struct screen *s; while(!SLIST_EMPTY(&W->h.screen)) { s = SLIST_FIRST(&W->h.screen); SLIST_REMOVE_HEAD(&W->h.screen, next); infobar_free(s); tag_free(s); free(s); } }
static void snmp_enumtc_listfree(struct snmp_enum_tc *headp) { struct enum_type *t; while (!SLIST_EMPTY(headp)) { t = SLIST_FIRST(headp); SLIST_REMOVE_HEAD(headp, link); if (t->name) free(t->name); enum_pairs_free(t->snmp_enum); free(t); } }
/* * The Mbuf master zone destructor. */ static void mb_dtor_mbuf(void *mem, int size, void *arg) { struct mbuf *m; unsigned long flags; m = (struct mbuf *)mem; flags = (unsigned long)arg; KASSERT((m->m_flags & M_NOFREE) == 0, ("%s: M_NOFREE set", __func__)); if ((m->m_flags & M_PKTHDR) && !SLIST_EMPTY(&m->m_pkthdr.tags)) m_tag_delete_chain(m, NULL); #ifdef INVARIANTS trash_dtor(mem, size, arg); #endif }
int userfw_domain_uninit(void) { if (!SLIST_EMPTY(so_list)) return EBUSY; #ifdef SKIP_DOMAIN_STUB return EBUSY; /* we cannot unregister domain */ #endif #ifndef SKIP_DOMAIN_STUB userfw_unreg_domain(&userfwreqs); #endif mtx_destroy(&so_list_mtx); return 0; }
void free_pkglist(Plisthead *plisthead) { Pkglist *plist; if (plisthead == NULL) return; while (!SLIST_EMPTY(plisthead)) { plist = SLIST_FIRST(plisthead); SLIST_REMOVE_HEAD(plisthead, next); XFREE(plist->pkgname); XFREE(plist->comment); XFREE(plist); } XFREE(plisthead); }
static void snmp_mapping_table_listfree(struct snmp_table_index *headp) { struct snmp_index_entry *t; while (!SLIST_EMPTY(headp)) { t = SLIST_FIRST(headp); SLIST_REMOVE_HEAD(headp, link); if (t->string) free(t->string); snmp_index_listfree(&(t->index_list)); free(t); } }
/* Starts the default sandbox. */ void startNullSandbox(void) { struct sandbox *newsandbox; if (!slist_initiated) { SLIST_INIT(&sandboxes); /* Here we add a sandbox used for not structure-related stuff */ /* This will be the first sandbox always */ if (SLIST_EMPTY(&sandboxes)) { newsandbox = startChild(NULL); SLIST_INSERT_HEAD(&sandboxes, newsandbox, next); } } slist_initiated = 1; }
static void pgt_free_unlocked(struct pgt_cache *pgt_cache, bool save_ctx) { while (!SLIST_EMPTY(pgt_cache)) { struct pgt *p = SLIST_FIRST(pgt_cache); SLIST_REMOVE_HEAD(pgt_cache, link); if (save_ctx && p->num_used_entries) { push_to_cache_list(p); } else { tee_pager_pgt_save_and_release_entries(p); assert(!p->num_used_entries); p->ctx = NULL; p->vabase = 0; push_to_free_list(p); } } }