modify ip option field by netfilter loadable kernel module
Hi
I want to modify IP option field by netfilter loadable kernel module.
I extract the IP header by the the bellow code :
struct iphdr * ip_header = (struct iphdr *)skb_network_header(skb);
and i want to modify IP option field, for example applying "AND" operator to a specific byte of IP option field, then i think after modifying i have to run bellow command to correct checksum too:
ip_header->check = 0;
ip_send_check(ip_header);
How can i perform Modifying;
The complete code is as bellow:
static 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);
ip_header->check = 0; // after modifying IP option field
ip_send_check(ip_header);
return NF_ACCEPT;
}
|