Example #1
0
static int
sysctl_kern_ktrace_request_pool(SYSCTL_HANDLER_ARGS)
{
	struct thread *td;
	u_int newsize, oldsize, wantsize;
	int error;

	/* Handle easy read-only case first to avoid warnings from GCC. */
	if (!req->newptr) {
		oldsize = ktr_requestpool;
		return (SYSCTL_OUT(req, &oldsize, sizeof(u_int)));
	}

	error = SYSCTL_IN(req, &wantsize, sizeof(u_int));
	if (error)
		return (error);
	td = curthread;
	ktrace_enter(td);
	oldsize = ktr_requestpool;
	newsize = ktrace_resize_pool(oldsize, wantsize);
	ktrace_exit(td);
	error = SYSCTL_OUT(req, &oldsize, sizeof(u_int));
	if (error)
		return (error);
	if (wantsize > oldsize && newsize < wantsize)
		return (ENOSPC);
	return (0);
}
Example #2
0
static int
sysctl_kern_cp_time(SYSCTL_HANDLER_ARGS)
{
	int error;
	long cp_time[CPUSTATES];
#ifdef SCTL_MASK32
	int i;
	unsigned int cp_time32[CPUSTATES];
#endif

	read_cpu_time(cp_time);
#ifdef SCTL_MASK32
	if (req->flags & SCTL_MASK32) {
		if (!req->oldptr)
			return SYSCTL_OUT(req, 0, sizeof(cp_time32));
		for (i = 0; i < CPUSTATES; i++)
			cp_time32[i] = (unsigned int)cp_time[i];
		error = SYSCTL_OUT(req, cp_time32, sizeof(cp_time32));
	} else
#endif
	{
		if (!req->oldptr)
			return SYSCTL_OUT(req, 0, sizeof(cp_time));
		error = SYSCTL_OUT(req, cp_time, sizeof(cp_time));
	}
	return error;
}
Example #3
0
static int
sysctl_debug_hashstat_rawnchash(SYSCTL_HANDLER_ARGS)
{
	int error;
	struct nchashhead *ncpp;
	struct namecache *ncp;
	int n_nchash;
	int count;

	n_nchash = nchash + 1;	/* nchash is max index, not count */
	if (!req->oldptr)
		return SYSCTL_OUT(req, 0, n_nchash * sizeof(int));

	/* Scan hash tables for applicable entries */
	for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
		CACHE_RLOCK();
		count = 0;
		BSD_LIST_FOREACH(ncp, ncpp, nc_hash) {
			count++;
		}
		CACHE_RUNLOCK();
		error = SYSCTL_OUT(req, &count, sizeof(count));
		if (error)
			return (error);
	}
	return (0);
}
Example #4
0
static int
sysctl_kern_boottime(SYSCTL_HANDLER_ARGS)
{
#ifdef SCTL_MASK32
	int tv[2];

	if (req->flags & SCTL_MASK32) {
		tv[0] = boottime.tv_sec;
		tv[1] = boottime.tv_usec;
		return SYSCTL_OUT(req, tv, sizeof(tv));
	} else
#endif
		return SYSCTL_OUT(req, &boottime, sizeof(boottime));
}
Example #5
0
static int
sysctl_debug_ddb_scripting_scripts(SYSCTL_HANDLER_ARGS)
{
	struct sbuf sb;
	int error, i, len;
	char *buffer;

	/*
	 * Make space to include a maximum-length name, = symbol,
	 * maximum-length script, and carriage return for every script that
	 * may be defined.
	 */
	len = DB_MAXSCRIPTS * (DB_MAXSCRIPTNAME + 1 + DB_MAXSCRIPTLEN + 1);
	buffer = malloc(len, M_TEMP, M_WAITOK);
	(void)sbuf_new(&sb, buffer, len, SBUF_FIXEDLEN);
	mtx_lock(&db_script_mtx);
	for (i = 0; i < DB_MAXSCRIPTS; i++) {
		if (strlen(db_script_table[i].ds_scriptname) == 0)
			continue;
		(void)sbuf_printf(&sb, "%s=%s\n",
		    db_script_table[i].ds_scriptname,
		    db_script_table[i].ds_script);
	}
	mtx_unlock(&db_script_mtx);
	sbuf_finish(&sb);
	error = SYSCTL_OUT(req, sbuf_data(&sb), sbuf_len(&sb) + 1);
	sbuf_delete(&sb);
	free(buffer, M_TEMP);
	return (error);
}
Example #6
0
static int
udp6_getcred(SYSCTL_HANDLER_ARGS)
{
	struct sockaddr_in6 addrs[2];
	struct inpcb *inp;
	int error;

	error = priv_check(req->td, PRIV_ROOT);
	if (error)
		return (error);

	if (req->newlen != sizeof(addrs))
		return (EINVAL);
	if (req->oldlen != sizeof(struct ucred))
		return (EINVAL);
	error = SYSCTL_IN(req, addrs, sizeof(addrs));
	if (error)
		return (error);
	crit_enter();
	inp = in6_pcblookup_hash(&udbinfo[0], &addrs[1].sin6_addr,
				 addrs[1].sin6_port,
				 &addrs[0].sin6_addr, addrs[0].sin6_port,
				 1, NULL);
	if (!inp || !inp->inp_socket) {
		error = ENOENT;
		goto out;
	}
	error = SYSCTL_OUT(req, inp->inp_socket->so_cred,
			   sizeof(struct ucred));

out:
	crit_exit();
	return (error);
}
Example #7
0
/**
 * Handler for all generic XenBus device systcl nodes.
 */
