예제 #1
0
static int
sysctl_machdep_led_display(SYSCTL_HANDLER_ARGS)
{
	size_t buflen;
	char buf[9];
	int error;

	if (req->newptr == NULL)
		return (EINVAL);

	if (cvmx_sysinfo_get()->led_display_base_addr == 0)
		return (ENODEV);

	/*
	 * Revision 1.x of the EBT3000 only supports 4 characters, but
	 * other devices support 8.
	 */
	if (cvmx_sysinfo_get()->board_type == CVMX_BOARD_TYPE_EBT3000 &&
	    cvmx_sysinfo_get()->board_rev_major == 1)
		buflen = 4;
	else
		buflen = 8;

	if (req->newlen > buflen)
		return (E2BIG);

	error = SYSCTL_IN(req, buf, req->newlen);
	if (error != 0)
		return (error);

	buf[req->newlen] = '\0';
	ebt3000_str_write(buf);

	return (0);
}
예제 #2
0
파일: kperfbsd.c 프로젝트: TalAloni/xnu
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;
}
예제 #3
0
파일: ioat.c 프로젝트: cyrilmagsuci/freebsd
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);
}
예제 #4
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);

}
예제 #5
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);
}
예제 #6
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);
}
예제 #7
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);
}
예제 #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;
}
예제 #9
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;
}
예제 #10
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);
}
예제 #11
0
파일: mca.c 프로젝트: MarginC/kame
static int
mca_sysctl_handler(SYSCTL_HANDLER_ARGS)
{
	int error = 0;

	if (!arg1)
		return (EINVAL);
	error = SYSCTL_OUT(req, arg1, arg2);

	if (error || !req->newptr)
		return (error);

	error = SYSCTL_IN(req, arg1, arg2);
	return (error);
}
예제 #12
0
static int
sysctl_udpstat(SYSCTL_HANDLER_ARGS)
{
	int cpu, error = 0;

	for (cpu = 0; cpu < ncpus; ++cpu) {
		if ((error = SYSCTL_OUT(req, &udpstat_percpu[cpu],
					sizeof(struct udpstat))))
			break;
		if ((error = SYSCTL_IN(req, &udpstat_percpu[cpu],
				       sizeof(struct udpstat))))
			break;
	}

	return (error);
}
예제 #13
0
static int
sysctl_ip6_tempvltime(SYSCTL_HANDLER_ARGS)
{
	int error = 0;
	int old;

	error = SYSCTL_OUT(req, arg1, sizeof(int));
	if (error || !req->newptr)
		return (error);
	old = ip6_temp_valid_lifetime;
	error = SYSCTL_IN(req, arg1, sizeof(int));
	if (ip6_temp_valid_lifetime < ip6_temp_preferred_lifetime) {
		ip6_temp_preferred_lifetime = old;
		return (EINVAL);
	}
	return (error);
}
예제 #14
0
파일: kern_mib.c 프로젝트: CptFrazz/xnu
/*
 * Debugging interface to the CPU power management code.
 *
 * Note:	Does not need locks because it disables interrupts over
 *		the call.
 */
static int
pmsSysctl(__unused struct sysctl_oid *oidp, __unused void *arg1,
	  __unused int arg2, struct sysctl_req *req)
{
	pmsctl_t	ctl;
	int		error;
	boolean_t	intr;

	if ((error = SYSCTL_IN(req, &ctl, sizeof(ctl))))
		return(error);

	intr = ml_set_interrupts_enabled(FALSE);		/* No interruptions in here */
	error = pmsControl(ctl.request, (user_addr_t)(uintptr_t)ctl.reqaddr, ctl.reqsize);
	(void)ml_set_interrupts_enabled(intr);			/* Restore interruptions */

	return(error);
}
예제 #15
0
파일: kperfbsd.c 프로젝트: TalAloni/xnu
static int
sysctl_action_filter( __unused struct sysctl_oid *oidp,
		      struct sysctl_req *req, int is_task_t )
{
    int error = 0;
    uint64_t inputs[3];
    int retval;
    unsigned actionid, set = 0;
    mach_port_name_t portname;
    int pid;

