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??
Thanks and Regards
Juliet
Hey Juliet,
Well, let me start by just reminding you of a fact: An NIC is represented in the system by the net_device structure so that's the first clue.
What we want to do is to let the kernel notify us when a change happens over the net_device; then we'll check which net_device it is
and was the event.
Declare a variable of type notifier_block: /* Create a notifier variable and let its notifier_call function pointer point to our handler */
struct notifier_block my_notifier = {
.notifier_call = my_handler_function,
};
The handler function HAS to have the following signature: int my_handler_function(struct notifier_block *self, unsigned long notification, void *data);
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)
register_netdevice_notifier(&my_notifier);
When you're done with it (probably in the module_exit), do not forget to remove it: unregister_netdevice_notifier(&my_notifier);
Now what's left is how you'll know which event happened, because your handler is gonna get called when so many events happen:
here's a sample code for the my_notifier that checks if the IP changed and if it did, it logs this
int my_handler_function(struct notifier_block *self, unsigned long notification, void *data)
{
struct net_device *dev;
/* To see what kind of events you can check, refer to the netdevice.h file */