⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 ospf_init.c

📁 vxworks下ospf协议栈
💻 C
字号:
/* ospf_init.c - initialize the OSPF protocol and register with IP *//* Copyright 1998 - 2003 Wind River Systems, Inc. */#include "copyright_wrs.h"/*modification history--------------------02l,11jun03,agi  Fixed SPR#88950, made ospfPartMemInitialize() global02k,10jun03,kkz  SPR 88929 Moved creation of ospf semaphores to here, and removed setting                 of ospf.ospf_enabled to TRUE02j,02jun03,agi  Set ospf.ospf_enabled to TRUE02i,02jun03,ram  Initialize OSPF memory partition in ospfInitialize02h,30may03,agi  removed ospfRawInputTaskId02g,08may03,asr  Changes to make OSPF virtual stack compatible02f,26may03,agi  Removed RWOS_MUTEXs02e,22apr03,ram  SPR#76812 Modifications for OSPF performance enhancements02d,17feb02,ram  SPR 81808 Added OSPF memory partition support02c,10feb03,kc   Fixed SPR#86175 - modified ospfInitialize() to ensure exclussive                 access to the protosw protocol table when OSPF is registered its                 protocol type to IP. Changed all printf statemets to use                 OSPF_PRINTF_DEBUG debug macro. Moved all ospf_xxx_stub()                 function calls from ospfInitialize() to ospf_initialize_router()                 in the ospf_initialization.c file.02c,28jan03,ram  SPR 85050 Added new mutex for external route queue02b,19nov02,mwv  Merge TMS code SPR 8428402a,08oct02,agi  Fixed compiler warning01k,15may02,jkw  Added capability to change external route queue to AVL tree.01j,25apr02,jkw  Added in ospf_show_routing_stub for displaying routing table.01i,12feb02,kc   Fixed compiler warnings.01h,11feb02,kc   Corrected misleading printf statement.01g,22sep01,kc   Fixed protosw[] for raw socket.01f,17sep01,kc   Moved ospfConfigurationTableInit() to ospf_vs_lib.c. Moved                 virtual initialization to ospf_initialize_protocol(). Moved                 ospf_show_xxx extern statements to ospf_prototypes.h. Moved                 ospf_cfg() to ospf_init().01e,23aug01,jkw  Fxed compiler warnings.01d,13aug01,kc   Fixed compiler warning for __NSSA__01c,13aug01,kc   Fixed compiler warning - changed ospf_receive() function to use                 void returned type.01b,24jul01,jkw  Removed WINROUTER preproc01a,23jul01,jkw  Added new configuration variables for ignoring tos and demand circuit*//*DESCRIPTIONospf_init.c is used for registering OSPF to the IP protocol using the protoswstructure.  This file will check to see if the OSPF has been initialized on thesending and receiving of OSPF packets.This file is used at the startup of OSPF.*/#include <stdio.h>#include <vxWorks.h>#include <netLib.h>#include <net/protosw.h>#include <net/domain.h>#include <net/mbuf.h>#include <netinet/in.h>#include <netinet/in_systm.h>#include <netinet/in_pcb.h>#include <netinet/ip.h>#include <netinet/ip_var.h>#include "ospf.h"#if defined (__OSPF_VIRTUAL_STACK__)    #include "ospf_vs_lib.h"#endif /* __OSPF_VIRTUAL_STACK__ *//*************************************************************************************************//* externs */#if !defined (VIRTUAL_STACK)    IMPORT int  _protoSwIndex;    IMPORT struct protosw   inetsw [IP_PROTO_NUM_MAX];    IMPORT u_char ip_protox[IPPROTO_MAX];#endif/* globals */#if !defined (__OSPF_VIRTUAL_STACK__)    OSPF_CLASS ospf;    /*raw socket - Added socket for input jkw*/    int ipSock;    OSPF_CALLBACK_IF OspfRegistrationInfo;    char ospf_configuration_text[OSPF_MAXIMUM_FILE_SIZE + 1];    UINT ten_seconds_counter;    /* SPR 81808 -- Begin */    ULONG ospfMemPartId;    /* SPR 81808 -- End */    /*RFC 1765*/    ULONG ospf_db_overflow_timer;#endif /* __OSPF_VIRTUAL_STACK__ */#if defined (__OSPF_ROUTER_STACK__)    extern void ospf_ctlinput(unsigned long intf, unsigned short intf_index, int intf_flags);    extern void  ospf_kernel_register_with_ip (FP_OSPF_RECEIVE pospfReceive,                                               FP_OSPF_SEND pospfSend);    extern void ospf_kernel_deregister_with_ip (FP_OSPF_RECEIVE pospfReceive,                                                FP_OSPF_SEND pospfSend);#else /*__OSPF_ROUTER_STACK__*/    extern void ospf_ctlinput (int command, struct sockaddr *sa,register struct ip *ip);#endif/*__OSPF_ROUTER_STACK__*/extern void ospf_init (void);#if defined (__OSPF_ROUTER_STACK__)    #if defined (__OSPF_VIRTUAL_STACK__)        /* Management stack identifier */        OSPF_VSID mgmtStackId;        void ospfConfigurationTableInit(CONFIGURATION_TABLE *configuration_table);    #endif /* OSPF_VIRTUAL_STACK */#endif /* __OSPF_ROUTER_STACK__ *//*************************************************************************************************//********************************************************************************  ospf_create_mutexes - create OSPF mutex semaphores** This function create OSPF mutex semaphores** RETURNS: OK on success, ERROR is a mutex semaphore could not be created** NOMANUAL*/STATUS ospf_create_mutexes ()    {    /* create global OSPF mutex semaphore for accessing OSPF datastructures */    ospf_global_mutex = semMCreate (        SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);    if (ospf_global_mutex == NULL)        {        printf ("ospf_create_tasks: ERROR: ");        printf ("Could not create global OSPF semaphore, exiting\n");        return ERROR;        }    /* create OSPF external router mutex semaphore */    ospf_external_route_mutex = semMCreate (        SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);    if (ospf_external_route_mutex == NULL)        {        printf ("ospf_create_tasks: ERROR: ");        printf ("Could not create OSPF external route mutex semaphore, ");        printf ("exiting\n");        return ERROR;        }    /* create OSPF config mutex semaphore */    ospf_config_mutex = semMCreate (        SEM_Q_PRIORITY | SEM_INVERSION_SAFE | SEM_DELETE_SAFE);    if (ospf_config_mutex == NULL)        {        printf ("ospf_create_tasks: ERROR: ");        printf ("Could not create OSPF config mutex semaphore, exiting\n");        return ERROR;        }    return OK;    }/*************************************************************************** ospfInitialize - registration function for OSPF to IP and RTM** This routine will make the appropriate registration calls to IP* and to the routing table manager.** <autostart> Auto start OSPF when the router comes up** <vsNum> May or may not be used.  Used for multiple instances of OSPF** RETURNS: INT** ERRNO: N/A** NOMANUAL*/#if defined (__OSPF_ROUTER_STACK__)int ospfInitialize (int vsNum){    #if defined (VIRTUAL_STACK)        /* asr: ospf_vs_id will be ignored if virtual stacks are not used */        ospf.ospf_vsid = vsNum;    #else        ospf.ospf_vsid = 0;    #endif    /* SPR 81808 -- Begin */    if(ospfPartMemInitialize() == FALSE)    {       OSPF_PRINTF_ALARM(OSPF_ALARM_PRINTF,"Failed to initialize OSPF memory partition. \n\r");       return(ERROR);    }    /* SPR 81808 -- End */    #if defined (__OSPF_VIRTUAL_STACK__)        /* Initialize support for virtual stacks. */        if (ospfVirtualStackLibInit() == ERROR) {            OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF,                               "ospfInitialize: unable to initialize ospf virtual stack support.\n");            return(ERROR);        }        /* set the startup task to create the ospf management stack */        if (ospfVirtualStackCreate (&mgmtStackId) == ERROR) {            OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "Unable to setup stack0.\n");            return(ERROR);        }        /* Start the initial ("management") ospf virtual stack. */        ospfVirtualStackInit (mgmtStackId);        ospfConfigurationTableInit(&ospf_configuration_table);    #endif/* __OSPF_VIRTUAL_STACK__ */    OspfRegistrationInfo.ospfEnabled = 0;    if (ospf_create_mutexes() == ERROR)        {        printf("OSPF: could not create mutex semaphores, exiting ...\n");        return ERROR;        }    /* asr: initialize protocol_initialized flag to false.     * After ospf_init is called, and initialization is successful,     * the flag would be set to true.     */    ospf.protocol_initialized = FALSE;    return(OK);}#endif /* __OSPF_ROUTER_STACK__ *//*************************************************************************** ospf_register_with_ip - registration function for OSPF to IP** This routine will make the appropriate registration calls to IP.** <pospfReceive> Receive function pointer to IP** <pospfSend> Send function pointer to IP** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/#if defined (__OSPF_ROUTER_STACK__)void ospf_register_with_ip (FP_OSPF_RECEIVE pospfReceive, FP_OSPF_SEND pospfSend){    ospf_kernel_register_with_ip(pospfReceive, pospfSend);    return;}/*************************************************************************** ospf_deregister_with_ip - deregistration function for OSPF to IP** This routine will make the appropriate deregistration calls to IP.** <pospfReceive> Receive function pointer to IP** <pospfSend> Send function pointer to IP** RETURNS: N/A** ERRNO: N/A** NOMANUAL*/void ospf_deregister_with_ip (FP_OSPF_RECEIVE pospfReceive, FP_OSPF_SEND pospfSend){    ospf_kernel_deregister_with_ip(pospfReceive, pospfSend);    return;}#else /* __OSPF_ROUTER_STACK__ */void ospf_register_with_ip (FP_OSPF_RECEIVE pospfReceive, FP_OSPF_SEND pospfSend){    OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_register_with_ip\r\n");    OspfRegistrationInfo.pOSpfReceive = pospfReceive;    OspfRegistrationInfo.pOSpfSend = pospfSend;    OspfRegistrationInfo.ospfEnabled = 1;    return;}void ospf_deregister_with_ip (FP_OSPF_RECEIVE pospfReceive, FP_OSPF_SEND pospfSend){    OSPF_PRINTF_DEBUG (OSPF_DEBUG_PRINTF, "OSPF: Entering ospf_deregister_with_ip\r\n");    OspfRegistrationInfo.pOSpfReceive = pospfReceive;    OspfRegistrationInfo.pOSpfSend = pospfSend;    OspfRegistrationInfo.ospfEnabled = 0;    return;}#endif /* __OSPF_ROUTER_STACK__ *//* SPR 81808 -- Begin *//******************************************************************************* ospfPartMemInitialize - initialize OSPF memory partition** This function initializes the OSPF memory partition and sets the partition* expansion parameters.** RETURNS: TRUE/FALSE*/bool ospfPartMemInitialize ()    {    ospfMemPartId = OSPF_PARTMEM_CREATE (OSPF_PARTMEM_LARGE_SIZE);    if(!ospfMemPartId)        {        /*         * Failed to allocate larget memory partition         * try allocating smaller partition         */         ospfMemPartId = OSPF_PARTMEM_CREATE (OSPF_PARTMEM_SMALL_SIZE);         if (!ospfMemPartId)             {             return (FALSE);             }        }     /* Configure OSPF partition */     OSPF_PARTMEM_CONFIG;     return (TRUE);    }/* SPR 81808 -- End */

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -