예제 #1
0
파일: data.c 프로젝트: Windeal/improxy
imp_interface* imp_interface_find(int family, if_type type)
{
    imp_interface    *p_if = imp_interface_first();

    for(; p_if; p_if = LIST_NEXT(p_if, link)){

        if(p_if->if_addr.ss.ss_family == family &&
            p_if->type == type)
            return p_if;
    }
    return NULL;

}
예제 #2
0
/*
 * allocate one address from address pool
 * if successful, returns pointer to struct of allocated address
 * if fails, returns 0
 *
 * caller must do LIST_INSERT_HEAD(&child_sa->lease_list, addr, link_sa)
 */
struct rcf_address *
rc_addrpool_alloc_any(struct rcf_addresspool *conf, int af)
{
	size_t addrsize;
	struct rcf_address_pool_item	*i;
	uint8_t	addr[MAX_ADDRESS_LENGTH];
	struct rcf_address	*a;

	if (!conf) {
		plog(PLOG_INTERR, PLOGLOC, NULL,
		     "no address pool specified\n");
		return 0;
	}

	addrsize = af_addrsize(af);
	if (addrsize == 0) 
		return 0;

	/*
	 * for each range of address pool
	 */
	for (i = LIST_FIRST(&conf->pool_list); i != NULL; i = LIST_NEXT(i, link)) {
		if (af != i->af)
			continue;

		/*
		 * try if it's possible to assign one
		 * XXX need better algorithm 
		 */
		for (memcpy(addr, &i->start, addrsize);
		     memcmp(addr, &i->end, addrsize) <= 0;
		     addrbits_incr(af, addr)) {

			if (addrpool_check(i, addr) != 0)
				continue;

			/*
			 * OK.  Assign it.
			 */
			a = rc_address_new(af, addr, IPV6_ADDRESS_PREFIX_LEN,
					   0, &i->lease_list);
			if (!a)
				return 0;
			return a;
		}
		/* all address in use.  try next range */
	}
	/* No address available for use */

	return 0;
}
예제 #3
0
/*
 * Synch buffers associated with a block device
 */
