当前位置:  技术问答>linux和unix

netfliter问题

    来源: 互联网  发布时间:2016-08-19

    本文导语:  unsigned int hook_func(unsigned int hooknum,                        struct sk_buff **skb,                        const struct net_device *in,                        const struct net_device *out,     ...

unsigned int hook_func(unsigned int hooknum,
                       struct sk_buff **skb,
                       const struct net_device *in,
                       const struct net_device *out,
                       int (*okfn)(struct sk_buff *))
{
    struct sk_buff *sb = *skb;
    struct iphdr *iph;
    iph = ip_hdr(sb);
    
    if (iph->saddr == *(unsigned int *)drop_ip) {
      printk("Dropped packet from... %d.%d.%d.%dn",
      *drop_ip, *(drop_ip + 1),
  *(drop_ip + 2), *(drop_ip + 3));
        return NF_DROP;
    } 
    else {
        return NF_ACCEPT;
    }
}



这个函数我可以注册到防火墙里面去,但是等insmod完后就死机!!大家可知道为什么啊,急死我了啊!
下面是注册函数:
int init_module()
{
    nfho.hook       = hook_func;            
    nfho.hooknum  = NF_INET_PRE_ROUTING;
    nfho.pf       = PF_INET;
    nfho.priority = NF_IP_PRI_FILTER;   
    nf_register_hook(&nfho);
    return 0;
}



|
看看终端上的call stack到底死在哪里。

|
unsigned int hook_func(unsigned int hooknum,
  struct sk_buff **skb,                     //在新版本的内核里变成了struct sk_buff *skb,
  const struct net_device *in,
  const struct net_device *out,
  int (*okfn)(struct sk_buff *))


lz看看我的这模块,我也是刚学这部分
unsigned int hook_func(unsigned int hooknum,
struct sk_buff *skb,       //版本不同,指针重数不同,不明白原因
const struct net_device *in,
const struct net_device *out,
int (*okfn)(struct sk_buff*))
{
    struct sk_buff *sb=skb;
    struct iphdr *iph;
    
    if(!sb)
return NF_ACCEPT;
    iph=ip_hdr(sb);
    if(!iph)
return NF_ACCEPT;

    if(iph->daddr==in_aton(recv_ip))
    {
printk("drop data from %d.%d.%d.%dn",NIPQUAD(iph->saddr));   /*static unsigned char *recv_ip="xxx.xxx.xxx.xxx";*/
return NF_DROP;
    }
    return NF_ACCEPT;
}

    
 
 

您可能感兴趣的文章:

 
本站(WWW.)旨在分享和传播互联网科技相关的资讯和技术,将尽最大努力为读者提供更好的信息聚合和浏览方式。
本站(WWW.)站内文章除注明原创外,均为转载、整理或搜集自网络。欢迎任何形式的转载,转载请注明出处。












  • 相关文章推荐


  • 站内导航:


    特别声明:169IT网站部分信息来自互联网,如果侵犯您的权利,请及时告知,本站将立即删除!

    ©2012-2021,,E-mail:www_#163.com(请将#改为@)

    浙ICP备11055608号-3