static int
xenbusb_device_sysctl_handler(SYSCTL_HANDLER_ARGS)  
{
	device_t dev;
        const char *value;

	dev = (device_t)arg1;
        switch (arg2) {
	case XENBUS_IVAR_NODE:
		value = xenbus_get_node(dev);
		break;
	case XENBUS_IVAR_TYPE:
		value = xenbus_get_type(dev);
		break;
	case XENBUS_IVAR_STATE:
		value = xenbus_strstate(xenbus_get_state(dev));
		break;
	case XENBUS_IVAR_OTHEREND_ID:
		return (sysctl_handle_int(oidp, NULL,
					  xenbus_get_otherend_id(dev),
					  req));
		/* NOTREACHED */
	case XENBUS_IVAR_OTHEREND_PATH:
		value = xenbus_get_otherend_path(dev);
                break;
	default:
		return (EINVAL);
	}
	return (SYSCTL_OUT(req, value, strlen(value)));
}
Example #8
0
static int
powernow_sysctl_helper(SYSCTL_HANDLER_ARGS)
{
	int		fq        , err = 0;
	int		i;
	struct k8pnow_cpu_state *cstate;
	struct k8pnow_state *state;
	cstate = k8pnow_current_state;
	if (req->newptr != NULL) {
		err = SYSCTL_IN(req, &fq, sizeof(fq));
		if (err)
			return err;
		if (fq != cpuspeed) {
			for (i = cstate->n_states; i > 0; i--) {
				state = &cstate->state_table[i - 1];
				if (fq == state->freq) {
					k8_powernow_setperf(fq);
					break;
				}
			}
		}
	} else {
		err = SYSCTL_OUT(req, &cpuspeed, sizeof(cpuspeed));
	}
	return err;
}
Example #9
0
static int
sysctl_settfp_policy(__unused struct sysctl_oid *oidp, void *arg1,
    __unused int arg2, struct sysctl_req *req)
{
    int error = 0;
	int new_value;

    error = SYSCTL_OUT(req, arg1, sizeof(int));
    if (error || req->newptr == USER_ADDR_NULL)
        return(error);

	if (!is_suser())
		return(EPERM);

	if ((error = SYSCTL_IN(req, &new_value, sizeof(int)))) {
		goto out;
	}
	if ((new_value == KERN_TFP_POLICY_DENY) 
		|| (new_value == KERN_TFP_POLICY_DEFAULT))
			tfp_policy = new_value;
	else
			error = EINVAL;		
out:
    return(error);

}
Example #10
0
static int
sysctl_handle_error(SYSCTL_HANDLER_ARGS)
{
	struct ioat_descriptor *desc;
	struct ioat_softc *ioat;
	int error, arg;

	ioat = arg1;

	arg = 0;
	error = SYSCTL_OUT(req, &arg, sizeof(arg));
	if (error != 0 || req->newptr == NULL)
		return (error);

	error = SYSCTL_IN(req, &arg, sizeof(arg));
	if (error != 0)
		return (error);

	if (arg != 0) {
		ioat_acquire(&ioat->dmaengine);
		desc = ioat_op_generic(ioat, IOAT_OP_COPY, 1,
		    0xffff000000000000ull, 0xffff000000000000ull, NULL, NULL,
		    0);
		if (desc == NULL)
			error = ENOMEM;
		else
			ioat_submit_single(ioat);
		ioat_release(&ioat->dmaengine);
	}
	return (error);
}
Example #11
0
static int
est_sysctl_helper(SYSCTL_HANDLER_ARGS)
{
	uint64_t msr;
	int	 fq, oldfq, err = 0;
	int	 i;

	if (est_fqlist == NULL)
		return (EOPNOTSUPP);

	oldfq = MSR2MHZ(rdmsr(MSR_PERF_CTL));

	if (req->newptr != NULL) {
		err = SYSCTL_IN(req, &fq, sizeof(fq));
		if (err)
			return err;

		if (fq != oldfq) {
			for (i = est_fqlist->tablec - 1; i > 0; i--) {
				if (est_fqlist->table[i].mhz >= fq)
					break;
			}
			fq = est_fqlist->table[i].mhz;
			msr = (rdmsr(MSR_PERF_CTL) & ~0xffffULL) |
			    MV2MSR(est_fqlist->table[i].mv) |
			    MHZ2MSR(est_fqlist->table[i].mhz);
			wrmsr(MSR_PERF_CTL, msr);
		}
	} else {
		err = SYSCTL_OUT(req, &oldfq, sizeof(oldfq));
	}

	return err;
}
Example #12
0
static int
udp_getcred(SYSCTL_HANDLER_ARGS)
{
	struct xucred xuc;
	struct sockaddr_in addrs[2];
	struct inpcb *inp;
	int error;

	error = priv_check(req->td, PRIV_NETINET_GETCRED);
	if (error)
		return (error);
	error = SYSCTL_IN(req, addrs, sizeof(addrs));
	if (error)
		return (error);
	inp = in_pcblookup(&V_udbinfo, addrs[1].sin_addr, addrs[1].sin_port,
	    addrs[0].sin_addr, addrs[0].sin_port,
	    INPLOOKUP_WILDCARD | INPLOOKUP_RLOCKPCB, NULL);
	if (inp != NULL) {
		INP_RLOCK_ASSERT(inp);
		if (inp->inp_socket == NULL)
			error = ENOENT;
		if (error == 0)
			error = cr_canseeinpcb(req->td->td_ucred, inp);
		if (error == 0)
			cru2x(inp->inp_cred, &xuc);
		INP_RUNLOCK(inp);
	} else
		error = ENOENT;
	if (error == 0)
		error = SYSCTL_OUT(req, &xuc, sizeof(struct xucred));
	return (error);
}
Example #13
0
static int
sysctl_hw_machine_arch(SYSCTL_HANDLER_ARGS)
{
	int error;
	static const char machine_arch[] = MACHINE_ARCH;
#ifdef SCTL_MASK32
	static const char machine_arch32[] = MACHINE_ARCH32;

	if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
		error = SYSCTL_OUT(req, machine_arch32, sizeof(machine_arch32));
	else
#endif
		error = SYSCTL_OUT(req, machine_arch, sizeof(machine_arch));
	return (error);

}
Example #14
0
static int
sysctl_msqids(SYSCTL_HANDLER_ARGS)
{

	return (SYSCTL_OUT(req, msqids,
	    sizeof(struct msqid_ds) * msginfo.msgmni));
}
Example #15
0
static int
sysctl_timer_period( __unused struct sysctl_oid *oidp, struct sysctl_req *req )
{
    int error = 0;
    uint64_t inputs[2], retval;
    unsigned timer, set = 0;
    
    /* get 2x 64-bit words */
    error = SYSCTL_IN( req, inputs, 2*sizeof(inputs[0]) );
    if(error)
	    return (error);

    /* setup inputs */
    timer = (unsigned) inputs[0];
    if( inputs[1] != ~0ULL )
	    set = 1;

    if( set )
    {
	    error = kperf_timer_set_period( timer, inputs[1] );
	    if( error )
		    return error;
    }

    error = kperf_timer_get_period(timer, &retval);
    if(error)
	    return (error);

    inputs[1] = retval;
    
    if( error == 0 )
	    error = SYSCTL_OUT( req, inputs, 2*sizeof(inputs[0]) );

    return error;
}
Example #16
0
static int
ieee80211_sysctl_parent(SYSCTL_HANDLER_ARGS)
{
	struct ieee80211com *ic = arg1;
	const char *name = ic->ic_ifp->if_xname;

	return SYSCTL_OUT(req, name, strlen(name));
}
Example #17
0
static int
sysctl_hw_machine(SYSCTL_HANDLER_ARGS)
{
#ifdef SCTL_MASK32
	static const char machine32[] = "i386";
#endif
	int error;

#ifdef SCTL_MASK32
	if ((req->flags & SCTL_MASK32) != 0 && adaptive_machine_arch)
		error = SYSCTL_OUT(req, machine32, sizeof(machine32));
	else
#endif
		error = SYSCTL_OUT(req, machine, sizeof(machine));
	return (error);

}
Example #18
0
static int
sysctl_debug_hashstat_nchash(SYSCTL_HANDLER_ARGS)
{
	int error;
	struct nchashhead *ncpp;
	struct namecache *ncp;
	int n_nchash;
	int count, maxlength, used, pct;

	if (!req->oldptr)
		return SYSCTL_OUT(req, 0, 4 * sizeof(int));

	n_nchash = nchash + 1;	/* nchash is max index, not count */
	used = 0;
	maxlength = 0;

	/* Scan hash tables for applicable entries */
	for (ncpp = nchashtbl; n_nchash > 0; n_nchash--, ncpp++) {
		count = 0;
		CACHE_RLOCK();
		BSD_LIST_FOREACH(ncp, ncpp, nc_hash) {
			count++;
		}
		CACHE_RUNLOCK();
		if (count)
			used++;
		if (maxlength < count)
			maxlength = count;
	}
	n_nchash = nchash + 1;
	pct = (used * 100 * 100) / n_nchash;
	error = SYSCTL_OUT(req, &n_nchash, sizeof(n_nchash));
	if (error)
		return (error);
	error = SYSCTL_OUT(req, &used, sizeof(used));
	if (error)
		return (error);
	error = SYSCTL_OUT(req, &maxlength, sizeof(maxlength));
	if (error)
		return (error);
	error = SYSCTL_OUT(req, &pct, sizeof(pct));
	if (error)
		return (error);
	return (0);
}
Example #19
0
/* Extra care is taken with this sysctl because the data type is volatile */
static int
sysctl_kern_smp_active(SYSCTL_HANDLER_ARGS)
{
	int error, active;

	active = smp_started;
	error = SYSCTL_OUT(req, &active, sizeof(active));
	return (error);
}
static int
ue_sysctl_parent(SYSCTL_HANDLER_ARGS)
{
	struct usb_ether *ue = arg1;
	const char *name;

	name = device_get_nameunit(ue->ue_dev);
	return SYSCTL_OUT(req, name, strlen(name));
}
Example #21
0
static int
sysctl_kern_stackprot(SYSCTL_HANDLER_ARGS)
{
	struct proc *p;

	p = curproc;
	return (SYSCTL_OUT(req, &p->p_sysent->sv_stackprot,
	    sizeof(p->p_sysent->sv_stackprot)));
}
Example #22
0
/*
 * Sysctl to read out the capture buffer from userspace.  We require
 * privilege as sensitive process/memory information may be accessed.
 */
