blob: 025a77104b289675880c78ea727a0a5284a563ef [file] [log] [blame]
paul718e3742002-12-13 20:15:29 +00001/*
hasso508e53e2004-05-18 18:57:06 +00002 * Copyright (C) 2003 Yasuhiro Ohara
paul718e3742002-12-13 20:15:29 +00003 *
4 * This file is part of GNU Zebra.
5 *
6 * GNU Zebra is free software; you can redistribute it and/or modify it
7 * under the terms of the GNU General Public License as published by the
8 * Free Software Foundation; either version 2, or (at your option) any
9 * later version.
10 *
11 * GNU Zebra is distributed in the hope that it will be useful, but
12 * WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 * General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
hasso508e53e2004-05-18 18:57:06 +000022#include <zebra.h>
23
24#include "log.h"
25#include "linklist.h"
26#include "thread.h"
27#include "memory.h"
28#include "if.h"
29#include "prefix.h"
30#include "table.h"
31#include "vty.h"
32#include "command.h"
33
hasso508e53e2004-05-18 18:57:06 +000034#include "ospf6_proto.h"
35#include "ospf6_message.h"
36#include "ospf6_route.h"
37#include "ospf6_lsa.h"
38#include "ospf6_lsdb.h"
paul718e3742002-12-13 20:15:29 +000039
hasso508e53e2004-05-18 18:57:06 +000040#include "ospf6_top.h"
41#include "ospf6_area.h"
42#include "ospf6_interface.h"
43#include "ospf6_neighbor.h"
44#include "ospf6_intra.h"
45#include "ospf6_asbr.h"
hasso6452df02004-08-15 05:52:07 +000046#include "ospf6_abr.h"
47#include "ospf6_flood.h"
hasso049207c2004-08-04 20:02:13 +000048#include "ospf6d.h"
paul718e3742002-12-13 20:15:29 +000049
Paul Jakmacb4b8842006-05-15 10:39:30 +000050
51unsigned char conf_debug_ospf6_brouter = 0;
52u_int32_t conf_debug_ospf6_brouter_specific_router_id;
53u_int32_t conf_debug_ospf6_brouter_specific_area_id;
54
hasso508e53e2004-05-18 18:57:06 +000055/******************************/
56/* RFC2740 3.4.3.1 Router-LSA */
57/******************************/
paul718e3742002-12-13 20:15:29 +000058
Paul Jakma6ac29a52008-08-15 13:45:30 +010059static int
hasso508e53e2004-05-18 18:57:06 +000060ospf6_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +000061{
hasso508e53e2004-05-18 18:57:06 +000062 char *start, *end, *current;
63 char buf[32], name[32], bits[16], options[32];
64 struct ospf6_router_lsa *router_lsa;
65 struct ospf6_router_lsdesc *lsdesc;
paul718e3742002-12-13 20:15:29 +000066
hasso508e53e2004-05-18 18:57:06 +000067 router_lsa = (struct ospf6_router_lsa *)
68 ((char *) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +000069
hasso508e53e2004-05-18 18:57:06 +000070 ospf6_capability_printbuf (router_lsa->bits, bits, sizeof (bits));
71 ospf6_options_printbuf (router_lsa->options, options, sizeof (options));
hasso049207c2004-08-04 20:02:13 +000072 vty_out (vty, " Bits: %s Options: %s%s", bits, options, VNL);
paul718e3742002-12-13 20:15:29 +000073
hasso508e53e2004-05-18 18:57:06 +000074 start = (char *) router_lsa + sizeof (struct ospf6_router_lsa);
paul718e3742002-12-13 20:15:29 +000075 end = (char *) lsa->header + ntohs (lsa->header->length);
hasso508e53e2004-05-18 18:57:06 +000076 for (current = start; current + sizeof (struct ospf6_router_lsdesc) <= end;
77 current += sizeof (struct ospf6_router_lsdesc))
paul718e3742002-12-13 20:15:29 +000078 {
hasso508e53e2004-05-18 18:57:06 +000079 lsdesc = (struct ospf6_router_lsdesc *) current;
paul718e3742002-12-13 20:15:29 +000080
hasso508e53e2004-05-18 18:57:06 +000081 if (lsdesc->type == OSPF6_ROUTER_LSDESC_POINTTOPOINT)
82 snprintf (name, sizeof (name), "Point-To-Point");
83 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK)
84 snprintf (name, sizeof (name), "Transit-Network");
85 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_STUB_NETWORK)
86 snprintf (name, sizeof (name), "Stub-Network");
87 else if (lsdesc->type == OSPF6_ROUTER_LSDESC_VIRTUAL_LINK)
88 snprintf (name, sizeof (name), "Virtual-Link");
paul718e3742002-12-13 20:15:29 +000089 else
hasso508e53e2004-05-18 18:57:06 +000090 snprintf (name, sizeof (name), "Unknown (%#x)", lsdesc->type);
paul718e3742002-12-13 20:15:29 +000091
hasso508e53e2004-05-18 18:57:06 +000092 vty_out (vty, " Type: %s Metric: %d%s",
hasso049207c2004-08-04 20:02:13 +000093 name, ntohs (lsdesc->metric), VNL);
hasso508e53e2004-05-18 18:57:06 +000094 vty_out (vty, " Interface ID: %s%s",
95 inet_ntop (AF_INET, &lsdesc->interface_id,
hasso049207c2004-08-04 20:02:13 +000096 buf, sizeof (buf)), VNL);
hasso508e53e2004-05-18 18:57:06 +000097 vty_out (vty, " Neighbor Interface ID: %s%s",
98 inet_ntop (AF_INET, &lsdesc->neighbor_interface_id,
hasso049207c2004-08-04 20:02:13 +000099 buf, sizeof (buf)), VNL);
hasso508e53e2004-05-18 18:57:06 +0000100 vty_out (vty, " Neighbor Router ID: %s%s",
101 inet_ntop (AF_INET, &lsdesc->neighbor_router_id,
hasso049207c2004-08-04 20:02:13 +0000102 buf, sizeof (buf)), VNL);
paul718e3742002-12-13 20:15:29 +0000103 }
104 return 0;
105}
106
hasso6452df02004-08-15 05:52:07 +0000107int
Dinesh Duttf41b4a02013-08-24 08:00:37 +0000108ospf6_router_is_stub_router (struct ospf6_lsa *lsa)
109{
110 struct ospf6_router_lsa *rtr_lsa;
111
112 if (lsa != NULL && OSPF6_LSA_IS_TYPE (ROUTER, lsa))
113 {
114 rtr_lsa = (struct ospf6_router_lsa *)
115 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
116
117 if (!OSPF6_OPT_ISSET (rtr_lsa->options, OSPF6_OPT_R))
118 {
119 return (OSPF6_IS_STUB_ROUTER);
120 }
121 else if (!OSPF6_OPT_ISSET (rtr_lsa->options, OSPF6_OPT_V6))
122 {
123 return (OSPF6_IS_STUB_ROUTER_V6);
124 }
125 }
126
127 return (OSPF6_NOT_STUB_ROUTER);
128}
129
130int
hasso6452df02004-08-15 05:52:07 +0000131ospf6_router_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000132{
hasso6452df02004-08-15 05:52:07 +0000133 struct ospf6_area *oa;
134
hasso508e53e2004-05-18 18:57:06 +0000135 char buffer [OSPF6_MAX_LSASIZE];
136 struct ospf6_lsa_header *lsa_header;
137 struct ospf6_lsa *lsa;
paul718e3742002-12-13 20:15:29 +0000138
hasso508e53e2004-05-18 18:57:06 +0000139 u_int32_t link_state_id = 0;
paul1eb8ef22005-04-07 07:30:20 +0000140 struct listnode *node, *nnode;
141 struct listnode *j;
hasso508e53e2004-05-18 18:57:06 +0000142 struct ospf6_interface *oi;
143 struct ospf6_neighbor *on, *drouter = NULL;
144 struct ospf6_router_lsa *router_lsa;
145 struct ospf6_router_lsdesc *lsdesc;
146 u_int16_t type;
147 u_int32_t router;
148 int count;
paul718e3742002-12-13 20:15:29 +0000149
hasso6452df02004-08-15 05:52:07 +0000150 oa = (struct ospf6_area *) THREAD_ARG (thread);
151 oa->thread_router_lsa = NULL;
152
hasso1e058382004-09-01 21:36:14 +0000153 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
hassoc6487d62004-12-24 06:00:11 +0000154 zlog_debug ("Originate Router-LSA for Area %s", oa->name);
paul718e3742002-12-13 20:15:29 +0000155
hasso508e53e2004-05-18 18:57:06 +0000156 memset (buffer, 0, sizeof (buffer));
157 lsa_header = (struct ospf6_lsa_header *) buffer;
158 router_lsa = (struct ospf6_router_lsa *)
159 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
160
161 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_V6);
162 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_E);
163 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_MC);
164 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_N);
165 OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_R);
166 OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_DC);
167
hasso6452df02004-08-15 05:52:07 +0000168 if (ospf6_is_router_abr (ospf6))
169 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
170 else
171 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B);
hasso508e53e2004-05-18 18:57:06 +0000172 if (ospf6_asbr_is_asbr (ospf6))
173 SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
174 else
175 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E);
176 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_V);
177 UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_W);
178
179 /* describe links for each interfaces */
180 lsdesc = (struct ospf6_router_lsdesc *)
181 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
182
paul1eb8ef22005-04-07 07:30:20 +0000183 for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi))
paul718e3742002-12-13 20:15:29 +0000184 {
hasso508e53e2004-05-18 18:57:06 +0000185 /* Interfaces in state Down or Loopback are not described */
186 if (oi->state == OSPF6_INTERFACE_DOWN ||
187 oi->state == OSPF6_INTERFACE_LOOPBACK)
paul718e3742002-12-13 20:15:29 +0000188 continue;
189
hasso508e53e2004-05-18 18:57:06 +0000190 /* Nor are interfaces without any full adjacencies described */
191 count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000192 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
193 if (on->state == OSPF6_NEIGHBOR_FULL)
194 count++;
195
hasso508e53e2004-05-18 18:57:06 +0000196 if (count == 0)
197 continue;
198
199 /* Multiple Router-LSA instance according to size limit setting */
paul0c083ee2004-10-10 12:54:58 +0000200 if ( (oa->router_lsa_size_limit != 0)
201 && ((caddr_t) lsdesc + sizeof (struct ospf6_router_lsdesc) -
gdt1686f932004-12-09 14:47:09 +0000202 /* XXX warning: comparison between signed and unsigned */
paul0c083ee2004-10-10 12:54:58 +0000203 (caddr_t) buffer > oa->router_lsa_size_limit))
hasso508e53e2004-05-18 18:57:06 +0000204 {
205 if ((caddr_t) lsdesc == (caddr_t) router_lsa +
206 sizeof (struct ospf6_router_lsa))
207 {
hasso1e058382004-09-01 21:36:14 +0000208 if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER))
hassoc6487d62004-12-24 06:00:11 +0000209 zlog_debug ("Size limit setting for Router-LSA too short");
hasso6452df02004-08-15 05:52:07 +0000210 return 0;
hasso508e53e2004-05-18 18:57:06 +0000211 }
212
213 /* Fill LSA Header */
214 lsa_header->age = 0;
215 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
216 lsa_header->id = htonl (link_state_id);
217 lsa_header->adv_router = oa->ospf6->router_id;
218 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000219 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
220 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000221 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
222
223 /* LSA checksum */
224 ospf6_lsa_checksum (lsa_header);
225
226 /* create LSA */
227 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000228
229 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000230 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000231
232 /* Reset setting for consecutive origination */
233 memset ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa),
234 0, (caddr_t) lsdesc - (caddr_t) router_lsa);
235 lsdesc = (struct ospf6_router_lsdesc *)
236 ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa));
237 link_state_id ++;
paul718e3742002-12-13 20:15:29 +0000238 }
239
hasso508e53e2004-05-18 18:57:06 +0000240 /* Point-to-Point interfaces */
Dinesh Duttc5926a92013-08-24 07:55:00 +0000241 if (oi->type == OSPF_IFTYPE_POINTOPOINT)
hasso508e53e2004-05-18 18:57:06 +0000242 {
paul1eb8ef22005-04-07 07:30:20 +0000243 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
hasso508e53e2004-05-18 18:57:06 +0000244 {
hasso508e53e2004-05-18 18:57:06 +0000245 if (on->state != OSPF6_NEIGHBOR_FULL)
246 continue;
paul718e3742002-12-13 20:15:29 +0000247
hasso508e53e2004-05-18 18:57:06 +0000248 lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT;
249 lsdesc->metric = htons (oi->cost);
250 lsdesc->interface_id = htonl (oi->interface->ifindex);
251 lsdesc->neighbor_interface_id = htonl (on->ifindex);
252 lsdesc->neighbor_router_id = on->router_id;
253
254 lsdesc++;
255 }
256 }
257
258 /* Broadcast and NBMA interfaces */
Dinesh Duttc5926a92013-08-24 07:55:00 +0000259 else if (oi->type == OSPF_IFTYPE_BROADCAST)
hasso508e53e2004-05-18 18:57:06 +0000260 {
261 /* If this router is not DR,
262 and If this router not fully adjacent with DR,
263 this interface is not transit yet: ignore. */
264 if (oi->state != OSPF6_INTERFACE_DR)
265 {
266 drouter = ospf6_neighbor_lookup (oi->drouter, oi);
267 if (drouter == NULL || drouter->state != OSPF6_NEIGHBOR_FULL)
268 continue;
269 }
270
271 lsdesc->type = OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK;
272 lsdesc->metric = htons (oi->cost);
273 lsdesc->interface_id = htonl (oi->interface->ifindex);
274 if (oi->state != OSPF6_INTERFACE_DR)
275 {
276 lsdesc->neighbor_interface_id = htonl (drouter->ifindex);
277 lsdesc->neighbor_router_id = drouter->router_id;
278 }
279 else
280 {
281 lsdesc->neighbor_interface_id = htonl (oi->interface->ifindex);
282 lsdesc->neighbor_router_id = oi->area->ospf6->router_id;
283 }
284
285 lsdesc++;
286 }
Dinesh Duttc5926a92013-08-24 07:55:00 +0000287 else
288 {
289 assert (0); /* Unknown interface type */
290 }
hasso508e53e2004-05-18 18:57:06 +0000291
292 /* Virtual links */
293 /* xxx */
294 /* Point-to-Multipoint interfaces */
295 /* xxx */
paul718e3742002-12-13 20:15:29 +0000296 }
hasso508e53e2004-05-18 18:57:06 +0000297
Dinesh Dutt17d003d2013-08-24 07:55:43 +0000298 /* Fill LSA Header */
299 lsa_header->age = 0;
300 lsa_header->type = htons (OSPF6_LSTYPE_ROUTER);
301 lsa_header->id = htonl (link_state_id);
302 lsa_header->adv_router = oa->ospf6->router_id;
303 lsa_header->seqnum =
304 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
305 lsa_header->adv_router, oa->lsdb);
306 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
hasso508e53e2004-05-18 18:57:06 +0000307
Dinesh Dutt17d003d2013-08-24 07:55:43 +0000308 /* LSA checksum */
309 ospf6_lsa_checksum (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000310
Dinesh Dutt17d003d2013-08-24 07:55:43 +0000311 /* create LSA */
312 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000313
Dinesh Dutt17d003d2013-08-24 07:55:43 +0000314 /* Originate */
315 ospf6_lsa_originate_area (lsa, oa);
hasso508e53e2004-05-18 18:57:06 +0000316
Dinesh Dutt17d003d2013-08-24 07:55:43 +0000317 link_state_id ++;
hasso508e53e2004-05-18 18:57:06 +0000318
319 /* Do premature-aging of rest, undesired Router-LSAs */
320 type = ntohs (OSPF6_LSTYPE_ROUTER);
321 router = oa->ospf6->router_id;
322 for (lsa = ospf6_lsdb_type_router_head (type, router, oa->lsdb); lsa;
323 lsa = ospf6_lsdb_type_router_next (type, router, lsa))
324 {
325 if (ntohl (lsa->header->id) < link_state_id)
326 continue;
hasso6452df02004-08-15 05:52:07 +0000327 ospf6_lsa_purge (lsa);
hasso508e53e2004-05-18 18:57:06 +0000328 }
hasso508e53e2004-05-18 18:57:06 +0000329
330 return 0;
331}
332
hasso508e53e2004-05-18 18:57:06 +0000333/*******************************/
334/* RFC2740 3.4.3.2 Network-LSA */
335/*******************************/
336
Paul Jakma6ac29a52008-08-15 13:45:30 +0100337static int
hasso508e53e2004-05-18 18:57:06 +0000338ospf6_network_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
339{
340 char *start, *end, *current;
341 struct ospf6_network_lsa *network_lsa;
342 struct ospf6_network_lsdesc *lsdesc;
343 char buf[128], options[32];
344
345 network_lsa = (struct ospf6_network_lsa *)
346 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
347
348 ospf6_options_printbuf (network_lsa->options, options, sizeof (options));
hasso049207c2004-08-04 20:02:13 +0000349 vty_out (vty, " Options: %s%s", options, VNL);
hasso508e53e2004-05-18 18:57:06 +0000350
351 start = (char *) network_lsa + sizeof (struct ospf6_network_lsa);
352 end = (char *) lsa->header + ntohs (lsa->header->length);
353 for (current = start; current + sizeof (struct ospf6_network_lsdesc) <= end;
354 current += sizeof (struct ospf6_network_lsdesc))
355 {
356 lsdesc = (struct ospf6_network_lsdesc *) current;
357 inet_ntop (AF_INET, &lsdesc->router_id, buf, sizeof (buf));
hasso049207c2004-08-04 20:02:13 +0000358 vty_out (vty, " Attached Router: %s%s", buf, VNL);
hasso508e53e2004-05-18 18:57:06 +0000359 }
360 return 0;
paul718e3742002-12-13 20:15:29 +0000361}
362
hasso6452df02004-08-15 05:52:07 +0000363int
364ospf6_network_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000365{
hasso6452df02004-08-15 05:52:07 +0000366 struct ospf6_interface *oi;
367
hasso508e53e2004-05-18 18:57:06 +0000368 char buffer [OSPF6_MAX_LSASIZE];
369 struct ospf6_lsa_header *lsa_header;
paul718e3742002-12-13 20:15:29 +0000370
hasso508e53e2004-05-18 18:57:06 +0000371 int count;
372 struct ospf6_lsa *old, *lsa;
373 struct ospf6_network_lsa *network_lsa;
374 struct ospf6_network_lsdesc *lsdesc;
375 struct ospf6_neighbor *on;
376 struct ospf6_link_lsa *link_lsa;
hasso52dc7ee2004-09-23 19:18:23 +0000377 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000378 u_int16_t type;
379
hasso6452df02004-08-15 05:52:07 +0000380 oi = (struct ospf6_interface *) THREAD_ARG (thread);
381 oi->thread_network_lsa = NULL;
382
383 /* The interface must be enabled until here. A Network-LSA of a
384 disabled interface (but was once enabled) should be flushed
385 by ospf6_lsa_refresh (), and does not come here. */
386 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000387
hasso508e53e2004-05-18 18:57:06 +0000388 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK),
389 htonl (oi->interface->ifindex),
390 oi->area->ospf6->router_id, oi->area->lsdb);
paul718e3742002-12-13 20:15:29 +0000391
hasso508e53e2004-05-18 18:57:06 +0000392 /* Do not originate Network-LSA if not DR */
393 if (oi->state != OSPF6_INTERFACE_DR)
paul718e3742002-12-13 20:15:29 +0000394 {
hasso508e53e2004-05-18 18:57:06 +0000395 if (old)
hasso6452df02004-08-15 05:52:07 +0000396 ospf6_lsa_purge (old);
397 return 0;
paul718e3742002-12-13 20:15:29 +0000398 }
hasso508e53e2004-05-18 18:57:06 +0000399
hasso1e058382004-09-01 21:36:14 +0000400 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
hassoc6487d62004-12-24 06:00:11 +0000401 zlog_debug ("Originate Network-LSA for Interface %s", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000402
403 /* If none of neighbor is adjacent to us */
404 count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000405
406 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
407 if (on->state == OSPF6_NEIGHBOR_FULL)
408 count++;
409
hasso508e53e2004-05-18 18:57:06 +0000410 if (count == 0)
411 {
hasso1e058382004-09-01 21:36:14 +0000412 if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK))
hassoc6487d62004-12-24 06:00:11 +0000413 zlog_debug ("Interface stub, ignore");
hasso508e53e2004-05-18 18:57:06 +0000414 if (old)
hasso6452df02004-08-15 05:52:07 +0000415 ospf6_lsa_purge (old);
416 return 0;
hasso508e53e2004-05-18 18:57:06 +0000417 }
418
419 /* prepare buffer */
420 memset (buffer, 0, sizeof (buffer));
421 lsa_header = (struct ospf6_lsa_header *) buffer;
422 network_lsa = (struct ospf6_network_lsa *)
423 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
424
425 /* Collect the interface's Link-LSAs to describe
426 network's optional capabilities */
427 type = htons (OSPF6_LSTYPE_LINK);
428 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
429 lsa = ospf6_lsdb_type_next (type, lsa))
430 {
431 link_lsa = (struct ospf6_link_lsa *)
432 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
433 network_lsa->options[0] |= link_lsa->options[0];
434 network_lsa->options[1] |= link_lsa->options[1];
435 network_lsa->options[2] |= link_lsa->options[2];
436 }
437
438 lsdesc = (struct ospf6_network_lsdesc *)
439 ((caddr_t) network_lsa + sizeof (struct ospf6_network_lsa));
440
441 /* set Link Description to the router itself */
442 lsdesc->router_id = oi->area->ospf6->router_id;
443 lsdesc++;
444
445 /* Walk through the neighbors */
paul1eb8ef22005-04-07 07:30:20 +0000446 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
hasso508e53e2004-05-18 18:57:06 +0000447 {
hasso508e53e2004-05-18 18:57:06 +0000448 if (on->state != OSPF6_NEIGHBOR_FULL)
449 continue;
450
451 /* set this neighbor's Router-ID to LSA */
452 lsdesc->router_id = on->router_id;
453 lsdesc++;
454 }
455
456 /* Fill LSA Header */
457 lsa_header->age = 0;
458 lsa_header->type = htons (OSPF6_LSTYPE_NETWORK);
459 lsa_header->id = htonl (oi->interface->ifindex);
460 lsa_header->adv_router = oi->area->ospf6->router_id;
461 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000462 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
463 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000464 lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer);
465
466 /* LSA checksum */
467 ospf6_lsa_checksum (lsa_header);
468
469 /* create LSA */
470 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000471
472 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000473 ospf6_lsa_originate_area (lsa, oi->area);
hasso508e53e2004-05-18 18:57:06 +0000474
475 return 0;
476}
477
478
479/****************************/
480/* RFC2740 3.4.3.6 Link-LSA */
481/****************************/
482
Paul Jakma6ac29a52008-08-15 13:45:30 +0100483static int
hasso508e53e2004-05-18 18:57:06 +0000484ospf6_link_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
485{
paul718e3742002-12-13 20:15:29 +0000486 char *start, *end, *current;
hasso508e53e2004-05-18 18:57:06 +0000487 struct ospf6_link_lsa *link_lsa;
488 int prefixnum;
489 char buf[128], options[32];
490 struct ospf6_prefix *prefix;
paul0c083ee2004-10-10 12:54:58 +0000491 const char *p, *mc, *la, *nu;
hasso508e53e2004-05-18 18:57:06 +0000492 struct in6_addr in6;
paul718e3742002-12-13 20:15:29 +0000493
hasso508e53e2004-05-18 18:57:06 +0000494 link_lsa = (struct ospf6_link_lsa *)
495 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000496
hasso508e53e2004-05-18 18:57:06 +0000497 ospf6_options_printbuf (link_lsa->options, options, sizeof (options));
498 inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf));
499 prefixnum = ntohl (link_lsa->prefix_num);
paul718e3742002-12-13 20:15:29 +0000500
hasso508e53e2004-05-18 18:57:06 +0000501 vty_out (vty, " Priority: %d Options: %s%s",
hasso049207c2004-08-04 20:02:13 +0000502 link_lsa->priority, options, VNL);
503 vty_out (vty, " LinkLocal Address: %s%s", buf, VNL);
504 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
paul718e3742002-12-13 20:15:29 +0000505
hasso508e53e2004-05-18 18:57:06 +0000506 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
507 end = (char *) lsa->header + ntohs (lsa->header->length);
paul718e3742002-12-13 20:15:29 +0000508 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
509 {
510 prefix = (struct ospf6_prefix *) current;
hasso508e53e2004-05-18 18:57:06 +0000511 if (prefix->prefix_length == 0 ||
512 current + OSPF6_PREFIX_SIZE (prefix) > end)
513 break;
paul718e3742002-12-13 20:15:29 +0000514
hasso508e53e2004-05-18 18:57:06 +0000515 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
516 "P" : "--");
517 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
518 "MC" : "--");
519 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
520 "LA" : "--");
521 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
522 "NU" : "--");
523 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000524 p, mc, la, nu, VNL);
paul718e3742002-12-13 20:15:29 +0000525
hasso508e53e2004-05-18 18:57:06 +0000526 memset (&in6, 0, sizeof (in6));
527 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
528 OSPF6_PREFIX_SPACE (prefix->prefix_length));
paul718e3742002-12-13 20:15:29 +0000529 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
530 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000531 buf, prefix->prefix_length, VNL);
paul718e3742002-12-13 20:15:29 +0000532 }
533
534 return 0;
535}
536
hasso6452df02004-08-15 05:52:07 +0000537int
538ospf6_link_lsa_originate (struct thread *thread)
paul718e3742002-12-13 20:15:29 +0000539{
hasso6452df02004-08-15 05:52:07 +0000540 struct ospf6_interface *oi;
541
hasso508e53e2004-05-18 18:57:06 +0000542 char buffer[OSPF6_MAX_LSASIZE];
543 struct ospf6_lsa_header *lsa_header;
544 struct ospf6_lsa *old, *lsa;
paul718e3742002-12-13 20:15:29 +0000545
hasso508e53e2004-05-18 18:57:06 +0000546 struct ospf6_link_lsa *link_lsa;
547 struct ospf6_route *route;
548 struct ospf6_prefix *op;
paul718e3742002-12-13 20:15:29 +0000549
hasso6452df02004-08-15 05:52:07 +0000550 oi = (struct ospf6_interface *) THREAD_ARG (thread);
551 oi->thread_link_lsa = NULL;
552
553 assert (oi->area);
paul718e3742002-12-13 20:15:29 +0000554
555 /* find previous LSA */
hasso508e53e2004-05-18 18:57:06 +0000556 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK),
557 htonl (oi->interface->ifindex),
558 oi->area->ospf6->router_id, oi->lsdb);
paul718e3742002-12-13 20:15:29 +0000559
hasso508e53e2004-05-18 18:57:06 +0000560 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
paul718e3742002-12-13 20:15:29 +0000561 {
562 if (old)
hasso6452df02004-08-15 05:52:07 +0000563 ospf6_lsa_purge (old);
564 return 0;
paul718e3742002-12-13 20:15:29 +0000565 }
566
hasso1e058382004-09-01 21:36:14 +0000567 if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
hassoc6487d62004-12-24 06:00:11 +0000568 zlog_debug ("Originate Link-LSA for Interface %s", oi->interface->name);
paul718e3742002-12-13 20:15:29 +0000569
hasso508e53e2004-05-18 18:57:06 +0000570 /* can't make Link-LSA if linklocal address not set */
571 if (oi->linklocal_addr == NULL)
paul718e3742002-12-13 20:15:29 +0000572 {
hasso1e058382004-09-01 21:36:14 +0000573 if (IS_OSPF6_DEBUG_ORIGINATE (LINK))
hassoc6487d62004-12-24 06:00:11 +0000574 zlog_debug ("No Linklocal address on %s, defer originating",
hasso508e53e2004-05-18 18:57:06 +0000575 oi->interface->name);
576 if (old)
hasso6452df02004-08-15 05:52:07 +0000577 ospf6_lsa_purge (old);
578 return 0;
hasso508e53e2004-05-18 18:57:06 +0000579 }
580
581 /* prepare buffer */
582 memset (buffer, 0, sizeof (buffer));
583 lsa_header = (struct ospf6_lsa_header *) buffer;
584 link_lsa = (struct ospf6_link_lsa *)
585 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
586
587 /* Fill Link-LSA */
588 link_lsa->priority = oi->priority;
589 memcpy (link_lsa->options, oi->area->options, 3);
590 memcpy (&link_lsa->linklocal_addr, oi->linklocal_addr,
591 sizeof (struct in6_addr));
592 link_lsa->prefix_num = htonl (oi->route_connected->count);
593
594 op = (struct ospf6_prefix *)
595 ((caddr_t) link_lsa + sizeof (struct ospf6_link_lsa));
596
597 /* connected prefix to advertise */
598 for (route = ospf6_route_head (oi->route_connected); route;
599 route = ospf6_route_next (route))
600 {
601 op->prefix_length = route->prefix.prefixlen;
602 op->prefix_options = route->path.prefix_options;
603 op->prefix_metric = htons (0);
604 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
605 OSPF6_PREFIX_SPACE (op->prefix_length));
606 op = OSPF6_PREFIX_NEXT (op);
607 }
608
609 /* Fill LSA Header */
610 lsa_header->age = 0;
611 lsa_header->type = htons (OSPF6_LSTYPE_LINK);
612 lsa_header->id = htonl (oi->interface->ifindex);
613 lsa_header->adv_router = oi->area->ospf6->router_id;
614 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000615 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
616 lsa_header->adv_router, oi->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000617 lsa_header->length = htons ((caddr_t) op - (caddr_t) buffer);
618
619 /* LSA checksum */
620 ospf6_lsa_checksum (lsa_header);
621
622 /* create LSA */
623 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000624
625 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000626 ospf6_lsa_originate_interface (lsa, oi);
hasso508e53e2004-05-18 18:57:06 +0000627
628 return 0;
629}
630
631
632/*****************************************/
633/* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
634/*****************************************/
635
Paul Jakma6ac29a52008-08-15 13:45:30 +0100636static int
hasso508e53e2004-05-18 18:57:06 +0000637ospf6_intra_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa)
638{
639 char *start, *end, *current;
640 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
641 int prefixnum;
642 char buf[128];
643 struct ospf6_prefix *prefix;
644 char id[16], adv_router[16];
paul0c083ee2004-10-10 12:54:58 +0000645 const char *p, *mc, *la, *nu;
hasso508e53e2004-05-18 18:57:06 +0000646 struct in6_addr in6;
647
648 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
649 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
650
651 prefixnum = ntohs (intra_prefix_lsa->prefix_num);
652
hasso049207c2004-08-04 20:02:13 +0000653 vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL);
hasso508e53e2004-05-18 18:57:06 +0000654
655 inet_ntop (AF_INET, &intra_prefix_lsa->ref_id, id, sizeof (id));
656 inet_ntop (AF_INET, &intra_prefix_lsa->ref_adv_router,
657 adv_router, sizeof (adv_router));
658 vty_out (vty, " Reference: %s Id: %s Adv: %s%s",
hasso1e058382004-09-01 21:36:14 +0000659 ospf6_lstype_name (intra_prefix_lsa->ref_type), id, adv_router,
hasso049207c2004-08-04 20:02:13 +0000660 VNL);
hasso508e53e2004-05-18 18:57:06 +0000661
662 start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa);
663 end = (char *) lsa->header + ntohs (lsa->header->length);
664 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix))
665 {
666 prefix = (struct ospf6_prefix *) current;
667 if (prefix->prefix_length == 0 ||
668 current + OSPF6_PREFIX_SIZE (prefix) > end)
669 break;
670
671 p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ?
672 "P" : "--");
673 mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ?
674 "MC" : "--");
675 la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ?
676 "LA" : "--");
677 nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ?
678 "NU" : "--");
679 vty_out (vty, " Prefix Options: %s|%s|%s|%s%s",
hasso049207c2004-08-04 20:02:13 +0000680 p, mc, la, nu, VNL);
hasso508e53e2004-05-18 18:57:06 +0000681
682 memset (&in6, 0, sizeof (in6));
683 memcpy (&in6, OSPF6_PREFIX_BODY (prefix),
684 OSPF6_PREFIX_SPACE (prefix->prefix_length));
685 inet_ntop (AF_INET6, &in6, buf, sizeof (buf));
686 vty_out (vty, " Prefix: %s/%d%s",
hasso049207c2004-08-04 20:02:13 +0000687 buf, prefix->prefix_length, VNL);
hasso508e53e2004-05-18 18:57:06 +0000688 }
689
690 return 0;
691}
692
hasso6452df02004-08-15 05:52:07 +0000693int
694ospf6_intra_prefix_lsa_originate_stub (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000695{
hasso6452df02004-08-15 05:52:07 +0000696 struct ospf6_area *oa;
697
hasso508e53e2004-05-18 18:57:06 +0000698 char buffer[OSPF6_MAX_LSASIZE];
699 struct ospf6_lsa_header *lsa_header;
700 struct ospf6_lsa *old, *lsa;
701
702 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
703 struct ospf6_interface *oi;
704 struct ospf6_neighbor *on;
705 struct ospf6_route *route;
706 struct ospf6_prefix *op;
hasso52dc7ee2004-09-23 19:18:23 +0000707 struct listnode *i, *j;
hasso508e53e2004-05-18 18:57:06 +0000708 int full_count = 0;
709 unsigned short prefix_num = 0;
710 char buf[BUFSIZ];
711 struct ospf6_route_table *route_advertise;
712
hasso6452df02004-08-15 05:52:07 +0000713 oa = (struct ospf6_area *) THREAD_ARG (thread);
714 oa->thread_intra_prefix_lsa = NULL;
715
hasso508e53e2004-05-18 18:57:06 +0000716 /* find previous LSA */
717 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
718 htonl (0), oa->ospf6->router_id, oa->lsdb);
719
hasso6452df02004-08-15 05:52:07 +0000720 if (! IS_AREA_ENABLED (oa))
hasso508e53e2004-05-18 18:57:06 +0000721 {
722 if (old)
hasso6452df02004-08-15 05:52:07 +0000723 ospf6_lsa_purge (old);
724 return 0;
hasso508e53e2004-05-18 18:57:06 +0000725 }
726
hasso1e058382004-09-01 21:36:14 +0000727 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000728 zlog_debug ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
hasso508e53e2004-05-18 18:57:06 +0000729 oa->name);
730
731 /* prepare buffer */
732 memset (buffer, 0, sizeof (buffer));
733 lsa_header = (struct ospf6_lsa_header *) buffer;
734 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
735 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
736
737 /* Fill Intra-Area-Prefix-LSA */
738 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_ROUTER);
739 intra_prefix_lsa->ref_id = htonl (0);
740 intra_prefix_lsa->ref_adv_router = oa->ospf6->router_id;
741
Paul Jakmacf1ce252006-05-15 10:46:07 +0000742 route_advertise = ospf6_route_table_create (0, 0);
hasso508e53e2004-05-18 18:57:06 +0000743
paul1eb8ef22005-04-07 07:30:20 +0000744 for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi))
hasso508e53e2004-05-18 18:57:06 +0000745 {
hasso508e53e2004-05-18 18:57:06 +0000746 if (oi->state == OSPF6_INTERFACE_DOWN)
747 {
hasso1e058382004-09-01 21:36:14 +0000748 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000749 zlog_debug (" Interface %s is down, ignore", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000750 continue;
751 }
752
753 full_count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000754
755 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on))
756 if (on->state == OSPF6_NEIGHBOR_FULL)
757 full_count++;
758
hasso508e53e2004-05-18 18:57:06 +0000759 if (oi->state != OSPF6_INTERFACE_LOOPBACK &&
760 oi->state != OSPF6_INTERFACE_POINTTOPOINT &&
761 full_count != 0)
762 {
hasso1e058382004-09-01 21:36:14 +0000763 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000764 zlog_debug (" Interface %s is not stub, ignore",
hasso508e53e2004-05-18 18:57:06 +0000765 oi->interface->name);
766 continue;
767 }
768
hasso1e058382004-09-01 21:36:14 +0000769 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000770 zlog_debug (" Interface %s:", oi->interface->name);
hasso508e53e2004-05-18 18:57:06 +0000771
772 /* connected prefix to advertise */
773 for (route = ospf6_route_head (oi->route_connected); route;
774 route = ospf6_route_best_next (route))
775 {
hasso1e058382004-09-01 21:36:14 +0000776 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +0000777 {
778 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000779 zlog_debug (" include %s", buf);
hasso508e53e2004-05-18 18:57:06 +0000780 }
781 ospf6_route_add (ospf6_route_copy (route), route_advertise);
782 }
783 }
784
785 if (route_advertise->count == 0)
786 {
787 if (old)
hasso6452df02004-08-15 05:52:07 +0000788 ospf6_lsa_purge (old);
hasso508e53e2004-05-18 18:57:06 +0000789 ospf6_route_table_delete (route_advertise);
hasso6452df02004-08-15 05:52:07 +0000790 return 0;
hasso508e53e2004-05-18 18:57:06 +0000791 }
792
793 /* put prefixes to advertise */
794 prefix_num = 0;
795 op = (struct ospf6_prefix *)
796 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
797 for (route = ospf6_route_head (route_advertise); route;
798 route = ospf6_route_best_next (route))
799 {
800 op->prefix_length = route->prefix.prefixlen;
801 op->prefix_options = route->path.prefix_options;
802 op->prefix_metric = htons (route->path.cost);
803 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
804 OSPF6_PREFIX_SPACE (op->prefix_length));
805 op = OSPF6_PREFIX_NEXT (op);
806 prefix_num++;
807 }
808
809 ospf6_route_table_delete (route_advertise);
810
811 if (prefix_num == 0)
812 {
hasso1e058382004-09-01 21:36:14 +0000813 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000814 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +0000815 return 0;
hasso508e53e2004-05-18 18:57:06 +0000816 }
817
818 intra_prefix_lsa->prefix_num = htons (prefix_num);
819
820 /* Fill LSA Header */
821 lsa_header->age = 0;
822 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
823 lsa_header->id = htonl (0);
824 lsa_header->adv_router = oa->ospf6->router_id;
825 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +0000826 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
827 lsa_header->adv_router, oa->lsdb);
hasso508e53e2004-05-18 18:57:06 +0000828 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
829
830 /* LSA checksum */
831 ospf6_lsa_checksum (lsa_header);
832
833 /* create LSA */
834 lsa = ospf6_lsa_create (lsa_header);
hasso508e53e2004-05-18 18:57:06 +0000835
836 /* Originate */
hasso6452df02004-08-15 05:52:07 +0000837 ospf6_lsa_originate_area (lsa, oa);
838
839 return 0;
hasso508e53e2004-05-18 18:57:06 +0000840}
841
hasso6452df02004-08-15 05:52:07 +0000842
843int
844ospf6_intra_prefix_lsa_originate_transit (struct thread *thread)
hasso508e53e2004-05-18 18:57:06 +0000845{
hasso6452df02004-08-15 05:52:07 +0000846 struct ospf6_interface *oi;
847
hasso508e53e2004-05-18 18:57:06 +0000848 char buffer[OSPF6_MAX_LSASIZE];
849 struct ospf6_lsa_header *lsa_header;
850 struct ospf6_lsa *old, *lsa;
851
852 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
853 struct ospf6_neighbor *on;
854 struct ospf6_route *route;
855 struct ospf6_prefix *op;
hasso52dc7ee2004-09-23 19:18:23 +0000856 struct listnode *i;
hasso508e53e2004-05-18 18:57:06 +0000857 int full_count = 0;
858 unsigned short prefix_num = 0;
859 struct ospf6_route_table *route_advertise;
860 struct ospf6_link_lsa *link_lsa;
861 char *start, *end, *current;
862 u_int16_t type;
863 char buf[BUFSIZ];
864
hasso6452df02004-08-15 05:52:07 +0000865 oi = (struct ospf6_interface *) THREAD_ARG (thread);
866 oi->thread_intra_prefix_lsa = NULL;
867
868 assert (oi->area);
hasso508e53e2004-05-18 18:57:06 +0000869
870 /* find previous LSA */
871 old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX),
872 htonl (oi->interface->ifindex),
873 oi->area->ospf6->router_id, oi->area->lsdb);
874
875 if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE))
876 {
877 if (old)
hasso6452df02004-08-15 05:52:07 +0000878 ospf6_lsa_purge (old);
879 return 0;
hasso508e53e2004-05-18 18:57:06 +0000880 }
881
hasso1e058382004-09-01 21:36:14 +0000882 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000883 zlog_debug ("Originate Intra-Area-Prefix-LSA for interface %s's prefix",
hasso508e53e2004-05-18 18:57:06 +0000884 oi->interface->name);
885
886 /* prepare buffer */
887 memset (buffer, 0, sizeof (buffer));
888 lsa_header = (struct ospf6_lsa_header *) buffer;
889 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
890 ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header));
891
892 /* Fill Intra-Area-Prefix-LSA */
893 intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_NETWORK);
894 intra_prefix_lsa->ref_id = htonl (oi->interface->ifindex);
895 intra_prefix_lsa->ref_adv_router = oi->area->ospf6->router_id;
896
897 if (oi->state != OSPF6_INTERFACE_DR)
898 {
hasso1e058382004-09-01 21:36:14 +0000899 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000900 zlog_debug (" Interface is not DR");
hasso508e53e2004-05-18 18:57:06 +0000901 if (old)
hasso6452df02004-08-15 05:52:07 +0000902 ospf6_lsa_purge (old);
903 return 0;
hasso508e53e2004-05-18 18:57:06 +0000904 }
905
906 full_count = 0;
paul1eb8ef22005-04-07 07:30:20 +0000907 for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on))
908 if (on->state == OSPF6_NEIGHBOR_FULL)
909 full_count++;
910
hasso508e53e2004-05-18 18:57:06 +0000911 if (full_count == 0)
912 {
hasso1e058382004-09-01 21:36:14 +0000913 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000914 zlog_debug (" Interface is stub");
hasso508e53e2004-05-18 18:57:06 +0000915 if (old)
hasso6452df02004-08-15 05:52:07 +0000916 ospf6_lsa_purge (old);
917 return 0;
hasso508e53e2004-05-18 18:57:06 +0000918 }
919
920 /* connected prefix to advertise */
Paul Jakmacf1ce252006-05-15 10:46:07 +0000921 route_advertise = ospf6_route_table_create (0, 0);
hasso508e53e2004-05-18 18:57:06 +0000922
923 type = ntohs (OSPF6_LSTYPE_LINK);
924 for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa;
925 lsa = ospf6_lsdb_type_next (type, lsa))
926 {
927 if (OSPF6_LSA_IS_MAXAGE (lsa))
paul718e3742002-12-13 20:15:29 +0000928 continue;
929
hasso1e058382004-09-01 21:36:14 +0000930 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000931 zlog_debug (" include prefix from %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000932
hasso508e53e2004-05-18 18:57:06 +0000933 if (lsa->header->adv_router != oi->area->ospf6->router_id)
paul718e3742002-12-13 20:15:29 +0000934 {
hasso508e53e2004-05-18 18:57:06 +0000935 on = ospf6_neighbor_lookup (lsa->header->adv_router, oi);
936 if (on == NULL || on->state != OSPF6_NEIGHBOR_FULL)
paul718e3742002-12-13 20:15:29 +0000937 {
hasso1e058382004-09-01 21:36:14 +0000938 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000939 zlog_debug (" Neighbor not found or not Full, ignore");
paul718e3742002-12-13 20:15:29 +0000940 continue;
941 }
942 }
943
hasso508e53e2004-05-18 18:57:06 +0000944 link_lsa = (struct ospf6_link_lsa *)
945 ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header));
paul718e3742002-12-13 20:15:29 +0000946
hasso508e53e2004-05-18 18:57:06 +0000947 prefix_num = (unsigned short) ntohl (link_lsa->prefix_num);
948 start = (char *) link_lsa + sizeof (struct ospf6_link_lsa);
949 end = (char *) lsa->header + ntohs (lsa->header->length);
950 for (current = start; current < end && prefix_num;
951 current += OSPF6_PREFIX_SIZE (op))
paul718e3742002-12-13 20:15:29 +0000952 {
hasso508e53e2004-05-18 18:57:06 +0000953 op = (struct ospf6_prefix *) current;
954 if (op->prefix_length == 0 ||
955 current + OSPF6_PREFIX_SIZE (op) > end)
956 break;
paul718e3742002-12-13 20:15:29 +0000957
hasso508e53e2004-05-18 18:57:06 +0000958 route = ospf6_route_create ();
959
960 route->type = OSPF6_DEST_TYPE_NETWORK;
961 route->prefix.family = AF_INET6;
962 route->prefix.prefixlen = op->prefix_length;
963 memset (&route->prefix.u.prefix6, 0, sizeof (struct in6_addr));
964 memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op),
965 OSPF6_PREFIX_SPACE (op->prefix_length));
966
967 route->path.origin.type = lsa->header->type;
968 route->path.origin.id = lsa->header->id;
969 route->path.origin.adv_router = lsa->header->adv_router;
970 route->path.options[0] = link_lsa->options[0];
971 route->path.options[1] = link_lsa->options[1];
972 route->path.options[2] = link_lsa->options[2];
973 route->path.prefix_options = op->prefix_options;
974 route->path.area_id = oi->area->area_id;
975 route->path.type = OSPF6_PATH_TYPE_INTRA;
976
hasso1e058382004-09-01 21:36:14 +0000977 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
paul718e3742002-12-13 20:15:29 +0000978 {
hasso508e53e2004-05-18 18:57:06 +0000979 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +0000980 zlog_debug (" include %s", buf);
paul718e3742002-12-13 20:15:29 +0000981 }
982
hasso508e53e2004-05-18 18:57:06 +0000983 ospf6_route_add (route, route_advertise);
984 prefix_num--;
paul718e3742002-12-13 20:15:29 +0000985 }
hasso1e058382004-09-01 21:36:14 +0000986 if (current != end && IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +0000987 zlog_debug ("Trailing garbage in %s", lsa->name);
paul718e3742002-12-13 20:15:29 +0000988 }
989
hasso508e53e2004-05-18 18:57:06 +0000990 op = (struct ospf6_prefix *)
991 ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa));
992
993 prefix_num = 0;
994 for (route = ospf6_route_head (route_advertise); route;
995 route = ospf6_route_best_next (route))
paul718e3742002-12-13 20:15:29 +0000996 {
hasso508e53e2004-05-18 18:57:06 +0000997 op->prefix_length = route->prefix.prefixlen;
998 op->prefix_options = route->path.prefix_options;
999 op->prefix_metric = htons (0);
1000 memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6,
1001 OSPF6_PREFIX_SPACE (op->prefix_length));
1002 op = OSPF6_PREFIX_NEXT (op);
1003 prefix_num++;
1004 }
1005
1006 ospf6_route_table_delete (route_advertise);
1007
1008 if (prefix_num == 0)
1009 {
hasso1e058382004-09-01 21:36:14 +00001010 if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001011 zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise");
hasso6452df02004-08-15 05:52:07 +00001012 return 0;
paul718e3742002-12-13 20:15:29 +00001013 }
1014
hasso508e53e2004-05-18 18:57:06 +00001015 intra_prefix_lsa->prefix_num = htons (prefix_num);
paul718e3742002-12-13 20:15:29 +00001016
hasso508e53e2004-05-18 18:57:06 +00001017 /* Fill LSA Header */
1018 lsa_header->age = 0;
1019 lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
1020 lsa_header->id = htonl (oi->interface->ifindex);
1021 lsa_header->adv_router = oi->area->ospf6->router_id;
1022 lsa_header->seqnum =
hasso049207c2004-08-04 20:02:13 +00001023 ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id,
1024 lsa_header->adv_router, oi->area->lsdb);
hasso508e53e2004-05-18 18:57:06 +00001025 lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header);
paul718e3742002-12-13 20:15:29 +00001026
hasso508e53e2004-05-18 18:57:06 +00001027 /* LSA checksum */
1028 ospf6_lsa_checksum (lsa_header);
paul718e3742002-12-13 20:15:29 +00001029
hasso508e53e2004-05-18 18:57:06 +00001030 /* create LSA */
1031 lsa = ospf6_lsa_create (lsa_header);
paul718e3742002-12-13 20:15:29 +00001032
hasso508e53e2004-05-18 18:57:06 +00001033 /* Originate */
hasso6452df02004-08-15 05:52:07 +00001034 ospf6_lsa_originate_area (lsa, oi->area);
paul718e3742002-12-13 20:15:29 +00001035
1036 return 0;
1037}
1038
1039void
hasso508e53e2004-05-18 18:57:06 +00001040ospf6_intra_prefix_lsa_add (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001041{
hasso508e53e2004-05-18 18:57:06 +00001042 struct ospf6_area *oa;
1043 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1044 struct prefix ls_prefix;
1045 struct ospf6_route *route, *ls_entry;
1046 int i, prefix_num;
1047 struct ospf6_prefix *op;
1048 char *start, *current, *end;
1049 char buf[64];
Dinesh Duttb81e97a2013-08-24 07:55:50 +00001050 struct interface *ifp;
1051 int direct_connect = 0;
paul718e3742002-12-13 20:15:29 +00001052
hassoccb59b12004-08-25 09:10:37 +00001053 if (OSPF6_LSA_IS_MAXAGE (lsa))
1054 return;
1055
hasso1e058382004-09-01 21:36:14 +00001056 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001057 zlog_debug ("%s found", lsa->name);
paul718e3742002-12-13 20:15:29 +00001058
hasso6452df02004-08-15 05:52:07 +00001059 oa = OSPF6_AREA (lsa->lsdb->data);
1060
hasso508e53e2004-05-18 18:57:06 +00001061 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1062 OSPF6_LSA_HEADER_END (lsa->header);
1063 if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_ROUTER))
1064 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1065 htonl (0), &ls_prefix);
1066 else if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_NETWORK))
1067 ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router,
1068 intra_prefix_lsa->ref_id, &ls_prefix);
1069 else
1070 {
hasso1e058382004-09-01 21:36:14 +00001071 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001072 zlog_debug ("Unknown reference LS-type: %#hx",
1073 ntohs (intra_prefix_lsa->ref_type));
hasso508e53e2004-05-18 18:57:06 +00001074 return;
1075 }
paul718e3742002-12-13 20:15:29 +00001076
hasso508e53e2004-05-18 18:57:06 +00001077 ls_entry = ospf6_route_lookup (&ls_prefix, oa->spf_table);
1078 if (ls_entry == NULL)
1079 {
hasso1e058382004-09-01 21:36:14 +00001080 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001081 {
1082 ospf6_linkstate_prefix2str (&ls_prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001083 zlog_debug ("LS entry does not exist: %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001084 }
1085 return;
1086 }
paul718e3742002-12-13 20:15:29 +00001087
Dinesh Duttb81e97a2013-08-24 07:55:50 +00001088 if (intra_prefix_lsa->ref_adv_router == oa->ospf6->router_id)
1089 {
1090 /* the intra-prefix are directly connected */
1091 direct_connect = 1;
1092 }
1093
hasso508e53e2004-05-18 18:57:06 +00001094 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1095 start = (caddr_t) intra_prefix_lsa +
1096 sizeof (struct ospf6_intra_prefix_lsa);
1097 end = OSPF6_LSA_END (lsa->header);
1098 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1099 {
1100 op = (struct ospf6_prefix *) current;
1101 if (prefix_num == 0)
1102 break;
1103 if (end < current + OSPF6_PREFIX_SIZE (op))
1104 break;
1105
1106 route = ospf6_route_create ();
hassoccb59b12004-08-25 09:10:37 +00001107
1108 memset (&route->prefix, 0, sizeof (struct prefix));
hasso508e53e2004-05-18 18:57:06 +00001109 route->prefix.family = AF_INET6;
hassoccb59b12004-08-25 09:10:37 +00001110 route->prefix.prefixlen = op->prefix_length;
1111 ospf6_prefix_in6_addr (&route->prefix.u.prefix6, op);
1112
hasso508e53e2004-05-18 18:57:06 +00001113 route->type = OSPF6_DEST_TYPE_NETWORK;
1114 route->path.origin.type = lsa->header->type;
1115 route->path.origin.id = lsa->header->id;
1116 route->path.origin.adv_router = lsa->header->adv_router;
1117 route->path.prefix_options = op->prefix_options;
1118 route->path.area_id = oa->area_id;
1119 route->path.type = OSPF6_PATH_TYPE_INTRA;
1120 route->path.metric_type = 1;
1121 route->path.cost = ls_entry->path.cost +
1122 ntohs (op->prefix_metric);
1123
Dinesh Duttb81e97a2013-08-24 07:55:50 +00001124 if (direct_connect)
1125 {
1126 ifp = if_lookup_prefix(&route->prefix);
1127 if (ifp)
1128 route->nexthop[0].ifindex = ifp->ifindex;
1129 }
1130 else
1131 {
1132 for (i = 0; ospf6_nexthop_is_set (&ls_entry->nexthop[i]) &&
1133 i < OSPF6_MULTI_PATH_LIMIT; i++)
1134 ospf6_nexthop_copy (&route->nexthop[i], &ls_entry->nexthop[i]);
1135 }
hasso508e53e2004-05-18 18:57:06 +00001136
hasso1e058382004-09-01 21:36:14 +00001137 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001138 {
1139 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001140 zlog_debug (" add %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001141 }
1142
1143 ospf6_route_add (route, oa->route_table);
1144 prefix_num--;
1145 }
1146
hasso1e058382004-09-01 21:36:14 +00001147 if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001148 zlog_debug ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001149}
1150
1151void
hasso508e53e2004-05-18 18:57:06 +00001152ospf6_intra_prefix_lsa_remove (struct ospf6_lsa *lsa)
paul718e3742002-12-13 20:15:29 +00001153{
hasso508e53e2004-05-18 18:57:06 +00001154 struct ospf6_area *oa;
1155 struct ospf6_intra_prefix_lsa *intra_prefix_lsa;
1156 struct prefix prefix;
1157 struct ospf6_route *route;
1158 int prefix_num;
1159 struct ospf6_prefix *op;
1160 char *start, *current, *end;
1161 char buf[64];
1162
hasso1e058382004-09-01 21:36:14 +00001163 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001164 zlog_debug ("%s disappearing", lsa->name);
hasso508e53e2004-05-18 18:57:06 +00001165
hasso6452df02004-08-15 05:52:07 +00001166 oa = OSPF6_AREA (lsa->lsdb->data);
1167
hasso508e53e2004-05-18 18:57:06 +00001168 intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *)
1169 OSPF6_LSA_HEADER_END (lsa->header);
1170
1171 prefix_num = ntohs (intra_prefix_lsa->prefix_num);
1172 start = (caddr_t) intra_prefix_lsa +
1173 sizeof (struct ospf6_intra_prefix_lsa);
1174 end = OSPF6_LSA_END (lsa->header);
1175 for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op))
1176 {
1177 op = (struct ospf6_prefix *) current;
1178 if (prefix_num == 0)
1179 break;
1180 if (end < current + OSPF6_PREFIX_SIZE (op))
1181 break;
1182 prefix_num--;
1183
hassoccb59b12004-08-25 09:10:37 +00001184 memset (&prefix, 0, sizeof (struct prefix));
hasso508e53e2004-05-18 18:57:06 +00001185 prefix.family = AF_INET6;
1186 prefix.prefixlen = op->prefix_length;
1187 ospf6_prefix_in6_addr (&prefix.u.prefix6, op);
1188
1189 route = ospf6_route_lookup (&prefix, oa->route_table);
1190 if (route == NULL)
1191 continue;
1192
1193 for (ospf6_route_lock (route);
1194 route && ospf6_route_is_prefix (&prefix, route);
1195 route = ospf6_route_next (route))
1196 {
1197 if (route->type != OSPF6_DEST_TYPE_NETWORK)
1198 continue;
1199 if (route->path.area_id != oa->area_id)
1200 continue;
1201 if (route->path.type != OSPF6_PATH_TYPE_INTRA)
1202 continue;
1203 if (route->path.origin.type != lsa->header->type ||
1204 route->path.origin.id != lsa->header->id ||
1205 route->path.origin.adv_router != lsa->header->adv_router)
1206 continue;
1207
hasso1e058382004-09-01 21:36:14 +00001208 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hasso508e53e2004-05-18 18:57:06 +00001209 {
1210 prefix2str (&route->prefix, buf, sizeof (buf));
hassoc6487d62004-12-24 06:00:11 +00001211 zlog_debug ("remove %s", buf);
hasso508e53e2004-05-18 18:57:06 +00001212 }
1213 ospf6_route_remove (route, oa->route_table);
1214 }
Tom Goffe7a6d802010-11-10 13:03:02 -08001215 if (route)
1216 ospf6_route_unlock (route);
hasso508e53e2004-05-18 18:57:06 +00001217 }
1218
hasso1e058382004-09-01 21:36:14 +00001219 if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001220 zlog_debug ("Trailing garbage ignored");
paul718e3742002-12-13 20:15:29 +00001221}
1222
1223void
hasso508e53e2004-05-18 18:57:06 +00001224ospf6_intra_route_calculation (struct ospf6_area *oa)
paul718e3742002-12-13 20:15:29 +00001225{
hasso508e53e2004-05-18 18:57:06 +00001226 struct ospf6_route *route;
1227 u_int16_t type;
1228 struct ospf6_lsa *lsa;
1229 void (*hook_add) (struct ospf6_route *) = NULL;
1230 void (*hook_remove) (struct ospf6_route *) = NULL;
1231
hasso1e058382004-09-01 21:36:14 +00001232 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001233 zlog_debug ("Re-examin intra-routes for area %s", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001234
1235 hook_add = oa->route_table->hook_add;
1236 hook_remove = oa->route_table->hook_remove;
1237 oa->route_table->hook_add = NULL;
1238 oa->route_table->hook_remove = NULL;
1239
1240 for (route = ospf6_route_head (oa->route_table); route;
1241 route = ospf6_route_next (route))
1242 route->flag = OSPF6_ROUTE_REMOVE;
1243
1244 type = htons (OSPF6_LSTYPE_INTRA_PREFIX);
1245 for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa;
1246 lsa = ospf6_lsdb_type_next (type, lsa))
1247 ospf6_intra_prefix_lsa_add (lsa);
1248
1249 oa->route_table->hook_add = hook_add;
1250 oa->route_table->hook_remove = hook_remove;
1251
1252 for (route = ospf6_route_head (oa->route_table); route;
1253 route = ospf6_route_next (route))
1254 {
1255 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) &&
1256 CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD))
1257 {
1258 UNSET_FLAG (route->flag, OSPF6_ROUTE_REMOVE);
1259 UNSET_FLAG (route->flag, OSPF6_ROUTE_ADD);
1260 }
1261
1262 if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE))
1263 ospf6_route_remove (route, oa->route_table);
1264 else if (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) ||
1265 CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE))
1266 {
1267 if (hook_add)
1268 (*hook_add) (route);
1269 }
1270
1271 route->flag = 0;
1272 }
1273
hasso1e058382004-09-01 21:36:14 +00001274 if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX))
hassoc6487d62004-12-24 06:00:11 +00001275 zlog_debug ("Re-examin intra-routes for area %s: Done", oa->name);
hasso508e53e2004-05-18 18:57:06 +00001276}
1277
Paul Jakma6ac29a52008-08-15 13:45:30 +01001278static void
Paul Jakmacf1ce252006-05-15 10:46:07 +00001279ospf6_brouter_debug_print (struct ospf6_route *brouter)
1280{
1281 u_int32_t brouter_id;
1282 char brouter_name[16];
1283 char area_name[16];
1284 char destination[64];
1285 char installed[16], changed[16];
1286 struct timeval now, res;
1287 char id[16], adv_router[16];
1288 char capa[16], options[16];
1289
1290 brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
1291 inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
1292 inet_ntop (AF_INET, &brouter->path.area_id, area_name, sizeof (area_name));
1293 ospf6_linkstate_prefix2str (&brouter->prefix, destination,
1294 sizeof (destination));
1295
Takashi Sogabe86f72dc2009-06-22 13:07:02 +09001296 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
Paul Jakmacf1ce252006-05-15 10:46:07 +00001297 timersub (&now, &brouter->installed, &res);
1298 timerstring (&res, installed, sizeof (installed));
1299
Takashi Sogabe86f72dc2009-06-22 13:07:02 +09001300 quagga_gettime (QUAGGA_CLK_MONOTONIC, &now);
Paul Jakmacf1ce252006-05-15 10:46:07 +00001301 timersub (&now, &brouter->changed, &res);
1302 timerstring (&res, changed, sizeof (changed));
1303
1304 inet_ntop (AF_INET, &brouter->path.origin.id, id, sizeof (id));
1305 inet_ntop (AF_INET, &brouter->path.origin.adv_router, adv_router,
1306 sizeof (adv_router));
1307
1308 ospf6_options_printbuf (brouter->path.options, options, sizeof (options));
1309 ospf6_capability_printbuf (brouter->path.router_bits, capa, sizeof (capa));
1310
1311 zlog_info ("Brouter: %s via area %s", brouter_name, area_name);
1312 zlog_info (" memory: prev: %p this: %p next: %p parent rnode: %p",
1313 brouter->prev, brouter, brouter->next, brouter->rnode);
1314 zlog_info (" type: %d prefix: %s installed: %s changed: %s",
1315 brouter->type, destination, installed, changed);
1316 zlog_info (" lock: %d flags: %s%s%s%s", brouter->lock,
1317 (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_BEST) ? "B" : "-"),
1318 (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD) ? "A" : "-"),
1319 (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE) ? "R" : "-"),
1320 (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_CHANGE) ? "C" : "-"));
1321 zlog_info (" path type: %s ls-origin %s id: %s adv-router %s",
1322 OSPF6_PATH_TYPE_NAME (brouter->path.type),
1323 ospf6_lstype_name (brouter->path.origin.type),
1324 id, adv_router);
1325 zlog_info (" options: %s router-bits: %s metric-type: %d metric: %d/%d",
1326 options, capa, brouter->path.metric_type,
1327 brouter->path.cost, brouter->path.cost_e2);
1328}
1329
1330void
hasso6452df02004-08-15 05:52:07 +00001331ospf6_intra_brouter_calculation (struct ospf6_area *oa)
hasso508e53e2004-05-18 18:57:06 +00001332{
Paul Jakmacb4b8842006-05-15 10:39:30 +00001333 struct ospf6_route *brouter, *copy;
hasso508e53e2004-05-18 18:57:06 +00001334 void (*hook_add) (struct ospf6_route *) = NULL;
1335 void (*hook_remove) (struct ospf6_route *) = NULL;
Paul Jakmacb4b8842006-05-15 10:39:30 +00001336 u_int32_t brouter_id;
1337 char brouter_name[16];
1338
1339 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
1340 zlog_info ("border-router calculation for area %s", oa->name);
1341
hasso6452df02004-08-15 05:52:07 +00001342 hook_add = oa->ospf6->brouter_table->hook_add;
1343 hook_remove = oa->ospf6->brouter_table->hook_remove;
1344 oa->ospf6->brouter_table->hook_add = NULL;
1345 oa->ospf6->brouter_table->hook_remove = NULL;
hasso508e53e2004-05-18 18:57:06 +00001346
hasso6452df02004-08-15 05:52:07 +00001347 /* withdraw the previous router entries for the area */
Paul Jakmacb4b8842006-05-15 10:39:30 +00001348 for (brouter = ospf6_route_head (oa->ospf6->brouter_table); brouter;
1349 brouter = ospf6_route_next (brouter))
hasso508e53e2004-05-18 18:57:06 +00001350 {
Paul Jakmacf1ce252006-05-15 10:46:07 +00001351 brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
1352 inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
Paul Jakmacb4b8842006-05-15 10:39:30 +00001353 if (brouter->path.area_id != oa->area_id)
hasso508e53e2004-05-18 18:57:06 +00001354 continue;
Paul Jakmacb4b8842006-05-15 10:39:30 +00001355 brouter->flag = OSPF6_ROUTE_REMOVE;
Paul Jakmacf1ce252006-05-15 10:46:07 +00001356
1357 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
1358 IS_OSPF6_DEBUG_ROUTE (MEMORY))
1359 {
1360 zlog_info ("%p: mark as removing: area %s brouter %s",
1361 brouter, oa->name, brouter_name);
1362 ospf6_brouter_debug_print (brouter);
1363 }
hasso508e53e2004-05-18 18:57:06 +00001364 }
1365
Paul Jakmacb4b8842006-05-15 10:39:30 +00001366 for (brouter = ospf6_route_head (oa->spf_table); brouter;
1367 brouter = ospf6_route_next (brouter))
hasso508e53e2004-05-18 18:57:06 +00001368 {
Paul Jakmacf1ce252006-05-15 10:46:07 +00001369 brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
1370 inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
1371
Paul Jakmacb4b8842006-05-15 10:39:30 +00001372 if (brouter->type != OSPF6_DEST_TYPE_LINKSTATE)
hasso508e53e2004-05-18 18:57:06 +00001373 continue;
Paul Jakmacb4b8842006-05-15 10:39:30 +00001374 if (ospf6_linkstate_prefix_id (&brouter->prefix) != htonl (0))
hasso508e53e2004-05-18 18:57:06 +00001375 continue;
Paul Jakmacb4b8842006-05-15 10:39:30 +00001376 if (! CHECK_FLAG (brouter->path.router_bits, OSPF6_ROUTER_BIT_E) &&
1377 ! CHECK_FLAG (brouter->path.router_bits, OSPF6_ROUTER_BIT_B))
hasso508e53e2004-05-18 18:57:06 +00001378 continue;
1379
Paul Jakmacb4b8842006-05-15 10:39:30 +00001380 copy = ospf6_route_copy (brouter);
hasso508e53e2004-05-18 18:57:06 +00001381 copy->type = OSPF6_DEST_TYPE_ROUTER;
hassoccb59b12004-08-25 09:10:37 +00001382 copy->path.area_id = oa->area_id;
hasso6452df02004-08-15 05:52:07 +00001383 ospf6_route_add (copy, oa->ospf6->brouter_table);
Paul Jakmacf1ce252006-05-15 10:46:07 +00001384
1385 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
1386 IS_OSPF6_DEBUG_ROUTE (MEMORY))
1387 {
1388 zlog_info ("%p: transfer: area %s brouter %s",
1389 brouter, oa->name, brouter_name);
1390 ospf6_brouter_debug_print (brouter);
1391 }
hasso508e53e2004-05-18 18:57:06 +00001392 }
1393
hasso6452df02004-08-15 05:52:07 +00001394 oa->ospf6->brouter_table->hook_add = hook_add;
1395 oa->ospf6->brouter_table->hook_remove = hook_remove;
hasso508e53e2004-05-18 18:57:06 +00001396
Paul Jakmacb4b8842006-05-15 10:39:30 +00001397 for (brouter = ospf6_route_head (oa->ospf6->brouter_table); brouter;
1398 brouter = ospf6_route_next (brouter))
hasso508e53e2004-05-18 18:57:06 +00001399 {
Paul Jakmacb4b8842006-05-15 10:39:30 +00001400 brouter_id = ADV_ROUTER_IN_PREFIX (&brouter->prefix);
1401 inet_ntop (AF_INET, &brouter_id, brouter_name, sizeof (brouter_name));
1402
1403 if (brouter->path.area_id != oa->area_id)
hasso508e53e2004-05-18 18:57:06 +00001404 continue;
1405
Paul Jakmacb4b8842006-05-15 10:39:30 +00001406 if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_WAS_REMOVED))
hasso9428f2d2004-09-13 14:01:12 +00001407 continue;
1408
Paul Jakmacb4b8842006-05-15 10:39:30 +00001409 if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE) &&
1410 CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD))
hasso508e53e2004-05-18 18:57:06 +00001411 {
Paul Jakmacb4b8842006-05-15 10:39:30 +00001412 UNSET_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE);
1413 UNSET_FLAG (brouter->flag, OSPF6_ROUTE_ADD);
hasso508e53e2004-05-18 18:57:06 +00001414 }
1415
Paul Jakmacb4b8842006-05-15 10:39:30 +00001416 if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_REMOVE))
hasso508e53e2004-05-18 18:57:06 +00001417 {
Paul Jakmacb4b8842006-05-15 10:39:30 +00001418 if (IS_OSPF6_DEBUG_BROUTER ||
1419 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
1420 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
1421 zlog_info ("brouter %s disappears via area %s",
1422 brouter_name, oa->name);
1423 ospf6_route_remove (brouter, oa->ospf6->brouter_table);
1424 }
1425 else if (CHECK_FLAG (brouter->flag, OSPF6_ROUTE_ADD) ||
1426 CHECK_FLAG (brouter->flag, OSPF6_ROUTE_CHANGE))
1427 {
1428 if (IS_OSPF6_DEBUG_BROUTER ||
1429 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
1430 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
1431 zlog_info ("brouter %s appears via area %s",
1432 brouter_name, oa->name);
Paul Jakmacf1ce252006-05-15 10:46:07 +00001433
Paul Jakmacb4b8842006-05-15 10:39:30 +00001434 /* newly added */
hasso508e53e2004-05-18 18:57:06 +00001435 if (hook_add)
Paul Jakmacb4b8842006-05-15 10:39:30 +00001436 (*hook_add) (brouter);
1437 }
1438 else
1439 {
1440 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID (brouter_id) ||
1441 IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
1442 zlog_info ("brouter %s still exists via area %s",
1443 brouter_name, oa->name);
hasso508e53e2004-05-18 18:57:06 +00001444 }
1445
Paul Jakmacb4b8842006-05-15 10:39:30 +00001446 brouter->flag = 0;
hasso508e53e2004-05-18 18:57:06 +00001447 }
1448
Paul Jakmacb4b8842006-05-15 10:39:30 +00001449 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID (oa->area_id))
1450 zlog_info ("border-router calculation for area %s: done", oa->name);
paul718e3742002-12-13 20:15:29 +00001451}
1452
hasso6452df02004-08-15 05:52:07 +00001453struct ospf6_lsa_handler router_handler =
1454{
1455 OSPF6_LSTYPE_ROUTER,
1456 "Router",
1457 ospf6_router_lsa_show
1458};
1459
1460struct ospf6_lsa_handler network_handler =
1461{
1462 OSPF6_LSTYPE_NETWORK,
1463 "Network",
1464 ospf6_network_lsa_show
1465};
1466
1467struct ospf6_lsa_handler link_handler =
1468{
1469 OSPF6_LSTYPE_LINK,
1470 "Link",
1471 ospf6_link_lsa_show
1472};
1473
1474struct ospf6_lsa_handler intra_prefix_handler =
1475{
1476 OSPF6_LSTYPE_INTRA_PREFIX,
1477 "Intra-Prefix",
1478 ospf6_intra_prefix_lsa_show
1479};
1480
paul718e3742002-12-13 20:15:29 +00001481void
Paul Jakmacb4b8842006-05-15 10:39:30 +00001482ospf6_intra_init (void)
paul718e3742002-12-13 20:15:29 +00001483{
hasso6452df02004-08-15 05:52:07 +00001484 ospf6_install_lsa_handler (&router_handler);
1485 ospf6_install_lsa_handler (&network_handler);
1486 ospf6_install_lsa_handler (&link_handler);
1487 ospf6_install_lsa_handler (&intra_prefix_handler);
paul718e3742002-12-13 20:15:29 +00001488}
1489
Paul Jakmacb4b8842006-05-15 10:39:30 +00001490DEFUN (debug_ospf6_brouter,
1491 debug_ospf6_brouter_cmd,
1492 "debug ospf6 border-routers",
1493 DEBUG_STR
1494 OSPF6_STR
1495 "Debug border router\n"
1496 )
1497{
1498 OSPF6_DEBUG_BROUTER_ON ();
1499 return CMD_SUCCESS;
1500}
1501
1502DEFUN (no_debug_ospf6_brouter,
1503 no_debug_ospf6_brouter_cmd,
1504 "no debug ospf6 border-routers",
1505 NO_STR
1506 DEBUG_STR
1507 OSPF6_STR
1508 "Debug border router\n"
1509 )
1510{
1511 OSPF6_DEBUG_BROUTER_OFF ();
1512 return CMD_SUCCESS;
1513}
1514
1515DEFUN (debug_ospf6_brouter_router,
1516 debug_ospf6_brouter_router_cmd,
1517 "debug ospf6 border-routers router-id A.B.C.D",
1518 DEBUG_STR
1519 OSPF6_STR
1520 "Debug border router\n"
1521 "Debug specific border router\n"
1522 "Specify border-router's router-id\n"
1523 )
1524{
1525 u_int32_t router_id;
1526 inet_pton (AF_INET, argv[0], &router_id);
1527 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ON (router_id);
1528 return CMD_SUCCESS;
1529}
1530
1531DEFUN (no_debug_ospf6_brouter_router,
1532 no_debug_ospf6_brouter_router_cmd,
1533 "no debug ospf6 border-routers router-id",
1534 NO_STR
1535 DEBUG_STR
1536 OSPF6_STR
1537 "Debug border router\n"
1538 "Debug specific border router\n"
1539 )
1540{
1541 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF ();
1542 return CMD_SUCCESS;
1543}
1544
1545DEFUN (debug_ospf6_brouter_area,
1546 debug_ospf6_brouter_area_cmd,
1547 "debug ospf6 border-routers area-id A.B.C.D",
1548 DEBUG_STR
1549 OSPF6_STR
1550 "Debug border router\n"
1551 "Debug border routers in specific Area\n"
1552 "Specify Area-ID\n"
1553 )
1554{
1555 u_int32_t area_id;
1556 inet_pton (AF_INET, argv[0], &area_id);
1557 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ON (area_id);
1558 return CMD_SUCCESS;
1559}
1560
1561DEFUN (no_debug_ospf6_brouter_area,
1562 no_debug_ospf6_brouter_area_cmd,
1563 "no debug ospf6 border-routers area-id",
1564 NO_STR
1565 DEBUG_STR
1566 OSPF6_STR
1567 "Debug border router\n"
1568 "Debug border routers in specific Area\n"
1569 )
1570{
1571 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF ();
1572 return CMD_SUCCESS;
1573}
1574
1575int
1576config_write_ospf6_debug_brouter (struct vty *vty)
1577{
1578 char buf[16];
1579 if (IS_OSPF6_DEBUG_BROUTER)
1580 vty_out (vty, "debug ospf6 border-routers%s", VNL);
1581 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER)
1582 {
1583 inet_ntop (AF_INET, &conf_debug_ospf6_brouter_specific_router_id,
1584 buf, sizeof (buf));
1585 vty_out (vty, "debug ospf6 border-routers router-id %s%s", buf, VNL);
1586 }
1587 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA)
1588 {
1589 inet_ntop (AF_INET, &conf_debug_ospf6_brouter_specific_area_id,
1590 buf, sizeof (buf));
1591 vty_out (vty, "debug ospf6 border-routers area-id %s%s", buf, VNL);
1592 }
1593 return 0;
1594}
1595
1596void
1597install_element_ospf6_debug_brouter (void)
1598{
1599 install_element (ENABLE_NODE, &debug_ospf6_brouter_cmd);
1600 install_element (ENABLE_NODE, &debug_ospf6_brouter_router_cmd);
1601 install_element (ENABLE_NODE, &debug_ospf6_brouter_area_cmd);
1602 install_element (ENABLE_NODE, &no_debug_ospf6_brouter_cmd);
1603 install_element (ENABLE_NODE, &no_debug_ospf6_brouter_router_cmd);
1604 install_element (ENABLE_NODE, &no_debug_ospf6_brouter_area_cmd);
1605 install_element (CONFIG_NODE, &debug_ospf6_brouter_cmd);
1606 install_element (CONFIG_NODE, &debug_ospf6_brouter_router_cmd);
1607 install_element (CONFIG_NODE, &debug_ospf6_brouter_area_cmd);
1608 install_element (CONFIG_NODE, &no_debug_ospf6_brouter_cmd);
1609 install_element (CONFIG_NODE, &no_debug_ospf6_brouter_router_cmd);
1610 install_element (CONFIG_NODE, &no_debug_ospf6_brouter_area_cmd);
1611}
1612
paul718e3742002-12-13 20:15:29 +00001613