int cli_ssld_https_show_cmd(
        void *data,
        const cli_command *cmd,
        const tstr_array *cmd_line,
        const tstr_array *params)
{
    int err = 0;
    uint32 num_intfs = 0;
    uint32 num_ports = 0;
    tbool t_conn_pool_status = true;

    UNUSED_ARGUMENT(data);
    UNUSED_ARGUMENT(cmd);
    UNUSED_ARGUMENT(cmd_line);
    UNUSED_ARGUMENT(params);

    err = cli_printf(
            _("Delivery Protocol : HTTPS\n"));
    bail_error(err);

    err = cli_printf(
            _("Server Ports: \n"));
    bail_error(err);

    err = mdc_foreach_binding(cli_mcc, "/nkn/ssld/delivery/config/server_port/*", NULL,
            cli_ssld_https_server_port_show, NULL, &num_ports);
    bail_error(err);
    if (num_ports == 0) {
        cli_printf(
                _("     NONE\n"));
    }

    err = cli_printf(
            _("\nInterfaces:\n"));
    bail_error(err);
    err = mdc_foreach_binding(cli_mcc,
            "/nkn/ssld/delivery/config/server_intf/*", NULL,
            cli_ssld_https_show_interface, NULL, &num_intfs);
    bail_error(err);

    if (num_intfs == 0) {
        err = cli_printf(
                _("     Default (All Configured interfaces)\n"));
        bail_error(err);
    }
    /*Show Connection  pool status*/

    err = mdc_get_binding_tbool(cli_mcc, NULL, NULL, NULL, 
		    &t_conn_pool_status, 
		    "/nkn/ssld/delivery/config/conn-pool/origin/enabled", NULL);
    bail_error(err);

    err = cli_printf(
		_("\nOrigin Connection Pooling: %s\n"), 
		t_conn_pool_status ? "Enabled" : "Disabled");
    bail_error(err);
    /*Show connection pool timeout value*/
    cli_printf_query(_(
                "    Connection Pooling Timeout       : #e:N.A.~/nkn/ssld/delivery/config/conn-pool/origin/timeout# (seconds)\n"));

    /*Show connection pool max-arp-entry value*/
    cli_printf_query(_(
                "    Connection Pooling Max-connection: #e:N.A.~/nkn/ssld/delivery/config/conn-pool/origin/max-conn# \n"));


bail :
    return err;
}
/*
 *	funtion : nvsd_pub_point_delete_cfg_handle_change ()
 *	purpose : handler for config delete changes for publish point module
 */
	int
nvsd_pub_point_delete_cfg_handle_change(const bn_binding_array * arr,
		uint32 idx,
		bn_binding * binding, void *data)
{
	int err = 0;
	const tstring *name = NULL;
	const char *t_pub_point = NULL;
	tstr_array *name_parts = NULL;
	tbool *rechecked_licenses_p = data;

	UNUSED_ARGUMENT(arr);
	UNUSED_ARGUMENT(idx);

	bail_null(rechecked_licenses_p);

	err = bn_binding_get_name(binding, &name);
	bail_error(err);

	/*
	 * Check if this is our node 
	 */
	if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/**")) {
		err = bn_binding_get_name_parts(binding, &name_parts);
		bail_error(err);

		t_pub_point = tstr_array_get_str_quick(name_parts, 4);

		lc_log_basic(LOG_DEBUG,
				"Read .../nkn/nvsd/virtual_player/config as : \"%s\"",
				t_pub_point);

		/*
		 * Delete this only if the wildcard change is received 
		 */
		if (bn_binding_name_pattern_match
				(ts_str(name), "/nkn/nvsd/pub-point/config/*")) {
			/*
			 * Get the pub-point entry in the global array 
			 */
			pstPublishPoint = get_publish_point_element(t_pub_point);
			if (pstPublishPoint && (NULL != pstPublishPoint->name)) {
				// rtsp_no_cfg_pub_point_callback (pstPublishPoint);

				free(pstPublishPoint->name);
				memset(pstPublishPoint, 0, sizeof (pub_point_node_data_t));

				remove_pub_point_in_namespace(t_pub_point);
			}
			/*
			 * Set the flag so that we know this is a dynamic change 
			 */
			dynamic_change = true;
		}
	} else {
		/*
		 * We arent interested in this node .. hence leave 
		 */
		goto bail;
	}

bail:
	tstr_array_free(&name_parts);
	return err;
}								/* end of
Ejemplo n.º 3
0
static void nodeCompletion(const char *buf, size_t bufLength, linenoiseCompletions *lc, uint8_t actionCode,
                           const char *partialNodeString, size_t partialNodeStringLength) {
    UNUSED_ARGUMENT(actionCode);

    // If partialNodeString is still empty, the first thing is to complete the root.
    if (partialNodeStringLength == 0) {
        linenoiseAddCompletionSuffix(lc, buf, bufLength, "/", false, false);
        return;
    }

    // Get all the children of the last fully defined node (/ or /../../).
    char *lastNode = strrchr(partialNodeString, '/');
    if (lastNode == NULL) {
        // No / found, invalid, cannot auto-complete.
        return;
    }

    size_t lastNodeLength = (size_t) (lastNode - partialNodeString) + 1;

    uint8_t dataBuffer[1024];

    // Send request for all children names.
    dataBuffer[0] = GET_CHILDREN;
    dataBuffer[1] = 0; // UNUSED.
    setExtraLen(dataBuffer, 0); // UNUSED.
    setNodeLen(dataBuffer, (uint16_t) (lastNodeLength + 1)); // +1 for terminating NUL byte.
    setKeyLen(dataBuffer, 0); // UNUSED.
    setValueLen(dataBuffer, 0); // UNUSED.

    memcpy(dataBuffer + 10, partialNodeString, lastNodeLength);
    dataBuffer[10 + lastNodeLength] = '\0';

    if (!sendUntilDone(sockFd, dataBuffer, 10 + lastNodeLength + 1)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    if (!recvUntilDone(sockFd, dataBuffer, 4)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    // Decode response header fields (all in little-endian).
    uint8_t action = dataBuffer[0];
    uint8_t type = dataBuffer[1];
    uint16_t msgLength = le16toh(*(uint16_t * )(dataBuffer + 2));

    // Total length to get for response.
    if (!recvUntilDone(sockFd, dataBuffer + 4, msgLength)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    if (action == ERROR || type != STRING) {
        // Invalid request made, no auto-completion.
        return;
    }

    // At this point we made a valid request and got back a full response.
    for (size_t i = 0; i < msgLength; i++) {
        if (strncasecmp((const char *) dataBuffer + 4 + i, lastNode + 1, strlen(lastNode + 1)) == 0) {
            linenoiseAddCompletionSuffix(lc, buf, bufLength - strlen(lastNode + 1), (const char *) dataBuffer + 4 + i,
                                         false, true);
        }

        // Jump to the NUL character after this string.
        i += strlen((const char *) dataBuffer + 4 + i);
    }
}
int
nvsd_disk_mon_handle_get(const char *bname,
	const tstr_array * bname_parts,
	void *data, bn_binding_array * resp_bindings)
{
    int err = 0;
    tbool done = false;
    tbool ext_mon_node = false;
    bn_binding *binding = NULL;
    uint32 num_parts = 0;
    const tstring *last_name_part = NULL;

    UNUSED_ARGUMENT(data);

    /*
     * Check if the node is of interest to us 
     */
    if ((!lc_is_prefix("/nkn/nvsd/diskcache/monitor", bname, false))) {
	/*
	 * Not for us 
	 */
	goto bail;
    }

    num_parts = tstr_array_length_quick(bname_parts);

    if (bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/diskcache/monitor/disk_id/**")) {
	ext_mon_node = true;
    } else if (bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/diskcache/monitor/diskname/**")) {
	ext_mon_node = true;
    }

    last_name_part = tstr_array_get_quick(bname_parts, num_parts - 1);

    /*
     * Check to see if it was a wildcard.  If so, just hand it back to
     * them as a value.   XXX: validation
     */
    if ((lc_is_prefix("/nkn/nvsd/diskcache/monitor/disk_id", bname, false)) ||
	    (lc_is_prefix("/nkn/nvsd/diskcache/monitor/diskname"
			  , bname, false))) {
	err = nvsd_mon_handle_get_wildcard(bname, bname_parts, num_parts,
		last_name_part, resp_bindings,
		&done);
	bail_error(err);
	if (done) {
	    goto bail;
	}
    }

    if (ext_mon_node && !strcmp(ts_str(last_name_part), "diskname")) {
	const tstring *diskid_part = NULL;
	const char *t_diskname = NULL;

	/*
	 * Get the diskid part from the node name 
	 */
	diskid_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskid_part);

	/*
	 * Get the disk name from the diskid 
	 */
	t_diskname = get_diskname_from_diskid(ts_str(diskid_part));
	if (NULL != t_diskname) {
	    /*
	     * Set the node to the disk name 
	     */
	    err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		    ba_value, bt_string, 0, t_diskname);
	    bail_error(err);
	} else {
	    err = 0;
	    goto bail;
	}
    }

    if (ext_mon_node && !strcmp(ts_str(last_name_part), "disktype")) {
	const tstring *diskid_part = NULL;
	const char *t_disktype = NULL;

	/*
	 * Get the diskid part from the node name 
	 */
	diskid_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskid_part);

	/*
	 * Get the disk name from the diskid 
	 */
	t_disktype = get_type_from_diskid(ts_str(diskid_part));
	if (NULL != t_disktype) {
	    /*
	     * Set the node to the disk type 
	     */
	    err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		    ba_value, bt_string, 0, t_disktype);
	    bail_error(err);
	} else {
	    err = 0;
	    goto bail;
	}
    }

    if (ext_mon_node && !strcmp(ts_str(last_name_part), "tier")) {
	const tstring *diskid_part = NULL;
	const char *t_tier = NULL;

	/*
	 * Get the diskid part from the node name 
	 */
	diskid_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskid_part);

	/*
	 * Get the disk name from the diskid 
	 */
	t_tier = get_tier_from_diskid(ts_str(diskid_part));
	if (NULL != t_tier) {
	    /*
	     * Set the node to the tier name 
	     */
	    err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		    ba_value, bt_string, 0, t_tier);
	    bail_error(err);
	} else {
	    err = 0;
	    goto bail;
	}
    }

    else if (ext_mon_node && !strcmp(ts_str(last_name_part), "diskstate")) {
	const tstring *diskid_part = NULL;
	const char *t_disk_state = NULL;

	/*
	 * Get the diskid part from the node name 
	 */
	diskid_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskid_part);

	/*
	 * Get the disk state from the diskid 
	 */
	t_disk_state = get_state_from_diskid(ts_str(diskid_part));

	if (NULL != t_disk_state) {
	    /*
	     * Set the node to the disk state 
	     */
	    err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		    ba_value, bt_string, 0,
		    t_disk_state);
	    bail_error(err);
	} else {
	    err = 0;
	    goto bail;
	}
    } else if (ext_mon_node && !strcmp(ts_str(last_name_part), "disk_id")) {
	const tstring *diskname_part = NULL;
	const char *t_disk_id = NULL;

	/*
	 * Get the diskname part from the node name 
	 */
	diskname_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskname_part);

	/*
	 * Get the disk id from the diskname 
	 */
	t_disk_id = get_diskid_from_diskname(ts_str(diskname_part));
	if (NULL != t_disk_id) {
	    /*
	     * Set the node to the disk id 
	     */
	    err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		    ba_value, bt_string, 0, t_disk_id);
	    bail_error(err);
	} else {
	    err = 0;
	    goto bail;
	}
    } else if (ext_mon_node && !strcmp(ts_str(last_name_part), "pre_format")) {
	const tstring *diskname_part = NULL;
	char ret_msg[MAX_FORMAT_CMD_LEN];

	/*
	 * Get the diskname part from the node name 
	 */
	diskname_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskname_part);

	/*
	 * Get the format command from diskcache module 
	 */
	/*
	 * Call the handler to get the format command string 
	 */
	err = nvsd_mgmt_diskcache_action_hdlr(ts_str(diskname_part),
		NVSD_DC_FORMAT, true, ret_msg);

	/*
	 * Send the response with the format string and the err 
	 */
	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (ext_mon_node && !strcmp(ts_str(last_name_part), "pre_format_sb")) {
	const tstring *diskname_part = NULL;
	char ret_msg[MAX_FORMAT_CMD_LEN];

	/*
	 * Get the diskname part from the node name 
	 */
	diskname_part = tstr_array_get_quick(bname_parts, num_parts - 2);
	bail_null(diskname_part);

	/*
	 * Get the format command from diskcache module 
	 */
	/*
	 * Call the handler to get the format command string 
	 */
	err = nvsd_mgmt_diskcache_action_hdlr(ts_str(diskname_part),
		NVSD_DC_FORMAT_BLOCKS, true,
		ret_msg);

	/*
	 * Send the response with the format string and the err 
	 */
	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    }
    if (binding) {
	err = bn_binding_array_append_takeover(resp_bindings, &binding);
	bail_error(err);
    }

