status_t y_ietf_interfaces_init ( const xmlChar *modname, const xmlChar *revision) { agt_profile_t *agt_profile; status_t res; agt_profile = agt_get_profile(); res = ncxmod_load_module( "ietf-interfaces", NULL, &agt_profile->agt_savedevQ, &ietf_interfaces_mod); if (res != NO_ERR) { return res; } interfaces_state_obj = ncx_find_object( ietf_interfaces_mod, "interfaces-state"); if (interfaces_state_obj == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } return res; }
status_t y_interfaces_alarms_init ( const xmlChar *modname, const xmlChar *revision) { agt_profile_t *agt_profile; status_t res; ncx_module_t *mod; agt_profile = agt_get_profile(); res = ncxmod_load_module( "interfaces-alarms", NULL, &agt_profile->agt_savedevQ, &mod); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( "ietf-alarms", (const xmlChar *)"/alarms", (const xmlChar *)NULL /*"YYYY-MM-DD"*/, y_interfaces_alarms_alarms_edit); if (res != NO_ERR) { return res; } agt_not_queue_notification_cb_register("intrfaces-alarms", notification_cb); return res; }
/******************************************************************** * FUNCTION agt_ses_init * * INIT 1: * Initialize the session manager module data structures * * INPUTS: * none * RETURNS: * status *********************************************************************/ status_t agt_ses_init (void) { agt_profile_t *agt_profile; status_t res; uint32 i; if (agt_ses_init_done) { return ERR_INTERNAL_INIT_SEQ; } #ifdef AGT_STATE_DEBUG log_debug2("\nagt: Loading netconf-state module"); #endif agt_profile = agt_get_profile(); for (i=0; i<AGT_SES_MAX_SESSIONS; i++) { agtses[i] = NULL; } next_sesid = 1; mysesmod = NULL; agttotals = ses_get_total_stats(); memset(agttotals, 0x0, sizeof(ses_total_stats_t)); tstamp_datetime(agttotals->startTime); (void)time(&last_timeout_check); agt_ses_init_done = TRUE; /* load the netconf-state module */ res = ncxmod_load_module(AGT_SES_MODULE, NULL, &agt_profile->agt_savedevQ, &mysesmod); if (res != NO_ERR) { return res; } /* set up get-my-session RPC operation */ res = agt_rpc_register_method(AGT_SES_MODULE, AGT_SES_GET_MY_SESSION, AGT_RPC_PH_INVOKE, get_my_session_invoke); if (res != NO_ERR) { return SET_ERROR(res); } /* set up set-my-session RPC operation */ res = agt_rpc_register_method(AGT_SES_MODULE, AGT_SES_SET_MY_SESSION, AGT_RPC_PH_INVOKE, set_my_session_invoke); if (res != NO_ERR) { return SET_ERROR(res); } return res; } /* agt_ses_init */
/******************************************************************** * FUNCTION y_yuma_time_filter_init * * initialize the yuma-time-filter server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_yuma_time_filter_init ( const xmlChar *modname, const xmlChar *revision) { agt_profile_t *agt_profile; status_t res; y_yuma_time_filter_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_yuma_time_filter_M_yuma_time_filter)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp(revision, y_yuma_time_filter_R_yuma_time_filter)) { return ERR_NCX_WRONG_VERSION; } agt_profile = agt_get_profile(); res = ncxmod_load_module( y_yuma_time_filter_M_yuma_time_filter, y_yuma_time_filter_R_yuma_time_filter, &agt_profile->agt_savedevQ, &yuma_time_filter_mod); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_yuma_time_filter_init */
/******************************************************************** * FUNCTION agt_cfg_new_transaction * * Malloc and initialize agt_cfg_transaction_t struct * * INPUTS: * cfgid == config ID to use * edit_type == database edit type * rootcheck == TRUE if root_check needs to be done before commit * during agt_val_apply_write; FALSE if it is done * manually via agt_val_root_check * is_validate == TRUE if this is a <validate> operation * the target data nodes will not be altered * at all during the transaction * FALSE if this is some sort of real edit * res == address of return status * OUTPUTS: * *res == return status * RETURNS: * malloced transaction struct; need to call agt_cfg_free_transaction *********************************************************************/ agt_cfg_transaction_t * agt_cfg_new_transaction (ncx_cfg_t cfgid, agt_cfg_edit_type_t edit_type, boolean rootcheck, boolean is_validate, status_t *res) { assert( edit_type && "edit_type in NONE" ); assert( res && "res is NULL" ); cfg_template_t *cfg = cfg_get_config_id(cfgid); if (cfg == NULL) { *res = ERR_NCX_CFG_NOT_FOUND; return NULL; } if (cfg->cur_txid != 0) { /* a current transaction is already in progress */ *res = ERR_NCX_NO_ACCESS_STATE; return NULL; } agt_cfg_transaction_t *txcb = m__getObj(agt_cfg_transaction_t); if (txcb == NULL) { *res = ERR_INTERNAL_MEM; return NULL; } memset(txcb, 0x0, sizeof(agt_cfg_transaction_t)); dlq_createSQue(&txcb->undoQ); dlq_createSQue(&txcb->auditQ); dlq_createSQue(&txcb->deadnodeQ); txcb->txid = allocate_txid(); txcb->cfg_id = cfgid; txcb->rootcheck = rootcheck; txcb->edit_type = edit_type; txcb->is_validate = is_validate; txcb->apply_res = ERR_NCX_SKIPPED; txcb->commit_res = ERR_NCX_SKIPPED; txcb->rollback_res = ERR_NCX_SKIPPED; agt_profile_t *profile = agt_get_profile(); if (profile->agt_config_state == AGT_CFG_STATE_BAD) { txcb->start_bad = TRUE; } cfg->cur_txid = txcb->txid; *res = NO_ERR; return txcb; } /* agt_cfg_new_transaction */
/******************************************************************** * FUNCTION agt_ses_ssh_port_allowed * * Check if the port number used for SSH connect is okay * * RETURNS: * TRUE if port allowed * FALSE if port not allowed *********************************************************************/ boolean agt_ses_ssh_port_allowed (uint16 port) { const agt_profile_t *profile; uint32 i; if (port == 0) { return FALSE; } profile = agt_get_profile(); if (!profile) { SET_ERROR(ERR_INTERNAL_VAL); return FALSE; } /* -------------- LEVI ---------------- */ if(profile->agt_port) { //port has been configured if(port == profile->agt_port) { return TRUE; } return FALSE; } // if (profile->agt_ports[0]) { // /* something configured, so use only that list */ // for (i = 0; i < AGT_MAX_PORTS; i++) { // if (port == profile->agt_ports[i]) { // return TRUE; // } // } // return FALSE; // } /* ------------- END LEVI ------------- */ else { /* no ports configured so allow 830 */ if (port==NCX_NCSSH_PORT) { return TRUE; } else { return FALSE; } } /*NOTREACHED*/ } /* agt_ses_ssh_port_allowed */
/******************************************************************** * FUNCTION y_simple_yang_test_init * * initialize the simple_yang_test server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_simple_yang_test_init ( const xmlChar *modname, const xmlChar *revision) { status_t res = NO_ERR; agt_profile_t *agt_profile; y_simple_yang_test_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_simple_yang_test_M_simple_yang_test)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp(revision, y_simple_yang_test_R_simple_yang_test)) { return ERR_NCX_WRONG_VERSION; } agt_profile = agt_get_profile(); res = ncxmod_load_module( y_simple_yang_test_M_simple_yang_test, y_simple_yang_test_R_simple_yang_test, &agt_profile->agt_savedevQ, &simple_yang_test_mod); if (res != NO_ERR) { return res; } protocol_obj = ncx_find_object( simple_yang_test_mod, y_simple_yang_test_N_protocol); if (simple_yang_test_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } interface_obj = ncx_find_object( simple_yang_test_mod, y_simple_yang_test_N_interface); if (simple_yang_test_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/interface", (const xmlChar *)"2011-11-21", simple_yang_test_interface_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/interface/ifMTU", (const xmlChar *)"2011-11-21", simple_yang_test_interface_ifMTU_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/interface/ifType", (const xmlChar *)"2011-11-21", simple_yang_test_interface_ifType_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/protocol", (const xmlChar *)"2011-11-21", simple_yang_test_protocol_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/protocol/name/tcp/tcp", (const xmlChar *)"2011-11-21", simple_yang_test_protocol_name_tcp_tcp_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_yang_test_M_simple_yang_test, (const xmlChar *)"/protocol/name/udp/udp", (const xmlChar *)"2011-11-21", simple_yang_test_protocol_name_udp_udp_edit); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_simple_yang_test_init */
/******************************************************************** * FUNCTION agt_top_dispatch_msg * * Find the appropriate top node handler and call it * called by the transport manager (through the session manager) * when a new message is detected * * INPUTS: * scb == session control block containing the xmlreader * set at the start of an incoming message. * * RETURNS: * none *********************************************************************/ void agt_top_dispatch_msg (ses_cb_t **ppscb) { ses_total_stats_t *myagttotals; agt_profile_t *profile; xml_node_t top; status_t res; top_handler_t handler; ses_cb_t *scb = *ppscb; #ifdef DEBUG if (!scb) { SET_ERROR(ERR_INTERNAL_PTR); return; } #endif myagttotals = ses_get_total_stats(); profile = agt_get_profile(); xml_init_node(&top); /* get the first node */ res = agt_xml_consume_node(scb, &top, NCX_LAYER_TRANSPORT, NULL); if (res != NO_ERR) { scb->stats.inBadRpcs++; myagttotals->stats.inBadRpcs++; myagttotals->droppedSessions++; if (LOGINFO) { log_info("\nagt_top: bad msg for session %d (%s)", scb->sid, get_error_string(res)); } xml_clean_node(&top); agt_ses_free_session(scb); /* set the supplied ptr to ptr to scb to NULL so that the * caller of this function knows that it was deallotcated */ *ppscb=NULL; return; } log_debug3("\nagt_top: got node"); if (LOGDEBUG4 && scb->state != SES_ST_INIT) { xml_dump_node(&top); } /* check node type and if handler exists, then call it */ if (top.nodetyp==XML_NT_START || top.nodetyp==XML_NT_EMPTY) { /* find the owner, elname tuple in the topQ */ handler = top_find_handler(top.module, top.elname); if (handler) { /* call the handler */ (*handler)(scb, &top); } else { res = ERR_NCX_DEF_NOT_FOUND; } } else { res = ERR_NCX_WRONG_NODETYP; } /* check any error trying to invoke the top handler */ if (res != NO_ERR) { scb->stats.inBadRpcs++; myagttotals->stats.inBadRpcs++; myagttotals->droppedSessions++; if (LOGINFO) { log_info("\nagt_top: bad msg for session %d (%s)", scb->sid, get_error_string(res)); } agt_ses_free_session(scb); /* set the supplied ptr to ptr to scb to NULL so that the * caller of this function knows that it was deallotcated */ *ppscb=NULL; } else if (profile->agt_stream_output && scb->state == SES_ST_SHUTDOWN_REQ) { /* session was closed */ agt_ses_kill_session(scb, scb->killedbysid, scb->termreason); /* set the supplied ptr to ptr to scb to NULL so that the * caller of this function knows that it was deallotcated */ *ppscb=NULL; } xml_clean_node(&top); } /* agt_top_dispatch_msg */
/******************************************************************** * FUNCTION load_running_config * * Load the NV startup config into the running config * * INPUTS: * startup == startup filespec provided by the user * == NULL if not set by user * (use default name and specified search path instead) * loaded == address of return config loaded flag * * OUTPUTS: * *loaded == TRUE if some config file was loaded * * The <running> config is loaded from NV-storage, * if the NV-storage <startup> config can be found an read * RETURNS: * status *********************************************************************/ static status_t load_running_config (const xmlChar *startup, boolean *loaded) { cfg_template_t *cfg; xmlChar *fname; agt_profile_t *profile; status_t res; res = NO_ERR; *loaded = FALSE; profile = agt_get_profile(); cfg = cfg_get_config(NCX_CFG_RUNNING); if (!cfg) { log_error("\nagt: No running config found!!"); return SET_ERROR(ERR_INTERNAL_VAL); } /* use the user-set startup or default filename */ if (startup) { /* relative filespec, use search path */ fname = ncxmod_find_data_file(startup, FALSE, &res); } else { /* search for the default startup-cfg.xml filename */ fname = ncxmod_find_data_file(NCX_DEF_STARTUP_FILE, FALSE, &res); } /* check if error finding the filespec */ if (!fname) { if (startup) { if (res == NO_ERR) { res = ERR_NCX_MISSING_FILE; } log_error("\nError: Startup config file (%s) not found (%s).", startup, get_error_string(res)); return res; } else { log_info("\nDefault startup config file (%s) not found." "\n Booting with default running configuration!\n", NCX_DEF_STARTUP_FILE); return NO_ERR; } } else if (LOGDEBUG2) { log_debug2("\nFound startup config: '%s'", fname); } /* try to load the config file that was found or given */ res = agt_ncx_cfg_load(cfg, CFG_LOC_FILE, fname); if (res == ERR_XML_READER_START_FAILED) { log_error("\nagt: Error: Could not open startup config file" "\n (%s)\n", fname); } else if (res != NO_ERR) { /* if an error is returned then it was a hard error * since the startup_error and running_error profile * variables have already been accounted for. * An error in the setup or in the AGT_RPC_PH_INVOKE phase * of the <load-config> operation occurred */ log_error("\nError: load startup config failed (%s)", get_error_string(res)); if (!dlq_empty(&cfg->load_errQ)) { *loaded = TRUE; } } else { /* assume OK or startup and running continue; if 1 or both is not * set then the server will exit anyway and the config state * will not matter */ profile->agt_config_state = AGT_CFG_STATE_OK; *loaded = TRUE; boolean errdone = FALSE; boolean errcontinue = FALSE; if (profile->agt_load_validate_errors) { if (profile->agt_startup_error) { /* quit if any startup validation errors */ log_error("\nError: validation errors occurred loading the " "<running> database\n from NV-storage" " (%s)\n", fname); errdone = TRUE; } else { /* continue if any startup errors */ log_warn("\nWarning: validation errors occurred loading " "the <running> database\n from NV-storage" " (%s)\n", fname); errcontinue = TRUE; } } if (!errdone && profile->agt_load_rootcheck_errors) { if (profile->agt_startup_error) { /* quit if any startup root-check validation errors */ log_error("\nError: root-check validation errors " "occurred loading the <running> database\n" " from NV-storage (%s)\n", fname); errdone = TRUE; } else { /* continue if any root-check validation errors */ log_warn("\nWarning: root-check validation errors " "occurred loading the <running> database\n" " from NV-storage (%s)\n", fname); errcontinue = TRUE; } } if (!errdone && profile->agt_load_top_rootcheck_errors) { if (profile->agt_running_error) { /* quit if any top-level root-check validation errors */ log_error("\nError: top-node root-check validation errors " "occurred loading the <running> database\n" " from NV-storage (%s)\n", fname); errdone = TRUE; } else { /* continue if any startup errors */ log_warn("\nWarning: top-node root-check validation errors " "occurred loading the <running> database\n" " from NV-storage (%s)\n", fname); profile->agt_config_state = AGT_CFG_STATE_BAD; errcontinue = TRUE; } } if (!errdone && profile->agt_load_apply_errors) { /* quit if any apply-to-running SIL errors */ errdone = TRUE; log_error("\nError: fatal errors " "occurred loading the <running> database " "from NV-storage\n (%s)\n", fname); } if (errdone) { res = ERR_NCX_OPERATION_FAILED; } else if (errcontinue) { val_purge_errors_from_root(cfg->root); log_info("\nagt: Startup config loaded after pruning error nodes\n" "Source: %s\n", fname); } else { log_info("\nagt: Startup config loaded OK\n Source: %s\n", fname); } } if (LOGDEBUG) { log_debug("\nContents of %s configuration:", cfg->name); val_dump_value(cfg->root, 0); log_debug("\n"); } if (fname) { m__free(fname); } return res; } /* load_running_config */
/******************************************************************** * FUNCTION agt_cap_set_caps * * Initialize the NETCONF agent capabilities * * INPUTS: * agttarg == the target of edit-config for this agent * agtstart == the type of startup configuration for this agent * defstyle == default with-defaults style for the entire agent * * RETURNS: * NO_ERR if all goes well *********************************************************************/ status_t agt_cap_set_caps (ncx_agttarg_t agttarg, ncx_agtstart_t agtstart, const xmlChar *defstyle) { xmlns_id_t nc_id = xmlns_nc_id(); status_t res = NO_ERR; val_value_t *newcaps = NULL; val_value_t *oldcaps = agt_caps; cap_list_t *oldmycaps = my_agt_caps; const agt_profile_t *agt_profile = agt_get_profile(); /* get a new cap_list */ cap_list_t *newmycaps = cap_new_caplist(); if (!newmycaps) { res = ERR_INTERNAL_MEM; } /* get a new val_value_t cap list for agent <hello> messages */ if (res == NO_ERR) { newcaps = xml_val_new_struct(NCX_EL_CAPABILITIES, nc_id); if (!newcaps) { res = ERR_INTERNAL_MEM; } } /* add capability for NETCONF version 1.0 and/or 1.1 support */ if (res == NO_ERR) { if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) { res = cap_add_std(newmycaps, CAP_STDID_V1); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_V1); } } if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) { res = cap_add_std(newmycaps, CAP_STDID_V11); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_V11); } } } if (res == NO_ERR) { /* set the capabilities based on the native target */ switch (agttarg) { case NCX_AGT_TARG_RUNNING: res = cap_add_std(newmycaps, CAP_STDID_WRITE_RUNNING); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_WRITE_RUNNING); } break; case NCX_AGT_TARG_CANDIDATE: res = cap_add_std(newmycaps, CAP_STDID_CANDIDATE); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_CANDIDATE); } if (res == NO_ERR) { if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) { res = cap_add_std(newmycaps, CAP_STDID_CONF_COMMIT); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_CONF_COMMIT); } } if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) { res = cap_add_std(newmycaps, CAP_STDID_CONF_COMMIT11); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_CONF_COMMIT11); } } } break; default: res = SET_ERROR(ERR_INTERNAL_VAL); break; } } if (res == NO_ERR) { /* set the rollback-on-error capability */ res = cap_add_std(newmycaps, CAP_STDID_ROLLBACK_ERR); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_ROLLBACK_ERR); } } if (res == NO_ERR) { if (agt_profile->agt_usevalidate) { /* set the validate capability */ if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) { res = cap_add_std(newmycaps, CAP_STDID_VALIDATE); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_VALIDATE); } } if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) { res = cap_add_std(newmycaps, CAP_STDID_VALIDATE11); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_VALIDATE11); } } } } /* check the startup type for distinct-startup capability */ if (res == NO_ERR) { if (agtstart==NCX_AGT_START_DISTINCT) { res = cap_add_std(newmycaps, CAP_STDID_STARTUP); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_STARTUP); } } } /* set the url capability */ if (res == NO_ERR) { if (agt_profile->agt_useurl) { res = cap_add_url(newmycaps, AGT_URL_SCHEME_LIST); if (res == NO_ERR) { res = cap_add_urlval(newcaps, AGT_URL_SCHEME_LIST); } } } /* set the xpath capability */ if (res == NO_ERR) { res = cap_add_std(newmycaps, CAP_STDID_XPATH); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_XPATH); } } /* set the notification capability if enabled */ if (agt_profile->agt_use_notifications) { if (res == NO_ERR) { res = cap_add_std(newmycaps, CAP_STDID_NOTIFICATION); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_NOTIFICATION); } } /* set the interleave capability */ if (res == NO_ERR) { res = cap_add_std(newmycaps, CAP_STDID_INTERLEAVE); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_INTERLEAVE); } } } /* set the partial-lock capability */ if (res == NO_ERR) { res = cap_add_std(newmycaps, CAP_STDID_PARTIAL_LOCK); if (res == NO_ERR) { res = cap_add_stdval(newcaps, CAP_STDID_PARTIAL_LOCK); } } /* set the with-defaults capability */ if (res == NO_ERR) { res = cap_add_withdef(newmycaps, defstyle); if (res == NO_ERR) { res = cap_add_withdefval(newcaps, defstyle); } } /* check the return value */ if (res != NO_ERR) { /* toss the new, put back the old */ cap_free_caplist(newmycaps); val_free_value(newcaps); my_agt_caps = oldmycaps; agt_caps = oldcaps; } else { /* toss the old, install the new */ if (oldmycaps) { cap_free_caplist(oldmycaps); } if (oldcaps) { val_free_value(oldcaps); } my_agt_caps = newmycaps; agt_caps = newcaps; } return res; } /* agt_cap_set_caps */
/******************************************************************** * FUNCTION y_ietf_netconf_partial_lock_init * * initialize the ietf-netconf-partial-lock server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_ietf_netconf_partial_lock_init ( const xmlChar *modname, const xmlChar *revision) { agt_profile_t *agt_profile; status_t res; y_ietf_netconf_partial_lock_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp (revision, y_ietf_netconf_partial_lock_R_ietf_netconf_partial_lock)) { return ERR_NCX_WRONG_VERSION; } agt_profile = agt_get_profile(); res = ncxmod_load_module( y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock, y_ietf_netconf_partial_lock_R_ietf_netconf_partial_lock, &agt_profile->agt_savedevQ, &ietf_netconf_partial_lock_mod); if (res != NO_ERR) { return res; } agt_plock_init_done = TRUE; partial_lock_obj = ncx_find_object( ietf_netconf_partial_lock_mod, y_ietf_netconf_partial_lock_N_partial_lock); if (ietf_netconf_partial_lock_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } partial_unlock_obj = ncx_find_object( ietf_netconf_partial_lock_mod, y_ietf_netconf_partial_lock_N_partial_unlock); if (ietf_netconf_partial_lock_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } res = agt_rpc_register_method( y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock, y_ietf_netconf_partial_lock_N_partial_lock, AGT_RPC_PH_VALIDATE, y_ietf_netconf_partial_lock_partial_lock_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock, y_ietf_netconf_partial_lock_N_partial_lock, AGT_RPC_PH_INVOKE, y_ietf_netconf_partial_lock_partial_lock_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock, y_ietf_netconf_partial_lock_N_partial_unlock, AGT_RPC_PH_VALIDATE, y_ietf_netconf_partial_lock_partial_unlock_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_ietf_netconf_partial_lock_M_ietf_netconf_partial_lock, y_ietf_netconf_partial_lock_N_partial_unlock, AGT_RPC_PH_INVOKE, y_ietf_netconf_partial_lock_partial_unlock_invoke); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_ietf_netconf_partial_lock_init */
/******************************************************************** * FUNCTION y_toaster_init * * initialize the toaster server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_toaster_init ( const xmlChar *modname, const xmlChar *revision) { agt_profile_t *agt_profile; status_t res; y_toaster_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_toaster_M_toaster)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp(revision, y_toaster_R_toaster)) { return ERR_NCX_WRONG_VERSION; } agt_profile = agt_get_profile(); res = ncxmod_load_module( y_toaster_M_toaster, y_toaster_R_toaster, &agt_profile->agt_savedevQ, &toaster_mod); if (res != NO_ERR) { return res; } toaster_obj = ncx_find_object( toaster_mod, y_toaster_N_toaster); if (toaster_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } make_toast_obj = ncx_find_object( toaster_mod, y_toaster_N_make_toast); if (toaster_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } cancel_toast_obj = ncx_find_object( toaster_mod, y_toaster_N_cancel_toast); if (toaster_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } toastDone_obj = ncx_find_object( toaster_mod, y_toaster_N_toastDone); if (toaster_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } res = agt_rpc_register_method( y_toaster_M_toaster, y_toaster_N_make_toast, AGT_RPC_PH_VALIDATE, y_toaster_make_toast_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_toaster_M_toaster, y_toaster_N_make_toast, AGT_RPC_PH_INVOKE, y_toaster_make_toast_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_toaster_M_toaster, y_toaster_N_cancel_toast, AGT_RPC_PH_VALIDATE, y_toaster_cancel_toast_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_toaster_M_toaster, y_toaster_N_cancel_toast, AGT_RPC_PH_INVOKE, y_toaster_cancel_toast_invoke); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_toaster_M_toaster, (const xmlChar *)"/toaster", (const xmlChar *)"2009-11-20", y_toaster_toaster_edit); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_toaster_init */
/******************************************************************** * FUNCTION y_simple_list_test_init * * initialize the simple_list_test server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_simple_list_test_init ( const xmlChar *modname, const xmlChar *revision) { status_t res = NO_ERR; agt_profile_t *agt_profile = agt_get_profile(); y_simple_list_test_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_simple_list_test_M_simple_list_test)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp(revision, y_simple_list_test_R_simple_list_test)) { return ERR_NCX_WRONG_VERSION; } res = ncxmod_load_module( y_simple_list_test_M_simple_list_test, y_simple_list_test_R_simple_list_test, &agt_profile->agt_savedevQ, &simple_list_test_mod); if (res != NO_ERR) { return res; } simple_list_obj = ncx_find_object( simple_list_test_mod, y_simple_list_test_N_simple_list); if (simple_list_test_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } inc_counter_obj = ncx_find_object( simple_list_test_mod, y_simple_list_test_N_inc_counter); if (simple_list_test_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } get_counter_obj = ncx_find_object( simple_list_test_mod, y_simple_list_test_N_get_counter); if (simple_list_test_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } res = agt_rpc_register_method( y_simple_list_test_M_simple_list_test, y_simple_list_test_N_inc_counter, AGT_RPC_PH_VALIDATE, y_simple_list_test_inc_counter_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_simple_list_test_M_simple_list_test, y_simple_list_test_N_inc_counter, AGT_RPC_PH_INVOKE, y_simple_list_test_inc_counter_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_simple_list_test_M_simple_list_test, y_simple_list_test_N_get_counter, AGT_RPC_PH_VALIDATE, y_simple_list_test_get_counter_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_simple_list_test_M_simple_list_test, y_simple_list_test_N_get_counter, AGT_RPC_PH_INVOKE, y_simple_list_test_get_counter_invoke); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_list_test_M_simple_list_test, (const xmlChar *)"/simple_list", y_simple_list_test_R_simple_list_test, simple_list_test_simple_list_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_list_test_M_simple_list_test, (const xmlChar *)"/simple_list/theList", y_simple_list_test_R_simple_list_test, simple_list_test_simple_list_theList_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_list_test_M_simple_list_test, (const xmlChar *)"/simple_list/theList/theKey", y_simple_list_test_R_simple_list_test, simple_list_test_simple_list_theList_theKey_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_simple_list_test_M_simple_list_test, (const xmlChar *)"/simple_list/theList/theVal", y_simple_list_test_R_simple_list_test, simple_list_test_simple_list_theList_theVal_edit); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_simple_list_test_init */
/******************************************************************** * FUNCTION agt_ses_check_timeouts * * Check if any sessions need to be dropped because they * have been idle too long. * *********************************************************************/ void agt_ses_check_timeouts (void) { ses_cb_t *scb; agt_profile_t *agt_profile; uint32 i, last; time_t timenow; double timediff; agt_profile = agt_get_profile(); /* check if both timeouts are disabled and the * confirmed-commit is not active -- quick exit */ if (agt_profile->agt_idle_timeout == 0 && agt_profile->agt_hello_timeout == 0 && !agt_ncx_cc_active()) { return; } /* at least one timeout enabled, so check if enough * time has elapsed since the last time through * the process loop; the AGT_SES_TIMEOUT_INTERVAL * is used for this purpose */ (void)time(&timenow); timediff = difftime(timenow, last_timeout_check); if (timediff < (double)AGT_SES_TIMEOUT_INTERVAL) { return; } /* reset the timeout interval for next time */ last_timeout_check = timenow; /* check all the sessions only if idle or hello * timeout checking is enabled */ if (agt_profile->agt_idle_timeout == 0 && agt_profile->agt_hello_timeout == 0) { last = 0; } else if (next_sesid == 0) { last = AGT_SES_MAX_SESSIONS; } else { last = next_sesid; } for (i=1; i < last; i++) { scb = agtses[i]; if (scb == NULL) { continue; } /* check if the the hello timer needs to be tested */ if (agt_profile->agt_hello_timeout > 0 && scb->state == SES_ST_HELLO_WAIT) { timediff = difftime(timenow, scb->hello_time); if (timediff >= (double)agt_profile->agt_hello_timeout) { if (LOGDEBUG) { log_debug("\nHello timeout for session %u", i); } agt_ses_kill_session(scb, 0, SES_TR_TIMEOUT); continue; } } /* check if the the idle timer needs to be tested * check only active sessions * skip if notifications are active */ if (agt_profile->agt_idle_timeout > 0 && scb->active && !scb->notif_active) { timediff = difftime(timenow, scb->last_rpc_time); if (timediff >= (double)agt_profile->agt_idle_timeout) { if (LOGDEBUG) { log_debug("\nIdle timeout for session %u", i); } agt_ses_kill_session(scb, 0, SES_TR_TIMEOUT); continue; } } } /* check the confirmed-commit timeout */ agt_ncx_check_cc_timeout(); } /* agt_ses_check_timeouts */
/******************************************************************** * FUNCTION agt_ses_new_session * * Create a real agent session control block * * INPUTS: * transport == the transport type * fd == file descriptor number to use for IO * RETURNS: * pointer to initialized SCB, or NULL if some error * This pointer is stored in the session table, so it does * not have to be saved by the caller *********************************************************************/ ses_cb_t * agt_ses_new_session (ses_transport_t transport, int fd) { ses_cb_t *scb; agt_profile_t *profile; uint32 i, slot; status_t res; if (!agt_ses_init_done) { agt_ses_init(); } res = NO_ERR; slot = 0; scb = NULL; /* check if any sessions are available */ if (next_sesid == 0) { /* end has already been reached, so now in brute force * session reclaim mode */ slot = 0; for (i=1; i<AGT_SES_MAX_SESSIONS && !slot; i++) { if (!agtses[i]) { slot = i; } } } else { slot = next_sesid; } if (slot) { /* make sure there is memory for a session control block */ scb = ses_new_scb(); if (scb) { /* initialize the profile vars */ profile = agt_get_profile(); scb->linesize = profile->agt_linesize; scb->withdef = profile->agt_defaultStyleEnum; scb->indent = profile->agt_indent; if (ncx_protocol_enabled(NCX_PROTO_NETCONF10)) { scb->protocols_requested |= NCX_FL_PROTO_NETCONF10; } if (ncx_protocol_enabled(NCX_PROTO_NETCONF11)) { scb->protocols_requested |= NCX_FL_PROTO_NETCONF11; } /* initialize the static vars */ scb->type = SES_TYP_NETCONF; scb->transport = transport; scb->state = SES_ST_INIT; scb->mode = SES_MODE_XML; scb->sid = slot; scb->inready.sid = slot; scb->outready.sid = slot; scb->state = SES_ST_INIT; scb->fd = fd; scb->instate = SES_INST_IDLE; scb->stream_output = TRUE; res = ses_msg_new_buff(scb, TRUE, &scb->outbuff); } else { res = ERR_INTERNAL_MEM; } } else { res = ERR_NCX_RESOURCE_DENIED; } /* add the FD to SCB mapping in the definition registry */ if (res == NO_ERR) { res = def_reg_add_scb(scb->fd, scb); } /* check result and add to session array if NO_ERR */ if (res == NO_ERR) { agtses[slot] = scb; /* update the next slot now */ if (next_sesid) { if (++next_sesid==AGT_SES_MAX_SESSIONS) { /* reached the end */ next_sesid = 0; } } if (LOGINFO) { log_info("\nNew session %d created OK", slot); } agttotals->inSessions++; agttotals->active_sessions++; } else { if (scb) { agt_ses_free_session(scb); scb = NULL; } if (LOGINFO) { log_info("\nNew session request failed (%s)", get_error_string(res)); } } return scb; } /* agt_ses_new_session */
/******************************************************************** * FUNCTION cmn_init * * * *********************************************************************/ static status_t cmn_init ( int argc, char *argv[], boolean *showver, help_mode_t *showhelpmode) { #define BUFFLEN 256 status_t res; log_debug_t dlevel; int len; char buff[BUFFLEN]; /* set the default debug output level */ dlevel = LOG_DEBUG_INFO; /* initialize the NCX Library first to allow NCX modules to be processed. * No module can get its internal config until the NCX module parser and * definition registry is up */ len = strlen(START_MSG) + strlen(COPYRIGHT_STRING) + 2; if (len < BUFFLEN) { strcpy(buff, START_MSG); strcat(buff, COPYRIGHT_STRING); } else { return ERR_BUFF_OVFL; } res = ncx_init( FALSE, dlevel, TRUE, buff, argc, argv); if (res != NO_ERR) { return res; } log_debug2("\nnetconfd: Loading Netconf Server Library"); /* at this point, modules that need to read config params can be * initialized */ /* Load the core modules (netconfd and netconf) */ res = load_base_schema(); if (res != NO_ERR) { return res; } /* Initialize the Netconf Server Library with command line and conf file * parameters */ res = agt_init1(argc, argv, showver, showhelpmode); if (res != NO_ERR) { return res; } /* check quick-exit mode */ if (*showver || *showhelpmode != HELP_MODE_NONE) { return NO_ERR; } /* Load the core modules (netconfd and netconf) */ res = load_core_schema(agt_get_profile()); if (res != NO_ERR) { return res; } /* finidh initializing server data structures */ res = agt_init2(); if (res != NO_ERR) { return res; } log_debug("\nnetconfd init OK, ready for sessions\n"); return NO_ERR; } /* cmn_init */
/******************************************************************** * FUNCTION y_starter_init * * initialize the starter server instrumentation library * * INPUTS: * modname == requested module name * revision == requested version (NULL for any) * * RETURNS: * error status ********************************************************************/ status_t y_starter_init ( const xmlChar *modname, const xmlChar *revision) { status_t res = NO_ERR; agt_profile_t *agt_profile = agt_get_profile(); y_starter_init_static_vars(); /* change if custom handling done */ if (xml_strcmp(modname, y_starter_M_starter)) { return ERR_NCX_UNKNOWN_MODULE; } if (revision && xml_strcmp(revision, y_starter_R_starter)) { return ERR_NCX_WRONG_VERSION; } res = ncxmod_load_module( y_starter_M_starter, y_starter_R_starter, &agt_profile->agt_savedevQ, &starter_mod); if (res != NO_ERR) { return res; } starter_obj = ncx_find_object( starter_mod, y_starter_N_starter); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } starter_start_vnf_obj = ncx_find_object( starter_mod, y_starter_N_starter_start_vnf); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } starter_kill_vnf_obj = ncx_find_object( starter_mod, y_starter_N_starter_kill_vnf); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } starter_get_load_obj = ncx_find_object( starter_mod, y_starter_N_starter_get_load); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } starter_get_processes_obj = ncx_find_object( starter_mod, y_starter_N_starter_get_processes); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } processData_obj = ncx_find_object( starter_mod, y_starter_N_processData); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } processDone_obj = ncx_find_object( starter_mod, y_starter_N_processDone); if (starter_mod == NULL) { return SET_ERROR(ERR_NCX_DEF_NOT_FOUND); } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_start_vnf, AGT_RPC_PH_VALIDATE, y_starter_starter_start_vnf_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_start_vnf, AGT_RPC_PH_INVOKE, y_starter_starter_start_vnf_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_kill_vnf, AGT_RPC_PH_VALIDATE, y_starter_starter_kill_vnf_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_kill_vnf, AGT_RPC_PH_INVOKE, y_starter_starter_kill_vnf_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_get_load, AGT_RPC_PH_VALIDATE, y_starter_starter_get_load_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_get_load, AGT_RPC_PH_INVOKE, y_starter_starter_get_load_invoke); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_get_processes, AGT_RPC_PH_VALIDATE, y_starter_starter_get_processes_validate); if (res != NO_ERR) { return res; } res = agt_rpc_register_method( y_starter_M_starter, y_starter_N_starter_get_processes, AGT_RPC_PH_INVOKE, y_starter_starter_get_processes_invoke); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_starter_M_starter, (const xmlChar *)"/starter", y_starter_R_starter, starter_starter_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_starter_M_starter, (const xmlChar *)"/starter/appName", y_starter_R_starter, starter_starter_appName_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_starter_M_starter, (const xmlChar *)"/starter/appParams", y_starter_R_starter, starter_starter_appParams_edit); if (res != NO_ERR) { return res; } res = agt_cb_register_callback( y_starter_M_starter, (const xmlChar *)"/starter/capabilities", y_starter_R_starter, starter_starter_capabilities_edit); if (res != NO_ERR) { return res; } /* put your module initialization code here */ return res; } /* y_starter_init */
/******************************************************************** * FUNCTION set_initial_transaction_id * * Set the last_transaction_id for the running config * Will check for sys:transaction-id leaf in config->root * * RETURNS: * status *********************************************************************/ static status_t set_initial_transaction_id (void) { cfg_template_t *cfg = cfg_get_config_id(NCX_CFGID_RUNNING); if (cfg == NULL) { return ERR_NCX_CFG_NOT_FOUND; } if (cfg->root == NULL) { return ERR_NCX_EMPTY_VAL; } agt_profile_t *profile = agt_get_profile(); status_t res = NO_ERR; boolean foundfile = FALSE; /* figure out which transaction ID file to use */ if (profile->agt_startup_txid_file == NULL) { /* search for the default startup-cfg.xml filename */ xmlChar *fname = ncxmod_find_data_file(NCX_DEF_STARTUP_TXID_FILE, FALSE, &res); if (fname == NULL || res != NO_ERR || *fname == 0) { /* need to set the default startup transaction ID file name */ log_debug("\nSetting initial transaction ID file to default"); if (fname) { m__free(fname); } res = NO_ERR; fname = agt_get_startup_filespec(&res); if (fname == NULL || res != NO_ERR) { if (res == NO_ERR) { res = ERR_NCX_OPERATION_FAILED; } log_error("\nFailed to set initial transaction ID file (%s)", get_error_string(res)); if (fname) { m__free(fname); } return res; } /* get dir part and append the TXID file name to it */ uint32 fnamelen = xml_strlen(fname); xmlChar *str = &fname[fnamelen - 1]; while (str >= fname && *str && *str != NCX_PATHSEP_CH) { str--; } if (*str != NCX_PATHSEP_CH) { log_error("\nFailed to set initial transaction ID file"); m__free(fname); return ERR_NCX_INVALID_VALUE; } /* copy base filespec + 1 for the path-sep-ch */ uint32 baselen = (uint32)(str - fname) + 1; uint32 newlen = baselen + xml_strlen(NCX_DEF_STARTUP_TXID_FILE); xmlChar *newstr = m__getMem(newlen + 1); if (newstr == NULL) { m__free(fname); return ERR_INTERNAL_MEM; } str = newstr; str += xml_strncpy(str, fname, baselen); xml_strcpy(str, NCX_DEF_STARTUP_TXID_FILE); m__free(fname); profile->agt_startup_txid_file = newstr; // pass off memory here } else { foundfile = TRUE; profile->agt_startup_txid_file = fname; // pass off memory here } } /* initialize the starting transaction ID in the config module */ res = agt_cfg_init_transactions(profile->agt_startup_txid_file, foundfile); if (res != NO_ERR) { log_error("\nError: cfg-init transaction ID failed (%s)", get_error_string(res)); } return res; } /* set_initial_transaction_id */