Hi , I am new to kernel and i would like to know where i can get sample programs to use notifier chains .How to subscribe the notifier chains to some application so that i will get notified. Is there any way make this as service in linux system?? Thanks and Regards Juliet
On Fri, Jul 19, 2013 at 10:02 AM, PV Juliet <pvjuliet@gmail.com> wrote:
Hi , I am new to kernel and i would like to know where i can get sample programs to use notifier chains .How to subscribe the notifier chains to some application so that i will get notified. Is there any way make this as service in linux system?? Have a look at USB notifiers or extcon.c file in kernel.
Thanks and Regards Juliet
_______________________________________________ Kernelnewbies mailing list Kernelnewbies@kernelnewbies.org http://lists.kernelnewbies.org/mailman/listinfo/kernelnewbies
Hi, On Fri, Jul 19, 2013 at 10:02 AM, PV Juliet <pvjuliet@gmail.com> wrote:
Hi , I am new to kernel and i would like to know where i can get sample programs to use notifier chains .How to subscribe the notifier chains to some application so that i will get notified. Is there any way make this as service in linux system??
https://github.com/prashants/km/tree/master/notifier http://www.linuxforu.com/2009/01/the-crux-of-linux-notifier-chains/ Regards.
Hi, 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 On Fri, Jul 19, 2013 at 10:02 AM, PV Juliet <pvjuliet@gmail.com> wrote:
Hi , I am new to kernel and i would like to know where i can get sample programs to use notifier chains .How to subscribe the notifier chains to some application so that i will get notified. Is there any way make this as service in linux system??
Thanks and Regards Juliet
On Tue, Jul 23, 2013 at 7:21 AM, PV Juliet <pvjuliet@gmail.com> wrote:
Hi, 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 */* * if(notification != NETDEV_CHANGEADDR) return something;* * dev = data;* * printk("Device %s has changed its IP address\n", dev->name); }* * * Let us know if you have any more questions, Regards Adel P.S It's generally considered a bad practice to top-post the reply.
participants (4)
-
Adel Qodmani -
anish singh -
Prashant Shah -
PV Juliet