mirror of
https://gitlab.nic.cz/labs/bird.git
synced 2024-12-22 09:41:54 +00:00
Added functions for manipulating interface name pattern lists:
o iface_patt_match(list, iface) -- match interface against list o iface_patts_equal(a, b, c) -- compare whether two pattern lists are equal or not. c(x,y) is called for comparison of protocol-dependent data.
This commit is contained in:
parent
49e4a4d1fd
commit
ed45f2e126
42
nest/iface.c
42
nest/iface.c
@ -12,6 +12,7 @@
|
|||||||
#include "nest/iface.h"
|
#include "nest/iface.h"
|
||||||
#include "nest/protocol.h"
|
#include "nest/protocol.h"
|
||||||
#include "lib/resource.h"
|
#include "lib/resource.h"
|
||||||
|
#include "lib/string.h"
|
||||||
|
|
||||||
static pool *if_pool;
|
static pool *if_pool;
|
||||||
|
|
||||||
@ -353,3 +354,44 @@ if_init(void)
|
|||||||
neigh_slab = sl_new(if_pool, sizeof(neighbor));
|
neigh_slab = sl_new(if_pool, sizeof(neighbor));
|
||||||
init_list(&neigh_list);
|
init_list(&neigh_list);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interface Pattern Lists
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct iface_patt *
|
||||||
|
iface_patt_match(list *l, struct iface *i)
|
||||||
|
{
|
||||||
|
struct iface_patt *p;
|
||||||
|
|
||||||
|
WALK_LIST(p, *l)
|
||||||
|
{
|
||||||
|
char *t = p->pattern;
|
||||||
|
int ok = 1;
|
||||||
|
if (*t == '-')
|
||||||
|
{
|
||||||
|
t++;
|
||||||
|
ok = 0;
|
||||||
|
}
|
||||||
|
if (patmatch(t, i->name))
|
||||||
|
return ok ? p : NULL;
|
||||||
|
}
|
||||||
|
return NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
int
|
||||||
|
iface_patts_equal(list *a, list *b, int (*comp)(struct iface_patt *, struct iface_patt *))
|
||||||
|
{
|
||||||
|
struct iface_patt *x, *y;
|
||||||
|
|
||||||
|
x = HEAD(*a);
|
||||||
|
y = HEAD(*b);
|
||||||
|
while (x->n.next && y->n.next)
|
||||||
|
{
|
||||||
|
if (strcmp(x->pattern, y->pattern) || comp && !comp(x, y))
|
||||||
|
return 0;
|
||||||
|
x = (void *) x->n.next;
|
||||||
|
y = (void *) y->n.next;
|
||||||
|
}
|
||||||
|
return (!x->n.next && !y->n.next);
|
||||||
|
}
|
||||||
|
14
nest/iface.h
14
nest/iface.h
@ -91,4 +91,18 @@ neighbor *neigh_find(struct proto *, ip_addr *, unsigned flags);
|
|||||||
void neigh_dump(neighbor *);
|
void neigh_dump(neighbor *);
|
||||||
void neigh_dump_all(void);
|
void neigh_dump_all(void);
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Interface Pattern Lists
|
||||||
|
*/
|
||||||
|
|
||||||
|
struct iface_patt {
|
||||||
|
node n;
|
||||||
|
byte *pattern; /* Interface name pattern */
|
||||||
|
|
||||||
|
/* Protocol-specific data follow */
|
||||||
|
};
|
||||||
|
|
||||||
|
struct iface_patt *iface_patt_match(list *, struct iface *);
|
||||||
|
int iface_patts_equal(list *, list *, int (*)(struct iface_patt *, struct iface_patt *));
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
Loading…
Reference in New Issue
Block a user