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

📄 spantask.c

📁 基于vxworks操作系统,Tornado2.0平台,生成树STP源码.直接在其对应的设备中添加即可.
💻 C
📖 第 1 页 / 共 4 页
字号:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  set_stp_port_enable
    (
    ulong_t port,
    ulong_t status,
    Boolean startup
    )
{
#if 0
    printf("set_stp_port_enable: port = %ld  status = %ld  startup = %d\n",
            port, status, startup);
#endif
    if (startup == True)
        port_info[port].state = (status == 1) ? Blocking : Disabled;
    else
        (void) stpQSend( (status == 1) ? SPAN_PORT_ENABLE : SPAN_PORT_DISABLE,
                         (void *)port, 0);
}

/*******************************************************************************
* set_stp_protocol_state  -
*
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  set_stp_protocol_state
    (
    ulong_t port,
    ulong_t state,
    Boolean startup
    )
{
    if (startup == True)
        port_info[port].protocol_enabled = state == 1 ? True : False;
    else
        (void) stpQSend( (state == 1) ? SPAN_PROTO_ENABLE : SPAN_PROTO_DISABLE,
                         (void *)port, 0);
}

/*******************************************************************************
* get_stp_priority  -
*
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
ulong_t get_stp_priority
    (
    void
    )
{
    return (ulong_t)ntohs(bridge_info.bridge_id.priority);
}

/*******************************************************************************
* set_stp_priority  -
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  set_stp_priority
    (
    ulong_t priority,
    Boolean startup
    )
{
    if (startup == True)
        bridge_info.bridge_id.priority = htons((ushort_t) priority);
    else
        (void) stpQSend( SPAN_PRIO_CHANGE, (void *)priority, 0 );
}

/*******************************************************************************
* get_stp_port_priority  -
*
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
ulong_t get_stp_port_priority
    (
    ulong_t port
    )
{
    ulong_t Rc;
    uchar_t port_priority = (port_info[port].port_id >> 8);

    Rc = (ulong_t) port_priority;
    return Rc;
}

/*******************************************************************************
* set_stp_port_priority  -
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  set_stp_port_priority
    (
    ulong_t port,
    ulong_t priority,
    Boolean startup
    )
{
    Port_id port_id = port_info[port].port_id & 0xff;

    port_id |= ((uchar_t) priority << 8);

    if (startup == True)
        port_info[port].port_id = port_id;
    else
        (void) stpQSend( SPAN_PORT_PRIO_CHANGE, (void *)port, port_id );
}

/*******************************************************************************
* span_update_bridge_parms  -
*
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  span_update_bridge_parms
    (
    void
    )
{
    (void) stpQSend( SPAN_UPDATE_BRIDGE, (void *)0, 0 );
}

/*******************************************************************************
* get_stp_port_path_cost  -
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
ulong_t get_stp_port_path_cost
    (
    ulong_t port
    )
{
    ulong_t Rc = (ulong_t) port_info[port].path_cost;
    return Rc;
}

/*******************************************************************************
* set_stp_port_path_cost  -
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void  set_stp_port_path_cost
    (
    ulong_t port,
    ulong_t cost,
    Boolean startup
    )
{
    if (startup == True)
        port_info[port].path_cost = (Cost_t) cost;
    else
        (void) stpQSend( SPAN_PORT_PATH_COST_CHANGE, (void *)port, cost );
}

/*******************************************************************************
* span_send_config_bpdu  - Send routine for Config BPDU
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL
*/
void span_send_config_bpdu
    (
    int port_no,
    Config_bpdu * bpdu
    )
{
    M_BLK_ID    pMblk;
    uchar_t     * p;
    ulong_t     value;
    END_OBJ *   pEnd;
    uchar_t     * buf;
 
    pEnd = endFindByName (&(deviceName[port_no-1][0]), portNum[port_no - 1]);
    if (!pEnd)
        return;
 
    if ( (port_info[port_no].protocol_enabled == True) &&
         (get_stp_global_enable()             == True))
    { 
        dbgPrintf (STP_TXPDU, ("[%d:TxPDU]", port_no));
        /*
         * Always allocate the MAX buffer size and adjust later. This works
         * because we only have one size in STP code.
         */
        pMblk = netTupleGet( SpanDrvCtrl->pNetPool, SPAN_BUFSIZ,
                             M_DONTWAIT, MT_DATA, TRUE);
        if ( pMblk == NULL )
            return;

        p = buf=(uchar_t *)pMblk->m_data;

        /* send the config BPDU out the designated port    */
        bzero((char *)p, SPAN_BUFSIZ);

        /* 802.1d DESTINATION (Always 01:80:C2:00:00:00) */
        *p++ = 0x01;
        *p++ = 0x80;
        *p++ = 0xC2;
        *p++ = 0x00;
        *p++ = 0x00;
        *p++ = 0x00;

        /* Source address is filled in by the agEnd driver. */

        /* 802.3 SOURCE (My MAC) */
        bcopy(SpanDrvCtrl->muxInfo[port_no].mac, p, 6);

        p += 6;

        /* Add the VLAN QTag space if needed. */
        p += SpanDrvCtrl->muxInfo[port_no].qtag;

        /* 802.3 Length */
        *p++ = 0x00;
        *p++ = sizeof(Config_pkt_t) + 3;

        /* 802.3 LSAP Always 0x42 */
        *p++ = 0x42;
        *p++ = 0x42;

        /* 802.3 CTL */
        *p++ = 0x03;

        /* Here's the data; Protocol ID (Always 0) */
        *p++ = 0x00;
        *p++ = 0x00;

        /* Protocol Version (Always 0) */
        *p++ = 0x00;

        *p++ = bpdu->type;

        *p = (bpdu->topology_change_acknowledgment ? 0x80 : 0x00);
        *p++ |= bpdu->topology_change;

        bcopy((char *)&bpdu->root_id, (char *)p, sizeof(Identifier));
        p += sizeof(Identifier);
        slong(p, bpdu->root_path_cost);
        p += 4;
        bcopy((char *)&bpdu->bridge_id, (char *)p, sizeof(Identifier));
        p += sizeof(Identifier);
        sshort(p, bpdu->port_id);
        p += 2;
        value = bpdu->message_age << 8;
        sshort(p, value);
        p += 2;
        value = bpdu->max_age << 8;
        sshort(p, value);
        p += 2;
        value = bpdu->hello_time << 8;
        sshort(p, value);
        p += 2;
        value = bpdu->forward_delay << 8;
        sshort(p, value);
        p += 2;

        /* Adjust the the length to the real size. */
        pMblk->mBlkHdr.mLen     = p - (uchar_t *)pMblk->m_data;
        pMblk->mBlkPktHdr.len   = p - (uchar_t *)pMblk->m_data;
 	 pMblk->mBlkHdr.mFlags|= M_PKTHDR;
	
	buf[13]=pMblk->mBlkPktHdr.len-14;
        /*
         * Because this packet is being sent to a given agN device the
         * port number no longer needs to be in the upper 16 bits of the
         * pSpareData value (the last argument). We set this to zero
         * and allow the agEnd.c code to set the pSpareData value.
         */     
	if (muxSend(SpanDrvCtrl->muxInfo[port_no].pCookie, pMblk)==ERROR)
        {
            dbgPrintf (STP_AG_WARNING, 
                ("\nmuxTkSend failed for port_no %d %d!\n", 
                     (int)port_no, (int)errnoGet()));
        }
    }
}

