paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* BGP nexthop scan |
| 2 | Copyright (C) 2000 Kunihiro Ishiguro |
| 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 Free |
| 18 | Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 19 | 02111-1307, USA. */ |
| 20 | |
| 21 | #include <zebra.h> |
| 22 | |
| 23 | #include "command.h" |
| 24 | #include "thread.h" |
| 25 | #include "prefix.h" |
| 26 | #include "zclient.h" |
| 27 | #include "stream.h" |
| 28 | #include "network.h" |
| 29 | #include "log.h" |
| 30 | #include "memory.h" |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 31 | #include "hash.h" |
| 32 | #include "jhash.h" |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 33 | |
| 34 | #include "bgpd/bgpd.h" |
| 35 | #include "bgpd/bgp_table.h" |
| 36 | #include "bgpd/bgp_route.h" |
| 37 | #include "bgpd/bgp_attr.h" |
| 38 | #include "bgpd/bgp_nexthop.h" |
| 39 | #include "bgpd/bgp_debug.h" |
| 40 | #include "bgpd/bgp_damp.h" |
| 41 | #include "zebra/rib.h" |
| 42 | #include "zebra/zserv.h" /* For ZEBRA_SERV_PATH. */ |
| 43 | |
| 44 | struct bgp_nexthop_cache *zlookup_query (struct in_addr); |
| 45 | #ifdef HAVE_IPV6 |
| 46 | struct bgp_nexthop_cache *zlookup_query_ipv6 (struct in6_addr *); |
| 47 | #endif /* HAVE_IPV6 */ |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 48 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 49 | /* Only one BGP scan thread are activated at the same time. */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 50 | static struct thread *bgp_scan_thread = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 51 | |
| 52 | /* BGP import thread */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 53 | static struct thread *bgp_import_thread = NULL; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 54 | |
| 55 | /* BGP scan interval. */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 56 | static int bgp_scan_interval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 57 | |
| 58 | /* BGP import interval. */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 59 | static int bgp_import_interval; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 60 | |
| 61 | /* Route table for next-hop lookup cache. */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 62 | static struct bgp_table *bgp_nexthop_cache_table[AFI_MAX]; |
| 63 | static struct bgp_table *cache1_table[AFI_MAX]; |
| 64 | static struct bgp_table *cache2_table[AFI_MAX]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 65 | |
| 66 | /* Route table for connected route. */ |
paul | 00d252c | 2005-05-23 14:19:54 +0000 | [diff] [blame] | 67 | static struct bgp_table *bgp_connected_table[AFI_MAX]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 68 | |
| 69 | /* BGP nexthop lookup query client. */ |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 70 | struct zclient *zlookup = NULL; |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 71 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 72 | /* Add nexthop to the end of the list. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 73 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 74 | bnc_nexthop_add (struct bgp_nexthop_cache *bnc, struct nexthop *nexthop) |
| 75 | { |
| 76 | struct nexthop *last; |
| 77 | |
| 78 | for (last = bnc->nexthop; last && last->next; last = last->next) |
| 79 | ; |
| 80 | if (last) |
| 81 | last->next = nexthop; |
| 82 | else |
| 83 | bnc->nexthop = nexthop; |
| 84 | nexthop->prev = last; |
| 85 | } |
| 86 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 87 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 88 | bnc_nexthop_free (struct bgp_nexthop_cache *bnc) |
| 89 | { |
| 90 | struct nexthop *nexthop; |
| 91 | struct nexthop *next = NULL; |
| 92 | |
| 93 | for (nexthop = bnc->nexthop; nexthop; nexthop = next) |
| 94 | { |
| 95 | next = nexthop->next; |
| 96 | XFREE (MTYPE_NEXTHOP, nexthop); |
| 97 | } |
| 98 | } |
| 99 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 100 | static struct bgp_nexthop_cache * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 101 | bnc_new (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 102 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 103 | return XCALLOC (MTYPE_BGP_NEXTHOP_CACHE, sizeof (struct bgp_nexthop_cache)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 104 | } |
| 105 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 106 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 107 | bnc_free (struct bgp_nexthop_cache *bnc) |
| 108 | { |
| 109 | bnc_nexthop_free (bnc); |
| 110 | XFREE (MTYPE_BGP_NEXTHOP_CACHE, bnc); |
| 111 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 112 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 113 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 114 | bgp_nexthop_same (struct nexthop *next1, struct nexthop *next2) |
| 115 | { |
| 116 | if (next1->type != next2->type) |
| 117 | return 0; |
| 118 | |
| 119 | switch (next1->type) |
| 120 | { |
| 121 | case ZEBRA_NEXTHOP_IPV4: |
| 122 | if (! IPV4_ADDR_SAME (&next1->gate.ipv4, &next2->gate.ipv4)) |
| 123 | return 0; |
| 124 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 125 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 126 | if (! IPV4_ADDR_SAME (&next1->gate.ipv4, &next2->gate.ipv4) |
| 127 | || next1->ifindex != next2->ifindex) |
| 128 | return 0; |
| 129 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 130 | case ZEBRA_NEXTHOP_IFINDEX: |
| 131 | case ZEBRA_NEXTHOP_IFNAME: |
| 132 | if (next1->ifindex != next2->ifindex) |
| 133 | return 0; |
| 134 | break; |
| 135 | #ifdef HAVE_IPV6 |
| 136 | case ZEBRA_NEXTHOP_IPV6: |
| 137 | if (! IPV6_ADDR_SAME (&next1->gate.ipv6, &next2->gate.ipv6)) |
| 138 | return 0; |
| 139 | break; |
| 140 | case ZEBRA_NEXTHOP_IPV6_IFINDEX: |
| 141 | case ZEBRA_NEXTHOP_IPV6_IFNAME: |
| 142 | if (! IPV6_ADDR_SAME (&next1->gate.ipv6, &next2->gate.ipv6)) |
| 143 | return 0; |
| 144 | if (next1->ifindex != next2->ifindex) |
| 145 | return 0; |
| 146 | break; |
| 147 | #endif /* HAVE_IPV6 */ |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 148 | default: |
| 149 | /* do nothing */ |
| 150 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 151 | } |
| 152 | return 1; |
| 153 | } |
| 154 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 155 | static int |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 156 | bgp_nexthop_cache_different (struct bgp_nexthop_cache *bnc1, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 157 | struct bgp_nexthop_cache *bnc2) |
| 158 | { |
| 159 | int i; |
| 160 | struct nexthop *next1, *next2; |
| 161 | |
| 162 | if (bnc1->nexthop_num != bnc2->nexthop_num) |
| 163 | return 1; |
| 164 | |
| 165 | next1 = bnc1->nexthop; |
| 166 | next2 = bnc2->nexthop; |
| 167 | |
| 168 | for (i = 0; i < bnc1->nexthop_num; i++) |
| 169 | { |
| 170 | if (! bgp_nexthop_same (next1, next2)) |
| 171 | return 1; |
| 172 | |
| 173 | next1 = next1->next; |
| 174 | next2 = next2->next; |
| 175 | } |
| 176 | return 0; |
| 177 | } |
| 178 | |
| 179 | /* If nexthop exists on connected network return 1. */ |
| 180 | int |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 181 | bgp_nexthop_onlink (afi_t afi, struct attr *attr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 182 | { |
| 183 | struct bgp_node *rn; |
Paul Jakma | fc98d16 | 2012-01-09 11:36:23 +0000 | [diff] [blame] | 184 | |
| 185 | /* If zebra is not enabled return */ |
| 186 | if (zlookup->sock < 0) |
| 187 | return 1; |
| 188 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 189 | /* Lookup the address is onlink or not. */ |
| 190 | if (afi == AFI_IP) |
| 191 | { |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 192 | rn = bgp_node_match_ipv4 (bgp_connected_table[AFI_IP], &attr->nexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 193 | if (rn) |
| 194 | { |
| 195 | bgp_unlock_node (rn); |
| 196 | return 1; |
| 197 | } |
| 198 | } |
| 199 | #ifdef HAVE_IPV6 |
| 200 | else if (afi == AFI_IP6) |
| 201 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 202 | if (attr->extra->mp_nexthop_len == 32) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 203 | return 1; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 204 | else if (attr->extra->mp_nexthop_len == 16) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 205 | { |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 206 | if (IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 207 | return 1; |
| 208 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 209 | rn = bgp_node_match_ipv6 (bgp_connected_table[AFI_IP6], |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 210 | &attr->extra->mp_nexthop_global); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 211 | if (rn) |
| 212 | { |
| 213 | bgp_unlock_node (rn); |
| 214 | return 1; |
| 215 | } |
| 216 | } |
| 217 | } |
| 218 | #endif /* HAVE_IPV6 */ |
| 219 | return 0; |
| 220 | } |
| 221 | |
| 222 | #ifdef HAVE_IPV6 |
| 223 | /* Check specified next-hop is reachable or not. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 224 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 225 | bgp_nexthop_lookup_ipv6 (struct peer *peer, struct bgp_info *ri, int *changed, |
| 226 | int *metricchanged) |
| 227 | { |
| 228 | struct bgp_node *rn; |
| 229 | struct prefix p; |
| 230 | struct bgp_nexthop_cache *bnc; |
| 231 | struct attr *attr; |
Paul Jakma | fc98d16 | 2012-01-09 11:36:23 +0000 | [diff] [blame] | 232 | |
| 233 | /* If lookup is not enabled, return valid. */ |
| 234 | if (zlookup->sock < 0) |
| 235 | { |
| 236 | if (ri->extra) |
| 237 | ri->extra->igpmetric = 0; |
| 238 | return 1; |
| 239 | } |
| 240 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 241 | /* Only check IPv6 global address only nexthop. */ |
| 242 | attr = ri->attr; |
| 243 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 244 | if (attr->extra->mp_nexthop_len != 16 |
| 245 | || IN6_IS_ADDR_LINKLOCAL (&attr->extra->mp_nexthop_global)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 246 | return 1; |
| 247 | |
| 248 | memset (&p, 0, sizeof (struct prefix)); |
| 249 | p.family = AF_INET6; |
| 250 | p.prefixlen = IPV6_MAX_BITLEN; |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 251 | p.u.prefix6 = attr->extra->mp_nexthop_global; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 252 | |
| 253 | /* IBGP or ebgp-multihop */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 254 | rn = bgp_node_get (bgp_nexthop_cache_table[AFI_IP6], &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 255 | |
| 256 | if (rn->info) |
| 257 | { |
| 258 | bnc = rn->info; |
| 259 | bgp_unlock_node (rn); |
| 260 | } |
| 261 | else |
| 262 | { |
Denis Ovsienko | b64bfc1 | 2011-08-08 19:36:44 +0400 | [diff] [blame] | 263 | if (NULL == (bnc = zlookup_query_ipv6 (&attr->extra->mp_nexthop_global))) |
| 264 | bnc = bnc_new (); |
| 265 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 266 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 267 | if (changed) |
| 268 | { |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 269 | struct bgp_table *old; |
| 270 | struct bgp_node *oldrn; |
| 271 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 272 | if (bgp_nexthop_cache_table[AFI_IP6] == cache1_table[AFI_IP6]) |
| 273 | old = cache2_table[AFI_IP6]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 274 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 275 | old = cache1_table[AFI_IP6]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 276 | |
| 277 | oldrn = bgp_node_lookup (old, &p); |
| 278 | if (oldrn) |
| 279 | { |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 280 | struct bgp_nexthop_cache *oldbnc = oldrn->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 281 | |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 282 | bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 283 | |
| 284 | if (bnc->metric != oldbnc->metric) |
| 285 | bnc->metricchanged = 1; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 286 | |
| 287 | bgp_unlock_node (oldrn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 288 | } |
| 289 | } |
| 290 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 291 | rn->info = bnc; |
| 292 | } |
| 293 | |
| 294 | if (changed) |
| 295 | *changed = bnc->changed; |
| 296 | |
| 297 | if (metricchanged) |
| 298 | *metricchanged = bnc->metricchanged; |
| 299 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 300 | if (bnc->valid && bnc->metric) |
| 301 | (bgp_info_extra_get (ri))->igpmetric = bnc->metric; |
| 302 | else if (ri->extra) |
| 303 | ri->extra->igpmetric = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 304 | |
| 305 | return bnc->valid; |
| 306 | } |
| 307 | #endif /* HAVE_IPV6 */ |
| 308 | |
| 309 | /* Check specified next-hop is reachable or not. */ |
| 310 | int |
| 311 | bgp_nexthop_lookup (afi_t afi, struct peer *peer, struct bgp_info *ri, |
| 312 | int *changed, int *metricchanged) |
| 313 | { |
| 314 | struct bgp_node *rn; |
| 315 | struct prefix p; |
| 316 | struct bgp_nexthop_cache *bnc; |
| 317 | struct in_addr addr; |
Paul Jakma | fc98d16 | 2012-01-09 11:36:23 +0000 | [diff] [blame] | 318 | |
| 319 | /* If lookup is not enabled, return valid. */ |
| 320 | if (zlookup->sock < 0) |
| 321 | { |
| 322 | if (ri->extra) |
| 323 | ri->extra->igpmetric = 0; |
| 324 | return 1; |
| 325 | } |
| 326 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 327 | #ifdef HAVE_IPV6 |
| 328 | if (afi == AFI_IP6) |
| 329 | return bgp_nexthop_lookup_ipv6 (peer, ri, changed, metricchanged); |
| 330 | #endif /* HAVE_IPV6 */ |
| 331 | |
| 332 | addr = ri->attr->nexthop; |
| 333 | |
| 334 | memset (&p, 0, sizeof (struct prefix)); |
| 335 | p.family = AF_INET; |
| 336 | p.prefixlen = IPV4_MAX_BITLEN; |
| 337 | p.u.prefix4 = addr; |
| 338 | |
| 339 | /* IBGP or ebgp-multihop */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 340 | rn = bgp_node_get (bgp_nexthop_cache_table[AFI_IP], &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | |
| 342 | if (rn->info) |
| 343 | { |
| 344 | bnc = rn->info; |
| 345 | bgp_unlock_node (rn); |
| 346 | } |
| 347 | else |
| 348 | { |
Denis Ovsienko | b64bfc1 | 2011-08-08 19:36:44 +0400 | [diff] [blame] | 349 | if (NULL == (bnc = zlookup_query (addr))) |
| 350 | bnc = bnc_new (); |
| 351 | else |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 352 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 353 | if (changed) |
| 354 | { |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 355 | struct bgp_table *old; |
| 356 | struct bgp_node *oldrn; |
| 357 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 358 | if (bgp_nexthop_cache_table[AFI_IP] == cache1_table[AFI_IP]) |
| 359 | old = cache2_table[AFI_IP]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 360 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 361 | old = cache1_table[AFI_IP]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 362 | |
| 363 | oldrn = bgp_node_lookup (old, &p); |
| 364 | if (oldrn) |
| 365 | { |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 366 | struct bgp_nexthop_cache *oldbnc = oldrn->info; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 367 | |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 368 | bnc->changed = bgp_nexthop_cache_different (bnc, oldbnc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 369 | |
| 370 | if (bnc->metric != oldbnc->metric) |
| 371 | bnc->metricchanged = 1; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 372 | |
| 373 | bgp_unlock_node (oldrn); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 374 | } |
| 375 | } |
| 376 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 377 | rn->info = bnc; |
| 378 | } |
| 379 | |
| 380 | if (changed) |
| 381 | *changed = bnc->changed; |
| 382 | |
| 383 | if (metricchanged) |
| 384 | *metricchanged = bnc->metricchanged; |
| 385 | |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 386 | if (bnc->valid && bnc->metric) |
| 387 | (bgp_info_extra_get(ri))->igpmetric = bnc->metric; |
| 388 | else if (ri->extra) |
| 389 | ri->extra->igpmetric = 0; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 390 | |
| 391 | return bnc->valid; |
| 392 | } |
| 393 | |
| 394 | /* Reset and free all BGP nexthop cache. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 395 | static void |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 396 | bgp_nexthop_cache_reset (struct bgp_table *table) |
| 397 | { |
| 398 | struct bgp_node *rn; |
| 399 | struct bgp_nexthop_cache *bnc; |
| 400 | |
| 401 | for (rn = bgp_table_top (table); rn; rn = bgp_route_next (rn)) |
| 402 | if ((bnc = rn->info) != NULL) |
| 403 | { |
| 404 | bnc_free (bnc); |
| 405 | rn->info = NULL; |
| 406 | bgp_unlock_node (rn); |
| 407 | } |
| 408 | } |
| 409 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 410 | static void |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 411 | bgp_scan (afi_t afi, safi_t safi) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 412 | { |
| 413 | struct bgp_node *rn; |
| 414 | struct bgp *bgp; |
| 415 | struct bgp_info *bi; |
| 416 | struct bgp_info *next; |
| 417 | struct peer *peer; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 418 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 419 | int valid; |
| 420 | int current; |
| 421 | int changed; |
| 422 | int metricchanged; |
| 423 | |
| 424 | /* Change cache. */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 425 | if (bgp_nexthop_cache_table[afi] == cache1_table[afi]) |
| 426 | bgp_nexthop_cache_table[afi] = cache2_table[afi]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 427 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 428 | bgp_nexthop_cache_table[afi] = cache1_table[afi]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 429 | |
| 430 | /* Get default bgp. */ |
| 431 | bgp = bgp_get_default (); |
| 432 | if (bgp == NULL) |
| 433 | return; |
| 434 | |
| 435 | /* Maximum prefix check */ |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 436 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 437 | { |
| 438 | if (peer->status != Established) |
| 439 | continue; |
| 440 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 441 | if (peer->afc[afi][SAFI_UNICAST]) |
| 442 | bgp_maximum_prefix_overflow (peer, afi, SAFI_UNICAST, 1); |
| 443 | if (peer->afc[afi][SAFI_MULTICAST]) |
| 444 | bgp_maximum_prefix_overflow (peer, afi, SAFI_MULTICAST, 1); |
| 445 | if (peer->afc[afi][SAFI_MPLS_VPN]) |
| 446 | bgp_maximum_prefix_overflow (peer, afi, SAFI_MPLS_VPN, 1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 447 | } |
| 448 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 449 | for (rn = bgp_table_top (bgp->rib[afi][SAFI_UNICAST]); rn; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 450 | rn = bgp_route_next (rn)) |
| 451 | { |
| 452 | for (bi = rn->info; bi; bi = next) |
| 453 | { |
| 454 | next = bi->next; |
| 455 | |
| 456 | if (bi->type == ZEBRA_ROUTE_BGP && bi->sub_type == BGP_ROUTE_NORMAL) |
| 457 | { |
| 458 | changed = 0; |
| 459 | metricchanged = 0; |
| 460 | |
Christian Franke | a0f6ce5 | 2013-04-11 08:24:30 +0000 | [diff] [blame] | 461 | if (bi->peer->sort == BGP_PEER_EBGP && bi->peer->ttl == 1 |
| 462 | && !CHECK_FLAG(bi->peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK)) |
Denis Ovsienko | 8e80bdf | 2011-08-05 18:52:52 +0400 | [diff] [blame] | 463 | valid = bgp_nexthop_onlink (afi, bi->attr); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 464 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 465 | valid = bgp_nexthop_lookup (afi, bi->peer, bi, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 466 | &changed, &metricchanged); |
| 467 | |
| 468 | current = CHECK_FLAG (bi->flags, BGP_INFO_VALID) ? 1 : 0; |
| 469 | |
| 470 | if (changed) |
| 471 | SET_FLAG (bi->flags, BGP_INFO_IGP_CHANGED); |
| 472 | else |
| 473 | UNSET_FLAG (bi->flags, BGP_INFO_IGP_CHANGED); |
| 474 | |
| 475 | if (valid != current) |
| 476 | { |
| 477 | if (CHECK_FLAG (bi->flags, BGP_INFO_VALID)) |
| 478 | { |
| 479 | bgp_aggregate_decrement (bgp, &rn->p, bi, |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 480 | afi, SAFI_UNICAST); |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 481 | bgp_info_unset_flag (rn, bi, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 482 | } |
| 483 | else |
| 484 | { |
Paul Jakma | 1a392d4 | 2006-09-07 00:24:49 +0000 | [diff] [blame] | 485 | bgp_info_set_flag (rn, bi, BGP_INFO_VALID); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 486 | bgp_aggregate_increment (bgp, &rn->p, bi, |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 487 | afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 488 | } |
| 489 | } |
| 490 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 491 | if (CHECK_FLAG (bgp->af_flags[afi][SAFI_UNICAST], |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 492 | BGP_CONFIG_DAMPENING) |
Paul Jakma | fb982c2 | 2007-05-04 20:15:47 +0000 | [diff] [blame] | 493 | && bi->extra && bi->extra->damp_info ) |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 494 | if (bgp_damp_scan (bi, afi, SAFI_UNICAST)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 495 | bgp_aggregate_increment (bgp, &rn->p, bi, |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 496 | afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | } |
| 498 | } |
Paul Jakma | 91b9e85 | 2015-12-01 14:32:11 +0000 | [diff] [blame^] | 499 | if (rn->info) |
| 500 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 501 | } |
| 502 | |
| 503 | /* Flash old cache. */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 504 | if (bgp_nexthop_cache_table[afi] == cache1_table[afi]) |
| 505 | bgp_nexthop_cache_reset (cache2_table[afi]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 506 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 507 | bgp_nexthop_cache_reset (cache1_table[afi]); |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 508 | |
| 509 | if (BGP_DEBUG (events, EVENTS)) |
| 510 | { |
| 511 | if (afi == AFI_IP) |
| 512 | zlog_debug ("scanning IPv4 Unicast routing tables"); |
| 513 | else if (afi == AFI_IP6) |
| 514 | zlog_debug ("scanning IPv6 Unicast routing tables"); |
| 515 | } |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 516 | |
| 517 | /* Reevaluate default-originate route-maps and announce/withdraw |
| 518 | * default route if neccesary. */ |
| 519 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
| 520 | { |
| 521 | if (peer->status == Established |
| 522 | && CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE) |
| 523 | && peer->default_rmap[afi][safi].name) |
| 524 | bgp_default_originate (peer, afi, safi, 0); |
| 525 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 526 | } |
| 527 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | /* BGP scan thread. This thread check nexthop reachability. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 529 | static int |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 530 | bgp_scan_timer (struct thread *t) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 531 | { |
| 532 | bgp_scan_thread = |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 533 | thread_add_timer (bm->master, bgp_scan_timer, NULL, bgp_scan_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 534 | |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 535 | if (BGP_DEBUG (events, EVENTS)) |
ajs | 478ba05 | 2004-12-08 20:41:23 +0000 | [diff] [blame] | 536 | zlog_debug ("Performing BGP general scanning"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 537 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 538 | bgp_scan (AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 539 | |
| 540 | #ifdef HAVE_IPV6 |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 541 | bgp_scan (AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 542 | #endif /* HAVE_IPV6 */ |
| 543 | |
| 544 | return 0; |
| 545 | } |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 546 | |
| 547 | /* BGP own address structure */ |
| 548 | struct bgp_addr |
| 549 | { |
| 550 | struct in_addr addr; |
| 551 | int refcnt; |
| 552 | }; |
| 553 | |
| 554 | static struct hash *bgp_address_hash; |
| 555 | |
| 556 | static void * |
| 557 | bgp_address_hash_alloc (void *p) |
| 558 | { |
| 559 | struct in_addr *val = p; |
| 560 | struct bgp_addr *addr; |
| 561 | |
| 562 | addr = XMALLOC (MTYPE_BGP_ADDR, sizeof (struct bgp_addr)); |
| 563 | addr->refcnt = 0; |
| 564 | addr->addr.s_addr = val->s_addr; |
| 565 | |
| 566 | return addr; |
| 567 | } |
| 568 | |
| 569 | static unsigned int |
| 570 | bgp_address_hash_key_make (void *p) |
| 571 | { |
| 572 | const struct bgp_addr *addr = p; |
| 573 | |
| 574 | return jhash_1word(addr->addr.s_addr, 0); |
| 575 | } |
| 576 | |
| 577 | static int |
| 578 | bgp_address_hash_cmp (const void *p1, const void *p2) |
| 579 | { |
| 580 | const struct bgp_addr *addr1 = p1; |
| 581 | const struct bgp_addr *addr2 = p2; |
| 582 | |
| 583 | return addr1->addr.s_addr == addr2->addr.s_addr; |
| 584 | } |
| 585 | |
| 586 | void |
| 587 | bgp_address_init (void) |
| 588 | { |
| 589 | bgp_address_hash = hash_create (bgp_address_hash_key_make, |
| 590 | bgp_address_hash_cmp); |
| 591 | } |
| 592 | |
| 593 | static void |
| 594 | bgp_address_add (struct prefix *p) |
| 595 | { |
| 596 | struct bgp_addr tmp; |
| 597 | struct bgp_addr *addr; |
| 598 | |
| 599 | tmp.addr = p->u.prefix4; |
| 600 | |
| 601 | addr = hash_get (bgp_address_hash, &tmp, bgp_address_hash_alloc); |
| 602 | addr->refcnt++; |
| 603 | } |
| 604 | |
| 605 | static void |
| 606 | bgp_address_del (struct prefix *p) |
| 607 | { |
| 608 | struct bgp_addr tmp; |
| 609 | struct bgp_addr *addr; |
| 610 | |
| 611 | tmp.addr = p->u.prefix4; |
| 612 | |
| 613 | addr = hash_lookup (bgp_address_hash, &tmp); |
Rakesh Garimella | 9e47abd | 2013-03-11 12:38:31 +0000 | [diff] [blame] | 614 | /* may have been deleted earlier by bgp_interface_down() */ |
| 615 | if (addr == NULL) |
| 616 | return; |
| 617 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 618 | addr->refcnt--; |
| 619 | |
| 620 | if (addr->refcnt == 0) |
| 621 | { |
| 622 | hash_release (bgp_address_hash, addr); |
| 623 | XFREE (MTYPE_BGP_ADDR, addr); |
| 624 | } |
| 625 | } |
| 626 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 627 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 628 | struct bgp_connected_ref |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 629 | { |
| 630 | unsigned int refcnt; |
| 631 | }; |
| 632 | |
| 633 | void |
| 634 | bgp_connected_add (struct connected *ifc) |
| 635 | { |
| 636 | struct prefix p; |
| 637 | struct prefix *addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 638 | struct interface *ifp; |
| 639 | struct bgp_node *rn; |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 640 | struct bgp_connected_ref *bc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 641 | |
| 642 | ifp = ifc->ifp; |
| 643 | |
| 644 | if (! ifp) |
| 645 | return; |
| 646 | |
| 647 | if (if_is_loopback (ifp)) |
| 648 | return; |
| 649 | |
| 650 | addr = ifc->address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 651 | |
Donald Sharp | 26a18eb | 2015-09-29 09:25:10 -0400 | [diff] [blame] | 652 | p = *(CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 653 | if (addr->family == AF_INET) |
| 654 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 655 | apply_mask_ipv4 ((struct prefix_ipv4 *) &p); |
| 656 | |
| 657 | if (prefix_ipv4_any ((struct prefix_ipv4 *) &p)) |
| 658 | return; |
| 659 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 660 | bgp_address_add (addr); |
| 661 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 662 | rn = bgp_node_get (bgp_connected_table[AFI_IP], (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 663 | if (rn->info) |
| 664 | { |
| 665 | bc = rn->info; |
| 666 | bc->refcnt++; |
| 667 | } |
| 668 | else |
| 669 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 670 | bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 671 | bc->refcnt = 1; |
| 672 | rn->info = bc; |
| 673 | } |
| 674 | } |
| 675 | #ifdef HAVE_IPV6 |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 676 | else if (addr->family == AF_INET6) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 677 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 678 | apply_mask_ipv6 ((struct prefix_ipv6 *) &p); |
| 679 | |
| 680 | if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) |
| 681 | return; |
| 682 | |
| 683 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 684 | return; |
| 685 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 686 | rn = bgp_node_get (bgp_connected_table[AFI_IP6], (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 687 | if (rn->info) |
| 688 | { |
| 689 | bc = rn->info; |
| 690 | bc->refcnt++; |
| 691 | } |
| 692 | else |
| 693 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 694 | bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 695 | bc->refcnt = 1; |
| 696 | rn->info = bc; |
| 697 | } |
| 698 | } |
| 699 | #endif /* HAVE_IPV6 */ |
| 700 | } |
| 701 | |
| 702 | void |
| 703 | bgp_connected_delete (struct connected *ifc) |
| 704 | { |
| 705 | struct prefix p; |
| 706 | struct prefix *addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 707 | struct interface *ifp; |
| 708 | struct bgp_node *rn; |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 709 | struct bgp_connected_ref *bc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 710 | |
| 711 | ifp = ifc->ifp; |
| 712 | |
| 713 | if (if_is_loopback (ifp)) |
| 714 | return; |
| 715 | |
| 716 | addr = ifc->address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 717 | |
Donald Sharp | 26a18eb | 2015-09-29 09:25:10 -0400 | [diff] [blame] | 718 | p = *(CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 719 | if (addr->family == AF_INET) |
| 720 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 721 | apply_mask_ipv4 ((struct prefix_ipv4 *) &p); |
| 722 | |
| 723 | if (prefix_ipv4_any ((struct prefix_ipv4 *) &p)) |
| 724 | return; |
| 725 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 726 | bgp_address_del (addr); |
| 727 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 728 | rn = bgp_node_lookup (bgp_connected_table[AFI_IP], &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 729 | if (! rn) |
| 730 | return; |
| 731 | |
| 732 | bc = rn->info; |
| 733 | bc->refcnt--; |
| 734 | if (bc->refcnt == 0) |
| 735 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 736 | XFREE (MTYPE_BGP_CONN, bc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 737 | rn->info = NULL; |
| 738 | } |
| 739 | bgp_unlock_node (rn); |
| 740 | bgp_unlock_node (rn); |
| 741 | } |
| 742 | #ifdef HAVE_IPV6 |
| 743 | else if (addr->family == AF_INET6) |
| 744 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 745 | apply_mask_ipv6 ((struct prefix_ipv6 *) &p); |
| 746 | |
| 747 | if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) |
| 748 | return; |
| 749 | |
| 750 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 751 | return; |
| 752 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 753 | rn = bgp_node_lookup (bgp_connected_table[AFI_IP6], (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 754 | if (! rn) |
| 755 | return; |
| 756 | |
| 757 | bc = rn->info; |
| 758 | bc->refcnt--; |
| 759 | if (bc->refcnt == 0) |
| 760 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 761 | XFREE (MTYPE_BGP_CONN, bc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 762 | rn->info = NULL; |
| 763 | } |
| 764 | bgp_unlock_node (rn); |
| 765 | bgp_unlock_node (rn); |
| 766 | } |
| 767 | #endif /* HAVE_IPV6 */ |
| 768 | } |
| 769 | |
| 770 | int |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 771 | bgp_nexthop_self (struct attr *attr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 772 | { |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 773 | struct bgp_addr tmp, *addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 774 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 775 | tmp.addr = attr->nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 776 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 777 | addr = hash_lookup (bgp_address_hash, &tmp); |
| 778 | if (addr) |
| 779 | return 1; |
| 780 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 781 | return 0; |
| 782 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 783 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 784 | static struct bgp_nexthop_cache * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 785 | zlookup_read (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 786 | { |
| 787 | struct stream *s; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 788 | uint16_t length; |
| 789 | u_char marker; |
| 790 | u_char version; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 791 | uint16_t vrf_id; |
| 792 | uint16_t command; |
| 793 | int err; |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 794 | struct in_addr raddr __attribute__((unused)); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 795 | uint32_t metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 796 | int i; |
| 797 | u_char nexthop_num; |
| 798 | struct nexthop *nexthop; |
| 799 | struct bgp_nexthop_cache *bnc; |
| 800 | |
| 801 | s = zlookup->ibuf; |
| 802 | stream_reset (s); |
| 803 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 804 | err = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 805 | &vrf_id, &command); |
| 806 | if (err < 0) |
| 807 | { |
| 808 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 809 | return NULL; |
| 810 | } |
Donald Sharp | a9d4cb3 | 2015-09-17 10:54:25 -0400 | [diff] [blame] | 811 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 812 | /* XXX: not doing anything with raddr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 813 | raddr.s_addr = stream_get_ipv4 (s); |
| 814 | metric = stream_getl (s); |
| 815 | nexthop_num = stream_getc (s); |
| 816 | |
| 817 | if (nexthop_num) |
| 818 | { |
| 819 | bnc = bnc_new (); |
| 820 | bnc->valid = 1; |
| 821 | bnc->metric = metric; |
| 822 | bnc->nexthop_num = nexthop_num; |
| 823 | |
| 824 | for (i = 0; i < nexthop_num; i++) |
| 825 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 826 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 827 | nexthop->type = stream_getc (s); |
| 828 | switch (nexthop->type) |
| 829 | { |
| 830 | case ZEBRA_NEXTHOP_IPV4: |
| 831 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); |
| 832 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 833 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 834 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); |
| 835 | nexthop->ifindex = stream_getl (s); |
| 836 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 837 | case ZEBRA_NEXTHOP_IFINDEX: |
| 838 | case ZEBRA_NEXTHOP_IFNAME: |
| 839 | nexthop->ifindex = stream_getl (s); |
| 840 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 841 | default: |
| 842 | /* do nothing */ |
| 843 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 844 | } |
| 845 | bnc_nexthop_add (bnc, nexthop); |
| 846 | } |
| 847 | } |
| 848 | else |
| 849 | return NULL; |
| 850 | |
| 851 | return bnc; |
| 852 | } |
| 853 | |
| 854 | struct bgp_nexthop_cache * |
| 855 | zlookup_query (struct in_addr addr) |
| 856 | { |
| 857 | int ret; |
| 858 | struct stream *s; |
| 859 | |
| 860 | /* Check socket. */ |
| 861 | if (zlookup->sock < 0) |
| 862 | return NULL; |
| 863 | |
| 864 | s = zlookup->obuf; |
| 865 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 866 | zclient_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | stream_put_in_addr (s, &addr); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 868 | |
| 869 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 870 | |
| 871 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 872 | if (ret < 0) |
| 873 | { |
| 874 | zlog_err ("can't write to zlookup->sock"); |
| 875 | close (zlookup->sock); |
| 876 | zlookup->sock = -1; |
| 877 | return NULL; |
| 878 | } |
| 879 | if (ret == 0) |
| 880 | { |
| 881 | zlog_err ("zlookup->sock connection closed"); |
| 882 | close (zlookup->sock); |
| 883 | zlookup->sock = -1; |
| 884 | return NULL; |
| 885 | } |
| 886 | |
| 887 | return zlookup_read (); |
| 888 | } |
| 889 | |
| 890 | #ifdef HAVE_IPV6 |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 891 | static struct bgp_nexthop_cache * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 892 | zlookup_read_ipv6 (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 893 | { |
| 894 | struct stream *s; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 895 | uint16_t length, vrf_id, cmd; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 896 | u_char version, marker; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 897 | struct in6_addr raddr; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 898 | uint32_t metric; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 899 | int i, err; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 900 | u_char nexthop_num; |
| 901 | struct nexthop *nexthop; |
| 902 | struct bgp_nexthop_cache *bnc; |
| 903 | |
| 904 | s = zlookup->ibuf; |
| 905 | stream_reset (s); |
| 906 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 907 | err = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 908 | &vrf_id, &cmd); |
| 909 | if (err < 0) |
| 910 | { |
| 911 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 912 | return NULL; |
| 913 | } |
Donald Sharp | a9d4cb3 | 2015-09-17 10:54:25 -0400 | [diff] [blame] | 914 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 915 | /* XXX: not actually doing anything with raddr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 916 | stream_get (&raddr, s, 16); |
| 917 | |
| 918 | metric = stream_getl (s); |
| 919 | nexthop_num = stream_getc (s); |
| 920 | |
| 921 | if (nexthop_num) |
| 922 | { |
| 923 | bnc = bnc_new (); |
| 924 | bnc->valid = 1; |
| 925 | bnc->metric = metric; |
| 926 | bnc->nexthop_num = nexthop_num; |
| 927 | |
| 928 | for (i = 0; i < nexthop_num; i++) |
| 929 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 930 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 931 | nexthop->type = stream_getc (s); |
| 932 | switch (nexthop->type) |
| 933 | { |
| 934 | case ZEBRA_NEXTHOP_IPV6: |
| 935 | stream_get (&nexthop->gate.ipv6, s, 16); |
| 936 | break; |
| 937 | case ZEBRA_NEXTHOP_IPV6_IFINDEX: |
| 938 | case ZEBRA_NEXTHOP_IPV6_IFNAME: |
| 939 | stream_get (&nexthop->gate.ipv6, s, 16); |
| 940 | nexthop->ifindex = stream_getl (s); |
| 941 | break; |
| 942 | case ZEBRA_NEXTHOP_IFINDEX: |
| 943 | case ZEBRA_NEXTHOP_IFNAME: |
| 944 | nexthop->ifindex = stream_getl (s); |
| 945 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 946 | default: |
| 947 | /* do nothing */ |
| 948 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 949 | } |
| 950 | bnc_nexthop_add (bnc, nexthop); |
| 951 | } |
| 952 | } |
| 953 | else |
| 954 | return NULL; |
| 955 | |
| 956 | return bnc; |
| 957 | } |
| 958 | |
| 959 | struct bgp_nexthop_cache * |
| 960 | zlookup_query_ipv6 (struct in6_addr *addr) |
| 961 | { |
| 962 | int ret; |
| 963 | struct stream *s; |
| 964 | |
| 965 | /* Check socket. */ |
| 966 | if (zlookup->sock < 0) |
| 967 | return NULL; |
| 968 | |
| 969 | s = zlookup->obuf; |
| 970 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 971 | zclient_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 972 | stream_put (s, addr, 16); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 973 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 974 | |
| 975 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 976 | if (ret < 0) |
| 977 | { |
| 978 | zlog_err ("can't write to zlookup->sock"); |
| 979 | close (zlookup->sock); |
| 980 | zlookup->sock = -1; |
| 981 | return NULL; |
| 982 | } |
| 983 | if (ret == 0) |
| 984 | { |
| 985 | zlog_err ("zlookup->sock connection closed"); |
| 986 | close (zlookup->sock); |
| 987 | zlookup->sock = -1; |
| 988 | return NULL; |
| 989 | } |
| 990 | |
| 991 | return zlookup_read_ipv6 (); |
| 992 | } |
| 993 | #endif /* HAVE_IPV6 */ |
| 994 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 995 | static int |
| 996 | bgp_import_check (struct prefix *p, u_int32_t *igpmetric, |
| 997 | struct in_addr *igpnexthop) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 998 | { |
| 999 | struct stream *s; |
| 1000 | int ret; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 1001 | u_int16_t length, vrf_id, command; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1002 | u_char version, marker; |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 1003 | struct in_addr addr __attribute__((unused)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1004 | struct in_addr nexthop; |
| 1005 | u_int32_t metric = 0; |
| 1006 | u_char nexthop_num; |
| 1007 | u_char nexthop_type; |
| 1008 | |
| 1009 | /* If lookup connection is not available return valid. */ |
| 1010 | if (zlookup->sock < 0) |
| 1011 | { |
| 1012 | if (igpmetric) |
| 1013 | *igpmetric = 0; |
| 1014 | return 1; |
| 1015 | } |
| 1016 | |
| 1017 | /* Send query to the lookup connection */ |
| 1018 | s = zlookup->obuf; |
| 1019 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1020 | zclient_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP, VRF_DEFAULT); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1021 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1022 | stream_putc (s, p->prefixlen); |
| 1023 | stream_put_in_addr (s, &p->u.prefix4); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1024 | |
| 1025 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 1026 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1027 | /* Write the packet. */ |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1028 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1029 | |
| 1030 | if (ret < 0) |
| 1031 | { |
| 1032 | zlog_err ("can't write to zlookup->sock"); |
| 1033 | close (zlookup->sock); |
| 1034 | zlookup->sock = -1; |
| 1035 | return 1; |
| 1036 | } |
| 1037 | if (ret == 0) |
| 1038 | { |
| 1039 | zlog_err ("zlookup->sock connection closed"); |
| 1040 | close (zlookup->sock); |
| 1041 | zlookup->sock = -1; |
| 1042 | return 1; |
| 1043 | } |
| 1044 | |
| 1045 | /* Get result. */ |
| 1046 | stream_reset (s); |
| 1047 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 1048 | ret = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 1049 | &vrf_id, &command); |
| 1050 | if (ret < 0) |
| 1051 | { |
| 1052 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 1053 | return 0; |
| 1054 | } |
Donald Sharp | a9d4cb3 | 2015-09-17 10:54:25 -0400 | [diff] [blame] | 1055 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 1056 | /* XXX: not using addr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1057 | addr.s_addr = stream_get_ipv4 (s); |
| 1058 | metric = stream_getl (s); |
| 1059 | nexthop_num = stream_getc (s); |
| 1060 | |
| 1061 | /* Set IGP metric value. */ |
| 1062 | if (igpmetric) |
| 1063 | *igpmetric = metric; |
| 1064 | |
| 1065 | /* If there is nexthop then this is active route. */ |
| 1066 | if (nexthop_num) |
| 1067 | { |
| 1068 | nexthop.s_addr = 0; |
| 1069 | nexthop_type = stream_getc (s); |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1070 | switch (nexthop_type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1071 | { |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1072 | case ZEBRA_NEXTHOP_IPV4: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1073 | nexthop.s_addr = stream_get_ipv4 (s); |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1074 | break; |
| 1075 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 1076 | nexthop.s_addr = stream_get_ipv4 (s); |
| 1077 | /* ifindex */ (void)stream_getl (s); |
| 1078 | break; |
| 1079 | default: |
| 1080 | /* do nothing */ |
| 1081 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1082 | } |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1083 | *igpnexthop = nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1084 | |
| 1085 | return 1; |
| 1086 | } |
| 1087 | else |
| 1088 | return 0; |
| 1089 | } |
| 1090 | |
| 1091 | /* Scan all configured BGP route then check the route exists in IGP or |
| 1092 | not. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1093 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1094 | bgp_import (struct thread *t) |
| 1095 | { |
| 1096 | struct bgp *bgp; |
| 1097 | struct bgp_node *rn; |
| 1098 | struct bgp_static *bgp_static; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1099 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1100 | int valid; |
| 1101 | u_int32_t metric; |
| 1102 | struct in_addr nexthop; |
| 1103 | afi_t afi; |
| 1104 | safi_t safi; |
| 1105 | |
| 1106 | bgp_import_thread = |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1107 | thread_add_timer (bm->master, bgp_import, NULL, bgp_import_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1108 | |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 1109 | if (BGP_DEBUG (events, EVENTS)) |
| 1110 | zlog_debug ("Import timer expired."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1111 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1112 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1113 | { |
| 1114 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 1115 | for (safi = SAFI_UNICAST; safi < SAFI_MPLS_VPN; safi++) |
| 1116 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; |
| 1117 | rn = bgp_route_next (rn)) |
| 1118 | if ((bgp_static = rn->info) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1119 | { |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1120 | if (bgp_static->backdoor) |
| 1121 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1122 | |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1123 | valid = bgp_static->valid; |
| 1124 | metric = bgp_static->igpmetric; |
| 1125 | nexthop = bgp_static->igpnexthop; |
| 1126 | |
| 1127 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) |
| 1128 | && afi == AFI_IP && safi == SAFI_UNICAST) |
| 1129 | bgp_static->valid = bgp_import_check (&rn->p, &bgp_static->igpmetric, |
| 1130 | &bgp_static->igpnexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1131 | else |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1132 | { |
| 1133 | bgp_static->valid = 1; |
| 1134 | bgp_static->igpmetric = 0; |
| 1135 | bgp_static->igpnexthop.s_addr = 0; |
| 1136 | } |
| 1137 | |
| 1138 | if (bgp_static->valid != valid) |
| 1139 | { |
| 1140 | if (bgp_static->valid) |
| 1141 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); |
| 1142 | else |
| 1143 | bgp_static_withdraw (bgp, &rn->p, afi, safi); |
| 1144 | } |
| 1145 | else if (bgp_static->valid) |
| 1146 | { |
| 1147 | if (bgp_static->igpmetric != metric |
| 1148 | || bgp_static->igpnexthop.s_addr != nexthop.s_addr |
| 1149 | || bgp_static->rmap.name) |
| 1150 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); |
| 1151 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1152 | } |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1153 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1154 | return 0; |
| 1155 | } |
| 1156 | |
| 1157 | /* Connect to zebra for nexthop lookup. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1158 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1159 | zlookup_connect (struct thread *t) |
| 1160 | { |
| 1161 | struct zclient *zlookup; |
| 1162 | |
| 1163 | zlookup = THREAD_ARG (t); |
| 1164 | zlookup->t_connect = NULL; |
| 1165 | |
| 1166 | if (zlookup->sock != -1) |
| 1167 | return 0; |
| 1168 | |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 1169 | if (zclient_socket_connect (zlookup) < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1170 | return -1; |
| 1171 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1172 | return 0; |
| 1173 | } |
| 1174 | |
| 1175 | /* Check specified multiaccess next-hop. */ |
| 1176 | int |
| 1177 | bgp_multiaccess_check_v4 (struct in_addr nexthop, char *peer) |
| 1178 | { |
| 1179 | struct bgp_node *rn1; |
| 1180 | struct bgp_node *rn2; |
| 1181 | struct prefix p1; |
| 1182 | struct prefix p2; |
| 1183 | struct in_addr addr; |
| 1184 | int ret; |
| 1185 | |
| 1186 | ret = inet_aton (peer, &addr); |
| 1187 | if (! ret) |
| 1188 | return 0; |
| 1189 | |
| 1190 | memset (&p1, 0, sizeof (struct prefix)); |
| 1191 | p1.family = AF_INET; |
| 1192 | p1.prefixlen = IPV4_MAX_BITLEN; |
| 1193 | p1.u.prefix4 = nexthop; |
| 1194 | memset (&p2, 0, sizeof (struct prefix)); |
| 1195 | p2.family = AF_INET; |
| 1196 | p2.prefixlen = IPV4_MAX_BITLEN; |
| 1197 | p2.u.prefix4 = addr; |
| 1198 | |
| 1199 | /* If bgp scan is not enabled, return invalid. */ |
| 1200 | if (zlookup->sock < 0) |
| 1201 | return 0; |
| 1202 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1203 | rn1 = bgp_node_match (bgp_connected_table[AFI_IP], &p1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1204 | if (! rn1) |
| 1205 | return 0; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1206 | bgp_unlock_node (rn1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1207 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1208 | rn2 = bgp_node_match (bgp_connected_table[AFI_IP], &p2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1209 | if (! rn2) |
| 1210 | return 0; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1211 | bgp_unlock_node (rn2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1212 | |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1213 | /* This is safe, even with above unlocks, since we are just |
| 1214 | comparing pointers to the objects, not the objects themselves. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1215 | if (rn1 == rn2) |
| 1216 | return 1; |
| 1217 | |
| 1218 | return 0; |
| 1219 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1220 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1221 | DEFUN (bgp_scan_time, |
| 1222 | bgp_scan_time_cmd, |
| 1223 | "bgp scan-time <5-60>", |
| 1224 | "BGP specific commands\n" |
| 1225 | "Configure background scanner interval\n" |
| 1226 | "Scanner interval (seconds)\n") |
| 1227 | { |
| 1228 | bgp_scan_interval = atoi (argv[0]); |
| 1229 | |
| 1230 | if (bgp_scan_thread) |
| 1231 | { |
| 1232 | thread_cancel (bgp_scan_thread); |
| 1233 | bgp_scan_thread = |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1234 | thread_add_timer (bm->master, bgp_scan_timer, NULL, bgp_scan_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1235 | } |
| 1236 | |
| 1237 | return CMD_SUCCESS; |
| 1238 | } |
| 1239 | |
| 1240 | DEFUN (no_bgp_scan_time, |
| 1241 | no_bgp_scan_time_cmd, |
| 1242 | "no bgp scan-time", |
| 1243 | NO_STR |
| 1244 | "BGP specific commands\n" |
| 1245 | "Configure background scanner interval\n") |
| 1246 | { |
| 1247 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; |
| 1248 | |
| 1249 | if (bgp_scan_thread) |
| 1250 | { |
| 1251 | thread_cancel (bgp_scan_thread); |
| 1252 | bgp_scan_thread = |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1253 | thread_add_timer (bm->master, bgp_scan_timer, NULL, bgp_scan_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1254 | } |
| 1255 | |
| 1256 | return CMD_SUCCESS; |
| 1257 | } |
| 1258 | |
| 1259 | ALIAS (no_bgp_scan_time, |
| 1260 | no_bgp_scan_time_val_cmd, |
| 1261 | "no bgp scan-time <5-60>", |
| 1262 | NO_STR |
| 1263 | "BGP specific commands\n" |
| 1264 | "Configure background scanner interval\n" |
| 1265 | "Scanner interval (seconds)\n") |
| 1266 | |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1267 | static int |
| 1268 | show_ip_bgp_scan_tables (struct vty *vty, const char detail) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1269 | { |
| 1270 | struct bgp_node *rn; |
| 1271 | struct bgp_nexthop_cache *bnc; |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1272 | char buf[INET6_ADDRSTRLEN]; |
| 1273 | u_char i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1274 | |
| 1275 | if (bgp_scan_thread) |
| 1276 | vty_out (vty, "BGP scan is running%s", VTY_NEWLINE); |
| 1277 | else |
| 1278 | vty_out (vty, "BGP scan is not running%s", VTY_NEWLINE); |
| 1279 | vty_out (vty, "BGP scan interval is %d%s", bgp_scan_interval, VTY_NEWLINE); |
| 1280 | |
| 1281 | vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1282 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP]); rn; rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1283 | if ((bnc = rn->info) != NULL) |
| 1284 | { |
| 1285 | if (bnc->valid) |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1286 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1287 | vty_out (vty, " %s valid [IGP metric %d]%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1288 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); |
| 1289 | if (detail) |
| 1290 | for (i = 0; i < bnc->nexthop_num; i++) |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1291 | switch (bnc->nexthop[i].type) |
| 1292 | { |
| 1293 | case NEXTHOP_TYPE_IPV4: |
| 1294 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
| 1295 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 1296 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 1297 | vty_out (vty, " gate %s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN)); |
| 1298 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1299 | break; |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1300 | case NEXTHOP_TYPE_IFINDEX: |
| 1301 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1302 | break; |
| 1303 | default: |
| 1304 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); |
| 1305 | } |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1306 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1307 | else |
| 1308 | vty_out (vty, " %s invalid%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1309 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1310 | } |
| 1311 | |
| 1312 | #ifdef HAVE_IPV6 |
| 1313 | { |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1314 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); |
| 1315 | rn; |
| 1316 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1317 | if ((bnc = rn->info) != NULL) |
| 1318 | { |
| 1319 | if (bnc->valid) |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1320 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1321 | vty_out (vty, " %s valid [IGP metric %d]%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1322 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1323 | bnc->metric, VTY_NEWLINE); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1324 | if (detail) |
| 1325 | for (i = 0; i < bnc->nexthop_num; i++) |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1326 | switch (bnc->nexthop[i].type) |
| 1327 | { |
| 1328 | case NEXTHOP_TYPE_IPV6: |
| 1329 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv6, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
| 1330 | break; |
| 1331 | case NEXTHOP_TYPE_IFINDEX: |
| 1332 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1333 | break; |
| 1334 | default: |
| 1335 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); |
| 1336 | } |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1337 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1338 | else |
| 1339 | vty_out (vty, " %s invalid%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1340 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1341 | VTY_NEWLINE); |
| 1342 | } |
| 1343 | } |
| 1344 | #endif /* HAVE_IPV6 */ |
| 1345 | |
| 1346 | vty_out (vty, "BGP connected route:%s", VTY_NEWLINE); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1347 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP]); |
| 1348 | rn; |
| 1349 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1350 | if (rn->info != NULL) |
| 1351 | vty_out (vty, " %s/%d%s", inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, |
| 1352 | VTY_NEWLINE); |
| 1353 | |
| 1354 | #ifdef HAVE_IPV6 |
| 1355 | { |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1356 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP6]); |
| 1357 | rn; |
| 1358 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1359 | if (rn->info != NULL) |
| 1360 | vty_out (vty, " %s/%d%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1361 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1362 | rn->p.prefixlen, |
| 1363 | VTY_NEWLINE); |
| 1364 | } |
| 1365 | #endif /* HAVE_IPV6 */ |
| 1366 | |
| 1367 | return CMD_SUCCESS; |
| 1368 | } |
| 1369 | |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1370 | DEFUN (show_ip_bgp_scan, |
| 1371 | show_ip_bgp_scan_cmd, |
| 1372 | "show ip bgp scan", |
| 1373 | SHOW_STR |
| 1374 | IP_STR |
| 1375 | BGP_STR |
| 1376 | "BGP scan status\n") |
| 1377 | { |
| 1378 | return show_ip_bgp_scan_tables (vty, 0); |
| 1379 | } |
| 1380 | |
| 1381 | DEFUN (show_ip_bgp_scan_detail, |
| 1382 | show_ip_bgp_scan_detail_cmd, |
| 1383 | "show ip bgp scan detail", |
| 1384 | SHOW_STR |
| 1385 | IP_STR |
| 1386 | BGP_STR |
| 1387 | "BGP scan status\n" |
| 1388 | "More detailed output\n") |
| 1389 | { |
| 1390 | return show_ip_bgp_scan_tables (vty, 1); |
| 1391 | } |
| 1392 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1393 | int |
| 1394 | bgp_config_write_scan_time (struct vty *vty) |
| 1395 | { |
| 1396 | if (bgp_scan_interval != BGP_SCAN_INTERVAL_DEFAULT) |
| 1397 | vty_out (vty, " bgp scan-time %d%s", bgp_scan_interval, VTY_NEWLINE); |
| 1398 | return CMD_SUCCESS; |
| 1399 | } |
| 1400 | |
| 1401 | void |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 1402 | bgp_scan_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1403 | { |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1404 | zlookup = zclient_new (bm->master); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1405 | zlookup->sock = -1; |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1406 | zlookup->t_connect = thread_add_event (bm->master, zlookup_connect, zlookup, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1407 | |
| 1408 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; |
| 1409 | bgp_import_interval = BGP_IMPORT_INTERVAL_DEFAULT; |
| 1410 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1411 | cache1_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
| 1412 | cache2_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1413 | bgp_nexthop_cache_table[AFI_IP] = cache1_table[AFI_IP]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1414 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1415 | bgp_connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1416 | |
| 1417 | #ifdef HAVE_IPV6 |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1418 | cache1_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
| 1419 | cache2_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1420 | bgp_nexthop_cache_table[AFI_IP6] = cache1_table[AFI_IP6]; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1421 | bgp_connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1422 | #endif /* HAVE_IPV6 */ |
| 1423 | |
| 1424 | /* Make BGP scan thread. */ |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1425 | bgp_scan_thread = thread_add_timer (bm->master, bgp_scan_timer, |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1426 | NULL, bgp_scan_interval); |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1427 | /* Make BGP import there. */ |
Donald Sharp | 774914f | 2015-10-14 08:50:39 -0400 | [diff] [blame] | 1428 | bgp_import_thread = thread_add_timer (bm->master, bgp_import, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1429 | |
| 1430 | install_element (BGP_NODE, &bgp_scan_time_cmd); |
| 1431 | install_element (BGP_NODE, &no_bgp_scan_time_cmd); |
| 1432 | install_element (BGP_NODE, &no_bgp_scan_time_val_cmd); |
| 1433 | install_element (VIEW_NODE, &show_ip_bgp_scan_cmd); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1434 | install_element (VIEW_NODE, &show_ip_bgp_scan_detail_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 1435 | install_element (RESTRICTED_NODE, &show_ip_bgp_scan_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1436 | install_element (ENABLE_NODE, &show_ip_bgp_scan_cmd); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1437 | install_element (ENABLE_NODE, &show_ip_bgp_scan_detail_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1438 | } |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1439 | |
| 1440 | void |
| 1441 | bgp_scan_finish (void) |
| 1442 | { |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1443 | if (cache1_table[AFI_IP]) |
| 1444 | bgp_table_unlock (cache1_table[AFI_IP]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1445 | cache1_table[AFI_IP] = NULL; |
| 1446 | |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1447 | if (cache2_table[AFI_IP]) |
| 1448 | bgp_table_unlock (cache2_table[AFI_IP]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1449 | cache2_table[AFI_IP] = NULL; |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1450 | |
| 1451 | if (bgp_connected_table[AFI_IP]) |
| 1452 | bgp_table_unlock (bgp_connected_table[AFI_IP]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1453 | bgp_connected_table[AFI_IP] = NULL; |
| 1454 | |
| 1455 | #ifdef HAVE_IPV6 |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1456 | if (cache1_table[AFI_IP6]) |
| 1457 | bgp_table_unlock (cache1_table[AFI_IP6]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1458 | cache1_table[AFI_IP6] = NULL; |
| 1459 | |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1460 | if (cache2_table[AFI_IP6]) |
| 1461 | bgp_table_unlock (cache2_table[AFI_IP6]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1462 | cache2_table[AFI_IP6] = NULL; |
| 1463 | |
Lou Berger | 056f376 | 2013-04-10 12:30:04 -0700 | [diff] [blame] | 1464 | if (bgp_connected_table[AFI_IP6]) |
| 1465 | bgp_table_unlock (bgp_connected_table[AFI_IP6]); |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1466 | bgp_connected_table[AFI_IP6] = NULL; |
| 1467 | #endif /* HAVE_IPV6 */ |
| 1468 | } |