<div dir="ltr">I used the following code with the output, I don&#39;t understand why this doesn&#39;t work.<div><br></div><div>                struct iphdr *iph = ip_hdr(skb);<br></div><div><div>                char *tmp = NULL;</div>
<div>                int optlen = iph-&gt;ihl*4 - sizeof(struct iphdr);</div><div><span class="" style="white-space:pre">                </span>if (optlen &gt; 0)</div><div><span class="" style="white-space:pre">                </span>{</div><div><span class="" style="white-space:pre">                        </span>printk(&quot;ihl=%d\n&quot;, iph-&gt;ihl);</div>
<div><span class="" style="white-space:pre">                        </span>printk(&quot;optlen=%d\n&quot;, optlen);</div><div><span class="" style="white-space:pre">                        </span>tmp = kzalloc(sizeof(struct iphdr), GFP_ATOMIC);</div><div><span class="" style="white-space:pre">                        </span>memcpy(tmp, iph, sizeof(struct iphdr));</div>
<div><span class="" style="white-space:pre">                        </span>memcpy(iph + optlen, tmp, sizeof(struct iphdr));</div><div><span class="" style="white-space:pre">                        </span>kfree(tmp);</div><div><div><span class="" style="white-space:pre">                        skb_pull(skb, optlen);</span></div>
<div><span class="" style="white-space:pre">                        </span>skb_reset_network_header(skb);</div><div><br></div><div><span class="" style="white-space:pre">                        </span>iph = ip_hdr(skb);</div><div><span class="" style="white-space:pre">                        </span>printk(&quot;new ihl=%d\n&quot;, iph-&gt;ihl);</div>
<div><span class="" style="white-space:pre">                        </span>iph-&gt;ihl -= optlen&gt;&gt;2;</div><div><span class="" style="white-space:pre">                         </span>printk(&quot;newest ihl=%d\n&quot;, iph-&gt;ihl);</div></div>
<div><span class="" style="white-space:pre">                </span>}<br></div><div><br></div><div>The output is:<br></div><div><br></div><div><div>[  401.754279] ihl=8</div><div>[  401.754288] optlen=12</div><div>[  401.754293] new ihl=15</div>
<div>[  401.754296] newest ihl=12</div></div><div><br></div><div><br></div></div></div><div class="gmail_extra"><br><br><div class="gmail_quote">On Tue, Jan 28, 2014 at 8:54 PM, Guibin(Bill) Tian <span dir="ltr">&lt;<a href="mailto:gbtian@gmail.com" target="_blank">gbtian@gmail.com</a>&gt;</span> wrote:<br>
<blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Hi, <div>In the kernel, I added some customized options to the ip_options struct, and I send the ip packet with these option fields set. </div>
<div><br></div><div>After I receive the packet, I extract these options and try to remove them from the ip packet because I don&#39;t want these options be delivered to upper layer. </div>
<div><br></div><div>In the method ip_rcv_finish of the file ip_input.c, I added following code: </div><div><br></div><div><div><span style="white-space:pre-wrap">/*********My code to process the options****/</span></div>

<div><span style="white-space:pre-wrap">        process_my_options(skb);</span></div><div><span style="white-space:pre-wrap">/*********My code to remove the options ****/<br></span></div><div><span style="white-space:pre-wrap">        </span>//skb_pull(skb, sizeof(struct iphdr) + 12);<br>

</div><div><span style="white-space:pre-wrap">        </span>//skb_push(skb, sizeof(struct iphdr));</div><div><span style="white-space:pre-wrap">        </span>//skb_reset_network_header(skb);</div><div><span style="white-space:pre-wrap">        //</span>iph-&gt;ihl -= 3;</div>

<div><br></div><div><span style="white-space:pre-wrap">/*********Normal process of the ip packet.****/</span><br></div><div><span style="white-space:pre-wrap">        </span>if (iph-&gt;ihl &gt; 5 &amp;&amp; ip_rcv_options(skb))</div>

<div><span style="white-space:pre-wrap">                </span>goto drop;</div></div><div><br></div><div><br></div><div>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.</div>

</div>
</blockquote></div><br></div>