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 | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 499 | bgp_process (bgp, rn, afi, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 500 | } |
| 501 | |
| 502 | /* Flash old cache. */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 503 | if (bgp_nexthop_cache_table[afi] == cache1_table[afi]) |
| 504 | bgp_nexthop_cache_reset (cache2_table[afi]); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 505 | else |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 506 | bgp_nexthop_cache_reset (cache1_table[afi]); |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 507 | |
| 508 | if (BGP_DEBUG (events, EVENTS)) |
| 509 | { |
| 510 | if (afi == AFI_IP) |
| 511 | zlog_debug ("scanning IPv4 Unicast routing tables"); |
| 512 | else if (afi == AFI_IP6) |
| 513 | zlog_debug ("scanning IPv6 Unicast routing tables"); |
| 514 | } |
Christian Franke | dcab1bb | 2012-12-07 16:45:52 +0000 | [diff] [blame] | 515 | |
| 516 | /* Reevaluate default-originate route-maps and announce/withdraw |
| 517 | * default route if neccesary. */ |
| 518 | for (ALL_LIST_ELEMENTS (bgp->peer, node, nnode, peer)) |
| 519 | { |
| 520 | if (peer->status == Established |
| 521 | && CHECK_FLAG(peer->af_flags[afi][safi], PEER_FLAG_DEFAULT_ORIGINATE) |
| 522 | && peer->default_rmap[afi][safi].name) |
| 523 | bgp_default_originate (peer, afi, safi, 0); |
| 524 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 525 | } |
| 526 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 527 | /* BGP scan thread. This thread check nexthop reachability. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 528 | static int |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 529 | bgp_scan_timer (struct thread *t) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 530 | { |
| 531 | bgp_scan_thread = |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 532 | thread_add_timer (master, bgp_scan_timer, NULL, bgp_scan_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 534 | if (BGP_DEBUG (events, EVENTS)) |
ajs | 478ba05 | 2004-12-08 20:41:23 +0000 | [diff] [blame] | 535 | zlog_debug ("Performing BGP general scanning"); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 536 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 537 | bgp_scan (AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 538 | |
| 539 | #ifdef HAVE_IPV6 |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 540 | bgp_scan (AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 541 | #endif /* HAVE_IPV6 */ |
| 542 | |
| 543 | return 0; |
| 544 | } |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 545 | |
| 546 | /* BGP own address structure */ |
| 547 | struct bgp_addr |
| 548 | { |
| 549 | struct in_addr addr; |
| 550 | int refcnt; |
| 551 | }; |
| 552 | |
| 553 | static struct hash *bgp_address_hash; |
| 554 | |
| 555 | static void * |
| 556 | bgp_address_hash_alloc (void *p) |
| 557 | { |
| 558 | struct in_addr *val = p; |
| 559 | struct bgp_addr *addr; |
| 560 | |
| 561 | addr = XMALLOC (MTYPE_BGP_ADDR, sizeof (struct bgp_addr)); |
| 562 | addr->refcnt = 0; |
| 563 | addr->addr.s_addr = val->s_addr; |
| 564 | |
| 565 | return addr; |
| 566 | } |
| 567 | |
| 568 | static unsigned int |
| 569 | bgp_address_hash_key_make (void *p) |
| 570 | { |
| 571 | const struct bgp_addr *addr = p; |
| 572 | |
| 573 | return jhash_1word(addr->addr.s_addr, 0); |
| 574 | } |
| 575 | |
| 576 | static int |
| 577 | bgp_address_hash_cmp (const void *p1, const void *p2) |
| 578 | { |
| 579 | const struct bgp_addr *addr1 = p1; |
| 580 | const struct bgp_addr *addr2 = p2; |
| 581 | |
| 582 | return addr1->addr.s_addr == addr2->addr.s_addr; |
| 583 | } |
| 584 | |
| 585 | void |
| 586 | bgp_address_init (void) |
| 587 | { |
| 588 | bgp_address_hash = hash_create (bgp_address_hash_key_make, |
| 589 | bgp_address_hash_cmp); |
| 590 | } |
| 591 | |
| 592 | static void |
| 593 | bgp_address_add (struct prefix *p) |
| 594 | { |
| 595 | struct bgp_addr tmp; |
| 596 | struct bgp_addr *addr; |
| 597 | |
| 598 | tmp.addr = p->u.prefix4; |
| 599 | |
| 600 | addr = hash_get (bgp_address_hash, &tmp, bgp_address_hash_alloc); |
| 601 | addr->refcnt++; |
| 602 | } |
| 603 | |
| 604 | static void |
| 605 | bgp_address_del (struct prefix *p) |
| 606 | { |
| 607 | struct bgp_addr tmp; |
| 608 | struct bgp_addr *addr; |
| 609 | |
| 610 | tmp.addr = p->u.prefix4; |
| 611 | |
| 612 | addr = hash_lookup (bgp_address_hash, &tmp); |
Rakesh Garimella | 9e47abd | 2013-03-11 12:38:31 +0000 | [diff] [blame] | 613 | /* may have been deleted earlier by bgp_interface_down() */ |
| 614 | if (addr == NULL) |
| 615 | return; |
| 616 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 617 | addr->refcnt--; |
| 618 | |
| 619 | if (addr->refcnt == 0) |
| 620 | { |
| 621 | hash_release (bgp_address_hash, addr); |
| 622 | XFREE (MTYPE_BGP_ADDR, addr); |
| 623 | } |
| 624 | } |
| 625 | |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 626 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 627 | struct bgp_connected_ref |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 628 | { |
| 629 | unsigned int refcnt; |
| 630 | }; |
| 631 | |
| 632 | void |
| 633 | bgp_connected_add (struct connected *ifc) |
| 634 | { |
| 635 | struct prefix p; |
| 636 | struct prefix *addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 637 | struct interface *ifp; |
| 638 | struct bgp_node *rn; |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 639 | struct bgp_connected_ref *bc; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 640 | |
| 641 | ifp = ifc->ifp; |
| 642 | |
| 643 | if (! ifp) |
| 644 | return; |
| 645 | |
| 646 | if (if_is_loopback (ifp)) |
| 647 | return; |
| 648 | |
| 649 | addr = ifc->address; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 650 | |
| 651 | if (addr->family == AF_INET) |
| 652 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 653 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 654 | apply_mask_ipv4 ((struct prefix_ipv4 *) &p); |
| 655 | |
| 656 | if (prefix_ipv4_any ((struct prefix_ipv4 *) &p)) |
| 657 | return; |
| 658 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 659 | bgp_address_add (addr); |
| 660 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 661 | rn = bgp_node_get (bgp_connected_table[AFI_IP], (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 662 | if (rn->info) |
| 663 | { |
| 664 | bc = rn->info; |
| 665 | bc->refcnt++; |
| 666 | } |
| 667 | else |
| 668 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 669 | bc = XCALLOC (MTYPE_BGP_CONN, sizeof (struct bgp_connected_ref)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 670 | bc->refcnt = 1; |
| 671 | rn->info = bc; |
| 672 | } |
| 673 | } |
| 674 | #ifdef HAVE_IPV6 |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 675 | else if (addr->family == AF_INET6) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 676 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 677 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
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 | |
| 718 | if (addr->family == AF_INET) |
| 719 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 720 | PREFIX_COPY_IPV4(&p, CONNECTED_PREFIX(ifc)); |
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 | { |
Andrew J. Schorr | e452963 | 2006-12-12 19:18:21 +0000 | [diff] [blame] | 745 | PREFIX_COPY_IPV6(&p, CONNECTED_PREFIX(ifc)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 746 | apply_mask_ipv6 ((struct prefix_ipv6 *) &p); |
| 747 | |
| 748 | if (IN6_IS_ADDR_UNSPECIFIED (&p.u.prefix6)) |
| 749 | return; |
| 750 | |
| 751 | if (IN6_IS_ADDR_LINKLOCAL (&p.u.prefix6)) |
| 752 | return; |
| 753 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 754 | rn = bgp_node_lookup (bgp_connected_table[AFI_IP6], (struct prefix *) &p); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 755 | if (! rn) |
| 756 | return; |
| 757 | |
| 758 | bc = rn->info; |
| 759 | bc->refcnt--; |
| 760 | if (bc->refcnt == 0) |
| 761 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 762 | XFREE (MTYPE_BGP_CONN, bc); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 763 | rn->info = NULL; |
| 764 | } |
| 765 | bgp_unlock_node (rn); |
| 766 | bgp_unlock_node (rn); |
| 767 | } |
| 768 | #endif /* HAVE_IPV6 */ |
| 769 | } |
| 770 | |
| 771 | int |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 772 | bgp_nexthop_self (struct attr *attr) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 773 | { |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 774 | struct bgp_addr tmp, *addr; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 775 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 776 | tmp.addr = attr->nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 777 | |
Jorge Boncompte [DTI2] | 10f9bf3 | 2012-05-07 16:52:52 +0000 | [diff] [blame] | 778 | addr = hash_lookup (bgp_address_hash, &tmp); |
| 779 | if (addr) |
| 780 | return 1; |
| 781 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 782 | return 0; |
| 783 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 784 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 785 | static struct bgp_nexthop_cache * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 786 | zlookup_read (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 787 | { |
| 788 | struct stream *s; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 789 | uint16_t length; |
| 790 | u_char marker; |
| 791 | u_char version; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 792 | uint16_t vrf_id; |
| 793 | uint16_t command; |
| 794 | int err; |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 795 | struct in_addr raddr __attribute__((unused)); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 796 | uint32_t metric; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 797 | int i; |
| 798 | u_char nexthop_num; |
| 799 | struct nexthop *nexthop; |
| 800 | struct bgp_nexthop_cache *bnc; |
| 801 | |
| 802 | s = zlookup->ibuf; |
| 803 | stream_reset (s); |
| 804 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 805 | err = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 806 | &vrf_id, &command); |
| 807 | if (err < 0) |
| 808 | { |
| 809 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 810 | return NULL; |
| 811 | } |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 812 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) |
| 813 | { |
| 814 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", |
| 815 | __func__, zlookup->sock, marker, version); |
| 816 | return NULL; |
| 817 | } |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 818 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 819 | /* XXX: not doing anything with raddr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 820 | raddr.s_addr = stream_get_ipv4 (s); |
| 821 | metric = stream_getl (s); |
| 822 | nexthop_num = stream_getc (s); |
| 823 | |
| 824 | if (nexthop_num) |
| 825 | { |
| 826 | bnc = bnc_new (); |
| 827 | bnc->valid = 1; |
| 828 | bnc->metric = metric; |
| 829 | bnc->nexthop_num = nexthop_num; |
| 830 | |
| 831 | for (i = 0; i < nexthop_num; i++) |
| 832 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 833 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 834 | nexthop->type = stream_getc (s); |
| 835 | switch (nexthop->type) |
| 836 | { |
| 837 | case ZEBRA_NEXTHOP_IPV4: |
| 838 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); |
| 839 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 840 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 841 | nexthop->gate.ipv4.s_addr = stream_get_ipv4 (s); |
| 842 | nexthop->ifindex = stream_getl (s); |
| 843 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 844 | case ZEBRA_NEXTHOP_IFINDEX: |
| 845 | case ZEBRA_NEXTHOP_IFNAME: |
| 846 | nexthop->ifindex = stream_getl (s); |
| 847 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 848 | default: |
| 849 | /* do nothing */ |
| 850 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 851 | } |
| 852 | bnc_nexthop_add (bnc, nexthop); |
| 853 | } |
| 854 | } |
| 855 | else |
| 856 | return NULL; |
| 857 | |
| 858 | return bnc; |
| 859 | } |
| 860 | |
| 861 | struct bgp_nexthop_cache * |
| 862 | zlookup_query (struct in_addr addr) |
| 863 | { |
| 864 | int ret; |
| 865 | struct stream *s; |
| 866 | |
| 867 | /* Check socket. */ |
| 868 | if (zlookup->sock < 0) |
| 869 | return NULL; |
| 870 | |
| 871 | s = zlookup->obuf; |
| 872 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 873 | zclient_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 874 | stream_put_in_addr (s, &addr); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 875 | |
| 876 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 877 | |
| 878 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 879 | if (ret < 0) |
| 880 | { |
| 881 | zlog_err ("can't write to zlookup->sock"); |
| 882 | close (zlookup->sock); |
| 883 | zlookup->sock = -1; |
| 884 | return NULL; |
| 885 | } |
| 886 | if (ret == 0) |
| 887 | { |
| 888 | zlog_err ("zlookup->sock connection closed"); |
| 889 | close (zlookup->sock); |
| 890 | zlookup->sock = -1; |
| 891 | return NULL; |
| 892 | } |
| 893 | |
| 894 | return zlookup_read (); |
| 895 | } |
| 896 | |
| 897 | #ifdef HAVE_IPV6 |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 898 | static struct bgp_nexthop_cache * |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 899 | zlookup_read_ipv6 (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 900 | { |
| 901 | struct stream *s; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 902 | uint16_t length, vrf_id, cmd; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 903 | u_char version, marker; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 904 | struct in6_addr raddr; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 905 | uint32_t metric; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 906 | int i, err; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 907 | u_char nexthop_num; |
| 908 | struct nexthop *nexthop; |
| 909 | struct bgp_nexthop_cache *bnc; |
| 910 | |
| 911 | s = zlookup->ibuf; |
| 912 | stream_reset (s); |
| 913 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 914 | err = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 915 | &vrf_id, &cmd); |
| 916 | if (err < 0) |
| 917 | { |
| 918 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 919 | return NULL; |
| 920 | } |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 921 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) |
| 922 | { |
| 923 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", |
| 924 | __func__, zlookup->sock, marker, version); |
| 925 | return NULL; |
| 926 | } |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 927 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 928 | /* XXX: not actually doing anything with raddr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 929 | stream_get (&raddr, s, 16); |
| 930 | |
| 931 | metric = stream_getl (s); |
| 932 | nexthop_num = stream_getc (s); |
| 933 | |
| 934 | if (nexthop_num) |
| 935 | { |
| 936 | bnc = bnc_new (); |
| 937 | bnc->valid = 1; |
| 938 | bnc->metric = metric; |
| 939 | bnc->nexthop_num = nexthop_num; |
| 940 | |
| 941 | for (i = 0; i < nexthop_num; i++) |
| 942 | { |
Stephen Hemminger | 393deb9 | 2008-08-18 14:13:29 -0700 | [diff] [blame] | 943 | nexthop = XCALLOC (MTYPE_NEXTHOP, sizeof (struct nexthop)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 944 | nexthop->type = stream_getc (s); |
| 945 | switch (nexthop->type) |
| 946 | { |
| 947 | case ZEBRA_NEXTHOP_IPV6: |
| 948 | stream_get (&nexthop->gate.ipv6, s, 16); |
| 949 | break; |
| 950 | case ZEBRA_NEXTHOP_IPV6_IFINDEX: |
| 951 | case ZEBRA_NEXTHOP_IPV6_IFNAME: |
| 952 | stream_get (&nexthop->gate.ipv6, s, 16); |
| 953 | nexthop->ifindex = stream_getl (s); |
| 954 | break; |
| 955 | case ZEBRA_NEXTHOP_IFINDEX: |
| 956 | case ZEBRA_NEXTHOP_IFNAME: |
| 957 | nexthop->ifindex = stream_getl (s); |
| 958 | break; |
hasso | fa2b17e | 2004-03-04 17:45:00 +0000 | [diff] [blame] | 959 | default: |
| 960 | /* do nothing */ |
| 961 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 962 | } |
| 963 | bnc_nexthop_add (bnc, nexthop); |
| 964 | } |
| 965 | } |
| 966 | else |
| 967 | return NULL; |
| 968 | |
| 969 | return bnc; |
| 970 | } |
| 971 | |
| 972 | struct bgp_nexthop_cache * |
| 973 | zlookup_query_ipv6 (struct in6_addr *addr) |
| 974 | { |
| 975 | int ret; |
| 976 | struct stream *s; |
| 977 | |
| 978 | /* Check socket. */ |
| 979 | if (zlookup->sock < 0) |
| 980 | return NULL; |
| 981 | |
| 982 | s = zlookup->obuf; |
| 983 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 984 | zclient_create_header (s, ZEBRA_IPV6_NEXTHOP_LOOKUP, VRF_DEFAULT); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 985 | stream_put (s, addr, 16); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 986 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 987 | |
| 988 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 989 | if (ret < 0) |
| 990 | { |
| 991 | zlog_err ("can't write to zlookup->sock"); |
| 992 | close (zlookup->sock); |
| 993 | zlookup->sock = -1; |
| 994 | return NULL; |
| 995 | } |
| 996 | if (ret == 0) |
| 997 | { |
| 998 | zlog_err ("zlookup->sock connection closed"); |
| 999 | close (zlookup->sock); |
| 1000 | zlookup->sock = -1; |
| 1001 | return NULL; |
| 1002 | } |
| 1003 | |
| 1004 | return zlookup_read_ipv6 (); |
| 1005 | } |
| 1006 | #endif /* HAVE_IPV6 */ |
| 1007 | |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1008 | static int |
| 1009 | bgp_import_check (struct prefix *p, u_int32_t *igpmetric, |
| 1010 | struct in_addr *igpnexthop) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1011 | { |
| 1012 | struct stream *s; |
| 1013 | int ret; |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 1014 | u_int16_t length, vrf_id, command; |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1015 | u_char version, marker; |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 1016 | struct in_addr addr __attribute__((unused)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1017 | struct in_addr nexthop; |
| 1018 | u_int32_t metric = 0; |
| 1019 | u_char nexthop_num; |
| 1020 | u_char nexthop_type; |
| 1021 | |
| 1022 | /* If lookup connection is not available return valid. */ |
| 1023 | if (zlookup->sock < 0) |
| 1024 | { |
| 1025 | if (igpmetric) |
| 1026 | *igpmetric = 0; |
| 1027 | return 1; |
| 1028 | } |
| 1029 | |
| 1030 | /* Send query to the lookup connection */ |
| 1031 | s = zlookup->obuf; |
| 1032 | stream_reset (s); |
Feng Lu | c99f348 | 2014-10-16 09:52:36 +0800 | [diff] [blame] | 1033 | zclient_create_header (s, ZEBRA_IPV4_IMPORT_LOOKUP, VRF_DEFAULT); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1034 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1035 | stream_putc (s, p->prefixlen); |
| 1036 | stream_put_in_addr (s, &p->u.prefix4); |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1037 | |
| 1038 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 1039 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1040 | /* Write the packet. */ |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1041 | ret = writen (zlookup->sock, s->data, stream_get_endp (s)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1042 | |
| 1043 | if (ret < 0) |
| 1044 | { |
| 1045 | zlog_err ("can't write to zlookup->sock"); |
| 1046 | close (zlookup->sock); |
| 1047 | zlookup->sock = -1; |
| 1048 | return 1; |
| 1049 | } |
| 1050 | if (ret == 0) |
| 1051 | { |
| 1052 | zlog_err ("zlookup->sock connection closed"); |
| 1053 | close (zlookup->sock); |
| 1054 | zlookup->sock = -1; |
| 1055 | return 1; |
| 1056 | } |
| 1057 | |
| 1058 | /* Get result. */ |
| 1059 | stream_reset (s); |
| 1060 | |
Nicolas Dichtel | 794c473 | 2015-09-16 09:42:36 +0200 | [diff] [blame] | 1061 | ret = zclient_read_header (s, zlookup->sock, &length, &marker, &version, |
| 1062 | &vrf_id, &command); |
| 1063 | if (ret < 0) |
| 1064 | { |
| 1065 | zlog_err("%s: zserv_read_header() failed", __func__); |
| 1066 | return 0; |
| 1067 | } |
paul | d3092e7 | 2006-01-17 17:33:46 +0000 | [diff] [blame] | 1068 | if (version != ZSERV_VERSION || marker != ZEBRA_HEADER_MARKER) |
| 1069 | { |
| 1070 | zlog_err("%s: socket %d version mismatch, marker %d, version %d", |
| 1071 | __func__, zlookup->sock, marker, version); |
| 1072 | return 0; |
| 1073 | } |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 1074 | |
Paul Jakma | 7aa9dce | 2014-09-19 14:42:23 +0100 | [diff] [blame] | 1075 | /* XXX: not using addr */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1076 | addr.s_addr = stream_get_ipv4 (s); |
| 1077 | metric = stream_getl (s); |
| 1078 | nexthop_num = stream_getc (s); |
| 1079 | |
| 1080 | /* Set IGP metric value. */ |
| 1081 | if (igpmetric) |
| 1082 | *igpmetric = metric; |
| 1083 | |
| 1084 | /* If there is nexthop then this is active route. */ |
| 1085 | if (nexthop_num) |
| 1086 | { |
| 1087 | nexthop.s_addr = 0; |
| 1088 | nexthop_type = stream_getc (s); |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1089 | switch (nexthop_type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1090 | { |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1091 | case ZEBRA_NEXTHOP_IPV4: |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1092 | nexthop.s_addr = stream_get_ipv4 (s); |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1093 | break; |
| 1094 | case ZEBRA_NEXTHOP_IPV4_IFINDEX: |
| 1095 | nexthop.s_addr = stream_get_ipv4 (s); |
| 1096 | /* ifindex */ (void)stream_getl (s); |
| 1097 | break; |
| 1098 | default: |
| 1099 | /* do nothing */ |
| 1100 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1101 | } |
Christian Franke | a12afd5 | 2013-05-25 14:01:36 +0000 | [diff] [blame] | 1102 | *igpnexthop = nexthop; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1103 | |
| 1104 | return 1; |
| 1105 | } |
| 1106 | else |
| 1107 | return 0; |
| 1108 | } |
| 1109 | |
| 1110 | /* Scan all configured BGP route then check the route exists in IGP or |
| 1111 | not. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1112 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1113 | bgp_import (struct thread *t) |
| 1114 | { |
| 1115 | struct bgp *bgp; |
| 1116 | struct bgp_node *rn; |
| 1117 | struct bgp_static *bgp_static; |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1118 | struct listnode *node, *nnode; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1119 | int valid; |
| 1120 | u_int32_t metric; |
| 1121 | struct in_addr nexthop; |
| 1122 | afi_t afi; |
| 1123 | safi_t safi; |
| 1124 | |
| 1125 | bgp_import_thread = |
| 1126 | thread_add_timer (master, bgp_import, NULL, bgp_import_interval); |
| 1127 | |
hasso | f418446 | 2005-02-01 20:13:16 +0000 | [diff] [blame] | 1128 | if (BGP_DEBUG (events, EVENTS)) |
| 1129 | zlog_debug ("Import timer expired."); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1130 | |
paul | 1eb8ef2 | 2005-04-07 07:30:20 +0000 | [diff] [blame] | 1131 | for (ALL_LIST_ELEMENTS (bm->bgp, node, nnode, bgp)) |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1132 | { |
| 1133 | for (afi = AFI_IP; afi < AFI_MAX; afi++) |
| 1134 | for (safi = SAFI_UNICAST; safi < SAFI_MPLS_VPN; safi++) |
| 1135 | for (rn = bgp_table_top (bgp->route[afi][safi]); rn; |
| 1136 | rn = bgp_route_next (rn)) |
| 1137 | if ((bgp_static = rn->info) != NULL) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1138 | { |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1139 | if (bgp_static->backdoor) |
| 1140 | continue; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1141 | |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1142 | valid = bgp_static->valid; |
| 1143 | metric = bgp_static->igpmetric; |
| 1144 | nexthop = bgp_static->igpnexthop; |
| 1145 | |
| 1146 | if (bgp_flag_check (bgp, BGP_FLAG_IMPORT_CHECK) |
| 1147 | && afi == AFI_IP && safi == SAFI_UNICAST) |
| 1148 | bgp_static->valid = bgp_import_check (&rn->p, &bgp_static->igpmetric, |
| 1149 | &bgp_static->igpnexthop); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1150 | else |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1151 | { |
| 1152 | bgp_static->valid = 1; |
| 1153 | bgp_static->igpmetric = 0; |
| 1154 | bgp_static->igpnexthop.s_addr = 0; |
| 1155 | } |
| 1156 | |
| 1157 | if (bgp_static->valid != valid) |
| 1158 | { |
| 1159 | if (bgp_static->valid) |
| 1160 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); |
| 1161 | else |
| 1162 | bgp_static_withdraw (bgp, &rn->p, afi, safi); |
| 1163 | } |
| 1164 | else if (bgp_static->valid) |
| 1165 | { |
| 1166 | if (bgp_static->igpmetric != metric |
| 1167 | || bgp_static->igpnexthop.s_addr != nexthop.s_addr |
| 1168 | || bgp_static->rmap.name) |
| 1169 | bgp_static_update (bgp, &rn->p, bgp_static, afi, safi); |
| 1170 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1171 | } |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1172 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1173 | return 0; |
| 1174 | } |
| 1175 | |
| 1176 | /* Connect to zebra for nexthop lookup. */ |
paul | 94f2b39 | 2005-06-28 12:44:16 +0000 | [diff] [blame] | 1177 | static int |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1178 | zlookup_connect (struct thread *t) |
| 1179 | { |
| 1180 | struct zclient *zlookup; |
| 1181 | |
| 1182 | zlookup = THREAD_ARG (t); |
| 1183 | zlookup->t_connect = NULL; |
| 1184 | |
| 1185 | if (zlookup->sock != -1) |
| 1186 | return 0; |
| 1187 | |
Vyacheslav Trushkin | b511468 | 2011-11-25 18:51:48 +0400 | [diff] [blame] | 1188 | if (zclient_socket_connect (zlookup) < 0) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1189 | return -1; |
| 1190 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1191 | return 0; |
| 1192 | } |
| 1193 | |
| 1194 | /* Check specified multiaccess next-hop. */ |
| 1195 | int |
| 1196 | bgp_multiaccess_check_v4 (struct in_addr nexthop, char *peer) |
| 1197 | { |
| 1198 | struct bgp_node *rn1; |
| 1199 | struct bgp_node *rn2; |
| 1200 | struct prefix p1; |
| 1201 | struct prefix p2; |
| 1202 | struct in_addr addr; |
| 1203 | int ret; |
| 1204 | |
| 1205 | ret = inet_aton (peer, &addr); |
| 1206 | if (! ret) |
| 1207 | return 0; |
| 1208 | |
| 1209 | memset (&p1, 0, sizeof (struct prefix)); |
| 1210 | p1.family = AF_INET; |
| 1211 | p1.prefixlen = IPV4_MAX_BITLEN; |
| 1212 | p1.u.prefix4 = nexthop; |
| 1213 | memset (&p2, 0, sizeof (struct prefix)); |
| 1214 | p2.family = AF_INET; |
| 1215 | p2.prefixlen = IPV4_MAX_BITLEN; |
| 1216 | p2.u.prefix4 = addr; |
| 1217 | |
| 1218 | /* If bgp scan is not enabled, return invalid. */ |
| 1219 | if (zlookup->sock < 0) |
| 1220 | return 0; |
| 1221 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1222 | rn1 = bgp_node_match (bgp_connected_table[AFI_IP], &p1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1223 | if (! rn1) |
| 1224 | return 0; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1225 | bgp_unlock_node (rn1); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1226 | |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1227 | rn2 = bgp_node_match (bgp_connected_table[AFI_IP], &p2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1228 | if (! rn2) |
| 1229 | return 0; |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1230 | bgp_unlock_node (rn2); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1231 | |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1232 | /* This is safe, even with above unlocks, since we are just |
| 1233 | comparing pointers to the objects, not the objects themselves. */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1234 | if (rn1 == rn2) |
| 1235 | return 1; |
| 1236 | |
| 1237 | return 0; |
| 1238 | } |
David Lamparter | 6b0655a | 2014-06-04 06:53:35 +0200 | [diff] [blame] | 1239 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1240 | DEFUN (bgp_scan_time, |
| 1241 | bgp_scan_time_cmd, |
| 1242 | "bgp scan-time <5-60>", |
| 1243 | "BGP specific commands\n" |
| 1244 | "Configure background scanner interval\n" |
| 1245 | "Scanner interval (seconds)\n") |
| 1246 | { |
| 1247 | bgp_scan_interval = atoi (argv[0]); |
| 1248 | |
| 1249 | if (bgp_scan_thread) |
| 1250 | { |
| 1251 | thread_cancel (bgp_scan_thread); |
| 1252 | bgp_scan_thread = |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1253 | thread_add_timer (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 | DEFUN (no_bgp_scan_time, |
| 1260 | no_bgp_scan_time_cmd, |
| 1261 | "no bgp scan-time", |
| 1262 | NO_STR |
| 1263 | "BGP specific commands\n" |
| 1264 | "Configure background scanner interval\n") |
| 1265 | { |
| 1266 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; |
| 1267 | |
| 1268 | if (bgp_scan_thread) |
| 1269 | { |
| 1270 | thread_cancel (bgp_scan_thread); |
| 1271 | bgp_scan_thread = |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1272 | thread_add_timer (master, bgp_scan_timer, NULL, bgp_scan_interval); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1273 | } |
| 1274 | |
| 1275 | return CMD_SUCCESS; |
| 1276 | } |
| 1277 | |
| 1278 | ALIAS (no_bgp_scan_time, |
| 1279 | no_bgp_scan_time_val_cmd, |
| 1280 | "no bgp scan-time <5-60>", |
| 1281 | NO_STR |
| 1282 | "BGP specific commands\n" |
| 1283 | "Configure background scanner interval\n" |
| 1284 | "Scanner interval (seconds)\n") |
| 1285 | |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1286 | static int |
| 1287 | show_ip_bgp_scan_tables (struct vty *vty, const char detail) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1288 | { |
| 1289 | struct bgp_node *rn; |
| 1290 | struct bgp_nexthop_cache *bnc; |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1291 | char buf[INET6_ADDRSTRLEN]; |
| 1292 | u_char i; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1293 | |
| 1294 | if (bgp_scan_thread) |
| 1295 | vty_out (vty, "BGP scan is running%s", VTY_NEWLINE); |
| 1296 | else |
| 1297 | vty_out (vty, "BGP scan is not running%s", VTY_NEWLINE); |
| 1298 | vty_out (vty, "BGP scan interval is %d%s", bgp_scan_interval, VTY_NEWLINE); |
| 1299 | |
| 1300 | vty_out (vty, "Current BGP nexthop cache:%s", VTY_NEWLINE); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1301 | 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] | 1302 | if ((bnc = rn->info) != NULL) |
| 1303 | { |
| 1304 | if (bnc->valid) |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1305 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1306 | vty_out (vty, " %s valid [IGP metric %d]%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1307 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), bnc->metric, VTY_NEWLINE); |
| 1308 | if (detail) |
| 1309 | for (i = 0; i < bnc->nexthop_num; i++) |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1310 | switch (bnc->nexthop[i].type) |
| 1311 | { |
| 1312 | case NEXTHOP_TYPE_IPV4: |
| 1313 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
| 1314 | break; |
Christian Franke | bb97e46 | 2013-05-25 14:01:35 +0000 | [diff] [blame] | 1315 | case NEXTHOP_TYPE_IPV4_IFINDEX: |
| 1316 | vty_out (vty, " gate %s", inet_ntop (AF_INET, &bnc->nexthop[i].gate.ipv4, buf, INET6_ADDRSTRLEN)); |
| 1317 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1318 | break; |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1319 | case NEXTHOP_TYPE_IFINDEX: |
| 1320 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1321 | break; |
| 1322 | default: |
| 1323 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); |
| 1324 | } |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1325 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1326 | else |
| 1327 | vty_out (vty, " %s invalid%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1328 | inet_ntop (AF_INET, &rn->p.u.prefix4, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1329 | } |
| 1330 | |
| 1331 | #ifdef HAVE_IPV6 |
| 1332 | { |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1333 | for (rn = bgp_table_top (bgp_nexthop_cache_table[AFI_IP6]); |
| 1334 | rn; |
| 1335 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1336 | if ((bnc = rn->info) != NULL) |
| 1337 | { |
| 1338 | if (bnc->valid) |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1339 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1340 | vty_out (vty, " %s valid [IGP metric %d]%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1341 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1342 | bnc->metric, VTY_NEWLINE); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1343 | if (detail) |
| 1344 | for (i = 0; i < bnc->nexthop_num; i++) |
Denis Ovsienko | 0e8032d | 2011-08-09 14:42:58 +0400 | [diff] [blame] | 1345 | switch (bnc->nexthop[i].type) |
| 1346 | { |
| 1347 | case NEXTHOP_TYPE_IPV6: |
| 1348 | vty_out (vty, " gate %s%s", inet_ntop (AF_INET6, &bnc->nexthop[i].gate.ipv6, buf, INET6_ADDRSTRLEN), VTY_NEWLINE); |
| 1349 | break; |
| 1350 | case NEXTHOP_TYPE_IFINDEX: |
| 1351 | vty_out (vty, " ifidx %u%s", bnc->nexthop[i].ifindex, VTY_NEWLINE); |
| 1352 | break; |
| 1353 | default: |
| 1354 | vty_out (vty, " invalid nexthop type %u%s", bnc->nexthop[i].type, VTY_NEWLINE); |
| 1355 | } |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1356 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1357 | else |
| 1358 | vty_out (vty, " %s invalid%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1359 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1360 | VTY_NEWLINE); |
| 1361 | } |
| 1362 | } |
| 1363 | #endif /* HAVE_IPV6 */ |
| 1364 | |
| 1365 | vty_out (vty, "BGP connected route:%s", VTY_NEWLINE); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1366 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP]); |
| 1367 | rn; |
| 1368 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1369 | if (rn->info != NULL) |
| 1370 | vty_out (vty, " %s/%d%s", inet_ntoa (rn->p.u.prefix4), rn->p.prefixlen, |
| 1371 | VTY_NEWLINE); |
| 1372 | |
| 1373 | #ifdef HAVE_IPV6 |
| 1374 | { |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1375 | for (rn = bgp_table_top (bgp_connected_table[AFI_IP6]); |
| 1376 | rn; |
| 1377 | rn = bgp_route_next (rn)) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1378 | if (rn->info != NULL) |
| 1379 | vty_out (vty, " %s/%d%s", |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1380 | inet_ntop (AF_INET6, &rn->p.u.prefix6, buf, INET6_ADDRSTRLEN), |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1381 | rn->p.prefixlen, |
| 1382 | VTY_NEWLINE); |
| 1383 | } |
| 1384 | #endif /* HAVE_IPV6 */ |
| 1385 | |
| 1386 | return CMD_SUCCESS; |
| 1387 | } |
| 1388 | |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1389 | DEFUN (show_ip_bgp_scan, |
| 1390 | show_ip_bgp_scan_cmd, |
| 1391 | "show ip bgp scan", |
| 1392 | SHOW_STR |
| 1393 | IP_STR |
| 1394 | BGP_STR |
| 1395 | "BGP scan status\n") |
| 1396 | { |
| 1397 | return show_ip_bgp_scan_tables (vty, 0); |
| 1398 | } |
| 1399 | |
| 1400 | DEFUN (show_ip_bgp_scan_detail, |
| 1401 | show_ip_bgp_scan_detail_cmd, |
| 1402 | "show ip bgp scan detail", |
| 1403 | SHOW_STR |
| 1404 | IP_STR |
| 1405 | BGP_STR |
| 1406 | "BGP scan status\n" |
| 1407 | "More detailed output\n") |
| 1408 | { |
| 1409 | return show_ip_bgp_scan_tables (vty, 1); |
| 1410 | } |
| 1411 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1412 | int |
| 1413 | bgp_config_write_scan_time (struct vty *vty) |
| 1414 | { |
| 1415 | if (bgp_scan_interval != BGP_SCAN_INTERVAL_DEFAULT) |
| 1416 | vty_out (vty, " bgp scan-time %d%s", bgp_scan_interval, VTY_NEWLINE); |
| 1417 | return CMD_SUCCESS; |
| 1418 | } |
| 1419 | |
| 1420 | void |
Stephen Hemminger | 66e5cd8 | 2009-02-09 10:14:16 -0800 | [diff] [blame] | 1421 | bgp_scan_init (void) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1422 | { |
| 1423 | zlookup = zclient_new (); |
| 1424 | zlookup->sock = -1; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1425 | zlookup->t_connect = thread_add_event (master, zlookup_connect, zlookup, 0); |
| 1426 | |
| 1427 | bgp_scan_interval = BGP_SCAN_INTERVAL_DEFAULT; |
| 1428 | bgp_import_interval = BGP_IMPORT_INTERVAL_DEFAULT; |
| 1429 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1430 | cache1_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
| 1431 | cache2_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1432 | bgp_nexthop_cache_table[AFI_IP] = cache1_table[AFI_IP]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1433 | |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1434 | bgp_connected_table[AFI_IP] = bgp_table_init (AFI_IP, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1435 | |
| 1436 | #ifdef HAVE_IPV6 |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1437 | cache1_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
| 1438 | cache2_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1439 | bgp_nexthop_cache_table[AFI_IP6] = cache1_table[AFI_IP6]; |
Paul Jakma | 64e580a | 2006-02-21 01:09:01 +0000 | [diff] [blame] | 1440 | bgp_connected_table[AFI_IP6] = bgp_table_init (AFI_IP6, SAFI_UNICAST); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1441 | #endif /* HAVE_IPV6 */ |
| 1442 | |
| 1443 | /* Make BGP scan thread. */ |
paul | 5932020 | 2004-11-09 01:54:03 +0000 | [diff] [blame] | 1444 | bgp_scan_thread = thread_add_timer (master, bgp_scan_timer, |
| 1445 | NULL, bgp_scan_interval); |
paul | 6cbbc3c | 2003-04-28 17:11:02 +0000 | [diff] [blame] | 1446 | /* Make BGP import there. */ |
| 1447 | bgp_import_thread = thread_add_timer (master, bgp_import, NULL, 0); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1448 | |
| 1449 | install_element (BGP_NODE, &bgp_scan_time_cmd); |
| 1450 | install_element (BGP_NODE, &no_bgp_scan_time_cmd); |
| 1451 | install_element (BGP_NODE, &no_bgp_scan_time_val_cmd); |
| 1452 | install_element (VIEW_NODE, &show_ip_bgp_scan_cmd); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1453 | install_element (VIEW_NODE, &show_ip_bgp_scan_detail_cmd); |
Paul Jakma | 62687ff | 2008-08-23 14:27:06 +0100 | [diff] [blame] | 1454 | install_element (RESTRICTED_NODE, &show_ip_bgp_scan_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1455 | install_element (ENABLE_NODE, &show_ip_bgp_scan_cmd); |
Denis Ovsienko | 318f0d8 | 2011-08-05 21:47:08 +0400 | [diff] [blame] | 1456 | install_element (ENABLE_NODE, &show_ip_bgp_scan_detail_cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1457 | } |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1458 | |
| 1459 | void |
| 1460 | bgp_scan_finish (void) |
| 1461 | { |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1462 | /* Only the current one needs to be reset. */ |
| 1463 | bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP]); |
| 1464 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1465 | bgp_table_unlock (cache1_table[AFI_IP]); |
| 1466 | cache1_table[AFI_IP] = NULL; |
| 1467 | |
| 1468 | bgp_table_unlock (cache2_table[AFI_IP]); |
| 1469 | cache2_table[AFI_IP] = NULL; |
| 1470 | |
| 1471 | bgp_table_unlock (bgp_connected_table[AFI_IP]); |
| 1472 | bgp_connected_table[AFI_IP] = NULL; |
| 1473 | |
| 1474 | #ifdef HAVE_IPV6 |
Chris Caputo | 6c88b44 | 2010-07-27 16:28:55 +0000 | [diff] [blame] | 1475 | /* Only the current one needs to be reset. */ |
| 1476 | bgp_nexthop_cache_reset (bgp_nexthop_cache_table[AFI_IP6]); |
| 1477 | |
Chris Caputo | 228da42 | 2009-07-18 05:44:03 +0000 | [diff] [blame] | 1478 | bgp_table_unlock (cache1_table[AFI_IP6]); |
| 1479 | cache1_table[AFI_IP6] = NULL; |
| 1480 | |
| 1481 | bgp_table_unlock (cache2_table[AFI_IP6]); |
| 1482 | cache2_table[AFI_IP6] = NULL; |
| 1483 | |
| 1484 | bgp_table_unlock (bgp_connected_table[AFI_IP6]); |
| 1485 | bgp_connected_table[AFI_IP6] = NULL; |
| 1486 | #endif /* HAVE_IPV6 */ |
| 1487 | } |