bail:
    return (err);
}
Ejemplo n.º 5
0
Archivo: avp.c Proyecto: ticty/siml2tp
inline int avp_handle_result_code( struct tunnel *t, struct buffer *buf )
{
    //_u16 *ptr;
    struct avp_hdr *hdr = (struct avp_hdr *) buf->current;

    UNUSED_ARGUMENT(t);

    if( !IS_M_SET(hdr->head_node) )
    {
#ifdef DEBUG_AVP
        msg_log( LEVEL_ERR,
                 "%s: M bit not set for msg-type-avp which is required!\n",
                 __func__ );
#endif  /* DEBUG_AVP */
        return -1;
    }

    if( IS_H_SET(hdr->head_node) )
    {
#ifdef DEBUG_AVP
        msg_log( LEVEL_ERR,
                 "%s: H bit cannot be set for %x type avp!\n",
                 __func__,
                 hdr->attribute_type );
#endif  /* DEBUG_AVP */
        return -1;
    }

    if( GET_AVP_LEN(hdr->head_node) < 0x0008 )
    {
#ifdef DEBUG_AVP
        msg_log( LEVEL_ERR,
                 "%s: result_code-type-avp's length is less 8\n",
                 __func__ );
#endif  /* DEBUG_AVP */
        return -1;
    }

//    ptr = (_u16 *)&hdr->attribute_type + 1;

//    if( t->tunnel_state == StopCCN )
//    {
//        t->result_code = *ptr;

//        if( GET_AVP_LEN(hdr->head_node) >= 10
//            && (*ptr == 2 || *ptr == 5) )
//        {
//            t->error_code = *++ptr;
//        }

//        if( GET_AVP_LEN(hdr->head_node) > 10 )
//        {
    /*
            bcopy( ptr + 1,
                   t->err_msg,
                   GET_AVP_LEN(hdr->head_node) - 10 >= MAX_ERR_MSG_LEN ? \
                   MAX_ERR_MSG_LEN :
                   GET_AVP_LEN(hdr->head_node) - 10 );
                   */

//            t->err_msg[MAX_ERR_MSG_LEN - 1] = '\0';
//        }
//    }
//    else if( t->call.call_state == CDN )
//    {
//        t->call.result_code = *ptr;

//        if( GET_AVP_LEN(hdr->head_node) >= 10
//            && *ptr == 2 )
//        {
//            t->call.error_code = *++ptr;
//        }

//        if( GET_AVP_LEN(hdr->head_node) > 10 )
//        {
    /*
            bcopy( ptr + 1,
                   t->call.err_msg,
                   GET_AVP_LEN(hdr->head_node) - 10 >= MAX_ERR_MSG_LEN ? \
                   MAX_ERR_MSG_LEN :
                   GET_AVP_LEN(hdr->head_node) - 10 );
                   */

//            t->call.err_msg[MAX_ERR_MSG_LEN - 1] = '\0';
//        }
//    }

    buf->current += GET_AVP_LEN(hdr->head_node);

    return 0;
}
/*----------------------------------------------------------------------------
 * MODULE ENTRY POINT
 *---------------------------------------------------------------------------*/
