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

📄 net_icmp.c

📁 ucos的tcpip协议占
💻 C
📖 第 1 页 / 共 5 页
字号:
    NetICMP_ErrInvalidTypeCtr          =  0;


    NetICMP_ErrRxInvalidBufIxCtr       =  0;

    NetICMP_ErrRxHdrDataLenCtr         =  0;


    NetICMP_ErrTxInvalidBufIxCtr       =  0;

    NetICMP_ErrTxHdrPtrCtr             =  0;
#endif


#if (NET_ICMP_CFG_TX_SRC_QUENCH_EN     == DEF_ENABLED)
    NetICMP_ErrNoneAvailCtr            =  0;
#endif
#endif
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                     NetICMP_CfgTxSrcQuenchTh()
*
* Description : Configure ICMP transmit source quench entry's access-transmit threshold.
*
* Argument(s) : th          Desired number of received IP packets from a specific IP source host that trips
*                               the transmission of an additional ICMP Source Quench Error Message.
*
* Return(s)   : DEF_OK, ICMP transmit source quench threshold configured.
*
* Caller(s)   : Net_InitDflt(),
*               Application.
*
*               This function is a network protocol suite application interface (API) function & MAY be 
*               called by application function(s).
*
* Note(s)     : none.
*********************************************************************************************************
*/

#if (NET_ICMP_CFG_TX_SRC_QUENCH_EN == DEF_ENABLED)
CPU_BOOLEAN  NetICMP_CfgTxSrcQuenchTh (CPU_INT16U  th)
{
#if (CPU_CFG_CRITICAL_METHOD == CPU_CRITICAL_METHOD_STATUS_LOCAL)
    CPU_SR  cpu_sr;
#endif


#if (NET_ICMP_TX_SRC_QUENCH_TH_MIN > DEF_INT_16U_MIN_VAL)
    if (th < NET_ICMP_TX_SRC_QUENCH_TH_MIN) {
        th = NET_ICMP_TX_SRC_QUENCH_TH_MIN;
    }
#endif
#if (NET_ICMP_TX_SRC_QUENCH_TH_MAX < DEF_INT_16U_MAX_VAL)
    if (th > NET_ICMP_TX_SRC_QUENCH_TH_MAX) {
        th = NET_ICMP_TX_SRC_QUENCH_TH_MAX;
    }
#endif

    CPU_CRITICAL_ENTER();
    NetICMP_TxSrcQuenchTxTh_nbr = th;
    CPU_CRITICAL_EXIT();

    return (DEF_OK);
}
#endif


/*$PAGE*/
/*
*********************************************************************************************************
*                                            NetICMP_Rx()
*
* Description : (1) Process received messages :
*
*                   (a) Validate ICMP packet
*                   (b) Demultiplex ICMP message
*                   (c) Free ICMP packet
*                   (d) Update receive statistics
*
*               (2) Although ICMP data units are typically referred to as 'messages' (see RFC #792, Section
*                   'Introduction'), the term 'ICMP packet' (see RFC #1983, 'packet') is used for ICMP 
*                   Receive until the packet is validated as an ICMP message.
*
*
* Argument(s) : pbuf        Pointer to network buffer that received ICMP packet.
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ICMP_ERR_NONE               ICMP message successfully received & processed.
*                               NET_ERR_INIT_INCOMPLETE         Network initialization NOT complete.
*
*                                                               ---- RETURNED BY NetICMP_RxPktDiscard() : -----
*                               NET_ERR_RX                      Receive error; packet discarded.
*
* Return(s)   : none.
*
* Caller(s)   : NetIP_RxPktDemuxDatagram().
*
*               This function is an INTERNAL network protocol suite function & MUST NOT be called by 
*               application function(s).
*
* Note(s)     : (3) NetICMP_Rx() blocked until network initialization completes; perform NO action.
*
*               (4) #### ICMP Receive Error/Reply Messages NOT yet implemented :
*
*                   (a) Define "User Process" to report ICMP Error Messages to Transport &/or Application Layers.
*
*                   (b) Define procedure to demultiplex & enqueue ICMP Reply Messages to Application.
*
*                       (1) MUST implement mechanism to de-queue ICMP message data from single, complete
*                           datagram packet buffers or multiple, fragmented packet buffers.
*********************************************************************************************************
*/
/*$PAGE*/
void  NetICMP_Rx (NET_BUF  *pbuf,
                  NET_ERR  *perr)
{
#if ((((NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)                    && \
       (NET_CTR_CFG_ERR_EN         == DEF_ENABLED))                   || \
       (NET_CTR_CFG_STAT_EN        == DEF_ENABLED))                   && \
       (CPU_CFG_CRITICAL_METHOD    == CPU_CRITICAL_METHOD_STATUS_LOCAL))
    CPU_SR         cpu_sr;
#endif
#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
    NET_CTR       *pctr;
#endif
    NET_BUF_HDR   *pbuf_hdr;
    NET_ICMP_HDR  *picmp_hdr;


#if (NET_ERR_CFG_ARG_CHK_EXT_EN == DEF_ENABLED)
    if (Net_InitDone != DEF_YES) {                              /* If init NOT complete, exit rx (see Note #3).         */
        NetICMP_RxPktDiscard(pbuf, perr);
       *perr = NET_ERR_INIT_INCOMPLETE;
        return;
    }
#endif


