Exemplo n.º 1
0
static bool TcpCaCheck(int flow_id)
{
    unsigned long pkt_num;
    
    pkt_num = FlowPktNum(flow_id);
    if (pkt_num > limit_pkts || (pkt_num > 0 && FlowIsClose(flow_id) == TRUE)) {
        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 2
0
bool FlowGrpIsClose(int flow_id)
{
    bool ret;

    FlowTblLock();
    
    /* with or without group */
    if (flow_tbl[flow_id].grp_id != -1) {
        ret = GrpIsClose(flow_tbl[flow_id].grp_id);
    }
    else {
        ret = FlowIsClose(flow_id);
    }
    
    FlowTblUnlock();

    return ret;
}
Exemplo n.º 3
0
static bool TcpCaCheckGrp(int flow_id)
{
    unsigned long pkt_num;
    bool elab;
    tca_flow *niflw;
    
    pkt_num = FlowPktNum(flow_id);
    if (pkt_num > limit_pkts || (pkt_num > 0 && FlowIsClose(flow_id) == TRUE)) {
        niflw = xmalloc(sizeof(tca_flow));
        if (niflw == NULL) {
            return FALSE;
        }
        memset(niflw, 0, sizeof(tca_flow));
        niflw->nxt = NULL;
        niflw->pre = NULL;
        niflw->flow_id = flow_id;
        niflw->pkt_elb = 0;
        
        pthread_mutex_lock(&pthrs_mux);
        niflw->nxt = prl_thrs[pthrs_ins];
        prl_thrs[pthrs_ins] = niflw;
        if (prl_thrs_en[pthrs_ins] != 0) {
            elab = TRUE;
        }
        else {
            prl_thrs_en[pthrs_ins] = 1;
            elab = FALSE;
        }
        pthrs_ins++;
        if (pthrs_dim == pthrs_ins) {
            pthrs_ins = 0;
        }
        pthread_mutex_unlock(&pthrs_mux);
        
        if (elab) {
            FlowSetElab(flow_id, -1);
        }

        return TRUE;
    }

    return FALSE;
}
Exemplo n.º 4
0
static bool RtpCheck(int flow_id)
{
    const pstack_f *ip;
    packet *pkt;
    bool ret;
    ftval ips, ipx, port;
    bool ipv4, cmp;
    int pt_1, pt_2;
    unsigned int ssrc_1, ssrc_2;
    int cnt, ecnt;
    rtp_hdr *rtp;
    unsigned short min_size;

    if (FlowPktNum(flow_id) < RTP_PKT_LIMIT && FlowIsClose(flow_id) == FALSE) {
        return FALSE;
    }

    ipv4 = FALSE;
    ret = FALSE;
    cnt = ecnt = 0;

    pkt = FlowGetPktCp(flow_id);
    if (pkt != NULL) {
        /* check port */
        ProtGetAttr(pkt->stk, uport_dst_id, &port);
        if (port.uint16 < 1024) {
            PktFree(pkt);
            return FALSE;
        }
        ProtGetAttr(pkt->stk, uport_src_id, &port);
        if (port.uint16 < 1024) {
            PktFree(pkt);
            return FALSE;
        }
        /* check ip */
        ip = ProtGetNxtFrame(pkt->stk);
        if (ProtFrameProtocol(ip) == ip_id)
            ipv4 = TRUE;
        if (ipv4 == TRUE)
            ProtGetAttr(ip, ip_src_id, &ips);
        else
            ProtGetAttr(ip, ipv6_src_id, &ips);
        while (pkt->len == 0) {
            PktFree(pkt);
            pkt = FlowGetPktCp(flow_id);
            if (pkt == NULL)
                break;
        }
    }
    if (pkt != NULL) {
        pt_1 = pt_2 = -1;
        do {
            if (pkt->len > sizeof(rtp_hdr)) {
                rtp = (rtp_hdr *)pkt->data;
                if (rtp->version != 2) {
                    cnt = 0;
                    ecnt++;
                }
                else {
                    ip = ProtGetNxtFrame(pkt->stk);
                    if (ipv4 == TRUE) {
                        ProtGetAttr(ip, ip_src_id, &ipx);
                        cmp = FTCmp(&ips, &ipx, FT_IPv4, FT_OP_EQ, NULL);
                        if (cmp) {
                            if (pt_1 == -1) {
                                pt_1 = rtp->pt;
                                ssrc_1 = rtp->ssrc;
                            }
                            else if (pt_1 != rtp->pt || ssrc_1 != rtp->ssrc)
                                break;
                        }
                        else {
                            if (pt_2 == -1) {
                                pt_2 = rtp->pt;
                                ssrc_2 = rtp->ssrc;
                            }
                            else if (pt_2 != rtp->pt || ssrc_2 != rtp->ssrc)
                                break;
                        }
                        /* check size */
                        if (rtp->cc != 0) {
                            min_size = rtp->cc * 4; /* every CSRC has 4 byte */
                            min_size += sizeof(rtp_hdr);
                            if (pkt->len < min_size)
                                break;
                        }
                    }
                    else {
                        ProtGetAttr(ip, ipv6_src_id, &ipx);
                        cmp = FTCmp(&ips, &ipx, FT_IPv6, FT_OP_EQ, NULL);
                        if (cmp) {
                            if (pt_1 == -1) {
                                pt_1 = rtp->pt;
                            ssrc_1 = rtp->ssrc;
                            }
                            else if (pt_1 != rtp->pt || ssrc_1 != rtp->ssrc)
                                break;
                        }
                        else {
                            if (pt_2 == -1) {
                                pt_2 = rtp->pt;
                                ssrc_2 = rtp->ssrc;
                            }
                            else if (pt_2 != rtp->pt || ssrc_2 != rtp->ssrc)
                                break;
                        }
                        /* check size */
                        if (rtp->cc != 0) {
                            min_size = rtp->cc * 4; /* every CSRC has 4 byte */
                            min_size += sizeof(rtp_hdr);
                            if (pkt->len < min_size)
                                break;
                        }
                    }
                    cnt++;
                }
            }
            else {
                cnt = 0;
                ecnt++;
            }
            PktFree(pkt);
            pkt = FlowGetPktCp(flow_id);
        } while (ecnt != RTP_PKT_ERR_CHECK && cnt != RTP_PKT_CHECK && pkt != NULL);
    }
    
    if (pkt != NULL) {
        PktFree(pkt);
        pkt = NULL;
    }
    
    if (cnt == RTP_PKT_CHECK) {
        ret = TRUE;
    }

    return ret;
}