I used the following code with the output, I don't understand why this doesn't work.
struct iphdr *iph = ip_hdr(skb);
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
On Tue, Jan 28, 2014 at 8:54 PM, Guibin(Bill) Tian <gbtian@xxxxxxxxx> wrote:
Hi,In the kernel, I added some customized options to the ip_options struct, and I send the ip packet with these option fields set.After I receive the packet, I extract these options and try to remove them from the ip packet because I don't want these options be delivered to upper layer.In the method ip_rcv_finish of the file ip_input.c, I added following code:/*********My code to process the options****/process_my_options(skb);/*********My code to remove the options ****///skb_pull(skb, sizeof(struct iphdr) + 12);
//skb_push(skb, sizeof(struct iphdr));//skb_reset_network_header(skb);//iph->ihl -= 3;/*********Normal process of the ip packet.****/if (iph->ihl > 5 && ip_rcv_options(skb))goto drop;The question is at how to remove the options. I tried some code but none of them works correctly. Can anybody give me some suggestion? Thanks.
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@xxxxxxxxxxxxxxxxx http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies