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

📄 rtab.c

📁 基于东南大学开发的SEP3203的ARM7中的所有驱动
💻 C
📖 第 1 页 / 共 4 页
字号:

        else

            /* Add this route to the SNMP routing table */
            SNMP_ipRouteTableUpdate (SNMP_ADD, (INT)(device->dev_index), dest_ptr,
                re.metric, (UNSIGNED)-1, (UNSIGNED)-1, (UNSIGNED)-1, (UNSIGNED)-1, 
                gw_ptr, 3, 8, 0, re.submask, "0.0");
    }

#endif

    return(st);
}   /* RTAB_Add_Route */

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       RTAB_Insert_Node                                                
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       Insert a node to either the left or right side of node.         
*                                                                       
*   INPUTS                                                                
*                                                                       
*       n           node to insert into tree                              
*                                                                       
*   OUTPUTS                                                               
*                                                                       
*       Returns TRUE or FALSE.                                           
*                                                                       
*************************************************************************/
int RTAB_Insert_Node( ROUTE_NODE *n )
{
    int dir;
    int ret = 0;
    VOID *pointer;
    STATUS status;
    ROUTE_NODE *node, *nn, *r;

    r = Root_Node;

    /* If this is the first time called then setup root node */
    if( r == NULL_ROUTE_NODE )
    {
        r = Root_Node = RTAB_Create_Node();

        /* Allocate space for the rip2 structure. */
        status = NU_Allocate_Memory (&System_Memory, &pointer,
                                    sizeof(RIP2_ENTRY), NU_SUSPEND);

        if (status != NU_SUCCESS)
            return(-1);                 /* could not get the memory */

        r->rt_rip2 = (RIP2_ENTRY *)pointer;

        /* Allocate space for the rip2 structure. */
        status = NU_Allocate_Memory (&System_Memory, &pointer,
                                    sizeof(RIP2_AUTH_ENTRY), NU_SUSPEND);

        if (status != NU_SUCCESS)
            return(-1);                 /* could not get the memory */

        r->rt_auth = (RIP2_AUTH_ENTRY *)pointer;

        *(r->rt_rip2) = *(n->rt_rip2);
        r->rt_gateway.sck_addr = n->rt_gateway.sck_addr;
        r->rt_gateway.sck_family = NU_FAMILY_IP;
        r->rt_gateway.sck_len = sizeof(r->rt_gateway);
        
        if( n->rt_auth )
            *(r->rt_auth) = *(n->rt_auth);
        else
            r->rt_auth = 0;
        r->rt_device = n->rt_device;
        r->rt_clock = NU_Retrieve_Clock();
        r->rt_refcnt = n->rt_refcnt;
        r->rt_use = n->rt_use;
        r->rt_flags = n->rt_flags;

        return(ret);
    }
    else
    {
        node = RTAB_Find_Leaf(n);
        if( node == NULL_ROUTE_NODE )
            return(-1);
    }
    
    /* find out which side it is to go on. */
    dir = RTAB_Compare_Addresses(node, n);
    switch( dir )
    {
        case CMP_ERROR:
            break;

        case MIDDLE:
            RTAB_Update_Address(node, n);
            break;

        default:
            /* Do not add infinity routes. (see RFC 1058) */
            if (n->rt_rip2->metric >= RT_INFINITY )
                break;

            /* make sure that child pointer is really null */
            if( node->rt_child[dir] )
                return( -1 );

            /* create a new node */
            nn = RTAB_Create_Node();

            /* make sure that it was allocated */
            if( nn == NULL_ROUTE_NODE )
                return(-1);

            /* Allocate space for the rip2 structure. */
            status = NU_Allocate_Memory (&System_Memory, &pointer,
                                        sizeof(RIP2_ENTRY), NU_SUSPEND);

            if (status != NU_SUCCESS)
                return(-1);                     /* could not get the memory */

            nn->rt_rip2 = (RIP2_ENTRY *)pointer;

            /* Allocate space for the rip2 structure. */
            status = NU_Allocate_Memory (&System_Memory, &pointer,
                                        sizeof(RIP2_AUTH_ENTRY), NU_SUSPEND);

            if (status != NU_SUCCESS)
                return(-1);                     /* could not get the memory */

            nn->rt_auth = (RIP2_AUTH_ENTRY *)pointer;

            /* point mode to new node */
            node->rt_child[dir] =nn;

            /* point new node parent pointer to it's parent */
            nn->rt_parent = node;
            nn->rt_gateway.sck_addr = n->rt_gateway.sck_addr;
            nn->rt_gateway.sck_family = NU_FAMILY_IP;
            nn->rt_gateway.sck_len = sizeof (nn->rt_gateway);

            *(nn->rt_rip2) = *(n->rt_rip2);
            if ( n->rt_auth )
                *(nn->rt_auth) = *(n->rt_auth);
            nn->rt_device = n->rt_device;
            nn->rt_clock = NU_Retrieve_Clock();
            nn->rt_refcnt = n->rt_refcnt;
            nn->rt_use = n->rt_use;
            nn->rt_flags = n->rt_flags;
            break;
    }

    return(ret);
}   /* RTAB_Insert_Node */

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       RTAB_Update_Address                                             
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       Update the node with new data and reset the clock.              
*                                                                       
*   INPUTS                                                                
*                                                                       
*       *r          node to update                                        
*       *n          data to update with.                                  
*                                                                       
*   OUTPUTS                                                               
*                                                                       
*       Returns 0 for success and -1 for failure.                        
*                                                                       
*************************************************************************/
int RTAB_Update_Address( ROUTE_NODE *r, ROUTE_NODE *n )
{
    UINT32 addr1, addr2, mask1, mask2;

    if( r == NULL_ROUTE_NODE || n == NULL_ROUTE_NODE )
        return( -1 );
    
    /* to see if it really needs to be updated, but always update the clock */

    addr1 = *(UINT32 *)r->rt_rip2->ip_addr;
    addr2 = *(UINT32 *)n->rt_rip2->ip_addr;
    mask1 = *(UINT32 *)r->rt_rip2->submask;
    mask2 = *(UINT32 *)n->rt_rip2->submask;
    addr1 = addr1 & mask1;
    addr2 = addr2 & mask2;

    if( r->rt_rip2->metric > n->rt_rip2->metric || addr1 != addr2 )
    {
        /* What n points to is reused by the caller, so we have to copy it. */
        /* and we do not want to free and reallocate memory. */
        *(r->rt_rip2) = *(n->rt_rip2);
        r->rt_gateway = n->rt_gateway;
        if( n->rt_auth )
            *(r->rt_auth) = *(n->rt_auth);
        else
            r->rt_auth = 0;
        r->rt_device = n->rt_device;  /* only the address to device struct */

        r->rt_clock = NU_Retrieve_Clock();

        /* Update with the new flags setting. */
        r->rt_flags = n->rt_flags;

    }
    else
    {
        /* Don't update rt_clock unless this route was received on the same
         * interface card.
         */
        if( r->rt_device->dev_addr.dev_ip_addr == 
            n->rt_device->dev_addr.dev_ip_addr )
        {
            r->rt_clock = NU_Retrieve_Clock();
        }

        /* Update with the new flags setting. */
        r->rt_flags = n->rt_flags;

    }

    return(0);

}   /* RTAB_Update_Address */