    /* get 3x 64-bit words */
    error = SYSCTL_IN( req, inputs, 3*sizeof(inputs[0]) );
    if(error)
	    return (error);

    /* setup inputs */
    set = (unsigned) inputs[0];
    actionid = (unsigned) inputs[1];

    if( set )
    {
	    if( is_task_t )
	    {
		    portname = (mach_port_name_t) inputs[2];
		    pid = kperf_port_to_pid(portname);
	    }
	    else
		    pid = (int) inputs[2];

	    error = kperf_action_set_filter( actionid, pid );
	    if( error )
		    return error;
    }

    error = kperf_action_get_filter(actionid, &retval);
    if(error)
	    return (error);

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

    return error;
}
예제 #16
0
/* net.inet6.ip6 */
static int
sysctl_ip6_temppltime(SYSCTL_HANDLER_ARGS)
{
	int error = 0;
	int old;

	error = SYSCTL_OUT(req, arg1, sizeof(int));
	if (error || !req->newptr)
		return (error);
	old = ip6_temp_preferred_lifetime;
	error = SYSCTL_IN(req, arg1, sizeof(int));
	if (ip6_temp_preferred_lifetime <
	    ip6_desync_factor + ip6_temp_regen_advance) {
		ip6_temp_preferred_lifetime = old;
		return (EINVAL);
	}
	return (error);
}
예제 #17
0
static int
udp6_getcred(SYSCTL_HANDLER_ARGS)
{
	struct xucred xuc;
	struct sockaddr_in6 addrs[2];
	struct inpcb *inp;
	int error;

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

	if (req->newlen != sizeof(addrs))
		return (EINVAL);
	if (req->oldlen != sizeof(struct xucred))
		return (EINVAL);
	error = SYSCTL_IN(req, addrs, sizeof(addrs));
	if (error)
		return (error);
	if ((error = sa6_embedscope(&addrs[0], V_ip6_use_defzone)) != 0 ||
	    (error = sa6_embedscope(&addrs[1], V_ip6_use_defzone)) != 0) {
		return (error);
	}
	inp = in6_pcblookup(&V_udbinfo, &addrs[1].sin6_addr,
	    addrs[1].sin6_port, &addrs[0].sin6_addr, addrs[0].sin6_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_canseesocket(req->td->td_ucred,
			    inp->inp_socket);
		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);
}
예제 #18
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);
}
예제 #19
0
static int
sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
{
	struct sfxge_softc *sc = arg1;
	struct sfxge_intr *intr = &sc->intr;
	unsigned int moderation;
	int error;
	unsigned int index;

	SFXGE_ADAPTER_LOCK(sc);

	if (req->newptr != NULL) {
		if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
		    != 0)
			goto out;

		/* We may not be calling efx_ev_qmoderate() now,
		 * so we have to range-check the value ourselves.
		 */
		if (moderation >
		    efx_nic_cfg_get(sc->enp)->enc_evq_timer_max_us) {
			error = EINVAL;
			goto out;
		}

		sc->ev_moderation = moderation;
		if (intr->state == SFXGE_INTR_STARTED) {
			for (index = 0; index < sc->evq_count; index++)
				sfxge_ev_qmoderate(sc, index, moderation);
		}
	} else {
		error = SYSCTL_OUT(req, &sc->ev_moderation,
				   sizeof(sc->ev_moderation));
	}