int
spec_fsync(void *v)
{
	struct vop_fsync_args *ap = v;
	struct vnode *vp = ap->a_vp;
	struct buf *bp;
	struct buf *nbp;
	int s;

	if (vp->v_type == VCHR)
		return (0);

#ifdef WAPBL
	if (vp->v_type == VBLK &&
	    vp->v_specmountpoint != NULL &&
	    vp->v_specmountpoint->mnt_wapbl != NULL)
		return (ffs_wapbl_fsync_vfs(vp, ap->a_waitfor));
#endif

	/*
	 * Flush all dirty buffers associated with a block device.
	 */
loop:
	s = splbio();
	for (bp = LIST_FIRST(&vp->v_dirtyblkhd);
	    bp != LIST_END(&vp->v_dirtyblkhd); bp = nbp) {
		nbp = LIST_NEXT(bp, b_vnbufs);
		if ((bp->b_flags & B_BUSY))
			continue;
		if ((bp->b_flags & B_DELWRI) == 0)
			panic("spec_fsync: not dirty");
		bremfree(bp);
		buf_acquire(bp);
		splx(s);
		bawrite(bp);
		goto loop;
	}
	if (ap->a_waitfor == MNT_WAIT) {
		vwaitforio (vp, 0, "spec_fsync", 0);

#ifdef DIAGNOSTIC
		if (!LIST_EMPTY(&vp->v_dirtyblkhd)) {
			splx(s);
			vprint("spec_fsync: dirty", vp);
			goto loop;
		}
#endif
	}
	splx(s);
	return (0);
}
예제 #4
0
파일: kern_time.c 프로젝트: ryo/netbsd-src
/* Delete a POSIX realtime timer */
int
sys_timer_delete(struct lwp *l, const struct sys_timer_delete_args *uap,
    register_t *retval)
{
	/* {
		syscallarg(timer_t) timerid;
	} */
	struct proc *p = l->l_proc;
	timer_t timerid;
	struct ptimers *pts;
	struct ptimer *pt, *ptn;

	timerid = SCARG(uap, timerid);
	pts = p->p_timers;
	
	if (pts == NULL || timerid < 2 || timerid >= TIMER_MAX)
		return (EINVAL);

	mutex_spin_enter(&timer_lock);
	if ((pt = pts->pts_timers[timerid]) == NULL) {
		mutex_spin_exit(&timer_lock);
		return (EINVAL);
	}
	if (CLOCK_VIRTUAL_P(pt->pt_type)) {
		if (pt->pt_active) {
			ptn = LIST_NEXT(pt, pt_list);
			LIST_REMOVE(pt, pt_list);
			for ( ; ptn; ptn = LIST_NEXT(ptn, pt_list))
				timespecadd(&pt->pt_time.it_value,
				    &ptn->pt_time.it_value,
				    &ptn->pt_time.it_value);
			pt->pt_active = 0;
		}
	}
	itimerfree(pts, timerid);

	return (0);
}
예제 #5
0
파일: input.c 프로젝트: kimel/improxy
static imp_interface* mcast_if_get_by_addr(pi_addr *p_pia)
{
    imp_interface *p_if = imp_interface_first();

    while(p_if) {

       if (memcmp(&p_if->if_addr, p_pia, sizeof(pi_addr)) == 0)
            return p_if;

        p_if = LIST_NEXT(p_if, link);
    }

    return NULL;
}
예제 #6
0
static void
hcirawpr(kvm_t *kvmd, u_long addr)
{
	ng_btsocket_hci_raw_pcb_p	this = NULL, next = NULL;
	ng_btsocket_hci_raw_pcb_t	pcb;
	struct socket			so;
	int				first = 1;

	if (addr == 0)
		return;

        if (kread(kvmd, addr, (char *) &this, sizeof(this)) < 0)
		return;

	for ( ; this != NULL; this = next) {
		if (kread(kvmd, (u_long) this, (char *) &pcb, sizeof(pcb)) < 0)
			return;
		if (kread(kvmd, (u_long) pcb.so, (char *) &so, sizeof(so)) < 0)
			return;

		next = LIST_NEXT(&pcb, next);

		if (first) {
			first = 0;
			fprintf(stdout,
"Active raw HCI sockets\n" \
"%-8.8s %-8.8s %-6.6s %-6.6s %-6.6s %-16.16s\n",
				"Socket",
				"PCB",
				"Flags",
				"Recv-Q",
				"Send-Q",
				"Local address");
		}

		if (pcb.addr.hci_node[0] == 0) {
			pcb.addr.hci_node[0] = '*';
			pcb.addr.hci_node[1] = 0;
		}

		fprintf(stdout,
"%-8lx %-8lx %-6.6x %6d %6d %-16.16s\n",
			(unsigned long) pcb.so,
			(unsigned long) this,
			pcb.flags,
			so.so_rcv.sb_ccc,
			so.so_snd.sb_ccc,
			pcb.addr.hci_node);
	}
} /* hcirawpr */
예제 #7
0
파일: bio.c 프로젝트: ajinkya93/OpenBSD
void
bio_unregister(struct device *dev)
{
	struct bio_mapping *bm, *next;

	for (bm = LIST_FIRST(&bios); bm != NULL; bm = next) {
		next = LIST_NEXT(bm, bm_link);

		if (dev == bm->bm_dev) {
			LIST_REMOVE(bm, bm_link);
			free(bm, M_DEVBUF, sizeof(*bm));
		}
	}
}
예제 #8
0
usbd_status
usb_allocmem(usbd_bus_handle bus, size_t size, size_t align, usb_dma_t *p)
{
	bus_dma_tag_t tag = bus->dmatag;
	usbd_status err;
	struct usb_frag_dma *f;
	usb_dma_block_t *b;
	int i;
	int s;

	/* If the request is large then just use a full block. */
	if (size > USB_MEM_SMALL || align > USB_MEM_SMALL) {
		DPRINTFN(1, ("usb_allocmem: large alloc %d\n", (int)size));
		size = (size + USB_MEM_BLOCK - 1) & ~(USB_MEM_BLOCK - 1);
		err = usb_block_allocmem(tag, size, align, &p->block);
		if (!err) {
			p->block->fullblock = 1;
			p->offs = 0;
		}
		return (err);
	}

	s = splusb();
	/* Check for free fragments. */
	for (f = LIST_FIRST(&usb_frag_freelist); f; f = LIST_NEXT(f, next))
		if (f->block->tag == tag)
			break;
	if (f == NULL) {
		DPRINTFN(1, ("usb_allocmem: adding fragments\n"));
		err = usb_block_allocmem(tag, USB_MEM_BLOCK, USB_MEM_SMALL,&b);
		if (err) {
			splx(s);
			return (err);
		}
		b->fullblock = 0;
		for (i = 0; i < USB_MEM_BLOCK; i += USB_MEM_SMALL) {
			f = (struct usb_frag_dma *)(b->kaddr + i);
			f->block = b;
			f->offs = i;
			LIST_INSERT_HEAD(&usb_frag_freelist, f, next);
		}
		f = LIST_FIRST(&usb_frag_freelist);
	}
	p->block = f->block;
	p->offs = f->offs;
	LIST_REMOVE(f, next);
	splx(s);
	DPRINTFN(5, ("usb_allocmem: use frag=%p size=%d\n", f, (int)size));
	return (USBD_NORMAL_COMPLETION);
}
예제 #9
0
파일: data.c 프로젝트: Windeal/improxy
imp_source* imp_source_find_scheduled(imp_group *p_gp, int sflag)
{
    imp_source  *p_is = NULL;

    for (p_is = LIST_FIRST(&p_gp->src_list); p_is ;
            p_is = LIST_NEXT(p_is, link)) {

        if (imp_source_is_scheduled(p_is, sflag) != 0)
            return p_is;;

    }
    return NULL;

}
예제 #10
0
파일: data.c 프로젝트: Windeal/improxy
/*-----------------------------------------------------------------------
 * Name         : imp_source_exist_allow
 *
 * Brief        : check if there exsit source which is allowed in group
 * Params       : [in] p_gp -- struct imp_group
 * Return       : 1:exsit 0:not exsit
*------------------------------------------------------------------------
*/
int imp_source_exist_allow(imp_group *p_gp)
{
    imp_source  *p_is = NULL;

    for (p_is = LIST_FIRST(&p_gp->src_list); p_is ;
            p_is = LIST_NEXT(p_is, link)) {

        if(!TIMEVAL_ISZERO(p_is->timer->tm))
            return 1;

    }
    return 0;

}
예제 #11
0
파일: battle.c 프로젝트: phoboz/yz
static void next_battle_turn(
    BATTLE *battle
)
{
    BATTLE_ACTOR *ba;

    for (ba = (BATTLE_ACTOR *) LIST_HEAD(&battle->battleList);
            ba != NULL;
            ba = (BATTLE_ACTOR *) LIST_NEXT(&ba->listNode) ) {

        set_battle_state(battle, ba, BATTLE_STATE_IDLE, NULL);

    }
}
예제 #12
0
파일: battle.c 프로젝트: phoboz/yz
static void draw_battle_field(
    BATTLE *battle
)
{
    BATTLE_ACTOR *ba;

    for (ba = (BATTLE_ACTOR *) LIST_HEAD(&battle->battleList);
            ba != NULL;
            ba = (BATTLE_ACTOR *) LIST_NEXT(&ba->listNode) ) {

        draw_player(ba->player, battle->world);

    }
}
예제 #13
0
파일: mass.c 프로젝트: mysidia/snservices1
/**
 * @brief Cancel mass ad cache from a user
 * @param u User to flush out
 * @param rcv -1 = cancel all, or cancel where ad->rcvd_by == rcv
 */