#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
                                                                /* ------------------- VALIDATE PTR ------------------- */
    if (pbuf == (NET_BUF *)0) {
        NetICMP_RxPktDiscard(pbuf, perr);
        NET_CTR_ERR_INC(NetICMP_ErrNullPtrCtr);
        return;
    }
#endif


    NET_CTR_STAT_INC(NetICMP_StatRxMsgCtr);


                                                                /* ----------------- VALIDATE ICMP PKT ---------------- */
    pbuf_hdr = &pbuf->Hdr;
#if (NET_ERR_CFG_ARG_CHK_DBG_EN == DEF_ENABLED)
    NetICMP_RxPktValidateBuf(pbuf_hdr, perr);                   /* Validate rx'd buf.                                   */
    switch (*perr) {
        case NET_ICMP_ERR_NONE:                                 
             break;


        case NET_ERR_INVALID_PROTOCOL:
        case NET_BUF_ERR_INVALID_IX:
        default:
             NetICMP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
#endif
    picmp_hdr = (NET_ICMP_HDR *)&pbuf->Data[pbuf_hdr->ICMP_MsgIx];
    NetICMP_RxPktValidate(pbuf, pbuf_hdr, picmp_hdr, perr);     /* Validate rx'd pkt.                                   */


/*$PAGE*/
                                                                /* ------------------ DEMUX ICMP MSG ------------------ */
    switch (*perr) {
        case NET_ICMP_ERR_MSG_TYPE_ERR:
                                                                /* See Note #4a.                                        */

#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
             pctr = &NetICMP_StatRxMsgErrProcessedCtr;
#endif
             break;


        case NET_ICMP_ERR_MSG_TYPE_REQ:
             NetICMP_TxMsgReply(pbuf, pbuf_hdr, picmp_hdr, perr);

#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
             pctr = &NetICMP_StatRxMsgReqProcessedCtr;
#endif
             break;


        case NET_ICMP_ERR_MSG_TYPE_REPLY:
                                                                /* See Note #4b.                                        */

#if (NET_CTR_CFG_STAT_EN == DEF_ENABLED)
             pctr = &NetICMP_StatRxMsgReplyProcessedCtr;
#endif
             break;


        case NET_ICMP_ERR_INVALID_TYPE:
        case NET_ICMP_ERR_INVALID_CODE:
        case NET_ICMP_ERR_INVALID_PTR:
        case NET_ICMP_ERR_INVALID_LEN:
        case NET_ICMP_ERR_INVALID_LEN_DATA:
        case NET_ICMP_ERR_INVALID_CHK_SUM:
        default:
             NetICMP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }


                                                                /* --------- FREE ICMP PKT / UPDATE RX STATS ---------- */
    switch (*perr) {                                            /* Chk err from NetICMP_TxMsg???().                     */
        case NET_ICMP_ERR_NONE:
             NetICMP_RxPktFree(pbuf);
             NET_CTR_STAT_INC(NetICMP_StatRxMsgProcessedCtr);
             NET_CTR_STAT_INC(*pctr);
             break;


        default:
             NetICMP_RxPktDiscard(pbuf, perr);
             return;                                            /* Prevent 'break NOT reachable' compiler warning.      */
    }
}


/*$PAGE*/
/*
*********************************************************************************************************
*                                         NetICMP_TxMsgErr()
*
* Description : (1) Transmit ICMP Error Message in response to received packet with one or more errors :
*
*                   (a) Validate ICMP Error Message
*
*                   (b) Get buffer for ICMP Error Message :
*
*                       (1) Calculate  ICMP Error Message buffer size
*                       (2) Copy received packet's IP header & data into ICMP Error Message
*                       (3) Initialize ICMP Error Message buffer controls
*
*                   (c) Prepare ICMP Error Message :
*
*                       (1) Type                                    See Note #1cA
*                       (2) Code                                    See Note #1cA
*                       (3) Pointer
*                       (4) Unused
*                       (5) Check-Sum
*
*                           (A) See 'net_icmp.h  ICMP MESSAGE TYPES & CODES  Notes #2 & #3' for supported
*                               ICMP message types & codes.
*
*                   (d) Transmit ICMP Error Message
*
*                       (1) RFC #1122, Section 3.2.2 specifies that "an ICMP error message SHOULD be sent
*                           with normal (i.e., zero) TOS bits".  RFC #1349, Section 5.1 confirms that "an
*                           ICMP error message is always sent with the default TOS (0000)".
*
*                   (e) Free ICMP Error Message buffer
*
*                   (f) Update transmit statistics
*
*
* Argument(s) : pbuf        Pointer to network buffer that received a packet with error(s).
*
*               type        ICMP Error Message type (see Note #1cA) :
*
*                               NET_ICMP_MSG_TYPE_DEST_UNREACH
*                               NET_ICMP_MSG_TYPE_SRC_QUENCH
*                               NET_ICMP_MSG_TYPE_TIME_EXCEED
*                               NET_ICMP_MSG_TYPE_PARAM_PROB
*
*               code        ICMP Error Message code (see Note #1cA).
*
*               ptr         Pointer to received packet's ICMP error (optional).
*
*               perr        Pointer to variable that will receive the return error code from this function :
*
*                               NET_ICMP_ERR_NONE               ICMP Error Message successfully transmitted.
*                               NET_ERR_INIT_INCOMPLETE         Network initialization NOT complete.
*

⌨️ 快捷键说明

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