int
cli_bgp_cmds_init(
        const lc_dso_info *info,
        const cli_module_context *context)
{
    int err = 0;
    cli_command *cmd = NULL;

    UNUSED_ARGUMENT(info);
    UNUSED_ARGUMENT(context);

    if (context->cmc_mgmt_avail == false) {
        goto bail;
    }

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router";
    cmd->cc_help_descr      = N_("Configure router");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router";
    cmd->cc_help_descr      = N_("Remove router configurations");
    CLI_CMD_REGISTER; 

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp";
    cmd->cc_help_descr      = N_("Configure BGP");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp";
    cmd->cc_help_descr      =  N_("Remove BGP configurations");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp *";
    cmd->cc_help_exp        = N_("<1-4294967295>");
    cmd->cc_help_exp_hint   = N_("AS number");
    cmd->cc_flags           = ccf_terminal | ccf_prefix_mode_root;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_comp_type       = cct_matching_names;
    cmd->cc_comp_pattern    = "/nkn/bgp/config/local_as/*";
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$";
    cmd->cc_exec_value      = "$1$";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp *";
    cmd->cc_help_exp        = N_("<1-4294967295>");
    cmd->cc_help_exp_hint   = N_("AS number");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_comp_type       = cct_matching_names;
    cmd->cc_comp_pattern    = "/nkn/bgp/config/local_as/*";
    cmd->cc_exec_operation  = cxo_delete;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * no";
    cmd->cc_help_descr      =  N_("Clear/remove existing BGP configuration options");
    cmd->cc_req_prefix_count =  3;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * neighbor";
    cmd->cc_help_descr      = N_("Specify neighbor router");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * neighbor";
    cmd->cc_help_descr      = N_("Specify neighbor router");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * neighbor *";
    cmd->cc_help_exp        = N_("<A.B.C.D>");
    cmd->cc_help_exp_hint   = N_("IP address");
    cmd->cc_comp_type       = cct_matching_names;
    cmd->cc_comp_pattern    = "/nkn/bgp/config/local_as/$1$/neighbor/*";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * neighbor *";
    cmd->cc_help_exp        = N_("<A.B.C.D>");
    cmd->cc_help_exp_hint   = N_("IP address");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_comp_type       = cct_matching_names;
    cmd->cc_comp_pattern    = "/nkn/bgp/config/local_as/$1$/neighbor/*";
    cmd->cc_exec_operation  = cxo_delete;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/neighbor/$2$";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * neighbor * remote-as";
    cmd->cc_help_descr      = N_("Remote AS number");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * neighbor * remote-as *";
    cmd->cc_help_exp        = N_("<1-4294967295>");
    cmd->cc_help_exp_hint   = N_("AS number");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/neighbor/$2$/remote_as";
    cmd->cc_exec_value      = "$3$";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_revmap_type     = crt_auto;
    cmd->cc_revmap_order    = cro_bgp;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * neighbor * shutdown";
    cmd->cc_help_descr      = N_("Shutdown the neighbor");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/neighbor/$2$/shutdown";
    cmd->cc_exec_value      = "true";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * neighbor * shutdown";
    cmd->cc_help_descr      = N_("Cancel shutdown of the neighbor");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_reset;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/neighbor/$2$/shutdown";
    cmd->cc_exec_value      = "false";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/neighbor/*/shutdown";
    cmd->cc_revmap_callback = cli_bgp_neighbor_shutdown_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * network";
    cmd->cc_help_descr      = N_("Specify a network to announce via BGP");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * network";
    cmd->cc_help_descr      = N_("Specify a network to remove");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * network *";
    cmd->cc_help_exp        = N_("<A.B.C.D>");
    cmd->cc_help_exp_hint   = N_("Prefix");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * network *";
    cmd->cc_help_exp        = N_("<A.B.C.D>");
    cmd->cc_help_exp_hint   = N_("Prefix");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * network * *";
    cmd->cc_help_exp        = N_("/<0-32>");
    cmd->cc_help_exp_hint   = N_("Mask length");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_magic           = BGP_ADD;
    cmd->cc_exec_callback   = cli_bgp_network;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/network/*/*";
    cmd->cc_revmap_cmds     = "router bgp $5$ network $7$ /$8$";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * network * *";
    cmd->cc_help_exp        = N_("/<0-32>");
    cmd->cc_help_exp_hint   = N_("Mask length");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_magic           = BGP_DELETE;
    cmd->cc_exec_callback   = cli_bgp_network;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * redistribute";
    cmd->cc_help_descr      = N_("Redistribute routes");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * redistribute";
    cmd->cc_help_descr      = N_("Stop redistribution");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * redistribute connected";
    cmd->cc_help_descr      = N_("Redistribute connected");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/redist_conn";
    cmd->cc_exec_value      = "true";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/redist_conn";
    cmd->cc_revmap_callback = cli_bgp_redist_conn_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * redistribute connected";
    cmd->cc_help_descr      = N_("Remove connected routes");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/redist_conn";
    cmd->cc_exec_value      = "false";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * bgp";
    cmd->cc_help_descr      = N_("BGP specific commands");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * bgp";
    cmd->cc_help_descr      = N_("BGP specific commands");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * bgp log-neighbor-changes";
    cmd->cc_help_descr      = N_("Log neighbor up/down and reset reason");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_reset;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/log_neighbor";
    cmd->cc_revmap_type     = crt_none;
    CLI_CMD_REGISTER;
    
    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * bgp log-neighbor-changes";
    cmd->cc_help_descr      = N_("Do not log neighbor up/down and reset reason");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/log_neighbor";
    cmd->cc_exec_value      = "false";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/log_neighbor";
    cmd->cc_revmap_callback = cli_bgp_log_neighbor_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * bgp router-id";
    cmd->cc_help_descr      = N_("Override default router ID");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * bgp router-id *";
    cmd->cc_help_exp        = N_("<A.B.C.D>");
    cmd->cc_help_exp_hint   = N_("Manually configured router id");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/router_id";
    cmd->cc_exec_value      = "$2$";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/router_id";
    cmd->cc_revmap_callback = cli_bgp_router_id_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * bgp router-id";
    cmd->cc_help_descr      = N_("Use default router ID");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/router_id";
    cmd->cc_exec_value      = "false";
    cmd->cc_exec_type       = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * timers";
    cmd->cc_help_descr      = N_("Adjust routing timers");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * timers";
    cmd->cc_help_descr      = N_("Use default routing timers");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * timers bgp";
    cmd->cc_help_descr      = N_("BGP timers");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * timers bgp *";
    cmd->cc_help_exp        = N_("<0-21845>");
    cmd->cc_help_exp_hint   = N_("Keepalive interval");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "router bgp * timers bgp * *";
    cmd->cc_help_exp        = N_("<0-65535>");
    cmd->cc_help_exp_hint   = N_("Holdtime");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/timer_ka";
    cmd->cc_exec_value      = "$2$";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_exec_name2      = "/nkn/bgp/config/local_as/$1$/timer_hold";
    cmd->cc_exec_value2     = "$3$";
    cmd->cc_exec_type2      = bt_string;
    cmd->cc_revmap_type     = crt_manual;
    cmd->cc_revmap_order    = cro_bgp;
    cmd->cc_revmap_names    = "/nkn/bgp/config/local_as/*/timer_ka";
    cmd->cc_revmap_callback = cli_bgp_timers_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "no router bgp * timers bgp";
    cmd->cc_help_descr      = N_("BGP timers");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_set_rstr_curr;
    cmd->cc_exec_operation  = cxo_set;
    cmd->cc_exec_name       = "/nkn/bgp/config/local_as/$1$/timer_ka";
    cmd->cc_exec_value      = "false";
    cmd->cc_exec_type       = bt_string;
    cmd->cc_exec_name2      = "/nkn/bgp/config/local_as/$1$/timer_hold";
    cmd->cc_exec_value2     = "false";
    cmd->cc_exec_type2      = bt_string;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "show bgp";
    cmd->cc_help_descr      = N_("Display BGP information");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_query_rstr_curr;
    cmd->cc_exec_callback   = cli_show_bgp;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str       = "clear bgp";
    cmd->cc_help_descr      = N_("Clear BGP neighbors");
    cmd->cc_flags           = ccf_terminal;
    cmd->cc_capab_required  = ccp_query_rstr_curr;
    cmd->cc_exec_callback   = cli_clear_bgp;
    CLI_CMD_REGISTER;

    err = cli_revmap_ignore_bindings_arr(bgp_ignore_bindings);
bail:
    return err;
}
int
cli_nvsd_tfm_cmds_init(
        const lc_dso_info *info,
        const cli_module_context *context)
{
    int err = 0;
    cli_command *cmd = NULL;

    UNUSED_ARGUMENT(info);

#ifdef PROD_FEATURE_I18N_SUPPORT
    err = cli_set_gettext_domain(GETTEXT_DOMAIN);
    bail_error(err);
#endif

    if (context->cmc_mgmt_avail == false) {
        goto bail;
    }

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache";
    cmd->cc_help_descr =        N_("Configure temporary file manager (TFM) options");
    cmd->cc_flags =             ccf_hidden;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-files";
    cmd->cc_help_descr =        N_("Configure maximum number of files that can be stored in TFM");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-files *";
    cmd->cc_help_exp =          N_("<number of files>");
    cmd->cc_help_exp_hint =     N_("Maximum number of files to store. (Default - 25)");
    //cmd->cc_flags =             ccf_terminal;
    //cmd->cc_capab_required =    ccp_set_rstr_curr;
    //cmd->cc_exec_operation =    cxo_set;
    //cmd->cc_revmap_type =       crt_auto;
    //cmd->cc_revmap_order =      cro_namespace;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-files * partial-file";
    cmd->cc_help_descr =        N_("Configure partial file options, such as eviction time, etc.");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-files * partial-file timeout";
    cmd->cc_help_descr =        N_("Configure partial file eviction time");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-files * partial-file timeout *";
    cmd->cc_help_exp =          N_("<seconds>");
    cmd->cc_help_exp_hint =     N_("Time in seconds for eviction of partial files");
    cmd->cc_flags =             ccf_terminal;
    cmd->cc_capab_required =    ccp_set_rstr_curr;
    cmd->cc_exec_operation =    cxo_set;
    cmd->cc_exec_name =         "/nkn/nvsd/tfm/config/partial_file/evict_time";
    cmd->cc_exec_value =        "$2$";
    cmd->cc_exec_type =         bt_uint32;
    cmd->cc_exec_name2 =         "/nkn/nvsd/tfm/config/max_num_files";
    cmd->cc_exec_type2 =         bt_uint32;
    cmd->cc_exec_value2 =        "$1$";
    cmd->cc_revmap_type =       crt_none;
    CLI_CMD_REGISTER;


    CLI_CMD_NEW;
    cmd->cc_words_str =         "show temp-file-cache";
    cmd->cc_help_descr =        N_("Display TFM configuration");
    cmd->cc_flags =             ccf_terminal | ccf_hidden;
    cmd->cc_capab_required =    ccp_query_rstr_curr;
    cmd->cc_exec_callback =     cli_nvsd_tfm_show_cmd;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-file-size";
    cmd->cc_help_descr =        N_("Configure maximum number of files that can be stored in TFM");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =         "temp-file-cache max-file-size *";
    cmd->cc_help_exp =          N_("<bytes>");
    cmd->cc_help_exp_hint =     N_("Maximum file size. (Default - 10000000)");
    cmd->cc_flags =             ccf_terminal;
    cmd->cc_capab_required =    ccp_set_rstr_curr;
    cmd->cc_exec_operation =    cxo_set;
    cmd->cc_exec_name = 	"/nkn/nvsd/tfm/config/max_file_size";
    cmd->cc_exec_value = 	"$1$";
    cmd->cc_exec_type = 	bt_int32;
    CLI_CMD_REGISTER;



    err = cli_revmap_ignore_bindings_va(4, "/nkn/nvsd/fmgr/config/*",
            "/nkn/nvsd/tfm/config/max_num_files",
            "/nkn/nvsd/tfm/config/max_file_size",
            "/nkn/nvsd/tfm/config/partial_file/evict_time");
    bail_error(err);

bail:
    return err;
}
/*Dummy output function for scheduler*/
void auth_mgr_cleanup(nkn_task_id_t id)
{
    UNUSED_ARGUMENT(id);
    return;
}
void *auth_mgr_adns_handler_epoll(void *arg)
{
    //struct timeval *tvp, tv, tv_copy;
    ares_socket_t dns_client_fds[16] = {0};
    struct epoll_event ev, events[DNS_MAX_EVENTS];
    int i,bitmask,nfds, epollfd, timeout, fd_count, ret;

    UNUSED_ARGUMENT(arg);
    memset(dns_client_fds, 0, sizeof(dns_client_fds));

    memset((char *)&ev, 0, sizeof(struct epoll_event));
    memset((char *)&events[0], 0, sizeof(events));

    epollfd = epoll_create(DNS_MAX_SERVERS);
    if (epollfd < 0) {
        DBG_LOG(SEVERE, MOD_AUTHMGR, "epoll_create() error");
        assert(0);
    }

    prctl(PR_SET_NAME, "nvsd-adns", 0, 0, 0);

    /*Infinite loop, to process all the dns responses. Each channel can handle
     16 name servers in RR fashion. Inside each channel there is one socket
    dedicated for one nameserver. So if there are 2 nameservers in /etc/resol.conf
    , then c-ares will assign 2 fds to the channel*/
    while(1)
    {
        nfds=0;
        bitmask=0;
        for (i =0; i < DNS_MAX_SERVERS ; i++) {
            if (dns_client_fds[i] > 0) {
                if (epoll_ctl(epollfd, EPOLL_CTL_DEL, dns_client_fds[i], NULL) < 0) {
                    //not a serious problem, strange that we should hit this case
                    continue;
                }
            }
        }
        memset(dns_client_fds, 0, sizeof(dns_client_fds));
        pthread_mutex_lock(&cares_mutex);
        bitmask = ares_getsock(channel, dns_client_fds, DNS_MAX_SERVERS);
        for (i =0; i < DNS_MAX_SERVERS ; i++) {
            if (dns_client_fds[i] > 0) {
                ev.events = 0;
                if (ARES_GETSOCK_READABLE(bitmask, i)) {
                    ev.events |= EPOLLIN;
                }
                if (ARES_GETSOCK_WRITABLE(bitmask, i)) {
                    ev.events |= EPOLLOUT;
                }
                ev.data.fd = dns_client_fds[i];
                if (epoll_ctl(epollfd, EPOLL_CTL_ADD, dns_client_fds[i], &ev) < 0) {
                    if(errno == EEXIST) {
                        nfds++;
                        continue;
                    }
                    DBG_LOG(SEVERE, MOD_AUTHMGR, "%d fd has trouble when adding to epoll:%s\n",
                            dns_client_fds[i], strerror(errno));
                    continue;
                }
                nfds++;
            }
        }
        if(nfds==0)
        {
            pthread_cond_wait(&cares_cond, &cares_mutex);
            pthread_mutex_unlock(&cares_mutex);
            continue;
        }
        //tvp = ares_timeout(channel, NULL, &tv);
        //memcpy(&tv_copy, tvp, sizeof(struct timeval));
        pthread_mutex_unlock(&cares_mutex);
        //timeout = (tv_copy.tv_sec)*1000;//millisecs
        timeout = 1000;//millisecs
        /*********************************************************
        The default timeout was 5 seconds with default retries
        as 4. The timeout algorith that c-ares adopts, has
        timeout increasing linearly for every retry, and can
        go upto 75secs(~5+~10+~20+~40). To avoid such a big
        block in our select, reduced the timeout to 3secs
        and retries to 2, so max blocking limited to 9 secs
        Changes in ares_init.
        ******************************************************/
        fd_count = epoll_wait(epollfd, events, DNS_MAX_EVENTS, timeout);
        if (fd_count < 0) {
            DBG_LOG(SEVERE, MOD_AUTHMGR, "epoll_wait failed:%s", strerror(errno));
            continue;
        }
        pthread_mutex_lock(&cares_mutex);
        if (fd_count > 0) {
            for (i = 0; i < fd_count; ++i) {
                ares_process_fd(channel,
                                ((events[i].events) & (EPOLLIN) ?
                                 events[i].data.fd:ARES_SOCKET_BAD),
                                ((events[i].events) & (EPOLLOUT)?
                                 events[i].data.fd:ARES_SOCKET_BAD));
            }
        } else {
            ares_process_fd(channel, ARES_SOCKET_BAD, ARES_SOCKET_BAD);
        }
        if (channel_ready == 0 ) {
            ares_destroy(channel);
            //re-init the channel to get a new port
            ret = ares_init_options(&channel, &options, optmask);
            if (ret != ARES_SUCCESS) {
                DBG_LOG(SEVERE, MOD_AUTHMGR,"ares_init: %d %s", ret, ares_strerror(ret));
                assert(0);
            }
            channel_ready = 1;
            AO_fetch_and_add1(&glob_dns_channel_reinit);
        }
        pthread_mutex_unlock(&cares_mutex);
    }
}
void cares_callback_req(void *argdata, int status, int timeouts,
                        unsigned char *abuf, int alen)
{
    UNUSED_ARGUMENT(timeouts);
    struct hostent *hostptr = NULL;
    int is_a_reply = 0;
    int nttl, cnt = 0;
    int i;
    struct ares_addrttl *ttls = (struct ares_addrttl*)
                                nkn_malloc_type(sizeof(struct ares_addrttl) * nkn_max_domain_ips,
                                        mod_auth_addrttl);
    struct ares_addr6ttl *ttls6 = (struct ares_addr6ttl*)
                                  nkn_malloc_type(sizeof(struct ares_addr6ttl) * nkn_max_domain_ips,
                                          mod_auth_addr6ttl);

    if (http_cfg_fo_use_dns)
        nttl = nkn_max_domain_ips;
    else
        nttl = 1;

    auth_dns_t* pdns = (auth_dns_t*)(((auth_msg_t*)(argdata))->authdata);
    if (pdns == NULL) {
        DBG_LOG(ERROR, MOD_AUTHMGR, "invalid pdns entry");
        free(ttls);
        free(ttls6);
        return;
    }

    pdns->resolved = 0;
    if(status != ARES_SUCCESS) {
        ip_addr_t ip;
        ip.addr.v4.s_addr = INADDR_NONE;
        ip.family = AF_INET;
        memcpy(&pdns->ip[0], &ip, sizeof(ip_addr_t));
        pdns->ttl[0] = DEFAULT_DNS_ERR_TTL; //nvsd defaults
        pdns->num_ips = 1;
        DBG_LOG(ERROR, MOD_AUTHMGR,
                "Dnslookup for domain:%s failed:%s", pdns->domain,
                ares_strerror(status));
        AO_fetch_and_add1(&glob_dns_task_failed);
        AO_fetch_and_add1(&glob_dns_task_completed);
        free(ttls);
        free(ttls6);
    } else {
        if (pdns->ip[0].family == AF_INET) {
            status = ares_parse_a_reply(abuf, alen, &hostptr, ttls, &nttl);
            is_a_reply = 1;
        } else {
            status = ares_parse_aaaa_reply(abuf, alen, &hostptr, ttls6, &nttl);
        }
        if (status != ARES_SUCCESS || !hostptr) {
            ip_addr_t ip;
            ip.addr.v4.s_addr = INADDR_NONE;
            ip.family = AF_INET;
            memcpy(&pdns->ip[0], &ip, sizeof(ip_addr_t));
            pdns->ttl[0] = DEFAULT_DNS_ERR_TTL; //nvsd defaults
            pdns->num_ips = 1;
            DBG_LOG(ERROR, MOD_AUTHMGR,
                    "Dnslookup for domain:%s failed:%s in parsing ",
                    pdns->domain,ares_strerror(status));
            AO_fetch_and_add1(&glob_dns_task_failed);
            AO_fetch_and_add1(&glob_dns_task_completed);
            free(ttls);
            free(ttls6);
        } else	{
            for (i=0, cnt=nttl-1; i<nttl && cnt>=0; i++, cnt--) {
                /* multiple RR are given and we are chosing only
                 * the first one, so ttls[0].ipaddr will also provide
                 * the ip, memcopy not needed, its just assignment*/
                if (hostptr->h_length > (int)sizeof(struct in6_addr)) {
                    DBG_LOG(ERROR, MOD_AUTHMGR, "incorrect host->h_length");
                } else {
                    if (is_a_reply) {
                        memcpy(&(pdns->ip[i].addr.v4.s_addr), &ttls[cnt].ipaddr.s_addr, sizeof(in_addr_t));
                        pdns->ip[i].family = AF_INET;
                        //apply nvsd default if something is wrong
                        pdns->ttl[i] = (ttls[cnt].ttl<0)? DEFAULT_DNS_TTL:ttls[cnt].ttl;
                    } else {
                        memcpy(&(pdns->ip[i].addr.v6), &ttls6[cnt].ip6addr, sizeof(struct in6_addr));
                        pdns->ip[i].family = AF_INET6;
                        //apply nvsd default if something is wrong
                        pdns->ttl[i] = (ttls6[cnt].ttl<0)? DEFAULT_DNS_TTL:ttls6[cnt].ttl;
                    }

                    if (is_loopback(&(pdns->ip[i])) == 0) {
                        pdns->resolved = 1;
                    }
                }
            }
            pdns->num_ips = nttl;
            AO_fetch_and_add1(&glob_dns_task_completed);

            //free ares memory
            ares_free_hostent(hostptr);
            free(ttls);
            free(ttls6);
        }
    }

    /* Negative hashing, forcing a failure in find_origin_server*/
    dns_hash_and_insert((char*)pdns->domain, &pdns->ip[0], &pdns->ttl[0], pdns->resolved, pdns->num_ips);

    nkn_task_set_action_and_state((nkn_task_id_t)(pdns->auth_task_id),
                                  TASK_ACTION_OUTPUT, TASK_STATE_RUNNABLE);

    if (enable_reinit && (status == ARES_ESERVFAIL)) {
        /*
         * something is wrong here. BIND9 servers do not respond to this
         * channel after encountering this error, so reset everything
         */
        channel_ready = 0;
        AO_fetch_and_add1(&glob_dns_servfail);
    }
}
/*Dummy output function for scheduler*/
void auth_mgr_output(nkn_task_id_t id)
{
    UNUSED_ARGUMENT(id);
    return;
}
/*----------------------------------------------------------------------------
 * MODULE ENTRY POINT
 *---------------------------------------------------------------------------*/
