亚洲av成人无遮挡网站在线观看,少妇性bbb搡bbb爽爽爽,亚洲av日韩精品久久久久久,兔费看少妇性l交大片免费,无码少妇一区二区三区

Chinaunix

標(biāo)題: 請(qǐng)教netfilter抓混雜模式數(shù)據(jù)包 [打印本頁(yè)]

作者: zmhzcy    時(shí)間: 2013-08-14 18:59
標(biāo)題: 請(qǐng)教netfilter抓混雜模式數(shù)據(jù)包
目前在做用netfilter hook的方式抓包,想抓混雜模式下的數(shù)據(jù)包。查看內(nèi)核代碼在ip_input.c下面的ip_rcv函數(shù)里面
        if (skb->pkt_type == PACKET_OTHERHOST)
                goto drop;
注釋掉這兩句后,neitfilter可以抓到混雜模式下的數(shù)據(jù)包。但是在抓包時(shí)發(fā)現(xiàn)一個(gè)問(wèn)題,cpu的軟中斷占用資源很高,達(dá)到85%si.導(dǎo)致用戶態(tài)和內(nèi)核其他模塊執(zhí)行時(shí)速度很慢,查了下資源說(shuō)網(wǎng)卡要用napi的模式,不能用傳統(tǒng)的中斷模式,但具體怎么實(shí)現(xiàn)不是很清楚。各位大神有沒(méi)有碰到這種情況,有知道的給指點(diǎn)一下,兄弟在此感謝了!

作者: Godbach    時(shí)間: 2013-08-15 13:10
回復(fù) 1# zmhzcy
抓到之后,你做了什么處理

   
作者: 瀚海書香    時(shí)間: 2013-08-15 17:17
回復(fù) 1# zmhzcy
目前在做用netfilter hook的方式抓包,想抓混雜模式下的數(shù)據(jù)包。查看內(nèi)核代碼在ip_input.c下面的ip_rcv函數(shù)里面
        if (skb->pkt_type == PACKET_OTHERHOST)
                goto drop;
注釋掉這兩句后,neitfilter可以抓到混雜模式下的數(shù)據(jù)包。但是在抓包時(shí)發(fā)現(xiàn)一個(gè)問(wèn)題,cpu的軟中斷占用資源很高,達(dá)到85%si.導(dǎo)致用戶態(tài)和內(nèi)核其他模塊執(zhí)行時(shí)速度很慢,查了下資源說(shuō)網(wǎng)卡要用napi的模式,不能用傳統(tǒng)的中斷模式,但具體怎么實(shí)現(xiàn)不是很清楚。各位大神有沒(méi)有碰到這種情況,有知道的給指點(diǎn)一下,兄弟在此感謝了!



估計(jì)你的內(nèi)核(網(wǎng)卡驅(qū)動(dòng))可能已經(jīng)工作在napi模式了,問(wèn)題應(yīng)該出在你添加的處理邏輯上。建議說(shuō)一下你添加的代碼都做了什么工作
   
作者: zmhzcy    時(shí)間: 2013-08-18 13:54
回復(fù) 2# Godbach
抓到后我拿到想要的一些數(shù)據(jù),就把這個(gè)數(shù)據(jù)包在netfilter模塊中 return NF_DROP;

   
作者: zmhzcy    時(shí)間: 2013-08-18 14:47
回復(fù) 3# 瀚海書香

在ip_input.c文件的ip_rcv()函數(shù)中
int ip_rcv(struct sk_buff *skb, struct net_device *dev, struct packet_type *pt, struct net_device *orig_dev)
{
        struct iphdr *iph;
        u32 len;

        /* When the interface is in promisc. mode, drop all the crap
         * that it receives, do not try to analyse it.
         */
        //if (skb->pkt_type == PACKET_OTHERHOST)
        //        goto drop;


        IP_UPD_PO_STATS_BH(dev_net(dev), IPSTATS_MIB_IN, skb->len);

        if ((skb = skb_share_check(skb, GFP_ATOMIC)) == NULL) {
                IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
                goto out;
        }

        if (!pskb_may_pull(skb, sizeof(struct iphdr)))
                goto inhdr_error;

        iph = ip_hdr(skb);

        /*
         *        RFC1122: 3.2.1.2 MUST silently discard any IP frame that fails the checksum.
         *
         *        Is the datagram acceptable?
         *
         *        1.        Length at least the size of an ip header
         *        2.        Version of 4
         *        3.        Checksums correctly. [Speed optimisation for later, skip loopback checksums]
         *        4.        Doesn't have a bogus length
         */

        if (iph->ihl < 5 || iph->version != 4)
                goto inhdr_error;

        if (!pskb_may_pull(skb, iph->ihl*4))
                goto inhdr_error;

        iph = ip_hdr(skb);

        if (unlikely(ip_fast_csum((u8 *)iph, iph->ihl)))
                goto inhdr_error;

        len = ntohs(iph->tot_len);
        if (skb->len < len) {
                IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INTRUNCATEDPKTS);
                goto drop;
        } else if (len < (iph->ihl*4))
                goto inhdr_error;

        /* Our transport medium may have padded the buffer out. Now we know it
         * is IP we can trim to the true length of the frame.
         * Note this now means skb->len holds ntohs(iph->tot_len).
         */
        if (pskb_trim_rcsum(skb, len)) {
                IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INDISCARDS);
                goto drop;
        }

        /* Remove any debris in the socket control block */
        memset(IPCB(skb), 0, sizeof(struct inet_skb_parm));

        /* Must drop socket now because of tproxy. */
        skb_orphan(skb);

        return NF_HOOK(NFPROTO_IPV4, NF_INET_PRE_ROUTING, skb, dev, NULL,
                       ip_rcv_finish);

inhdr_error:
        IP_INC_STATS_BH(dev_net(dev), IPSTATS_MIB_INHDRERRORS);
drop:
        kfree_skb(skb);
out:
        return NET_RX_DROP;
}

注釋掉            //if (skb->pkt_type == PACKET_OTHERHOST)
        //        goto drop;
保證混雜模式的數(shù)據(jù)包可以進(jìn)入到netfilter的hook里面,在netfilter的hook里面,我拿到想要的數(shù)據(jù)包信息后,return NF_DROP,把數(shù)據(jù)給拋掉!邏輯很簡(jiǎn)單,內(nèi)核接收數(shù)據(jù)包把這些包扔到hook里面,在hook里面拋掉


作者: wsgtrsys    時(shí)間: 2013-08-18 19:21
你把全部包都收進(jìn)來(lái)處理,當(dāng)然占cpu了。
作者: zmhzcy    時(shí)間: 2013-08-19 12:14
回復(fù) 6# wsgtrsys
請(qǐng)問(wèn)有沒(méi)有其他方式抓混雜模式數(shù)據(jù)包,數(shù)據(jù)包量很大,40Gb/s

   
作者: wsgtrsys    時(shí)間: 2013-08-19 13:07
回復(fù) 7# zmhzcy


    用intel的dpdk試下




歡迎光臨 Chinaunix (http://www.72891.cn/) Powered by Discuz! X3.2