]>
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. */ |
d7c0a89a QY |
97 | struct external_info *ospf_external_info_new(uint8_t type, |
98 | unsigned short instance) | |
718e3744 | 99 | { |
d62a17ae | 100 | struct external_info *new; |
718e3744 | 101 | |
d62a17ae | 102 | new = (struct external_info *)XCALLOC(MTYPE_OSPF_EXTERNAL_INFO, |
103 | sizeof(struct external_info)); | |
104 | new->type = type; | |
105 | new->instance = instance; | |
718e3744 | 106 | |
d62a17ae | 107 | ospf_reset_route_map_set_values(&new->route_map_set); |
108 | return new; | |
718e3744 | 109 | } |
110 | ||
d62a17ae | 111 | static void ospf_external_info_free(struct external_info *ei) |
718e3744 | 112 | { |
d62a17ae | 113 | XFREE(MTYPE_OSPF_EXTERNAL_INFO, ei); |
718e3744 | 114 | } |
115 | ||
d62a17ae | 116 | void ospf_reset_route_map_set_values(struct route_map_set_values *values) |
718e3744 | 117 | { |
d62a17ae | 118 | values->metric = -1; |
119 | values->metric_type = -1; | |
718e3744 | 120 | } |
121 | ||
d62a17ae | 122 | int ospf_route_map_set_compare(struct route_map_set_values *values1, |
123 | struct route_map_set_values *values2) | |
718e3744 | 124 | { |
d62a17ae | 125 | return values1->metric == values2->metric |
126 | && values1->metric_type == values2->metric_type; | |
718e3744 | 127 | } |
128 | ||
129 | /* Add an External info for AS-external-LSA. */ | |
996c9314 | 130 | struct external_info * |
d7c0a89a | 131 | ospf_external_info_add(struct ospf *ospf, uint8_t type, unsigned short instance, |
996c9314 LB |
132 | struct prefix_ipv4 p, ifindex_t ifindex, |
133 | struct in_addr nexthop, route_tag_t tag) | |
718e3744 | 134 | { |
d62a17ae | 135 | struct external_info *new; |
136 | struct route_node *rn; | |
137 | struct ospf_external *ext; | |
138 | char inetbuf[INET6_BUFSIZ]; | |
139 | ||
de1ac5fd | 140 | ext = ospf_external_lookup(ospf, type, instance); |
d62a17ae | 141 | if (!ext) |
de1ac5fd | 142 | ext = ospf_external_add(ospf, type, instance); |
d62a17ae | 143 | |
144 | rn = route_node_get(EXTERNAL_INFO(ext), (struct prefix *)&p); | |
145 | /* If old info exists, -- discard new one or overwrite with new one? */ | |
146 | if (rn) | |
147 | if (rn->info) { | |
148 | new = rn->info; | |
149 | if ((new->ifindex == ifindex) | |
150 | && (new->nexthop.s_addr == nexthop.s_addr) | |
151 | && (new->tag == tag)) { | |
152 | route_unlock_node(rn); | |
153 | return NULL; /* NULL => no LSA to refresh */ | |
154 | } | |
155 | ||
156 | inet_ntop(AF_INET, (void *)&nexthop.s_addr, inetbuf, | |
157 | INET6_BUFSIZ); | |
158 | zlog_warn( | |
de1ac5fd | 159 | "Redistribute[%s][%d][%u]: %s/%d discarding old info with NH %s.", |
d62a17ae | 160 | ospf_redist_string(type), instance, |
996c9314 LB |
161 | ospf->vrf_id, inet_ntoa(p.prefix), p.prefixlen, |
162 | inetbuf); | |
d62a17ae | 163 | XFREE(MTYPE_OSPF_EXTERNAL_INFO, rn->info); |
164 | rn->info = NULL; | |
165 | } | |
166 | ||
167 | /* Create new External info instance. */ | |
168 | new = ospf_external_info_new(type, instance); | |
169 | new->p = p; | |
170 | new->ifindex = ifindex; | |
171 | new->nexthop = nexthop; | |
172 | new->tag = tag; | |
173 | ||
174 | /* we don't unlock rn from the get() because we're attaching the info */ | |
175 | if (rn) | |
176 | rn->info = new; | |
177 | ||
178 | if (IS_DEBUG_OSPF(lsa, LSA_GENERATE)) { | |
179 | inet_ntop(AF_INET, (void *)&nexthop.s_addr, inetbuf, | |
180 | INET6_BUFSIZ); | |
181 | zlog_debug( | |
de1ac5fd CS |
182 | "Redistribute[%s][%u]: %s/%d external info created, with NH %s", |
183 | ospf_redist_string(type), ospf->vrf_id, | |
184 | inet_ntoa(p.prefix), p.prefixlen, inetbuf); | |
d62a17ae | 185 | } |
186 | return new; | |
718e3744 | 187 | } |
188 | ||
d7c0a89a QY |
189 | void ospf_external_info_delete(struct ospf *ospf, uint8_t type, |
190 | unsigned short instance, struct prefix_ipv4 p) | |
718e3744 | 191 | { |
d62a17ae | 192 | struct route_node *rn; |
193 | struct ospf_external *ext; | |
194 | ||
de1ac5fd | 195 | ext = ospf_external_lookup(ospf, type, instance); |
d62a17ae | 196 | if (!ext) |
197 | return; | |
198 | ||
199 | rn = route_node_lookup(EXTERNAL_INFO(ext), (struct prefix *)&p); | |
200 | if (rn) { | |
201 | ospf_external_info_free(rn->info); | |
202 | rn->info = NULL; | |
203 | route_unlock_node(rn); | |
204 | route_unlock_node(rn); | |
205 | } | |
718e3744 | 206 | } |
207 | ||
d7c0a89a QY |
208 | struct external_info *ospf_external_info_lookup(struct ospf *ospf, uint8_t type, |
209 | unsigned short instance, | |
d62a17ae | 210 | struct prefix_ipv4 *p) |
718e3744 | 211 | { |
d62a17ae | 212 | struct route_node *rn; |
213 | struct ospf_external *ext; | |
214 | ||
de1ac5fd | 215 | ext = ospf_external_lookup(ospf, type, instance); |
d62a17ae | 216 | if (!ext) |
217 | return NULL; | |
218 | ||
219 | rn = route_node_lookup(EXTERNAL_INFO(ext), (struct prefix *)p); | |
220 | if (rn) { | |
221 | route_unlock_node(rn); | |
222 | if (rn->info) | |
223 | return rn->info; | |
224 | } | |
225 | ||
226 | return NULL; | |
718e3744 | 227 | } |
228 | ||
d62a17ae | 229 | struct ospf_lsa *ospf_external_info_find_lsa(struct ospf *ospf, |
230 | struct prefix_ipv4 *p) | |
718e3744 | 231 | { |
d62a17ae | 232 | struct ospf_lsa *lsa; |
233 | struct as_external_lsa *al; | |
234 | struct in_addr mask, id; | |
718e3744 | 235 | |
d62a17ae | 236 | lsa = ospf_lsdb_lookup_by_id(ospf->lsdb, OSPF_AS_EXTERNAL_LSA, |
237 | p->prefix, ospf->router_id); | |
718e3744 | 238 | |
d62a17ae | 239 | if (!lsa) |
240 | return NULL; | |
718e3744 | 241 | |
d62a17ae | 242 | al = (struct as_external_lsa *)lsa->data; |
718e3744 | 243 | |
d62a17ae | 244 | masklen2ip(p->prefixlen, &mask); |
718e3744 | 245 | |
d62a17ae | 246 | if (mask.s_addr != al->mask.s_addr) { |
247 | id.s_addr = p->prefix.s_addr | (~mask.s_addr); | |
248 | lsa = ospf_lsdb_lookup_by_id(ospf->lsdb, OSPF_AS_EXTERNAL_LSA, | |
249 | id, ospf->router_id); | |
250 | if (!lsa) | |
251 | return NULL; | |
252 | } | |
718e3744 | 253 | |
d62a17ae | 254 | return lsa; |
718e3744 | 255 | } |
256 | ||
6b0655a2 | 257 | |
718e3744 | 258 | /* Update ASBR status. */ |
d7c0a89a | 259 | void ospf_asbr_status_update(struct ospf *ospf, uint8_t status) |
718e3744 | 260 | { |
d62a17ae | 261 | zlog_info("ASBR[Status:%d]: Update", status); |
262 | ||
263 | /* ASBR on. */ | |
264 | if (status) { | |
265 | /* Already ASBR. */ | |
266 | if (IS_OSPF_ASBR(ospf)) { | |
267 | zlog_info("ASBR[Status:%d]: Already ASBR", status); | |
268 | return; | |
269 | } | |
270 | SET_FLAG(ospf->flags, OSPF_FLAG_ASBR); | |
271 | } else { | |
272 | /* Already non ASBR. */ | |
273 | if (!IS_OSPF_ASBR(ospf)) { | |
274 | zlog_info("ASBR[Status:%d]: Already non ASBR", status); | |
275 | return; | |
276 | } | |
277 | UNSET_FLAG(ospf->flags, OSPF_FLAG_ASBR); | |
718e3744 | 278 | } |
718e3744 | 279 | |
d62a17ae | 280 | /* Transition from/to status ASBR, schedule timer. */ |
281 | ospf_spf_calculate_schedule(ospf, SPF_FLAG_ASBR_STATUS_CHANGE); | |
282 | ospf_router_lsa_update(ospf); | |
718e3744 | 283 | } |
284 | ||
d7c0a89a QY |
285 | void ospf_redistribute_withdraw(struct ospf *ospf, uint8_t type, |
286 | unsigned short instance) | |
718e3744 | 287 | { |
d62a17ae | 288 | struct route_node *rn; |
289 | struct external_info *ei; | |
290 | struct ospf_external *ext; | |
291 | ||
de1ac5fd | 292 | ext = ospf_external_lookup(ospf, type, instance); |
d62a17ae | 293 | if (!ext) |
294 | return; | |
295 | ||
296 | /* Delete external info for specified type. */ | |
297 | if (EXTERNAL_INFO(ext)) | |
298 | for (rn = route_top(EXTERNAL_INFO(ext)); rn; | |
299 | rn = route_next(rn)) | |
300 | if ((ei = rn->info)) | |
301 | if (ospf_external_info_find_lsa(ospf, &ei->p)) { | |
302 | if (is_prefix_default(&ei->p) | |
303 | && ospf->default_originate | |
304 | != DEFAULT_ORIGINATE_NONE) | |
305 | continue; | |
306 | ospf_external_lsa_flush( | |
307 | ospf, type, &ei->p, | |
308 | ei->ifindex /*, ei->nexthop */); | |
309 | ||
310 | ospf_external_info_free(ei); | |
311 | route_unlock_node(rn); | |
312 | rn->info = NULL; | |
313 | } | |
718e3744 | 314 | } |