]>
git.ipfire.org Git - thirdparty/bird.git/blob - nest/rt-attr.c
2 * BIRD -- Route Attribute Cache
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
10 * DOC: Route attribute cache
12 * Each route entry carries a set of route attributes. Several of them
13 * vary from route to route, but most attributes are usually common
14 * for a large number of routes. To conserve memory, we've decided to
15 * store only the varying ones directly in the &rte and hold the rest
16 * in a special structure called &rta which is shared among all the
17 * &rte's with these attributes.
19 * Each &rta contains all the static attributes of the route (i.e.,
20 * those which are always present) as structure members and a list of
21 * dynamic attributes represented by a linked list of &ea_list
22 * structures, each of them consisting of an array of &eattr's containing
23 * the individual attributes. An attribute can be specified more than once
24 * in the &ea_list chain and in such case the first occurrence overrides
25 * the others. This semantics is used especially when someone (for example
26 * a filter) wishes to alter values of several dynamic attributes, but
27 * it wants to preserve the original attribute lists maintained by
30 * Each &eattr contains an attribute identifier (split to protocol ID and
31 * per-protocol attribute ID), protocol dependent flags, a type code (consisting
32 * of several bit fields describing attribute characteristics) and either an
33 * embedded 32-bit value or a pointer to a &adata structure holding attribute
36 * There exist two variants of &rta's -- cached and un-cached ones. Un-cached
37 * &rta's can have arbitrarily complex structure of &ea_list's and they
38 * can be modified by any module in the route processing chain. Cached
39 * &rta's have their attribute lists normalized (that means at most one
40 * &ea_list is present and its values are sorted in order to speed up
41 * searching), they are stored in a hash table to make fast lookup possible
42 * and they are provided with a use count to allow sharing.
44 * Routing tables always contain only cached &rta's.
47 #include "nest/bird.h"
48 #include "nest/route.h"
49 #include "nest/protocol.h"
50 #include "nest/iface.h"
52 #include "nest/attrs.h"
53 #include "lib/alloca.h"
56 #include "lib/resource.h"
57 #include "lib/string.h"
63 static slab
*rta_slab
;
64 static slab
*mpnh_slab
;
65 static slab
*rte_src_slab
;
67 static struct idm src_ids
;
68 #define SRC_ID_INIT_SIZE 4
72 #define RSH_KEY(n) n->proto, n->private_id
73 #define RSH_NEXT(n) n->next
74 #define RSH_EQ(p1,n1,p2,n2) p1 == p2 && n1 == n2
75 #define RSH_FN(p,n) p->hash_key ^ u32_hash(n)
77 #define RSH_REHASH rte_src_rehash
78 #define RSH_PARAMS /2, *2, 1, 1, 8, 20
79 #define RSH_INIT_ORDER 6
81 static HASH(struct rte_src
) src_hash
;
83 struct protocol
*attr_class_to_protocol
[EAP_MAX
];
89 rte_src_slab
= sl_new(rta_pool
, sizeof(struct rte_src
));
91 idm_init(&src_ids
, rta_pool
, SRC_ID_INIT_SIZE
);
93 HASH_INIT(src_hash
, rta_pool
, RSH_INIT_ORDER
);
97 HASH_DEFINE_REHASH_FN(RSH
, struct rte_src
)
100 rt_find_source(struct proto
*p
, u32 id
)
102 return HASH_FIND(src_hash
, RSH
, p
, id
);
106 rt_get_source(struct proto
*p
, u32 id
)
108 struct rte_src
*src
= rt_find_source(p
, id
);
113 src
= sl_alloc(rte_src_slab
);
115 src
->private_id
= id
;
116 src
->global_id
= idm_alloc(&src_ids
);
119 HASH_INSERT2(src_hash
, RSH
, rta_pool
, src
);
125 rt_prune_sources(void)
127 HASH_WALK_FILTER(src_hash
, next
, src
, sp
)
131 HASH_DO_REMOVE(src_hash
, RSH
, sp
);
132 idm_free(&src_ids
, src
->global_id
);
133 sl_free(rte_src_slab
, src
);
136 HASH_WALK_FILTER_END
;
138 HASH_MAY_RESIZE_DOWN(src_hash
, RSH
, rta_pool
);
147 mpnh_hash(struct mpnh
*x
)
150 for (; x
; x
= x
->next
)
151 h
^= ipa_hash(x
->gw
);
157 mpnh__same(struct mpnh
*x
, struct mpnh
*y
)
159 for (; x
&& y
; x
= x
->next
, y
= y
->next
)
160 if (!ipa_equal(x
->gw
, y
->gw
) || (x
->iface
!= y
->iface
) || (x
->weight
!= y
->weight
))
167 mpnh_compare_node(struct mpnh
*x
, struct mpnh
*y
)
177 r
= ((int) y
->weight
) - ((int) x
->weight
);
181 r
= ipa_compare(x
->gw
, y
->gw
);
185 return ((int) x
->iface
->index
) - ((int) y
->iface
->index
);
188 static inline struct mpnh
*
189 mpnh_copy_node(const struct mpnh
*src
, linpool
*lp
)
191 struct mpnh
*n
= lp_alloc(lp
, sizeof(struct mpnh
));
193 n
->iface
= src
->iface
;
195 n
->weight
= src
->weight
;
200 * mpnh_merge - merge nexthop lists
203 * @rx: reusability of list @x
204 * @ry: reusability of list @y
205 * @max: max number of nexthops
206 * @lp: linpool for allocating nexthops
208 * The mpnh_merge() function takes two nexthop lists @x and @y and merges them,
209 * eliminating possible duplicates. The input lists must be sorted and the
210 * result is sorted too. The number of nexthops in result is limited by @max.
211 * New nodes are allocated from linpool @lp.
213 * The arguments @rx and @ry specify whether corresponding input lists may be
214 * consumed by the function (i.e. their nodes reused in the resulting list), in
215 * that case the caller should not access these lists after that. To eliminate
216 * issues with deallocation of these lists, the caller should use some form of
217 * bulk deallocation (e.g. stack or linpool) to free these nodes when the
218 * resulting list is no longer needed. When reusability is not set, the
219 * corresponding lists are not modified nor linked from the resulting list.
222 mpnh_merge(struct mpnh
*x
, struct mpnh
*y
, int rx
, int ry
, int max
, linpool
*lp
)
224 struct mpnh
*root
= NULL
;
225 struct mpnh
**n
= &root
;
227 while ((x
|| y
) && max
--)
229 int cmp
= mpnh_compare_node(x
, y
);
232 *n
= rx
? x
: mpnh_copy_node(x
, lp
);
237 *n
= ry
? y
: mpnh_copy_node(y
, lp
);
242 *n
= rx
? x
: (ry
? y
: mpnh_copy_node(x
, lp
));
254 mpnh_insert(struct mpnh
**n
, struct mpnh
*x
)
256 for (; *n
; n
= &((*n
)->next
))
258 int cmp
= mpnh_compare_node(*n
, x
);
273 mpnh_is_sorted(struct mpnh
*x
)
275 for (; x
&& x
->next
; x
= x
->next
)
276 if (mpnh_compare_node(x
, x
->next
) >= 0)
283 mpnh_copy(struct mpnh
*o
)
285 struct mpnh
*first
= NULL
;
286 struct mpnh
**last
= &first
;
288 for (; o
; o
= o
->next
)
290 struct mpnh
*n
= sl_alloc(mpnh_slab
);
294 n
->weight
= o
->weight
;
304 mpnh_free(struct mpnh
*o
)
311 sl_free(mpnh_slab
, o
);
318 * Extended Attributes
321 static inline eattr
*
322 ea__find(ea_list
*e
, unsigned id
)
329 if (e
->flags
& EALF_BISECT
)
346 for(m
=0; m
<e
->count
; m
++)
347 if (e
->attrs
[m
].id
== id
)
355 * ea_find - find an extended attribute
356 * @e: attribute list to search in
357 * @id: attribute ID to search for
359 * Given an extended attribute list, ea_find() searches for a first
360 * occurrence of an attribute with specified ID, returning either a pointer
361 * to its &eattr structure or %NULL if no such attribute exists.
364 ea_find(ea_list
*e
, unsigned id
)
366 eattr
*a
= ea__find(e
, id
& EA_CODE_MASK
);
368 if (a
&& (a
->type
& EAF_TYPE_MASK
) == EAF_TYPE_UNDEF
&&
369 !(id
& EA_ALLOW_UNDEF
))
375 * ea_walk - walk through extended attributes
376 * @s: walk state structure
377 * @id: start of attribute ID interval
378 * @max: length of attribute ID interval
380 * Given an extended attribute list, ea_walk() walks through the list looking
381 * for first occurrences of attributes with ID in specified interval from @id to
382 * (@id + @max - 1), returning pointers to found &eattr structures, storing its
383 * walk state in @s for subsequent calls.
385 * The function ea_walk() is supposed to be called in a loop, with initially
386 * zeroed walk state structure @s with filled the initial extended attribute
387 * list, returning one found attribute in each call or %NULL when no other
388 * attribute exists. The extended attribute list or the arguments should not be
389 * modified between calls. The maximum value of @max is 128.
392 ea_walk(struct ea_walk_state
*s
, uint id
, uint max
)
394 ea_list
*e
= s
->eattrs
;
403 for (; e
; e
= e
->next
)
405 if (e
->flags
& EALF_BISECT
)
414 if (e
->attrs
[m
].id
< id
)
425 a_max
= e
->attrs
+ e
->count
;
426 for (; a
< a_max
; a
++)
427 if ((a
->id
>= id
) && (a
->id
< max
))
431 if (BIT32_TEST(s
->visited
, n
))
434 BIT32_SET(s
->visited
, n
);
436 if ((a
->type
& EAF_TYPE_MASK
) == EAF_TYPE_UNDEF
)
443 else if (e
->flags
& EALF_BISECT
)
451 * ea_get_int - fetch an integer attribute
454 * @def: default value
456 * This function is a shortcut for retrieving a value of an integer attribute
457 * by calling ea_find() to find the attribute, extracting its value or returning
458 * a provided default if no such attribute is present.
461 ea_get_int(ea_list
*e
, unsigned id
, int def
)
463 eattr
*a
= ea_find(e
, id
);
470 ea_do_sort(ea_list
*e
)
472 unsigned n
= e
->count
;
474 eattr
*b
= alloca(n
* sizeof(eattr
));
477 /* We need to use a stable sorting algorithm, hence mergesort */
483 eattr
*p
, *q
, *lo
, *hi
;
487 while (s
< n
&& p
[-1].id
<= a
[s
].id
)
493 while (s
< n
&& p
[-1].id
<= a
[s
].id
)
498 while (lo
< q
&& hi
< p
)
499 if (lo
->id
<= hi
->id
)
514 ea_do_prune(ea_list
*e
)
516 eattr
*s
, *d
, *l
, *s0
;
519 /* Discard duplicates and undefs. Do you remember sorting was stable? */
521 l
= e
->attrs
+ e
->count
;
525 while (s
< l
&& s
->id
== s
[-1].id
)
527 /* s0 is the most recent version, s[-1] the oldest one */
528 if ((s0
->type
& EAF_TYPE_MASK
) != EAF_TYPE_UNDEF
)
531 d
->type
= (d
->type
& ~EAF_ORIGINATED
) | (s
[-1].type
& EAF_ORIGINATED
);
540 * ea_sort - sort an attribute list
541 * @e: list to be sorted
543 * This function takes a &ea_list chain and sorts the attributes
544 * within each of its entries.
546 * If an attribute occurs multiple times in a single &ea_list,
547 * ea_sort() leaves only the first (the only significant) occurrence.
554 if (!(e
->flags
& EALF_SORTED
))
558 e
->flags
|= EALF_SORTED
;
561 e
->flags
|= EALF_BISECT
;
567 * ea_scan - estimate attribute list size
570 * This function calculates an upper bound of the size of
571 * a given &ea_list after merging with ea_merge().
583 return sizeof(ea_list
) + sizeof(eattr
)*cnt
;
587 * ea_merge - merge segments of an attribute list
589 * @t: buffer to store the result to
591 * This function takes a possibly multi-segment attribute list
592 * and merges all of its segments to one.
594 * The primary use of this function is for &ea_list normalization:
595 * first call ea_scan() to determine how much memory will the result
596 * take, then allocate a buffer (usually using alloca()), merge the
597 * segments with ea_merge() and finally sort and prune the result
598 * by calling ea_sort().
601 ea_merge(ea_list
*e
, ea_list
*t
)
610 memcpy(d
, e
->attrs
, sizeof(eattr
)*e
->count
);
611 t
->count
+= e
->count
;
618 * ea_same - compare two &ea_list's
622 * ea_same() compares two normalized attribute lists @x and @y and returns
623 * 1 if they contain the same attributes, 0 otherwise.
626 ea_same(ea_list
*x
, ea_list
*y
)
632 ASSERT(!x
->next
&& !y
->next
);
633 if (x
->count
!= y
->count
)
635 for(c
=0; c
<x
->count
; c
++)
637 eattr
*a
= &x
->attrs
[c
];
638 eattr
*b
= &y
->attrs
[c
];
640 if (a
->id
!= b
->id
||
641 a
->flags
!= b
->flags
||
642 a
->type
!= b
->type
||
643 ((a
->type
& EAF_EMBEDDED
) ? a
->u
.data
!= b
->u
.data
: !adata_same(a
->u
.ptr
, b
->u
.ptr
)))
649 static inline ea_list
*
650 ea_list_copy(ea_list
*o
)
658 len
= sizeof(ea_list
) + sizeof(eattr
) * o
->count
;
659 n
= mb_alloc(rta_pool
, len
);
661 n
->flags
|= EALF_CACHED
;
662 for(i
=0; i
<o
->count
; i
++)
664 eattr
*a
= &n
->attrs
[i
];
665 if (!(a
->type
& EAF_EMBEDDED
))
667 unsigned size
= sizeof(struct adata
) + a
->u
.ptr
->length
;
668 struct adata
*d
= mb_alloc(rta_pool
, size
);
669 memcpy(d
, a
->u
.ptr
, size
);
684 for(i
=0; i
<o
->count
; i
++)
686 eattr
*a
= &o
->attrs
[i
];
687 if (!(a
->type
& EAF_EMBEDDED
))
695 get_generic_attr(eattr
*a
, byte
**buf
, int buflen UNUSED
)
697 if (a
->id
== EA_GEN_IGP_METRIC
)
699 *buf
+= bsprintf(*buf
, "igp_metric");
707 ea_format_bitfield(struct eattr
*a
, byte
*buf
, int bufsize
, const char **names
, int min
, int max
)
709 byte
*bound
= buf
+ bufsize
- 32;
710 u32 data
= a
->u
.data
;
713 for (i
= min
; i
< max
; i
++)
714 if ((data
& (1u << i
)) && names
[i
])
722 buf
+= bsprintf(buf
, " %s", names
[i
]);
727 bsprintf(buf
, " %08x", data
);
733 opaque_format(struct adata
*ad
, byte
*buf
, uint size
)
735 byte
*bound
= buf
+ size
- 10;
738 for(i
= 0; i
< ad
->length
; i
++)
748 buf
+= bsprintf(buf
, "%02x", ad
->data
[i
]);
756 ea_show_int_set(struct cli
*c
, struct adata
*ad
, int way
, byte
*pos
, byte
*buf
, byte
*end
)
758 int i
= int_set_format(ad
, way
, 0, pos
, end
- pos
);
759 cli_printf(c
, -1012, "\t%s", buf
);
762 i
= int_set_format(ad
, way
, i
, buf
, end
- buf
- 1);
763 cli_printf(c
, -1012, "\t\t%s", buf
);
768 ea_show_ec_set(struct cli
*c
, struct adata
*ad
, byte
*pos
, byte
*buf
, byte
*end
)
770 int i
= ec_set_format(ad
, 0, pos
, end
- pos
);
771 cli_printf(c
, -1012, "\t%s", buf
);
774 i
= ec_set_format(ad
, i
, buf
, end
- buf
- 1);
775 cli_printf(c
, -1012, "\t\t%s", buf
);
780 ea_show_lc_set(struct cli
*c
, struct adata
*ad
, byte
*pos
, byte
*buf
, byte
*end
)
782 int i
= lc_set_format(ad
, 0, pos
, end
- pos
);
783 cli_printf(c
, -1012, "\t%s", buf
);
786 i
= lc_set_format(ad
, i
, buf
, end
- buf
- 1);
787 cli_printf(c
, -1012, "\t\t%s", buf
);
792 * ea_show - print an &eattr to CLI
793 * @c: destination CLI
794 * @e: attribute to be printed
796 * This function takes an extended attribute represented by its &eattr
797 * structure and prints it to the CLI according to the type information.
799 * If the protocol defining the attribute provides its own
800 * get_attr() hook, it's consulted first.
803 ea_show(struct cli
*c
, eattr
*e
)
806 int status
= GA_UNKNOWN
;
807 struct adata
*ad
= (e
->type
& EAF_EMBEDDED
) ? NULL
: e
->u
.ptr
;
808 byte buf
[CLI_MSG_SIZE
];
809 byte
*pos
= buf
, *end
= buf
+ sizeof(buf
);
811 if (p
= attr_class_to_protocol
[EA_PROTO(e
->id
)])
813 pos
+= bsprintf(pos
, "%s.", p
->name
);
815 status
= p
->get_attr(e
, pos
, end
- pos
);
818 else if (EA_PROTO(e
->id
))
819 pos
+= bsprintf(pos
, "%02x.", EA_PROTO(e
->id
));
821 status
= get_generic_attr(e
, &pos
, end
- pos
);
823 if (status
< GA_NAME
)
824 pos
+= bsprintf(pos
, "%02x", EA_ID(e
->id
));
825 if (status
< GA_FULL
)
829 switch (e
->type
& EAF_TYPE_MASK
)
832 bsprintf(pos
, "%u", e
->u
.data
);
834 case EAF_TYPE_OPAQUE
:
835 opaque_format(ad
, pos
, end
- pos
);
837 case EAF_TYPE_IP_ADDRESS
:
838 bsprintf(pos
, "%I", *(ip_addr
*) ad
->data
);
840 case EAF_TYPE_ROUTER_ID
:
841 bsprintf(pos
, "%R", e
->u
.data
);
843 case EAF_TYPE_AS_PATH
:
844 as_path_format(ad
, pos
, end
- pos
);
846 case EAF_TYPE_BITFIELD
:
847 bsprintf(pos
, "%08x", e
->u
.data
);
849 case EAF_TYPE_INT_SET
:
850 ea_show_int_set(c
, ad
, 1, pos
, buf
, end
);
852 case EAF_TYPE_EC_SET
:
853 ea_show_ec_set(c
, ad
, pos
, buf
, end
);
855 case EAF_TYPE_LC_SET
:
856 ea_show_lc_set(c
, ad
, pos
, buf
, end
);
860 bsprintf(pos
, "<type %02x>", e
->type
);
863 cli_printf(c
, -1012, "\t%s", buf
);
867 * ea_dump - dump an extended attribute
868 * @e: attribute to be dumped
870 * ea_dump() dumps contents of the extended attribute given to
886 (e
->flags
& EALF_SORTED
) ? 'S' : 's',
887 (e
->flags
& EALF_BISECT
) ? 'B' : 'b',
888 (e
->flags
& EALF_CACHED
) ? 'C' : 'c');
889 for(i
=0; i
<e
->count
; i
++)
891 eattr
*a
= &e
->attrs
[i
];
892 debug(" %02x:%02x.%02x", EA_PROTO(a
->id
), EA_ID(a
->id
), a
->flags
);
893 if (a
->type
& EAF_TEMP
)
895 debug("=%c", "?iO?I?P???S?????" [a
->type
& EAF_TYPE_MASK
]);
896 if (a
->type
& EAF_ORIGINATED
)
898 if (a
->type
& EAF_EMBEDDED
)
899 debug(":%08x", a
->u
.data
);
902 int j
, len
= a
->u
.ptr
->length
;
905 debug("%02x", a
->u
.ptr
->data
[j
]);
914 * ea_hash - calculate an &ea_list hash key
917 * ea_hash() takes an extended attribute list and calculated a hopefully
918 * uniformly distributed hash value from its contents.
923 const u64 mul
= 0x68576150f3d6847;
924 u64 h
= 0xafcef24eda8b29;
927 if (e
) /* Assuming chain of length 1 */
929 for(i
=0; i
<e
->count
; i
++)
931 struct eattr
*a
= &e
->attrs
[i
];
932 h
^= a
->id
; h
*= mul
;
933 if (a
->type
& EAF_EMBEDDED
)
937 struct adata
*d
= a
->u
.ptr
;
938 h
^= mem_hash(d
->data
, d
->length
);
943 return (h
>> 32) ^ (h
& 0xffffffff);
947 * ea_append - concatenate &ea_list's
948 * @to: destination list (can be %NULL)
949 * @what: list to be appended (can be %NULL)
951 * This function appends the &ea_list @what at the end of
952 * &ea_list @to and returns a pointer to the resulting list.
955 ea_append(ea_list
*to
, ea_list
*what
)
972 static uint rta_cache_count
;
973 static uint rta_cache_size
= 32;
974 static uint rta_cache_limit
;
975 static uint rta_cache_mask
;
976 static rta
**rta_hash_table
;
981 rta_hash_table
= mb_allocz(rta_pool
, sizeof(rta
*) * rta_cache_size
);
982 if (rta_cache_size
< 32768)
983 rta_cache_limit
= rta_cache_size
* 2;
985 rta_cache_limit
= ~0;
986 rta_cache_mask
= rta_cache_size
- 1;
994 #define MIX(f) mem_hash_mix(&h, &(a->f), sizeof(a->f));
1009 return mem_hash_value(&h
) ^ mpnh_hash(a
->nexthops
) ^ ea_hash(a
->eattrs
);
1013 rta_same(rta
*x
, rta
*y
)
1015 return (x
->src
== y
->src
&&
1016 x
->source
== y
->source
&&
1017 x
->scope
== y
->scope
&&
1018 x
->cast
== y
->cast
&&
1019 x
->dest
== y
->dest
&&
1020 x
->flags
== y
->flags
&&
1021 x
->igp_metric
== y
->igp_metric
&&
1022 ipa_equal(x
->gw
, y
->gw
) &&
1023 ipa_equal(x
->from
, y
->from
) &&
1024 x
->iface
== y
->iface
&&
1025 x
->hostentry
== y
->hostentry
&&
1026 mpnh_same(x
->nexthops
, y
->nexthops
) &&
1027 ea_same(x
->eattrs
, y
->eattrs
));
1033 rta
*r
= sl_alloc(rta_slab
);
1035 memcpy(r
, o
, sizeof(rta
));
1037 r
->nexthops
= mpnh_copy(o
->nexthops
);
1038 r
->eattrs
= ea_list_copy(o
->eattrs
);
1045 uint h
= r
->hash_key
& rta_cache_mask
;
1046 r
->next
= rta_hash_table
[h
];
1048 r
->next
->pprev
= &r
->next
;
1049 r
->pprev
= &rta_hash_table
[h
];
1050 rta_hash_table
[h
] = r
;
1056 uint ohs
= rta_cache_size
;
1059 rta
**oht
= rta_hash_table
;
1061 rta_cache_size
= 2*rta_cache_size
;
1062 DBG("Rehashing rta cache from %d to %d entries.\n", ohs
, rta_cache_size
);
1064 for(h
=0; h
<ohs
; h
++)
1065 for(r
=oht
[h
]; r
; r
=n
)
1074 * rta_lookup - look up a &rta in attribute cache
1075 * @o: a un-cached &rta
1077 * rta_lookup() gets an un-cached &rta structure and returns its cached
1078 * counterpart. It starts with examining the attribute cache to see whether
1079 * there exists a matching entry. If such an entry exists, it's returned and
1080 * its use count is incremented, else a new entry is created with use count
1083 * The extended attribute lists attached to the &rta are automatically
1084 * converted to the normalized form.
1092 ASSERT(!(o
->aflags
& RTAF_CACHED
));
1095 if (o
->eattrs
->next
) /* Multiple ea_list's, need to merge them */
1097 ea_list
*ml
= alloca(ea_scan(o
->eattrs
));
1098 ea_merge(o
->eattrs
, ml
);
1105 for(r
=rta_hash_table
[h
& rta_cache_mask
]; r
; r
=r
->next
)
1106 if (r
->hash_key
== h
&& rta_same(r
, o
))
1107 return rta_clone(r
);
1111 r
->aflags
= RTAF_CACHED
;
1112 rt_lock_source(r
->src
);
1113 rt_lock_hostentry(r
->hostentry
);
1116 if (++rta_cache_count
> rta_cache_limit
)
1125 ASSERT(rta_cache_count
&& (a
->aflags
& RTAF_CACHED
));
1127 *a
->pprev
= a
->next
;
1129 a
->next
->pprev
= a
->pprev
;
1130 a
->aflags
= 0; /* Poison the entry */
1131 rt_unlock_hostentry(a
->hostentry
);
1132 rt_unlock_source(a
->src
);
1133 mpnh_free(a
->nexthops
);
1135 sl_free(rta_slab
, a
);
1139 rta_do_cow(rta
*o
, linpool
*lp
)
1141 rta
*r
= lp_alloc(lp
, sizeof(rta
));
1142 memcpy(r
, o
, sizeof(rta
));
1149 * rta_dump - dump route attributes
1150 * @a: attribute structure to dump
1152 * This function takes a &rta and dumps its contents to the debug output.
1157 static char *rts
[] = { "RTS_DUMMY", "RTS_STATIC", "RTS_INHERIT", "RTS_DEVICE",
1158 "RTS_STAT_DEV", "RTS_REDIR", "RTS_RIP",
1159 "RTS_OSPF", "RTS_OSPF_IA", "RTS_OSPF_EXT1",
1160 "RTS_OSPF_EXT2", "RTS_BGP", "RTS_PIPE", "RTS_BABEL" };
1161 static char *rtc
[] = { "", " BC", " MC", " AC" };
1162 static char *rtd
[] = { "", " DEV", " HOLE", " UNREACH", " PROHIBIT" };
1164 debug("p=%s uc=%d %s %s%s%s h=%04x",
1165 a
->src
->proto
->name
, a
->uc
, rts
[a
->source
], ip_scope_text(a
->scope
), rtc
[a
->cast
],
1166 rtd
[a
->dest
], a
->hash_key
);
1167 if (!(a
->aflags
& RTAF_CACHED
))
1169 debug(" <-%I", a
->from
);
1170 if (a
->dest
== RTD_ROUTER
)
1171 debug(" ->%I", a
->gw
);
1172 if (a
->dest
== RTD_DEVICE
|| a
->dest
== RTD_ROUTER
)
1173 debug(" [%s]", a
->iface
? a
->iface
->name
: "???" );
1182 * rta_dump_all - dump attribute cache
1184 * This function dumps the whole contents of route attribute cache
1185 * to the debug output.
1193 debug("Route attribute cache (%d entries, rehash at %d):\n", rta_cache_count
, rta_cache_limit
);
1194 for(h
=0; h
<rta_cache_size
; h
++)
1195 for(a
=rta_hash_table
[h
]; a
; a
=a
->next
)
1205 rta_show(struct cli
*c
, rta
*a
, ea_list
*eal
)
1207 static char *src_names
[] = { "dummy", "static", "inherit", "device", "static-device", "redirect",
1208 "RIP", "OSPF", "OSPF-IA", "OSPF-E1", "OSPF-E2", "BGP", "pipe" };
1209 static char *cast_names
[] = { "unicast", "broadcast", "multicast", "anycast" };
1212 cli_printf(c
, -1008, "\tType: %s %s %s", src_names
[a
->source
], cast_names
[a
->cast
], ip_scope_text(a
->scope
));
1215 for(; eal
; eal
=eal
->next
)
1216 for(i
=0; i
<eal
->count
; i
++)
1217 ea_show(c
, &eal
->attrs
[i
]);
1221 * rta_init - initialize route attribute cache
1223 * This function is called during initialization of the routing
1224 * table module to set up the internals of the attribute cache.
1229 rta_pool
= rp_new(&root_pool
, "Attributes");
1230 rta_slab
= sl_new(rta_pool
, sizeof(rta
));
1231 mpnh_slab
= sl_new(rta_pool
, sizeof(struct mpnh
));
1237 * Documentation for functions declared inline in route.h
1242 * rta_clone - clone route attributes
1243 * @r: a &rta to be cloned
1245 * rta_clone() takes a cached &rta and returns its identical cached
1246 * copy. Currently it works by just returning the original &rta with
1247 * its use count incremented.
1249 static inline rta
*rta_clone(rta
*r
)
1253 * rta_free - free route attributes
1254 * @r: a &rta to be freed
1256 * If you stop using a &rta (for example when deleting a route which uses
1257 * it), you need to call rta_free() to notify the attribute cache the
1258 * attribute is no longer in use and can be freed if you were the last
1259 * user (which rta_free() tests by inspecting the use count).
1261 static inline void rta_free(rta
*r
)