/*******************************************************************************
* span_send_tcn_bpdu  - Send routine for TCN BPDU
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
void span_send_tcn_bpdu
    (
    int port_no,
    Tcn_bpdu * bpdu
    )
{
    /* send the TCN BPDU out the designated port    */
    M_BLK_ID    pMblk;
    uchar_t     * p;
    uchar_t     * buf;

    if ( (port_info[port_no].protocol_enabled == True) &&
         (get_stp_global_enable() == True) )
    {
        /*
         * Always allocate the MAX buffer size and adjust later. This works
         * because we only have one size in STP code.
         */
        pMblk = netTupleGet( SpanDrvCtrl->pNetPool, SPAN_BUFSIZ,
                             M_DONTWAIT, MT_DATA, TRUE);
        if ( pMblk == NULL )
            return;

        p = buf = (uchar_t *)pMblk->m_data;

        /* send the TCN BPDU out the designated port    */
        bzero((char *)p, SPAN_BUFSIZ);

        /* 802.1d DESTINATION (Always 01:80:C2:00:00:00) */
        *p++ = 0x01;
        *p++ = 0x80;
        *p++ = 0xC2;
        *p++ = 0x00;
        *p++ = 0x00;
        *p++ = 0x00;

        /* Source address is filled in by the agEnd driver. */
 
        /* 802.3 SOURCE (My MAC) */
        bcopy(SpanDrvCtrl->muxInfo[port_no].mac, p, 6);
 
        p += 6;

        /* Add the VLAN QTag space if needed. */
        p += SpanDrvCtrl->muxInfo[port_no].qtag;

        /* 802.3 Length */
        *p++ = 0x00;
        *p++ = sizeof(Tcn_pkt_t) + 3;

        /* 802.3 LSAP Always 0x42 */
        *p++ = 0x42;
        *p++ = 0x42;

        /* 802.3 CTL */
        *p++ = 0x03;

        /* Here's the data; Protocol ID (Always 0) */
        *p++ = 0x00;
        *p++ = 0x00;

        /* Protocol Version (Always 0) */
        *p++ = 0x00;

        /* BPDU Type (Always 128) */
        *p++ = bpdu->type;

        /* Adjust the the length to the real size. */
        pMblk->mBlkHdr.mLen     = p - buf;
        pMblk->mBlkPktHdr.len   = p - buf;
 	 pMblk->mBlkHdr.mFlags|= M_PKTHDR;
	buf[13]=pMblk->mBlkPktHdr.len-14;
        /*
         * Because this packet is being sent to a given agN device the
         * port number no longer needs to be in the upper 16 bits of the
         * pSpareData value (the last argument). We set this to zero
         * and allow the agEnd.c code to set the pSpareData value.
         */
	if (muxSend(SpanDrvCtrl->muxInfo[port_no].pCookie, pMblk) == ERROR)
        {
            dbgPrintf (STP_AG_WARNING, 
                ("\nmuxSend failed for port_no %d %d!\n", 
                     (int)port_no, (int)errnoGet()));
        }
    }
}

/*******************************************************************************
* span_receive_config  - receive a config BPDU and process.
*
* INPUTS:
*
* RETURNS:
*
* ERRORS:
*
* ERRNO:
*
* NOMANUAL <this will be removed later>
*/
LOCAL ulong_t span_receive_config
    (
    Config_pkt_t * cp,
    ulong_t port
    )
{

⌨️ 快捷键说明

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