int
cli_ssld_delivery_cmds_init(
        const lc_dso_info *info,
        const cli_module_context *context)
{
    int err = 0;
    cli_command *cmd = NULL;
    void *callback = NULL;


    UNUSED_ARGUMENT(info);
    UNUSED_ARGUMENT(context);


#ifdef PROD_FEATURE_I18N_SUPPORT
    err = cli_set_gettext_domain(GETTEXT_DOMAIN);
    bail_error(err);
#endif

    if (context->cmc_mgmt_avail == false) {
        goto bail;
    }

    err = lc_dso_module_get_symbol(info->ldi_context, 
            "cli_interface_cmds", "cli_interface_validate", 
            &callback);

    bail_error_null(err, callback);
    cli_interface_validate = (callback);


    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https";
    cmd->cc_help_descr =            N_("Configure HTTPS protocol options");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https listen";
    cmd->cc_help_descr =            N_("Configure listen port parameters");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https listen port";
    cmd->cc_help_descr =            N_("Set listening port parameters");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https listen";
    cmd->cc_help_descr =            N_("Clear listen port parameters");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https listen port *";
    cmd->cc_help_exp =              N_("<port number>");
    cmd->cc_help_exp_hint =         N_("for example, listen port 443");
    cmd->cc_help_use_comp =         true;
    cmd->cc_comp_type =             cct_matching_values ;
    cmd->cc_comp_pattern =          "/nkn/ssld/config/delivery/server_port/*";
    cmd->cc_flags =                 ccf_terminal | ccf_allow_extra_params;
    cmd->cc_capab_required =        ccp_set_basic_curr;
    cmd->cc_magic           =       cid_https_port_add;
    cmd->cc_revmap_order =          cro_delivery;
    cmd->cc_revmap_type =           crt_manual;
    cmd->cc_exec_callback  =        cli_ssld_config_port;
    cmd->cc_revmap_names =          "/nkn/ssld/delivery/config/server_port/*";
    cmd->cc_revmap_cmds =           "delivery protocol https listen port $v$";
    CLI_CMD_REGISTER;


    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https";
    cmd->cc_help_descr =            N_("Clear https related configuration");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https listen port";
    cmd->cc_help_descr =            N_("Reset listening port parameters");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https listen port *";
    cmd->cc_help_exp =              N_("<port number>");
    cmd->cc_help_exp_hint =         N_("for example, listen port 443 444 445-450");
    cmd->cc_help_use_comp =         true;
    cmd->cc_comp_type =             cct_matching_values;
    cmd->cc_comp_pattern =          "/nkn/ssld/delivery/config/server_port/*";
    cmd->cc_flags =                 ccf_terminal | ccf_allow_extra_params;
    cmd->cc_capab_required =        ccp_set_basic_curr;
    cmd->cc_exec_callback  =        cli_ssld_config_port;
    cmd->cc_magic           =       cid_https_port_delete;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https interface";
    cmd->cc_help_descr =            N_("Set the interface on which https will run");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https interface *";
    cmd->cc_help_exp =              N_("<Interface name>");
    cmd->cc_help_exp_hint =         N_("for example, eth0");
    cmd->cc_help_use_comp =         true;
    cmd->cc_comp_type =             cct_matching_values ;
    cmd->cc_comp_pattern =          "/nkn/ssld/config/delivery/server_intf/*";
    cmd->cc_flags =                 ccf_terminal | ccf_allow_extra_params;
    cmd->cc_capab_required =        ccp_set_basic_curr;
    cmd->cc_revmap_order =          cro_delivery;
    cmd->cc_revmap_type =           crt_manual;
    cmd->cc_exec_callback  =        cli_ssld_https_interface_config;
    cmd->cc_revmap_names =          "/nkn/ssld/delivery/config/server_intf/*";
    cmd->cc_revmap_cmds =           "delivery protocol https interface $v$";
    CLI_CMD_REGISTER;


    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https interface";
    cmd->cc_help_descr =            N_("Clear https listen interfaces");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no delivery protocol https interface *";
    cmd->cc_help_exp =              N_("<Interface name>");
    cmd->cc_help_exp_hint =         N_("for example, eth0");
    cmd->cc_help_use_comp =         true;
    cmd->cc_comp_type =             cct_matching_values;
    cmd->cc_comp_pattern =          "/nkn/ssld/delivery/config/server_intf/*";
    cmd->cc_flags =                 ccf_terminal | ccf_allow_extra_params;
    cmd->cc_capab_required =        ccp_set_basic_curr;
    cmd->cc_exec_callback  =        cli_ssld_https_interface_config;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool";
    cmd->cc_help_descr =            "Configure connection pooling parameters";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool origin";
    cmd->cc_help_descr =            "Configure origin side connection pooling parmeters";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool origin enable";
    cmd->cc_help_descr =            "Enable origin side connection pooling";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_priv_curr;
    cmd->cc_exec_operation =        cxo_set;
    cmd->cc_exec_name =             "/nkn/ssld/delivery/config/conn-pool/origin/enabled";
    cmd->cc_exec_value =            "true";
    cmd->cc_exec_type =             bt_bool;
    cmd->cc_revmap_type =           crt_auto;
    cmd->cc_revmap_order =          cro_delivery;
    //cmd->cc_revmap_callback =       cli_nvsd_http_revmap;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool origin disable";
    cmd->cc_help_descr =            "Disable origin side connection pooling";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_priv_curr;
    cmd->cc_exec_operation =        cxo_set;
    cmd->cc_exec_name =             "/nkn/ssld/delivery/config/conn-pool/origin/enabled";
    cmd->cc_exec_value =            "false";
    cmd->cc_exec_type =             bt_bool;
    cmd->cc_exec_callback = 		cli_ssld_https_conn_pool_disable;
    cmd->cc_revmap_type =           crt_auto;
    cmd->cc_revmap_order =          cro_delivery;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool origin timeout";
    cmd->cc_help_descr =            "Configure timeout value for connections in the origin side connection pool";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "delivery protocol https conn-pool origin timeout *";
    cmd->cc_help_exp =              "<seconds>";
    cmd->cc_help_exp_hint =         "Timeout, Default: 90 seconds";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_rstr_curr;
    cmd->cc_exec_operation =        cxo_set;
    cmd->cc_exec_name =             "/nkn/ssld/delivery/config/conn-pool/origin/timeout";
    cmd->cc_exec_value =            "$1$";
    cmd->cc_exec_type =             bt_uint32;
    cmd->cc_revmap_type =           crt_manual;
    cmd->cc_revmap_order =          cro_delivery;
    cmd->cc_revmap_names =          "/nkn/ssld/delivery/config/conn-pool/origin/timeout";
    cmd->cc_revmap_cmds =           "delivery protocol http conn-pool origin timeout $v$";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str = 	"delivery protocol https conn-pool origin max-conn";
    cmd->cc_help_descr = 	"Configure maximum number of connections that can be"
		    " opened to the origin server concurrently";
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str = 	"delivery protocol https conn-pool origin max-conn *";
    cmd->cc_help_exp = 		"<number>";
    cmd->cc_help_exp_hint = 	"Number of connections, Default: 4096, max: 128000, 0: demand driven";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_rstr_curr;
    cmd->cc_exec_operation =        cxo_set;
    cmd->cc_exec_name =             "/nkn/ssld/delivery/config/conn-pool/origin/max-conn";
    cmd->cc_exec_value =            "$1$";
    cmd->cc_exec_type =             bt_uint32;
    cmd->cc_revmap_type =           crt_manual;
    cmd->cc_revmap_order =          cro_delivery;
    cmd->cc_revmap_names =          "/nkn/ssld/delivery/config/conn-pool/origin/max-conn";
    cmd->cc_revmap_cmds =           "delivery protocol https conn-pool origin max-conn $v$";
    CLI_CMD_REGISTER;


    CLI_CMD_NEW;
    cmd->cc_words_str =             "show delivery protocol https";
    cmd->cc_help_descr =            "Display HTTPS configuration options";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_query_rstr_curr;
    cmd->cc_exec_callback =         cli_ssld_https_show_cmd;
    CLI_CMD_REGISTER;


bail:
    return err;
}
int
cli_ssld_config_port(void *data, const cli_command *cmd,
			const tstr_array *cmd_line,
			const tstr_array *params)

