<div dir="ltr">On Tue, Jul 23, 2013 at 7:21 AM, PV Juliet <span dir="ltr">&lt;<a href="mailto:pvjuliet@gmail.com" target="_blank">pvjuliet@gmail.com</a>&gt;</span> wrote:<br><div class="gmail_extra"><div class="gmail_quote">

<blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-color:rgb(204,204,204);border-left-style:solid;padding-left:1ex"><div dir="ltr"><div><div><div>Hi,  <br></div> Thanks for the reply . Can you tell me how i can subscribe to notifier chains when  IP address changes in a system ? What are all the steps to make it work??<br>

<br></div>Thanks and Regards<span class=""><font color="#888888"><br>
</font></span></div><span class=""><font color="#888888">Juliet</font></span></div></blockquote><div><br></div><div>Hey Juliet, <br><br>Well, let me start by just reminding you of a fact:<br>An NIC is represented in the system by the net_device structure so that&#39;s the first clue.</div>

<div>What we want to do is to let the kernel notify us when a change happens over the net_device; then we&#39;ll check which net_device it is</div><div>and was the event.</div><div><br></div><div>Declare a variable of type notifier_block:<br>

<b>/* Create a notifier variable and let its notifier_call function pointer point to our handler */</b></div><div><b>struct notifier_block my_notifier = <br>{</b></div><div><b>    .notifier_call = my_handler_function,</b></div>

<div><b>};</b></div><div><br></div><div>The handler function HAS to have the following signature:<br><b>int my_handler_function(struct notifier_block *self, unsigned long notification, void *data);</b></div><div><br></div>

<div>Next you want to register the notifier so that the kernel will call it when an event happens: (most likely, you should have this in the module_init code)</div><div><b>register_netdevice_notifier(&amp;my_notifier);</b></div>

<div>When you&#39;re done with it (probably in the module_exit), do not forget to remove it:<br><b>unregister_netdevice_notifier(&amp;my_notifier);</b></div><div><b><br></b></div><div>Now what&#39;s left is how you&#39;ll know which event happened, because your handler is gonna get called when so many events happen:</div>

<div>here&#39;s a sample code for the my_notifier that checks if the IP changed and if it did, it logs this </div><div><br></div><div><b>int my_handler_function(struct notifier_block *self, unsigned long notification, void *data)<br>

{</b></div><div><b>    struct net_device *dev;</b></div><div><b>    /* To see what kind of events you can check, refer to the netdevice.h file */</b></div><div><b>    if(notification != NETDEV_CHANGEADDR)<br>        return something;</b></div>

<div><b>     dev = data;</b></div><div><b>     printk(&quot;Device %s has changed its IP address\n&quot;, dev-&gt;name);<br>}</b></div><div><b><br></b></div><div>Let us know if you have any more questions,<br><br>Regards<br>

Adel<br><br>P.S It&#39;s generally considered a bad practice to top-post the reply.</div></div></div></div>