Example #1
0
static int
tc_nl_event_process(tc_event_t *rev)
{
    int             i, pass_through_flag = 0;
    char            buffer[65535];
    unsigned long   packet_id;
    tc_ip_header_t *ip_hdr;

    packet_id = 0;

    if (tc_nl_socket_recv(rev->fd, buffer, 65535) == TC_ERROR) {
        return TC_ERROR;
    }

    ip_hdr = tc_nl_ip_header(buffer);
    packet_id = tc_nl_packet_id(buffer);

    if (ip_hdr != NULL) {
        /* check if it is the valid user to pass through firewall */
        for (i = 0; i < srv_settings.passed_ips.num; i++) {
            if (srv_settings.passed_ips.ips[i] == ip_hdr->daddr) {
                pass_through_flag = 1;
                break;
            }
        }

        tot_resp_packs++;

        if (pass_through_flag) {

#if (INTERCEPT_THREAD)
            put_nl_verdict_to_pool(rev->fd, NF_ACCEPT, packet_id);
#else
            /* pass through the firewall */
            dispose_netlink_packet(rev->fd, NF_ACCEPT, packet_id);
#endif
        } else {

            tot_copy_resp_packs++;
#if (INTERCEPT_THREAD)
            /* put response packet header to pool */
            put_resp_header_to_pool(ip_hdr);
            /* drop the packet */
            put_nl_verdict_to_pool(rev->fd, NF_DROP, packet_id);
#else
            router_update(srv_settings.router_fd, ip_hdr);

            tc_check_cleaning();

            /* drop the packet */
            dispose_netlink_packet(rev->fd, NF_DROP, packet_id);
#endif
        }
    }

    return TC_OK;
}
Example #2
0
static int
tc_nl_event_process(tc_event_t *rev)
{
    int             i, pass_through_flag = 0;
    char            buffer[65536];
    unsigned long   packet_id;
    tc_ip_header_t *ip_hdr;

    if (tc_nl_socket_recv(rev->fd, buffer, 65536) == TC_ERROR) 
    {
        return TC_ERROR;
    }

    ip_hdr = tc_nl_ip_header(buffer);
    packet_id = tc_nl_packet_id(buffer);

    if (ip_hdr != NULL) {
        /* check if it is the valid user to pass through firewall */
        for (i = 0; i < srv_settings.passed_ips.num; i++) {
            if (srv_settings.passed_ips.ips[i] == ip_hdr->daddr) {
                pass_through_flag = 1;
                break;
            }
        }

        tot_resp_packs++;

        if (pass_through_flag) {

            /* pass through the firewall */
            dispose_netlink_packet(rev->fd, NF_ACCEPT, packet_id);
            
        } else {

            tot_copy_resp_packs++;
            router_update(srv_settings.old, srv_settings.router_fd, ip_hdr);
            /* drop the packet */
            dispose_netlink_packet(rev->fd, NF_DROP, packet_id);
        }
    }

    return TC_OK;
}