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