{
    int err = 0;
    bn_binding_array *barr = NULL;
    uint32 code = 0;
    uint32 num_params = 0;
    const char *param = NULL;
    uint32 i = 0;
    uint16 j = 0;
    char *p = NULL;
    const char *port = NULL;
    char *port_num = NULL;

    UNUSED_ARGUMENT(data);
    UNUSED_ARGUMENT(cmd_line);

    port = tstr_array_get_str_quick(params, 0);
    bail_null(port);

    num_params = tstr_array_length_quick(params);

    //tstr_array_print(params, "param");

    switch(cmd->cc_magic) 
    {
    case cid_https_port_add:
        
        err = bn_binding_array_new(&barr);
        bail_error(err);

        for (i = 0; i < num_params; i++) {

            param = tstr_array_get_str_quick(params, i);
            bail_null(param);

	    tstring *msg = NULL;
            /* Check whether this is a range */
            if ( NULL != (p = strstr(param, "-"))) {
                /* p contains pointer to start of the next segment */
                 int32 start = strtol(param, &p, 10);
                 int32 end = strtol(p+1, NULL, 10);
		/*
		 * If any of the value is negative give out an error
		 */
		if( start < 0 || start > 65535 || end < 0 || end > 65535) {
			code = 1;
			cli_printf(_("error: %s\n"), "Out of range value given."
						"Enter values between 0 and 65535");
			goto bail;
		}
		for (j = start; j <= end; j++) {

			port_num = smprintf("%d", j);

			str_value_t port_nd = {0};

			snprintf(port_nd, sizeof(port_nd), "/nkn/ssld/delivery/config/server_port/%s",
					port_num);
			err = mdc_set_binding(cli_mcc,
					&code,
					&msg,
					bsso_create,
					bt_uint16,
					port_num,
					port_nd);
			bail_error(err);


			if (code != 0) {
				cli_printf(_("error : %s\n"), ts_str(msg));
				break;
			}
			safe_free(port_num);
		}
                if (code != 0) {
                    break;
                }
            }
            else {
                int32 start = strtol(param, NULL, 10);
		/*
		 * If any of the value is negative give out an error
		 */
		if( start < 0 || start > 65535 ) {
			code = 1;
			cli_printf(_("error: %s\n"), "Out of range value given."
					"Enter values between 0 and 65535");
			goto bail;
		}

		port_num = smprintf("%d", start);

		str_value_t port_nd = {0};

		snprintf(port_nd, sizeof(port_nd), "/nkn/ssld/delivery/config/server_port/%s",
				port_num);
		err = mdc_set_binding(cli_mcc,
				&code,
				&msg,
				bsso_create,
				bt_uint16,
				port_num,
				port_nd);
		bail_error(err);
		if (code != 0) {
			cli_printf(_("error : %s\n"), ts_str(msg));
			break;
		}

            }
        }

        break;

    case cid_https_port_delete:
        err = bn_binding_array_new(&barr);
        bail_error(err);

        for (i = 0; i < num_params; i++) {

            param = tstr_array_get_str_quick(params, i);
            bail_null(param);

            /* Check whether this is a range */
            if ( NULL != (p = strstr(param, "-"))) {
                /* p contains pointer to start of the next segment */
                uint16 start = strtol(param, &p, 10);
                uint16 end = strtol(p+1, NULL, 10);

		for (j = start; j <= end; j++) {
			char *n = smprintf("%d", j);;
			str_value_t port_nd = {0};

			snprintf(port_nd, sizeof(port_nd), "/nkn/ssld/delivery/config/server_port/%s",
					n);

			err = mdc_delete_binding(cli_mcc, &code, NULL, port_nd);

                    safe_free(n);
                }
            }
	    else {
		    uint16 start = strtol(param, NULL, 10);
		    char *n = smprintf("%d", start);;
		    str_value_t port_nd = {0};

		    snprintf(port_nd, sizeof(port_nd), "/nkn/ssld/delivery/config/server_port/%s",
				    n);

		    err = mdc_delete_binding(cli_mcc, &code, NULL, port_nd);

	    }
        }

        break;
    }
    /* Call the standard cli processing */
    //err = cli_std_exec(data, cmd, cmd_line, params);
    //bail_error(err);

    /* Print the restart message */

 bail:

    safe_free(port_num);
    if (!err && !code) 
        cli_printf("warning: if command successful, please restart mod-ssld service for change to take effect\n");
    bn_binding_array_free(&barr);
    return(err);
}
int
cli_ssld_https_interface_config(
        void *data,
        const cli_command *cmd,
        const tstr_array *cmd_line,
        const tstr_array *params)
{
    int err = 0;
    tbool valid = false;
    uint32 idx = 0, num_parms = 0;
    tbool delete_cmd = false;
    const char *if_name = NULL;
    char *bname = NULL;

    UNUSED_ARGUMENT(data);
    UNUSED_ARGUMENT(cmd);

    num_parms = tstr_array_length_quick(params);
    for(idx = 0; idx < num_parms; ++idx) {
        err = cli_interface_validate(tstr_array_get_str_quick(params, idx), &valid);
        bail_error(err);

        if (!valid) {
            goto bail;
        }
        else {
            valid = false;
        }
    }

    delete_cmd = (strcmp(tstr_array_get_str_quick(cmd_line, 0), "no") == 0) ? 
            true : false;

    /* If we reached up to this line, then all params are valid interfaces
     */
    num_parms = tstr_array_length_quick(params);
    for(idx = 0; idx < num_parms; idx++) {
        if_name = tstr_array_get_str_quick(params, idx);
        bail_null(if_name);

        bname = smprintf("/nkn/ssld/delivery/config/server_intf/%s", if_name);
        bail_null(bname);

        /* Create the node */
        if (!delete_cmd) {
            err = mdc_create_binding(cli_mcc, NULL, NULL,
                    bt_string,
                    if_name,
                    bname);
            bail_error(err);
        }
        /* Delete the node */
        else {
            err = mdc_delete_binding(cli_mcc, NULL, NULL, bname);
            bail_error(err);
        }

        safe_free(bname);
    }

    err = cli_printf("warning: if command successful, please restart mod-ssl service for change to take effect\n");
    bail_error(err);

bail:
    safe_free(bname);
    return err;
}
Ejemplo n.º 15
0
static void
trie_destruct_func(void *nd)
{
    UNUSED_ARGUMENT(nd);
    return;
}
Ejemplo n.º 16
0
idigi_callback_status_t app_data_service_handler(idigi_data_service_request_t const request,
                                                  void const * request_data, size_t const request_length,
                                                  void * response_data, size_t * const response_length)
{
    idigi_callback_status_t status = idigi_callback_continue;
    idigi_data_service_msg_request_t const * const put_request = request_data;
    idigi_data_service_msg_response_t * const put_response = response_data;

    UNUSED_ARGUMENT(request_length);
    UNUSED_ARGUMENT(response_length);

    if ((put_request == NULL) || (put_response == NULL))
    {
         APP_DEBUG("Invalid request_data [%p] or response_data[%p]\n", request_data, response_data);
         goto done;
    }

    if (request == idigi_data_service_put_request)
    {
        switch (put_request->message_type)
        {
        case idigi_data_service_type_need_data:
            {
                idigi_data_service_block_t * message = put_response->client_data;
                char * dptr = message->data;
                char buffer[BUFFER_SIZE];

                snprintf(buffer, BUFFER_SIZE, "iDigi data service sample [%d]\n", sample_number);
                size_t const bytes = strlen(buffer);

                memcpy(dptr, buffer, bytes);
                message->length_in_bytes = bytes;
                message->flags = IDIGI_MSG_LAST_DATA | IDIGI_MSG_FIRST_DATA;
                put_response->message_status = idigi_msg_error_none;
                sample_number++;
            }
            break;

        case idigi_data_service_type_have_data:
            {
                idigi_data_service_block_t * message = put_request->server_data;
                uint8_t const * data = message->data;

                APP_DEBUG("Received %s response from server\n", ((message->flags & IDIGI_MSG_RESP_SUCCESS) != 0) ? "success" : "error");
                if (message->length_in_bytes > 0) 
                {
                    APP_DEBUG("Server response %s\n", (char *)data);
                }
            }
            break;

        case idigi_data_service_type_error:
            {
                idigi_data_service_block_t * message = put_request->server_data;
                idigi_msg_error_t const * const error_value = message->data;

                APP_DEBUG("Data service error: %d\n", *error_value);
            }
            break;

        default:            
            APP_DEBUG("Unexpected command: %d\n", request);
            break;
        }
    }
    else
    {
        APP_DEBUG("Request not supported in this sample: %d\n", request);
    }

done:
    return status;
}
Ejemplo n.º 17
0
static int jpsd_tdf_domain_rule_cfg_handle_change(const bn_binding_array *arr,
				uint32 idx, bn_binding *binding, void *data)
{
	int err;
        const tstring *name = NULL;
        const char *t_domain_rule = NULL;
        domain_rule_t *domain_rule = NULL;
	tstr_array *name_parts = NULL;
        tbool *rechecked_licenses = data;

        UNUSED_ARGUMENT(arr);
        UNUSED_ARGUMENT(idx);

        bail_null(rechecked_licenses);

        err = bn_binding_get_name(binding, &name);
        bail_error(err);

        if (bn_binding_name_pattern_match(ts_str(name), "/nkn/jpsd/tdf/domain-rule/**")) {
                bn_binding_get_name_parts(binding, &name_parts);
                bail_error_null(err, name_parts);

                t_domain_rule = tstr_array_get_str_quick(name_parts, 4);
                bail_error(err);

                log_debug("Read .../nkn/jpsd/tdf/domain-rule as : \"%s\"", t_domain_rule);
                domain_rule = get_domain_rule(t_domain_rule);
                if (domain_rule == NULL) goto bail;
        } else {
                goto bail;
        }

        if (bn_binding_name_parts_pattern_match_va(name_parts, 4, 2, "*", "precedence")) {
                uint32_t precedence;
                err = bn_binding_get_uint32(binding, ba_value,
                                        NULL, &precedence);
                bail_error(err);
                domain_rule->precedence = precedence;
        } else if (bn_binding_name_parts_pattern_match_va(name_parts, 4, 2, "*", "uplink-vrf")) {
                char *uplink_vrf = NULL;
                err = bn_binding_get_str(binding, ba_value,
                                        bt_string, NULL, &uplink_vrf);
		if (uplink_vrf) {
			if (strcmp(uplink_vrf, "-") == 0) {
				domain_rule->uplink_vrf_len = 0;
			} else {
				strcpy(domain_rule->uplink_vrf, uplink_vrf);
				domain_rule->uplink_vrf_len = strlen(domain_rule->uplink_vrf);
			}
		}
                safe_free(uplink_vrf);
        } else if (bn_binding_name_parts_pattern_match_va(name_parts, 4, 2, "*", "downlink-vrf")) {
                char *downlink_vrf = NULL;
                err = bn_binding_get_str(binding, ba_value,
                                        bt_string, NULL, &downlink_vrf);
		if (downlink_vrf) {
			if (strcmp(downlink_vrf, "-") == 0) {
				domain_rule->downlink_vrf_len = 0;
			} else {
				strcpy(domain_rule->downlink_vrf, downlink_vrf);
				domain_rule->downlink_vrf_len = strlen(domain_rule->downlink_vrf);
			}
		}
                safe_free(downlink_vrf);
	}

bail:
        tstr_array_free(&name_parts);
        return err;
}
idigi_callback_status_t iDigiFileSystem::appReqHandler(idigi_file_system_request_t const request,
                                        void const * request_data, size_t const request_length,
                                        void * response_data, size_t * const response_length)
{
    idigi_callback_status_t status = idigi_callback_continue;

    UNUSED_ARGUMENT(request_length);
    UNUSED_ARGUMENT(response_length);

    if (!serviceEnabled)
    {
        // Return an error to iDigi
        ((idigi_file_response_t *) response_data)->error->error_status = idigi_file_permision_denied;
        return status;
    }

    switch (request)
    {

        case idigi_file_system_open:
            status = app_process_file_open((idigi_file_open_request_t * const) request_data,
            	                           (idigi_file_open_response_t * const) response_data);
            break;

        case idigi_file_system_read:
            status = app_process_file_read((idigi_file_request_t * const) request_data,
            	                           (idigi_file_data_response_t * const) response_data);
            break;

        case idigi_file_system_write:
            status = app_process_file_write((idigi_file_write_request_t *) request_data,
            								(idigi_file_write_response_t *) response_data);
            break;

        case idigi_file_system_lseek:
            status = app_process_file_lseek((idigi_file_lseek_request_t * const) request_data,
            	                            (idigi_file_lseek_response_t * const) response_data);
            break;

        case idigi_file_system_close:
            status = app_process_file_close((idigi_file_request_t * const) request_data,
            	                            (idigi_file_response_t * const) response_data);
            break;

        case idigi_file_system_ftruncate:
            status = app_process_file_ftruncate((idigi_file_ftruncate_request_t * const) request_data,
            	                                (idigi_file_response_t * const) response_data);
            break;

        case idigi_file_system_rm:
            status = app_process_file_rm((idigi_file_path_request_t * const) request_data,
            	                         (idigi_file_response_t * const) response_data);
            break;

        case idigi_file_system_stat:
            status = app_process_file_stat((idigi_file_stat_request_t * const) request_data,
            	                           (idigi_file_stat_response_t * const) response_data);
            break;

        case idigi_file_system_opendir:
            status = app_process_file_opendir((idigi_file_path_request_t * const) request_data,
            	                              (idigi_file_open_response_t * const) response_data);
            break;
        case idigi_file_system_readdir:
            status = app_process_file_readdir((idigi_file_request_t * const) request_data, 
            	                              (idigi_file_data_response_t * const) response_data);
            break;

        case idigi_file_system_closedir:
            status = app_process_file_closedir((idigi_file_request_t * const) request_data,
            	                               (idigi_file_response_t * const) response_data);
            break;

        case idigi_file_system_strerror:
            status = app_process_file_strerror((idigi_file_data_response_t *) response_data);
            break;

        case idigi_file_system_msg_error:
            status = app_process_file_msg_error((idigi_file_error_request_t * const) request_data,
            	                                (idigi_file_response_t * const) response_data);
            break;

        default:
            APP_DEBUG("Unsupported file system request %d\n", request);
    }

    return status;
}
Ejemplo n.º 19
0
RETSIGTYPE
debug_signal_handler (int sig)
{
  UNUSED_ARGUMENT(sig);
  db_level = db_level ? DB_NONE : DB_BASIC;
}
/*----------------------------------------------------------------------------
 * MODULE ENTRY POINT
 *---------------------------------------------------------------------------*/
