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