]>
git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_lsdb.c
3 * Copyright (C) 1999, 2000 Alex Zinin, Kunihiro Ishiguro, Toshiaki Takada
5 * This file is part of GNU Zebra.
7 * GNU Zebra is free software; you can redistribute it and/or modify it
8 * under the terms of the GNU General Public License as published by the
9 * Free Software Foundation; either version 2, or (at your option) any
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the Free
19 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
29 #include "ospfd/ospfd.h"
30 #include "ospfd/ospf_asbr.h"
31 #include "ospfd/ospf_lsa.h"
32 #include "ospfd/ospf_lsdb.h"
37 struct ospf_lsdb
*new;
39 new = XCALLOC (MTYPE_OSPF_LSDB
, sizeof (struct ospf_lsdb
));
46 ospf_lsdb_init (struct ospf_lsdb
*lsdb
)
50 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
51 lsdb
->type
[i
].db
= route_table_init ();
55 ospf_lsdb_free (struct ospf_lsdb
*lsdb
)
57 ospf_lsdb_cleanup (lsdb
);
58 XFREE (MTYPE_OSPF_LSDB
, lsdb
);
62 ospf_lsdb_cleanup (struct ospf_lsdb
*lsdb
)
66 assert (lsdb
->total
== 0);
68 ospf_lsdb_delete_all (lsdb
);
70 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
71 route_table_finish (lsdb
->type
[i
].db
);
75 lsdb_prefix_set (struct prefix_ls
*lp
, struct ospf_lsa
*lsa
)
77 memset (lp
, 0, sizeof (struct prefix_ls
));
80 lp
->id
= lsa
->data
->id
;
81 lp
->adv_router
= lsa
->data
->adv_router
;
84 /* Add new LSA to lsdb. */
86 ospf_lsdb_add (struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
88 struct route_table
*table
;
90 struct route_node
*rn
;
92 table
= lsdb
->type
[lsa
->data
->type
].db
;
93 lsdb_prefix_set (&lp
, lsa
);
94 rn
= route_node_get (table
, (struct prefix
*)&lp
);
97 if (IS_LSA_SELF (lsa
))
98 lsdb
->type
[lsa
->data
->type
].count_self
++;
99 lsdb
->type
[lsa
->data
->type
].count
++;
107 ospf_lsa_unlock (rn
->info
);
108 route_unlock_node (rn
);
111 #ifdef MONITOR_LSDB_CHANGE
112 if (lsdb
->new_lsa_hook
!= NULL
)
113 (* lsdb
->new_lsa_hook
)(lsa
);
114 #endif /* MONITOR_LSDB_CHANGE */
115 rn
->info
= ospf_lsa_lock (lsa
);
119 ospf_lsdb_delete (struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
121 struct route_table
*table
;
123 struct route_node
*rn
;
125 table
= lsdb
->type
[lsa
->data
->type
].db
;
126 lsdb_prefix_set (&lp
, lsa
);
127 rn
= route_node_lookup (table
, (struct prefix
*) &lp
);
131 if (IS_LSA_SELF (lsa
))
132 lsdb
->type
[lsa
->data
->type
].count_self
--;
133 lsdb
->type
[lsa
->data
->type
].count
--;
136 route_unlock_node (rn
);
137 route_unlock_node (rn
);
138 #ifdef MONITOR_LSDB_CHANGE
139 if (lsdb
->del_lsa_hook
!= NULL
)
140 (* lsdb
->del_lsa_hook
)(lsa
);
141 #endif /* MONITOR_LSDB_CHANGE */
142 ospf_lsa_unlock (lsa
);
148 ospf_lsdb_delete_all (struct ospf_lsdb
*lsdb
)
150 struct route_table
*table
;
151 struct route_node
*rn
;
152 struct ospf_lsa
*lsa
;
155 for (i
= OSPF_MIN_LSA
; i
< OSPF_MAX_LSA
; i
++)
157 table
= lsdb
->type
[i
].db
;
158 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
159 if ((lsa
= (rn
->info
)) != NULL
)
161 if (IS_LSA_SELF (lsa
))
162 lsdb
->type
[i
].count_self
--;
163 lsdb
->type
[i
].count
--;
166 route_unlock_node (rn
);
167 #ifdef MONITOR_LSDB_CHANGE
168 if (lsdb
->del_lsa_hook
!= NULL
)
169 (* lsdb
->del_lsa_hook
)(lsa
);
170 #endif /* MONITOR_LSDB_CHANGE */
171 ospf_lsa_unlock (lsa
);
177 ospf_lsdb_lookup (struct ospf_lsdb
*lsdb
, struct ospf_lsa
*lsa
)
179 struct route_table
*table
;
181 struct route_node
*rn
;
182 struct ospf_lsa
*find
;
184 table
= lsdb
->type
[lsa
->data
->type
].db
;
185 lsdb_prefix_set (&lp
, lsa
);
186 rn
= route_node_lookup (table
, (struct prefix
*) &lp
);
190 route_unlock_node (rn
);
197 ospf_lsdb_lookup_by_id (struct ospf_lsdb
*lsdb
, u_char type
,
198 struct in_addr id
, struct in_addr adv_router
)
200 struct route_table
*table
;
202 struct route_node
*rn
;
203 struct ospf_lsa
*find
;
205 table
= lsdb
->type
[type
].db
;
207 memset (&lp
, 0, sizeof (struct prefix_ls
));
211 lp
.adv_router
= adv_router
;
213 rn
= route_node_lookup (table
, (struct prefix
*) &lp
);
217 route_unlock_node (rn
);
224 ospf_lsdb_lookup_by_id_next (struct ospf_lsdb
*lsdb
, u_char type
,
225 struct in_addr id
, struct in_addr adv_router
,
228 struct route_table
*table
;
230 struct route_node
*rn
;
231 struct ospf_lsa
*find
;
233 table
= lsdb
->type
[type
].db
;
235 memset (&lp
, 0, sizeof (struct prefix_ls
));
239 lp
.adv_router
= adv_router
;
242 rn
= route_top (table
);
245 rn
= route_node_get (table
, (struct prefix
*) &lp
);
246 rn
= route_next (rn
);
249 for (; rn
; rn
= route_next (rn
))
256 route_unlock_node (rn
);
263 ospf_lsdb_count_all (struct ospf_lsdb
*lsdb
)
269 ospf_lsdb_count (struct ospf_lsdb
*lsdb
, int type
)
271 return lsdb
->type
[type
].count
;
275 ospf_lsdb_count_self (struct ospf_lsdb
*lsdb
, int type
)
277 return lsdb
->type
[type
].count_self
;
281 ospf_lsdb_isempty (struct ospf_lsdb
*lsdb
)
283 return (lsdb
->total
== 0);
287 foreach_lsa (struct route_table
*table
, void *p_arg
, int int_arg
,
288 int (*callback
) (struct ospf_lsa
*, void *, int))
290 struct route_node
*rn
;
291 struct ospf_lsa
*lsa
;
293 for (rn
= route_top (table
); rn
; rn
= route_next (rn
))
294 if ((lsa
= rn
->info
) != NULL
)
295 if (callback (lsa
, p_arg
, int_arg
))