int
cli_nvsd_rtstream_media_cmds_init(
        const lc_dso_info *info,
        const cli_module_context *context)
{
    int err = 0;
    cli_command *cmd = NULL;

    UNUSED_ARGUMENT(info);

#ifdef PROD_FEATURE_I18N_SUPPORT
    err = cli_set_gettext_domain(GETTEXT_DOMAIN);
    bail_error(err);
#endif

    if (context->cmc_mgmt_avail == false) {
        goto bail;
    }

    CLI_CMD_NEW;
    cmd->cc_words_str =             "rt-stream";
    cmd->cc_help_descr =            N_("Configure rtstream protocol options");
    cmd->cc_flags =                 ccf_hidden;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no rt-stream";
    cmd->cc_help_descr =            N_("Clear rt-stream protocol options");
    CLI_CMD_REGISTER;


    CLI_CMD_NEW;
    cmd->cc_words_str =             "rt-stream media-encode";
    cmd->cc_help_descr =            N_("Configure media-encode option");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no rt-stream media-encode";
    cmd->cc_help_descr =            N_("Clear media encoding options");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "rt-stream media-encode *";
    cmd->cc_help_exp =              N_("<extension>");
    cmd->cc_help_exp_hint =         N_("File extension (.mpg, .ts, default, etc)");
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "rt-stream media-encode * *";
    cmd->cc_help_exp =              N_("<library>");
    cmd->cc_help_options =          cli_nvsd_rts_media_libs;
    cmd->cc_help_num_options =      sizeof(cli_nvsd_rts_media_libs)/sizeof(cli_expansion_option);
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_rstr_curr;
    cmd->cc_exec_callback =         cli_nvsd_rts_media_config;
    cmd->cc_magic =                 cid_rtstream_media_add;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "no rt-stream media-encode *";
    cmd->cc_help_exp =              N_("<name>");
    cmd->cc_help_use_comp =         true;
    cmd->cc_comp_type =             cct_matching_values;
    cmd->cc_comp_pattern =          "/nkn/nvsd/rtstream/config/media-encode/*/extension";
    cmd->cc_flags =                 ccf_terminal;
    cmd->cc_capab_required =        ccp_set_rstr_curr;
    cmd->cc_exec_callback =         cli_nvsd_rts_media_config;
    cmd->cc_magic =                 cid_rtstream_media_delete;
    CLI_CMD_REGISTER;

    CLI_CMD_NEW;
    cmd->cc_words_str =             "show rt-stream";
    cmd->cc_help_descr =            N_("Display rt-stream configuration options");
    cmd->cc_flags =                 ccf_terminal | ccf_hidden;
    cmd->cc_capab_required =        ccp_query_rstr_curr;
    cmd->cc_exec_callback =         cli_nvsd_rtstream_media_show_cmd;
    CLI_CMD_REGISTER;


    err = cli_revmap_ignore_bindings_va(1,
            "/nkn/nvsd/rtstream/config/media-encode/**");
    bail_error(err);


bail:
    return err;
}
Ejemplo n.º 21
0
static
void pe_free_rule(pe_rules_t *p_perule, pe_ilist_t *p_list)
{
    UNUSED_ARGUMENT(p_perule);
    UNUSED_ARGUMENT(p_list);
}
Ejemplo n.º 22
0
/**************************************************************************//*!
 *
 * @name  USB_Framework_Init
 *
 * @brief The function initializes the Class Module 
 *
 * @param handle :              handle to Identify the controller
 * @param class_callback:       event callback 
 * @param other_req_callback:   callback for vendor or usb framework class req    
 *
 * @return status       
 *         USB_OK           : When Successful 
 *         Others           : Errors
 *
 *****************************************************************************/
