X-Git-Url: http://www.chiark.greenend.org.uk/ucgi/~ian/git?p=secnet.git;a=blobdiff_plain;f=util.c;h=0ffdcdd8db381504707270c3efcfde083a0b1252;hp=c652537704333f55ded4eb8890ece6f29d0d7f2b;hb=baa06aeb963965b4b6a8a8051ec15b72372080dd;hpb=5963521296680c2aeb40baeb72459dffc14cd996 diff --git a/util.c b/util.c index c652537..0ffdcdd 100644 --- a/util.c +++ b/util.c @@ -8,19 +8,15 @@ * */ -#include "config.h" +#include "secnet.h" #include -#include #include #include -#include #include #include #include -#include #include #include "util.h" -#include "secnet.h" #include "unaligned.h" #define MIN_BUFFER_SIZE 64 @@ -252,6 +248,31 @@ bool_t subnet_match(struct subnet_list *list, uint32_t address) return False; } +bool_t subnets_intersect(struct subnet a, struct subnet b) +{ + uint32_t mask=a.mask&b.mask; + return ((a.prefix&mask)==(b.prefix&mask)); +} + +bool_t subnet_intersects_with_list(struct subnet a, struct subnet_list *b) +{ + uint32_t i; + + for (i=0; ientries; i++) { + if (subnets_intersect(a,b->list[i])) return True; + } + return False; +} + +bool_t subnet_lists_intersect(struct subnet_list *a, struct subnet_list *b) +{ + uint32_t i; + for (i=0; ientries; i++) { + if (subnet_intersects_with_list(a->list[i],b)) return True; + } + return False; +} + /* The string buffer must be at least 16 bytes long */ string_t ipaddr_to_string(uint32_t addr) { @@ -419,6 +440,7 @@ static char *phases[NR_PHASES]={ "PHASE_GETOPTS", "PHASE_READCONFIG", "PHASE_SETUP", + "PHASE_GETRESOURCES", "PHASE_DROPPRIV", "PHASE_RUN", "PHASE_SHUTDOWN" @@ -428,12 +450,13 @@ void enter_phase(uint32_t new_phase) { struct phase_hook *i; - Message(M_DEBUG_PHASE,"entering %s... ", phases[new_phase]); + if (hooks[new_phase]) + Message(M_DEBUG_PHASE,"Running hooks for %s...\n", phases[new_phase]); current_phase=new_phase; for (i=hooks[new_phase]; i; i=i->next) i->fn(i->state, new_phase); - Message(M_DEBUG_PHASE,"now in %s\n",phases[new_phase]); + Message(M_DEBUG_PHASE,"Now in %s\n",phases[new_phase]); } bool_t add_hook(uint32_t phase, hook_fn *fn, void *state)