1 | /*
|
---|
2 | * Routines to manage notifier chains for passing status changes to any
|
---|
3 | * interested routines. We need this instead of hard coded call lists so
|
---|
4 | * that modules can poke their nose into the innards. The network devices
|
---|
5 | * needed them so here they are for the rest of you.
|
---|
6 | *
|
---|
7 | * Alan Cox <Alan.Cox@linux.org>
|
---|
8 | */
|
---|
9 |
|
---|
10 | #ifndef _LINUX_NOTIFIER_H
|
---|
11 | #define _LINUX_NOTIFIER_H
|
---|
12 | #include <linux/errno.h>
|
---|
13 |
|
---|
14 | struct notifier_block
|
---|
15 | {
|
---|
16 | int (*notifier_call)(struct notifier_block *self, unsigned long, void *);
|
---|
17 | struct notifier_block *next;
|
---|
18 | int priority;
|
---|
19 | };
|
---|
20 |
|
---|
21 |
|
---|
22 | #ifdef __KERNEL__
|
---|
23 |
|
---|
24 | #define NOTIFY_DONE 0x0000 /* Don't care */
|
---|
25 | #define NOTIFY_OK 0x0001 /* Suits me */
|
---|
26 | #define NOTIFY_STOP_MASK 0x8000 /* Don't call further */
|
---|
27 | #define NOTIFY_BAD (NOTIFY_STOP_MASK|0x0002) /* Bad/Veto action */
|
---|
28 |
|
---|
29 | extern __inline__ int notifier_chain_register(struct notifier_block **list, struct notifier_block *n)
|
---|
30 | {
|
---|
31 | while(*list)
|
---|
32 | {
|
---|
33 | if(n->priority > (*list)->priority)
|
---|
34 | break;
|
---|
35 | list= &((*list)->next);
|
---|
36 | }
|
---|
37 | n->next = *list;
|
---|
38 | *list=n;
|
---|
39 | return 0;
|
---|
40 | }
|
---|
41 |
|
---|
42 | /*
|
---|
43 | * Warning to any non GPL module writers out there.. these functions are
|
---|
44 | * GPL'd
|
---|
45 | */
|
---|
46 |
|
---|
47 | extern __inline__ int notifier_chain_unregister(struct notifier_block **nl, struct notifier_block *n)
|
---|
48 | {
|
---|
49 | while((*nl)!=NULL)
|
---|
50 | {
|
---|
51 | if((*nl)==n)
|
---|
52 | {
|
---|
53 | *nl=n->next;
|
---|
54 | return 0;
|
---|
55 | }
|
---|
56 | nl=&((*nl)->next);
|
---|
57 | }
|
---|
58 | return -ENOENT;
|
---|
59 | }
|
---|
60 |
|
---|
61 | /*
|
---|
62 | * This is one of these things that is generally shorter inline
|
---|
63 | */
|
---|
64 |
|
---|
65 | extern __inline__ int notifier_call_chain(struct notifier_block **n, unsigned long val, void *v)
|
---|
66 | {
|
---|
67 | int ret=NOTIFY_DONE;
|
---|
68 | struct notifier_block *nb = *n;
|
---|
69 | while(nb)
|
---|
70 | {
|
---|
71 | ret=nb->notifier_call(nb,val,v);
|
---|
72 | if(ret&NOTIFY_STOP_MASK)
|
---|
73 | return ret;
|
---|
74 | nb=nb->next;
|
---|
75 | }
|
---|
76 | return ret;
|
---|
77 | }
|
---|
78 |
|
---|
79 |
|
---|
80 | /*
|
---|
81 | * Declared notifiers so far. I can imagine quite a few more chains
|
---|
82 | * over time (eg laptop power reset chains, reboot chain (to clean
|
---|
83 | * device units up), device [un]mount chain, module load/unload chain,
|
---|
84 | * low memory chain, screenblank chain (for plug in modular screenblankers)
|
---|
85 | * VC switch chains (for loadable kernel svgalib VC switch helpers) etc...
|
---|
86 | */
|
---|
87 |
|
---|
88 | /* netdevice notifier chain */
|
---|
89 | #define NETDEV_UP 0x0001 /* For now you can't veto a device up/down */
|
---|
90 | #define NETDEV_DOWN 0x0002
|
---|
91 | #define NETDEV_REBOOT 0x0003 /* Tell a protocol stack a network interface
|
---|
92 | detected a hardware crash and restarted
|
---|
93 | - we can use this eg to kick tcp sessions
|
---|
94 | once done */
|
---|
95 | #define NETDEV_CHANGE 0x0004 /* Notify device state change */
|
---|
96 | #define NETDEV_REGISTER 0x0005
|
---|
97 | #define NETDEV_UNREGISTER 0x0006
|
---|
98 | #define NETDEV_CHANGEMTU 0x0007
|
---|
99 | #define NETDEV_CHANGEADDR 0x0008
|
---|
100 | #define NETDEV_GOING_DOWN 0x0009
|
---|
101 | #define NETDEV_CHANGENAME 0x000A
|
---|
102 |
|
---|
103 | #define SYS_DOWN 0x0001 /* Notify of system down */
|
---|
104 | #define SYS_RESTART SYS_DOWN
|
---|
105 | #define SYS_HALT 0x0002 /* Notify of system halt */
|
---|
106 | #define SYS_POWER_OFF 0x0003 /* Notify of system power off */
|
---|
107 |
|
---|
108 | /*
|
---|
109 | * Publically visible notifier objects
|
---|
110 | */
|
---|
111 |
|
---|
112 | extern struct notifier_block *boot_notifier_list;
|
---|
113 |
|
---|
114 | #endif
|
---|
115 | #endif
|
---|