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