I used the following code with the output, I don't understand why this doesn't work.
char *tmp = NULL;
int optlen = iph->ihl*4 - sizeof(struct iphdr);
if (optlen > 0)
{
printk("ihl=%d\n", iph->ihl);
printk("optlen=%d\n", optlen);
tmp = kzalloc(sizeof(struct iphdr), GFP_ATOMIC);
memcpy(tmp, iph, sizeof(struct iphdr));
memcpy(iph + optlen, tmp, sizeof(struct iphdr));
kfree(tmp);
skb_pull(skb, optlen);
skb_reset_network_header(skb);
iph = ip_hdr(skb);
printk("new ihl=%d\n", iph->ihl);
iph->ihl -= optlen>>2;
printk("newest ihl=%d\n", iph->ihl);
}
The output is:
[ 401.754279] ihl=8
[ 401.754288] optlen=12
[ 401.754293] new ihl=15
[ 401.754296] newest ihl=12