]>
git.proxmox.com Git - mirror_frr.git/blob - lib/hook.c
2 * Copyright (c) 2016 David Lamparter, for NetDEF, Inc.
4 * Permission to use, copy, modify, and distribute this software for any
5 * purpose with or without fee is hereby granted, provided that the above
6 * copyright notice and this permission notice appear in all copies.
8 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
9 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
10 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
11 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
12 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
13 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
14 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
26 DEFINE_MTYPE_STATIC(LIB
, HOOK_ENTRY
, "Hook entry")
28 void _hook_register(struct hook
*hook
, struct hookent
*stackent
, void *funcptr
,
29 void *arg
, bool has_arg
, struct frrmod_runtime
*module
,
30 const char *funcname
, int priority
)
32 struct hookent
*he
, **pos
;
34 if (!stackent
->ent_used
)
37 he
= XCALLOC(MTYPE_HOOK_ENTRY
, sizeof(*he
));
38 he
->ent_on_heap
= true;
43 he
->has_arg
= has_arg
;
45 he
->fnname
= funcname
;
46 he
->priority
= priority
;
48 for (pos
= &hook
->entries
; *pos
; pos
= &(*pos
)->next
)
49 if (hook
->reverse
? (*pos
)->priority
< priority
50 : (*pos
)->priority
>= priority
)
57 void _hook_unregister(struct hook
*hook
, void *funcptr
, void *arg
, bool has_arg
)
59 struct hookent
*he
, **prev
;
61 for (prev
= &hook
->entries
; (he
= *prev
) != NULL
; prev
= &he
->next
)
62 if (he
->hookfn
== funcptr
&& he
->hookarg
== arg
63 && he
->has_arg
== has_arg
) {
66 XFREE(MTYPE_HOOK_ENTRY
, he
);
68 memset(he
, 0, sizeof(*he
));