out:
	SFXGE_ADAPTER_UNLOCK(sc);

	return (error);
}
예제 #20
0
static int
sfxge_int_mod_handler(SYSCTL_HANDLER_ARGS)
{
	struct sfxge_softc *sc = arg1;
	struct sfxge_intr *intr = &sc->intr;
	unsigned int moderation;
	int error;
	int index;

	sx_xlock(&sc->softc_lock);

	if (req->newptr) {
		if ((error = SYSCTL_IN(req, &moderation, sizeof(moderation)))
		    != 0)
			goto out;

		/* We may not be calling efx_ev_qmoderate() now,
		 * so we have to range-check the value ourselves.
		 */
		if (moderation >
		    efx_nic_cfg_get(sc->enp)->enc_evq_moderation_max) {
			error = EINVAL;
			goto out;
		}

		sc->ev_moderation = moderation;
		if (intr->state == SFXGE_INTR_STARTED) {
			for (index = 0; index < intr->n_alloc; index++)
				sfxge_ev_qmoderate(sc, index, moderation);
		}
	} else {
		error = SYSCTL_OUT(req, &sc->ev_moderation,
				   sizeof(sc->ev_moderation));
	}

out:
	sx_xunlock(&sc->softc_lock);

	return error;
}
예제 #21
0
파일: ioat.c 프로젝트: cyrilmagsuci/freebsd
static int
sysctl_handle_reset(SYSCTL_HANDLER_ARGS)
{
	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)
		error = ioat_reset_hw(ioat);

	return (error);
}
예제 #22
0
static int
udp_getcred(SYSCTL_HANDLER_ARGS)
{
	struct sockaddr_in addrs[2];
	struct ucred cred0, *cred = NULL;
	struct inpcb *inp;
	int error, cpu, origcpu;

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

	origcpu = mycpuid;
	cpu = udp_addrcpu(addrs[1].sin_addr.s_addr, addrs[1].sin_port,
	    addrs[0].sin_addr.s_addr, addrs[0].sin_port);

	lwkt_migratecpu(cpu);

	inp = in_pcblookup_hash(&udbinfo[cpu],
	    addrs[1].sin_addr, addrs[1].sin_port,
	    addrs[0].sin_addr, addrs[0].sin_port, TRUE, NULL);
	if (inp == NULL || inp->inp_socket == NULL) {
		error = ENOENT;
	} else if (inp->inp_socket->so_cred != NULL) {
		cred0 = *(inp->inp_socket->so_cred);
		cred = &cred0;
	}

	lwkt_migratecpu(origcpu);

	if (error)
		return error;

	return SYSCTL_OUT(req, cred, sizeof(struct ucred));
}
예제 #23
0
파일: mlfk_ipl.c 프로젝트: 2asoft/freebsd
int
sysctl_ipf_int ( SYSCTL_HANDLER_ARGS )
{
	int error = 0;

	if (arg1)
		error = SYSCTL_OUT(req, arg1, sizeof(int));
	else
		error = SYSCTL_OUT(req, &arg2, sizeof(int));

	if (error || !req->newptr)
		return (error);

	if (!arg1)
		error = EPERM;
	else {
		if ((oidp->oid_kind & CTLFLAG_OFF) && (V_ipfmain.ipf_running > 0))
			error = EBUSY;
		else
			error = SYSCTL_IN(req, arg1, sizeof(int));
	}
	return (error);
}
예제 #24
0
파일: kperfbsd.c 프로젝트: TalAloni/xnu
static int
sysctl_action_userdata( __unused struct sysctl_oid *oidp, 
                        struct sysctl_req *req )
{
    int error = 0;
    uint64_t inputs[3];
    uint32_t retval;
    unsigned actionid, set = 0;
    
    /* get 3x 64-bit words */
    error = SYSCTL_IN( req, inputs, 3*sizeof(inputs[0]) );
    if(error)
	    return (error);

    /* setup inputs */
    set = (unsigned) inputs[0];
    actionid = (unsigned) inputs[1];

    if( set )
    {
	    error = kperf_action_set_userdata( actionid, inputs[2] );
	    if( error )
		    return error;
    }

    error = kperf_action_get_userdata(actionid, &retval);
    if(error)
	    return (error);

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