aMassAd *
find_ad(UserList * u, int rcv)
{
	aMassAd *search;

	if ((search = LIST_FIRST(&masslist)) == NULL)
		return NULL;
	while (search) {
		if (search->sender == u && (search->rcvd_by == rcv || rcv == -1))
			return search;
		search = LIST_NEXT(search, ma_lst);
	}
	return NULL;
}
예제 #14
0
파일: pfil.c 프로젝트: MarginC/kame
/*
 * pfil_head_get() returns the pfil_head for a given key/dlt.
 */
struct pfil_head *
pfil_head_get(int type, u_long val)
{
	struct pfil_head *ph;

	for (ph = LIST_FIRST(&pfil_head_list); ph != NULL;
	     ph = LIST_NEXT(ph, ph_list)) {
		if (ph->ph_type == type &&
		    ph->ph_un.phu_val == val)
			break;
	}

	return (ph);
}
예제 #15
0
파일: in_pcblist.c 프로젝트: jndok/xnu
__private_extern__ uint32_t
inpcb_count_opportunistic(unsigned int ifindex, struct inpcbinfo *pcbinfo,
    u_int32_t flags)
{
	uint32_t opportunistic = 0;
	struct inpcb *inp;
	inp_gen_t gencnt;

	lck_rw_lock_shared(pcbinfo->ipi_lock);
	gencnt = pcbinfo->ipi_gencnt;
	for (inp = LIST_FIRST(pcbinfo->ipi_listhead);
	    inp != NULL; inp = LIST_NEXT(inp, inp_list)) {
		if (inp->inp_gencnt <= gencnt &&
		    inp->inp_state != INPCB_STATE_DEAD &&
		    inp->inp_socket != NULL &&
		    so_get_opportunistic(inp->inp_socket) &&
		    inp->inp_last_outifp != NULL &&
		    ifindex == inp->inp_last_outifp->if_index) {
			opportunistic++;
			struct socket *so = inp->inp_socket;
			if ((flags & INPCB_OPPORTUNISTIC_SETCMD) &&
			    (so->so_state & SS_ISCONNECTED)) {
				socket_lock(so, 1);
				if (flags & INPCB_OPPORTUNISTIC_THROTTLEON) {
					so->so_flags |= SOF_SUSPENDED;
					soevent(so,
					    (SO_FILT_HINT_LOCKED |
					    SO_FILT_HINT_SUSPEND));
				} else {
					so->so_flags &= ~(SOF_SUSPENDED);
					soevent(so,
					    (SO_FILT_HINT_LOCKED |
					    SO_FILT_HINT_RESUME));
				}
				SOTHROTTLELOG(("throttle[%d]: so 0x%llx "
				    "[%d,%d] %s\n", so->last_pid,
				    (uint64_t)VM_KERNEL_ADDRPERM(so),
				    SOCK_DOM(so), SOCK_TYPE(so),
				    (so->so_flags & SOF_SUSPENDED) ?
				    "SUSPENDED" : "RESUMED"));
				socket_unlock(so, 1);
			}
		}
	}

	lck_rw_done(pcbinfo->ipi_lock);

	return (opportunistic);
}
예제 #16
0
파일: room.c 프로젝트: OrangeTide/boris
/**
 * write a room structure to disk, if it is not dirty (dirty_fl).
 */
