]>
git.proxmox.com Git - mirror_frr.git/blob - lib/hook.c
1 // SPDX-License-Identifier: ISC
3 * Copyright (c) 2016 David Lamparter, for NetDEF, Inc.
15 DEFINE_MTYPE_STATIC(LIB
, HOOK_ENTRY
, "Hook entry");
17 void _hook_register(struct hook
*hook
, struct hookent
*stackent
, void *funcptr
,
18 void *arg
, bool has_arg
, struct frrmod_runtime
*module
,
19 const char *funcname
, int priority
)
21 struct hookent
*he
, **pos
;
23 if (!stackent
->ent_used
)
26 he
= XCALLOC(MTYPE_HOOK_ENTRY
, sizeof(*he
));
27 he
->ent_on_heap
= true;
32 he
->has_arg
= has_arg
;
34 he
->fnname
= funcname
;
35 he
->priority
= priority
;
37 for (pos
= &hook
->entries
; *pos
; pos
= &(*pos
)->next
)
38 if (hook
->reverse
? (*pos
)->priority
< priority
39 : (*pos
)->priority
>= priority
)
46 void _hook_unregister(struct hook
*hook
, void *funcptr
, void *arg
, bool has_arg
)
48 struct hookent
*he
, **prev
;
50 for (prev
= &hook
->entries
; (he
= *prev
) != NULL
; prev
= &he
->next
)
51 if (he
->hookfn
== funcptr
&& he
->hookarg
== arg
52 && he
->has_arg
== has_arg
) {
55 XFREE(MTYPE_HOOK_ENTRY
, he
);
57 memset(he
, 0, sizeof(*he
));