USB_CLASS_FW_HANDLE USB_Framework_Init
(
    _usb_device_handle handle, /*[IN]*/
    USB_CLASS_CALLBACK class_callback,/*[IN]*/
    USB_REQ_FUNC other_req_callback,/*[IN]*/
    void   *callback_data,/*[IN]*/
    int32_t data,/*[IN]*/
    DESC_CALLBACK_FUNCTIONS_STRUCT_PTR  desc_callback_ptr /*[IN]*/
        
) 
{   
    USB_CLASS_FW_OBJECT_STRUCT_PTR usb_fw_ptr = NULL;
    USB_CLASS_FW_HANDLE fw_handle;
    uint8_t error=USB_OK;
    UNUSED_ARGUMENT(error)
    
    usb_fw_ptr = (USB_CLASS_FW_OBJECT_STRUCT_PTR)USB_mem_alloc_zero(
        sizeof(USB_CLASS_FW_OBJECT_STRUCT));
    if (NULL == usb_fw_ptr)
    {
        #ifdef _DEV_DEBUG
            printf("USB_Framework_Init: Memalloc failed\n");
        #endif  
        return USBERR_ALLOC;
    }

     if (USBERR_DEVICE_BUSY == USB_Class_Fw_Allocate_Handle(&fw_handle))
     {
        USB_mem_free((void *)usb_fw_ptr);
        usb_fw_ptr = NULL;
        return USBERR_ERROR;
     }
    /* save input parameters */
    
    usb_fw_ptr->class_handle = data;
    usb_fw_ptr->ext_req_to_host = NULL;

    /* reserve memory for setup token and data received */
    usb_fw_ptr->ext_req_to_host = (uint8_t*)USB_mem_alloc_zero(MAX_EXPECTED_CONTROL_OUT_SIZE);
    if (NULL == usb_fw_ptr->ext_req_to_host)
    {
        #ifdef _DEV_DEBUG
            printf("ext_req_to_host malloc failed: USB_Framework_Init\n");
        #endif  
        return USBERR_ALLOC;
    }

    usb_fw_ptr->controller_handle = handle;
    usb_fw_ptr->other_req_callback.callback = other_req_callback;
    usb_fw_ptr->other_req_callback.arg = callback_data;
    usb_fw_ptr->class_callback.callback = class_callback;
    usb_fw_ptr->class_callback.arg = callback_data;
    USB_mem_copy( desc_callback_ptr,&usb_fw_ptr->desc,
    sizeof(DESC_CALLBACK_FUNCTIONS_STRUCT));
   
    /* Register CONTROL service */      
    error = _usb_device_register_service(handle, USB_SERVICE_EP0, 

#ifdef DELAYED_PROCESSING    
                                                 USB_Control_Service_Callback,
#else
                                                          USB_Control_Service,
#endif                                                          
     (void *)usb_fw_ptr );
     
    usb_class_fw_object[fw_handle] = usb_fw_ptr;
    return fw_handle;     
}
/* ------------------------------------------------------------------------- */
int
nvsd_mon_handle_get(const char *bname,
	const tstr_array * bname_parts,
	void *data, bn_binding_array * resp_bindings)
{
    int err = 0;
    bn_binding *binding = NULL;
    uint32 num_parts = 0;

    UNUSED_ARGUMENT(data);

    /*
     * Check if the node is of interest to us 
     */
    if ((!lc_is_prefix("/nkn/nvsd/buffermgr/monitor", bname, false)) &&
	    (!lc_is_prefix("/nkn/nvsd/am/monitor", bname, false)) &&
	    (!lc_is_prefix("/nkn/nvsd/resource_mgr/ns", bname, false)) &&
	    (!lc_is_prefix("/nkn/nvsd/resource_mgr/monitor", bname, false)) &&
	    (!lc_is_prefix("/nkn/nvsd/services/monitor/state/nvsd",
			   bname, false))) {
	/*
	 * Not for us 
	 */
	goto bail;
    }

    num_parts = tstr_array_length_quick(bname_parts);

    if (!strcmp("/nkn/nvsd/buffermgr/monitor/cachesize", bname)) {
	err = bn_binding_new_parts_uint32
	    (&binding, bname, bname_parts, true, ba_value, 0, glob_ram_cachesize);
	bail_error(err);
    } else if (!strcmp
	    ("/nkn/nvsd/buffermgr/monitor/max_cachesize_calculated", bname)) {
	err =
	    bn_binding_new_parts_uint32(&binding, bname, bname_parts, true,
		    ba_value, 0,
		    g_max_ram_cachesize_calculated);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/buffermgr/monitor/attributecount", bname)) {
	err = bn_binding_new_parts_uint32
	    (&binding, bname, bname_parts, true,
	     ba_value, 0, (uint32_t) glob_bm_min_attrcount);
	bail_error(err);
    } else if (bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/resource_mgr/ns/*/cache_tier1_util")
	    || bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/resource_mgr/ns/*/cache_tier2_util")
	    || bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/resource_mgr/ns/*/cache_tier3_util")) {
	/*
	 * Get the namespace node data,get the nsuid,
	 Call ns_stat_get_stat_token,
	 call ns_stat_get

	 We should be getting cache utilization per namespace.
	 compute the percentage acroos the reserved space for the resource pool
	 associated with the namespace.
	 */
	namespace_node_data_t *pstNamespace = NULL;
	int ns_idx = 0;
	ns_stat_token_t ns_stoken = NS_NULL_STAT_TOKEN;
	uint64_t res_max = 0;
	int64_t counter_val = 0;
	uint64_t cache_ratio = 0;
	const char *ns_namespace = NULL;
	const char *str_res_type = NULL;
	ns_stat_category_t ns_stat_category;
	rp_type_en rp_type;

	str_res_type = tstr_array_get_str_quick(bname_parts, num_parts - 1);
	bail_null(str_res_type);

	ns_namespace = tstr_array_get_str_quick(bname_parts, num_parts - 2);
	bail_null(ns_namespace);

	err = search_namespace(ns_namespace, &ns_idx);
	bail_error(err);

	pstNamespace = get_namespace(ns_idx);

	if (pstNamespace && pstNamespace->uid)
	    ns_stoken = ns_stat_get_stat_token(pstNamespace->uid + 1);

	if (!strcmp(str_res_type, "cache_tier1_util")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER1;
	    ns_stat_category = NS_USED_SPACE_SSD;
	} else if (!strcmp(str_res_type, "cache_tier2_util")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER2;
	    ns_stat_category = NS_USED_SPACE_SAS;
	} else if (!strcmp(str_res_type, "cache_tier3_util")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER3;
	    ns_stat_category = NS_USED_SPACE_SATA;
	} else {
	    lc_log_basic(LOG_NOTICE, "Invalid resource Type");
	    if (ns_is_stat_token_null(ns_stoken))
		ns_stat_free_stat_token(ns_stoken);
	    goto bail;
	}

	err = ns_stat_get(ns_stoken, ns_stat_category, &counter_val);
	res_max =
	    AO_load(&pstNamespace->resource_pool->resources[rp_type - 1].max);

	if (res_max) {
	    cache_ratio = ((uint64_t) counter_val / res_max) * 100;
	}
	ns_stat_free_stat_token(ns_stoken);

	err = bn_binding_new_parts_uint64
	    (&binding, bname, bname_parts, true, ba_value, 0, cache_ratio);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/buffermgr/monitor/cal_max_dict_size", bname)) {
	err = bn_binding_new_parts_uint32
	    (&binding, bname, bname_parts, true,
	     ba_value, 0, g_cal_ram_dictsize_MB);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/am/monitor/cal_am_mem_limit", bname)) {
	err = bn_binding_new_parts_uint32
	    (&binding, bname, bname_parts, true,
	     ba_value, 0, g_cal_AM_mem_limit);
	bail_error(err);
    } else if (bn_binding_name_parts_pattern_match(bname_parts, true,
		"/nkn/nvsd/resource_mgr/monitor/external/**")) {
	const char *rsrc_pool = NULL;
	const char *rsrc_name = NULL;
	const char *get_type = NULL;
	resource_pool_t *rp = NULL;
	rp_type_en rp_type;
	uint64_t res_used;
	uint64_t res_max;

	rsrc_pool = tstr_array_get_str_quick(bname_parts, num_parts - 3);
	rsrc_name = tstr_array_get_str_quick(bname_parts, num_parts - 1);
	get_type = tstr_array_get_str_quick(bname_parts, num_parts - 2);

	bail_null(rsrc_pool);
	bail_null(rsrc_name);
	bail_null(get_type);

	lc_log_basic(LOG_DEBUG,
		"monitor request for rsrc mgr pool = %s, rsrc_name = %s, get_type = %s",
		rsrc_pool, rsrc_name, get_type);

	if (!strcmp(rsrc_name, "client_sessions")) {
	    rp_type = RESOURCE_POOL_TYPE_CLIENT_SESSION;

	} else if (!strcmp(rsrc_name, "origin_sessions")) {
	    rp_type = RESOURCE_POOL_TYPE_ORIGIN_SESSION;

	} else if (!strcmp(rsrc_name, "max_bandwidth")) {
	    rp_type = RESOURCE_POOL_TYPE_BW;

	} else if (!strcmp(rsrc_name, "reserved_diskspace_tier1")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER1;

	} else if (!strcmp(rsrc_name, "reserved_diskspace_tier2")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER2;

	} else if (!strcmp(rsrc_name, "reserved_diskspace_tier3")) {
	    rp_type = RESOURCE_POOL_TYPE_UTIL_TIER3;
	} else {
	    lc_log_basic(LOG_NOTICE, "Invalid Resource Type");
	}

	if (rp_type > RESOURCE_POOL_MAX)
	    goto bail;

	rp = nvsd_mgmt_get_resource_mgr(rsrc_pool);

	if (rp && (rp->resources) && (strcmp(get_type, "available") == 0)) {

	    res_used = AO_load(&rp->resources[rp_type - 1].used);
	    res_max = AO_load(&rp->resources[rp_type - 1].max);

	    err = bn_binding_new_parts_uint64
		(&binding, bname, bname_parts, true,
		 ba_value, 0, res_max - res_used);
	    bail_error(err);

	} else if (rp && (rp->resources) && (strcmp(get_type, "used") == 0)) {
	    // For Bw get the value from g_rsrc_bw_1_sec
	    if (rp_type == RESOURCE_POOL_TYPE_BW) {
		res_used = g_rsrc_bw_1sec_val[rp->index];
	    } else {
		res_used = AO_load(&rp->resources[rp_type - 1].used);
	    }

	    err = bn_binding_new_parts_uint64
		(&binding, bname, bname_parts, true, ba_value, 0, res_used);
	    bail_error(err);
	} else if (rp && (rp->resources) && (strcmp(get_type, "max") == 0)) {

	    res_used = AO_load(&rp->resources[rp_type - 1].max);

	    err = bn_binding_new_parts_uint64
		(&binding, bname, bname_parts, true, ba_value, 0, res_used);
	    bail_error(err);
	}

    } else if (!strcmp("/nkn/nvsd/services/monitor/state/nvsd/global", bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;

	if (nkn_system_inited && nkn_http_service_inited) {
	    if ((service_init_flags & PREREAD_INIT)) {
		tbool ret = true;
		mgmt_disk_tier_t tier;

		for (tier = MGMT_TIER_SATA; tier < MGMT_TIER_MAX; tier++) {
		    ret &= is_dm2_preread_done(tier);
		}
		ret_msg = ret ? ("Ready") : ("Initializing");
	    } else {
		ret_msg = "Ready";
	    }
	} else {
	    ret_msg = "Initializing";
	}

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/services/monitor/state/nvsd/mgmt", bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;

	if (nvsd_mgmt_thrd_initd) {
	    ret_msg = "Ready";
	} else {
	    ret_msg = "Initializing";
	}

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp ("/nkn/nvsd/services/monitor/state/nvsd/preread/global"
		, bname)) {
	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;
	tbool ret = true;
	mgmt_disk_tier_t tier;

	for (tier = MGMT_TIER_SATA; tier < MGMT_TIER_MAX; tier++) {
	    ret &= is_dm2_preread_done(tier);
	}

	if (ret) {
	    ret_msg = "Ready";
	} else {
	    ret_msg = "Initializing";
	}

	if (!glob_dm2_init_done)
	    ret_msg = "Initializing";

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/services/monitor/state/nvsd/preread/sas"
		, bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;

	if (is_dm2_preread_done(MGMT_TIER_SAS)) {
	    ret_msg = "Done";
	} else {
	    ret_msg = "Reading";
	}

	if (!glob_dm2_sas_tier_avl)
	    ret_msg = "Hardware not present";

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/services/monitor/state/nvsd/preread/ssd"
		, bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;

	if (is_dm2_preread_done(MGMT_TIER_SSD)) {
	    ret_msg = "Done";
	} else {
	    ret_msg = "Reading";
	}

	if (!glob_dm2_ssd_tier_avl)
	    ret_msg = "Hardware not present";

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp ("/nkn/nvsd/services/monitor/state/nvsd/preread/sata"
		, bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */
	const char *ret_msg = NULL;

	if (is_dm2_preread_done(MGMT_TIER_SATA)) {
	    ret_msg = "Done";
	} else {
	    ret_msg = "Reading";
	}

	if (!glob_dm2_sata_tier_avl)
	    ret_msg = "Hardware not present";

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);
    } else if (!strcmp("/nkn/nvsd/services/monitor/state/nvsd/network", bname)) {

	/*
	 * Based on what is to be used for nvsd delivery readiness send the
	 * state 
	 */

	const char *ret_msg = NULL;

	if (nkn_http_service_inited) {
	    ret_msg = "Ready";
	} else {
	    ret_msg = "Initializing";
	}

	err = bn_binding_new_parts_str(&binding, bname, bname_parts, true,
		ba_value, bt_string, 0, ret_msg);
	bail_error(err);

    }

    if (binding) {
	err = bn_binding_array_append_takeover(resp_bindings, &binding);
	bail_error(err);
    }

bail:
    return (err);
}
/*
 * HRT thread handler
 */
static void *hrt_handler_func(void *arg)
{
    UNUSED_ARGUMENT(arg);
    int rv;
    pthread_condattr_t cattr;
    struct timespec cur_ts;
    struct timespec ts;
    int64_t clk_diff_msecs;
    int64_t msecs;
    int n;
    int end_bucket;
    int bucket;

    if (!hrt_init_complete) {
    	/* Name thread */
    	prctl(PR_SET_NAME, "nvsd-hrt", 0, 0, 0);

   	/* Use CLOCK_MONOTONIC for pthread_cond_timedwait */
	pthread_condattr_init(&cattr);
	pthread_condattr_setclock(&cattr, CLOCK_MONOTONIC);
	pthread_cond_init(&hrt_thread_cv, &cattr);

	/* Setup initialization state */
    	pthread_mutex_lock(&hrt_thread_mutex);
	HRT_BASE_BUCKET = 0;
        clock_gettime(CLOCK_MONOTONIC, &cur_ts);
	HRT_THREAD_TS = cur_ts;
	HRT_BASE_BUCKET_TS = HRT_THREAD_TS;
	HRT_THREAD_SLEEPING = 0;
    	hrt_init_complete = 1;
    }

    while (1) {
        clock_gettime(CLOCK_MONOTONIC, &cur_ts);
	clk_diff_msecs = timespec_diff_msecs(&HRT_BASE_BUCKET_TS, &cur_ts);
	if (clk_diff_msecs < 0) {
	    clk_diff_msecs = 0;
	}
	bucket = MSECS_TO_BUCKET(clk_diff_msecs);
	end_bucket = (HRT_BASE_BUCKET + bucket) % TIMER_BUCKETS;

	if (hrt_thread_trace_enabled) {
	    DBG_LOG(MSG, MOD_HRT,
		    "Scan bucket=%d-%d ts=%ld %ld base_ts=%ld %ld "
		    "sleeped=%ld\n", HRT_BASE_BUCKET, end_bucket, 
		    cur_ts.tv_sec, cur_ts.tv_nsec,
		    HRT_BASE_BUCKET_TS.tv_sec, HRT_BASE_BUCKET_TS.tv_nsec, 
		    clk_diff_msecs);
	}

	n = HRT_BASE_BUCKET;
	while (1) {
    	    TRACE_BUCKET(n);
	    while (process_timer_bucket(n)) {
	    	pthread_mutex_lock(&hrt_thread_mutex);
	    }
	    pthread_mutex_lock(&hrt_thread_mutex);

	    if (n == end_bucket) {
	    	break;
	    } else {
	    	n = (n + 1) % TIMER_BUCKETS;
	    }
	}

	/* Note if callout processing exceeds MSECS_PER_BUCKET */
        clock_gettime(CLOCK_MONOTONIC, &ts);
	msecs = timespec_diff_msecs(&cur_ts, &ts);
	if (msecs > MSECS_PER_BUCKET) {
	    glob_hrt_long_callout++;
    	    DBG_LOG(MSG, MOD_HRT, 
	    	    "Callout processing time exceeded, "
		    "%ld msecs %d msecs limit", msecs, MSECS_PER_BUCKET);
	}

	/* Determine the delay time to the next bucket */
	for (n = 1; n < TIMER_BUCKETS; n++) {
	    bucket = (end_bucket + n) % TIMER_BUCKETS;
	    if (timer_bucket[bucket].entries) {
	    	break;
	    }
	}

	HRT_BASE_BUCKET = end_bucket;
	HRT_BASE_BUCKET_TS = cur_ts;
	if (n < TIMER_BUCKETS) {
	    HRT_THREAD_TS = timer_bucket[bucket].d.prev->deadline_ts;
	    if (timespec_cmp(&cur_ts, &HRT_THREAD_TS) >= 0) {
	    	/* Bucket already expired, process it */
	    	HRT_BASE_BUCKET = bucket;
		glob_hrt_callout_behind++;
	    	continue;
	    }
	} else {
	    HRT_THREAD_TS = cur_ts;
	    timespec_add_msecs(&HRT_THREAD_TS, 
	    		       (TIMER_BUCKETS * MSECS_PER_BUCKET));
	}


	if (hrt_thread_trace_enabled) {
	    int sleep_time_msecs = timespec_diff_msecs(&cur_ts, &HRT_THREAD_TS);
	    DBG_LOG(MSG, MOD_HRT,
	    	    "Sleep %d msecs base_bucket=%d cur_ts=%ld %ld "
	            "hrt_ts=%ld %ld\n", sleep_time_msecs, 
		    HRT_BASE_BUCKET, cur_ts.tv_sec, cur_ts.tv_nsec,
		    HRT_THREAD_TS.tv_sec, HRT_THREAD_TS.tv_nsec);
	}

	HRT_THREAD_SLEEPING = 1;
	rv = pthread_cond_timedwait(&hrt_thread_cv, &hrt_thread_mutex, 
				    &HRT_THREAD_TS);
	HRT_THREAD_SLEEPING = 0;
    }
    return NULL;
}
/*
 *	funtion : nvsd_pub_point_cfg_handle_change()
 *	purpose : handler for config changes for pub-point module
 */
	int
nvsd_pub_point_cfg_handle_change(const bn_binding_array * arr,
		uint32 idx, bn_binding * binding, void *data)
{
	int err = 0;
	const tstring *name = NULL;
	const char *t_pub_point = NULL;
	tstr_array *name_parts = NULL;
	tbool *rechecked_licenses_p = data;

	UNUSED_ARGUMENT(arr);
	UNUSED_ARGUMENT(idx);

	bail_null(rechecked_licenses_p);

	err = bn_binding_get_name(binding, &name);
	bail_error(err);

	/*
	 * Check if this is our node 
	 */
	if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/**")) {
		/*
		 * get the publish point 
		 */
		err = bn_binding_get_name_parts(binding, &name_parts);
		bail_error(err);

		t_pub_point = tstr_array_get_str_quick(name_parts, 4);

		lc_log_basic(LOG_DEBUG,
				"Read .../nkn/nvsd/pub-point/config as : \"%s\"",
				t_pub_point);

		pstPublishPoint = get_publish_point_element(t_pub_point);
		if (!pstPublishPoint)
			goto bail;

		if (NULL == pstPublishPoint->name)
			pstPublishPoint->name = strdup(t_pub_point);

	} else {
		/*
		 * This is not a pub-point node.. hence bail 
		 */
		goto bail;
	}

	/*
	 * Get the value of EVENT-DURATION 
	 */
	if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/*/event/duration")) {
		char *t_event_duration = NULL;

		err = bn_binding_get_str(binding,
				ba_value, bt_string, NULL, &t_event_duration);
		bail_error(err);

		lc_log_basic(LOG_DEBUG,
				"Read .../pub-point/config/%s/event/duration as \"%s\"",
				t_pub_point, t_event_duration);

		if (NULL != pstPublishPoint->event_duration)
			free(pstPublishPoint->event_duration);

		if (t_event_duration)
			pstPublishPoint->event_duration = strdup(t_event_duration);
		else
			pstPublishPoint->event_duration = NULL;

		if (t_event_duration)
			safe_free(t_event_duration);
	}

	/*
	 * Get the value of SERVER-URI 
	 */
	else if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/*/pub-server/uri")) {
		char *t_server_uri = NULL;

		err = bn_binding_get_str(binding,
				ba_value, bt_uri, NULL, &t_server_uri);
		bail_error(err);

		lc_log_basic(LOG_DEBUG,
				"Read .../pub-point/config/%s/pub-server/uri as \"%s\"",
				t_pub_point, t_server_uri);

		if (NULL != pstPublishPoint->server_uri)
			free(pstPublishPoint->server_uri);

		if (t_server_uri)
			pstPublishPoint->server_uri = strdup(t_server_uri);
		else
			pstPublishPoint->server_uri = NULL;

		// rtsp_cfg_pub_point_callback (pstPublishPoint);

		if (t_server_uri)
			safe_free(t_server_uri);
	}

	/*
	 * Get the value of SERVER-URI MODE 
	 */
	else if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/*/pub-server/mode")) {
		char *t_mode = NULL;

		err = bn_binding_get_str(binding, ba_value, bt_string, NULL, &t_mode);
		bail_error(err);

		lc_log_basic(LOG_DEBUG,
				"Read .../pub-point/config/%s/pub-server/uri/mode as \"%s\"",
				t_pub_point, t_mode);

		if (t_mode && (0 == strcmp(t_mode, "pull")))
			pstPublishPoint->mode = PUB_SERVER_MODE_PULL;

		// rtsp_cfg_pub_point_callback (pstPublishPoint);

		if (t_mode)
			safe_free(t_mode);

	}

	/*
	 * Get the value of SDP-STATIC 
	 */
	else if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/*/sdp/static")) {
		tstring *t_sdp_static = NULL;

		err = bn_binding_get_tstr(binding,
				ba_value, bt_uri, NULL, &t_sdp_static);
		bail_error(err);

		lc_log_basic(LOG_DEBUG,
				"Read .../pub-point/config/%s/sdp/static as \"%s\"",
				t_pub_point, ts_str(t_sdp_static));

		if (NULL != pstPublishPoint->sdp_static)
			free(pstPublishPoint->sdp_static);

		if (t_sdp_static)
			pstPublishPoint->sdp_static = strdup(ts_str(t_sdp_static));
		else
			pstPublishPoint->sdp_static = NULL;

		// rtsp_cfg_pub_point_callback (pstPublishPoint);

		if (t_sdp_static)
			ts_free(&t_sdp_static);
	}

	/*
	 * Get the value of ACTIVE 
	 */
	else if (bn_binding_name_pattern_match
			(ts_str(name), "/nkn/nvsd/pub-point/config/*/active")) {
		tbool t_active = false;

		err = bn_binding_get_tbool(binding, ba_value, NULL, &t_active);

		lc_log_basic(LOG_DEBUG, "Read .../pub-point/config/%s/active as \"%s\"",
				t_pub_point, (t_active) ? "true" : "false");

		pstPublishPoint->enable = t_active;

		// rtsp_cfg_pub_point_callback (pstPublishPoint);
	}

	/*
	 * Crazy hack to send the configuration to RTSP 
	 */
bail:
	tstr_array_free(&name_parts);
	return err;
}								/* end of nvsd_pub_point_cfg_handle_change () 
Ejemplo n.º 26
0
/**
 * the handler of the ever-1-second timer
 *
 * @param fd, the descriptors of the socket
 * @param which, event flags
 * @param arg, argument
 */