static int room_save(struct room *r) {
	struct attr_entry *curr;
	struct fdb_write_handle *h;
	char numbuf[22]; /* big enough for a signed 64-bit decimal */

	assert(r != NULL);
	if(!r->dirty_fl) return 1; /* already saved - don't do it again. */

	/* refuse to save room 0. */
	if(!r->id) {
		b_log(B_LOG_ERROR, "room", "attempted to save room \"%u\", but it is reserved", r->id);
		return 0;
	}

	snprintf(numbuf, sizeof numbuf, "%u", r->id);

	h=fdb.write_begin("rooms", numbuf);
	if(!h) {
		b_log(B_LOG_ERROR, "room", "could not save room \"%s\"", numbuf);
		return 0; /* failure */
	}

	fdb.write_format(h, "id", "%u", r->id);
	if(r->name.short_str)
		fdb.write_pair(h, "name.short", r->name.short_str);
	if(r->name.long_str)
		fdb.write_pair(h, "name.long", r->name.long_str);
	if(r->desc.short_str)
		fdb.write_pair(h, "desc.short", r->desc.short_str);
	if(r->desc.long_str)
		fdb.write_pair(h, "desc.long", r->desc.long_str);
	if(r->owner)
		fdb.write_pair(h, "owner", r->owner);
	if(r->creator)
		fdb.write_pair(h, "creator", r->creator);

	for(curr=LIST_TOP(r->extra_values);curr;curr=LIST_NEXT(curr, list)) {
		fdb.write_pair(h, curr->name, curr->value);
	}

	if(!fdb.write_end(h)) {
		b_log(B_LOG_ERROR, "room", "could not save room \"%s\"", numbuf);
		return 0; /* failure */
	}

	r->dirty_fl=0;
	b_log(B_LOG_INFO, "room", "saved room \"%s\"", numbuf);
	return 1;
}
예제 #17
0
void
exit_daemon(void)
{
	struct session *s, *next;

	for (s = LIST_FIRST(&sessions); s != LIST_END(&sessions); s = next) {
		next = LIST_NEXT(s, entry);
		end_session(s);
	}

	if (daemonize)
		closelog();

	exit(0);
}
예제 #18
0
static int
eisa_add_resvaddr(struct eisa_device *e_dev, struct resvlist *head, u_long base,
		  u_long size, int flags)
{
	resvaddr_t *reservation;

	reservation = (resvaddr_t *)malloc(sizeof(resvaddr_t),
					   M_DEVBUF, M_NOWAIT);
	if(!reservation)
		return (ENOMEM);

	reservation->addr = base;
	reservation->size = size;
	reservation->flags = flags;

	if (!LIST_FIRST(head)) {
		LIST_INSERT_HEAD(head, reservation, links);
	}
	else {
		resvaddr_t *node;
		LIST_FOREACH(node, head, links) {
			if (node->addr > reservation->addr) {
				/*
				 * List is sorted in increasing
				 * address order.
				 */
				LIST_INSERT_BEFORE(node, reservation, links);
				break;
			}

			if (node->addr == reservation->addr) {
				/*
				 * If the entry we want to add
				 * matches any already in here,
				 * fail.
				 */
				free(reservation, M_DEVBUF);
				return (EEXIST);
			}

			if (!LIST_NEXT(node, links)) {
				LIST_INSERT_AFTER(node, reservation, links);
				break;
			}
		}
	}
	return (0);
}
예제 #19
0
파일: battle.c 프로젝트: phoboz/yz
void deinit_battle(
    BATTLE *battle
)
{
    BATTLE_ACTOR *ba;

    for (ba = (BATTLE_ACTOR *) LIST_HEAD(&battle->battleList);
            ba != NULL;
            ba = (BATTLE_ACTOR *) LIST_NEXT(&ba->listNode))  {
        set_battle_state(battle, ba, BATTLE_STATE_DONE, NULL);
        /* TODO: Free each battle actor */
    }

    /* TODO: Free all nodes */
    listInit(&battle->battleList);
}
예제 #20
0
파일: eval.c 프로젝트: oswjk/lispish
struct atom *builtin_atom(struct atom *expr, struct env *env)
{
    struct list *list = expr->list;
    struct atom *op = LIST_FIRST(list);
    struct atom *a = LIST_NEXT(op, entries);