/*************************************************************************
*                                                                       
*   FUNCTION                                                              
*                                                                       
*       RTAB_Delete_Node                                                
*                                                                       
*   DESCRIPTION                                                           
*                                                                       
*       Delete a node from the left or right side of node.              
*                                                                       
*   INPUTS                                                                
*                                                                       
*       *dn             node you want deleted.                            
*                                                                       
*   OUTPUTS                                                               
*                                                                       
*       int             0 or -1                                  
*                                                                       
*************************************************************************/
int RTAB_Delete_Node( ROUTE_NODE *dn )
{
    ROUTE_NODE *q, *rp, *s, *f = NU_NULL;

    if( (Root_Node == NULL_ROUTE_NODE) || (dn == NU_NULL) )
        return(-1);

    /* NOTE: if the refcnt is greater than 1 then we silently keep */
    /* the node and mark the interface as being down. */

    if( dn->rt_refcnt > 0 )
    {
        dn->rt_flags &= ~RT_UP;
        return(0);
    }

    if( ISLEAF(dn) )            /* it's a leaf, then just delete it */
    {
        /* node has no children attached. */
        rp = dn->rt_parent;

        if( dn->rt_rip2 )
            NU_Deallocate_Memory(dn->rt_rip2);
        if( dn->rt_auth )
            NU_Deallocate_Memory(dn->rt_auth);
        
        dn->rt_device = 0;
        dn->rt_parent = 0;
        dn->rt_refcnt = 0;
        dn->rt_use = 0;
        dn->rt_flags = 0;
        UTL_Zero(&(dn->rt_gateway), sizeof(SCK_SOCKADDR_IP));

        /* which parent child was I deleting */
        if( rp )
        {
            if(rp->rt_child[LESS] == dn)
                rp->rt_child[LESS] = 0;
            else
                rp->rt_child[MORE] = 0;
        }
        else
            Root_Node = NULL_ROUTE_NODE;
    }
    else
    if( dn->rt_child[LESS] != 0 && dn->rt_child[MORE] != 0 )
    {
        /* node has two children attached. */
        q  = dn->rt_parent;
        rp = dn->rt_child[LESS];
        s  = dn->rt_child[MORE];
        while( s )
        {
            f = rp;
            rp = s;
            s = rp->rt_child[LESS];
        }
    
        if( rp != dn->rt_child[MORE] )
        {
            s = rp->rt_child[MORE];        /*  <--- we added this */
            rp->rt_child[MORE] = dn->rt_child[MORE];
            rp->rt_child[MORE]->rt_parent = rp;       /*  <--- we added this */
            f->rt_child[LESS] = s;
            if (f->rt_child[LESS])                       /*  <--- we added this */
                f->rt_child[LESS]->rt_parent = f;
        }
        rp->rt_child[LESS] = dn->rt_child[LESS];

⌨️ 快捷键说明

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