paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 2 | * Copyright (C) 2003 Yasuhiro Ohara |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 3 | * |
| 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 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 22 | #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 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 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" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 39 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 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" |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 46 | #include "ospf6_abr.h" |
| 47 | #include "ospf6_flood.h" |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 48 | #include "ospf6d.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 50 | /******************************/ |
| 51 | /* RFC2740 3.4.3.1 Router-LSA */ |
| 52 | /******************************/ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 53 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 54 | int |
| 55 | ospf6_router_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 56 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 57 | char *start, *end, *current; |
| 58 | char buf[32], name[32], bits[16], options[32]; |
| 59 | struct ospf6_router_lsa *router_lsa; |
| 60 | struct ospf6_router_lsdesc *lsdesc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 61 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 62 | router_lsa = (struct ospf6_router_lsa *) |
| 63 | ((char *) lsa->header + sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 64 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 65 | ospf6_capability_printbuf (router_lsa->bits, bits, sizeof (bits)); |
| 66 | ospf6_options_printbuf (router_lsa->options, options, sizeof (options)); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 67 | vty_out (vty, " Bits: %s Options: %s%s", bits, options, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 69 | start = (char *) router_lsa + sizeof (struct ospf6_router_lsa); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 70 | end = (char *) lsa->header + ntohs (lsa->header->length); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 71 | for (current = start; current + sizeof (struct ospf6_router_lsdesc) <= end; |
| 72 | current += sizeof (struct ospf6_router_lsdesc)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 73 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 74 | lsdesc = (struct ospf6_router_lsdesc *) current; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 75 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 76 | if (lsdesc->type == OSPF6_ROUTER_LSDESC_POINTTOPOINT) |
| 77 | snprintf (name, sizeof (name), "Point-To-Point"); |
| 78 | else if (lsdesc->type == OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK) |
| 79 | snprintf (name, sizeof (name), "Transit-Network"); |
| 80 | else if (lsdesc->type == OSPF6_ROUTER_LSDESC_STUB_NETWORK) |
| 81 | snprintf (name, sizeof (name), "Stub-Network"); |
| 82 | else if (lsdesc->type == OSPF6_ROUTER_LSDESC_VIRTUAL_LINK) |
| 83 | snprintf (name, sizeof (name), "Virtual-Link"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 84 | else |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 85 | snprintf (name, sizeof (name), "Unknown (%#x)", lsdesc->type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 86 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 87 | vty_out (vty, " Type: %s Metric: %d%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 88 | name, ntohs (lsdesc->metric), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 89 | vty_out (vty, " Interface ID: %s%s", |
| 90 | inet_ntop (AF_INET, &lsdesc->interface_id, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 91 | buf, sizeof (buf)), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 92 | vty_out (vty, " Neighbor Interface ID: %s%s", |
| 93 | inet_ntop (AF_INET, &lsdesc->neighbor_interface_id, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 94 | buf, sizeof (buf)), VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 95 | vty_out (vty, " Neighbor Router ID: %s%s", |
| 96 | inet_ntop (AF_INET, &lsdesc->neighbor_router_id, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 97 | buf, sizeof (buf)), VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 98 | } |
| 99 | return 0; |
| 100 | } |
| 101 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 102 | int |
| 103 | ospf6_router_lsa_originate (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 105 | struct ospf6_area *oa; |
| 106 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 107 | char buffer [OSPF6_MAX_LSASIZE]; |
| 108 | struct ospf6_lsa_header *lsa_header; |
| 109 | struct ospf6_lsa *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 110 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 111 | u_int32_t link_state_id = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 112 | struct listnode *node, *nnode; |
| 113 | struct listnode *j; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 114 | struct ospf6_interface *oi; |
| 115 | struct ospf6_neighbor *on, *drouter = NULL; |
| 116 | struct ospf6_router_lsa *router_lsa; |
| 117 | struct ospf6_router_lsdesc *lsdesc; |
| 118 | u_int16_t type; |
| 119 | u_int32_t router; |
| 120 | int count; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 122 | oa = (struct ospf6_area *) THREAD_ARG (thread); |
| 123 | oa->thread_router_lsa = NULL; |
| 124 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 125 | if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 126 | zlog_debug ("Originate Router-LSA for Area %s", oa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 127 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 128 | memset (buffer, 0, sizeof (buffer)); |
| 129 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 130 | router_lsa = (struct ospf6_router_lsa *) |
| 131 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 132 | |
| 133 | OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_V6); |
| 134 | OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_E); |
| 135 | OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_MC); |
| 136 | OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_N); |
| 137 | OSPF6_OPT_SET (router_lsa->options, OSPF6_OPT_R); |
| 138 | OSPF6_OPT_CLEAR (router_lsa->options, OSPF6_OPT_DC); |
| 139 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 140 | if (ospf6_is_router_abr (ospf6)) |
| 141 | SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B); |
| 142 | else |
| 143 | UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_B); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 144 | if (ospf6_asbr_is_asbr (ospf6)) |
| 145 | SET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E); |
| 146 | else |
| 147 | UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_E); |
| 148 | UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_V); |
| 149 | UNSET_FLAG (router_lsa->bits, OSPF6_ROUTER_BIT_W); |
| 150 | |
| 151 | /* describe links for each interfaces */ |
| 152 | lsdesc = (struct ospf6_router_lsdesc *) |
| 153 | ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa)); |
| 154 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 155 | for (ALL_LIST_ELEMENTS (oa->if_list, node, nnode, oi)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 156 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 157 | /* Interfaces in state Down or Loopback are not described */ |
| 158 | if (oi->state == OSPF6_INTERFACE_DOWN || |
| 159 | oi->state == OSPF6_INTERFACE_LOOPBACK) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 160 | continue; |
| 161 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 162 | /* Nor are interfaces without any full adjacencies described */ |
| 163 | count = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 164 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) |
| 165 | if (on->state == OSPF6_NEIGHBOR_FULL) |
| 166 | count++; |
| 167 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 168 | if (count == 0) |
| 169 | continue; |
| 170 | |
| 171 | /* Multiple Router-LSA instance according to size limit setting */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 172 | if ( (oa->router_lsa_size_limit != 0) |
| 173 | && ((caddr_t) lsdesc + sizeof (struct ospf6_router_lsdesc) - |
gdt | 1686f93 | 2004-12-09 14:47:09 +0000 | [diff] [blame] | 174 | /* XXX warning: comparison between signed and unsigned */ |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 175 | (caddr_t) buffer > oa->router_lsa_size_limit)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 176 | { |
| 177 | if ((caddr_t) lsdesc == (caddr_t) router_lsa + |
| 178 | sizeof (struct ospf6_router_lsa)) |
| 179 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 180 | if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 181 | zlog_debug ("Size limit setting for Router-LSA too short"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 182 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 183 | } |
| 184 | |
| 185 | /* Fill LSA Header */ |
| 186 | lsa_header->age = 0; |
| 187 | lsa_header->type = htons (OSPF6_LSTYPE_ROUTER); |
| 188 | lsa_header->id = htonl (link_state_id); |
| 189 | lsa_header->adv_router = oa->ospf6->router_id; |
| 190 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 191 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 192 | lsa_header->adv_router, oa->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 193 | lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer); |
| 194 | |
| 195 | /* LSA checksum */ |
| 196 | ospf6_lsa_checksum (lsa_header); |
| 197 | |
| 198 | /* create LSA */ |
| 199 | lsa = ospf6_lsa_create (lsa_header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 200 | |
| 201 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 202 | ospf6_lsa_originate_area (lsa, oa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 203 | |
| 204 | /* Reset setting for consecutive origination */ |
| 205 | memset ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa), |
| 206 | 0, (caddr_t) lsdesc - (caddr_t) router_lsa); |
| 207 | lsdesc = (struct ospf6_router_lsdesc *) |
| 208 | ((caddr_t) router_lsa + sizeof (struct ospf6_router_lsa)); |
| 209 | link_state_id ++; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 210 | } |
| 211 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 212 | /* Point-to-Point interfaces */ |
| 213 | if (if_is_pointopoint (oi->interface)) |
| 214 | { |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 215 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 216 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 217 | if (on->state != OSPF6_NEIGHBOR_FULL) |
| 218 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 219 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 220 | lsdesc->type = OSPF6_ROUTER_LSDESC_POINTTOPOINT; |
| 221 | lsdesc->metric = htons (oi->cost); |
| 222 | lsdesc->interface_id = htonl (oi->interface->ifindex); |
| 223 | lsdesc->neighbor_interface_id = htonl (on->ifindex); |
| 224 | lsdesc->neighbor_router_id = on->router_id; |
| 225 | |
| 226 | lsdesc++; |
| 227 | } |
| 228 | } |
| 229 | |
| 230 | /* Broadcast and NBMA interfaces */ |
| 231 | if (if_is_broadcast (oi->interface)) |
| 232 | { |
| 233 | /* If this router is not DR, |
| 234 | and If this router not fully adjacent with DR, |
| 235 | this interface is not transit yet: ignore. */ |
| 236 | if (oi->state != OSPF6_INTERFACE_DR) |
| 237 | { |
| 238 | drouter = ospf6_neighbor_lookup (oi->drouter, oi); |
| 239 | if (drouter == NULL || drouter->state != OSPF6_NEIGHBOR_FULL) |
| 240 | continue; |
| 241 | } |
| 242 | |
| 243 | lsdesc->type = OSPF6_ROUTER_LSDESC_TRANSIT_NETWORK; |
| 244 | lsdesc->metric = htons (oi->cost); |
| 245 | lsdesc->interface_id = htonl (oi->interface->ifindex); |
| 246 | if (oi->state != OSPF6_INTERFACE_DR) |
| 247 | { |
| 248 | lsdesc->neighbor_interface_id = htonl (drouter->ifindex); |
| 249 | lsdesc->neighbor_router_id = drouter->router_id; |
| 250 | } |
| 251 | else |
| 252 | { |
| 253 | lsdesc->neighbor_interface_id = htonl (oi->interface->ifindex); |
| 254 | lsdesc->neighbor_router_id = oi->area->ospf6->router_id; |
| 255 | } |
| 256 | |
| 257 | lsdesc++; |
| 258 | } |
| 259 | |
| 260 | /* Virtual links */ |
| 261 | /* xxx */ |
| 262 | /* Point-to-Multipoint interfaces */ |
| 263 | /* xxx */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 265 | |
| 266 | if ((caddr_t) lsdesc != (caddr_t) router_lsa + |
| 267 | sizeof (struct ospf6_router_lsa)) |
| 268 | { |
| 269 | /* Fill LSA Header */ |
| 270 | lsa_header->age = 0; |
| 271 | lsa_header->type = htons (OSPF6_LSTYPE_ROUTER); |
| 272 | lsa_header->id = htonl (link_state_id); |
| 273 | lsa_header->adv_router = oa->ospf6->router_id; |
| 274 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 275 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 276 | lsa_header->adv_router, oa->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 277 | lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer); |
| 278 | |
| 279 | /* LSA checksum */ |
| 280 | ospf6_lsa_checksum (lsa_header); |
| 281 | |
| 282 | /* create LSA */ |
| 283 | lsa = ospf6_lsa_create (lsa_header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 284 | |
| 285 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 286 | ospf6_lsa_originate_area (lsa, oa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 287 | |
| 288 | link_state_id ++; |
| 289 | } |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 290 | else |
| 291 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 292 | if (IS_OSPF6_DEBUG_ORIGINATE (ROUTER)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 293 | zlog_debug ("Nothing to describe in Router-LSA, suppress"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 294 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 295 | |
| 296 | /* Do premature-aging of rest, undesired Router-LSAs */ |
| 297 | type = ntohs (OSPF6_LSTYPE_ROUTER); |
| 298 | router = oa->ospf6->router_id; |
| 299 | for (lsa = ospf6_lsdb_type_router_head (type, router, oa->lsdb); lsa; |
| 300 | lsa = ospf6_lsdb_type_router_next (type, router, lsa)) |
| 301 | { |
| 302 | if (ntohl (lsa->header->id) < link_state_id) |
| 303 | continue; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 304 | ospf6_lsa_purge (lsa); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 305 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 310 | /*******************************/ |
| 311 | /* RFC2740 3.4.3.2 Network-LSA */ |
| 312 | /*******************************/ |
| 313 | |
| 314 | int |
| 315 | ospf6_network_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 316 | { |
| 317 | char *start, *end, *current; |
| 318 | struct ospf6_network_lsa *network_lsa; |
| 319 | struct ospf6_network_lsdesc *lsdesc; |
| 320 | char buf[128], options[32]; |
| 321 | |
| 322 | network_lsa = (struct ospf6_network_lsa *) |
| 323 | ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header)); |
| 324 | |
| 325 | ospf6_options_printbuf (network_lsa->options, options, sizeof (options)); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 326 | vty_out (vty, " Options: %s%s", options, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 327 | |
| 328 | start = (char *) network_lsa + sizeof (struct ospf6_network_lsa); |
| 329 | end = (char *) lsa->header + ntohs (lsa->header->length); |
| 330 | for (current = start; current + sizeof (struct ospf6_network_lsdesc) <= end; |
| 331 | current += sizeof (struct ospf6_network_lsdesc)) |
| 332 | { |
| 333 | lsdesc = (struct ospf6_network_lsdesc *) current; |
| 334 | inet_ntop (AF_INET, &lsdesc->router_id, buf, sizeof (buf)); |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 335 | vty_out (vty, " Attached Router: %s%s", buf, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 336 | } |
| 337 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | } |
| 339 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 340 | int |
| 341 | ospf6_network_lsa_originate (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 342 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 343 | struct ospf6_interface *oi; |
| 344 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 345 | char buffer [OSPF6_MAX_LSASIZE]; |
| 346 | struct ospf6_lsa_header *lsa_header; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 347 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 348 | int count; |
| 349 | struct ospf6_lsa *old, *lsa; |
| 350 | struct ospf6_network_lsa *network_lsa; |
| 351 | struct ospf6_network_lsdesc *lsdesc; |
| 352 | struct ospf6_neighbor *on; |
| 353 | struct ospf6_link_lsa *link_lsa; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 354 | struct listnode *i; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 355 | u_int16_t type; |
| 356 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 357 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 358 | oi->thread_network_lsa = NULL; |
| 359 | |
| 360 | /* The interface must be enabled until here. A Network-LSA of a |
| 361 | disabled interface (but was once enabled) should be flushed |
| 362 | by ospf6_lsa_refresh (), and does not come here. */ |
| 363 | assert (oi->area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 364 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 365 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_NETWORK), |
| 366 | htonl (oi->interface->ifindex), |
| 367 | oi->area->ospf6->router_id, oi->area->lsdb); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 368 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 369 | /* Do not originate Network-LSA if not DR */ |
| 370 | if (oi->state != OSPF6_INTERFACE_DR) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 371 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 372 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 373 | ospf6_lsa_purge (old); |
| 374 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 375 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 376 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 377 | if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 378 | zlog_debug ("Originate Network-LSA for Interface %s", oi->interface->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 379 | |
| 380 | /* If none of neighbor is adjacent to us */ |
| 381 | count = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 382 | |
| 383 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) |
| 384 | if (on->state == OSPF6_NEIGHBOR_FULL) |
| 385 | count++; |
| 386 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 387 | if (count == 0) |
| 388 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 389 | if (IS_OSPF6_DEBUG_ORIGINATE (NETWORK)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 390 | zlog_debug ("Interface stub, ignore"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 391 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 392 | ospf6_lsa_purge (old); |
| 393 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 394 | } |
| 395 | |
| 396 | /* prepare buffer */ |
| 397 | memset (buffer, 0, sizeof (buffer)); |
| 398 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 399 | network_lsa = (struct ospf6_network_lsa *) |
| 400 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 401 | |
| 402 | /* Collect the interface's Link-LSAs to describe |
| 403 | network's optional capabilities */ |
| 404 | type = htons (OSPF6_LSTYPE_LINK); |
| 405 | for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa; |
| 406 | lsa = ospf6_lsdb_type_next (type, lsa)) |
| 407 | { |
| 408 | link_lsa = (struct ospf6_link_lsa *) |
| 409 | ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header)); |
| 410 | network_lsa->options[0] |= link_lsa->options[0]; |
| 411 | network_lsa->options[1] |= link_lsa->options[1]; |
| 412 | network_lsa->options[2] |= link_lsa->options[2]; |
| 413 | } |
| 414 | |
| 415 | lsdesc = (struct ospf6_network_lsdesc *) |
| 416 | ((caddr_t) network_lsa + sizeof (struct ospf6_network_lsa)); |
| 417 | |
| 418 | /* set Link Description to the router itself */ |
| 419 | lsdesc->router_id = oi->area->ospf6->router_id; |
| 420 | lsdesc++; |
| 421 | |
| 422 | /* Walk through the neighbors */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 423 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 424 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 425 | if (on->state != OSPF6_NEIGHBOR_FULL) |
| 426 | continue; |
| 427 | |
| 428 | /* set this neighbor's Router-ID to LSA */ |
| 429 | lsdesc->router_id = on->router_id; |
| 430 | lsdesc++; |
| 431 | } |
| 432 | |
| 433 | /* Fill LSA Header */ |
| 434 | lsa_header->age = 0; |
| 435 | lsa_header->type = htons (OSPF6_LSTYPE_NETWORK); |
| 436 | lsa_header->id = htonl (oi->interface->ifindex); |
| 437 | lsa_header->adv_router = oi->area->ospf6->router_id; |
| 438 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 439 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 440 | lsa_header->adv_router, oi->area->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 441 | lsa_header->length = htons ((caddr_t) lsdesc - (caddr_t) buffer); |
| 442 | |
| 443 | /* LSA checksum */ |
| 444 | ospf6_lsa_checksum (lsa_header); |
| 445 | |
| 446 | /* create LSA */ |
| 447 | lsa = ospf6_lsa_create (lsa_header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 448 | |
| 449 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 450 | ospf6_lsa_originate_area (lsa, oi->area); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 451 | |
| 452 | return 0; |
| 453 | } |
| 454 | |
| 455 | |
| 456 | /****************************/ |
| 457 | /* RFC2740 3.4.3.6 Link-LSA */ |
| 458 | /****************************/ |
| 459 | |
| 460 | int |
| 461 | ospf6_link_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 462 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 463 | char *start, *end, *current; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 464 | struct ospf6_link_lsa *link_lsa; |
| 465 | int prefixnum; |
| 466 | char buf[128], options[32]; |
| 467 | struct ospf6_prefix *prefix; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 468 | const char *p, *mc, *la, *nu; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 469 | struct in6_addr in6; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 470 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 471 | link_lsa = (struct ospf6_link_lsa *) |
| 472 | ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 473 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 474 | ospf6_options_printbuf (link_lsa->options, options, sizeof (options)); |
| 475 | inet_ntop (AF_INET6, &link_lsa->linklocal_addr, buf, sizeof (buf)); |
| 476 | prefixnum = ntohl (link_lsa->prefix_num); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 477 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 478 | vty_out (vty, " Priority: %d Options: %s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 479 | link_lsa->priority, options, VNL); |
| 480 | vty_out (vty, " LinkLocal Address: %s%s", buf, VNL); |
| 481 | vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 483 | start = (char *) link_lsa + sizeof (struct ospf6_link_lsa); |
| 484 | end = (char *) lsa->header + ntohs (lsa->header->length); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 485 | for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix)) |
| 486 | { |
| 487 | prefix = (struct ospf6_prefix *) current; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 488 | if (prefix->prefix_length == 0 || |
| 489 | current + OSPF6_PREFIX_SIZE (prefix) > end) |
| 490 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 491 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 492 | p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ? |
| 493 | "P" : "--"); |
| 494 | mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ? |
| 495 | "MC" : "--"); |
| 496 | la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ? |
| 497 | "LA" : "--"); |
| 498 | nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ? |
| 499 | "NU" : "--"); |
| 500 | vty_out (vty, " Prefix Options: %s|%s|%s|%s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 501 | p, mc, la, nu, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 502 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 503 | memset (&in6, 0, sizeof (in6)); |
| 504 | memcpy (&in6, OSPF6_PREFIX_BODY (prefix), |
| 505 | OSPF6_PREFIX_SPACE (prefix->prefix_length)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 506 | inet_ntop (AF_INET6, &in6, buf, sizeof (buf)); |
| 507 | vty_out (vty, " Prefix: %s/%d%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 508 | buf, prefix->prefix_length, VNL); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 509 | } |
| 510 | |
| 511 | return 0; |
| 512 | } |
| 513 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 514 | int |
| 515 | ospf6_link_lsa_originate (struct thread *thread) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 516 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 517 | struct ospf6_interface *oi; |
| 518 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 519 | char buffer[OSPF6_MAX_LSASIZE]; |
| 520 | struct ospf6_lsa_header *lsa_header; |
| 521 | struct ospf6_lsa *old, *lsa; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 522 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 523 | struct ospf6_link_lsa *link_lsa; |
| 524 | struct ospf6_route *route; |
| 525 | struct ospf6_prefix *op; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 527 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 528 | oi->thread_link_lsa = NULL; |
| 529 | |
| 530 | assert (oi->area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | |
| 532 | /* find previous LSA */ |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 533 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_LINK), |
| 534 | htonl (oi->interface->ifindex), |
| 535 | oi->area->ospf6->router_id, oi->lsdb); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 536 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 537 | if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | { |
| 539 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 540 | ospf6_lsa_purge (old); |
| 541 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 542 | } |
| 543 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 544 | if (IS_OSPF6_DEBUG_ORIGINATE (LINK)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 545 | zlog_debug ("Originate Link-LSA for Interface %s", oi->interface->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 546 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 547 | /* can't make Link-LSA if linklocal address not set */ |
| 548 | if (oi->linklocal_addr == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 549 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 550 | if (IS_OSPF6_DEBUG_ORIGINATE (LINK)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 551 | zlog_debug ("No Linklocal address on %s, defer originating", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 552 | oi->interface->name); |
| 553 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 554 | ospf6_lsa_purge (old); |
| 555 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 556 | } |
| 557 | |
| 558 | /* prepare buffer */ |
| 559 | memset (buffer, 0, sizeof (buffer)); |
| 560 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 561 | link_lsa = (struct ospf6_link_lsa *) |
| 562 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 563 | |
| 564 | /* Fill Link-LSA */ |
| 565 | link_lsa->priority = oi->priority; |
| 566 | memcpy (link_lsa->options, oi->area->options, 3); |
| 567 | memcpy (&link_lsa->linklocal_addr, oi->linklocal_addr, |
| 568 | sizeof (struct in6_addr)); |
| 569 | link_lsa->prefix_num = htonl (oi->route_connected->count); |
| 570 | |
| 571 | op = (struct ospf6_prefix *) |
| 572 | ((caddr_t) link_lsa + sizeof (struct ospf6_link_lsa)); |
| 573 | |
| 574 | /* connected prefix to advertise */ |
| 575 | for (route = ospf6_route_head (oi->route_connected); route; |
| 576 | route = ospf6_route_next (route)) |
| 577 | { |
| 578 | op->prefix_length = route->prefix.prefixlen; |
| 579 | op->prefix_options = route->path.prefix_options; |
| 580 | op->prefix_metric = htons (0); |
| 581 | memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6, |
| 582 | OSPF6_PREFIX_SPACE (op->prefix_length)); |
| 583 | op = OSPF6_PREFIX_NEXT (op); |
| 584 | } |
| 585 | |
| 586 | /* Fill LSA Header */ |
| 587 | lsa_header->age = 0; |
| 588 | lsa_header->type = htons (OSPF6_LSTYPE_LINK); |
| 589 | lsa_header->id = htonl (oi->interface->ifindex); |
| 590 | lsa_header->adv_router = oi->area->ospf6->router_id; |
| 591 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 592 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 593 | lsa_header->adv_router, oi->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 594 | lsa_header->length = htons ((caddr_t) op - (caddr_t) buffer); |
| 595 | |
| 596 | /* LSA checksum */ |
| 597 | ospf6_lsa_checksum (lsa_header); |
| 598 | |
| 599 | /* create LSA */ |
| 600 | lsa = ospf6_lsa_create (lsa_header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 601 | |
| 602 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 603 | ospf6_lsa_originate_interface (lsa, oi); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 604 | |
| 605 | return 0; |
| 606 | } |
| 607 | |
| 608 | |
| 609 | /*****************************************/ |
| 610 | /* RFC2740 3.4.3.7 Intra-Area-Prefix-LSA */ |
| 611 | /*****************************************/ |
| 612 | |
| 613 | int |
| 614 | ospf6_intra_prefix_lsa_show (struct vty *vty, struct ospf6_lsa *lsa) |
| 615 | { |
| 616 | char *start, *end, *current; |
| 617 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 618 | int prefixnum; |
| 619 | char buf[128]; |
| 620 | struct ospf6_prefix *prefix; |
| 621 | char id[16], adv_router[16]; |
paul | 0c083ee | 2004-10-10 12:54:58 +0000 | [diff] [blame] | 622 | const char *p, *mc, *la, *nu; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 623 | struct in6_addr in6; |
| 624 | |
| 625 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) |
| 626 | ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header)); |
| 627 | |
| 628 | prefixnum = ntohs (intra_prefix_lsa->prefix_num); |
| 629 | |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 630 | vty_out (vty, " Number of Prefix: %d%s", prefixnum, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 631 | |
| 632 | inet_ntop (AF_INET, &intra_prefix_lsa->ref_id, id, sizeof (id)); |
| 633 | inet_ntop (AF_INET, &intra_prefix_lsa->ref_adv_router, |
| 634 | adv_router, sizeof (adv_router)); |
| 635 | vty_out (vty, " Reference: %s Id: %s Adv: %s%s", |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 636 | ospf6_lstype_name (intra_prefix_lsa->ref_type), id, adv_router, |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 637 | VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 638 | |
| 639 | start = (char *) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa); |
| 640 | end = (char *) lsa->header + ntohs (lsa->header->length); |
| 641 | for (current = start; current < end; current += OSPF6_PREFIX_SIZE (prefix)) |
| 642 | { |
| 643 | prefix = (struct ospf6_prefix *) current; |
| 644 | if (prefix->prefix_length == 0 || |
| 645 | current + OSPF6_PREFIX_SIZE (prefix) > end) |
| 646 | break; |
| 647 | |
| 648 | p = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_P) ? |
| 649 | "P" : "--"); |
| 650 | mc = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_MC) ? |
| 651 | "MC" : "--"); |
| 652 | la = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_LA) ? |
| 653 | "LA" : "--"); |
| 654 | nu = (CHECK_FLAG (prefix->prefix_options, OSPF6_PREFIX_OPTION_NU) ? |
| 655 | "NU" : "--"); |
| 656 | vty_out (vty, " Prefix Options: %s|%s|%s|%s%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 657 | p, mc, la, nu, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 658 | |
| 659 | memset (&in6, 0, sizeof (in6)); |
| 660 | memcpy (&in6, OSPF6_PREFIX_BODY (prefix), |
| 661 | OSPF6_PREFIX_SPACE (prefix->prefix_length)); |
| 662 | inet_ntop (AF_INET6, &in6, buf, sizeof (buf)); |
| 663 | vty_out (vty, " Prefix: %s/%d%s", |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 664 | buf, prefix->prefix_length, VNL); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 665 | } |
| 666 | |
| 667 | return 0; |
| 668 | } |
| 669 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 670 | int |
| 671 | ospf6_intra_prefix_lsa_originate_stub (struct thread *thread) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 672 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 673 | struct ospf6_area *oa; |
| 674 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 675 | char buffer[OSPF6_MAX_LSASIZE]; |
| 676 | struct ospf6_lsa_header *lsa_header; |
| 677 | struct ospf6_lsa *old, *lsa; |
| 678 | |
| 679 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 680 | struct ospf6_interface *oi; |
| 681 | struct ospf6_neighbor *on; |
| 682 | struct ospf6_route *route; |
| 683 | struct ospf6_prefix *op; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 684 | struct listnode *i, *j; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 685 | int full_count = 0; |
| 686 | unsigned short prefix_num = 0; |
| 687 | char buf[BUFSIZ]; |
| 688 | struct ospf6_route_table *route_advertise; |
| 689 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 690 | oa = (struct ospf6_area *) THREAD_ARG (thread); |
| 691 | oa->thread_intra_prefix_lsa = NULL; |
| 692 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 693 | /* find previous LSA */ |
| 694 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX), |
| 695 | htonl (0), oa->ospf6->router_id, oa->lsdb); |
| 696 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 697 | if (! IS_AREA_ENABLED (oa)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 698 | { |
| 699 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 700 | ospf6_lsa_purge (old); |
| 701 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 702 | } |
| 703 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 704 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 705 | zlog_debug ("Originate Intra-Area-Prefix-LSA for area %s's stub prefix", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 706 | oa->name); |
| 707 | |
| 708 | /* prepare buffer */ |
| 709 | memset (buffer, 0, sizeof (buffer)); |
| 710 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 711 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) |
| 712 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 713 | |
| 714 | /* Fill Intra-Area-Prefix-LSA */ |
| 715 | intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_ROUTER); |
| 716 | intra_prefix_lsa->ref_id = htonl (0); |
| 717 | intra_prefix_lsa->ref_adv_router = oa->ospf6->router_id; |
| 718 | |
| 719 | route_advertise = ospf6_route_table_create (); |
| 720 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 721 | for (ALL_LIST_ELEMENTS_RO (oa->if_list, i, oi)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 722 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 723 | if (oi->state == OSPF6_INTERFACE_DOWN) |
| 724 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 725 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 726 | zlog_debug (" Interface %s is down, ignore", oi->interface->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 727 | continue; |
| 728 | } |
| 729 | |
| 730 | full_count = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 731 | |
| 732 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, j, on)) |
| 733 | if (on->state == OSPF6_NEIGHBOR_FULL) |
| 734 | full_count++; |
| 735 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 736 | if (oi->state != OSPF6_INTERFACE_LOOPBACK && |
| 737 | oi->state != OSPF6_INTERFACE_POINTTOPOINT && |
| 738 | full_count != 0) |
| 739 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 740 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 741 | zlog_debug (" Interface %s is not stub, ignore", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 742 | oi->interface->name); |
| 743 | continue; |
| 744 | } |
| 745 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 746 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 747 | zlog_debug (" Interface %s:", oi->interface->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 748 | |
| 749 | /* connected prefix to advertise */ |
| 750 | for (route = ospf6_route_head (oi->route_connected); route; |
| 751 | route = ospf6_route_best_next (route)) |
| 752 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 753 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 754 | { |
| 755 | prefix2str (&route->prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 756 | zlog_debug (" include %s", buf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 757 | } |
| 758 | ospf6_route_add (ospf6_route_copy (route), route_advertise); |
| 759 | } |
| 760 | } |
| 761 | |
| 762 | if (route_advertise->count == 0) |
| 763 | { |
| 764 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 765 | ospf6_lsa_purge (old); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 766 | ospf6_route_table_delete (route_advertise); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 767 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 768 | } |
| 769 | |
| 770 | /* put prefixes to advertise */ |
| 771 | prefix_num = 0; |
| 772 | op = (struct ospf6_prefix *) |
| 773 | ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa)); |
| 774 | for (route = ospf6_route_head (route_advertise); route; |
| 775 | route = ospf6_route_best_next (route)) |
| 776 | { |
| 777 | op->prefix_length = route->prefix.prefixlen; |
| 778 | op->prefix_options = route->path.prefix_options; |
| 779 | op->prefix_metric = htons (route->path.cost); |
| 780 | memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6, |
| 781 | OSPF6_PREFIX_SPACE (op->prefix_length)); |
| 782 | op = OSPF6_PREFIX_NEXT (op); |
| 783 | prefix_num++; |
| 784 | } |
| 785 | |
| 786 | ospf6_route_table_delete (route_advertise); |
| 787 | |
| 788 | if (prefix_num == 0) |
| 789 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 790 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 791 | zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 792 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 793 | } |
| 794 | |
| 795 | intra_prefix_lsa->prefix_num = htons (prefix_num); |
| 796 | |
| 797 | /* Fill LSA Header */ |
| 798 | lsa_header->age = 0; |
| 799 | lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX); |
| 800 | lsa_header->id = htonl (0); |
| 801 | lsa_header->adv_router = oa->ospf6->router_id; |
| 802 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 803 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 804 | lsa_header->adv_router, oa->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 805 | lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header); |
| 806 | |
| 807 | /* LSA checksum */ |
| 808 | ospf6_lsa_checksum (lsa_header); |
| 809 | |
| 810 | /* create LSA */ |
| 811 | lsa = ospf6_lsa_create (lsa_header); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 812 | |
| 813 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 814 | ospf6_lsa_originate_area (lsa, oa); |
| 815 | |
| 816 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 817 | } |
| 818 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 819 | |
| 820 | int |
| 821 | ospf6_intra_prefix_lsa_originate_transit (struct thread *thread) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 822 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 823 | struct ospf6_interface *oi; |
| 824 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 825 | char buffer[OSPF6_MAX_LSASIZE]; |
| 826 | struct ospf6_lsa_header *lsa_header; |
| 827 | struct ospf6_lsa *old, *lsa; |
| 828 | |
| 829 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 830 | struct ospf6_neighbor *on; |
| 831 | struct ospf6_route *route; |
| 832 | struct ospf6_prefix *op; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 833 | struct listnode *i; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 834 | int full_count = 0; |
| 835 | unsigned short prefix_num = 0; |
| 836 | struct ospf6_route_table *route_advertise; |
| 837 | struct ospf6_link_lsa *link_lsa; |
| 838 | char *start, *end, *current; |
| 839 | u_int16_t type; |
| 840 | char buf[BUFSIZ]; |
| 841 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 842 | oi = (struct ospf6_interface *) THREAD_ARG (thread); |
| 843 | oi->thread_intra_prefix_lsa = NULL; |
| 844 | |
| 845 | assert (oi->area); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 846 | |
| 847 | /* find previous LSA */ |
| 848 | old = ospf6_lsdb_lookup (htons (OSPF6_LSTYPE_INTRA_PREFIX), |
| 849 | htonl (oi->interface->ifindex), |
| 850 | oi->area->ospf6->router_id, oi->area->lsdb); |
| 851 | |
| 852 | if (CHECK_FLAG (oi->flag, OSPF6_INTERFACE_DISABLE)) |
| 853 | { |
| 854 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 855 | ospf6_lsa_purge (old); |
| 856 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 857 | } |
| 858 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 859 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 860 | zlog_debug ("Originate Intra-Area-Prefix-LSA for interface %s's prefix", |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 861 | oi->interface->name); |
| 862 | |
| 863 | /* prepare buffer */ |
| 864 | memset (buffer, 0, sizeof (buffer)); |
| 865 | lsa_header = (struct ospf6_lsa_header *) buffer; |
| 866 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) |
| 867 | ((caddr_t) lsa_header + sizeof (struct ospf6_lsa_header)); |
| 868 | |
| 869 | /* Fill Intra-Area-Prefix-LSA */ |
| 870 | intra_prefix_lsa->ref_type = htons (OSPF6_LSTYPE_NETWORK); |
| 871 | intra_prefix_lsa->ref_id = htonl (oi->interface->ifindex); |
| 872 | intra_prefix_lsa->ref_adv_router = oi->area->ospf6->router_id; |
| 873 | |
| 874 | if (oi->state != OSPF6_INTERFACE_DR) |
| 875 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 876 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 877 | zlog_debug (" Interface is not DR"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 878 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 879 | ospf6_lsa_purge (old); |
| 880 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 881 | } |
| 882 | |
| 883 | full_count = 0; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 884 | for (ALL_LIST_ELEMENTS_RO (oi->neighbor_list, i, on)) |
| 885 | if (on->state == OSPF6_NEIGHBOR_FULL) |
| 886 | full_count++; |
| 887 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 888 | if (full_count == 0) |
| 889 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 890 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 891 | zlog_debug (" Interface is stub"); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 892 | if (old) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 893 | ospf6_lsa_purge (old); |
| 894 | return 0; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 895 | } |
| 896 | |
| 897 | /* connected prefix to advertise */ |
| 898 | route_advertise = ospf6_route_table_create (); |
| 899 | |
| 900 | type = ntohs (OSPF6_LSTYPE_LINK); |
| 901 | for (lsa = ospf6_lsdb_type_head (type, oi->lsdb); lsa; |
| 902 | lsa = ospf6_lsdb_type_next (type, lsa)) |
| 903 | { |
| 904 | if (OSPF6_LSA_IS_MAXAGE (lsa)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 905 | continue; |
| 906 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 907 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 908 | zlog_debug (" include prefix from %s", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 909 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 910 | if (lsa->header->adv_router != oi->area->ospf6->router_id) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 911 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 912 | on = ospf6_neighbor_lookup (lsa->header->adv_router, oi); |
| 913 | if (on == NULL || on->state != OSPF6_NEIGHBOR_FULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 914 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 915 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 916 | zlog_debug (" Neighbor not found or not Full, ignore"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 917 | continue; |
| 918 | } |
| 919 | } |
| 920 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 921 | link_lsa = (struct ospf6_link_lsa *) |
| 922 | ((caddr_t) lsa->header + sizeof (struct ospf6_lsa_header)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 923 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 924 | prefix_num = (unsigned short) ntohl (link_lsa->prefix_num); |
| 925 | start = (char *) link_lsa + sizeof (struct ospf6_link_lsa); |
| 926 | end = (char *) lsa->header + ntohs (lsa->header->length); |
| 927 | for (current = start; current < end && prefix_num; |
| 928 | current += OSPF6_PREFIX_SIZE (op)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 930 | op = (struct ospf6_prefix *) current; |
| 931 | if (op->prefix_length == 0 || |
| 932 | current + OSPF6_PREFIX_SIZE (op) > end) |
| 933 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 934 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 935 | route = ospf6_route_create (); |
| 936 | |
| 937 | route->type = OSPF6_DEST_TYPE_NETWORK; |
| 938 | route->prefix.family = AF_INET6; |
| 939 | route->prefix.prefixlen = op->prefix_length; |
| 940 | memset (&route->prefix.u.prefix6, 0, sizeof (struct in6_addr)); |
| 941 | memcpy (&route->prefix.u.prefix6, OSPF6_PREFIX_BODY (op), |
| 942 | OSPF6_PREFIX_SPACE (op->prefix_length)); |
| 943 | |
| 944 | route->path.origin.type = lsa->header->type; |
| 945 | route->path.origin.id = lsa->header->id; |
| 946 | route->path.origin.adv_router = lsa->header->adv_router; |
| 947 | route->path.options[0] = link_lsa->options[0]; |
| 948 | route->path.options[1] = link_lsa->options[1]; |
| 949 | route->path.options[2] = link_lsa->options[2]; |
| 950 | route->path.prefix_options = op->prefix_options; |
| 951 | route->path.area_id = oi->area->area_id; |
| 952 | route->path.type = OSPF6_PATH_TYPE_INTRA; |
| 953 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 954 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 955 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 956 | prefix2str (&route->prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 957 | zlog_debug (" include %s", buf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 958 | } |
| 959 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 960 | ospf6_route_add (route, route_advertise); |
| 961 | prefix_num--; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 962 | } |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 963 | if (current != end && IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 964 | zlog_debug ("Trailing garbage in %s", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 965 | } |
| 966 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 967 | op = (struct ospf6_prefix *) |
| 968 | ((caddr_t) intra_prefix_lsa + sizeof (struct ospf6_intra_prefix_lsa)); |
| 969 | |
| 970 | prefix_num = 0; |
| 971 | for (route = ospf6_route_head (route_advertise); route; |
| 972 | route = ospf6_route_best_next (route)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 973 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 974 | op->prefix_length = route->prefix.prefixlen; |
| 975 | op->prefix_options = route->path.prefix_options; |
| 976 | op->prefix_metric = htons (0); |
| 977 | memcpy (OSPF6_PREFIX_BODY (op), &route->prefix.u.prefix6, |
| 978 | OSPF6_PREFIX_SPACE (op->prefix_length)); |
| 979 | op = OSPF6_PREFIX_NEXT (op); |
| 980 | prefix_num++; |
| 981 | } |
| 982 | |
| 983 | ospf6_route_table_delete (route_advertise); |
| 984 | |
| 985 | if (prefix_num == 0) |
| 986 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 987 | if (IS_OSPF6_DEBUG_ORIGINATE (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 988 | zlog_debug ("Quit to Advertise Intra-Prefix: no route to advertise"); |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 989 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 990 | } |
| 991 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 992 | intra_prefix_lsa->prefix_num = htons (prefix_num); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 993 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 994 | /* Fill LSA Header */ |
| 995 | lsa_header->age = 0; |
| 996 | lsa_header->type = htons (OSPF6_LSTYPE_INTRA_PREFIX); |
| 997 | lsa_header->id = htonl (oi->interface->ifindex); |
| 998 | lsa_header->adv_router = oi->area->ospf6->router_id; |
| 999 | lsa_header->seqnum = |
hasso | 049207c | 2004-08-04 20:02:13 +0000 | [diff] [blame] | 1000 | ospf6_new_ls_seqnum (lsa_header->type, lsa_header->id, |
| 1001 | lsa_header->adv_router, oi->area->lsdb); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1002 | lsa_header->length = htons ((caddr_t) op - (caddr_t) lsa_header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1003 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1004 | /* LSA checksum */ |
| 1005 | ospf6_lsa_checksum (lsa_header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1006 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1007 | /* create LSA */ |
| 1008 | lsa = ospf6_lsa_create (lsa_header); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1009 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1010 | /* Originate */ |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1011 | ospf6_lsa_originate_area (lsa, oi->area); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1012 | |
| 1013 | return 0; |
| 1014 | } |
| 1015 | |
| 1016 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1017 | ospf6_intra_prefix_lsa_add (struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1018 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1019 | struct ospf6_area *oa; |
| 1020 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 1021 | struct prefix ls_prefix; |
| 1022 | struct ospf6_route *route, *ls_entry; |
| 1023 | int i, prefix_num; |
| 1024 | struct ospf6_prefix *op; |
| 1025 | char *start, *current, *end; |
| 1026 | char buf[64]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1027 | |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1028 | if (OSPF6_LSA_IS_MAXAGE (lsa)) |
| 1029 | return; |
| 1030 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1031 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1032 | zlog_debug ("%s found", lsa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1033 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1034 | oa = OSPF6_AREA (lsa->lsdb->data); |
| 1035 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1036 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) |
| 1037 | OSPF6_LSA_HEADER_END (lsa->header); |
| 1038 | if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_ROUTER)) |
| 1039 | ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router, |
| 1040 | htonl (0), &ls_prefix); |
| 1041 | else if (intra_prefix_lsa->ref_type == htons (OSPF6_LSTYPE_NETWORK)) |
| 1042 | ospf6_linkstate_prefix (intra_prefix_lsa->ref_adv_router, |
| 1043 | intra_prefix_lsa->ref_id, &ls_prefix); |
| 1044 | else |
| 1045 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1046 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1047 | zlog_debug ("Unknown reference LS-type: %#hx", |
| 1048 | ntohs (intra_prefix_lsa->ref_type)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1049 | return; |
| 1050 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1051 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1052 | ls_entry = ospf6_route_lookup (&ls_prefix, oa->spf_table); |
| 1053 | if (ls_entry == NULL) |
| 1054 | { |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1055 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1056 | { |
| 1057 | ospf6_linkstate_prefix2str (&ls_prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1058 | zlog_debug ("LS entry does not exist: %s", buf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1059 | } |
| 1060 | return; |
| 1061 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1062 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1063 | prefix_num = ntohs (intra_prefix_lsa->prefix_num); |
| 1064 | start = (caddr_t) intra_prefix_lsa + |
| 1065 | sizeof (struct ospf6_intra_prefix_lsa); |
| 1066 | end = OSPF6_LSA_END (lsa->header); |
| 1067 | for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op)) |
| 1068 | { |
| 1069 | op = (struct ospf6_prefix *) current; |
| 1070 | if (prefix_num == 0) |
| 1071 | break; |
| 1072 | if (end < current + OSPF6_PREFIX_SIZE (op)) |
| 1073 | break; |
| 1074 | |
| 1075 | route = ospf6_route_create (); |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1076 | |
| 1077 | memset (&route->prefix, 0, sizeof (struct prefix)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1078 | route->prefix.family = AF_INET6; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1079 | route->prefix.prefixlen = op->prefix_length; |
| 1080 | ospf6_prefix_in6_addr (&route->prefix.u.prefix6, op); |
| 1081 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1082 | route->type = OSPF6_DEST_TYPE_NETWORK; |
| 1083 | route->path.origin.type = lsa->header->type; |
| 1084 | route->path.origin.id = lsa->header->id; |
| 1085 | route->path.origin.adv_router = lsa->header->adv_router; |
| 1086 | route->path.prefix_options = op->prefix_options; |
| 1087 | route->path.area_id = oa->area_id; |
| 1088 | route->path.type = OSPF6_PATH_TYPE_INTRA; |
| 1089 | route->path.metric_type = 1; |
| 1090 | route->path.cost = ls_entry->path.cost + |
| 1091 | ntohs (op->prefix_metric); |
| 1092 | |
| 1093 | for (i = 0; ospf6_nexthop_is_set (&ls_entry->nexthop[i]) && |
| 1094 | i < OSPF6_MULTI_PATH_LIMIT; i++) |
| 1095 | ospf6_nexthop_copy (&route->nexthop[i], &ls_entry->nexthop[i]); |
| 1096 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1097 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1098 | { |
| 1099 | prefix2str (&route->prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1100 | zlog_debug (" add %s", buf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1101 | } |
| 1102 | |
| 1103 | ospf6_route_add (route, oa->route_table); |
| 1104 | prefix_num--; |
| 1105 | } |
| 1106 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1107 | if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1108 | zlog_debug ("Trailing garbage ignored"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1109 | } |
| 1110 | |
| 1111 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1112 | ospf6_intra_prefix_lsa_remove (struct ospf6_lsa *lsa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1114 | struct ospf6_area *oa; |
| 1115 | struct ospf6_intra_prefix_lsa *intra_prefix_lsa; |
| 1116 | struct prefix prefix; |
| 1117 | struct ospf6_route *route; |
| 1118 | int prefix_num; |
| 1119 | struct ospf6_prefix *op; |
| 1120 | char *start, *current, *end; |
| 1121 | char buf[64]; |
| 1122 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1123 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1124 | zlog_debug ("%s disappearing", lsa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1125 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1126 | oa = OSPF6_AREA (lsa->lsdb->data); |
| 1127 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1128 | intra_prefix_lsa = (struct ospf6_intra_prefix_lsa *) |
| 1129 | OSPF6_LSA_HEADER_END (lsa->header); |
| 1130 | |
| 1131 | prefix_num = ntohs (intra_prefix_lsa->prefix_num); |
| 1132 | start = (caddr_t) intra_prefix_lsa + |
| 1133 | sizeof (struct ospf6_intra_prefix_lsa); |
| 1134 | end = OSPF6_LSA_END (lsa->header); |
| 1135 | for (current = start; current < end; current += OSPF6_PREFIX_SIZE (op)) |
| 1136 | { |
| 1137 | op = (struct ospf6_prefix *) current; |
| 1138 | if (prefix_num == 0) |
| 1139 | break; |
| 1140 | if (end < current + OSPF6_PREFIX_SIZE (op)) |
| 1141 | break; |
| 1142 | prefix_num--; |
| 1143 | |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1144 | memset (&prefix, 0, sizeof (struct prefix)); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1145 | prefix.family = AF_INET6; |
| 1146 | prefix.prefixlen = op->prefix_length; |
| 1147 | ospf6_prefix_in6_addr (&prefix.u.prefix6, op); |
| 1148 | |
| 1149 | route = ospf6_route_lookup (&prefix, oa->route_table); |
| 1150 | if (route == NULL) |
| 1151 | continue; |
| 1152 | |
| 1153 | for (ospf6_route_lock (route); |
| 1154 | route && ospf6_route_is_prefix (&prefix, route); |
| 1155 | route = ospf6_route_next (route)) |
| 1156 | { |
| 1157 | if (route->type != OSPF6_DEST_TYPE_NETWORK) |
| 1158 | continue; |
| 1159 | if (route->path.area_id != oa->area_id) |
| 1160 | continue; |
| 1161 | if (route->path.type != OSPF6_PATH_TYPE_INTRA) |
| 1162 | continue; |
| 1163 | if (route->path.origin.type != lsa->header->type || |
| 1164 | route->path.origin.id != lsa->header->id || |
| 1165 | route->path.origin.adv_router != lsa->header->adv_router) |
| 1166 | continue; |
| 1167 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1168 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1169 | { |
| 1170 | prefix2str (&route->prefix, buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1171 | zlog_debug ("remove %s", buf); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1172 | } |
| 1173 | ospf6_route_remove (route, oa->route_table); |
| 1174 | } |
| 1175 | } |
| 1176 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1177 | if (current != end && IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1178 | zlog_debug ("Trailing garbage ignored"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1179 | } |
| 1180 | |
| 1181 | void |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1182 | ospf6_intra_route_calculation (struct ospf6_area *oa) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1183 | { |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1184 | struct ospf6_route *route; |
| 1185 | u_int16_t type; |
| 1186 | struct ospf6_lsa *lsa; |
| 1187 | void (*hook_add) (struct ospf6_route *) = NULL; |
| 1188 | void (*hook_remove) (struct ospf6_route *) = NULL; |
| 1189 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1190 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1191 | zlog_debug ("Re-examin intra-routes for area %s", oa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1192 | |
| 1193 | hook_add = oa->route_table->hook_add; |
| 1194 | hook_remove = oa->route_table->hook_remove; |
| 1195 | oa->route_table->hook_add = NULL; |
| 1196 | oa->route_table->hook_remove = NULL; |
| 1197 | |
| 1198 | for (route = ospf6_route_head (oa->route_table); route; |
| 1199 | route = ospf6_route_next (route)) |
| 1200 | route->flag = OSPF6_ROUTE_REMOVE; |
| 1201 | |
| 1202 | type = htons (OSPF6_LSTYPE_INTRA_PREFIX); |
| 1203 | for (lsa = ospf6_lsdb_type_head (type, oa->lsdb); lsa; |
| 1204 | lsa = ospf6_lsdb_type_next (type, lsa)) |
| 1205 | ospf6_intra_prefix_lsa_add (lsa); |
| 1206 | |
| 1207 | oa->route_table->hook_add = hook_add; |
| 1208 | oa->route_table->hook_remove = hook_remove; |
| 1209 | |
| 1210 | for (route = ospf6_route_head (oa->route_table); route; |
| 1211 | route = ospf6_route_next (route)) |
| 1212 | { |
| 1213 | if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE) && |
| 1214 | CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD)) |
| 1215 | { |
| 1216 | UNSET_FLAG (route->flag, OSPF6_ROUTE_REMOVE); |
| 1217 | UNSET_FLAG (route->flag, OSPF6_ROUTE_ADD); |
| 1218 | } |
| 1219 | |
| 1220 | if (CHECK_FLAG (route->flag, OSPF6_ROUTE_REMOVE)) |
| 1221 | ospf6_route_remove (route, oa->route_table); |
| 1222 | else if (CHECK_FLAG (route->flag, OSPF6_ROUTE_ADD) || |
| 1223 | CHECK_FLAG (route->flag, OSPF6_ROUTE_CHANGE)) |
| 1224 | { |
| 1225 | if (hook_add) |
| 1226 | (*hook_add) (route); |
| 1227 | } |
| 1228 | |
| 1229 | route->flag = 0; |
| 1230 | } |
| 1231 | |
hasso | 1e05838 | 2004-09-01 21:36:14 +0000 | [diff] [blame] | 1232 | if (IS_OSPF6_DEBUG_EXAMIN (INTRA_PREFIX)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1233 | zlog_debug ("Re-examin intra-routes for area %s: Done", oa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1234 | } |
| 1235 | |
| 1236 | void |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1237 | ospf6_intra_brouter_calculation (struct ospf6_area *oa) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1238 | { |
| 1239 | struct ospf6_route *lsentry, *copy; |
| 1240 | void (*hook_add) (struct ospf6_route *) = NULL; |
| 1241 | void (*hook_remove) (struct ospf6_route *) = NULL; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1242 | char buf[16]; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1243 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1244 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1245 | zlog_debug ("Border-router calculation for area %s", oa->name); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1246 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1247 | hook_add = oa->ospf6->brouter_table->hook_add; |
| 1248 | hook_remove = oa->ospf6->brouter_table->hook_remove; |
| 1249 | oa->ospf6->brouter_table->hook_add = NULL; |
| 1250 | oa->ospf6->brouter_table->hook_remove = NULL; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1251 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1252 | /* withdraw the previous router entries for the area */ |
| 1253 | for (lsentry = ospf6_route_head (oa->ospf6->brouter_table); lsentry; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1254 | lsentry = ospf6_route_next (lsentry)) |
| 1255 | { |
| 1256 | if (lsentry->path.area_id != oa->area_id) |
| 1257 | continue; |
| 1258 | lsentry->flag = OSPF6_ROUTE_REMOVE; |
| 1259 | } |
| 1260 | |
| 1261 | for (lsentry = ospf6_route_head (oa->spf_table); lsentry; |
| 1262 | lsentry = ospf6_route_next (lsentry)) |
| 1263 | { |
| 1264 | if (lsentry->type != OSPF6_DEST_TYPE_LINKSTATE) |
| 1265 | continue; |
| 1266 | if (ospf6_linkstate_prefix_id (&lsentry->prefix) != htonl (0)) |
| 1267 | continue; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1268 | if (! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_E) && |
| 1269 | ! CHECK_FLAG (lsentry->path.router_bits, OSPF6_ROUTER_BIT_B)) |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1270 | continue; |
| 1271 | |
| 1272 | copy = ospf6_route_copy (lsentry); |
| 1273 | copy->type = OSPF6_DEST_TYPE_ROUTER; |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1274 | copy->path.area_id = oa->area_id; |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1275 | ospf6_route_add (copy, oa->ospf6->brouter_table); |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1276 | |
| 1277 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
| 1278 | { |
| 1279 | inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (©->prefix), |
| 1280 | buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1281 | zlog_debug ("Re-install router entry %s", buf); |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1282 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1283 | } |
| 1284 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1285 | oa->ospf6->brouter_table->hook_add = hook_add; |
| 1286 | oa->ospf6->brouter_table->hook_remove = hook_remove; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1287 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1288 | for (lsentry = ospf6_route_head (oa->ospf6->brouter_table); lsentry; |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1289 | lsentry = ospf6_route_next (lsentry)) |
| 1290 | { |
| 1291 | if (lsentry->path.area_id != oa->area_id) |
| 1292 | continue; |
| 1293 | |
hasso | 9428f2d | 2004-09-13 14:01:12 +0000 | [diff] [blame] | 1294 | if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_WAS_REMOVED)) |
| 1295 | continue; |
| 1296 | |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1297 | if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE) && |
| 1298 | CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD)) |
| 1299 | { |
| 1300 | UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE); |
| 1301 | UNSET_FLAG (lsentry->flag, OSPF6_ROUTE_ADD); |
| 1302 | } |
| 1303 | |
| 1304 | if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_REMOVE)) |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1305 | ospf6_route_remove (lsentry, oa->ospf6->brouter_table); |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1306 | else if (CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_ADD) || |
| 1307 | CHECK_FLAG (lsentry->flag, OSPF6_ROUTE_CHANGE)) |
| 1308 | { |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1309 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
| 1310 | { |
| 1311 | inet_ntop (AF_INET, &ADV_ROUTER_IN_PREFIX (&lsentry->prefix), |
| 1312 | buf, sizeof (buf)); |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1313 | zlog_debug ("Call hook for router entry %s", buf); |
hasso | ccb59b1 | 2004-08-25 09:10:37 +0000 | [diff] [blame] | 1314 | } |
hasso | 508e53e | 2004-05-18 18:57:06 +0000 | [diff] [blame] | 1315 | if (hook_add) |
| 1316 | (*hook_add) (lsentry); |
| 1317 | } |
| 1318 | |
| 1319 | lsentry->flag = 0; |
| 1320 | } |
| 1321 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1322 | if (IS_OSPF6_DEBUG_ROUTE (INTRA)) |
hasso | c6487d6 | 2004-12-24 06:00:11 +0000 | [diff] [blame] | 1323 | zlog_debug ("Border-router calculation for area %s: Done", oa->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1324 | } |
| 1325 | |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1326 | struct ospf6_lsa_handler router_handler = |
| 1327 | { |
| 1328 | OSPF6_LSTYPE_ROUTER, |
| 1329 | "Router", |
| 1330 | ospf6_router_lsa_show |
| 1331 | }; |
| 1332 | |
| 1333 | struct ospf6_lsa_handler network_handler = |
| 1334 | { |
| 1335 | OSPF6_LSTYPE_NETWORK, |
| 1336 | "Network", |
| 1337 | ospf6_network_lsa_show |
| 1338 | }; |
| 1339 | |
| 1340 | struct ospf6_lsa_handler link_handler = |
| 1341 | { |
| 1342 | OSPF6_LSTYPE_LINK, |
| 1343 | "Link", |
| 1344 | ospf6_link_lsa_show |
| 1345 | }; |
| 1346 | |
| 1347 | struct ospf6_lsa_handler intra_prefix_handler = |
| 1348 | { |
| 1349 | OSPF6_LSTYPE_INTRA_PREFIX, |
| 1350 | "Intra-Prefix", |
| 1351 | ospf6_intra_prefix_lsa_show |
| 1352 | }; |
| 1353 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1354 | void |
| 1355 | ospf6_intra_init () |
| 1356 | { |
hasso | 6452df0 | 2004-08-15 05:52:07 +0000 | [diff] [blame] | 1357 | ospf6_install_lsa_handler (&router_handler); |
| 1358 | ospf6_install_lsa_handler (&network_handler); |
| 1359 | ospf6_install_lsa_handler (&link_handler); |
| 1360 | ospf6_install_lsa_handler (&intra_prefix_handler); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1361 | } |
| 1362 | |
| 1363 | |