    (void) env;

    if (!a)
        return &nil_atom;

    if (IS_LIST(a))
        return &false_atom;
    else
        return &true_atom;
}
/*
 * insert a new element in an existing list that the ID's (size in struct
 * pci_memreg) are sorted.
 */
static void
insert_into_list(PCI_MEMREG *head, struct pci_memreg *elem)
{
    struct pci_memreg *p, *q;

    p = LIST_FIRST(head);
    q = NULL;

    for (; p != NULL && p->size < elem->size; q = p, p = LIST_NEXT(p, link));

    if (q == NULL) {
	LIST_INSERT_HEAD(head, elem, link);
    } else {
	LIST_INSERT_AFTER(q, elem, link);
    }
}
예제 #22
0
int
encap_detach(const struct encaptab *cookie)
{
	const struct encaptab *ep = cookie;
	struct encaptab *p;

	for (p = LIST_FIRST(&encaptab); p; p = LIST_NEXT(p, chain)) {
		if (p == ep) {
			LIST_REMOVE(p, chain);
			_FREE(p, M_NETADDR);	/*XXX*/
			return 0;
		}
	}

	return EINVAL;
}
예제 #23
0
/* Lookup an SA with the help from a user-supplied checking function.  */
struct sa *
sa_find(int (*check) (struct sa*, void *), void *arg)
{
	int             i;
	struct sa      *sa;

	for (i = 0; i <= bucket_mask; i++)
		for (sa = LIST_FIRST(&sa_tab[i]); sa; sa = LIST_NEXT(sa, link))
			if (check(sa, arg)) {
				LOG_DBG((LOG_SA, 90, "sa_find: return SA %p",
				    sa));
				return sa;
			}
	LOG_DBG((LOG_SA, 90, "sa_find: no SA matched query"));
	return 0;
}
예제 #24
0
static int
env_recover(char *progname)
{
	DbEnv *dbenv;
	home_entry *hp;
	u_int32_t flags;
	int exitval, ret;

	for (hp = LIST_FIRST(&__dbsrv_home); hp != NULL;
	    hp = LIST_NEXT(hp, entries)) {
		exitval = 0;
		dbenv = new DbEnv(DB_CXX_NO_EXCEPTIONS);
		if (__dbsrv_verbose == 1) {
			(void)dbenv->set_verbose(DB_VERB_RECOVERY, 1);
			(void)dbenv->set_verbose(DB_VERB_CHKPOINT, 1);
		}
		dbenv->set_errfile(stderr);
		dbenv->set_errpfx(progname);
		if (hp->passwd != NULL)
			(void)dbenv->set_encrypt(hp->passwd, DB_ENCRYPT_AES);

		/*
		 * Initialize the env with DB_RECOVER.  That is all we
		 * have to do to run recovery.
		 */
		if (__dbsrv_verbose)
			printf("Running recovery on %s\n", hp->home);
		flags = DB_CREATE | DB_INIT_LOCK | DB_INIT_LOG | DB_INIT_MPOOL |
		    DB_INIT_TXN | DB_USE_ENVIRON | DB_RECOVER;
		if ((ret = dbenv->open(hp->home, flags, 0)) != 0) {
			dbenv->err(ret, "DbEnv->open");
			goto error;
		}

		if (0) {
error:			exitval = 1;
		}
		if ((ret = dbenv->close(0)) != 0) {
			exitval = 1;
			fprintf(stderr, "%s: dbenv->close: %s\n",
			    progname, db_strerror(ret));
		}
		if (exitval)
			return (exitval);
	}
	return (0);
}
예제 #25
0
파일: world.c 프로젝트: phoboz/yz
int reveal_world_terrain(
  WORLD *world,
  int x,
  int y
  )
{
  FIELD *field;
  int i, j;
  WORLD_BLOCK_TYPE v;

  i = x / world->tile_width;
  j = y / world->tile_height;

  v = world->world_map[i + j * world->map->w];
  if (v > WORLD_EMPTY_BLOCK) {

    if ( (v >= WORLD_ROAD_BLOCK_S) ||
	 (v <= WORLD_ROAD_BLOCK_E) ) {

      reveal_world_road(world, i, j, v);

    }

    if (v == WORLD_FIELD_BLOCK) {

      for(field = (FIELD *) LIST_HEAD(&world->fieldList);
	  field != NULL;
          field = (FIELD *) LIST_NEXT(&field->listNode)) {

        if ( i >= field->x && i <= (field->x + field->w) &&
	     j >= field->y && j <= (field->y + field->h) ) {

          reveal_world_field(world, field);
          world->lastField = field;
	  return 1;

        }

      }

    }

  }

  return 0;

}
예제 #26
0
/*
 * Find the gre interface associated with our src/dst/proto set.
 */
