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