Пример #1
0
tcp_TrackInfo * find_tcp_TrackInfo_Reverse(tcp_Info_Manager *manager, struct sk_buff *skb)
{
    struct iphdr    *iph        = (struct iphdr*) ip_hdr(skb);
    struct tcphdr   *tcph       = (struct tcphdr *)((char *)iph+(iph->ihl*4));
    //struct tcphdr *tcph       = (struct tcphdr *)skb_transport_header(skb);
    unsigned long   flags       = 0;
    tcp_TrackInfo   *curNode    = NULL;
    tcp_TrackInfo   *result     = NULL;

    if (manager != NULL)
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        curNode = manager->head;
        while (curNode != NULL)
        {
            if ((curNode->srcIP == iph->daddr) &&
                (curNode->destIP == iph->saddr) &&
                (curNode->srcPort == tcph->dest) &&
                (curNode->destPort == tcph->source)	)
            {
                result = curNode;
                break;
            }
            curNode = curNode->next;
        }
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
    return result;
}
// sec filter read function
ssize_t	sec_url_filter_read( struct file *filp, char *buf, size_t count, loff_t *f_pos)
{
    int             result      = -EIO;
    tcp_TrackInfo   *notifyInfo = NULL;
    int             leftLen     = 0;
    int             writeCount  = count;
    int             notifyFlag  = 0;
    if (buf != NULL)
    {
        while (filterMode)
        {
            unsigned long   flags = 0;
            SEC_spin_lock_irqsave(&notifying_TrackInfo->tcp_info_lock, flags);
            notifyInfo = notifying_TrackInfo->head;
            SEC_spin_unlock_irqrestore(&notifying_TrackInfo->tcp_info_lock, flags);
            if (notifyInfo != NULL)
            {
                result  =   access_ok( VERIFY_WRITE, (void *)buf, count);	// This buffer should be verified because it is already blocked buffer.
                if (result != 0)
                {
                    leftLen = notifyInfo->urlLen - notifyInfo->notify_Index;    // Get left size
                    if ( leftLen <= count)              // If buffer is enough, it would be last block
                    {
                        writeCount  = leftLen;
                        notifyFlag  = 1;
                    }
                    result  = copy_to_user(buf, &(notifyInfo->url[notifyInfo->notify_Index]), writeCount);      // Check the result because it is blocked function
                    if (result == 0)
                    {
                        result  = writeCount;
                        notifyInfo->notify_Index += writeCount;
                        if (notifyFlag == 1)
                        {
                            notifyInfo->status = NOTIFIED;
                            notifyInfo = getFirst_tcp_TrackInfo(notifying_TrackInfo);
                            add_tcp_TrackInfo(notified_TrackInfo, notifyInfo);
                        }
                    }
                }
                break;      // Return result
            }
            else
            {
                interruptible_sleep_on(&user_noti_Q);
            }
        }
    }
    return (ssize_t)result;
}
Пример #3
0
tcp_TrackInfo * find_tcp_TrackInfo(tcp_Info_Manager *manager, struct sk_buff *skb, int option)
{
    struct  iphdr   *iph        = (struct iphdr*) ip_hdr(skb);
    struct  tcphdr  *tcph       = (struct tcphdr *)skb_transport_header(skb);
    unsigned long   flags       = 0;
    tcp_TrackInfo   *curNode    = NULL;
    tcp_TrackInfo   *preNode    = NULL;

    if (manager	!= NULL)
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        curNode = manager->head;
        while (curNode != NULL)
        {
            if ((curNode->srcIP == iph->saddr) &&
                (curNode->destIP == iph->daddr) &&
                (curNode->srcPort == tcph->source) &&
                (curNode->destPort == tcph->dest))
            {
                break;
            }
            preNode = curNode;
            curNode = curNode->next;
        }

        if ((option == 1) && (curNode != NULL))
        {
            if (preNode != NULL)                // Cur Node is Head
            {
                preNode->next = curNode->next;
            }
            if (manager->head == curNode)
            {
                manager->head = curNode->next;
            }
            if (manager->tail == curNode)
            {
                manager->tail = preNode;
            }
            curNode->next = NULL;
            manager->count--;
        }
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
    return curNode;
}
Пример #4
0
tcp_TrackInfo * add_tcp_TrackInfo_ToHead(tcp_Info_Manager *manager, tcp_TrackInfo *node)
{
    unsigned long   flags   = 0;
    if ((manager != NULL) &&(node != NULL))
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        node->next      = manager->head;
        manager->head   = node;
        manager->count++;
        if (manager->tail == NULL)
        {
            manager->tail = node;
        }
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
    return node;
}
Пример #5
0
tcp_TrackInfo * find_tcp_TrackInfo_withID(tcp_Info_Manager	*manager, int id)
{
    tcp_TrackInfo   *curNode    = NULL;
    tcp_TrackInfo   *preNode    = NULL;
    unsigned long   flags       = 0;

    if (manager	!= NULL)
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        curNode = manager->head;
        while (curNode != NULL)
        {
            if (curNode->id == id)
            {
                break;
            }
            preNode = curNode;
            curNode = curNode->next;
        }
        if (curNode != NULL)
        {
            if (preNode != NULL)			// Cur Node is Head
            {
                preNode->next = curNode->next;
            }
            if (manager->head == curNode)
            {
                manager->head = curNode->next;
            }
            if (manager->tail == curNode)
            {
                manager->tail = preNode;
            }
            curNode->next = NULL;
            manager->count--;
        }
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
    return curNode;
}
Пример #6
0
int add_tcp_TrackInfo( tcp_Info_Manager *manager, tcp_TrackInfo *node)
{
    unsigned long   flags   = 0;
    int             result  = 0;
    if ((manager != NULL) && (node != NULL))
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        if (manager->tail != NULL)
        {
            manager->tail->next = node;
        }
        else
        {
            manager->head   = node;
        }
        manager->tail = node;
        manager->count++;
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
        result  = 1;
    }
    return result;
}
Пример #7
0
tcp_TrackInfo * getFirst_tcp_TrackInfo(tcp_Info_Manager *manager)
{
    unsigned long   flags   = 0;
    tcp_TrackInfo   *result = NULL;
    if (manager != NULL)
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        if (manager->head != NULL)
        {
            result          = manager->head;
            manager->head   = manager->head->next;
            manager->count--;
            if (manager->head == NULL)
            {
                manager->tail= NULL;
            }
            result->next = NULL;
        }
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
    return result;
}
Пример #8
0
void    clean_tcp_TrackInfos(tcp_Info_Manager *manager)
{
    unsigned long   flags   = 0;
    tcp_TrackInfo   *node   = NULL;

    if (manager != NULL)
    {
        SEC_spin_lock_irqsave(&manager->tcp_info_lock, flags);
        while (manager->head != NULL)
        {
            node = manager->head;
            manager->head = manager->head->next;
            if (node->q_entry != NULL)
            {
                nf_reinject((struct nf_queue_entry *)node->q_entry, NF_DROP);
                node->q_entry = NULL;
            }
            free_tcp_TrackInfo(node);
        }
        manager->tail = NULL;
        manager->count  = 0;
        SEC_spin_unlock_irqrestore(&manager->tcp_info_lock, flags);
    }
}