📄 ospf_system.c
字号:
semDelete (ospf_startup_sem_id); return ERROR; }#if defined (__OSPF_MIB__)/********************************************************************************* ospf_startup - startup OSPF protocol** This routine startup the OSPF Protocol. It is invoked by the MIB API to * dynamically bring up the OSPF. No FTP capability can be used since the * configuration parameters required for FTP operation is not accessible by MIB * API. Therefore, OSPF configuration will be read either from NVRAM or the * pre-compile ospf_cfg (from the ospf_cfg.c file).** NOTE:* User *shall* not invoke this routine from WindShell and/or target shell.** RETURNS: N/A*/STATUS ospf_startup () { int spl_value; FAST struct protosw *p_ospf_protocol_switch = NULL; /* asr: check if ospf_startup was called previously */ if (ospf.protocol_initialized == TRUE) { printf("OSPF was already initialized... Nothing to be done.\n"); return OK; } /* asr: since this function is intended to be called from MAPI, make sure that virtual stack context is set to the value configured in project facility. */#if defined (VIRTUAL_STACK) virtualStackNumTaskIdSet (ospf.ospf_vsid);#endif /* VIRTUAL_STACK */ /* asr: moved OSPF protocol registration from ospfInitialize to here so that OSPF is able to register with any virtual stack instance after the boot and not just virtual stack 0. */ /* * since this routine is invoked in the context of the usrAppInit(), access to * the protosw protocol table must be protected. This is because the stack has * completed its initialization at this time and there may be network activities * while OSPF is trying to register its protocol type to IP. To avoid any * possible collisions, lock out the tNetTask when OSPF is accessing the protosw * protocol table. */ spl_value = splnet (); if (_protoSwIndex >= ((sizeof(inetsw))/(sizeof(inetsw[0])))) { splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: _protoSwIndex not correct ... Returning error\r\n"); return ERROR; } p_ospf_protocol_switch = &inetsw [_protoSwIndex]; if (p_ospf_protocol_switch->pr_domain != NULL) { splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF has already been registered with Router Stack\r\n"); } else { p_ospf_protocol_switch->pr_type = SOCK_RAW; p_ospf_protocol_switch->pr_domain = &inetdomain; p_ospf_protocol_switch->pr_protocol = IPPROTO_OSPF; p_ospf_protocol_switch->pr_flags = PR_ATOMIC|PR_ADDR; /* use rip_input to receive packets from IP layer */ p_ospf_protocol_switch->pr_input = rip_input; /* pr_output and pr_ctlinput in protosw[] are not used by raw socket */ p_ospf_protocol_switch->pr_output = 0; p_ospf_protocol_switch->pr_ctlinput = 0; p_ospf_protocol_switch->pr_ctloutput = rip_ctloutput; p_ospf_protocol_switch->pr_usrreq = rip_usrreq; p_ospf_protocol_switch->pr_init = 0 ; p_ospf_protocol_switch->pr_fasttimo = 0; p_ospf_protocol_switch->pr_slowtimo = 0; p_ospf_protocol_switch->pr_drain = 0; p_ospf_protocol_switch->pr_sysctl = 0; ip_protox[IPPROTO_OSPF] = (unsigned char)_protoSwIndex; _protoSwIndex++; /* release the spl semaphore previously taken */ splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "Register OSPF to IP Protocol switch table...OK\r\n"); }#if !defined(__OSPF_VIRTUAL_STACK__) /* * Call ospf_cfg to setup ospf_configuration_text[] for static configuration */ ospf_cfg();#endif /* __OSPF_VIRTUAL_STACK__ */ ospf_task_initialize (ospf_configuration_text); if (ospf_create_tasks() != ERROR) { /* asr: set protocol_initialized flag to true */ ospf.protocol_initialized = TRUE; } return OK; } /********************************************************************************* ospf_management_init - initialize ospf management facilities** This routine initialize the ospf management facilities as well the Envoy * application interface for OSPF-MIB and WRN-OSPF Enterprise MIB. This routine* can be invoked either from command line or be included in the usrAppInit.c * from Project Facility. It is important to mention that this routine MUST be* invoked prior OSPF is initialized. It is also the implementation goal to * allow the OSPF configuration be mangement with or without OSPF protocol * running.** RETURNS: OK or ERROR*/STATUS ospf_management_init (){ STATUS rc; /* Setting all function pointer tp NULL implies system does not have nonvolatile * memory for saving the OSPF configuration. */ rc = ospfMapiInit( NULL, /* NVRAM_SAVE_FUNCPTR, to save configuration to nvram */ NULL, /* NVRAM_DELETE_FUNCPTR, to delete a row from nvram */ NULL /* NVRAM_RETRIEVE_FUNCPTR, to retrieve config from nvram */ ); /* if failed to initialize MIB API, do not continue */ if ( rc == ERROR ) { printf("ospf_management_init:ospf_mApi_init() failed\n"); return ERROR; }#if defined(__ENVOY_SNMP_API__) /* intialize the RFC1850 OSPF-MIB management facility */ if ( ospfEnvoyInit() == ERROR ) { printf("ospf_management_init:ospfEnvoyInit failed\n"); return ERROR; } /* initialize the WRN OSPF-MIB Enterprise MIB */ if ( ospfEnvoyWrnInit() == ERROR ) { printf("ospf_management_init:ospfEnvoyWrnInit failed\n"); return ERROR; }#endif /* __ENVOY_SNMP_API__ */ return OK;}#endif /* __OSPF_MIB__ *//******************************************************************************** ospf_init - initialize the OSPF instance** This function initializes the OSPF instance.** RETURNS: OK on success, ERROR otherwise.** ERRNO: N/A** NOMANUAL*/#if defined (__OSPF_FTP__)STATUS ospf_init ( const char * p_configuration_file, const char * p_ftp_server_address, const char * p_directory, const char * p_user, const char * p_password )#elseint ospf_init ()#endif { int spl_value; FAST struct protosw *p_ospf_protocol_switch = NULL; /* asr: check if ospf_init was called previously */ if (ospf.protocol_initialized == TRUE) { printf ("OSPF was already initialized.. nothing to be done.\n"); return OK; } /* asr: since this function is intended to be called from the shell, make sure that OSPF is being started in the right virtual stack context. Here we assume that the virtual stack ID would have been set already as a result of call to virtualStackCreate or virtualStackNumTaskIdSet prior to calling ospf_init from the shell. */#if defined (VIRTUAL_STACK) if ( ospf.ospf_vsid != myStackNum ) { printf ("OSPF is being started in wrong virtual stack.\n"); return ERROR; }#endif /* VIRTUAL_STACK */ /* asr: moved OSPF protocol registration from ospfInitialize to here so that OSPF is able to register with any virtual stack instance and not just virtual stack 0. Also, we can now validate if OSPF is started in the correct virtual stack (as configured in the project facility). */ /* * since this routine is invoked in the context of the usrAppInit(), access to * the protosw protocol table must be protected. This is because the stack has * completed its initialization at this time and there may be network activities * while OSPF is trying to register its protocol type to IP. To avoid any * possible collisions, lock out the tNetTask when OSPF is accessing the protosw * protocol table. */ spl_value = splnet (); if (_protoSwIndex >= ((sizeof(inetsw))/(sizeof(inetsw[0])))) { splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: _protoSwIndex not correct ... Returning error\r\n"); return ERROR; } p_ospf_protocol_switch = &inetsw [_protoSwIndex]; if (p_ospf_protocol_switch->pr_domain != NULL) { splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF has already been registered with Router Stack\r\n"); } else { p_ospf_protocol_switch->pr_type = SOCK_RAW; p_ospf_protocol_switch->pr_domain = &inetdomain; p_ospf_protocol_switch->pr_protocol = IPPROTO_OSPF; p_ospf_protocol_switch->pr_flags = PR_ATOMIC|PR_ADDR; /* use rip_input to receive packets from IP layer */ p_ospf_protocol_switch->pr_input = rip_input; /* pr_output and pr_ctlinput in protosw[] are not used by raw socket */ p_ospf_protocol_switch->pr_output = 0; p_ospf_protocol_switch->pr_ctlinput = 0; p_ospf_protocol_switch->pr_ctloutput = rip_ctloutput; p_ospf_protocol_switch->pr_usrreq = rip_usrreq; p_ospf_protocol_switch->pr_init = 0 ; p_ospf_protocol_switch->pr_fasttimo = 0; p_ospf_protocol_switch->pr_slowtimo = 0; p_ospf_protocol_switch->pr_drain = 0; p_ospf_protocol_switch->pr_sysctl = 0; ip_protox[IPPROTO_OSPF] = (unsigned char)_protoSwIndex; _protoSwIndex++; /* release the spl semaphore previously taken */ splx (spl_value); OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "Register OSPF to IP Protocol switch table...OK\r\n"); }#if defined(__OSPF_MIB__) if ( ospf_management_init() == ERROR ) { printf("ospf_init:ospf_management_init() failed\n"); return ERROR; } #endif /* __OSPF_MIB__ */#if !defined(__OSPF_VIRTUAL_STACK__) /* call ospf_cfg to setup ospf_configuration_text[] for static configuration */ ospf_cfg();#endif /* __OSPF_VIRTUAL_STACK__ */#if defined (__OSPF_FTP__) ospf.ftp_configuration_file = p_configuration_file; ospf.ftp_server_address = p_ftp_server_address; ospf.ftp_dir = p_directory; ospf.ftp_user = p_user; ospf.ftp_pwd = p_password; if (open_configuration_file (p_configuration_file, p_ftp_server_address, p_directory, p_user, p_password) == false) { return ERROR; } ospf_task_initialize (configuration_data);#else ospf_task_initialize (ospf_configuration_text);#endif if (ospf_create_tasks() != ERROR) { /* asr: set protocol_initialized flag to true */ ospf.protocol_initialized = TRUE; }#if defined (__OSPF_FTP__) close_configuration_file ( );#endif /*__OSPF_FTP__*/ return OK; }
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -