Exemplo n.º 1
0
/* ARGSUSED */
static int
dlcosmk_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
    ipp_flags_t flags)
{
	nvlist_t *nvlp;
	dlcosmk_data_t *dlcosmk_data;
	char *next_action;
	int err;

	ASSERT(fn != NULL);

	dlcosmk_data = (dlcosmk_data_t *)ipp_action_get_ptr(aid);
	ASSERT(dlcosmk_data != NULL);

	/* allocate nvlist to be passed back */
	if ((err = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
		dlcosmk0dbg(("dlcosmk_info: error allocating memory\n"));
		return (err);
	}

	/* look up next action with the next action id */
	if ((err = ipp_action_name(dlcosmk_data->next_action,
	    &next_action)) != 0) {
		dlcosmk0dbg(("dlcosmk_info: next action not available\n"));
		nvlist_free(nvlp);
		return (err);
	}

	/* add next action name */
	if ((err = nvlist_add_string(nvlp, DLCOSMK_NEXT_ACTION_NAME,
	    next_action)) != 0) {
		dlcosmk0dbg(("dlcosmk_info: error adding next action\n"));
		nvlist_free(nvlp);
		kmem_free(next_action, (strlen(next_action) + 1));
		return (err);
	}

	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));

	/* add config type */
	if ((err = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
		dlcosmk0dbg(("dlcosmk_info: error adding config. type\n"));
		nvlist_free(nvlp);
		return (err);
	}

	/* just give the cos, since that is what is provided in the config */
	if ((err = nvlist_add_byte(nvlp, DLCOSMK_COS, dlcosmk_data->usr_pri))
	    != 0) {
		dlcosmk0dbg(("dlcosmk_info: error adding cos\n"));
		nvlist_free(nvlp);
		return (err);
	}

	/* add gather stats boolean */
	if ((err = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
	    (dlcosmk_data->gather_stats ? 1 : 0))) != 0) {
		dlcosmk0dbg(("dlcosmk_info: error adding stats status\n"));
		nvlist_free(nvlp);
		return (err);
	}

	/* call back with nvlist */
	err = fn(nvlp, arg);

	nvlist_free(nvlp);
	return (err);
}
Exemplo n.º 2
0
static int
ippctl_mod_list_actions(
	char		*modname)
{
	ipp_mod_id_t	mid;
	nvlist_t	*nvlp;
	int		ipp_rc;
	int		rc = 0;
	ipp_action_id_t	*aid_array;
	char		**aname_array = NULL;
	int		nelt;
	int		length;
	int		i;

	/*
	 * Get the module id.
	 */

	mid = ipp_mod_lookup(modname);
	FREE_TEXT(modname);

	/*
	 * Get a list of all the action ids for the module. If that succeeds,
	 * translate the ids into names.
	 *
	 * NOTE: This translation may fail if an action is
	 * destroyed during this operation. If this occurs, EAGAIN
	 * will be passed back to libipp note that a transient
	 * problem occured.
	 */

	if ((ipp_rc = ipp_mod_list_actions(mid, &aid_array, &nelt)) == 0) {

		/*
		 * It is possible that there are no actions defined.
		 * (This is unlikely though as the module would normally
		 * be auto-unloaded fairly quickly)
		 */

		if (nelt > 0) {
			length = nelt * sizeof (char *);
			aname_array = kmem_zalloc(length, KM_SLEEP);

			for (i = 0; i < nelt; i++) {
				if (ipp_action_name(aid_array[i],
				    &aname_array[i]) != 0) {
					kmem_free(aid_array, nelt *
					    sizeof (ipp_action_id_t));
					FREE_TEXT_ARRAY(aname_array, nelt);
					ipp_rc = EAGAIN;
					goto done;
				}
			}

			kmem_free(aid_array, nelt * sizeof (ipp_action_id_t));

			if ((rc = nvlist_alloc(&nvlp, NV_UNIQUE_NAME,
			    KM_SLEEP)) != 0) {
				FREE_TEXT_ARRAY(aname_array, nelt);
				return (rc);
			}

			if ((rc = ippctl_attach_aname_array(nvlp, aname_array,
			    nelt)) != 0) {
				FREE_TEXT_ARRAY(aname_array, nelt);
				nvlist_free(nvlp);
				return (rc);
			}

			FREE_TEXT_ARRAY(aname_array, nelt);

			if ((rc = ippctl_callback(nvlp, NULL)) != 0) {
				nvlist_free(nvlp);
				return (rc);
			}

			nvlist_free(nvlp);
		}
	}

done:
	/*
	 * Add an nvlist containing the kernel return code to the
	 * set of nvlists to pass back to libipp.
	 */

	if ((rc = ippctl_set_rc(ipp_rc)) != 0)
		return (rc);

	return (0);
}
Exemplo n.º 3
0
/* ARGSUSED */
static int
tswtcl_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
    ipp_flags_t flags)
{
	nvlist_t *nvlp;
	tswtcl_data_t *tswtcl_data;
	tswtcl_cfg_t *cfg_parms;
	char *next_action;
	int rc;

	tswtcl_data = (tswtcl_data_t *)ipp_action_get_ptr(aid);
	ASSERT(tswtcl_data != NULL);

	cfg_parms = tswtcl_data->cfg_parms;

	/* allocate nvlist to be passed back */
	if ((rc = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
		tswtcl0dbg(("tswtcl_info: memory allocation failure\n"));
		return (rc);
	}

	/* look up red next action with the next action id */
	if ((rc = ipp_action_name(cfg_parms->red_action, &next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: red action not available\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add next action name */
	if ((rc = nvlist_add_string(nvlp, TSWTCL_RED_ACTION_NAME,
	    next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding\n"));
		nvlist_free(nvlp);
		kmem_free(next_action, (strlen(next_action) + 1));
		return (rc);
	}

	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));

	/* look up yellow next action with the next action id */
	if ((rc = ipp_action_name(cfg_parms->yellow_action,
	    &next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: yellow action not available\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add next action name */
	if ((rc = nvlist_add_string(nvlp, TSWTCL_YELLOW_ACTION_NAME,
	    next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding yellow action\n"));
		nvlist_free(nvlp);
		kmem_free(next_action, (strlen(next_action) + 1));
		return (rc);
	}
	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));

	/* look up green next action with the next action id */
	if ((rc = ipp_action_name(cfg_parms->green_action,
	    &next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: green action not available\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add next action name */
	if ((rc = nvlist_add_string(nvlp, TSWTCL_GREEN_ACTION_NAME,
	    next_action)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding green action\n"));
		nvlist_free(nvlp);
		kmem_free(next_action, (strlen(next_action) + 1));
		return (rc);
	}

	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));

	/* add config type */
	if ((rc = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding config_type\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add committed_rate  */
	if ((rc = nvlist_add_uint32(nvlp, TSWTCL_COMMITTED_RATE,
	    cfg_parms->committed_rate)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding committed_rate\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add peak_rate  */
	if ((rc = nvlist_add_uint32(nvlp, TSWTCL_PEAK_RATE,
	    cfg_parms->peak_rate)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding peak_rate\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add window  */
	if ((rc = nvlist_add_uint32(nvlp, TSWTCL_WINDOW,
	    cfg_parms->window)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding window\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	if ((rc = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
	    (uint32_t)(uintptr_t)tswtcl_data->stats)) != 0) {
		tswtcl0dbg(("tswtcl_info: error adding stats status\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* call back with nvlist */
	rc = fn(nvlp, arg);

	nvlist_free(nvlp);
	return (rc);
}
Exemplo n.º 4
0
/* ARGSUSED */
static int
tokenmt_info(ipp_action_id_t aid, int (*fn)(nvlist_t *, void *), void *arg,
    ipp_flags_t flags)
{
	nvlist_t *nvlp;
	tokenmt_data_t *tokenmt_data;
	tokenmt_cfg_t *cfg_parms;
	char *next_action;
	int32_t dscp_to_colour[64];
	int rc;

	tokenmt_data = (tokenmt_data_t *)ipp_action_get_ptr(aid);
	ASSERT(tokenmt_data != NULL);

	cfg_parms = tokenmt_data->cfg_parms;

	/* allocate nvlist to be passed back */
	if ((rc = nvlist_alloc(&nvlp, NV_UNIQUE_NAME, KM_NOSLEEP)) != 0) {
		tokenmt0dbg(("tokenmt_info: memory allocation failure\n"));
		return (rc);
	}

	/* look up red next action with the next action id */
	if ((rc = ipp_action_name(cfg_parms->red_action, &next_action)) != 0) {
		tokenmt0dbg(("tokenmt_info: red_action not available\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add next action name */
	if ((rc = nvlist_add_string(nvlp, TOKENMT_RED_ACTION_NAME,
	    next_action)) != 0) {
		nvlist_free(nvlp);
		tokenmt0dbg(("tokenmt_info: error adding red_action\n"));
		kmem_free(next_action, (strlen(next_action) + 1));
		return (rc);
	}

	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));


	/* look up yellow next action with the next action id */
	if (cfg_parms->yellow_action != TOKENMT_NO_ACTION) {
		if ((rc = ipp_action_name(cfg_parms->yellow_action,
		    &next_action)) != 0) {
			tokenmt0dbg(("tokenmt_info: yellow_action not "\
			    "available\n"));
			nvlist_free(nvlp);
			return (rc);
		}
		/* add next action name */
		if ((rc = nvlist_add_string(nvlp, TOKENMT_YELLOW_ACTION_NAME,
		    next_action)) != 0) {
			nvlist_free(nvlp);
			tokenmt0dbg(("tokenmt_info: error adding "\
			    "yellow_action\n"));
			kmem_free(next_action, (strlen(next_action) + 1));
			return (rc);
		}
		/* free action name */
		kmem_free(next_action, (strlen(next_action) + 1));
	}

	/* look up green next action with the next action id */
	if ((rc = ipp_action_name(cfg_parms->green_action,
	    &next_action)) != 0) {
		tokenmt0dbg(("tokenmt_info: green_action not available\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add next action name */
	if ((rc = nvlist_add_string(nvlp, TOKENMT_GREEN_ACTION_NAME,
	    next_action)) != 0) {
		nvlist_free(nvlp);
		tokenmt0dbg(("tokenmt_info: error adding green_action\n"));
		kmem_free(next_action, (strlen(next_action) + 1));
		return (rc);
	}

	/* free action name */
	kmem_free(next_action, (strlen(next_action) + 1));

	/* add config type */
	if ((rc = nvlist_add_byte(nvlp, IPP_CONFIG_TYPE, IPP_SET)) != 0) {
		tokenmt0dbg(("tokenmt_info: error adding config_type\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add committed_rate  */
	if ((rc = nvlist_add_uint32(nvlp, TOKENMT_COMMITTED_RATE,
	    cfg_parms->committed_rate)) != 0) {
		tokenmt0dbg(("tokenmt_info: error adding committed_rate\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	if (cfg_parms->tokenmt_type == TRTCL_TOKENMT) {
		/* add peak  rate */
		if ((rc = nvlist_add_uint32(nvlp, TOKENMT_PEAK_RATE,
		    cfg_parms->peak_rate)) != 0) {
			tokenmt0dbg(("tokenmt_info: error adding peak_rate\n"));
			nvlist_free(nvlp);
			return (rc);
		}
	}

	/* add committed_burst  */
	if ((rc = nvlist_add_uint32(nvlp, TOKENMT_COMMITTED_BURST,
	    cfg_parms->committed_burst)) != 0) {
		tokenmt0dbg(("tokenmt_info: error adding committed_burst\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* add peak_burst  */
	if (cfg_parms->peak_burst != 0) {
		if ((rc = nvlist_add_uint32(nvlp, TOKENMT_PEAK_BURST,
		    cfg_parms->peak_burst)) != 0) {
			tokenmt0dbg(("tokenmt_info: error adding peak "\
			    "burst\n"));
			nvlist_free(nvlp);
			return (rc);
		}
	}

	/* add colour aware  */
	if ((rc = nvlist_add_uint32(nvlp, TOKENMT_COLOUR_AWARE,
	    cfg_parms->colour_aware)) != 0) {
		tokenmt0dbg(("tokenmt_info: error adding mode\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	if (cfg_parms->colour_aware) {
		bcopy(cfg_parms->dscp_to_colour, dscp_to_colour,
		    sizeof (cfg_parms->dscp_to_colour));
		if ((rc = nvlist_add_int32_array(nvlp, TOKENMT_COLOUR_MAP,
		    dscp_to_colour, 64)) != 0) {
			tokenmt0dbg(("tokenmt_info: error adding colour "\
			    "array\n"));
			nvlist_free(nvlp);
			return (rc);
		}
	}

	if ((rc = nvlist_add_uint32(nvlp, IPP_ACTION_STATS_ENABLE,
	    (uint32_t)cfg_parms->stats)) != 0) {
		tokenmt0dbg(("tokenmt_info: error adding stats status\n"));
		nvlist_free(nvlp);
		return (rc);
	}

	/* call back with nvlist */
	rc = fn(nvlp, arg);

	nvlist_free(nvlp);
	return (rc);
}