Example #1
0
void gen_ip_frag_proc(int it, TPTD_Token * token)
{
	//fprintf(stderr, "gen_ip_frag_proc\n");
	struct proc_node *i;
	u_char *data = token->data;
	//fprintf(stderr, "f**k f**k  id %d\n", it);
    struct ip *iph = (struct ip *) data;
    int need_free = 0;
    int skblen;
    void (*glibc_syslog_h_workaround)(int, int, struct ip *, void*)=
       nids_params.syslog;

	ip_fast_csum((unsigned char *) iph, iph->ip_hl);

    if (token->caplen < (int)sizeof(struct ip) || iph->ip_hl < 5 || iph->ip_v != 4 ||
	(u_short)ip_fast_csum((unsigned char *) iph, iph->ip_hl) != 0 ||
	token->caplen < ntohs(iph->ip_len) || ntohs(iph->ip_len) < iph->ip_hl << 2) {
	glibc_syslog_h_workaround(NIDS_WARN_IP, NIDS_WARN_IP_HDR, iph, 0);
		token->token_state = TOKEN_STATE_END;
   // fprintf(stderr, "break on ipfragment 1\n");
		return;
    }
   if (iph->ip_hl > 5 && ip_options_compile((unsigned char *)data)) {
	glibc_syslog_h_workaround(NIDS_WARN_IP, NIDS_WARN_IP_SRR, iph, 0);
	token->token_state = TOKEN_STATE_END;
//fprintf(stderr, "break on ipfragment 2\n");
	return;
   }

    switch (ip_defrag_stub((struct ip *) data, &iph)) {
    	case IPF_ISF:
			//fprintf(stderr, "IPF_ISF\n");
			token->token_state = TOKEN_STATE_ALIVE;
            //fprintf(stderr, "break on ipfragment 2\n");
			return;
    	case IPF_NOTF:
			need_free = 0;
			iph = (struct ip *) data;
			break;
    	case IPF_NEW:
			need_free = 1;
			break;
    	default:;
    }
    skblen = ntohs(iph->ip_len) + 16;
    if (!need_free)
		skblen += nids_params.dev_addon;
    skblen = (skblen + 15) & ~15;
    skblen += nids_params.sk_buff_size;


    if (need_free)
		free(iph);
	token->token_state = TOKEN_STATE_GOON;
	return;
}
Example #2
0
static void gen_ip_frag_proc(u_char * data, int len)
{
    struct proc_node *i;
    struct ip *iph = (struct ip *) data;
    int need_free = 0;
    int skblen;
    void (*glibc_syslog_h_workaround)(int, int, struct ip *, void*)=
        nids_params.syslog;

    if (!nids_params.ip_filter(iph, len))
        return;

#if 0
    if (len < (int)sizeof(struct ip) || iph->ip_hl < 5 || iph->ip_v != 4 ||
            ip_fast_csum((unsigned char *) iph, iph->ip_hl) != 0 ||
            len < ntohs(iph->ip_len) || ntohs(iph->ip_len) < iph->ip_hl << 2) {
        glibc_syslog_h_workaround(NIDS_WARN_IP, NIDS_WARN_IP_HDR, iph, 0);
        return;
    }
#endif
    if (iph->ip_hl > 5 && ip_options_compile((unsigned char *)data)) {
        glibc_syslog_h_workaround(NIDS_WARN_IP, NIDS_WARN_IP_SRR, iph, 0);
        return;
    }
    switch (ip_defrag_stub((struct ip *) data, &iph)) {
    case IPF_ISF:
        return;
    case IPF_NOTF:
        need_free = 0;
        iph = (struct ip *) data;
        break;
    case IPF_NEW:
        need_free = 1;
        break;
    default:
        ;
    }
    skblen = ntohs(iph->ip_len) + 16;
    if (!need_free)
        skblen += nids_params.dev_addon;
    skblen = (skblen + 15) & ~15;
    skblen += nids_params.sk_buff_size;

    for (i = ip_procs; i; i = i->next)
        (i->item) (iph, skblen);
    if (need_free)
        free(iph);
}