diff options
author | Martin Mares <mj@ucw.cz> | 1999-11-18 15:41:29 +0100 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1999-11-18 15:41:29 +0100 |
commit | 8d24b6899d0aba52fef8c48921ce4d1481ee212c (patch) | |
tree | 05647436846040fcd1b3fb204720ea1df6276505 /nest/rt-attr.c | |
parent | f31156ca217226ad110cc46e6365d70e64c527e0 (diff) | |
download | bird-8d24b6899d0aba52fef8c48921ce4d1481ee212c.tar bird-8d24b6899d0aba52fef8c48921ce4d1481ee212c.zip |
Allow EA type to be set to 'undefined' which overrides all further definitons
of that EA in the same list and causes ea_find() to fail unless you add
EA_ALLOW_UNDEF to the second argument.
ea_sort (resp. ea_do_prune()) removes all undef'd attributes from the list.
I hope this works :)
Diffstat (limited to 'nest/rt-attr.c')
-rw-r--r-- | nest/rt-attr.c | 40 |
1 files changed, 29 insertions, 11 deletions
diff --git a/nest/rt-attr.c b/nest/rt-attr.c index ca6cb10..2c50f4d 100644 --- a/nest/rt-attr.c +++ b/nest/rt-attr.c @@ -27,8 +27,8 @@ static pool *rta_pool; * Extended Attributes */ -eattr * -ea_find(ea_list *e, unsigned id) +static inline eattr * +ea__find(ea_list *e, unsigned id) { eattr *a; int l, r, m; @@ -60,6 +60,17 @@ ea_find(ea_list *e, unsigned id) return NULL; } +eattr * +ea_find(ea_list *e, unsigned id) +{ + eattr *a = ea__find(e, id & EA_CODE_MASK); + + if (a && (a->type & EAF_TYPE_MASK) == EAF_TYPE_UNDEF && + !(id & EA_ALLOW_UNDEF)) + return NULL; + return a; +} + static inline void ea_do_sort(ea_list *e) { @@ -107,17 +118,24 @@ ea_do_sort(ea_list *e) static inline void ea_do_prune(ea_list *e) { - eattr *s, *d; - int i; + eattr *s, *d, *l; + int i = 0; - /* Discard duplicates. Do you remember sorting was stable? */ - s = d = e->attrs + 1; - for(i=1; i<e->count; i++) - if (s->id != d[-1].id) - *d++ = *s++; - else + /* Discard duplicates and undefs. Do you remember sorting was stable? */ + s = d = e->attrs; + l = e->attrs + e->count; + while (s < l) + { + if ((s->type & EAF_TYPE_MASK) != EAF_TYPE_UNDEF) + { + *d++ = *s; + i++; + } s++; - e->count = d - e->attrs; + while (s < l && s->id == s[-1].id) + s++; + } + e->count = i; } void |