]> git.proxmox.com Git - mirror_frr.git/blame - lib/hook.c
zebra: Allow json output to give a bit more data
[mirror_frr.git] / lib / hook.c
CommitLineData
a5b38c5b
DL
1/*
2 * Copyright (c) 2016 David Lamparter, for NetDEF, Inc.
3 *
78412258
DL
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.
a5b38c5b 7 *
78412258
DL
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.
a5b38c5b
DL
15 */
16
17#include "memory.h"
18#include "hook.h"
19
20DEFINE_MTYPE_STATIC(LIB, HOOK_ENTRY, "Hook entry")
21
22void _hook_register(struct hook *hook, void *funcptr, void *arg, bool has_arg,
08c4c73b
DL
23 struct frrmod_runtime *module, const char *funcname,
24 int priority)
a5b38c5b 25{
08c4c73b 26 struct hookent *he = XCALLOC(MTYPE_HOOK_ENTRY, sizeof(*he)), **pos;
a5b38c5b
DL
27 he->hookfn = funcptr;
28 he->hookarg = arg;
29 he->has_arg = has_arg;
30 he->module = module;
31 he->fnname = funcname;
08c4c73b 32 he->priority = priority;
a5b38c5b 33
08c4c73b 34 for (pos = &hook->entries; *pos; pos = &(*pos)->next)
996c9314
LB
35 if (hook->reverse ? (*pos)->priority < priority
36 : (*pos)->priority >= priority)
08c4c73b
DL
37 break;
38
39 he->next = *pos;
40 *pos = he;
a5b38c5b
DL
41}
42
d62a17ae 43void _hook_unregister(struct hook *hook, void *funcptr, void *arg, bool has_arg)
a5b38c5b
DL
44{
45 struct hookent *he, **prev;
46
47 for (prev = &hook->entries; (he = *prev) != NULL; prev = &he->next)
48 if (he->hookfn == funcptr && he->hookarg == arg
d62a17ae 49 && he->has_arg == has_arg) {
a5b38c5b
DL
50 *prev = he->next;
51 XFREE(MTYPE_HOOK_ENTRY, he);
52 break;
53 }
54}