    return error;
}
예제 #25
0
static int
sysctl_rule(SYSCTL_HANDLER_ARGS)
{
	struct mac_bsdextended_rule temprule, *ruleptr;
	u_int namelen;
	int error, index, *name;

	error = 0;
	name = (int *)arg1;
	namelen = arg2;
	if (namelen != 1)
		return (EINVAL);
	index = name[0];
        if (index >= MAC_BSDEXTENDED_MAXRULES)
		return (ENOENT);

	ruleptr = NULL;
	if (req->newptr && req->newlen != 0) {
		error = SYSCTL_IN(req, &temprule, sizeof(temprule));
		if (error)
			return (error);
		ruleptr = malloc(sizeof(*ruleptr), M_MACBSDEXTENDED,
		    M_WAITOK | M_ZERO);
	}

	mtx_lock(&ugidfw_mtx);
	if (req->oldptr) {
		if (index < 0 || index > rule_slots + 1) {
			error = ENOENT;
			goto out;
		}
		if (rules[index] == NULL) {
			error = ENOENT;
			goto out;
		}
		temprule = *rules[index];
	}
	if (req->newptr && req->newlen == 0) {
		KASSERT(ruleptr == NULL, ("sysctl_rule: ruleptr != NULL"));
		ruleptr = rules[index];
		if (ruleptr == NULL) {
			error = ENOENT;
			goto out;
		}
		rule_count--;
		rules[index] = NULL;
	} else if (req->newptr) {
		error = ugidfw_rule_valid(&temprule);
		if (error)
			goto out;
		if (rules[index] == NULL) {
			*ruleptr = temprule;
			rules[index] = ruleptr;
			ruleptr = NULL;
			if (index + 1 > rule_slots)
				rule_slots = index + 1;
			rule_count++;
		} else
			*rules[index] = temprule;
	}
out:
	mtx_unlock(&ugidfw_mtx);
	if (ruleptr != NULL)
		free(ruleptr, M_MACBSDEXTENDED);
	if (req->oldptr && error == 0)
		error = SYSCTL_OUT(req, &temprule, sizeof(temprule));
	return (error);
}
예제 #26
0
파일: usb_debug.c 프로젝트: coyizumi/cs111
/*------------------------------------------------------------------------*
 *	usb_timings_sysctl_handler
 *
 * This function updates timings variables, adjusting them where necessary.
 *------------------------------------------------------------------------*/