static void ms_clock_handler(const int fd, const short which, void *arg)
{
  ms_thread_t *ms_thread= pthread_getspecific(ms_thread_key);
  struct timeval t=
  {
    .tv_sec= 1, .tv_usec= 0
  };

  UNUSED_ARGUMENT(fd);
  UNUSED_ARGUMENT(which);
  UNUSED_ARGUMENT(arg);

  ms_set_current_time();

  if (ms_thread->initialized)
  {
    /* only delete the event if it's actually there. */
    evtimer_del(&ms_thread->clock_event);
    ms_check_sock_timeout();
  }
  else
  {
    ms_thread->initialized= true;
  }

  ms_reconn_thread_socks();

  evtimer_set(&ms_thread->clock_event, ms_clock_handler, 0);
  event_base_set(ms_thread->base, &ms_thread->clock_event);
  evtimer_add(&ms_thread->clock_event, &t);
} /* ms_clock_handler */


/**
 * used to bind thread to CPU if the system supports
 *
 * @param cpu, cpu index
 *
 * @return if success, return EXIT_SUCCESS, else return -1
 */
/** +EDIT */
/*
static uint32_t ms_set_thread_cpu_affinity(uint32_t cpu)
{
  uint32_t ret= 0;

#ifdef HAVE_CPU_SET_T
  cpu_set_t cpu_set;
  CPU_ZERO(&cpu_set);
  CPU_SET(cpu, &cpu_set);

  if (sched_setaffinity(0, sizeof(cpu_set_t), &cpu_set) == -1)
  {
    fprintf(stderr, "WARNING: Could not set CPU Affinity, continuing...\n");
    ret= 1;
  }
#else
  UNUSED_ARGUMENT(cpu);
#endif

  return ret;
}
*/
/** -EDIT */
/* ms_set_thread_cpu_affinity */


/**
 * Set up a thread's information.
 *
 * @param thread_ctx, pointer of the thread context structure
 *
 * @return if success, return EXIT_SUCCESS, else return -1
 */
static int ms_setup_thread(ms_thread_ctx_t *thread_ctx)
{

  ms_thread_t *ms_thread= (ms_thread_t *)calloc(sizeof(*ms_thread), 1);
  pthread_setspecific(ms_thread_key, (void *)ms_thread);

  ms_thread->thread_ctx= thread_ctx;
  ms_thread->nactive_conn= thread_ctx->nconns;
  ms_thread->initialized= false;
  static volatile uint32_t cnt= 0;

  gettimeofday(&ms_thread->startup_time, NULL);

  ms_thread->base= event_init();
  if (ms_thread->base == NULL)
  {
    if (atomic_add_32_nv(&cnt, 1) == 0)
    {
      fprintf(stderr, "Can't allocate event base.\n");
    }

    return -1;
  }

  ms_thread->conn=
    (ms_conn_t *)malloc((size_t)thread_ctx->nconns * sizeof(ms_conn_t));
  if (ms_thread->conn == NULL)
  {
    if (atomic_add_32_nv(&cnt, 1) == 0)
    {
      fprintf(
        stderr,
        "Can't allocate concurrency structure for thread descriptors.");
    }

    return -1;
  }
  memset(ms_thread->conn, 0, (size_t)thread_ctx->nconns * sizeof(ms_conn_t));

  for (uint32_t i= 0; i < thread_ctx->nconns; i++)
  {
    ms_thread->conn[i].conn_idx= i;
    if (ms_setup_conn(&ms_thread->conn[i]) != 0)
    {
      /* only output this error once */
      if (atomic_add_32_nv(&cnt, 1) == 0)
      {
        fprintf(stderr, "Initializing connection failed.\n");
      }

      return -1;
    }
  }

  return EXIT_SUCCESS;
} /* ms_setup_thread */
Ejemplo n.º 27
0
int ashmem_set_prot_region(int fd, int prot)
{
        UNUSED_ARGUMENT( fd );
        UNUSED_ARGUMENT( prot );
	return 0;
}
Ejemplo n.º 28
0
static void *
trie_copy_func(void *nd)
{
    UNUSED_ARGUMENT(nd);
    return nd;
}
Ejemplo n.º 29
0
static void valueCompletion(const char *buf, size_t bufLength, linenoiseCompletions *lc, uint8_t actionCode,
                            const char *nodeString, size_t nodeStringLength, const char *keyString, size_t keyStringLength,
                            const char *typeString, size_t typeStringLength, const char *partialValueString, size_t partialValueStringLength) {
    UNUSED_ARGUMENT(actionCode);
    UNUSED_ARGUMENT(typeStringLength);

    enum sshs_node_attr_value_type type = sshsHelperStringToTypeConverter(typeString);
    if (type == UNKNOWN) {
        // Invalid type, no auto-completion.
        return;
    }

    if (partialValueStringLength != 0) {
        // If there already is content, we can't do any auto-completion here, as
        // we have no idea about what a valid value would be to complete ...
        // Unless this is a boolean, then we can propose true/false strings.
        if (type == BOOL) {
            if (strncmp("true", partialValueString, partialValueStringLength) == 0) {
                linenoiseAddCompletionSuffix(lc, buf, bufLength - partialValueStringLength, "true", false, false);
            }
            if (strncmp("false", partialValueString, partialValueStringLength) == 0) {
                linenoiseAddCompletionSuffix(lc, buf, bufLength - partialValueStringLength, "false", false, false);
            }
        }

        return;
    }

    uint8_t dataBuffer[1024];

    // Send request for the current value, so we can auto-complete with it as default.
    dataBuffer[0] = GET;
    dataBuffer[1] = (uint8_t) type;
    setExtraLen(dataBuffer, 0); // UNUSED.
    setNodeLen(dataBuffer, (uint16_t) (nodeStringLength + 1)); // +1 for terminating NUL byte.
    setKeyLen(dataBuffer, (uint16_t) (keyStringLength + 1)); // +1 for terminating NUL byte.
    setValueLen(dataBuffer, 0); // UNUSED.

    memcpy(dataBuffer + 10, nodeString, nodeStringLength);
    dataBuffer[10 + nodeStringLength] = '\0';

    memcpy(dataBuffer + 10 + nodeStringLength + 1, keyString, keyStringLength);
    dataBuffer[10 + nodeStringLength + 1 + keyStringLength] = '\0';

    if (!sendUntilDone(sockFd, dataBuffer, 10 + nodeStringLength + 1 + keyStringLength + 1)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    if (!recvUntilDone(sockFd, dataBuffer, 4)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    // Decode response header fields (all in little-endian).
    uint8_t action = dataBuffer[0];
    uint16_t msgLength = le16toh(*(uint16_t * )(dataBuffer + 2));

    // Total length to get for response.
    if (!recvUntilDone(sockFd, dataBuffer + 4, msgLength)) {
        // Failed to contact remote host, no auto-completion!
        return;
    }

    if (action == ERROR) {
        // Invalid request made, no auto-completion.
        return;
    }

    // At this point we made a valid request and got back a full response.
    // We can just use it directly and paste it in as completion.
    linenoiseAddCompletionSuffix(lc, buf, bufLength, (const char *) dataBuffer + 4, false, false);

    // If this is a boolean value, we can also add the inverse as a second completion.
    if (type == BOOL) {
        if (strcmp((const char *) dataBuffer + 4, "true") == 0) {
            linenoiseAddCompletionSuffix(lc, buf, bufLength, "false", false, false);
        }
        else {
            linenoiseAddCompletionSuffix(lc, buf, bufLength, "true", false, false);
        }
    }
}
bool SemanticVerificationStage0::parseOptions(po::variables_map& vm)
{
	UNUSED_ARGUMENT(vm);
	return true;
}