2 * Copyright (C) 2003 Yasuhiro Ohara
4 * This file is part of GNU Zebra.
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
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.
16 * You should have received a copy of the GNU General Public License along
17 * with this program; see the file COPYING; if not, write to the Free Software
18 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
34 #include "ospf6_proto.h"
35 #include "ospf6_message.h"
36 #include "ospf6_route.h"
37 #include "ospf6_lsa.h"
38 #include "ospf6_lsdb.h"
40 #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"
46 #include "ospf6_abr.h"
47 #include "ospf6_flood.h"
49 #include "ospf6_spf.h"
51 unsigned char conf_debug_ospf6_brouter
= 0;
52 uint32_t conf_debug_ospf6_brouter_specific_router_id
;
53 uint32_t conf_debug_ospf6_brouter_specific_area_id
;
55 #define MAX_LSA_PAYLOAD (1024 + 256)
56 /******************************/
57 /* RFC2740 3.4.3.1 Router-LSA */
58 /******************************/
60 static char *ospf6_router_lsa_get_nbr_id(struct ospf6_lsa
*lsa
, char *buf
,
63 struct ospf6_router_lsa
*router_lsa
;
64 struct ospf6_router_lsdesc
*lsdesc
;
66 char buf1
[INET_ADDRSTRLEN
], buf2
[INET_ADDRSTRLEN
];
69 router_lsa
= (struct ospf6_router_lsa
70 *)((char *)lsa
->header
71 + sizeof(struct ospf6_lsa_header
));
72 start
= (char *)router_lsa
+ sizeof(struct ospf6_router_lsa
);
73 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
75 lsdesc
= (struct ospf6_router_lsdesc
77 + pos
* (sizeof(struct
78 ospf6_router_lsdesc
)));
79 if ((char *)lsdesc
< end
) {
80 if (buf
&& (buflen
> INET_ADDRSTRLEN
* 2)) {
82 &lsdesc
->neighbor_interface_id
, buf1
,
84 inet_ntop(AF_INET
, &lsdesc
->neighbor_router_id
,
86 sprintf(buf
, "%s/%s", buf2
, buf1
);
95 static int ospf6_router_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
)
97 char *start
, *end
, *current
;
98 char buf
[32], name
[32], bits
[16], options
[32];
99 struct ospf6_router_lsa
*router_lsa
;
100 struct ospf6_router_lsdesc
*lsdesc
;
103 (struct ospf6_router_lsa
*)((char *)lsa
->header
104 + sizeof(struct ospf6_lsa_header
));
106 ospf6_capability_printbuf(router_lsa
->bits
, bits
, sizeof(bits
));
107 ospf6_options_printbuf(router_lsa
->options
, options
, sizeof(options
));
108 vty_out(vty
, " Bits: %s Options: %s\n", bits
, options
);
110 start
= (char *)router_lsa
+ sizeof(struct ospf6_router_lsa
);
111 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
112 for (current
= start
;
113 current
+ sizeof(struct ospf6_router_lsdesc
) <= end
;
114 current
+= sizeof(struct ospf6_router_lsdesc
)) {
115 lsdesc
= (struct ospf6_router_lsdesc
*)current
;
117 if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_POINTTOPOINT
)
118 snprintf(name
, sizeof(name
), "Point-To-Point");
119 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK
)
120 snprintf(name
, sizeof(name
), "Transit-Network");
121 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_STUB_NETWORK
)
122 snprintf(name
, sizeof(name
), "Stub-Network");
123 else if (lsdesc
->type
== OSPF6_ROUTER_LSDESC_VIRTUAL_LINK
)
124 snprintf(name
, sizeof(name
), "Virtual-Link");
126 snprintf(name
, sizeof(name
), "Unknown (%#x)",
129 vty_out(vty
, " Type: %s Metric: %d\n", name
,
130 ntohs(lsdesc
->metric
));
131 vty_out(vty
, " Interface ID: %s\n",
132 inet_ntop(AF_INET
, &lsdesc
->interface_id
, buf
,
134 vty_out(vty
, " Neighbor Interface ID: %s\n",
135 inet_ntop(AF_INET
, &lsdesc
->neighbor_interface_id
, buf
,
137 vty_out(vty
, " Neighbor Router ID: %s\n",
138 inet_ntop(AF_INET
, &lsdesc
->neighbor_router_id
, buf
,
144 static void ospf6_router_lsa_options_set(struct ospf6_area
*oa
,
145 struct ospf6_router_lsa
*router_lsa
)
147 OSPF6_OPT_CLEAR_ALL(router_lsa
->options
);
148 memcpy(router_lsa
->options
, oa
->options
, 3);
150 if (ospf6_is_router_abr(ospf6
))
151 SET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_B
);
153 UNSET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_B
);
155 if (!IS_AREA_STUB(oa
) && ospf6_asbr_is_asbr(oa
->ospf6
)) {
156 SET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_E
);
158 UNSET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_E
);
161 UNSET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_V
);
162 UNSET_FLAG(router_lsa
->bits
, OSPF6_ROUTER_BIT_W
);
165 int ospf6_router_is_stub_router(struct ospf6_lsa
*lsa
)
167 struct ospf6_router_lsa
*rtr_lsa
;
169 if (lsa
!= NULL
&& OSPF6_LSA_IS_TYPE(ROUTER
, lsa
)) {
170 rtr_lsa
= (struct ospf6_router_lsa
171 *)((caddr_t
)lsa
->header
172 + sizeof(struct ospf6_lsa_header
));
174 if (!OSPF6_OPT_ISSET(rtr_lsa
->options
, OSPF6_OPT_R
)) {
175 return (OSPF6_IS_STUB_ROUTER
);
176 } else if (!OSPF6_OPT_ISSET(rtr_lsa
->options
, OSPF6_OPT_V6
)) {
177 return (OSPF6_IS_STUB_ROUTER_V6
);
181 return (OSPF6_NOT_STUB_ROUTER
);
184 int ospf6_router_lsa_originate(struct thread
*thread
)
186 struct ospf6_area
*oa
;
188 char buffer
[OSPF6_MAX_LSASIZE
];
189 struct ospf6_lsa_header
*lsa_header
;
190 struct ospf6_lsa
*lsa
;
192 uint32_t link_state_id
= 0;
193 struct listnode
*node
, *nnode
;
195 struct ospf6_interface
*oi
;
196 struct ospf6_neighbor
*on
, *drouter
= NULL
;
197 struct ospf6_router_lsa
*router_lsa
;
198 struct ospf6_router_lsdesc
*lsdesc
;
203 oa
= (struct ospf6_area
*)THREAD_ARG(thread
);
204 oa
->thread_router_lsa
= NULL
;
206 if (IS_OSPF6_DEBUG_ORIGINATE(ROUTER
))
207 zlog_debug("Originate Router-LSA for Area %s", oa
->name
);
209 memset(buffer
, 0, sizeof(buffer
));
210 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
212 (struct ospf6_router_lsa
*)((caddr_t
)lsa_header
213 + sizeof(struct ospf6_lsa_header
));
215 ospf6_router_lsa_options_set(oa
, router_lsa
);
217 /* describe links for each interfaces */
218 lsdesc
= (struct ospf6_router_lsdesc
219 *)((caddr_t
)router_lsa
220 + sizeof(struct ospf6_router_lsa
));
222 for (ALL_LIST_ELEMENTS(oa
->if_list
, node
, nnode
, oi
)) {
223 /* Interfaces in state Down or Loopback are not described */
224 if (oi
->state
== OSPF6_INTERFACE_DOWN
225 || oi
->state
== OSPF6_INTERFACE_LOOPBACK
)
228 /* Nor are interfaces without any full adjacencies described */
230 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, j
, on
))
231 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
237 /* Multiple Router-LSA instance according to size limit setting
239 if ((oa
->router_lsa_size_limit
!= 0)
240 && ((size_t)((char *)lsdesc
- buffer
)
241 + sizeof(struct ospf6_router_lsdesc
)
242 > oa
->router_lsa_size_limit
)) {
244 == (caddr_t
)router_lsa
245 + sizeof(struct ospf6_router_lsa
)) {
246 if (IS_OSPF6_DEBUG_ORIGINATE(ROUTER
))
248 "Size limit setting for Router-LSA too short");
252 /* Fill LSA Header */
254 lsa_header
->type
= htons(OSPF6_LSTYPE_ROUTER
);
255 lsa_header
->id
= htonl(link_state_id
);
256 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
257 lsa_header
->seqnum
= ospf6_new_ls_seqnum(
258 lsa_header
->type
, lsa_header
->id
,
259 lsa_header
->adv_router
, oa
->lsdb
);
261 htons((caddr_t
)lsdesc
- (caddr_t
)buffer
);
264 ospf6_lsa_checksum(lsa_header
);
267 lsa
= ospf6_lsa_create(lsa_header
);
270 ospf6_lsa_originate_area(lsa
, oa
);
272 /* Reset Buffer to fill next Router LSA */
273 memset(buffer
, 0, sizeof(buffer
));
274 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
276 (struct ospf6_router_lsa
277 *)((caddr_t
)lsa_header
278 + sizeof(struct ospf6_lsa_header
));
280 ospf6_router_lsa_options_set(oa
, router_lsa
);
282 /* describe links for each interfaces */
283 lsdesc
= (struct ospf6_router_lsdesc
284 *)((caddr_t
)router_lsa
285 + sizeof(struct ospf6_router_lsa
));
290 /* Point-to-Point interfaces */
291 if (oi
->type
== OSPF_IFTYPE_POINTOPOINT
) {
292 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, j
, on
)) {
293 if (on
->state
!= OSPF6_NEIGHBOR_FULL
)
296 lsdesc
->type
= OSPF6_ROUTER_LSDESC_POINTTOPOINT
;
297 lsdesc
->metric
= htons(oi
->cost
);
298 lsdesc
->interface_id
=
299 htonl(oi
->interface
->ifindex
);
300 lsdesc
->neighbor_interface_id
=
302 lsdesc
->neighbor_router_id
= on
->router_id
;
308 /* Broadcast and NBMA interfaces */
309 else if (oi
->type
== OSPF_IFTYPE_BROADCAST
) {
310 /* If this router is not DR,
311 and If this router not fully adjacent with DR,
312 this interface is not transit yet: ignore. */
313 if (oi
->state
!= OSPF6_INTERFACE_DR
) {
315 ospf6_neighbor_lookup(oi
->drouter
, oi
);
317 || drouter
->state
!= OSPF6_NEIGHBOR_FULL
)
321 lsdesc
->type
= OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK
;
322 lsdesc
->metric
= htons(oi
->cost
);
323 lsdesc
->interface_id
= htonl(oi
->interface
->ifindex
);
324 if (oi
->state
!= OSPF6_INTERFACE_DR
) {
325 lsdesc
->neighbor_interface_id
=
326 htonl(drouter
->ifindex
);
327 lsdesc
->neighbor_router_id
= drouter
->router_id
;
329 lsdesc
->neighbor_interface_id
=
330 htonl(oi
->interface
->ifindex
);
331 lsdesc
->neighbor_router_id
=
332 oi
->area
->ospf6
->router_id
;
337 assert(0); /* Unknown interface type */
342 /* Point-to-Multipoint interfaces */
346 /* Fill LSA Header */
348 lsa_header
->type
= htons(OSPF6_LSTYPE_ROUTER
);
349 lsa_header
->id
= htonl(link_state_id
);
350 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
352 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
353 lsa_header
->adv_router
, oa
->lsdb
);
354 lsa_header
->length
= htons((caddr_t
)lsdesc
- (caddr_t
)buffer
);
357 ospf6_lsa_checksum(lsa_header
);
360 lsa
= ospf6_lsa_create(lsa_header
);
363 ospf6_lsa_originate_area(lsa
, oa
);
367 /* Do premature-aging of rest, undesired Router-LSAs */
368 type
= ntohs(OSPF6_LSTYPE_ROUTER
);
369 router
= oa
->ospf6
->router_id
;
371 for (ALL_LSDB_TYPED_ADVRTR(oa
->lsdb
, type
, router
, lsa
)) {
372 if (ntohl(lsa
->header
->id
) < link_state_id
)
374 ospf6_lsa_purge(lsa
);
379 * Waiting till the LSA is actually removed from the database to trigger
380 * SPF delays network convergence. Unlike IPv4, for an ABR, when all
381 * interfaces associated with an area are gone, triggering an SPF right
383 * helps convergence with inter-area routes.
385 if (count
&& !link_state_id
)
386 ospf6_spf_schedule(oa
->ospf6
,
387 OSPF6_SPF_FLAGS_ROUTER_LSA_ORIGINATED
);
392 /*******************************/
393 /* RFC2740 3.4.3.2 Network-LSA */
394 /*******************************/
396 static char *ospf6_network_lsa_get_ar_id(struct ospf6_lsa
*lsa
, char *buf
,
399 char *start
, *end
, *current
;
400 struct ospf6_network_lsa
*network_lsa
;
401 struct ospf6_network_lsdesc
*lsdesc
;
404 network_lsa
= (struct ospf6_network_lsa
405 *)((caddr_t
)lsa
->header
406 + sizeof(struct ospf6_lsa_header
));
408 start
= (char *)network_lsa
+ sizeof(struct ospf6_network_lsa
);
409 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
410 current
= start
+ pos
* (sizeof(struct ospf6_network_lsdesc
));
412 if ((current
+ sizeof(struct ospf6_network_lsdesc
)) <= end
) {
413 lsdesc
= (struct ospf6_network_lsdesc
*)current
;
415 inet_ntop(AF_INET
, &lsdesc
->router_id
, buf
,
424 static int ospf6_network_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
)
426 char *start
, *end
, *current
;
427 struct ospf6_network_lsa
*network_lsa
;
428 struct ospf6_network_lsdesc
*lsdesc
;
429 char buf
[128], options
[32];
432 (struct ospf6_network_lsa
*)((caddr_t
)lsa
->header
433 + sizeof(struct ospf6_lsa_header
));
435 ospf6_options_printbuf(network_lsa
->options
, options
, sizeof(options
));
436 vty_out(vty
, " Options: %s\n", options
);
438 start
= (char *)network_lsa
+ sizeof(struct ospf6_network_lsa
);
439 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
440 for (current
= start
;
441 current
+ sizeof(struct ospf6_network_lsdesc
) <= end
;
442 current
+= sizeof(struct ospf6_network_lsdesc
)) {
443 lsdesc
= (struct ospf6_network_lsdesc
*)current
;
444 inet_ntop(AF_INET
, &lsdesc
->router_id
, buf
, sizeof(buf
));
445 vty_out(vty
, " Attached Router: %s\n", buf
);
450 int ospf6_network_lsa_originate(struct thread
*thread
)
452 struct ospf6_interface
*oi
;
454 char buffer
[OSPF6_MAX_LSASIZE
];
455 struct ospf6_lsa_header
*lsa_header
;
458 struct ospf6_lsa
*old
, *lsa
;
459 struct ospf6_network_lsa
*network_lsa
;
460 struct ospf6_network_lsdesc
*lsdesc
;
461 struct ospf6_neighbor
*on
;
462 struct ospf6_link_lsa
*link_lsa
;
466 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
467 oi
->thread_network_lsa
= NULL
;
469 /* The interface must be enabled until here. A Network-LSA of a
470 disabled interface (but was once enabled) should be flushed
471 by ospf6_lsa_refresh (), and does not come here. */
474 old
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_NETWORK
),
475 htonl(oi
->interface
->ifindex
),
476 oi
->area
->ospf6
->router_id
, oi
->area
->lsdb
);
478 /* Do not originate Network-LSA if not DR */
479 if (oi
->state
!= OSPF6_INTERFACE_DR
) {
481 ospf6_lsa_purge(old
);
483 * Waiting till the LSA is actually removed from the
485 * trigger SPF delays network convergence.
489 OSPF6_SPF_FLAGS_NETWORK_LSA_ORIGINATED
);
494 if (IS_OSPF6_DEBUG_ORIGINATE(NETWORK
))
495 zlog_debug("Originate Network-LSA for Interface %s",
496 oi
->interface
->name
);
498 /* If none of neighbor is adjacent to us */
501 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, i
, on
))
502 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
506 if (IS_OSPF6_DEBUG_ORIGINATE(NETWORK
))
507 zlog_debug("Interface stub, ignore");
509 ospf6_lsa_purge(old
);
514 memset(buffer
, 0, sizeof(buffer
));
515 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
517 (struct ospf6_network_lsa
*)((caddr_t
)lsa_header
518 + sizeof(struct ospf6_lsa_header
));
520 /* Collect the interface's Link-LSAs to describe
521 network's optional capabilities */
522 type
= htons(OSPF6_LSTYPE_LINK
);
523 for (ALL_LSDB_TYPED(oi
->lsdb
, type
, lsa
)) {
524 link_lsa
= (struct ospf6_link_lsa
525 *)((caddr_t
)lsa
->header
526 + sizeof(struct ospf6_lsa_header
));
527 network_lsa
->options
[0] |= link_lsa
->options
[0];
528 network_lsa
->options
[1] |= link_lsa
->options
[1];
529 network_lsa
->options
[2] |= link_lsa
->options
[2];
532 lsdesc
= (struct ospf6_network_lsdesc
533 *)((caddr_t
)network_lsa
534 + sizeof(struct ospf6_network_lsa
));
536 /* set Link Description to the router itself */
537 lsdesc
->router_id
= oi
->area
->ospf6
->router_id
;
540 /* Walk through the neighbors */
541 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, i
, on
)) {
542 if (on
->state
!= OSPF6_NEIGHBOR_FULL
)
545 /* set this neighbor's Router-ID to LSA */
546 lsdesc
->router_id
= on
->router_id
;
550 /* Fill LSA Header */
552 lsa_header
->type
= htons(OSPF6_LSTYPE_NETWORK
);
553 lsa_header
->id
= htonl(oi
->interface
->ifindex
);
554 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
556 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
557 lsa_header
->adv_router
, oi
->area
->lsdb
);
558 lsa_header
->length
= htons((caddr_t
)lsdesc
- (caddr_t
)buffer
);
561 ospf6_lsa_checksum(lsa_header
);
564 lsa
= ospf6_lsa_create(lsa_header
);
567 ospf6_lsa_originate_area(lsa
, oi
->area
);
573 /****************************/
574 /* RFC2740 3.4.3.6 Link-LSA */
575 /****************************/
577 static char *ospf6_link_lsa_get_prefix_str(struct ospf6_lsa
*lsa
, char *buf
,
580 char *start
, *end
, *current
;
581 struct ospf6_link_lsa
*link_lsa
;
583 struct ospf6_prefix
*prefix
;
584 int cnt
= 0, prefixnum
;
587 link_lsa
= (struct ospf6_link_lsa
588 *)((caddr_t
)lsa
->header
589 + sizeof(struct ospf6_lsa_header
));
592 inet_ntop(AF_INET6
, &link_lsa
->linklocal_addr
, buf
,
597 prefixnum
= ntohl(link_lsa
->prefix_num
);
601 start
= (char *)link_lsa
+ sizeof(struct ospf6_link_lsa
);
602 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
606 prefix
= (struct ospf6_prefix
*)current
;
607 if (prefix
->prefix_length
== 0
608 || current
+ OSPF6_PREFIX_SIZE(prefix
) > end
) {
614 start
+ pos
* OSPF6_PREFIX_SIZE(prefix
);
617 memset(&in6
, 0, sizeof(in6
));
618 memcpy(&in6
, OSPF6_PREFIX_BODY(prefix
),
620 prefix
->prefix_length
));
621 inet_ntop(AF_INET6
, &in6
, buf
, buflen
);
624 } while (current
<= end
);
629 static int ospf6_link_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
)
631 char *start
, *end
, *current
;
632 struct ospf6_link_lsa
*link_lsa
;
634 char buf
[128], options
[32];
635 struct ospf6_prefix
*prefix
;
636 const char *p
, *mc
, *la
, *nu
;
639 link_lsa
= (struct ospf6_link_lsa
*)((caddr_t
)lsa
->header
640 + sizeof(struct ospf6_lsa_header
));
642 ospf6_options_printbuf(link_lsa
->options
, options
, sizeof(options
));
643 inet_ntop(AF_INET6
, &link_lsa
->linklocal_addr
, buf
, sizeof(buf
));
644 prefixnum
= ntohl(link_lsa
->prefix_num
);
646 vty_out(vty
, " Priority: %d Options: %s\n", link_lsa
->priority
,
648 vty_out(vty
, " LinkLocal Address: %s\n", buf
);
649 vty_out(vty
, " Number of Prefix: %d\n", prefixnum
);
651 start
= (char *)link_lsa
+ sizeof(struct ospf6_link_lsa
);
652 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
653 for (current
= start
; current
< end
;
654 current
+= OSPF6_PREFIX_SIZE(prefix
)) {
655 prefix
= (struct ospf6_prefix
*)current
;
656 if (prefix
->prefix_length
== 0
657 || current
+ OSPF6_PREFIX_SIZE(prefix
) > end
)
660 p
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_P
)
663 mc
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_MC
)
666 la
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_LA
)
669 nu
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_NU
)
672 vty_out(vty
, " Prefix Options: %s|%s|%s|%s\n", p
, mc
, la
,
675 memset(&in6
, 0, sizeof(in6
));
676 memcpy(&in6
, OSPF6_PREFIX_BODY(prefix
),
677 OSPF6_PREFIX_SPACE(prefix
->prefix_length
));
678 inet_ntop(AF_INET6
, &in6
, buf
, sizeof(buf
));
679 vty_out(vty
, " Prefix: %s/%d\n", buf
,
680 prefix
->prefix_length
);
686 int ospf6_link_lsa_originate(struct thread
*thread
)
688 struct ospf6_interface
*oi
;
690 char buffer
[OSPF6_MAX_LSASIZE
];
691 struct ospf6_lsa_header
*lsa_header
;
692 struct ospf6_lsa
*old
, *lsa
;
694 struct ospf6_link_lsa
*link_lsa
;
695 struct ospf6_route
*route
;
696 struct ospf6_prefix
*op
;
698 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
699 oi
->thread_link_lsa
= NULL
;
703 /* find previous LSA */
704 old
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_LINK
),
705 htonl(oi
->interface
->ifindex
),
706 oi
->area
->ospf6
->router_id
, oi
->lsdb
);
708 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
)) {
710 ospf6_lsa_purge(old
);
714 if (IS_OSPF6_DEBUG_ORIGINATE(LINK
))
715 zlog_debug("Originate Link-LSA for Interface %s",
716 oi
->interface
->name
);
718 /* can't make Link-LSA if linklocal address not set */
719 if (oi
->linklocal_addr
== NULL
) {
720 if (IS_OSPF6_DEBUG_ORIGINATE(LINK
))
722 "No Linklocal address on %s, defer originating",
723 oi
->interface
->name
);
725 ospf6_lsa_purge(old
);
730 memset(buffer
, 0, sizeof(buffer
));
731 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
732 link_lsa
= (struct ospf6_link_lsa
*)((caddr_t
)lsa_header
733 + sizeof(struct ospf6_lsa_header
));
736 link_lsa
->priority
= oi
->priority
;
737 memcpy(link_lsa
->options
, oi
->area
->options
, 3);
738 memcpy(&link_lsa
->linklocal_addr
, oi
->linklocal_addr
,
739 sizeof(struct in6_addr
));
740 link_lsa
->prefix_num
= htonl(oi
->route_connected
->count
);
742 op
= (struct ospf6_prefix
*)((caddr_t
)link_lsa
743 + sizeof(struct ospf6_link_lsa
));
745 /* connected prefix to advertise */
746 for (route
= ospf6_route_head(oi
->route_connected
); route
;
747 route
= ospf6_route_next(route
)) {
748 op
->prefix_length
= route
->prefix
.prefixlen
;
749 op
->prefix_options
= route
->path
.prefix_options
;
750 op
->prefix_metric
= htons(0);
751 memcpy(OSPF6_PREFIX_BODY(op
), &route
->prefix
.u
.prefix6
,
752 OSPF6_PREFIX_SPACE(op
->prefix_length
));
753 op
= OSPF6_PREFIX_NEXT(op
);
756 /* Fill LSA Header */
758 lsa_header
->type
= htons(OSPF6_LSTYPE_LINK
);
759 lsa_header
->id
= htonl(oi
->interface
->ifindex
);
760 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
762 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
763 lsa_header
->adv_router
, oi
->lsdb
);
764 lsa_header
->length
= htons((caddr_t
)op
- (caddr_t
)buffer
);
767 ospf6_lsa_checksum(lsa_header
);
770 lsa
= ospf6_lsa_create(lsa_header
);
773 ospf6_lsa_originate_interface(lsa
, oi
);
779 /*****************************************/
780 /* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */
781 /*****************************************/
782 static char *ospf6_intra_prefix_lsa_get_prefix_str(struct ospf6_lsa
*lsa
,
783 char *buf
, int buflen
,
786 char *start
, *end
, *current
;
787 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
789 int prefixnum
, cnt
= 0;
790 struct ospf6_prefix
*prefix
;
794 (struct ospf6_intra_prefix_lsa
795 *)((caddr_t
)lsa
->header
796 + sizeof(struct ospf6_lsa_header
));
798 prefixnum
= ntohs(intra_prefix_lsa
->prefix_num
);
802 start
= (char *)intra_prefix_lsa
803 + sizeof(struct ospf6_intra_prefix_lsa
);
804 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
808 prefix
= (struct ospf6_prefix
*)current
;
809 if (prefix
->prefix_length
== 0
810 || current
+ OSPF6_PREFIX_SIZE(prefix
) > end
) {
816 start
+ pos
* OSPF6_PREFIX_SIZE(prefix
);
819 memset(&in6
, 0, sizeof(in6
));
820 memcpy(&in6
, OSPF6_PREFIX_BODY(prefix
),
822 prefix
->prefix_length
));
823 inet_ntop(AF_INET6
, &in6
, buf
, buflen
);
824 sprintf(&buf
[strlen(buf
)], "/%d",
825 prefix
->prefix_length
);
828 } while (current
<= end
);
833 static int ospf6_intra_prefix_lsa_show(struct vty
*vty
, struct ospf6_lsa
*lsa
)
835 char *start
, *end
, *current
;
836 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
839 struct ospf6_prefix
*prefix
;
840 char id
[16], adv_router
[16];
841 const char *p
, *mc
, *la
, *nu
;
844 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
845 *)((caddr_t
)lsa
->header
846 + sizeof(struct ospf6_lsa_header
));
848 prefixnum
= ntohs(intra_prefix_lsa
->prefix_num
);
850 vty_out(vty
, " Number of Prefix: %d\n", prefixnum
);
852 inet_ntop(AF_INET
, &intra_prefix_lsa
->ref_id
, id
, sizeof(id
));
853 inet_ntop(AF_INET
, &intra_prefix_lsa
->ref_adv_router
, adv_router
,
855 vty_out(vty
, " Reference: %s Id: %s Adv: %s\n",
856 ospf6_lstype_name(intra_prefix_lsa
->ref_type
), id
, adv_router
);
858 start
= (char *)intra_prefix_lsa
859 + sizeof(struct ospf6_intra_prefix_lsa
);
860 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
861 for (current
= start
; current
< end
;
862 current
+= OSPF6_PREFIX_SIZE(prefix
)) {
863 prefix
= (struct ospf6_prefix
*)current
;
864 if (prefix
->prefix_length
== 0
865 || current
+ OSPF6_PREFIX_SIZE(prefix
) > end
)
868 p
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_P
)
871 mc
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_MC
)
874 la
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_LA
)
877 nu
= (CHECK_FLAG(prefix
->prefix_options
, OSPF6_PREFIX_OPTION_NU
)
880 vty_out(vty
, " Prefix Options: %s|%s|%s|%s\n", p
, mc
, la
,
883 memset(&in6
, 0, sizeof(in6
));
884 memcpy(&in6
, OSPF6_PREFIX_BODY(prefix
),
885 OSPF6_PREFIX_SPACE(prefix
->prefix_length
));
886 inet_ntop(AF_INET6
, &in6
, buf
, sizeof(buf
));
887 vty_out(vty
, " Prefix: %s/%d\n", buf
,
888 prefix
->prefix_length
);
894 int ospf6_intra_prefix_lsa_originate_stub(struct thread
*thread
)
896 struct ospf6_area
*oa
;
898 char buffer
[OSPF6_MAX_LSASIZE
];
899 struct ospf6_lsa_header
*lsa_header
;
900 struct ospf6_lsa
*old
, *lsa
, *old_next
= NULL
;
902 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
903 struct ospf6_interface
*oi
;
904 struct ospf6_neighbor
*on
;
905 struct ospf6_route
*route
;
906 struct ospf6_prefix
*op
;
907 struct listnode
*i
, *j
;
909 unsigned short prefix_num
= 0;
910 char buf
[PREFIX2STR_BUFFER
];
911 struct ospf6_route_table
*route_advertise
;
914 oa
= (struct ospf6_area
*)THREAD_ARG(thread
);
915 oa
->thread_intra_prefix_lsa
= NULL
;
917 /* find previous LSA */
918 old
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_INTRA_PREFIX
), htonl(0),
919 oa
->ospf6
->router_id
, oa
->lsdb
);
921 if (!IS_AREA_ENABLED(oa
)) {
923 ospf6_lsa_purge(old
);
924 /* find previous LSA */
925 old_next
= ospf6_lsdb_lookup(
926 htons(OSPF6_LSTYPE_INTRA_PREFIX
),
927 htonl(++ls_id
), oa
->ospf6
->router_id
, oa
->lsdb
);
930 ospf6_lsa_purge(old_next
);
931 old_next
= ospf6_lsdb_lookup(
932 htons(OSPF6_LSTYPE_INTRA_PREFIX
),
933 htonl(++ls_id
), oa
->ospf6
->router_id
,
940 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
942 "Originate Intra-Area-Prefix-LSA for area %s's stub prefix",
946 memset(buffer
, 0, sizeof(buffer
));
947 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
948 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
949 *)((caddr_t
)lsa_header
950 + sizeof(struct ospf6_lsa_header
));
952 /* Fill Intra-Area-Prefix-LSA */
953 intra_prefix_lsa
->ref_type
= htons(OSPF6_LSTYPE_ROUTER
);
954 intra_prefix_lsa
->ref_id
= htonl(0);
955 intra_prefix_lsa
->ref_adv_router
= oa
->ospf6
->router_id
;
957 route_advertise
= ospf6_route_table_create(0, 0);
959 for (ALL_LIST_ELEMENTS_RO(oa
->if_list
, i
, oi
)) {
960 if (oi
->state
== OSPF6_INTERFACE_DOWN
) {
961 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
962 zlog_debug(" Interface %s is down, ignore",
963 oi
->interface
->name
);
969 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, j
, on
))
970 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
973 if (oi
->state
!= OSPF6_INTERFACE_LOOPBACK
974 && oi
->state
!= OSPF6_INTERFACE_POINTTOPOINT
975 && full_count
!= 0) {
976 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
977 zlog_debug(" Interface %s is not stub, ignore",
978 oi
->interface
->name
);
982 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
983 zlog_debug(" Interface %s:", oi
->interface
->name
);
985 /* connected prefix to advertise */
986 for (route
= ospf6_route_head(oi
->route_connected
); route
;
987 route
= ospf6_route_best_next(route
)) {
988 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
)) {
989 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
990 zlog_debug(" include %s", buf
);
992 ospf6_route_add(ospf6_route_copy(route
),
997 if (route_advertise
->count
== 0) {
1000 ospf6_lsa_purge(old
);
1001 /* find previous LSA */
1002 old_next
= ospf6_lsdb_lookup(
1003 htons(OSPF6_LSTYPE_INTRA_PREFIX
),
1004 htonl(++ls_id
), oa
->ospf6
->router_id
, oa
->lsdb
);
1007 ospf6_lsa_purge(old_next
);
1008 old_next
= ospf6_lsdb_lookup(
1009 htons(OSPF6_LSTYPE_INTRA_PREFIX
),
1010 htonl(++ls_id
), oa
->ospf6
->router_id
,
1014 ospf6_route_table_delete(route_advertise
);
1018 /* Neighbor change to FULL, if INTRA-AREA-PREFIX LSA
1019 * has not change, Flush old LSA and Re-Originate INP,
1020 * as ospf6_flood() checks if LSA is same as DB,
1021 * it won't be updated to neighbor's DB.
1023 if (oa
->intra_prefix_originate
) {
1024 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1025 zlog_debug("%s: Re-originate intra prefix LSA, Current full nbrs %u",
1026 __PRETTY_FUNCTION__
, oa
->full_nbrs
);
1028 ospf6_lsa_purge_multi_ls_id(oa
, old
);
1029 oa
->intra_prefix_originate
= 0;
1032 /* put prefixes to advertise */
1034 op
= (struct ospf6_prefix
*)((caddr_t
)intra_prefix_lsa
1035 + sizeof(struct ospf6_intra_prefix_lsa
));
1036 for (route
= ospf6_route_head(route_advertise
); route
;
1037 route
= ospf6_route_best_next(route
)) {
1038 if (((caddr_t
)op
- (caddr_t
)lsa_header
) > MAX_LSA_PAYLOAD
) {
1040 intra_prefix_lsa
->prefix_num
= htons(prefix_num
);
1042 /* Fill LSA Header */
1043 lsa_header
->age
= 0;
1044 lsa_header
->type
= htons(OSPF6_LSTYPE_INTRA_PREFIX
);
1045 lsa_header
->id
= htonl(ls_id
++);
1046 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
1047 lsa_header
->seqnum
= ospf6_new_ls_seqnum(
1048 lsa_header
->type
, lsa_header
->id
,
1049 lsa_header
->adv_router
, oa
->lsdb
);
1050 lsa_header
->length
=
1051 htons((caddr_t
)op
- (caddr_t
)lsa_header
);
1054 ospf6_lsa_checksum(lsa_header
);
1057 lsa
= ospf6_lsa_create(lsa_header
);
1060 ospf6_lsa_originate_area(lsa
, oa
);
1062 /* Prepare next buffer */
1063 memset(buffer
, 0, sizeof(buffer
));
1064 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
1066 (struct ospf6_intra_prefix_lsa
1067 *)((caddr_t
)lsa_header
1068 + sizeof(struct ospf6_lsa_header
));
1070 /* Fill Intra-Area-Prefix-LSA */
1071 intra_prefix_lsa
->ref_type
= htons(OSPF6_LSTYPE_ROUTER
);
1072 intra_prefix_lsa
->ref_id
= htonl(0);
1073 intra_prefix_lsa
->ref_adv_router
= oa
->ospf6
->router_id
;
1075 /* Put next set of prefixes to advertise */
1077 op
= (struct ospf6_prefix
1078 *)((caddr_t
)intra_prefix_lsa
1080 ospf6_intra_prefix_lsa
));
1083 op
->prefix_length
= route
->prefix
.prefixlen
;
1084 op
->prefix_options
= route
->path
.prefix_options
;
1085 op
->prefix_metric
= htons(route
->path
.cost
);
1086 memcpy(OSPF6_PREFIX_BODY(op
), &route
->prefix
.u
.prefix6
,
1087 OSPF6_PREFIX_SPACE(op
->prefix_length
));
1090 op
= OSPF6_PREFIX_NEXT(op
);
1093 ospf6_route_table_delete(route_advertise
);
1095 if (prefix_num
== 0) {
1096 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1098 "Quit to Advertise Intra-Prefix: no route to advertise");
1102 intra_prefix_lsa
->prefix_num
= htons(prefix_num
);
1104 /* Fill LSA Header */
1105 lsa_header
->age
= 0;
1106 lsa_header
->type
= htons(OSPF6_LSTYPE_INTRA_PREFIX
);
1107 lsa_header
->id
= htonl(ls_id
++);
1108 lsa_header
->adv_router
= oa
->ospf6
->router_id
;
1109 lsa_header
->seqnum
=
1110 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
1111 lsa_header
->adv_router
, oa
->lsdb
);
1112 lsa_header
->length
= htons((caddr_t
)op
- (caddr_t
)lsa_header
);
1115 ospf6_lsa_checksum(lsa_header
);
1118 lsa
= ospf6_lsa_create(lsa_header
);
1121 ospf6_lsa_originate_area(lsa
, oa
);
1127 int ospf6_intra_prefix_lsa_originate_transit(struct thread
*thread
)
1129 struct ospf6_interface
*oi
;
1131 char buffer
[OSPF6_MAX_LSASIZE
];
1132 struct ospf6_lsa_header
*lsa_header
;
1133 struct ospf6_lsa
*old
, *lsa
;
1135 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1136 struct ospf6_neighbor
*on
;
1137 struct ospf6_route
*route
;
1138 struct ospf6_prefix
*op
;
1141 unsigned short prefix_num
= 0;
1142 struct ospf6_route_table
*route_advertise
;
1143 struct ospf6_link_lsa
*link_lsa
;
1144 char *start
, *end
, *current
;
1146 char buf
[PREFIX2STR_BUFFER
];
1148 oi
= (struct ospf6_interface
*)THREAD_ARG(thread
);
1149 oi
->thread_intra_prefix_lsa
= NULL
;
1153 /* find previous LSA */
1154 old
= ospf6_lsdb_lookup(htons(OSPF6_LSTYPE_INTRA_PREFIX
),
1155 htonl(oi
->interface
->ifindex
),
1156 oi
->area
->ospf6
->router_id
, oi
->area
->lsdb
);
1158 if (CHECK_FLAG(oi
->flag
, OSPF6_INTERFACE_DISABLE
)) {
1160 ospf6_lsa_purge(old
);
1164 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1166 "Originate Intra-Area-Prefix-LSA for interface %s's prefix",
1167 oi
->interface
->name
);
1169 /* prepare buffer */
1170 memset(buffer
, 0, sizeof(buffer
));
1171 lsa_header
= (struct ospf6_lsa_header
*)buffer
;
1172 intra_prefix_lsa
= (struct ospf6_intra_prefix_lsa
1173 *)((caddr_t
)lsa_header
1174 + sizeof(struct ospf6_lsa_header
));
1176 /* Fill Intra-Area-Prefix-LSA */
1177 intra_prefix_lsa
->ref_type
= htons(OSPF6_LSTYPE_NETWORK
);
1178 intra_prefix_lsa
->ref_id
= htonl(oi
->interface
->ifindex
);
1179 intra_prefix_lsa
->ref_adv_router
= oi
->area
->ospf6
->router_id
;
1181 if (oi
->state
!= OSPF6_INTERFACE_DR
) {
1182 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1183 zlog_debug(" Interface is not DR");
1185 ospf6_lsa_purge(old
);
1190 for (ALL_LIST_ELEMENTS_RO(oi
->neighbor_list
, i
, on
))
1191 if (on
->state
== OSPF6_NEIGHBOR_FULL
)
1194 if (full_count
== 0) {
1195 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1196 zlog_debug(" Interface is stub");
1198 ospf6_lsa_purge(old
);
1202 /* connected prefix to advertise */
1203 route_advertise
= ospf6_route_table_create(0, 0);
1205 type
= ntohs(OSPF6_LSTYPE_LINK
);
1206 for (ALL_LSDB_TYPED(oi
->lsdb
, type
, lsa
)) {
1207 if (OSPF6_LSA_IS_MAXAGE(lsa
))
1210 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1211 zlog_debug(" include prefix from %s", lsa
->name
);
1213 if (lsa
->header
->adv_router
!= oi
->area
->ospf6
->router_id
) {
1214 on
= ospf6_neighbor_lookup(lsa
->header
->adv_router
, oi
);
1215 if (on
== NULL
|| on
->state
!= OSPF6_NEIGHBOR_FULL
) {
1216 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1218 " Neighbor not found or not Full, ignore");
1223 link_lsa
= (struct ospf6_link_lsa
1224 *)((caddr_t
)lsa
->header
1225 + sizeof(struct ospf6_lsa_header
));
1227 prefix_num
= (unsigned short)ntohl(link_lsa
->prefix_num
);
1228 start
= (char *)link_lsa
+ sizeof(struct ospf6_link_lsa
);
1229 end
= (char *)lsa
->header
+ ntohs(lsa
->header
->length
);
1230 for (current
= start
; current
< end
&& prefix_num
;
1231 current
+= OSPF6_PREFIX_SIZE(op
)) {
1232 op
= (struct ospf6_prefix
*)current
;
1233 if (op
->prefix_length
== 0
1234 || current
+ OSPF6_PREFIX_SIZE(op
) > end
)
1237 route
= ospf6_route_create();
1239 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
1240 route
->prefix
.family
= AF_INET6
;
1241 route
->prefix
.prefixlen
= op
->prefix_length
;
1242 memset(&route
->prefix
.u
.prefix6
, 0,
1243 sizeof(struct in6_addr
));
1244 memcpy(&route
->prefix
.u
.prefix6
, OSPF6_PREFIX_BODY(op
),
1245 OSPF6_PREFIX_SPACE(op
->prefix_length
));
1247 route
->path
.origin
.type
= lsa
->header
->type
;
1248 route
->path
.origin
.id
= lsa
->header
->id
;
1249 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
1250 route
->path
.options
[0] = link_lsa
->options
[0];
1251 route
->path
.options
[1] = link_lsa
->options
[1];
1252 route
->path
.options
[2] = link_lsa
->options
[2];
1253 route
->path
.prefix_options
= op
->prefix_options
;
1254 route
->path
.area_id
= oi
->area
->area_id
;
1255 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
1257 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
)) {
1258 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1259 zlog_debug(" include %s", buf
);
1262 ospf6_route_add(route
, route_advertise
);
1265 if (current
!= end
&& IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1266 zlog_debug("Trailing garbage in %s", lsa
->name
);
1269 op
= (struct ospf6_prefix
*)((caddr_t
)intra_prefix_lsa
1270 + sizeof(struct ospf6_intra_prefix_lsa
));
1273 for (route
= ospf6_route_head(route_advertise
); route
;
1274 route
= ospf6_route_best_next(route
)) {
1275 op
->prefix_length
= route
->prefix
.prefixlen
;
1276 op
->prefix_options
= route
->path
.prefix_options
;
1277 op
->prefix_metric
= htons(0);
1278 memcpy(OSPF6_PREFIX_BODY(op
), &route
->prefix
.u
.prefix6
,
1279 OSPF6_PREFIX_SPACE(op
->prefix_length
));
1280 op
= OSPF6_PREFIX_NEXT(op
);
1284 ospf6_route_table_delete(route_advertise
);
1286 if (prefix_num
== 0) {
1287 if (IS_OSPF6_DEBUG_ORIGINATE(INTRA_PREFIX
))
1289 "Quit to Advertise Intra-Prefix: no route to advertise");
1293 intra_prefix_lsa
->prefix_num
= htons(prefix_num
);
1295 /* Fill LSA Header */
1296 lsa_header
->age
= 0;
1297 lsa_header
->type
= htons(OSPF6_LSTYPE_INTRA_PREFIX
);
1298 lsa_header
->id
= htonl(oi
->interface
->ifindex
);
1299 lsa_header
->adv_router
= oi
->area
->ospf6
->router_id
;
1300 lsa_header
->seqnum
=
1301 ospf6_new_ls_seqnum(lsa_header
->type
, lsa_header
->id
,
1302 lsa_header
->adv_router
, oi
->area
->lsdb
);
1303 lsa_header
->length
= htons((caddr_t
)op
- (caddr_t
)lsa_header
);
1306 ospf6_lsa_checksum(lsa_header
);
1309 lsa
= ospf6_lsa_create(lsa_header
);
1312 ospf6_lsa_originate_area(lsa
, oi
->area
);
1317 static void ospf6_intra_prefix_update_route_origin(struct ospf6_route
*oa_route
)
1319 struct ospf6_path
*h_path
;
1320 struct ospf6_route
*g_route
, *nroute
;
1322 /* Update Global ospf6 route path */
1323 g_route
= ospf6_route_lookup(&oa_route
->prefix
,
1324 ospf6
->route_table
);
1328 for (ospf6_route_lock(g_route
); g_route
&&
1329 ospf6_route_is_prefix(&oa_route
->prefix
, g_route
);
1331 nroute
= ospf6_route_next(g_route
);
1332 if (g_route
->type
!= oa_route
->type
)
1334 if (g_route
->path
.area_id
!= oa_route
->path
.area_id
)
1336 if (g_route
->path
.type
!= OSPF6_PATH_TYPE_INTRA
)
1338 if (g_route
->path
.cost
!= oa_route
->path
.cost
)
1341 if (ospf6_route_is_same_origin(g_route
, oa_route
)) {
1342 h_path
= (struct ospf6_path
*)listgetdata(
1343 listhead(g_route
->paths
));
1344 g_route
->path
.origin
.type
= h_path
->origin
.type
;
1345 g_route
->path
.origin
.id
= h_path
->origin
.id
;
1346 g_route
->path
.origin
.adv_router
=
1347 h_path
->origin
.adv_router
;
1352 h_path
= (struct ospf6_path
*)listgetdata(
1353 listhead(oa_route
->paths
));
1354 oa_route
->path
.origin
.type
= h_path
->origin
.type
;
1355 oa_route
->path
.origin
.id
= h_path
->origin
.id
;
1356 oa_route
->path
.origin
.adv_router
= h_path
->origin
.adv_router
;
1359 void ospf6_intra_prefix_route_ecmp_path(struct ospf6_area
*oa
,
1360 struct ospf6_route
*old
,
1361 struct ospf6_route
*route
)
1363 struct ospf6_route
*old_route
, *ls_entry
;
1364 struct ospf6_path
*ecmp_path
, *o_path
= NULL
;
1365 struct listnode
*anode
, *anext
;
1366 struct listnode
*nnode
, *rnode
, *rnext
;
1367 struct ospf6_nexthop
*nh
, *rnh
;
1368 char buf
[PREFIX2STR_BUFFER
];
1369 bool route_found
= false;
1370 struct interface
*ifp
;
1371 struct ospf6_lsa
*lsa
;
1372 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1374 /* check for old entry match with new route origin,
1377 for (old_route
= old
; old_route
; old_route
= old_route
->next
) {
1378 bool route_updated
= false;
1380 if (!ospf6_route_is_same(old_route
, route
) ||
1381 (old_route
->path
.type
!= route
->path
.type
))
1384 /* Current and New route has same origin,
1387 for (ALL_LIST_ELEMENTS(old_route
->paths
, anode
, anext
,
1389 /* Check old route path and route has same
1392 if (o_path
->area_id
!= route
->path
.area_id
||
1393 (memcmp(&(o_path
)->origin
, &(route
)->path
.origin
,
1394 sizeof(struct ospf6_ls_origin
)) != 0))
1397 /* Cost is not same then delete current path */
1398 if (o_path
->cost
== route
->path
.cost
)
1401 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1402 prefix2str(&old_route
->prefix
, buf
,
1404 zlog_debug("%s: route %s cost old %u new %u is not same, replace route",
1405 __PRETTY_FUNCTION__
, buf
,
1406 o_path
->cost
, route
->path
.cost
);
1409 /* Remove selected current path's nh from
1410 * effective nh list.
1412 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
, nnode
, nh
)) {
1413 for (ALL_LIST_ELEMENTS(old_route
->nh_list
,
1414 rnode
, rnext
, rnh
)) {
1415 if (!ospf6_nexthop_is_same(rnh
, nh
))
1417 listnode_delete(old_route
->nh_list
,
1419 ospf6_nexthop_delete(rnh
);
1420 route_updated
= true;
1424 listnode_delete(old_route
->paths
, o_path
);
1425 ospf6_path_free(o_path
);
1427 /* Current route's path (adv_router info) is similar
1428 * to route being added.
1429 * Replace current route's path with paths list head.
1430 * Update FIB with effective NHs.
1432 if (listcount(old_route
->paths
)) {
1433 if (route_updated
) {
1434 for (ALL_LIST_ELEMENTS(old_route
->paths
,
1435 anode
, anext
, o_path
)) {
1436 ospf6_merge_nexthops(
1440 /* Update ospf6 route table and
1441 * RIB/FIB with effective
1444 if (oa
->route_table
->hook_add
)
1445 (*oa
->route_table
->hook_add
)
1448 if (old_route
->path
.origin
.id
==
1449 route
->path
.origin
.id
&&
1450 old_route
->path
.origin
.adv_router
==
1451 route
->path
.origin
.adv_router
) {
1452 ospf6_intra_prefix_update_route_origin(
1458 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1459 prefix2str(&old_route
->prefix
, buf
,
1461 zlog_debug("%s: route %s old cost %u new cost %u, delete old entry.",
1462 __PRETTY_FUNCTION__
, buf
,
1463 old_route
->path
.cost
,
1466 if (oa
->route_table
->hook_remove
)
1467 ospf6_route_remove(old_route
,
1470 SET_FLAG(old_route
->flag
,
1471 OSPF6_ROUTE_REMOVE
);
1479 for (old_route
= old
; old_route
; old_route
= old_route
->next
) {
1481 if (!ospf6_route_is_same(old_route
, route
) ||
1482 (old_route
->path
.type
!= route
->path
.type
))
1485 /* Old Route and New Route have Equal Cost, Merge NHs */
1486 if (old_route
->path
.cost
== route
->path
.cost
) {
1489 /* check if this path exists already in
1490 * route->paths list, if so, replace nh_list.
1492 for (ALL_LIST_ELEMENTS_RO(old_route
->paths
, anode
,
1494 if (o_path
->area_id
== route
->path
.area_id
&&
1495 (memcmp(&(o_path
)->origin
,
1496 &(route
)->path
.origin
,
1497 sizeof(struct ospf6_ls_origin
)) == 0))
1500 /* If path is not found in old_route paths's list,
1501 * add a new path to route paths list and merge
1502 * nexthops in route->path->nh_list.
1503 * Otherwise replace existing path's nh_list.
1505 if (o_path
== NULL
) {
1506 ecmp_path
= ospf6_path_dup(&route
->path
);
1508 /* Add a nh_list to new ecmp path */
1509 ospf6_copy_nexthops(ecmp_path
->nh_list
,
1511 /* Add the new path to route's path list */
1512 listnode_add_sort(old_route
->paths
, ecmp_path
);
1514 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1515 prefix2str(&route
->prefix
, buf
,
1518 "%s: route %s %p another path added with nh %u, effective paths %u nh %u",
1519 __PRETTY_FUNCTION__
, buf
,
1521 listcount(ecmp_path
->nh_list
),
1523 listcount(old_route
->paths
) : 0,
1524 listcount(old_route
->nh_list
));
1528 list_delete_all_node(o_path
->nh_list
);
1529 ospf6_copy_nexthops(o_path
->nh_list
,
1534 list_delete_all_node(old_route
->nh_list
);
1536 for (ALL_LIST_ELEMENTS_RO(old_route
->paths
, anode
,
1538 ls_entry
= ospf6_route_lookup(
1541 if (ls_entry
== NULL
) {
1542 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1543 zlog_debug("%s: ls_prfix %s ls_entry not found.",
1544 __PRETTY_FUNCTION__
,
1548 lsa
= ospf6_lsdb_lookup(o_path
->origin
.type
,
1550 o_path
->origin
.adv_router
,
1553 if (IS_OSPF6_DEBUG_EXAMIN(
1555 struct prefix adv_prefix
;
1557 ospf6_linkstate_prefix(
1558 o_path
->origin
.adv_router
,
1559 o_path
->origin
.id
, &adv_prefix
);
1560 prefix2str(&adv_prefix
, buf
,
1562 zlog_debug("%s: adv_router %s lsa not found",
1563 __PRETTY_FUNCTION__
,
1569 (struct ospf6_intra_prefix_lsa
*)
1570 OSPF6_LSA_HEADER_END(lsa
->header
);
1572 if (intra_prefix_lsa
->ref_adv_router
1573 == oa
->ospf6
->router_id
) {
1574 ifp
= if_lookup_prefix(
1578 ospf6_route_add_nexthop(
1583 ospf6_route_merge_nexthops(old_route
,
1588 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1589 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1590 zlog_debug("%s: route %s %p with final effective paths %u nh%u",
1591 __PRETTY_FUNCTION__
, buf
,
1594 listcount(old_route
->paths
) : 0,
1595 listcount(old_route
->nh_list
));
1598 /* used in intra_route_calculation() to add to
1599 * global ospf6 route table.
1601 UNSET_FLAG(old_route
->flag
, OSPF6_ROUTE_REMOVE
);
1602 SET_FLAG(old_route
->flag
, OSPF6_ROUTE_ADD
);
1603 /* Update ospf6 route table and RIB/FIB */
1604 if (oa
->route_table
->hook_add
)
1605 (*oa
->route_table
->hook_add
)(old_route
);
1606 /* Delete the new route its info added to existing
1609 ospf6_route_delete(route
);
1616 /* Add new route to existing node in ospf6 route table. */
1617 ospf6_route_add(route
, oa
->route_table
);
1621 void ospf6_intra_prefix_lsa_add(struct ospf6_lsa
*lsa
)
1623 struct ospf6_area
*oa
;
1624 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1625 struct prefix ls_prefix
;
1626 struct ospf6_route
*route
, *ls_entry
, *old
;
1628 struct ospf6_prefix
*op
;
1629 char *start
, *current
, *end
;
1630 char buf
[PREFIX2STR_BUFFER
];
1631 struct interface
*ifp
;
1632 int direct_connect
= 0;
1633 struct ospf6_path
*path
;
1635 if (OSPF6_LSA_IS_MAXAGE(lsa
))
1638 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1639 zlog_debug("%s: LSA %s found", __PRETTY_FUNCTION__
, lsa
->name
);
1641 oa
= OSPF6_AREA(lsa
->lsdb
->data
);
1644 (struct ospf6_intra_prefix_lsa
*)OSPF6_LSA_HEADER_END(
1646 if (intra_prefix_lsa
->ref_type
== htons(OSPF6_LSTYPE_ROUTER
))
1647 ospf6_linkstate_prefix(intra_prefix_lsa
->ref_adv_router
,
1648 intra_prefix_lsa
->ref_id
, &ls_prefix
);
1649 else if (intra_prefix_lsa
->ref_type
== htons(OSPF6_LSTYPE_NETWORK
))
1650 ospf6_linkstate_prefix(intra_prefix_lsa
->ref_adv_router
,
1651 intra_prefix_lsa
->ref_id
, &ls_prefix
);
1653 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1654 zlog_debug("Unknown reference LS-type: %#hx",
1655 ntohs(intra_prefix_lsa
->ref_type
));
1659 ls_entry
= ospf6_route_lookup(&ls_prefix
, oa
->spf_table
);
1660 if (ls_entry
== NULL
) {
1661 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1662 ospf6_linkstate_prefix2str(&ls_prefix
, buf
,
1664 zlog_debug("LS entry does not exist: %s", buf
);
1669 if (intra_prefix_lsa
->ref_adv_router
== oa
->ospf6
->router_id
) {
1670 /* the intra-prefix are directly connected */
1674 prefix_num
= ntohs(intra_prefix_lsa
->prefix_num
);
1675 start
= (caddr_t
)intra_prefix_lsa
1676 + sizeof(struct ospf6_intra_prefix_lsa
);
1677 end
= OSPF6_LSA_END(lsa
->header
);
1678 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE(op
)) {
1679 op
= (struct ospf6_prefix
*)current
;
1680 if (prefix_num
== 0)
1682 if (end
< current
+ OSPF6_PREFIX_SIZE(op
))
1685 /* Appendix A.4.1.1 */
1686 if (CHECK_FLAG(op
->prefix_options
, OSPF6_PREFIX_OPTION_NU
)) {
1687 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1688 ospf6_linkstate_prefix2str(
1689 (struct prefix
*)OSPF6_PREFIX_BODY(op
),
1692 "%s: Skipping Prefix %s has NU option set",
1698 route
= ospf6_route_create();
1700 memset(&route
->prefix
, 0, sizeof(struct prefix
));
1701 route
->prefix
.family
= AF_INET6
;
1702 route
->prefix
.prefixlen
= op
->prefix_length
;
1703 ospf6_prefix_in6_addr(&route
->prefix
.u
.prefix6
,
1704 intra_prefix_lsa
, op
);
1706 route
->type
= OSPF6_DEST_TYPE_NETWORK
;
1707 route
->path
.origin
.type
= lsa
->header
->type
;
1708 route
->path
.origin
.id
= lsa
->header
->id
;
1709 route
->path
.origin
.adv_router
= lsa
->header
->adv_router
;
1710 route
->path
.prefix_options
= op
->prefix_options
;
1711 route
->path
.area_id
= oa
->area_id
;
1712 route
->path
.type
= OSPF6_PATH_TYPE_INTRA
;
1713 route
->path
.metric_type
= 1;
1715 ls_entry
->path
.cost
+ ntohs(op
->prefix_metric
);
1716 memcpy(&route
->path
.ls_prefix
, &ls_prefix
,
1717 sizeof(struct prefix
));
1718 if (direct_connect
) {
1719 ifp
= if_lookup_prefix(&route
->prefix
, VRF_DEFAULT
);
1721 ospf6_route_add_nexthop(route
, ifp
->ifindex
,
1724 ospf6_route_copy_nexthops(route
, ls_entry
);
1727 path
= ospf6_path_dup(&route
->path
);
1728 ospf6_copy_nexthops(path
->nh_list
, route
->path
.nh_list
);
1729 listnode_add_sort(route
->paths
, path
);
1731 old
= ospf6_route_lookup(&route
->prefix
, oa
->route_table
);
1733 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1734 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1735 zlog_debug("%s Update route: %s old cost %u new cost %u paths %u nh %u",
1736 __PRETTY_FUNCTION__
, buf
,
1737 old
->path
.cost
, route
->path
.cost
,
1738 listcount(route
->paths
),
1739 listcount(route
->nh_list
));
1741 ospf6_intra_prefix_route_ecmp_path(oa
, old
, route
);
1743 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1744 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1745 zlog_debug("%s route %s add with cost %u paths %u nh %u",
1746 __PRETTY_FUNCTION__
, buf
,
1748 listcount(route
->paths
),
1749 listcount(route
->nh_list
));
1751 ospf6_route_add(route
, oa
->route_table
);
1756 if (current
!= end
&& IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1757 zlog_debug("Trailing garbage ignored");
1760 static void ospf6_intra_prefix_lsa_remove_update_route(struct ospf6_lsa
*lsa
,
1761 struct ospf6_area
*oa
,
1762 struct ospf6_route
*route
)
1764 struct listnode
*anode
, *anext
;
1765 struct listnode
*nnode
, *rnode
, *rnext
;
1766 struct ospf6_nexthop
*nh
, *rnh
;
1767 struct ospf6_path
*o_path
;
1768 bool nh_updated
= false;
1769 char buf
[PREFIX2STR_BUFFER
];
1771 /* Iterate all paths of route to find maching
1772 * with LSA remove info.
1773 * If route->path is same, replace
1776 for (ALL_LIST_ELEMENTS(route
->paths
, anode
, anext
, o_path
)) {
1777 if ((o_path
->origin
.type
!= lsa
->header
->type
) ||
1778 (o_path
->origin
.adv_router
!= lsa
->header
->adv_router
) ||
1779 (o_path
->origin
.id
!= lsa
->header
->id
))
1782 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1783 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1785 "%s: route %s path found with cost %u nh %u to remove.",
1786 __PRETTY_FUNCTION__
, buf
, o_path
->cost
,
1787 listcount(o_path
->nh_list
));
1790 /* Remove found path's nh_list from
1791 * the route's nh_list.
1793 for (ALL_LIST_ELEMENTS_RO(o_path
->nh_list
, nnode
, nh
)) {
1794 for (ALL_LIST_ELEMENTS(route
->nh_list
, rnode
,
1796 if (!ospf6_nexthop_is_same(rnh
, nh
))
1798 listnode_delete(route
->nh_list
, rnh
);
1799 ospf6_nexthop_delete(rnh
);
1802 /* Delete the path from route's
1805 listnode_delete(route
->paths
, o_path
);
1806 ospf6_path_free(o_path
);
1812 /* Iterate all paths and merge nexthop,
1813 * unlesss any of the nexthop similar to
1814 * ones deleted as part of path deletion.
1816 for (ALL_LIST_ELEMENTS(route
->paths
, anode
, anext
, o_path
))
1817 ospf6_merge_nexthops(route
->nh_list
, o_path
->nh_list
);
1820 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1821 prefix2str(&route
->prefix
, buf
, sizeof(buf
));
1822 zlog_debug("%s: route %s update paths %u nh %u",
1823 __PRETTY_FUNCTION__
, buf
,
1824 route
->paths
? listcount(route
->paths
) : 0,
1825 route
->nh_list
? listcount(route
->nh_list
)
1829 /* Update Global Route table and
1830 * RIB/FIB with effective
1833 if (oa
->route_table
->hook_add
)
1834 (*oa
->route_table
->hook_add
)(route
);
1836 /* route's primary path is similar
1837 * to LSA, replace route's primary
1838 * path with route's paths list
1841 if ((route
->path
.origin
.id
== lsa
->header
->id
) &&
1842 (route
->path
.origin
.adv_router
==
1843 lsa
->header
->adv_router
)) {
1844 ospf6_intra_prefix_update_route_origin(route
);
1850 void ospf6_intra_prefix_lsa_remove(struct ospf6_lsa
*lsa
)
1852 struct ospf6_area
*oa
;
1853 struct ospf6_intra_prefix_lsa
*intra_prefix_lsa
;
1854 struct prefix prefix
;
1855 struct ospf6_route
*route
, *nroute
;
1857 struct ospf6_prefix
*op
;
1858 char *start
, *current
, *end
;
1859 char buf
[PREFIX2STR_BUFFER
];
1861 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1862 zlog_debug("%s: %s disappearing", __PRETTY_FUNCTION__
,
1865 oa
= OSPF6_AREA(lsa
->lsdb
->data
);
1868 (struct ospf6_intra_prefix_lsa
*)OSPF6_LSA_HEADER_END(
1871 prefix_num
= ntohs(intra_prefix_lsa
->prefix_num
);
1872 start
= (caddr_t
)intra_prefix_lsa
1873 + sizeof(struct ospf6_intra_prefix_lsa
);
1874 end
= OSPF6_LSA_END(lsa
->header
);
1875 for (current
= start
; current
< end
; current
+= OSPF6_PREFIX_SIZE(op
)) {
1876 op
= (struct ospf6_prefix
*)current
;
1877 if (prefix_num
== 0)
1879 if (end
< current
+ OSPF6_PREFIX_SIZE(op
))
1883 memset(&prefix
, 0, sizeof(struct prefix
));
1884 prefix
.family
= AF_INET6
;
1885 prefix
.prefixlen
= op
->prefix_length
;
1886 ospf6_prefix_in6_addr(&prefix
.u
.prefix6
, intra_prefix_lsa
, op
);
1888 route
= ospf6_route_lookup(&prefix
, oa
->route_table
);
1892 for (ospf6_route_lock(route
);
1893 route
&& ospf6_route_is_prefix(&prefix
, route
);
1895 nroute
= ospf6_route_next(route
);
1896 if (route
->type
!= OSPF6_DEST_TYPE_NETWORK
)
1898 if (route
->path
.area_id
!= oa
->area_id
)
1900 if (route
->path
.type
!= OSPF6_PATH_TYPE_INTRA
)
1902 /* Route has multiple ECMP paths, remove matching
1903 * path. Update current route's effective nh list
1904 * after removal of one of the path.
1906 if (listcount(route
->paths
) > 1) {
1907 ospf6_intra_prefix_lsa_remove_update_route(
1911 if (route
->path
.origin
.type
!= lsa
->header
->type
1912 || route
->path
.origin
.id
!= lsa
->header
->id
1913 || route
->path
.origin
.adv_router
1914 != lsa
->header
->adv_router
)
1917 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
)) {
1918 prefix2str(&route
->prefix
, buf
,
1920 zlog_debug("%s: route remove %s with path type %u cost %u paths %u nh %u",
1921 __PRETTY_FUNCTION__
, buf
,
1924 listcount(route
->paths
),
1925 listcount(route
->nh_list
));
1927 ospf6_route_remove(route
, oa
->route_table
);
1931 ospf6_route_unlock(route
);
1934 if (current
!= end
&& IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1935 zlog_debug("Trailing garbage ignored");
1938 void ospf6_intra_route_calculation(struct ospf6_area
*oa
)
1940 struct ospf6_route
*route
, *nroute
;
1942 struct ospf6_lsa
*lsa
;
1943 void (*hook_add
)(struct ospf6_route
*) = NULL
;
1944 void (*hook_remove
)(struct ospf6_route
*) = NULL
;
1946 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1947 zlog_debug("Re-examin intra-routes for area %s", oa
->name
);
1949 hook_add
= oa
->route_table
->hook_add
;
1950 hook_remove
= oa
->route_table
->hook_remove
;
1951 oa
->route_table
->hook_add
= NULL
;
1952 oa
->route_table
->hook_remove
= NULL
;
1954 for (route
= ospf6_route_head(oa
->route_table
); route
;
1955 route
= ospf6_route_next(route
))
1956 route
->flag
= OSPF6_ROUTE_REMOVE
;
1958 type
= htons(OSPF6_LSTYPE_INTRA_PREFIX
);
1959 for (ALL_LSDB_TYPED(oa
->lsdb
, type
, lsa
))
1960 ospf6_intra_prefix_lsa_add(lsa
);
1962 oa
->route_table
->hook_add
= hook_add
;
1963 oa
->route_table
->hook_remove
= hook_remove
;
1965 for (route
= ospf6_route_head(oa
->route_table
); route
; route
= nroute
) {
1966 nroute
= ospf6_route_next(route
);
1967 if (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
)
1968 && CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
)) {
1969 UNSET_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
);
1970 UNSET_FLAG(route
->flag
, OSPF6_ROUTE_ADD
);
1973 if (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_REMOVE
))
1974 ospf6_route_remove(route
, oa
->route_table
);
1975 else if (CHECK_FLAG(route
->flag
, OSPF6_ROUTE_ADD
)
1976 || CHECK_FLAG(route
->flag
, OSPF6_ROUTE_CHANGE
)) {
1981 /* Redo the summaries as things might have changed */
1982 ospf6_abr_originate_summary(route
);
1987 if (IS_OSPF6_DEBUG_EXAMIN(INTRA_PREFIX
))
1988 zlog_debug("Re-examin intra-routes for area %s: Done",
1992 static void ospf6_brouter_debug_print(struct ospf6_route
*brouter
)
1994 uint32_t brouter_id
;
1995 char brouter_name
[16];
1997 char destination
[64];
1998 char installed
[64], changed
[64];
1999 struct timeval now
, res
;
2000 char id
[16], adv_router
[16];
2001 char capa
[16], options
[16];
2003 brouter_id
= ADV_ROUTER_IN_PREFIX(&brouter
->prefix
);
2004 inet_ntop(AF_INET
, &brouter_id
, brouter_name
, sizeof(brouter_name
));
2005 inet_ntop(AF_INET
, &brouter
->path
.area_id
, area_name
,
2007 ospf6_linkstate_prefix2str(&brouter
->prefix
, destination
,
2008 sizeof(destination
));
2011 timersub(&now
, &brouter
->installed
, &res
);
2012 timerstring(&res
, installed
, sizeof(installed
));
2015 timersub(&now
, &brouter
->changed
, &res
);
2016 timerstring(&res
, changed
, sizeof(changed
));
2018 inet_ntop(AF_INET
, &brouter
->path
.origin
.id
, id
, sizeof(id
));
2019 inet_ntop(AF_INET
, &brouter
->path
.origin
.adv_router
, adv_router
,
2020 sizeof(adv_router
));
2022 ospf6_options_printbuf(brouter
->path
.options
, options
, sizeof(options
));
2023 ospf6_capability_printbuf(brouter
->path
.router_bits
, capa
,
2026 zlog_info("Brouter: %s via area %s", brouter_name
, area_name
);
2027 zlog_info(" memory: prev: %p this: %p next: %p parent rnode: %p",
2028 (void *)brouter
->prev
, (void *)brouter
, (void *)brouter
->next
,
2029 (void *)brouter
->rnode
);
2030 zlog_info(" type: %d prefix: %s installed: %s changed: %s",
2031 brouter
->type
, destination
, installed
, changed
);
2032 zlog_info(" lock: %d flags: %s%s%s%s", brouter
->lock
,
2033 (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_BEST
) ? "B" : "-"),
2034 (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_ADD
) ? "A" : "-"),
2035 (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
) ? "R" : "-"),
2036 (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_CHANGE
) ? "C" : "-"));
2037 zlog_info(" path type: %s ls-origin %s id: %s adv-router %s",
2038 OSPF6_PATH_TYPE_NAME(brouter
->path
.type
),
2039 ospf6_lstype_name(brouter
->path
.origin
.type
), id
, adv_router
);
2040 zlog_info(" options: %s router-bits: %s metric-type: %d metric: %d/%d",
2041 options
, capa
, brouter
->path
.metric_type
, brouter
->path
.cost
,
2042 brouter
->path
.u
.cost_e2
);
2043 zlog_info(" paths %u nh %u", listcount(brouter
->paths
),
2044 listcount(brouter
->nh_list
));
2047 void ospf6_intra_brouter_calculation(struct ospf6_area
*oa
)
2049 struct ospf6_route
*brouter
, *nbrouter
, *copy
;
2050 void (*hook_add
)(struct ospf6_route
*) = NULL
;
2051 void (*hook_remove
)(struct ospf6_route
*) = NULL
;
2052 uint32_t brouter_id
;
2053 char brouter_name
[16];
2055 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(oa
->area_id
) ||
2056 IS_OSPF6_DEBUG_ROUTE(MEMORY
))
2057 zlog_info("%s: border-router calculation for area %s",
2058 __PRETTY_FUNCTION__
, oa
->name
);
2060 hook_add
= oa
->ospf6
->brouter_table
->hook_add
;
2061 hook_remove
= oa
->ospf6
->brouter_table
->hook_remove
;
2062 oa
->ospf6
->brouter_table
->hook_add
= NULL
;
2063 oa
->ospf6
->brouter_table
->hook_remove
= NULL
;
2065 /* withdraw the previous router entries for the area */
2066 for (brouter
= ospf6_route_head(oa
->ospf6
->brouter_table
); brouter
;
2067 brouter
= ospf6_route_next(brouter
)) {
2068 brouter_id
= ADV_ROUTER_IN_PREFIX(&brouter
->prefix
);
2069 inet_ntop(AF_INET
, &brouter_id
, brouter_name
,
2070 sizeof(brouter_name
));
2072 if (brouter
->path
.area_id
!= oa
->area_id
)
2075 SET_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
);
2077 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(brouter_id
)
2078 || IS_OSPF6_DEBUG_ROUTE(MEMORY
)) {
2079 zlog_info("%p: mark as removing: area %s brouter %s",
2080 (void *)brouter
, oa
->name
, brouter_name
);
2081 ospf6_brouter_debug_print(brouter
);
2085 for (brouter
= ospf6_route_head(oa
->spf_table
); brouter
;
2086 brouter
= ospf6_route_next(brouter
)) {
2087 brouter_id
= ADV_ROUTER_IN_PREFIX(&brouter
->prefix
);
2088 inet_ntop(AF_INET
, &brouter_id
, brouter_name
,
2089 sizeof(brouter_name
));
2091 if (brouter
->type
!= OSPF6_DEST_TYPE_LINKSTATE
)
2094 if (ospf6_linkstate_prefix_id(&brouter
->prefix
) != htonl(0))
2097 if (!CHECK_FLAG(brouter
->path
.router_bits
, OSPF6_ROUTER_BIT_E
)
2098 && !CHECK_FLAG(brouter
->path
.router_bits
,
2099 OSPF6_ROUTER_BIT_B
))
2102 if (!OSPF6_OPT_ISSET(brouter
->path
.options
, OSPF6_OPT_V6
)
2103 || !OSPF6_OPT_ISSET(brouter
->path
.options
, OSPF6_OPT_R
))
2106 copy
= ospf6_route_copy(brouter
);
2107 copy
->type
= OSPF6_DEST_TYPE_ROUTER
;
2108 copy
->path
.area_id
= oa
->area_id
;
2109 ospf6_route_add(copy
, oa
->ospf6
->brouter_table
);
2111 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(brouter_id
)
2112 || IS_OSPF6_DEBUG_ROUTE(MEMORY
)) {
2113 zlog_info("%p: transfer: area %s brouter %s",
2114 (void *)brouter
, oa
->name
, brouter_name
);
2115 ospf6_brouter_debug_print(brouter
);
2119 oa
->ospf6
->brouter_table
->hook_add
= hook_add
;
2120 oa
->ospf6
->brouter_table
->hook_remove
= hook_remove
;
2122 for (brouter
= ospf6_route_head(oa
->ospf6
->brouter_table
); brouter
;
2123 brouter
= nbrouter
) {
2126 * brouter may have been "deleted" in the last loop iteration.
2127 * If this is the case there is still 1 final refcount lock
2128 * taken by ospf6_route_next, that will be released by the same
2129 * call and result in deletion. To avoid heap UAF we must then
2130 * skip processing the deleted route.
2132 if (brouter
->lock
== 1) {
2133 if (IS_OSPF6_DEBUG_ROUTE(MEMORY
))
2134 ospf6_brouter_debug_print(brouter
);
2135 nbrouter
= ospf6_route_next(brouter
);
2138 nbrouter
= ospf6_route_next(brouter
);
2141 brouter_id
= ADV_ROUTER_IN_PREFIX(&brouter
->prefix
);
2142 inet_ntop(AF_INET
, &brouter_id
, brouter_name
,
2143 sizeof(brouter_name
));
2145 if (brouter
->path
.area_id
!= oa
->area_id
)
2148 if (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_WAS_REMOVED
))
2151 /* After iterating spf_table for all routers including
2152 * intra brouter, clear mark for remove flag for
2153 * inter border router if its adv router present in
2156 if (brouter
->path
.type
== OSPF6_PATH_TYPE_INTER
) {
2157 struct prefix adv_prefix
;
2159 ospf6_linkstate_prefix(brouter
->path
.origin
.adv_router
,
2160 htonl(0), &adv_prefix
);
2162 if (ospf6_route_lookup(&adv_prefix
, oa
->spf_table
)) {
2163 if (IS_OSPF6_DEBUG_BROUTER
) {
2164 zlog_debug("%s: keep inter brouter %s as adv router 0x%x found in spf",
2165 __PRETTY_FUNCTION__
,
2167 brouter
->path
.origin
.adv_router
);
2168 ospf6_brouter_debug_print(brouter
);
2170 UNSET_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
);
2174 if (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
)
2175 && CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_ADD
)) {
2176 UNSET_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
);
2177 UNSET_FLAG(brouter
->flag
, OSPF6_ROUTE_ADD
);
2180 if (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_REMOVE
)) {
2181 if (IS_OSPF6_DEBUG_BROUTER
2182 || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(
2184 || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(
2186 zlog_info("%s: brouter %s disappears via area %s",
2187 __PRETTY_FUNCTION__
, brouter_name
,
2189 /* This is used to protect nbrouter from removed from
2190 * the table. For an example, ospf6_abr_examin_summary,
2191 * removes brouters which are marked for remove.
2193 oa
->intra_brouter_calc
= 1;
2194 ospf6_route_remove(brouter
, oa
->ospf6
->brouter_table
);
2196 } else if (CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_ADD
)
2197 || CHECK_FLAG(brouter
->flag
, OSPF6_ROUTE_CHANGE
)) {
2198 if (IS_OSPF6_DEBUG_BROUTER
2199 || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(
2201 || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(
2203 zlog_info("%s: brouter %s appears via area %s",
2204 __PRETTY_FUNCTION__
, brouter_name
,
2209 (*hook_add
)(brouter
);
2211 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ID(
2213 || IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(
2215 zlog_info("brouter %s still exists via area %s",
2216 brouter_name
, oa
->name
);
2217 /* But re-originate summaries */
2218 ospf6_abr_originate_summary(brouter
);
2222 UNSET_FLAG(brouter
->flag
, OSPF6_ROUTE_ADD
);
2223 UNSET_FLAG(brouter
->flag
, OSPF6_ROUTE_CHANGE
);
2225 /* Reset for nbrouter */
2226 oa
->intra_brouter_calc
= 0;
2229 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ID(oa
->area_id
) ||
2230 IS_OSPF6_DEBUG_ROUTE(MEMORY
))
2231 zlog_info("%s: border-router calculation for area %s: done",
2232 __PRETTY_FUNCTION__
, oa
->name
);
2235 static const struct ospf6_lsa_handler router_handler
= {
2236 .lh_type
= OSPF6_LSTYPE_ROUTER
,
2237 .lh_name
= "Router",
2238 .lh_short_name
= "Rtr",
2239 .lh_show
= ospf6_router_lsa_show
,
2240 .lh_get_prefix_str
= ospf6_router_lsa_get_nbr_id
,
2243 static const struct ospf6_lsa_handler network_handler
= {
2244 .lh_type
= OSPF6_LSTYPE_NETWORK
,
2245 .lh_name
= "Network",
2246 .lh_short_name
= "Net",
2247 .lh_show
= ospf6_network_lsa_show
,
2248 .lh_get_prefix_str
= ospf6_network_lsa_get_ar_id
,
2251 static const struct ospf6_lsa_handler link_handler
= {
2252 .lh_type
= OSPF6_LSTYPE_LINK
,
2254 .lh_short_name
= "Lnk",
2255 .lh_show
= ospf6_link_lsa_show
,
2256 .lh_get_prefix_str
= ospf6_link_lsa_get_prefix_str
,
2259 static const struct ospf6_lsa_handler intra_prefix_handler
= {
2260 .lh_type
= OSPF6_LSTYPE_INTRA_PREFIX
,
2261 .lh_name
= "Intra-Prefix",
2262 .lh_short_name
= "INP",
2263 .lh_show
= ospf6_intra_prefix_lsa_show
,
2264 .lh_get_prefix_str
= ospf6_intra_prefix_lsa_get_prefix_str
,
2267 void ospf6_intra_init(void)
2269 ospf6_install_lsa_handler(&router_handler
);
2270 ospf6_install_lsa_handler(&network_handler
);
2271 ospf6_install_lsa_handler(&link_handler
);
2272 ospf6_install_lsa_handler(&intra_prefix_handler
);
2275 DEFUN (debug_ospf6_brouter
,
2276 debug_ospf6_brouter_cmd
,
2277 "debug ospf6 border-routers",
2280 "Debug border router\n"
2283 OSPF6_DEBUG_BROUTER_ON();
2287 DEFUN (no_debug_ospf6_brouter
,
2288 no_debug_ospf6_brouter_cmd
,
2289 "no debug ospf6 border-routers",
2293 "Debug border router\n"
2296 OSPF6_DEBUG_BROUTER_OFF();
2300 DEFUN (debug_ospf6_brouter_router
,
2301 debug_ospf6_brouter_router_cmd
,
2302 "debug ospf6 border-routers router-id A.B.C.D",
2305 "Debug border router\n"
2306 "Debug specific border router\n"
2307 "Specify border-router's router-id\n"
2312 inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &router_id
);
2313 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_ON(router_id
);
2317 DEFUN (no_debug_ospf6_brouter_router
,
2318 no_debug_ospf6_brouter_router_cmd
,
2319 "no debug ospf6 border-routers router-id",
2323 "Debug border router\n"
2324 "Debug specific border router\n"
2327 OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER_OFF();
2331 DEFUN (debug_ospf6_brouter_area
,
2332 debug_ospf6_brouter_area_cmd
,
2333 "debug ospf6 border-routers area-id A.B.C.D",
2336 "Debug border router\n"
2337 "Debug border routers in specific Area\n"
2343 inet_pton(AF_INET
, argv
[idx_ipv4
]->arg
, &area_id
);
2344 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_ON(area_id
);
2348 DEFUN (no_debug_ospf6_brouter_area
,
2349 no_debug_ospf6_brouter_area_cmd
,
2350 "no debug ospf6 border-routers area-id",
2354 "Debug border router\n"
2355 "Debug border routers in specific Area\n"
2358 OSPF6_DEBUG_BROUTER_SPECIFIC_AREA_OFF();
2362 int config_write_ospf6_debug_brouter(struct vty
*vty
)
2365 if (IS_OSPF6_DEBUG_BROUTER
)
2366 vty_out(vty
, "debug ospf6 border-routers\n");
2367 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_ROUTER
) {
2368 inet_ntop(AF_INET
, &conf_debug_ospf6_brouter_specific_router_id
,
2370 vty_out(vty
, "debug ospf6 border-routers router-id %s\n", buf
);
2372 if (IS_OSPF6_DEBUG_BROUTER_SPECIFIC_AREA
) {
2373 inet_ntop(AF_INET
, &conf_debug_ospf6_brouter_specific_area_id
,
2375 vty_out(vty
, "debug ospf6 border-routers area-id %s\n", buf
);
2380 void install_element_ospf6_debug_brouter(void)
2382 install_element(ENABLE_NODE
, &debug_ospf6_brouter_cmd
);
2383 install_element(ENABLE_NODE
, &debug_ospf6_brouter_router_cmd
);
2384 install_element(ENABLE_NODE
, &debug_ospf6_brouter_area_cmd
);
2385 install_element(ENABLE_NODE
, &no_debug_ospf6_brouter_cmd
);
2386 install_element(ENABLE_NODE
, &no_debug_ospf6_brouter_router_cmd
);
2387 install_element(ENABLE_NODE
, &no_debug_ospf6_brouter_area_cmd
);
2388 install_element(CONFIG_NODE
, &debug_ospf6_brouter_cmd
);
2389 install_element(CONFIG_NODE
, &debug_ospf6_brouter_router_cmd
);
2390 install_element(CONFIG_NODE
, &debug_ospf6_brouter_area_cmd
);
2391 install_element(CONFIG_NODE
, &no_debug_ospf6_brouter_cmd
);
2392 install_element(CONFIG_NODE
, &no_debug_ospf6_brouter_router_cmd
);
2393 install_element(CONFIG_NODE
, &no_debug_ospf6_brouter_area_cmd
);