static int usb_timings_sysctl_handler(SYSCTL_HANDLER_ARGS)
{
	int error = 0;
	unsigned int val;

	/*
	 * Attempt to get a coherent snapshot by making a copy of the data.
	 */
	if (arg1)
		val = *(unsigned int *)arg1;
	else
		val = arg2;
	error = SYSCTL_OUT(req, &val, sizeof(int));
	if (error || !req->newptr)
		return (error);

	if (!arg1)
		return EPERM;

	error = SYSCTL_IN(req, &val, sizeof(unsigned int));
	if (error)
		return (error);

	/*
	 * Now make sure the values are decent, and certainly no lower than
	 * what the USB spec prescribes.
	 */
	unsigned int *p = (unsigned int *)arg1;
	if (p == &usb_port_reset_delay) {
		if (val < USB_PORT_RESET_DELAY_SPEC)
			return (EINVAL);
	} else if (p == &usb_port_root_reset_delay) {
		if (val < USB_PORT_ROOT_RESET_DELAY_SPEC)
			return (EINVAL);
	} else if (p == &usb_port_reset_recovery) {
		if (val < USB_PORT_RESET_RECOVERY_SPEC)
			return (EINVAL);
	} else if (p == &usb_port_powerup_delay) {
		if (val < USB_PORT_POWERUP_DELAY_SPEC)
			return (EINVAL);
	} else if (p == &usb_port_resume_delay) {
		if (val < USB_PORT_RESUME_DELAY_SPEC)
			return (EINVAL);
	} else if (p == &usb_set_address_settle) {
		if (val < USB_SET_ADDRESS_SETTLE_SPEC)
			return (EINVAL);
	} else if (p == &usb_resume_delay) {
		if (val < USB_RESUME_DELAY_SPEC)
			return (EINVAL);
	} else if (p == &usb_resume_wait) {
		if (val < USB_RESUME_WAIT_SPEC)
			return (EINVAL);
	} else if (p == &usb_resume_recovery) {
		if (val < USB_RESUME_RECOVERY_SPEC)
			return (EINVAL);
	} else if (p == &usb_extra_power_up_time) {
		if (val < USB_EXTRA_POWER_UP_TIME_SPEC)
			return (EINVAL);
	} else {
		/* noop */
	}

	*p = val;
	return 0;
}
예제 #27
0
static int
sysctl_machdep_elan_gpio_config(SYSCTL_HANDLER_ARGS)
{
	u_int u, v;
	int i, np, ne;
	int error;
	char buf[32];
	char tmp[10];

	error = SYSCTL_OUT(req, gpio_config, 33);
	if (error != 0 || req->newptr == NULL)
		return (error);
	if (req->newlen != 32)
		return (EINVAL);
	error = SYSCTL_IN(req, buf, 32);
	if (error != 0)
		return (error);
	/* Disallow any disabled pins and count pps and echo */
	np = ne = 0;
	for (i = 0; i < 32; i++) {
		if (gpio_config[i] == '-' && buf[i] == '.')
			buf[i] = gpio_config[i];
		if (gpio_config[i] == '-' && buf[i] != '-')
			return (EPERM);
		if (buf[i] == 'P') {
			np++;
			if (np > 1)
				return (EINVAL);
		}
		if (buf[i] == 'e' || buf[i] == 'E') {
			ne++;
			if (ne > 1)
				return (EINVAL);
		}
		if (buf[i] != 'L' && buf[i] != 'l'
#ifdef CPU_ELAN_PPS
		    && buf[i] != 'P' && buf[i] != 'E' && buf[i] != 'e'
#endif /* CPU_ELAN_PPS */
		    && buf[i] != '.' && buf[i] != '-')
			return (EINVAL);
	}
#ifdef CPU_ELAN_PPS
	if (np == 0)
		pps_a = pps_d = 0;
	if (ne == 0)
		echo_a = echo_d = 0;
#endif
	for (i = 0; i < 32; i++) {
		u = 1 << (i & 0xf);
		if (i >= 16)
			v = 2;
		else
			v = 0;
#ifdef CPU_SOEKRIS
		if (i == 9)
			;
		else
#endif
		if (buf[i] != 'l' && buf[i] != 'L' && led_dev[i] != NULL) {
			led_destroy(led_dev[i]);	
			led_dev[i] = NULL;
			mmcrptr[(0xc2a + v) / 2] &= ~u;
		}
		switch (buf[i]) {
#ifdef CPU_ELAN_PPS
		case 'P':
			pps_d = u;
			pps_a = 0xc30 + v;
			pps_ap[0] = &mmcrptr[pps_a / 2];
			pps_ap[1] = &elan_mmcr->GPTMR2CNT;
			pps_ap[2] = &elan_mmcr->GPTMR1CNT;
			mmcrptr[(0xc2a + v) / 2] &= ~u;
			gpio_config[i] = buf[i];
			break;
		case 'e':
		case 'E':
			echo_d = u;
			if (buf[i] == 'E')
				echo_a = 0xc34 + v;
			else
				echo_a = 0xc38 + v;
			mmcrptr[(0xc2a + v) / 2] |= u;
			gpio_config[i] = buf[i];
			break;
#endif /* CPU_ELAN_PPS */
		case 'l':
		case 'L':
			if (buf[i] == 'L')
				led_cookie[i] = (0xc34 + v) | (u << 16);
			else
				led_cookie[i] = (0xc38 + v) | (u << 16);
			if (led_dev[i])
				break;
			sprintf(tmp, "gpio%d", i);
			mmcrptr[(0xc2a + v) / 2] |= u;
			gpio_config[i] = buf[i];
			led_dev[i] =
			    led_create(gpio_led, &led_cookie[i], tmp);
			break;
		case '.':
			gpio_config[i] = buf[i];
			break;
		case '-':
		default:
			break;
		}
	}
	return (0);
}
예제 #28
0
static int
sysctl_hophandle(SYSCTL_HANDLER_ARGS)
{
    int             error,
                    i;
    struct sysctl_hoptable tab;
    struct sysctl_hop *hops;

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

    hops = malloc(tab.hopcount * sizeof(*hops), M_TEMP, M_WAITOK);
    if (!hops) {
        printf("copyin buf alloc failed\n");
        return ENOMEM;
    }
    copyin(tab.hops, hops, tab.hopcount * sizeof(*hops));

    uninit_paths();

    hoptable = malloc(tab.hopcount * sizeof(*hoptable),
                      M_MN_CONF, M_WAITOK | M_ZERO);

    mtx_lock(mn_mtx);
    
    if (!hoptable) {
        printf("hop alloc failed. (%d KB)\n",
		tab.hopcount * sizeof(*hoptable)/1024);
        
	mtx_unlock(mn_mtx);

        return ENOMEM;
    }

    hopcount = tab.hopcount;

    for (i = 0; i < hopcount; ++i) {
        struct hop     *hop = hoptable + i;

        hop->KBps = hops[i].bandwidth/8; 
        hop->delay = (hz * hops[i].delay) / 1000;
        hop->plr = hops[i].plr;
        hop->qsize = hops[i].qsize;
        hop->emulator = hops[i].emulator;
	hop->bytespertick = hop->KBps*1000/hz;
        hop->id = i;

#if 0
	printf("hoptable: idx(%d) bw(%d) delay(%d) plr(%d) qsize(%d)\n",
	   hop->id,hop->KBps, hop->delay, hop->plr, hop->qsize);
#endif
#ifdef QCALC
if ((hop->qsize*1500)/hop->KBps > (1<<14)/hz ) 
	printf("hop %d: max delay %dms may overrun calender period %dms\n", i,
		(hop->qsize*1500)/hop->KBps , (1<<14)/hz ); 
#endif

        /*
         * initialize bandwidth queue 
         */
        hop->exittick = malloc(hop->qsize * sizeof(*hop->exittick),
                              M_MN_CONF, M_WAITOK);
        if (!hop->exittick) {
            printf("hop alloc failed\n");
            
	    mtx_unlock(mn_mtx);
            return ENOMEM;
        }
        bzero(hop->exittick, sizeof(int *) * hop->qsize);
        hop->slotdepth = 0;
        hop->bytedepth = 0;
        hop->headslot = 0;
        hop->fragment = 0;

	hop->slotlen = malloc(hop->qsize * sizeof(*hop->slotlen),
                              M_MN_CONF, M_WAITOK);
        if (!hop->slotlen) {
            printf("hop alloc failed\n");
            
	    mtx_unlock(mn_mtx);
            return ENOMEM;
        } 	
        bzero(hop->slotlen, sizeof(int *) * hop->qsize);

	xtq_install(hop, hops[i].xtq_type);
    }

    free(hops, M_TEMP);
    
    mtx_unlock(mn_mtx);

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

    return (error);
}
예제 #29
0
static int
sysctl_integriforce_so(SYSCTL_HANDLER_ARGS)
{
    integriforce_so_check_t *integriforce_so;
    secadm_prison_entry_t *entry;
    secadm_rule_t r, *rule;
    struct nameidata nd;
    struct vattr vap;
    secadm_key_t key;
    int err;

    if (!(req->newptr) || req->newlen != sizeof(integriforce_so_check_t))
        return (EINVAL);

    if (!(req->oldptr) || req->oldlen != sizeof(integriforce_so_check_t))
        return (EINVAL);

    integriforce_so = malloc(sizeof(integriforce_so_check_t), M_SECADM, M_WAITOK);

    err = SYSCTL_IN(req, integriforce_so, sizeof(integriforce_so_check_t));
    if (err) {
        free(integriforce_so, M_SECADM);
        return (err);
    }

    NDINIT(&nd, LOOKUP, FOLLOW, UIO_SYSSPACE, integriforce_so->isc_path, req->td);
    err = namei(&nd);
    if (err) {
        free(integriforce_so, M_SECADM);
        NDFREE(&nd, 0);
        return (err);
    }

    if ((err = vn_lock(nd.ni_vp, LK_SHARED | LK_RETRY)) != 0) {
        free(integriforce_so, M_SECADM);
        NDFREE(&nd, 0);
        return (err);
    }

    err = VOP_GETATTR(nd.ni_vp, &vap, req->td->td_ucred);
    if (err) {
        free(integriforce_so, M_SECADM);
        NDFREE(&nd, 0);
        return (err);
    }

    VOP_UNLOCK(nd.ni_vp, 0);

    key.sk_jid = req->td->td_ucred->cr_prison->pr_id;
    key.sk_type = secadm_integriforce_rule;
    key.sk_fileid = vap.va_fileid;
    strncpy(key.sk_mntonname,
            nd.ni_vp->v_mount->mnt_stat.f_mntonname, MNAMELEN);
    r.sr_key = fnv_32_buf(&key, sizeof(secadm_key_t), FNV1_32_INIT);

    entry = get_prison_list_entry(
                req->td->td_ucred->cr_prison->pr_id);

    PE_RLOCK(entry);
    rule = RB_FIND(secadm_rules_tree, &(entry->sp_rules), &r);

    if (rule) {
        integriforce_so->isc_result =
            do_integriforce_check(rule, &vap, nd.ni_vp,
                                  req->td->td_ucred);
    }

    PE_RUNLOCK(entry);

    SYSCTL_OUT(req, integriforce_so, sizeof(integriforce_so_check_t));
    free(integriforce_so, M_SECADM);

    NDFREE(&nd, 0);

    return (0);
}
예제 #30
0
static int
sysctl_ifdata(SYSCTL_HANDLER_ARGS) /* XXX bad syntax! */
{
	int *name = (int *)arg1;
	int error;
	u_int namelen = arg2;
	struct ifnet *ifp;
	struct ifmibdata ifmd;
	size_t dlen;
	char *dbuf;

	if (namelen != 2)
		return EINVAL;
	if (name[0] <= 0)
		return (ENOENT);
	ifp = ifnet_byindex_ref(name[0]);
	if (ifp == NULL)
		return (ENOENT);

	switch(name[1]) {
	default:
		error = ENOENT;
		goto out;

	case IFDATA_GENERAL:
		bzero(&ifmd, sizeof(ifmd));
		strlcpy(ifmd.ifmd_name, ifp->if_xname, sizeof(ifmd.ifmd_name));

#define COPY(fld) ifmd.ifmd_##fld = ifp->if_##fld
		COPY(pcount);
		COPY(data);
#undef COPY
		ifmd.ifmd_flags = ifp->if_flags | ifp->if_drv_flags;
		ifmd.ifmd_snd_len = ifp->if_snd.ifq_len;
		ifmd.ifmd_snd_maxlen = ifp->if_snd.ifq_maxlen;
		ifmd.ifmd_snd_drops = ifp->if_snd.ifq_drops;

		error = SYSCTL_OUT(req, &ifmd, sizeof ifmd);
		if (error || !req->newptr)
			goto out;

		error = SYSCTL_IN(req, &ifmd, sizeof ifmd);
		if (error)
			goto out;

#define DONTCOPY(fld) ifmd.ifmd_data.ifi_##fld = ifp->if_data.ifi_##fld
		DONTCOPY(type);
		DONTCOPY(physical);
		DONTCOPY(addrlen);
		DONTCOPY(hdrlen);
		DONTCOPY(mtu);
		DONTCOPY(metric);
		DONTCOPY(baudrate);
#undef DONTCOPY
#define COPY(fld) ifp->if_##fld = ifmd.ifmd_##fld
		COPY(data);
		ifp->if_snd.ifq_maxlen = ifmd.ifmd_snd_maxlen;
		ifp->if_snd.ifq_drops = ifmd.ifmd_snd_drops;
#undef COPY
		break;

	case IFDATA_LINKSPECIFIC:
		error = SYSCTL_OUT(req, ifp->if_linkmib, ifp->if_linkmiblen);
		if (error || !req->newptr)
			goto out;

		error = SYSCTL_IN(req, ifp->if_linkmib, ifp->if_linkmiblen);
		if (error)
			goto out;
		break;

	case IFDATA_DRIVERNAME:
		/* 20 is enough for 64bit ints */
		dlen = strlen(ifp->if_dname) + 20 + 1;
		if ((dbuf = malloc(dlen, M_TEMP, M_NOWAIT)) == NULL) {
			error = ENOMEM;
			goto out;
		}
		if (ifp->if_dunit == IF_DUNIT_NONE)
			strcpy(dbuf, ifp->if_dname);
		else
			sprintf(dbuf, "%s%d", ifp->if_dname, ifp->if_dunit);

		error = SYSCTL_OUT(req, dbuf, strlen(dbuf) + 1);
		if (error == 0 && req->newptr != NULL)
			error = EPERM;
		free(dbuf, M_TEMP);
		goto out;
	}
out:
	if_rele(ifp);
	return error;
}