static struct gre_softc *
gre_lookup(struct mbuf *m, u_int8_t proto)
{
	struct ip *ip = mtod(m, struct ip *);
	struct gre_softc *sc;

	for (sc = LIST_FIRST(&gre_softc_list); sc != NULL;
	     sc = LIST_NEXT(sc, sc_list)) {
		if ((sc->g_dst.s_addr == ip->ip_src.s_addr) &&
		    (sc->g_src.s_addr == ip->ip_dst.s_addr) &&
		    (sc->g_proto == proto) &&
		    ((sc->sc_if.if_flags & IFF_UP) != 0))
			return (sc);
	}

	return (NULL);
}
예제 #27
0
파일: vm.c 프로젝트: Marvenlee/cheviot
SYSCALL int ExpungeCachedSegment (uint64 *in_segment_id)
{
    struct Process *current;
    struct Segment *seg;
    uint64 segment_id;
    uint64 key;
    
    current = GetCurrentProcess();
    
    CopyIn (&segment_id, in_segment_id, sizeof (segment_id));
    
    key = segment_id % CACHE_HASH_SZ;
    
    seg = LIST_HEAD (&cache_hash[key]);

    DisablePreemption();
                
    while (seg != NULL)
    {
        if (seg->segment_id == segment_id && seg->owner == current)
        {
            LIST_REM_ENTRY (&cache_lru_list, seg, lru_link);
            LIST_REM_ENTRY (&cache_hash[key], seg, hash_link);

            if (seg == last_aged_seg)
                last_aged_seg = NULL;
            
            HEAP_ADD_HEAD (&free_segment_list[seg->bucket_q], seg, link);
            seg->size = 0;
            seg->physical_addr = (vm_addr)NULL;
            seg->flags = MEM_FREE;
            seg->owner = NULL;
            
            PmapRemoveRegion (seg);
            return 0;
        }
        else if (seg->segment_id == segment_id && seg->owner != current)
        {
            return memoryErr;
        }
        
        seg = LIST_NEXT (seg, hash_link);
    }
    
    return memoryErr;        
}
예제 #28
0
파일: in_pcblist.c 프로젝트: Algozjb/xnu
__private_extern__ void
inpcb_get_ports_used(unsigned int ifindex, uint8_t *bitfield, struct inpcbinfo *pcbinfo)
{
	lck_rw_lock_shared(pcbinfo->mtx);
	
	struct inpcb *inp;
	inp_gen_t	gencnt = pcbinfo->ipi_gencnt;
	for (inp = LIST_FIRST(pcbinfo->listhead); inp; inp = LIST_NEXT(inp, inp_list)) {
		if (inp->inp_gencnt <= gencnt && inp->inp_state != INPCB_STATE_DEAD &&
			(ifindex == 0 || inp->inp_last_outifp == NULL || ifindex == inp->inp_last_outifp->if_index)) {
			uint16_t port = ntohs(inp->inp_lport);
			bitfield[port / 8] |= 1 << (port & 0x7);
		}
	}
	
	lck_rw_done(pcbinfo->mtx);
}
예제 #29
0
struct rcf_address *
rc_addrpool_assign_ip6intf(struct rcf_addresspool *conf, uint8_t *addr)
{
	struct rcf_address_pool_item	*i;
	struct in6_addr	a;
	const size_t ip6prefix_bytes = 8;
	const int ip6intf_id = ip6prefix_bytes;
	const size_t ip6intf_id_bytes = 8;
	int p;

	if (!conf) {
		plog(PLOG_INTERR, PLOGLOC, NULL,
		     PLOGLOC, "no address pool specified\n");
		return 0;
	}

	for (i = LIST_FIRST(&conf->pool_list); i != NULL; i = LIST_NEXT(i, link)) {
		if (i->af != AF_INET6)
			continue;

		/* concat prefix and interface identifier */
		memcpy(&a, i->start, ip6prefix_bytes);
		memcpy(&a.s6_addr[ip6intf_id], &addr[ip6intf_id], ip6intf_id_bytes);
		while (memcmp(a.s6_addr, i->end, sizeof(struct in6_addr)) <= 0) {
			if (addrpool_check(i, a.s6_addr) == 0) {
				struct rcf_address *n;

				/* ok.  use it */
				n = rc_address_new(AF_INET6, addr,
						   IPV6_ADDRESS_PREFIX_LEN, 0,
						   &i->lease_list);
				if (!n)
					return 0;	       /* allocation failed */
				return n;
			}

			/* try different prefix */
			for (p = ip6prefix_bytes; --p >= 0; ) {
				if (++a.s6_addr[p] != 0)
					break;
			}
		}
	}
	/* no appropriate prefix found */
	return 0;
}
예제 #30
0
파일: in_pcblist.c 프로젝트: jndok/xnu
__private_extern__ uint32_t
inpcb_find_anypcb_byaddr(struct ifaddr *ifa, struct inpcbinfo *pcbinfo)
{
	struct inpcb *inp;
	inp_gen_t gencnt = pcbinfo->ipi_gencnt;
	struct socket *so = NULL;
	int af;

	if ((ifa->ifa_addr->sa_family != AF_INET) &&
	    (ifa->ifa_addr->sa_family != AF_INET6)) {
		return (0);
	}

	lck_rw_lock_shared(pcbinfo->ipi_lock);
	for (inp = LIST_FIRST(pcbinfo->ipi_listhead);
	    inp != NULL; inp = LIST_NEXT(inp, inp_list)) {

		if (inp->inp_gencnt <= gencnt &&
		    inp->inp_state != INPCB_STATE_DEAD &&
		    inp->inp_socket != NULL) {
			so = inp->inp_socket;
			af = SOCK_DOM(so);
			if (af != ifa->ifa_addr->sa_family)
				continue;
			if (inp->inp_last_outifp != ifa->ifa_ifp)
				continue;

			if (af == AF_INET) {
				if (inp->inp_laddr.s_addr ==
				    (satosin(ifa->ifa_addr))->sin_addr.s_addr) {
					lck_rw_done(pcbinfo->ipi_lock);
					return (1);
				}
			}
			if (af == AF_INET6) {
				if (IN6_ARE_ADDR_EQUAL(IFA_IN6(ifa),
				    &inp->in6p_laddr)) {
					lck_rw_done(pcbinfo->ipi_lock);
					return (1);
				}
			}
		}
	}
	lck_rw_done(pcbinfo->ipi_lock);
	return (0);
}