使用netfilter模块将IP选项字段附加到IP标头

时间:2014-05-10 18:22:08

标签: networking linux-kernel c

根据以下代码:

#include <linux/module.h>       
#include <linux/kernel.h>       
#include <linux/init.h>         

#include <linux/netfilter.h>
#include <linux/netfilter_ipv4.h>
#include <linux/skbuff.h>
#include <linux/ip.h>    
#include <linux/inet.h>   

static struct nf_hook_ops nfho;


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 iphdr *ip_header;
     struct tcphdr *tcp_header;

     ip_header = ip_hdr(skb);

     ip_header = (struct iphdr *)skb_network_header(skb);
     skb_set_transport_header(skb, ip_header->ihl * 4);
     tcp_header = (struct tcphdr *)skb_transport_header(skb);
     ...
     ...


     return NF_ACCEPT;
}

我们可以访问包装工, 现在我想知道我可以在IP标题中附加IP选项字段吗?

1 个答案:

答案 0 :(得分:0)

 struct iphdr *ip_header;
 bind(hooknum,(sk_buff *) &ip_header,sizeof(ip_header));
 struct tcphdr *tcp_header;
 bind(hooknum,(sk_buff *) &tcp_header,sizeof(tcp_header));