back to topotato report
topotato coverage report
Current view: top level - lib - hook.c (source / functions) Hit Total Coverage
Test: test_bgp_ecmp_enhe.py::BGP_Unnumbered_ECMP Lines: 26 29 89.7 %
Date: 2023-11-16 17:19:14 Functions: 4 7 57.1 %

          Line data    Source code
       1             : // SPDX-License-Identifier: ISC
       2             : /*
       3             :  * Copyright (c) 2016  David Lamparter, for NetDEF, Inc.
       4             :  */
       5             : 
       6             : #ifdef HAVE_CONFIG_H
       7             : #include "config.h"
       8             : #endif
       9             : 
      10             : #include <string.h>
      11             : 
      12             : #include "memory.h"
      13             : #include "hook.h"
      14             : 
      15          12 : DEFINE_MTYPE_STATIC(LIB, HOOK_ENTRY, "Hook entry");
      16             : 
      17         106 : 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)
      20             : {
      21         106 :         struct hookent *he, **pos;
      22             : 
      23         106 :         if (!stackent->ent_used)
      24             :                 he = stackent;
      25             :         else {
      26           0 :                 he = XCALLOC(MTYPE_HOOK_ENTRY, sizeof(*he));
      27           0 :                 he->ent_on_heap = true;
      28             :         }
      29         106 :         he->ent_used = true;
      30         106 :         he->hookfn = funcptr;
      31         106 :         he->hookarg = arg;
      32         106 :         he->has_arg = has_arg;
      33         106 :         he->module = module;
      34         106 :         he->fnname = funcname;
      35         106 :         he->priority = priority;
      36             : 
      37         202 :         for (pos = &hook->entries; *pos; pos = &(*pos)->next)
      38         104 :                 if (hook->reverse ? (*pos)->priority < priority
      39           4 :                                   : (*pos)->priority >= priority)
      40             :                         break;
      41             : 
      42         106 :         he->next = *pos;
      43         106 :         *pos = he;
      44         106 : }
      45             : 
      46          14 : void _hook_unregister(struct hook *hook, void *funcptr, void *arg, bool has_arg)
      47             : {
      48          14 :         struct hookent *he, **prev;
      49             : 
      50          20 :         for (prev = &hook->entries; (he = *prev) != NULL; prev = &he->next)
      51          20 :                 if (he->hookfn == funcptr && he->hookarg == arg
      52          14 :                     && he->has_arg == has_arg) {
      53          14 :                         *prev = he->next;
      54          14 :                         if (he->ent_on_heap)
      55           0 :                                 XFREE(MTYPE_HOOK_ENTRY, he);
      56             :                         else
      57          14 :                                 memset(he, 0, sizeof(*he));
      58             :                         break;
      59             :                 }
      60          14 : }

Generated by: LCOV version v1.16-topotato