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