Notifying Events on a Chain
Notifications are generated with notifier_call_chain. This function simply invokes, in order of priority, all the callback routines registered against the chain. Note that callback routines are executed in the context of the process that calls notifier_call_chain. A callback routine could, however, be implemented so that it queues the notification somewhere and wakes up a process that will look at it.
NOTE: Similar to register and unregister functions we don't directly call notifier_call_chain function as we have wrapper functions for respective chains.
<kernel/notifier.c> 58 static int __kprobes notifier_call_chain(struct notifier_block **nl, 59 unsigned long val, void *v, 60 int nr_to_call, int *nr_calls) 61 { 62 int ret = NOTIFY_DONE; 63 struct notifier_block *nb, *next_nb; 64 65 nb = rcu_dereference(*nl); 66 67 while (nb && nr_to_call) { 68 next_nb = rcu_dereference(nb->next); 69 ret = nb->notifier_call(nb, val, v); . 76 nb = next_nb; 77 nr_to_call--; 78 } 79 return ret; 80 }
- nl
Notification chain. - val
Event type. The chain itself identifies a class of events; val unequivocally identifies an event type (i.e., NETDEV_REGISTER). - v
Input parameter that can be used by the handlers registered by the various clients. This can be used in different ways under different circumstances. For instance, when a new network device is registered with the kernel, the associated notification uses v to identify the net_device data structure. - nr_to_call
Number of notifier functions to be called. Don't care value of this parameter is -1. - nr_calls
Records the number of notifications sent. Don't care value of this field is NULL.