]> git.proxmox.com Git - mirror_frr.git/blame - ospfd/ospf_asbr.c
Revert "lib: Macroize CLI matcher tracing"
[mirror_frr.git] / ospfd / ospf_asbr.c
CommitLineData
718e3744 1/*
2 * OSPF AS Boundary Router functions.
3 * Copyright (C) 1999, 2000 Kunihiro Ishiguro, Toshiaki Takada
4 *
5 * This file is part of GNU Zebra.
6 *
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
10 * later version.
11 *
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.
16 *
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
20 * 02111-1307, USA.
21 */
22
23#include <zebra.h>
24
25#include "thread.h"
26#include "memory.h"
27#include "linklist.h"
28#include "prefix.h"
29#include "if.h"
30#include "table.h"
31#include "vty.h"
32#include "filter.h"
33#include "log.h"
34
35#include "ospfd/ospfd.h"
36#include "ospfd/ospf_interface.h"
37#include "ospfd/ospf_asbr.h"
38#include "ospfd/ospf_lsa.h"
39#include "ospfd/ospf_lsdb.h"
40#include "ospfd/ospf_neighbor.h"
41#include "ospfd/ospf_spf.h"
42#include "ospfd/ospf_flood.h"
43#include "ospfd/ospf_route.h"
44#include "ospfd/ospf_zebra.h"
45#include "ospfd/ospf_dump.h"
e84cc647 46
6b0655a2 47
718e3744 48/* Remove external route. */
49void
e84cc647 50ospf_external_route_remove (struct ospf *ospf, struct prefix_ipv4 *p)
718e3744 51{
52 struct route_node *rn;
53 struct ospf_route *or;
54
e84cc647 55 rn = route_node_lookup (ospf->old_external_route, (struct prefix *) p);
718e3744 56 if (rn)
57 if ((or = rn->info))
58 {
59 zlog_info ("Route[%s/%d]: external path deleted",
60 inet_ntoa (p->prefix), p->prefixlen);
61
62 /* Remove route from zebra. */
63 if (or->type == OSPF_DESTINATION_NETWORK)
64 ospf_zebra_delete ((struct prefix_ipv4 *) &rn->p, or);
65
66 ospf_route_free (or);
67 rn->info = NULL;
68
69 route_unlock_node (rn);
70 route_unlock_node (rn);
71 return;
72 }
73
74 zlog_info ("Route[%s/%d]: no such external path",
75 inet_ntoa (p->prefix), p->prefixlen);
76}
77
78/* Lookup external route. */
79struct ospf_route *
e84cc647 80ospf_external_route_lookup (struct ospf *ospf,
81 struct prefix_ipv4 *p)
718e3744 82{
83 struct route_node *rn;
84
e84cc647 85 rn = route_node_lookup (ospf->old_external_route, (struct prefix *) p);
718e3744 86 if (rn)
87 {
88 route_unlock_node (rn);
89 if (rn->info)
90 return rn->info;
91 }
92
93 zlog_warn ("Route[%s/%d]: lookup, no such prefix",
94 inet_ntoa (p->prefix), p->prefixlen);
95
96 return NULL;
97}
98
6b0655a2 99
718e3744 100/* Add an External info for AS-external-LSA. */
101struct external_info *
7c8ff89e 102ospf_external_info_new (u_char type, u_short instance)
718e3744 103{
104 struct external_info *new;
105
106 new = (struct external_info *)
393deb9b 107 XCALLOC (MTYPE_OSPF_EXTERNAL_INFO, sizeof (struct external_info));
718e3744 108 new->type = type;
7c8ff89e 109 new->instance = instance;
718e3744 110
111 ospf_reset_route_map_set_values (&new->route_map_set);
112 return new;
113}
114
4dadc291 115static void
718e3744 116ospf_external_info_free (struct external_info *ei)
117{
118 XFREE (MTYPE_OSPF_EXTERNAL_INFO, ei);
119}
120
121void
122ospf_reset_route_map_set_values (struct route_map_set_values *values)
123{
124 values->metric = -1;
125 values->metric_type = -1;
126}
127
128int
129ospf_route_map_set_compare (struct route_map_set_values *values1,
130 struct route_map_set_values *values2)
131{
132 return values1->metric == values2->metric &&
133 values1->metric_type == values2->metric_type;
134}
135
136/* Add an External info for AS-external-LSA. */
137struct external_info *
7c8ff89e 138ospf_external_info_add (u_char type, u_short instance, struct prefix_ipv4 p,
b892f1dd 139 ifindex_t ifindex, struct in_addr nexthop,
dc9ffce8 140 route_tag_t tag)
718e3744 141{
142 struct external_info *new;
143 struct route_node *rn;
7c8ff89e 144 struct ospf_external *ext;
5048fe14 145 char inetbuf[INET6_BUFSIZ];
718e3744 146
7c8ff89e
DS
147 ext = ospf_external_lookup(type, instance);
148 if (!ext)
149 ext = ospf_external_add(type, instance);
718e3744 150
7c8ff89e 151 rn = route_node_get (EXTERNAL_INFO (ext), (struct prefix *) &p);
718e3744 152 /* If old info exists, -- discard new one or overwrite with new one? */
153 if (rn)
154 if (rn->info)
155 {
5048fe14 156 new = rn->info;
157 if ((new->ifindex == ifindex) &&
158 (new->nexthop.s_addr == nexthop.s_addr) && (new->tag == tag))
159 {
160 route_unlock_node(rn);
161 return NULL; /* NULL => no LSA to refresh */
162 }
163
164 inet_ntop(AF_INET, (void *)&nexthop.s_addr, inetbuf, INET6_BUFSIZ);
165 zlog_warn ("Redistribute[%s][%d]: %s/%d discarding old info with NH %s.",
7c8ff89e 166 ospf_redist_string(type), instance,
5048fe14 167 inet_ntoa (p.prefix), p.prefixlen, inetbuf);
168 XFREE (MTYPE_OSPF_EXTERNAL_INFO, rn->info);
169 rn->info = NULL;
718e3744 170 }
171
172 /* Create new External info instance. */
7c8ff89e 173 new = ospf_external_info_new (type, instance);
718e3744 174 new->p = p;
175 new->ifindex = ifindex;
176 new->nexthop = nexthop;
0d9551dc 177 new->tag = tag;
718e3744 178
5048fe14 179 /* we don't unlock rn from the get() because we're attaching the info */
a11e012e
RG
180 if (rn)
181 rn->info = new;
718e3744 182
183 if (IS_DEBUG_OSPF (lsa, LSA_GENERATE))
5048fe14 184 {
185 inet_ntop(AF_INET, (void *)&nexthop.s_addr, inetbuf, INET6_BUFSIZ);
186 zlog_debug ("Redistribute[%s]: %s/%d external info created, with NH %s",
187 ospf_redist_string(type),
188 inet_ntoa (p.prefix), p.prefixlen, inetbuf);
189 }
718e3744 190 return new;
191}
192
193void
7c8ff89e 194ospf_external_info_delete (u_char type, u_short instance, struct prefix_ipv4 p)
718e3744 195{
196 struct route_node *rn;
7c8ff89e 197 struct ospf_external *ext;
718e3744 198
7c8ff89e
DS
199 ext = ospf_external_lookup(type, instance);
200 if (!ext)
201 return;
202
203 rn = route_node_lookup (EXTERNAL_INFO (ext), (struct prefix *) &p);
718e3744 204 if (rn)
205 {
206 ospf_external_info_free (rn->info);
207 rn->info = NULL;
208 route_unlock_node (rn);
209 route_unlock_node (rn);
210 }
211}
212
213struct external_info *
7c8ff89e 214ospf_external_info_lookup (u_char type, u_short instance, struct prefix_ipv4 *p)
718e3744 215{
216 struct route_node *rn;
7c8ff89e
DS
217 struct ospf_external *ext;
218
219 ext = ospf_external_lookup(type, instance);
220 if (!ext)
221 return NULL;
222
223 rn = route_node_lookup (EXTERNAL_INFO (ext), (struct prefix *) p);
718e3744 224 if (rn)
225 {
226 route_unlock_node (rn);
227 if (rn->info)
228 return rn->info;
229 }
230
231 return NULL;
232}
233
234struct ospf_lsa *
e84cc647 235ospf_external_info_find_lsa (struct ospf *ospf,
236 struct prefix_ipv4 *p)
718e3744 237{
238 struct ospf_lsa *lsa;
239 struct as_external_lsa *al;
240 struct in_addr mask, id;
241
e84cc647 242 lsa = ospf_lsdb_lookup_by_id (ospf->lsdb, OSPF_AS_EXTERNAL_LSA,
243 p->prefix, ospf->router_id);
718e3744 244
245 if (!lsa)
246 return NULL;
247
248 al = (struct as_external_lsa *) lsa->data;
249
250 masklen2ip (p->prefixlen, &mask);
251
252 if (mask.s_addr != al->mask.s_addr)
253 {
254 id.s_addr = p->prefix.s_addr | (~mask.s_addr);
e84cc647 255 lsa = ospf_lsdb_lookup_by_id (ospf->lsdb, OSPF_AS_EXTERNAL_LSA,
256 id, ospf->router_id);
718e3744 257 if (!lsa)
258 return NULL;
259 }
260
261 return lsa;
262}
263
6b0655a2 264
718e3744 265/* Update ASBR status. */
266void
e84cc647 267ospf_asbr_status_update (struct ospf *ospf, u_char status)
718e3744 268{
269 zlog_info ("ASBR[Status:%d]: Update", status);
270
271 /* ASBR on. */
272 if (status)
273 {
274 /* Already ASBR. */
e84cc647 275 if (IS_OSPF_ASBR (ospf))
718e3744 276 {
277 zlog_info ("ASBR[Status:%d]: Already ASBR", status);
278 return;
279 }
e84cc647 280 SET_FLAG (ospf->flags, OSPF_FLAG_ASBR);
718e3744 281 }
282 else
283 {
284 /* Already non ASBR. */
e84cc647 285 if (! IS_OSPF_ASBR (ospf))
718e3744 286 {
287 zlog_info ("ASBR[Status:%d]: Already non ASBR", status);
288 return;
289 }
e84cc647 290 UNSET_FLAG (ospf->flags, OSPF_FLAG_ASBR);
718e3744 291 }
292
293 /* Transition from/to status ASBR, schedule timer. */
d3a9c768 294 ospf_spf_calculate_schedule (ospf, SPF_FLAG_ASBR_STATUS_CHANGE);
c363d386 295 ospf_router_lsa_update (ospf);
718e3744 296}
297
298void
7c8ff89e 299ospf_redistribute_withdraw (struct ospf *ospf, u_char type, u_short instance)
718e3744 300{
301 struct route_node *rn;
302 struct external_info *ei;
7c8ff89e
DS
303 struct ospf_external *ext;
304
305 ext = ospf_external_lookup(type, instance);
306 if (!ext)
307 return;
718e3744 308
309 /* Delete external info for specified type. */
7c8ff89e
DS
310 if (EXTERNAL_INFO (ext))
311 for (rn = route_top (EXTERNAL_INFO (ext)); rn; rn = route_next (rn))
718e3744 312 if ((ei = rn->info))
e84cc647 313 if (ospf_external_info_find_lsa (ospf, &ei->p))
718e3744 314 {
315 if (is_prefix_default (&ei->p) &&
e84cc647 316 ospf->default_originate != DEFAULT_ORIGINATE_NONE)
718e3744 317 continue;
5339cfdb 318 ospf_external_lsa_flush (ospf, type, &ei->p,
319 ei->ifindex /*, ei->nexthop */);
fb01f87f
SH
320
321 ospf_external_info_free (ei);
322 route_unlock_node (rn);
323 rn->info = NULL;
718e3744 324 }
325}