static int
sysctl_debug_ddb_capture_data(SYSCTL_HANDLER_ARGS)
{
    int error;
    char ch;

    error = priv_check(req->td, PRIV_DDB_CAPTURE);
    if (error)
        return (error);

    sx_slock(&db_capture_sx);
    error = SYSCTL_OUT(req, db_capture_buf, db_capture_bufoff);
    sx_sunlock(&db_capture_sx);
    if (error)
        return (error);
    ch = '\0';
    return (SYSCTL_OUT(req, &ch, sizeof(ch)));
}
Example #23
0
static int
hpt_copy_info(HPT_GET_INFO *pinfo, char *fmt, ...) 
{
	int printfretval;
	va_list ap;
	
	if(fmt == NULL) {
		*hptproc_buffer = 0;
		return (SYSCTL_OUT(pinfo, hptproc_buffer, 1));
	}
	else 
	{
		va_start(ap, fmt);
		printfretval = vsnprintf(hptproc_buffer, sizeof(hptproc_buffer), fmt, ap);
		va_end(ap);
		return(SYSCTL_OUT(pinfo, hptproc_buffer, strlen(hptproc_buffer)));
	}
}
Example #24
0
static int
sysctl_kern_usrstack(SYSCTL_HANDLER_ARGS)
{
	struct proc *p;
	int error;

	p = curproc;
#ifdef SCTL_MASK32
	if (req->flags & SCTL_MASK32) {
		unsigned int val;
		val = (unsigned int)p->p_sysent->sv_usrstack;
		error = SYSCTL_OUT(req, &val, sizeof(val));
	} else
#endif
		error = SYSCTL_OUT(req, &p->p_sysent->sv_usrstack,
		    sizeof(p->p_sysent->sv_usrstack));
	return error;
}
Example #25
0
static int
sfstat_sysctl(SYSCTL_HANDLER_ARGS)
{
	struct sfstat s;

	COUNTER_ARRAY_COPY(sfstat, &s, sizeof(s) / sizeof(uint64_t));
	if (req->newptr)
		COUNTER_ARRAY_ZERO(sfstat, sizeof(s) / sizeof(uint64_t));
	return (SYSCTL_OUT(req, &s, sizeof(s)));
}
Example #26
0
static int
sfxge_ev_stat_handler(SYSCTL_HANDLER_ARGS)
{
	struct sfxge_softc *sc = arg1;
	unsigned int id = arg2;

	sfxge_ev_stat_update(sc);

	return SYSCTL_OUT(req, &sc->ev_stats[id], sizeof(sc->ev_stats[id]));
}
Example #27
0
static int
sysctl_cpu_capability
(__unused struct sysctl_oid *oidp, void *arg1, __unused int arg2, struct sysctl_req *req)
{
	uint64_t	mask = (uint64_t) (uintptr_t) arg1;
	boolean_t	is_capable = (_get_cpu_capabilities() & mask) != 0;
 
	return SYSCTL_OUT(req, &is_capable, sizeof(is_capable));

}
Example #28
0
static int
sysctl_hopmodhandle(SYSCTL_HANDLER_ARGS)
{
    int             error;
    struct sysctl_hopmod mod;
    struct hop     *hop;

    error = SYSCTL_IN(req, &mod, sizeof(mod));
    if (error || !req->newptr) {
        if (!req->oldptr)
            error = SYSCTL_OUT(req, &hopcount, sizeof(hopcount));
        return error;
    }

    if (mod.hopidx>=hopcount) return EINVAL;

    mtx_lock(mn_mtx);

    hop = hoptable + mod.hopidx;

    hop->KBps = mod.hop.bandwidth/8; 
    hop->delay = (hz * mod.hop.delay) / 1000;
    hop->plr = mod.hop.plr;
    /* qsize change not allowed due to re-allocation
     * hop->qsize = mod.hop.qsize;
     */
    hop->emulator = mod.hop.emulator;
    hop->bytespertick = hop->KBps*1000/hz;
    /* XTQ */
    xtq_uninstall(hop, mod.hop.xtq_type);

    mtx_unlock(mn_mtx);
#if 0
    printf("hopmod: idx(%d) bw(%d) delay(%d) plr(%d) qsize(%d)\n",
	   mod.hopidx,hop->KBps, hop->delay, hop->plr, hop->qsize);
#endif


    error = SYSCTL_OUT(req, &hopcount, sizeof(hopcount));

    return (error);
}
Example #29
0
static int
sysctl_kern_arnd(SYSCTL_HANDLER_ARGS)
{
	char buf[256];
	size_t len;

	len = req->oldlen;
	if (len > sizeof(buf))
		len = sizeof(buf);
	arc4rand(buf, len, 0);
	return (SYSCTL_OUT(req, buf, len));
}
Example #30
0
static int
sysctl_pathentry(SYSCTL_HANDLER_ARGS)
{
    int             error, i;
    struct sysctl_pathentry entry;
    int            *hops;



    error = SYSCTL_IN(req, &entry, sizeof(entry));
    if (error || !req->newptr) {
        if (!req->oldptr)
            error = SYSCTL_OUT(req, &entry.pathlen, sizeof(entry.pathlen));

        return error;
    }

    if (!pathtable || !hoptable)
        return EINVAL;

    if (entry.src_node > nodecount || entry.dst_node > nodecount)
        return EINVAL;


    hops = malloc(entry.pathlen * sizeof *hops, M_TEMP, M_NOWAIT);
    if (!hops) {
        printf("hop alloc failed\n");
        return ENOMEM;
    }
    copyin(entry.hops, hops, entry.pathlen * sizeof *hops);

    mtx_lock(mn_mtx);

    pathtable[entry.src_node][entry.dst_node] = malloc((entry.pathlen + 1) *
	       sizeof(struct hop *), M_MN_ROUTE, M_NOWAIT | M_ZERO);
    if (!pathtable[entry.src_node][entry.dst_node]) {
        printf("path alloc failed\n");
        
	mtx_unlock(mn_mtx);
        return ENOMEM;
    }
    for (i = 0; i < entry.pathlen; ++i) {
        pathtable[entry.src_node][entry.dst_node][i] = hoptable + hops[i];
    }
    pathtable[entry.src_node][entry.dst_node][entry.pathlen] = NULL;

    free(hops, M_TEMP);

    mtx_unlock(mn_mtx);

    return (error);
}