paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* |
| 2 | * Zebra connect library for OSPFd |
| 3 | * Copyright (C) 1997, 98, 99, 2000 Kunihiro Ishiguro, Toshiaki Takada |
| 4 | * |
| 5 | * This file is part of GNU Zebra. |
| 6 | * |
| 7 | * GNU Zebra is free software; you can redistribute it and/or modify it |
| 8 | * under the terms of the GNU General Public License as published by the |
| 9 | * Free Software Foundation; either version 2, or (at your option) any |
| 10 | * later version. |
| 11 | * |
| 12 | * GNU Zebra is distributed in the hope that it will be useful, but |
| 13 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 15 | * General Public License for more details. |
| 16 | * |
| 17 | * You should have received a copy of the GNU General Public License |
| 18 | * along with GNU Zebra; see the file COPYING. If not, write to the |
| 19 | * Free Software Foundation, Inc., 59 Temple Place - Suite 330, |
| 20 | * Boston, MA 02111-1307, USA. |
| 21 | */ |
| 22 | |
| 23 | #include <zebra.h> |
| 24 | |
| 25 | #include "thread.h" |
| 26 | #include "command.h" |
| 27 | #include "network.h" |
| 28 | #include "prefix.h" |
| 29 | #include "routemap.h" |
| 30 | #include "table.h" |
| 31 | #include "stream.h" |
| 32 | #include "memory.h" |
| 33 | #include "zclient.h" |
| 34 | #include "filter.h" |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 35 | #include "plist.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 36 | #include "log.h" |
| 37 | |
| 38 | #include "ospfd/ospfd.h" |
| 39 | #include "ospfd/ospf_interface.h" |
| 40 | #include "ospfd/ospf_ism.h" |
| 41 | #include "ospfd/ospf_asbr.h" |
| 42 | #include "ospfd/ospf_asbr.h" |
| 43 | #include "ospfd/ospf_abr.h" |
| 44 | #include "ospfd/ospf_lsa.h" |
| 45 | #include "ospfd/ospf_dump.h" |
| 46 | #include "ospfd/ospf_route.h" |
| 47 | #include "ospfd/ospf_zebra.h" |
| 48 | #ifdef HAVE_SNMP |
| 49 | #include "ospfd/ospf_snmp.h" |
| 50 | #endif /* HAVE_SNMP */ |
| 51 | |
| 52 | /* Zebra structure to hold current status. */ |
| 53 | struct zclient *zclient = NULL; |
| 54 | |
| 55 | /* For registering threads. */ |
| 56 | extern struct thread_master *master; |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 57 | struct in_addr router_id_zebra; |
| 58 | |
| 59 | /* Router-id update message from zebra. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 60 | static int |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 61 | ospf_router_id_update_zebra (int command, struct zclient *zclient, |
| 62 | zebra_size_t length) |
| 63 | { |
| 64 | struct ospf *ospf; |
| 65 | struct prefix router_id; |
| 66 | zebra_router_id_update_read(zclient->ibuf,&router_id); |
| 67 | |
| 68 | router_id_zebra = router_id.u.prefix4; |
| 69 | |
| 70 | ospf = ospf_lookup (); |
| 71 | if (ospf != NULL) |
| 72 | { |
| 73 | if (ospf->t_router_id_update == NULL) |
| 74 | OSPF_TIMER_ON (ospf->t_router_id_update, ospf_router_id_update_timer, |
| 75 | OSPF_ROUTER_ID_UPDATE_DELAY); |
| 76 | } |
| 77 | return 0; |
| 78 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 79 | |
| 80 | /* Inteface addition message from zebra. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 81 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 82 | ospf_interface_add (int command, struct zclient *zclient, zebra_size_t length) |
| 83 | { |
| 84 | struct interface *ifp; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 85 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 86 | |
| 87 | ifp = zebra_interface_add_read (zclient->ibuf); |
| 88 | |
| 89 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 90 | zlog_debug ("Zebra: interface add %s index %d flags %ld metric %d mtu %d", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 91 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 92 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 93 | assert (ifp->info); |
paul | f2c8065 | 2002-12-13 21:44:27 +0000 | [diff] [blame] | 94 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 95 | if (!OSPF_IF_PARAM_CONFIGURED (IF_DEF_PARAMS (ifp), type)) |
| 96 | { |
| 97 | SET_IF_PARAM (IF_DEF_PARAMS (ifp), type); |
ajs | bc18d61 | 2004-12-15 15:07:19 +0000 | [diff] [blame] | 98 | IF_DEF_PARAMS (ifp)->type = ospf_default_iftype(ifp); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 99 | } |
| 100 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 101 | ospf = ospf_lookup (); |
| 102 | if (ospf != NULL) |
| 103 | ospf_if_update (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | |
| 105 | #ifdef HAVE_SNMP |
| 106 | ospf_snmp_if_update (ifp); |
| 107 | #endif /* HAVE_SNMP */ |
| 108 | |
| 109 | return 0; |
| 110 | } |
| 111 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 112 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 113 | ospf_interface_delete (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 114 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 115 | { |
| 116 | struct interface *ifp; |
| 117 | struct stream *s; |
| 118 | struct route_node *rn; |
| 119 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 120 | s = zclient->ibuf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 121 | /* zebra_interface_state_read() updates interface structure in iflist */ |
| 122 | ifp = zebra_interface_state_read (s); |
| 123 | |
| 124 | if (ifp == NULL) |
| 125 | return 0; |
| 126 | |
| 127 | if (if_is_up (ifp)) |
| 128 | zlog_warn ("Zebra: got delete of %s, but interface is still up", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 129 | ifp->name); |
| 130 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 131 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 132 | zlog_debug |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 133 | ("Zebra: interface delete %s index %d flags %ld metric %d mtu %d", |
| 134 | ifp->name, ifp->ifindex, ifp->flags, ifp->metric, ifp->mtu); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 135 | |
| 136 | #ifdef HAVE_SNMP |
| 137 | ospf_snmp_if_delete (ifp); |
| 138 | #endif /* HAVE_SNMP */ |
| 139 | |
| 140 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
| 141 | if (rn->info) |
| 142 | ospf_if_free ((struct ospf_interface *) rn->info); |
| 143 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 144 | ifp->ifindex = IFINDEX_INTERNAL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 145 | return 0; |
| 146 | } |
| 147 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 148 | static struct interface * |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 149 | zebra_interface_if_lookup (struct stream *s) |
| 150 | { |
ajs | 21fefa9 | 2005-04-02 23:16:41 +0000 | [diff] [blame] | 151 | char ifname_tmp[INTERFACE_NAMSIZ]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 152 | |
| 153 | /* Read interface name. */ |
| 154 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); |
| 155 | |
ajs | d2fc889 | 2005-04-02 18:38:43 +0000 | [diff] [blame] | 156 | /* And look it up. */ |
ajs | 21fefa9 | 2005-04-02 23:16:41 +0000 | [diff] [blame] | 157 | return if_lookup_by_name_len(ifname_tmp, |
| 158 | strnlen(ifname_tmp, INTERFACE_NAMSIZ)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 159 | } |
| 160 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 161 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 162 | ospf_interface_state_up (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 163 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 164 | { |
| 165 | struct interface *ifp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 166 | struct ospf_interface *oi; |
| 167 | struct route_node *rn; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 168 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 169 | ifp = zebra_interface_if_lookup (zclient->ibuf); |
| 170 | |
| 171 | if (ifp == NULL) |
| 172 | return 0; |
| 173 | |
| 174 | /* Interface is already up. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 175 | if (if_is_operative (ifp)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 176 | { |
| 177 | /* Temporarily keep ifp values. */ |
ajs | a608bbf | 2005-03-29 17:03:49 +0000 | [diff] [blame] | 178 | struct interface if_tmp; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 179 | memcpy (&if_tmp, ifp, sizeof (struct interface)); |
| 180 | |
| 181 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
| 182 | |
| 183 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 184 | zlog_debug ("Zebra: Interface[%s] state update.", ifp->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 185 | |
| 186 | if (if_tmp.bandwidth != ifp->bandwidth) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 187 | { |
| 188 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 189 | zlog_debug ("Zebra: Interface[%s] bandwidth change %d -> %d.", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 190 | ifp->name, if_tmp.bandwidth, ifp->bandwidth); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 191 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 192 | ospf_if_recalculate_output_cost (ifp); |
| 193 | } |
ajs | a608bbf | 2005-03-29 17:03:49 +0000 | [diff] [blame] | 194 | |
| 195 | if (if_tmp.mtu != ifp->mtu) |
| 196 | { |
| 197 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
| 198 | zlog_debug ("Zebra: Interface[%s] MTU change %u -> %u.", |
| 199 | ifp->name, if_tmp.mtu, ifp->mtu); |
| 200 | |
| 201 | /* Must reset the interface (simulate down/up) when MTU changes. */ |
| 202 | ospf_if_reset(ifp); |
| 203 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 204 | return 0; |
| 205 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 206 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | zebra_interface_if_set_value (zclient->ibuf, ifp); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 208 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 209 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 210 | zlog_debug ("Zebra: Interface[%s] state change to up.", ifp->name); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 211 | |
| 212 | for (rn = route_top (IF_OIFS (ifp)); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 213 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 214 | if ((oi = rn->info) == NULL) |
| 215 | continue; |
| 216 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 217 | ospf_if_up (oi); |
| 218 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 219 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 220 | return 0; |
| 221 | } |
| 222 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 223 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 224 | ospf_interface_state_down (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 225 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 226 | { |
| 227 | struct interface *ifp; |
| 228 | struct ospf_interface *oi; |
| 229 | struct route_node *node; |
| 230 | |
| 231 | ifp = zebra_interface_state_read (zclient->ibuf); |
| 232 | |
| 233 | if (ifp == NULL) |
| 234 | return 0; |
| 235 | |
| 236 | if (IS_DEBUG_OSPF (zebra, ZEBRA_INTERFACE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 237 | zlog_debug ("Zebra: Interface[%s] state change to down.", ifp->name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 238 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 239 | for (node = route_top (IF_OIFS (ifp)); node; node = route_next (node)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 240 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 241 | if ((oi = node->info) == NULL) |
| 242 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 243 | ospf_if_down (oi); |
| 244 | } |
| 245 | |
| 246 | return 0; |
| 247 | } |
| 248 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 249 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 250 | ospf_interface_address_add (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 251 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 252 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 253 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 254 | struct connected *c; |
| 255 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 256 | c = zebra_interface_address_read (command, zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 257 | |
| 258 | if (c == NULL) |
| 259 | return 0; |
| 260 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 261 | ospf = ospf_lookup (); |
| 262 | if (ospf != NULL) |
| 263 | ospf_if_update (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 264 | |
| 265 | #ifdef HAVE_SNMP |
| 266 | ospf_snmp_if_update (c->ifp); |
| 267 | #endif /* HAVE_SNMP */ |
| 268 | |
| 269 | return 0; |
| 270 | } |
| 271 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 272 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 273 | ospf_interface_address_delete (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 274 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 275 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 276 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 277 | struct connected *c; |
| 278 | struct interface *ifp; |
| 279 | struct ospf_interface *oi; |
| 280 | struct route_node *rn; |
| 281 | struct prefix p; |
| 282 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 283 | c = zebra_interface_address_read (command, zclient->ibuf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 284 | |
| 285 | if (c == NULL) |
| 286 | return 0; |
| 287 | |
| 288 | ifp = c->ifp; |
| 289 | p = *c->address; |
| 290 | p.prefixlen = IPV4_MAX_PREFIXLEN; |
| 291 | |
| 292 | rn = route_node_lookup (IF_OIFS (ifp), &p); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 293 | if (!rn) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 294 | return 0; |
| 295 | |
| 296 | assert (rn->info); |
| 297 | oi = rn->info; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 298 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 299 | /* Call interface hook functions to clean up */ |
| 300 | ospf_if_free (oi); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 301 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 302 | #ifdef HAVE_SNMP |
| 303 | ospf_snmp_if_update (c->ifp); |
| 304 | #endif /* HAVE_SNMP */ |
| 305 | |
| 306 | connected_free (c); |
| 307 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 308 | ospf = ospf_lookup (); |
| 309 | if (ospf != NULL) |
| 310 | ospf_if_update (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 311 | |
| 312 | return 0; |
| 313 | } |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 314 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 315 | void |
| 316 | ospf_zebra_add (struct prefix_ipv4 *p, struct ospf_route *or) |
| 317 | { |
| 318 | u_char message; |
| 319 | u_char distance; |
| 320 | u_char flags; |
| 321 | int psize; |
| 322 | struct stream *s; |
| 323 | struct ospf_path *path; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 324 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 325 | |
| 326 | if (zclient->redist[ZEBRA_ROUTE_OSPF]) |
| 327 | { |
| 328 | message = 0; |
| 329 | flags = 0; |
| 330 | |
| 331 | /* OSPF pass nexthop and metric */ |
| 332 | SET_FLAG (message, ZAPI_MESSAGE_NEXTHOP); |
| 333 | SET_FLAG (message, ZAPI_MESSAGE_METRIC); |
| 334 | |
| 335 | /* Distance value. */ |
| 336 | distance = ospf_distance_apply (p, or); |
| 337 | if (distance) |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 338 | SET_FLAG (message, ZAPI_MESSAGE_DISTANCE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 339 | |
| 340 | /* Make packet. */ |
| 341 | s = zclient->obuf; |
| 342 | stream_reset (s); |
| 343 | |
| 344 | /* Length place holder. */ |
| 345 | stream_putw (s, 0); |
| 346 | |
| 347 | /* Put command, type, flags, message. */ |
| 348 | stream_putc (s, ZEBRA_IPV4_ROUTE_ADD); |
| 349 | stream_putc (s, ZEBRA_ROUTE_OSPF); |
| 350 | stream_putc (s, flags); |
| 351 | stream_putc (s, message); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 352 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | /* Put prefix information. */ |
| 354 | psize = PSIZE (p->prefixlen); |
| 355 | stream_putc (s, p->prefixlen); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 356 | stream_write (s, (u_char *) & p->prefix, psize); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 357 | |
| 358 | /* Nexthop count. */ |
paul | 96735ee | 2003-08-10 02:51:22 +0000 | [diff] [blame] | 359 | stream_putc (s, or->paths->count); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | |
| 361 | /* Nexthop, ifindex, distance and metric information. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 362 | for (ALL_LIST_ELEMENTS_RO (or->paths, node, path)) |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 363 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 364 | if (path->nexthop.s_addr != INADDR_ANY) |
| 365 | { |
| 366 | stream_putc (s, ZEBRA_NEXTHOP_IPV4); |
| 367 | stream_put_in_addr (s, &path->nexthop); |
| 368 | } |
| 369 | else |
| 370 | { |
| 371 | stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); |
| 372 | if (path->oi) |
| 373 | stream_putl (s, path->oi->ifp->ifindex); |
| 374 | else |
| 375 | stream_putl (s, 0); |
| 376 | } |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 377 | |
| 378 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
| 379 | { |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 380 | zlog_debug ("Zebra: Route add %s/%d nexthop %s", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 381 | inet_ntoa (p->prefix), |
| 382 | p->prefixlen, inet_ntoa (path->nexthop)); |
| 383 | } |
| 384 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 385 | |
| 386 | if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 387 | stream_putc (s, distance); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 388 | if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 389 | { |
| 390 | if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL) |
| 391 | stream_putl (s, or->cost + or->u.ext.type2_cost); |
| 392 | else if (or->path_type == OSPF_PATH_TYPE2_EXTERNAL) |
| 393 | stream_putl (s, or->u.ext.type2_cost); |
| 394 | else |
| 395 | stream_putl (s, or->cost); |
| 396 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 397 | |
| 398 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 399 | |
ajs | 634f9ea | 2005-04-11 15:51:40 +0000 | [diff] [blame] | 400 | zclient_send_message(zclient); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 401 | } |
| 402 | } |
| 403 | |
| 404 | void |
| 405 | ospf_zebra_delete (struct prefix_ipv4 *p, struct ospf_route *or) |
| 406 | { |
| 407 | struct zapi_ipv4 api; |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 408 | struct ospf_path *path; |
| 409 | struct in_addr *nexthop; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 410 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 411 | |
| 412 | if (zclient->redist[ZEBRA_ROUTE_OSPF]) |
| 413 | { |
| 414 | api.type = ZEBRA_ROUTE_OSPF; |
| 415 | api.flags = 0; |
| 416 | api.message = 0; |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 417 | api.ifindex_num = 0; |
| 418 | api.nexthop_num = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 420 | for (ALL_LIST_ELEMENTS (or->paths, node, nnode, path)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 421 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 422 | if (path->nexthop.s_addr != INADDR_ANY) |
| 423 | { |
paul | d8e1d6b | 2003-08-10 04:04:41 +0000 | [diff] [blame] | 424 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 425 | api.nexthop_num = 1; |
| 426 | nexthop = &path->nexthop; |
| 427 | api.nexthop = &nexthop; |
| 428 | } |
hasso | 2db3d05 | 2004-02-11 21:52:13 +0000 | [diff] [blame] | 429 | else if (ospf_if_exists(path->oi) && (path->oi->ifp)) |
paul | bb8ff1e | 2003-08-12 06:00:30 +0000 | [diff] [blame] | 430 | { |
| 431 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 432 | api.ifindex_num = 1; |
| 433 | api.ifindex = &path->oi->ifp->ifindex; |
| 434 | } |
| 435 | else if ( IS_DEBUG_OSPF(zebra,ZEBRA_REDISTRIBUTE) ) |
| 436 | { |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 437 | zlog_debug("Zebra: no ifp %s %d", |
paul | bb8ff1e | 2003-08-12 06:00:30 +0000 | [diff] [blame] | 438 | inet_ntoa(p->prefix), |
| 439 | p->prefixlen); |
| 440 | } |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 441 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 442 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 443 | |
| 444 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE) && api.nexthop_num) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 445 | { |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 446 | zlog_debug ("Zebra: Route delete %s/%d nexthop %s", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 447 | inet_ntoa (p->prefix), |
| 448 | p->prefixlen, inet_ntoa (**api.nexthop)); |
| 449 | } |
paul | bb8ff1e | 2003-08-12 06:00:30 +0000 | [diff] [blame] | 450 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE) && api.ifindex_num) |
| 451 | { |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 452 | zlog_debug ("Zebra: Route delete %s/%d ifindex %d", |
paul | bb8ff1e | 2003-08-12 06:00:30 +0000 | [diff] [blame] | 453 | inet_ntoa (p->prefix), |
| 454 | p->prefixlen, *api.ifindex); |
| 455 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 456 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 457 | } |
| 458 | } |
| 459 | |
| 460 | void |
| 461 | ospf_zebra_add_discard (struct prefix_ipv4 *p) |
| 462 | { |
| 463 | struct zapi_ipv4 api; |
| 464 | |
| 465 | if (zclient->redist[ZEBRA_ROUTE_OSPF]) |
| 466 | { |
| 467 | api.type = ZEBRA_ROUTE_OSPF; |
| 468 | api.flags = ZEBRA_FLAG_BLACKHOLE; |
| 469 | api.message = 0; |
| 470 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 471 | api.nexthop_num = 0; |
| 472 | api.ifindex_num = 0; |
| 473 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 474 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_ADD, zclient, p, &api); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 475 | } |
| 476 | } |
| 477 | |
| 478 | void |
| 479 | ospf_zebra_delete_discard (struct prefix_ipv4 *p) |
| 480 | { |
| 481 | struct zapi_ipv4 api; |
| 482 | |
| 483 | if (zclient->redist[ZEBRA_ROUTE_OSPF]) |
| 484 | { |
| 485 | api.type = ZEBRA_ROUTE_OSPF; |
| 486 | api.flags = ZEBRA_FLAG_BLACKHOLE; |
| 487 | api.message = 0; |
| 488 | SET_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP); |
| 489 | api.nexthop_num = 0; |
| 490 | api.ifindex_num = 0; |
| 491 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 492 | zapi_ipv4_route (ZEBRA_IPV4_ROUTE_DELETE, zclient, p, &api); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 493 | |
| 494 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 495 | zlog_debug ("Zebra: Route delete discard %s/%d", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 496 | inet_ntoa (p->prefix), p->prefixlen); |
paul | 72357f2 | 2003-06-19 02:11:23 +0000 | [diff] [blame] | 497 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 498 | } |
| 499 | } |
| 500 | |
| 501 | int |
| 502 | ospf_is_type_redistributed (int type) |
| 503 | { |
| 504 | return (DEFAULT_ROUTE_TYPE (type)) ? |
| 505 | zclient->default_information : zclient->redist[type]; |
| 506 | } |
| 507 | |
| 508 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 509 | ospf_redistribute_set (struct ospf *ospf, int type, int mtype, int mvalue) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 510 | { |
| 511 | int force = 0; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 512 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 513 | if (ospf_is_type_redistributed (type)) |
| 514 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 515 | if (mtype != ospf->dmetric[type].type) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 516 | { |
| 517 | ospf->dmetric[type].type = mtype; |
| 518 | force = LSA_REFRESH_FORCE; |
| 519 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 520 | if (mvalue != ospf->dmetric[type].value) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 521 | { |
| 522 | ospf->dmetric[type].value = mvalue; |
| 523 | force = LSA_REFRESH_FORCE; |
| 524 | } |
| 525 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 526 | ospf_external_lsa_refresh_type (ospf, type, force); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 527 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 529 | zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 530 | LOOKUP (ospf_redistributed_proto, type), |
| 531 | metric_type (ospf, type), metric_value (ospf, type)); |
| 532 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | return CMD_SUCCESS; |
| 534 | } |
| 535 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 536 | ospf->dmetric[type].type = mtype; |
| 537 | ospf->dmetric[type].value = mvalue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 539 | zclient_redistribute (ZEBRA_REDISTRIBUTE_ADD, zclient, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 540 | |
| 541 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 542 | zlog_debug ("Redistribute[%s]: Start Type[%d], Metric[%d]", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 543 | LOOKUP (ospf_redistributed_proto, type), |
| 544 | metric_type (ospf, type), metric_value (ospf, type)); |
| 545 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 546 | ospf_asbr_status_update (ospf, ++ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 547 | |
| 548 | return CMD_SUCCESS; |
| 549 | } |
| 550 | |
| 551 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 552 | ospf_redistribute_unset (struct ospf *ospf, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | { |
| 554 | if (type == zclient->redist_default) |
| 555 | return CMD_SUCCESS; |
| 556 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 557 | if (!ospf_is_type_redistributed (type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 558 | return CMD_SUCCESS; |
| 559 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 560 | zclient_redistribute (ZEBRA_REDISTRIBUTE_DELETE, zclient, type); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 561 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 562 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 563 | zlog_debug ("Redistribute[%s]: Stop", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 564 | LOOKUP (ospf_redistributed_proto, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 565 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 566 | ospf->dmetric[type].type = -1; |
| 567 | ospf->dmetric[type].value = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 568 | |
| 569 | /* Remove the routes from OSPF table. */ |
| 570 | ospf_redistribute_withdraw (type); |
| 571 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 572 | ospf_asbr_status_update (ospf, --ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 573 | |
| 574 | return CMD_SUCCESS; |
| 575 | } |
| 576 | |
| 577 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 578 | ospf_redistribute_default_set (struct ospf *ospf, int originate, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 579 | int mtype, int mvalue) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 580 | { |
| 581 | int force = 0; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 582 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 583 | if (ospf_is_type_redistributed (DEFAULT_ROUTE)) |
| 584 | { |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 585 | if (mtype != ospf->dmetric[DEFAULT_ROUTE].type) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 586 | { |
| 587 | ospf->dmetric[DEFAULT_ROUTE].type = mtype; |
| 588 | force = 1; |
| 589 | } |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 590 | if (mvalue != ospf->dmetric[DEFAULT_ROUTE].value) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 591 | { |
| 592 | force = 1; |
| 593 | ospf->dmetric[DEFAULT_ROUTE].value = mvalue; |
| 594 | } |
| 595 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 596 | ospf_external_lsa_refresh_default (ospf); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 597 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 598 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 599 | zlog_debug ("Redistribute[%s]: Refresh Type[%d], Metric[%d]", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 600 | LOOKUP (ospf_redistributed_proto, DEFAULT_ROUTE), |
| 601 | metric_type (ospf, DEFAULT_ROUTE), |
| 602 | metric_value (ospf, DEFAULT_ROUTE)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 603 | return CMD_SUCCESS; |
| 604 | } |
| 605 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 606 | ospf->default_originate = originate; |
| 607 | ospf->dmetric[DEFAULT_ROUTE].type = mtype; |
| 608 | ospf->dmetric[DEFAULT_ROUTE].value = mvalue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 609 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 610 | zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_ADD, zclient); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 611 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 612 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 613 | zlog_debug ("Redistribute[DEFAULT]: Start Type[%d], Metric[%d]", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 614 | metric_type (ospf, DEFAULT_ROUTE), |
| 615 | metric_value (ospf, DEFAULT_ROUTE)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 616 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 617 | if (ospf->router_id.s_addr == 0) |
| 618 | ospf->external_origin |= (1 << DEFAULT_ROUTE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 619 | else |
| 620 | thread_add_timer (master, ospf_default_originate_timer, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 621 | &ospf->default_originate, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 622 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 623 | ospf_asbr_status_update (ospf, ++ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 624 | |
| 625 | return CMD_SUCCESS; |
| 626 | } |
| 627 | |
| 628 | int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 629 | ospf_redistribute_default_unset (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 630 | { |
| 631 | if (!ospf_is_type_redistributed (DEFAULT_ROUTE)) |
| 632 | return CMD_SUCCESS; |
| 633 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 634 | ospf->default_originate = DEFAULT_ORIGINATE_NONE; |
| 635 | ospf->dmetric[DEFAULT_ROUTE].type = -1; |
| 636 | ospf->dmetric[DEFAULT_ROUTE].value = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 637 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 638 | zclient_redistribute_default (ZEBRA_REDISTRIBUTE_DEFAULT_DELETE, zclient); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 639 | |
| 640 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 641 | zlog_debug ("Redistribute[DEFAULT]: Stop"); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 642 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 643 | ospf_asbr_status_update (ospf, --ospf->redistribute); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 644 | |
| 645 | return CMD_SUCCESS; |
| 646 | } |
| 647 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 648 | static int |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 649 | ospf_external_lsa_originate_check (struct ospf *ospf, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 650 | struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 651 | { |
| 652 | /* If prefix is multicast, then do not originate LSA. */ |
| 653 | if (IN_MULTICAST (htonl (ei->p.prefix.s_addr))) |
| 654 | { |
| 655 | zlog_info ("LSA[Type5:%s]: Not originate AS-external-LSA, " |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 656 | "Prefix belongs multicast", inet_ntoa (ei->p.prefix)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 657 | return 0; |
| 658 | } |
| 659 | |
| 660 | /* Take care of default-originate. */ |
| 661 | if (is_prefix_default (&ei->p)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 662 | if (ospf->default_originate == DEFAULT_ORIGINATE_NONE) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 663 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 664 | zlog_info ("LSA[Type5:0.0.0.0]: Not originate AS-exntenal-LSA " |
| 665 | "for default"); |
| 666 | return 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 667 | } |
| 668 | |
| 669 | return 1; |
| 670 | } |
| 671 | |
| 672 | /* If connected prefix is OSPF enable interface, then do not announce. */ |
| 673 | int |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 674 | ospf_distribute_check_connected (struct ospf *ospf, struct external_info *ei) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 675 | { |
| 676 | struct route_node *rn; |
| 677 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 678 | for (rn = route_top (ospf->networks); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 679 | if (rn->info != NULL) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 680 | if (prefix_match (&rn->p, (struct prefix *) &ei->p)) |
| 681 | { |
| 682 | route_unlock_node (rn); |
| 683 | return 0; |
| 684 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 685 | |
| 686 | return 1; |
| 687 | } |
| 688 | |
| 689 | /* return 1 if external LSA must be originated, 0 otherwise */ |
| 690 | int |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 691 | ospf_redistribute_check (struct ospf *ospf, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 692 | struct external_info *ei, int *changed) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 693 | { |
| 694 | struct route_map_set_values save_values; |
| 695 | struct prefix_ipv4 *p = &ei->p; |
| 696 | u_char type = is_prefix_default (&ei->p) ? DEFAULT_ROUTE : ei->type; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 697 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | if (changed) |
| 699 | *changed = 0; |
| 700 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 701 | if (!ospf_external_lsa_originate_check (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 702 | return 0; |
| 703 | |
| 704 | /* Take care connected route. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 705 | if (type == ZEBRA_ROUTE_CONNECT && |
| 706 | !ospf_distribute_check_connected (ospf, ei)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 707 | return 0; |
| 708 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 709 | if (!DEFAULT_ROUTE_TYPE (type) && DISTRIBUTE_NAME (ospf, type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 710 | /* distirbute-list exists, but access-list may not? */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 711 | if (DISTRIBUTE_LIST (ospf, type)) |
| 712 | if (access_list_apply (DISTRIBUTE_LIST (ospf, type), p) == FILTER_DENY) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 713 | { |
| 714 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 715 | zlog_debug ("Redistribute[%s]: %s/%d filtered by ditribute-list.", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 716 | LOOKUP (ospf_redistributed_proto, type), |
| 717 | inet_ntoa (p->prefix), p->prefixlen); |
| 718 | return 0; |
| 719 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 720 | |
| 721 | save_values = ei->route_map_set; |
| 722 | ospf_reset_route_map_set_values (&ei->route_map_set); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 723 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 724 | /* apply route-map if needed */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 725 | if (ROUTEMAP_NAME (ospf, type)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 726 | { |
| 727 | int ret; |
| 728 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 729 | ret = route_map_apply (ROUTEMAP (ospf, type), (struct prefix *) p, |
| 730 | RMAP_OSPF, ei); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 731 | |
| 732 | if (ret == RMAP_DENYMATCH) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 733 | { |
| 734 | ei->route_map_set = save_values; |
| 735 | if (IS_DEBUG_OSPF (zebra, ZEBRA_REDISTRIBUTE)) |
ajs | 9b0e25c | 2004-12-08 19:06:51 +0000 | [diff] [blame] | 736 | zlog_debug ("Redistribute[%s]: %s/%d filtered by route-map.", |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 737 | LOOKUP (ospf_redistributed_proto, type), |
| 738 | inet_ntoa (p->prefix), p->prefixlen); |
| 739 | return 0; |
| 740 | } |
| 741 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 742 | /* check if 'route-map set' changed something */ |
| 743 | if (changed) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 744 | *changed = !ospf_route_map_set_compare (&ei->route_map_set, |
| 745 | &save_values); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 746 | } |
| 747 | |
| 748 | return 1; |
| 749 | } |
| 750 | |
| 751 | /* OSPF route-map set for redistribution */ |
| 752 | void |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 753 | ospf_routemap_set (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 754 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 755 | if (ROUTEMAP_NAME (ospf, type)) |
| 756 | free (ROUTEMAP_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 757 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 758 | ROUTEMAP_NAME (ospf, type) = strdup (name); |
| 759 | ROUTEMAP (ospf, type) = route_map_lookup_by_name (name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 760 | } |
| 761 | |
| 762 | void |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 763 | ospf_routemap_unset (struct ospf *ospf, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 764 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 765 | if (ROUTEMAP_NAME (ospf, type)) |
| 766 | free (ROUTEMAP_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 767 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 768 | ROUTEMAP_NAME (ospf, type) = NULL; |
| 769 | ROUTEMAP (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 770 | } |
| 771 | |
| 772 | /* Zebra route add and delete treatment. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 773 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 774 | ospf_zebra_read_ipv4 (int command, struct zclient *zclient, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 775 | zebra_size_t length) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 776 | { |
| 777 | struct stream *s; |
| 778 | struct zapi_ipv4 api; |
| 779 | unsigned long ifindex; |
| 780 | struct in_addr nexthop; |
| 781 | struct prefix_ipv4 p; |
| 782 | struct external_info *ei; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 783 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 784 | |
| 785 | s = zclient->ibuf; |
| 786 | ifindex = 0; |
| 787 | nexthop.s_addr = 0; |
| 788 | |
| 789 | /* Type, flags, message. */ |
| 790 | api.type = stream_getc (s); |
| 791 | api.flags = stream_getc (s); |
| 792 | api.message = stream_getc (s); |
| 793 | |
| 794 | /* IPv4 prefix. */ |
| 795 | memset (&p, 0, sizeof (struct prefix_ipv4)); |
| 796 | p.family = AF_INET; |
| 797 | p.prefixlen = stream_getc (s); |
| 798 | stream_get (&p.prefix, s, PSIZE (p.prefixlen)); |
| 799 | |
hasso | 8585d4e | 2004-04-20 17:25:12 +0000 | [diff] [blame] | 800 | if (IPV4_NET127(ntohl(p.prefix.s_addr))) |
| 801 | return 0; |
| 802 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 803 | /* Nexthop, ifindex, distance, metric. */ |
| 804 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP)) |
| 805 | { |
| 806 | api.nexthop_num = stream_getc (s); |
| 807 | nexthop.s_addr = stream_get_ipv4 (s); |
| 808 | } |
| 809 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_IFINDEX)) |
| 810 | { |
| 811 | api.ifindex_num = stream_getc (s); |
gdt | 6a8da85 | 2004-02-13 17:40:51 +0000 | [diff] [blame] | 812 | /* XXX assert(api.ifindex_num == 1); */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | ifindex = stream_getl (s); |
| 814 | } |
| 815 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE)) |
| 816 | api.distance = stream_getc (s); |
| 817 | if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC)) |
| 818 | api.metric = stream_getl (s); |
| 819 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 820 | ospf = ospf_lookup (); |
| 821 | if (ospf == NULL) |
| 822 | return 0; |
| 823 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 824 | if (command == ZEBRA_IPV4_ROUTE_ADD) |
| 825 | { |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 826 | /* XXX|HACK|TODO|FIXME: |
hasso | a0a3976 | 2004-04-23 08:51:10 +0000 | [diff] [blame] | 827 | * Maybe we should ignore reject/blackhole routes? Testing shows that |
| 828 | * there is no problems though and this is only way to "summarize" |
| 829 | * routes in ASBR at the moment. Maybe we need just a better generalised |
| 830 | * solution for these types? |
| 831 | * |
| 832 | * if ( CHECK_FLAG (api.flags, ZEBRA_FLAG_BLACKHOLE) |
| 833 | * || CHECK_FLAG (api.flags, ZEBRA_FLAG_REJECT)) |
| 834 | * return 0; |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 835 | */ |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 836 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | ei = ospf_external_info_add (api.type, p, ifindex, nexthop); |
| 838 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 839 | if (ospf->router_id.s_addr == 0) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 840 | /* Set flags to generate AS-external-LSA originate event |
| 841 | for each redistributed protocols later. */ |
| 842 | ospf->external_origin |= (1 << api.type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 843 | else |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 844 | { |
| 845 | if (ei) |
| 846 | { |
| 847 | if (is_prefix_default (&p)) |
| 848 | ospf_external_lsa_refresh_default (ospf); |
| 849 | else |
| 850 | { |
| 851 | struct ospf_lsa *current; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 852 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 853 | current = ospf_external_info_find_lsa (ospf, &ei->p); |
| 854 | if (!current) |
| 855 | ospf_external_lsa_originate (ospf, ei); |
| 856 | else if (IS_LSA_MAXAGE (current)) |
| 857 | ospf_external_lsa_refresh (ospf, current, |
| 858 | ei, LSA_REFRESH_FORCE); |
| 859 | else |
| 860 | zlog_warn ("ospf_zebra_read_ipv4() : %s already exists", |
| 861 | inet_ntoa (p.prefix)); |
| 862 | } |
| 863 | } |
| 864 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 865 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 866 | else /* if (command == ZEBRA_IPV4_ROUTE_DELETE) */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | { |
| 868 | ospf_external_info_delete (api.type, p); |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 869 | if (is_prefix_default (&p)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 870 | ospf_external_lsa_refresh_default (ospf); |
paul | 7021c42 | 2003-07-15 12:52:22 +0000 | [diff] [blame] | 871 | else |
| 872 | ospf_external_lsa_flush (ospf, api.type, &p, ifindex, nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 873 | } |
| 874 | |
| 875 | return 0; |
| 876 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 877 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 878 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 880 | ospf_distribute_list_out_set (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 881 | { |
| 882 | /* Lookup access-list for distribute-list. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 883 | DISTRIBUTE_LIST (ospf, type) = access_list_lookup (AFI_IP, name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 884 | |
| 885 | /* Clear previous distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 886 | if (DISTRIBUTE_NAME (ospf, type)) |
| 887 | free (DISTRIBUTE_NAME (ospf, type)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 888 | |
| 889 | /* Set distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 890 | DISTRIBUTE_NAME (ospf, type) = strdup (name); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 891 | |
| 892 | /* If access-list have been set, schedule update timer. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 893 | if (DISTRIBUTE_LIST (ospf, type)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 894 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 895 | |
| 896 | return CMD_SUCCESS; |
| 897 | } |
| 898 | |
| 899 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 900 | ospf_distribute_list_out_unset (struct ospf *ospf, int type, const char *name) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 901 | { |
| 902 | /* Schedule update timer. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 903 | if (DISTRIBUTE_LIST (ospf, type)) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 904 | ospf_distribute_list_update (ospf, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 905 | |
| 906 | /* Unset distribute-list. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 907 | DISTRIBUTE_LIST (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 908 | |
| 909 | /* Clear distribute-name. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 910 | if (DISTRIBUTE_NAME (ospf, type)) |
| 911 | free (DISTRIBUTE_NAME (ospf, type)); |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 912 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 913 | DISTRIBUTE_NAME (ospf, type) = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 914 | |
| 915 | return CMD_SUCCESS; |
| 916 | } |
| 917 | |
| 918 | /* distribute-list update timer. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 919 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 920 | ospf_distribute_list_update_timer (struct thread *thread) |
| 921 | { |
| 922 | struct route_node *rn; |
| 923 | struct external_info *ei; |
| 924 | struct route_table *rt; |
| 925 | struct ospf_lsa *lsa; |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 926 | intptr_t type; |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 927 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 928 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 929 | type = (intptr_t)THREAD_ARG (thread); |
paul | 64511f3 | 2004-10-31 18:01:13 +0000 | [diff] [blame] | 930 | assert (type < ZEBRA_ROUTE_MAX); |
| 931 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 932 | rt = EXTERNAL_INFO (type); |
| 933 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 934 | ospf = ospf_lookup (); |
| 935 | if (ospf == NULL) |
| 936 | return 0; |
| 937 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 938 | ospf->t_distribute_update = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 939 | |
| 940 | zlog_info ("Zebra[Redistribute]: distribute-list update timer fired!"); |
| 941 | |
| 942 | /* foreach all external info. */ |
| 943 | if (rt) |
| 944 | for (rn = route_top (rt); rn; rn = route_next (rn)) |
| 945 | if ((ei = rn->info) != NULL) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 946 | { |
| 947 | if (is_prefix_default (&ei->p)) |
| 948 | ospf_external_lsa_refresh_default (ospf); |
| 949 | else if ((lsa = ospf_external_info_find_lsa (ospf, &ei->p))) |
| 950 | ospf_external_lsa_refresh (ospf, lsa, ei, LSA_REFRESH_IF_CHANGED); |
| 951 | else |
| 952 | ospf_external_lsa_originate (ospf, ei); |
| 953 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 954 | return 0; |
| 955 | } |
| 956 | |
| 957 | #define OSPF_DISTRIBUTE_UPDATE_DELAY 5 |
| 958 | |
| 959 | /* Update distribute-list and set timer to apply access-list. */ |
| 960 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 961 | ospf_distribute_list_update (struct ospf *ospf, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 962 | { |
| 963 | struct route_table *rt; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 964 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 965 | /* External info does not exist. */ |
| 966 | if (!(rt = EXTERNAL_INFO (type))) |
| 967 | return; |
| 968 | |
| 969 | /* If exists previously invoked thread, then cancel it. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 970 | if (ospf->t_distribute_update) |
| 971 | OSPF_TIMER_OFF (ospf->t_distribute_update); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 972 | |
| 973 | /* Set timer. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 974 | ospf->t_distribute_update = |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 975 | thread_add_timer (master, ospf_distribute_list_update_timer, |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 976 | (void *) type, OSPF_DISTRIBUTE_UPDATE_DELAY); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 977 | } |
| 978 | |
| 979 | /* If access-list is updated, apply some check. */ |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 980 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 981 | ospf_filter_update (struct access_list *access) |
| 982 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 983 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 984 | int type; |
| 985 | int abr_inv = 0; |
| 986 | struct ospf_area *area; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 987 | struct listnode *node; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 988 | |
| 989 | /* If OSPF instatnce does not exist, return right now. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 990 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 991 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 992 | return; |
| 993 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 994 | /* Update distribute-list, and apply filter. */ |
| 995 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
| 996 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 997 | if (ROUTEMAP (ospf, type) != NULL) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 998 | { |
| 999 | /* if route-map is not NULL it may be using this access list */ |
| 1000 | ospf_distribute_list_update (ospf, type); |
| 1001 | continue; |
| 1002 | } |
| 1003 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1004 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1005 | if (DISTRIBUTE_NAME (ospf, type)) |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1006 | { |
| 1007 | /* Keep old access-list for distribute-list. */ |
| 1008 | struct access_list *old = DISTRIBUTE_LIST (ospf, type); |
| 1009 | |
| 1010 | /* Update access-list for distribute-list. */ |
| 1011 | DISTRIBUTE_LIST (ospf, type) = |
| 1012 | access_list_lookup (AFI_IP, DISTRIBUTE_NAME (ospf, type)); |
| 1013 | |
| 1014 | /* No update for this distribute type. */ |
| 1015 | if (old == NULL && DISTRIBUTE_LIST (ospf, type) == NULL) |
| 1016 | continue; |
| 1017 | |
| 1018 | /* Schedule distribute-list update timer. */ |
| 1019 | if (DISTRIBUTE_LIST (ospf, type) == NULL || |
| 1020 | strcmp (DISTRIBUTE_NAME (ospf, type), access->name) == 0) |
| 1021 | ospf_distribute_list_update (ospf, type); |
| 1022 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1023 | } |
| 1024 | |
| 1025 | /* Update Area access-list. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1026 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
| 1027 | { |
| 1028 | if (EXPORT_NAME (area)) |
| 1029 | { |
| 1030 | EXPORT_LIST (area) = NULL; |
| 1031 | abr_inv++; |
| 1032 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1033 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1034 | if (IMPORT_NAME (area)) |
| 1035 | { |
| 1036 | IMPORT_LIST (area) = NULL; |
| 1037 | abr_inv++; |
| 1038 | } |
| 1039 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1040 | |
| 1041 | /* Schedule ABR tasks -- this will be changed -- takada. */ |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1042 | if (IS_OSPF_ABR (ospf) && abr_inv) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1043 | ospf_schedule_abr_task (ospf); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1044 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1045 | |
| 1046 | /* If prefix-list is updated, do some updates. */ |
| 1047 | void |
| 1048 | ospf_prefix_list_update (struct prefix_list *plist) |
| 1049 | { |
| 1050 | struct ospf *ospf; |
| 1051 | int type; |
| 1052 | int abr_inv = 0; |
| 1053 | struct ospf_area *area; |
hasso | 52dc7ee | 2004-09-23 19:18:23 +0000 | [diff] [blame] | 1054 | struct listnode *node; |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1055 | |
| 1056 | /* If OSPF instatnce does not exist, return right now. */ |
| 1057 | ospf = ospf_lookup (); |
| 1058 | if (ospf == NULL) |
| 1059 | return; |
| 1060 | |
| 1061 | /* Update all route-maps which are used as redistribution filters. |
| 1062 | * They might use prefix-list. |
| 1063 | */ |
| 1064 | for (type = 0; type < ZEBRA_ROUTE_MAX; type++) |
| 1065 | { |
| 1066 | if (ROUTEMAP (ospf, type) != NULL) |
| 1067 | { |
| 1068 | /* If route-map is not NULL it may be using this prefix list */ |
| 1069 | ospf_distribute_list_update (ospf, type); |
| 1070 | continue; |
| 1071 | } |
| 1072 | } |
| 1073 | |
| 1074 | /* Update area filter-lists. */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1075 | for (ALL_LIST_ELEMENTS_RO (ospf->areas, node, area)) |
| 1076 | { |
| 1077 | /* Update filter-list in. */ |
| 1078 | if (PREFIX_NAME_IN (area)) |
| 1079 | if (strcmp (PREFIX_NAME_IN (area), plist->name) == 0) |
| 1080 | { |
| 1081 | PREFIX_LIST_IN (area) = |
| 1082 | prefix_list_lookup (AFI_IP, PREFIX_NAME_IN (area)); |
| 1083 | abr_inv++; |
| 1084 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1085 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1086 | /* Update filter-list out. */ |
| 1087 | if (PREFIX_NAME_OUT (area)) |
| 1088 | if (strcmp (PREFIX_NAME_OUT (area), plist->name) == 0) |
| 1089 | { |
| 1090 | PREFIX_LIST_IN (area) = |
| 1091 | prefix_list_lookup (AFI_IP, PREFIX_NAME_OUT (area)); |
| 1092 | abr_inv++; |
| 1093 | } |
| 1094 | } |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1095 | |
| 1096 | /* Schedule ABR task. */ |
| 1097 | if (IS_OSPF_ABR (ospf) && abr_inv) |
| 1098 | ospf_schedule_abr_task (ospf); |
| 1099 | } |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1100 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 1101 | static struct ospf_distance * |
| 1102 | ospf_distance_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1103 | { |
| 1104 | struct ospf_distance *new; |
| 1105 | new = XMALLOC (MTYPE_OSPF_DISTANCE, sizeof (struct ospf_distance)); |
| 1106 | memset (new, 0, sizeof (struct ospf_distance)); |
| 1107 | return new; |
| 1108 | } |
| 1109 | |
paul | 4dadc29 | 2005-05-06 21:37:42 +0000 | [diff] [blame^] | 1110 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1111 | ospf_distance_free (struct ospf_distance *odistance) |
| 1112 | { |
| 1113 | XFREE (MTYPE_OSPF_DISTANCE, odistance); |
| 1114 | } |
| 1115 | |
| 1116 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1117 | ospf_distance_set (struct vty *vty, struct ospf *ospf, |
| 1118 | const char *distance_str, |
| 1119 | const char *ip_str, |
| 1120 | const char *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1121 | { |
| 1122 | int ret; |
| 1123 | struct prefix_ipv4 p; |
| 1124 | u_char distance; |
| 1125 | struct route_node *rn; |
| 1126 | struct ospf_distance *odistance; |
| 1127 | |
| 1128 | ret = str2prefix_ipv4 (ip_str, &p); |
| 1129 | if (ret == 0) |
| 1130 | { |
| 1131 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 1132 | return CMD_WARNING; |
| 1133 | } |
| 1134 | |
| 1135 | distance = atoi (distance_str); |
| 1136 | |
| 1137 | /* Get OSPF distance node. */ |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1138 | rn = route_node_get (ospf->distance_table, (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1139 | if (rn->info) |
| 1140 | { |
| 1141 | odistance = rn->info; |
| 1142 | route_unlock_node (rn); |
| 1143 | } |
| 1144 | else |
| 1145 | { |
| 1146 | odistance = ospf_distance_new (); |
| 1147 | rn->info = odistance; |
| 1148 | } |
| 1149 | |
| 1150 | /* Set distance value. */ |
| 1151 | odistance->distance = distance; |
| 1152 | |
| 1153 | /* Reset access-list configuration. */ |
| 1154 | if (odistance->access_list) |
| 1155 | { |
| 1156 | free (odistance->access_list); |
| 1157 | odistance->access_list = NULL; |
| 1158 | } |
| 1159 | if (access_list_str) |
| 1160 | odistance->access_list = strdup (access_list_str); |
| 1161 | |
| 1162 | return CMD_SUCCESS; |
| 1163 | } |
| 1164 | |
| 1165 | int |
paul | 6c83567 | 2004-10-11 11:00:30 +0000 | [diff] [blame] | 1166 | ospf_distance_unset (struct vty *vty, struct ospf *ospf, |
| 1167 | const char *distance_str, |
| 1168 | const char *ip_str, char |
| 1169 | const *access_list_str) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1170 | { |
| 1171 | int ret; |
| 1172 | struct prefix_ipv4 p; |
| 1173 | u_char distance; |
| 1174 | struct route_node *rn; |
| 1175 | struct ospf_distance *odistance; |
| 1176 | |
| 1177 | ret = str2prefix_ipv4 (ip_str, &p); |
| 1178 | if (ret == 0) |
| 1179 | { |
| 1180 | vty_out (vty, "Malformed prefix%s", VTY_NEWLINE); |
| 1181 | return CMD_WARNING; |
| 1182 | } |
| 1183 | |
| 1184 | distance = atoi (distance_str); |
| 1185 | |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1186 | rn = route_node_lookup (ospf->distance_table, (struct prefix *) &p); |
| 1187 | if (!rn) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1188 | { |
| 1189 | vty_out (vty, "Can't find specified prefix%s", VTY_NEWLINE); |
| 1190 | return CMD_WARNING; |
| 1191 | } |
| 1192 | |
| 1193 | odistance = rn->info; |
| 1194 | |
| 1195 | if (odistance->access_list) |
| 1196 | free (odistance->access_list); |
| 1197 | ospf_distance_free (odistance); |
| 1198 | |
| 1199 | rn->info = NULL; |
| 1200 | route_unlock_node (rn); |
| 1201 | route_unlock_node (rn); |
| 1202 | |
| 1203 | return CMD_SUCCESS; |
| 1204 | } |
| 1205 | |
| 1206 | void |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1207 | ospf_distance_reset (struct ospf *ospf) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1208 | { |
| 1209 | struct route_node *rn; |
| 1210 | struct ospf_distance *odistance; |
| 1211 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1212 | for (rn = route_top (ospf->distance_table); rn; rn = route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1213 | if ((odistance = rn->info) != NULL) |
| 1214 | { |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1215 | if (odistance->access_list) |
| 1216 | free (odistance->access_list); |
| 1217 | ospf_distance_free (odistance); |
| 1218 | rn->info = NULL; |
| 1219 | route_unlock_node (rn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1220 | } |
| 1221 | } |
| 1222 | |
| 1223 | u_char |
| 1224 | ospf_distance_apply (struct prefix_ipv4 *p, struct ospf_route *or) |
| 1225 | { |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1226 | struct ospf *ospf; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1227 | |
paul | 020709f | 2003-04-04 02:44:16 +0000 | [diff] [blame] | 1228 | ospf = ospf_lookup (); |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1229 | if (ospf == NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1230 | return 0; |
| 1231 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1232 | if (ospf->distance_intra) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1233 | if (or->path_type == OSPF_PATH_INTRA_AREA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1234 | return ospf->distance_intra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1235 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1236 | if (ospf->distance_inter) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1237 | if (or->path_type == OSPF_PATH_INTER_AREA) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1238 | return ospf->distance_inter; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1239 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1240 | if (ospf->distance_external) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1241 | if (or->path_type == OSPF_PATH_TYPE1_EXTERNAL |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1242 | || or->path_type == OSPF_PATH_TYPE2_EXTERNAL) |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1243 | return ospf->distance_external; |
paul | cf795c5 | 2003-06-19 02:13:25 +0000 | [diff] [blame] | 1244 | |
paul | 6898008 | 2003-03-25 05:07:42 +0000 | [diff] [blame] | 1245 | if (ospf->distance_all) |
| 1246 | return ospf->distance_all; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1247 | |
| 1248 | return 0; |
| 1249 | } |
| 1250 | |
| 1251 | void |
| 1252 | ospf_zebra_init () |
| 1253 | { |
| 1254 | /* Allocate zebra structure. */ |
| 1255 | zclient = zclient_new (); |
| 1256 | zclient_init (zclient, ZEBRA_ROUTE_OSPF); |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 1257 | zclient->router_id_update = ospf_router_id_update_zebra; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1258 | zclient->interface_add = ospf_interface_add; |
| 1259 | zclient->interface_delete = ospf_interface_delete; |
| 1260 | zclient->interface_up = ospf_interface_state_up; |
| 1261 | zclient->interface_down = ospf_interface_state_down; |
| 1262 | zclient->interface_address_add = ospf_interface_address_add; |
| 1263 | zclient->interface_address_delete = ospf_interface_address_delete; |
| 1264 | zclient->ipv4_route_add = ospf_zebra_read_ipv4; |
| 1265 | zclient->ipv4_route_delete = ospf_zebra_read_ipv4; |
| 1266 | |
| 1267 | access_list_add_hook (ospf_filter_update); |
| 1268 | access_list_delete_hook (ospf_filter_update); |
hasso | dd669bb | 2004-05-10 07:43:59 +0000 | [diff] [blame] | 1269 | prefix_list_add_hook (ospf_prefix_list_update); |
| 1270 | prefix_list_delete_hook (ospf_prefix_list_update); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1271 | } |