From 20e94fb85b7097b57089e3912475ac881fd5528d Mon Sep 17 00:00:00 2001 From: Ondrej Zajicek Date: Wed, 6 May 2009 22:02:45 +0200 Subject: A change in OSPF and RIP interface patterns. Allows to add more interface patterns to one common 'options' section like: interface "eth3", "eth4" { options common to eth3 and eth4 }; Also removes undocumented and unnecessary ability to specify more interface patterns with different 'options' sections: interface "eth3" { options ... }, "eth4" { options ... }; --- nest/iface.c | 67 +++++++++++++++++++++++++++++++++++++++++++++--------------- 1 file changed, 51 insertions(+), 16 deletions(-) (limited to 'nest/iface.c') diff --git a/nest/iface.c b/nest/iface.c index 157a977..01f2581 100644 --- a/nest/iface.c +++ b/nest/iface.c @@ -543,32 +543,72 @@ if_init(void) * Interface Pattern Lists */ -struct iface_patt * -iface_patt_match(list *l, struct iface *i) +static int +iface_patt_match(struct iface_patt *ifp, struct iface *i) { - struct iface_patt *p; + struct iface_patt_node *p; - WALK_LIST(p, *l) + WALK_LIST(p, ifp->ipn_list) { char *t = p->pattern; - int ok = 1; + int pos = p->positive; + if (t) { if (*t == '-') { t++; - ok = 0; + pos = !pos; } + if (!patmatch(t, i->name)) continue; } - if (!i->addr || !ipa_in_net(i->addr->ip, p->prefix, p->pxlen)) - continue; - return ok ? p : NULL; + + if (p->pxlen) + if (!i->addr || !ipa_in_net(i->addr->ip, p->prefix, p->pxlen)) + continue; + + return pos; } + + return 0; +} + +struct iface_patt * +iface_patt_find(list *l, struct iface *i) +{ + struct iface_patt *p; + + WALK_LIST(p, *l) + if (iface_patt_match(p, i)) + return p; + return NULL; } +static int +iface_plists_equal(struct iface_patt *pa, struct iface_patt *pb) +{ + struct iface_patt_node *x, *y; + + x = HEAD(pa->ipn_list); + y = HEAD(pb->ipn_list); + while (x->n.next && y->n.next) + { + if ((x->positive != y->positive) || + (!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */ + (!y->pattern && x->pattern) || + ((x->pattern != y->pattern) && strcmp(x->pattern, y->pattern)) || + !ipa_equal(x->prefix, y->prefix) || + (x->pxlen != y->pxlen)) + return 0; + x = (void *) x->n.next; + y = (void *) y->n.next; + } + return (!x->n.next && !y->n.next); +} + int iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct iface_patt *)) { @@ -578,13 +618,8 @@ iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct ifac y = HEAD(*b); while (x->n.next && y->n.next) { - if ((!x->pattern && y->pattern) || /* This nasty lines where written by me... :-( Feela */ - (!y->pattern && x->pattern) || - (!(x->pattern==y->pattern) && - strcmp(x->pattern, y->pattern)) || - !ipa_equal(x->prefix, y->prefix) || - x->pxlen != y->pxlen || - comp && !comp(x, y)) + if (!iface_plists_equal(x, y) || + (comp && !comp(x, y))) return 0; x = (void *) x->n.next; y = (void *) y->n.next; -- cgit v1.2.3