日期:2014-05-16  浏览次数:20817 次

【在线急等】Linux网络内核相关的问题?

  我一直在做Android L2TP/IPsec 这块的代码,之前跟综上层没发现啥问题,后来我跟了下内核部分,
内核是:Linux2.6.35.3 的。

  每次都是到L2TP发送SCCRQ的部分就发不出去,然后我就跟内核,总是在查找安全路由的时候被分到一个黑洞路由,然后我就看了看代码,代码大概是下面这个样子的,每次net->xfrm.sysctl_larval_drop总是通过,然后就制做了一个黑洞路由。

C/C++ code

    if (route == NULL && num_xfrms > 0) {
        /* The only case when xfrm_bundle_lookup() returns a
         * bundle with null route, is when the template could
         * not be resolved. It means policies are there, but
         * bundle could not be created, since we don't yet
         * have the xfrm_state's. We need to wait for KM to
         * negotiate new SA's or bail out with error.*/
        if (net->xfrm.sysctl_larval_drop) {
            /* EREMOTE tells the caller to generate
             * a one-shot blackhole route. */
            dst_release(dst);
            xfrm_pols_put(pols, drop_pols);
            XFRM_INC_STATS(net, LINUX_MIB_XFRMOUTNOSTATES);

            return make_blackhole(net, family, dst_orig);
        }
         .....
         }




后来我又看了下初始化net->xfrm.sysctl_larval_drop的地方,是在xfrm_sysctl.c中的__xfrm_sysctl_init函数。代码是下面这个样子
C/C++ code

static void __net_init __xfrm_sysctl_init(struct net *net)
{
    net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
    net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
    net->xfrm.sysctl_larval_drop = 1;//改的这里
    net->xfrm.sysctl_acq_expires = 30;
}



后来我就把这个net->xfrm.sysctl_larval_drop这行改成了 等于0
C/C++ code

static void __net_init __xfrm_sysctl_init(struct net *net)
{
    net->xfrm.sysctl_aevent_etime = XFRM_AE_ETIME;
    net->xfrm.sysctl_aevent_rseqth = XFRM_AE_SEQT_SIZE;
    net->xfrm.sysctl_larval_drop = 0;//改的这里
    net->xfrm.sysctl_acq_expires = 30;
}



这时候重新编译了下内核,然后把生成的包烧进android的机子,这时ipsec确实正常通过了,可是在日志上却出现了下面这样的情况

12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544692] ------------[ cut here ]------------
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544739] WARNING: at /home/b617/git/bbdev/hardware/intel/linux-2.6/include/linux/skbuff.h:474 xfrm_output_resume+0x2fc/0x351()
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544765] Modules linked in: tiwlan_drv atomisp lm3554 mt9m114 mt9e013 videobuf_vmalloc videobuf_dma_contig videobuf_core bt_drv st_drv sdio [last unloaded: tiwlan_drv]
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544914] Pid: 3329, comm: mtpd Tainted: G W 2.6.35.3+ #11
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544932] Call Trace:
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.544977] [<c123175b>] warn_slowpath_common+0x4a/0xa6
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.545012] [<c160359a>] ? xfrm_output_resume+0x2fc/0x351
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.545050] [<c12317c6>] warn_slowpath_null+0xf/0x13
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.545086] [<c160359a>] xfrm_output_resume+0x2fc/0x351
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.545125] [<c160369d>] xfrm_output+0x9f/0xaa
12-06 13:21:46.606 W/Kernel-Dmesg( 0): <4>[ 4563.545162] [<c15fc5d9>] xfrm4_output_finish+0x39/0x3c
12-06 13:21:46.610 W/Kernel-Dmesg( 0): <4>[ 4563.545195] [<c15fc631>] xfrm4_output+0x55/0x5c
12-06 13:21:46.610 W/Kernel-Dmesg( 0): <4>[ 4563.545230] [<c15be6f7>] dst_outp