]>
Commit | Line | Data |
---|---|---|
718e3744 | 1 | /* zebra client |
896014f4 DL |
2 | * Copyright (C) 1997, 98, 99 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 along | |
17 | * with this program; see the file COPYING; if not, write to the Free Software | |
18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA | |
19 | */ | |
718e3744 | 20 | |
21 | #include <zebra.h> | |
22 | ||
23 | #include "command.h" | |
24 | #include "stream.h" | |
25 | #include "network.h" | |
26 | #include "prefix.h" | |
27 | #include "log.h" | |
28 | #include "sockunion.h" | |
29 | #include "zclient.h" | |
30 | #include "routemap.h" | |
31 | #include "thread.h" | |
3f9c7369 | 32 | #include "queue.h" |
6e919709 | 33 | #include "memory.h" |
856ca177 | 34 | #include "lib/json.h" |
2376c3f2 | 35 | #include "lib/bfd.h" |
039f3a34 | 36 | #include "filter.h" |
cd1964ff | 37 | #include "mpls.h" |
128ea8ab | 38 | #include "vxlan.h" |
718e3744 | 39 | |
40 | #include "bgpd/bgpd.h" | |
41 | #include "bgpd/bgp_route.h" | |
42 | #include "bgpd/bgp_attr.h" | |
43 | #include "bgpd/bgp_nexthop.h" | |
44 | #include "bgpd/bgp_zebra.h" | |
45 | #include "bgpd/bgp_fsm.h" | |
a39275d7 | 46 | #include "bgpd/bgp_debug.h" |
14454c9f | 47 | #include "bgpd/bgp_errors.h" |
8196f13d | 48 | #include "bgpd/bgp_mpath.h" |
fb018d25 | 49 | #include "bgpd/bgp_nexthop.h" |
ffd0c037 | 50 | #include "bgpd/bgp_nht.h" |
8c4f6381 | 51 | #include "bgpd/bgp_bfd.h" |
cd1964ff | 52 | #include "bgpd/bgp_label.h" |
65efcfce | 53 | #if ENABLE_BGP_VNC |
d62a17ae | 54 | #include "bgpd/rfapi/rfapi_backend.h" |
55 | #include "bgpd/rfapi/vnc_export_bgp.h" | |
65efcfce | 56 | #endif |
128ea8ab | 57 | #include "bgpd/bgp_evpn.h" |
ddb5b488 | 58 | #include "bgpd/bgp_mplsvpn.h" |
955bfd98 | 59 | #include "bgpd/bgp_labelpool.h" |
30d50e6d | 60 | #include "bgpd/bgp_pbr.h" |
6b0655a2 | 61 | |
718e3744 | 62 | /* All information about zebra. */ |
228da428 | 63 | struct zclient *zclient = NULL; |
718e3744 | 64 | |
ad4cbda1 | 65 | /* Can we install into zebra? */ |
d62a17ae | 66 | static inline int bgp_install_info_to_zebra(struct bgp *bgp) |
ad4cbda1 | 67 | { |
d62a17ae | 68 | if (zclient->sock <= 0) |
69 | return 0; | |
ad4cbda1 | 70 | |
d62a17ae | 71 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) |
72 | return 0; | |
ad4cbda1 | 73 | |
d62a17ae | 74 | return 1; |
ad4cbda1 | 75 | } |
76 | ||
afbb1c59 LB |
77 | int zclient_num_connects; |
78 | ||
18a6dce6 | 79 | /* Router-id update message from zebra. */ |
d62a17ae | 80 | static int bgp_router_id_update(int command, struct zclient *zclient, |
81 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 82 | { |
d62a17ae | 83 | struct prefix router_id; |
718e3744 | 84 | |
d62a17ae | 85 | zebra_router_id_update_read(zclient->ibuf, &router_id); |
a39275d7 | 86 | |
d62a17ae | 87 | if (BGP_DEBUG(zebra, ZEBRA)) { |
88 | char buf[PREFIX2STR_BUFFER]; | |
89 | prefix2str(&router_id, buf, sizeof(buf)); | |
90 | zlog_debug("Rx Router Id update VRF %u Id %s", vrf_id, buf); | |
91 | } | |
a39275d7 | 92 | |
d62a17ae | 93 | bgp_router_id_zebra_bump(vrf_id, &router_id); |
94 | return 0; | |
718e3744 | 95 | } |
96 | ||
fb018d25 | 97 | /* Nexthop update message from zebra. */ |
d62a17ae | 98 | static int bgp_read_nexthop_update(int command, struct zclient *zclient, |
99 | zebra_size_t length, vrf_id_t vrf_id) | |
fb018d25 | 100 | { |
d62a17ae | 101 | bgp_parse_nexthop_update(command, vrf_id); |
102 | return 0; | |
078430f6 DS |
103 | } |
104 | ||
d62a17ae | 105 | static int bgp_read_import_check_update(int command, struct zclient *zclient, |
106 | zebra_size_t length, vrf_id_t vrf_id) | |
078430f6 | 107 | { |
d62a17ae | 108 | bgp_parse_nexthop_update(command, vrf_id); |
109 | return 0; | |
fb018d25 DS |
110 | } |
111 | ||
4a04e5f7 | 112 | /* Set or clear interface on which unnumbered neighbor is configured. This |
113 | * would in turn cause BGP to initiate or turn off IPv6 RAs on this | |
114 | * interface. | |
115 | */ | |
d62a17ae | 116 | static void bgp_update_interface_nbrs(struct bgp *bgp, struct interface *ifp, |
117 | struct interface *upd_ifp) | |
4a04e5f7 | 118 | { |
d62a17ae | 119 | struct listnode *node, *nnode; |
120 | struct peer *peer; | |
121 | ||
122 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
123 | if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0)) { | |
124 | if (upd_ifp) { | |
125 | peer->ifp = upd_ifp; | |
126 | bgp_zebra_initiate_radv(bgp, peer); | |
127 | } else { | |
128 | bgp_zebra_terminate_radv(bgp, peer); | |
129 | peer->ifp = upd_ifp; | |
130 | } | |
131 | } | |
132 | } | |
4a04e5f7 | 133 | } |
134 | ||
d62a17ae | 135 | static int bgp_read_fec_update(int command, struct zclient *zclient, |
136 | zebra_size_t length) | |
cd1964ff | 137 | { |
d62a17ae | 138 | bgp_parse_fec_update(); |
139 | return 0; | |
cd1964ff DS |
140 | } |
141 | ||
d62a17ae | 142 | static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp) |
a80beece | 143 | { |
d62a17ae | 144 | struct listnode *node, *nnode; |
145 | struct peer *peer; | |
146 | ||
147 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
148 | if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) | |
149 | && peer->status != Established) { | |
150 | if (peer_active(peer)) | |
151 | BGP_EVENT_ADD(peer, BGP_Stop); | |
152 | BGP_EVENT_ADD(peer, BGP_Start); | |
153 | } | |
154 | } | |
a80beece DS |
155 | } |
156 | ||
d62a17ae | 157 | static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc) |
a197c47c | 158 | { |
d62a17ae | 159 | struct listnode *node; |
160 | struct connected *connected; | |
161 | struct interface *ifp; | |
162 | struct prefix *p; | |
163 | ||
164 | /* Kick-off the FSM for any relevant peers only if there is a | |
165 | * valid local address on the interface. | |
166 | */ | |
167 | ifp = ifc->ifp; | |
168 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { | |
169 | p = connected->address; | |
170 | if (p->family == AF_INET6 | |
171 | && IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) | |
172 | break; | |
173 | } | |
174 | if (!connected) | |
175 | return; | |
176 | ||
177 | bgp_start_interface_nbrs(bgp, ifp); | |
a197c47c DS |
178 | } |
179 | ||
d62a17ae | 180 | static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc, |
181 | int del) | |
a80beece | 182 | { |
d62a17ae | 183 | struct listnode *node, *nnode; |
184 | struct peer *peer; | |
185 | struct interface *ifp; | |
186 | ||
187 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
188 | if (peer->conf_if | |
189 | && (strcmp(peer->conf_if, ifc->ifp->name) == 0)) { | |
190 | peer->last_reset = PEER_DOWN_NBR_ADDR_DEL; | |
191 | BGP_EVENT_ADD(peer, BGP_Stop); | |
192 | } | |
193 | } | |
194 | /* Free neighbor also, if we're asked to. */ | |
195 | if (del) { | |
196 | ifp = ifc->ifp; | |
197 | listnode_delete(ifp->nbr_connected, ifc); | |
198 | nbr_connected_free(ifc); | |
199 | } | |
a80beece DS |
200 | } |
201 | ||
718e3744 | 202 | /* Inteface addition message from zebra. */ |
d62a17ae | 203 | static int bgp_interface_add(int command, struct zclient *zclient, |
204 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 205 | { |
d62a17ae | 206 | struct interface *ifp; |
207 | struct bgp *bgp; | |
718e3744 | 208 | |
d62a17ae | 209 | ifp = zebra_interface_add_read(zclient->ibuf, vrf_id); |
210 | if (!ifp) // unexpected | |
211 | return 0; | |
718e3744 | 212 | |
d62a17ae | 213 | if (BGP_DEBUG(zebra, ZEBRA) && ifp) |
214 | zlog_debug("Rx Intf add VRF %u IF %s", vrf_id, ifp->name); | |
a39275d7 | 215 | |
d62a17ae | 216 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
217 | if (!bgp) | |
218 | return 0; | |
4a04e5f7 | 219 | |
d62a17ae | 220 | bgp_update_interface_nbrs(bgp, ifp, ifp); |
221 | return 0; | |
718e3744 | 222 | } |
223 | ||
d62a17ae | 224 | static int bgp_interface_delete(int command, struct zclient *zclient, |
225 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 226 | { |
d62a17ae | 227 | struct stream *s; |
228 | struct interface *ifp; | |
229 | struct bgp *bgp; | |
718e3744 | 230 | |
2f9123e0 | 231 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2f9123e0 | 232 | |
d62a17ae | 233 | s = zclient->ibuf; |
234 | ifp = zebra_interface_state_read(s, vrf_id); | |
235 | if (!ifp) /* This may happen if we've just unregistered for a VRF. */ | |
236 | return 0; | |
a4499b83 | 237 | |
d62a17ae | 238 | if (BGP_DEBUG(zebra, ZEBRA)) |
239 | zlog_debug("Rx Intf del VRF %u IF %s", vrf_id, ifp->name); | |
a39275d7 | 240 | |
85751d1d DS |
241 | if (bgp) |
242 | bgp_update_interface_nbrs(bgp, ifp, NULL); | |
64745052 | 243 | |
ff880b78 | 244 | if_set_index(ifp, IFINDEX_INTERNAL); |
d62a17ae | 245 | return 0; |
718e3744 | 246 | } |
247 | ||
d62a17ae | 248 | static int bgp_interface_up(int command, struct zclient *zclient, |
249 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 250 | { |
d62a17ae | 251 | struct stream *s; |
252 | struct interface *ifp; | |
253 | struct connected *c; | |
254 | struct nbr_connected *nc; | |
255 | struct listnode *node, *nnode; | |
256 | struct bgp *bgp; | |
6aeb9e78 | 257 | |
2f9123e0 | 258 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2f9123e0 | 259 | |
d62a17ae | 260 | s = zclient->ibuf; |
261 | ifp = zebra_interface_state_read(s, vrf_id); | |
718e3744 | 262 | |
d62a17ae | 263 | if (!ifp) |
264 | return 0; | |
718e3744 | 265 | |
d62a17ae | 266 | if (BGP_DEBUG(zebra, ZEBRA)) |
267 | zlog_debug("Rx Intf up VRF %u IF %s", vrf_id, ifp->name); | |
ad4cbda1 | 268 | |
85751d1d DS |
269 | if (!bgp) |
270 | return 0; | |
271 | ||
d62a17ae | 272 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
273 | bgp_connected_add(bgp, c); | |
718e3744 | 274 | |
d62a17ae | 275 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
276 | bgp_nbr_connected_add(bgp, nc); | |
a80beece | 277 | |
d62a17ae | 278 | return 0; |
718e3744 | 279 | } |
280 | ||
d62a17ae | 281 | static int bgp_interface_down(int command, struct zclient *zclient, |
282 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 283 | { |
d62a17ae | 284 | struct stream *s; |
285 | struct interface *ifp; | |
286 | struct connected *c; | |
287 | struct nbr_connected *nc; | |
288 | struct listnode *node, *nnode; | |
289 | struct bgp *bgp; | |
c19fe3c7 | 290 | struct peer *peer; |
6aeb9e78 | 291 | |
2f9123e0 | 292 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2f9123e0 | 293 | |
d62a17ae | 294 | s = zclient->ibuf; |
295 | ifp = zebra_interface_state_read(s, vrf_id); | |
296 | if (!ifp) | |
297 | return 0; | |
718e3744 | 298 | |
d62a17ae | 299 | if (BGP_DEBUG(zebra, ZEBRA)) |
300 | zlog_debug("Rx Intf down VRF %u IF %s", vrf_id, ifp->name); | |
ad4cbda1 | 301 | |
85751d1d DS |
302 | if (!bgp) |
303 | return 0; | |
304 | ||
d62a17ae | 305 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
306 | bgp_connected_delete(bgp, c); | |
718e3744 | 307 | |
d62a17ae | 308 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
309 | bgp_nbr_connected_delete(bgp, nc, 1); | |
a80beece | 310 | |
d62a17ae | 311 | /* Fast external-failover */ |
c19fe3c7 | 312 | if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { |
718e3744 | 313 | |
d62a17ae | 314 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { |
8c4f6381 | 315 | #if defined(HAVE_CUMULUS) |
d62a17ae | 316 | /* Take down directly connected EBGP peers as well as |
317 | * 1-hop BFD | |
318 | * tracked (directly connected) IBGP peers. | |
319 | */ | |
320 | if ((peer->ttl != 1) && (peer->gtsm_hops != 1) | |
321 | && (!peer->bfd_info | |
322 | || bgp_bfd_is_peer_multihop(peer))) | |
8c4f6381 | 323 | #else |
d62a17ae | 324 | /* Take down directly connected EBGP peers */ |
325 | if ((peer->ttl != 1) && (peer->gtsm_hops != 1)) | |
8c4f6381 | 326 | #endif |
d62a17ae | 327 | continue; |
718e3744 | 328 | |
d62a17ae | 329 | if (ifp == peer->nexthop.ifp) { |
330 | BGP_EVENT_ADD(peer, BGP_Stop); | |
331 | peer->last_reset = PEER_DOWN_IF_DOWN; | |
332 | } | |
333 | } | |
334 | } | |
718e3744 | 335 | |
d62a17ae | 336 | return 0; |
718e3744 | 337 | } |
338 | ||
d62a17ae | 339 | static int bgp_interface_address_add(int command, struct zclient *zclient, |
340 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 341 | { |
d62a17ae | 342 | struct connected *ifc; |
2f9123e0 DS |
343 | struct bgp *bgp; |
344 | ||
345 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
d62a17ae | 346 | |
347 | ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); | |
348 | ||
349 | if (ifc == NULL) | |
350 | return 0; | |
351 | ||
352 | if (bgp_debug_zebra(ifc->address)) { | |
353 | char buf[PREFIX2STR_BUFFER]; | |
354 | prefix2str(ifc->address, buf, sizeof(buf)); | |
355 | zlog_debug("Rx Intf address add VRF %u IF %s addr %s", vrf_id, | |
356 | ifc->ifp->name, buf); | |
357 | } | |
358 | ||
85751d1d DS |
359 | if (!bgp) |
360 | return 0; | |
361 | ||
d62a17ae | 362 | if (if_is_operative(ifc->ifp)) { |
d62a17ae | 363 | bgp_connected_add(bgp, ifc); |
2f9123e0 | 364 | |
d62a17ae | 365 | /* If we have learnt of any neighbors on this interface, |
366 | * check to kick off any BGP interface-based neighbors, | |
367 | * but only if this is a link-local address. | |
368 | */ | |
369 | if (IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6) | |
370 | && !list_isempty(ifc->ifp->nbr_connected)) | |
371 | bgp_start_interface_nbrs(bgp, ifc->ifp); | |
372 | } | |
373 | ||
374 | return 0; | |
718e3744 | 375 | } |
376 | ||
d62a17ae | 377 | static int bgp_interface_address_delete(int command, struct zclient *zclient, |
378 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 379 | { |
d62a17ae | 380 | struct connected *ifc; |
381 | struct bgp *bgp; | |
6aeb9e78 | 382 | |
2f9123e0 | 383 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2f9123e0 | 384 | |
d62a17ae | 385 | ifc = zebra_interface_address_read(command, zclient->ibuf, vrf_id); |
718e3744 | 386 | |
d62a17ae | 387 | if (ifc == NULL) |
388 | return 0; | |
718e3744 | 389 | |
d62a17ae | 390 | if (bgp_debug_zebra(ifc->address)) { |
391 | char buf[PREFIX2STR_BUFFER]; | |
392 | prefix2str(ifc->address, buf, sizeof(buf)); | |
393 | zlog_debug("Rx Intf address del VRF %u IF %s addr %s", vrf_id, | |
394 | ifc->ifp->name, buf); | |
395 | } | |
a39275d7 | 396 | |
85751d1d | 397 | if (bgp && if_is_operative(ifc->ifp)) { |
2f9123e0 | 398 | bgp_connected_delete(bgp, ifc); |
d62a17ae | 399 | } |
718e3744 | 400 | |
d62a17ae | 401 | connected_free(ifc); |
718e3744 | 402 | |
d62a17ae | 403 | return 0; |
718e3744 | 404 | } |
405 | ||
d62a17ae | 406 | static int bgp_interface_nbr_address_add(int command, struct zclient *zclient, |
407 | zebra_size_t length, vrf_id_t vrf_id) | |
a80beece | 408 | { |
d62a17ae | 409 | struct nbr_connected *ifc = NULL; |
410 | struct bgp *bgp; | |
411 | ||
412 | ifc = zebra_interface_nbr_address_read(command, zclient->ibuf, vrf_id); | |
413 | ||
414 | if (ifc == NULL) | |
415 | return 0; | |
416 | ||
417 | if (bgp_debug_zebra(ifc->address)) { | |
418 | char buf[PREFIX2STR_BUFFER]; | |
419 | prefix2str(ifc->address, buf, sizeof(buf)); | |
420 | zlog_debug("Rx Intf neighbor add VRF %u IF %s addr %s", vrf_id, | |
421 | ifc->ifp->name, buf); | |
422 | } | |
423 | ||
424 | if (if_is_operative(ifc->ifp)) { | |
425 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
426 | if (bgp) | |
427 | bgp_nbr_connected_add(bgp, ifc); | |
428 | } | |
429 | ||
430 | return 0; | |
a80beece DS |
431 | } |
432 | ||
d62a17ae | 433 | static int bgp_interface_nbr_address_delete(int command, |
434 | struct zclient *zclient, | |
435 | zebra_size_t length, | |
436 | vrf_id_t vrf_id) | |
a80beece | 437 | { |
d62a17ae | 438 | struct nbr_connected *ifc = NULL; |
439 | struct bgp *bgp; | |
6aeb9e78 | 440 | |
d62a17ae | 441 | ifc = zebra_interface_nbr_address_read(command, zclient->ibuf, vrf_id); |
a80beece | 442 | |
d62a17ae | 443 | if (ifc == NULL) |
444 | return 0; | |
a80beece | 445 | |
d62a17ae | 446 | if (bgp_debug_zebra(ifc->address)) { |
447 | char buf[PREFIX2STR_BUFFER]; | |
448 | prefix2str(ifc->address, buf, sizeof(buf)); | |
449 | zlog_debug("Rx Intf neighbor del VRF %u IF %s addr %s", vrf_id, | |
450 | ifc->ifp->name, buf); | |
451 | } | |
a80beece | 452 | |
d62a17ae | 453 | if (if_is_operative(ifc->ifp)) { |
454 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
455 | if (bgp) | |
456 | bgp_nbr_connected_delete(bgp, ifc, 0); | |
457 | } | |
a80beece | 458 | |
d62a17ae | 459 | nbr_connected_free(ifc); |
a80beece | 460 | |
d62a17ae | 461 | return 0; |
a80beece DS |
462 | } |
463 | ||
bfcd43b2 | 464 | /* VRF update for an interface. */ |
d62a17ae | 465 | static int bgp_interface_vrf_update(int command, struct zclient *zclient, |
466 | zebra_size_t length, vrf_id_t vrf_id) | |
bfcd43b2 | 467 | { |
d62a17ae | 468 | struct interface *ifp; |
469 | vrf_id_t new_vrf_id; | |
470 | struct connected *c; | |
471 | struct nbr_connected *nc; | |
472 | struct listnode *node, *nnode; | |
473 | struct bgp *bgp; | |
c19fe3c7 | 474 | struct peer *peer; |
bfcd43b2 | 475 | |
d62a17ae | 476 | ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, |
477 | &new_vrf_id); | |
478 | if (!ifp) | |
479 | return 0; | |
bfcd43b2 | 480 | |
d62a17ae | 481 | if (BGP_DEBUG(zebra, ZEBRA) && ifp) |
482 | zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u", vrf_id, | |
483 | ifp->name, new_vrf_id); | |
bfcd43b2 | 484 | |
d62a17ae | 485 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
bfcd43b2 | 486 | |
85751d1d DS |
487 | if (bgp) { |
488 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) | |
489 | bgp_connected_delete(bgp, c); | |
bfcd43b2 | 490 | |
85751d1d DS |
491 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
492 | bgp_nbr_connected_delete(bgp, nc, 1); | |
bfcd43b2 | 493 | |
85751d1d DS |
494 | /* Fast external-failover */ |
495 | if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { | |
496 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
497 | if ((peer->ttl != 1) && (peer->gtsm_hops != 1)) | |
498 | continue; | |
bfcd43b2 | 499 | |
85751d1d DS |
500 | if (ifp == peer->nexthop.ifp) |
501 | BGP_EVENT_ADD(peer, BGP_Stop); | |
502 | } | |
d62a17ae | 503 | } |
504 | } | |
bfcd43b2 | 505 | |
d62a17ae | 506 | if_update_to_new_vrf(ifp, new_vrf_id); |
bfcd43b2 | 507 | |
d62a17ae | 508 | bgp = bgp_lookup_by_vrf_id(new_vrf_id); |
509 | if (!bgp) | |
510 | return 0; | |
bfcd43b2 | 511 | |
d62a17ae | 512 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
513 | bgp_connected_add(bgp, c); | |
bfcd43b2 | 514 | |
d62a17ae | 515 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
516 | bgp_nbr_connected_add(bgp, nc); | |
517 | return 0; | |
bfcd43b2 | 518 | } |
519 | ||
718e3744 | 520 | /* Zebra route add and delete treatment. */ |
74489921 RW |
521 | static int zebra_read_route(int command, struct zclient *zclient, |
522 | zebra_size_t length, vrf_id_t vrf_id) | |
718e3744 | 523 | { |
9de1f7ff | 524 | enum nexthop_types_t nhtype; |
74489921 RW |
525 | struct zapi_route api; |
526 | union g_addr nexthop; | |
9de1f7ff | 527 | ifindex_t ifindex; |
74489921 | 528 | int add, i; |
d62a17ae | 529 | struct bgp *bgp; |
530 | ||
531 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
532 | if (!bgp) | |
533 | return 0; | |
534 | ||
74489921 RW |
535 | if (zapi_route_decode(zclient->ibuf, &api) < 0) |
536 | return -1; | |
d62a17ae | 537 | |
74489921 RW |
538 | /* we completely ignore srcdest routes for now. */ |
539 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) | |
540 | return 0; | |
d62a17ae | 541 | |
74489921 RW |
542 | /* ignore link-local address. */ |
543 | if (api.prefix.family == AF_INET6 | |
544 | && IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6)) | |
545 | return 0; | |
d62a17ae | 546 | |
74489921 RW |
547 | nexthop = api.nexthops[0].gate; |
548 | ifindex = api.nexthops[0].ifindex; | |
9de1f7ff | 549 | nhtype = api.nexthops[0].type; |
d62a17ae | 550 | |
74489921 RW |
551 | add = (command == ZEBRA_REDISTRIBUTE_ROUTE_ADD); |
552 | if (add) { | |
d62a17ae | 553 | /* |
554 | * The ADD message is actually an UPDATE and there is no | |
555 | * explicit DEL | |
556 | * for a prior redistributed route, if any. So, perform an | |
557 | * implicit | |
558 | * DEL processing for the same redistributed route from any | |
559 | * other | |
560 | * source type. | |
561 | */ | |
562 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
563 | if (i != api.type) | |
74489921 | 564 | bgp_redistribute_delete(bgp, &api.prefix, i, |
d62a17ae | 565 | api.instance); |
566 | } | |
567 | ||
568 | /* Now perform the add/update. */ | |
74489921 | 569 | bgp_redistribute_add(bgp, &api.prefix, &nexthop, ifindex, |
a4d82a8a PZ |
570 | nhtype, api.metric, api.type, api.instance, |
571 | api.tag); | |
d62a17ae | 572 | } else { |
74489921 RW |
573 | bgp_redistribute_delete(bgp, &api.prefix, api.type, |
574 | api.instance); | |
a39275d7 | 575 | } |
d62a17ae | 576 | |
74489921 RW |
577 | if (bgp_debug_zebra(&api.prefix)) { |
578 | char buf[2][PREFIX_STRLEN]; | |
579 | ||
580 | prefix2str(&api.prefix, buf[0], sizeof(buf[0])); | |
77e62f2b | 581 | if (add) { |
582 | inet_ntop(api.prefix.family, &nexthop, buf[1], | |
583 | sizeof(buf[1])); | |
584 | zlog_debug( | |
585 | "Rx route ADD VRF %u %s[%d] %s nexthop %s (type %d if %u) metric %u tag %" ROUTE_TAG_PRI, | |
586 | vrf_id, zebra_route_string(api.type), | |
587 | api.instance, buf[0], buf[1], nhtype, | |
588 | ifindex, api.metric, api.tag); | |
589 | } else { | |
590 | zlog_debug( | |
591 | "Rx route DEL VRF %u %s[%d] %s", | |
592 | vrf_id, zebra_route_string(api.type), | |
593 | api.instance, buf[0]); | |
594 | } | |
d62a17ae | 595 | } |
596 | ||
597 | return 0; | |
718e3744 | 598 | } |
6b0655a2 | 599 | |
d62a17ae | 600 | struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) |
718e3744 | 601 | { |
f4e14fdb | 602 | struct vrf *vrf; |
d62a17ae | 603 | struct listnode *cnode; |
604 | struct interface *ifp; | |
605 | struct connected *connected; | |
606 | struct prefix_ipv4 p; | |
607 | struct prefix *cp; | |
608 | ||
f4e14fdb RW |
609 | vrf = vrf_lookup_by_id(vrf_id); |
610 | if (!vrf) | |
611 | return NULL; | |
612 | ||
d62a17ae | 613 | p.family = AF_INET; |
614 | p.prefix = *addr; | |
615 | p.prefixlen = IPV4_MAX_BITLEN; | |
616 | ||
451fda4f | 617 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 618 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
619 | cp = connected->address; | |
620 | ||
621 | if (cp->family == AF_INET) | |
622 | if (prefix_match(cp, (struct prefix *)&p)) | |
623 | return ifp; | |
624 | } | |
718e3744 | 625 | } |
d62a17ae | 626 | return NULL; |
718e3744 | 627 | } |
628 | ||
d62a17ae | 629 | struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) |
718e3744 | 630 | { |
f4e14fdb | 631 | struct vrf *vrf; |
d62a17ae | 632 | struct listnode *cnode; |
633 | struct interface *ifp; | |
634 | struct connected *connected; | |
635 | struct prefix *cp; | |
636 | ||
f4e14fdb RW |
637 | vrf = vrf_lookup_by_id(vrf_id); |
638 | if (!vrf) | |
639 | return NULL; | |
640 | ||
451fda4f | 641 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 642 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
643 | cp = connected->address; | |
644 | ||
645 | if (cp->family == AF_INET) | |
646 | if (IPV4_ADDR_SAME(&cp->u.prefix4, addr)) | |
647 | return ifp; | |
648 | } | |
718e3744 | 649 | } |
d62a17ae | 650 | return NULL; |
718e3744 | 651 | } |
652 | ||
d62a17ae | 653 | struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, |
654 | vrf_id_t vrf_id) | |
718e3744 | 655 | { |
f4e14fdb | 656 | struct vrf *vrf; |
d62a17ae | 657 | struct listnode *cnode; |
658 | struct interface *ifp; | |
659 | struct connected *connected; | |
660 | struct prefix_ipv6 p; | |
661 | struct prefix *cp; | |
662 | ||
f4e14fdb RW |
663 | vrf = vrf_lookup_by_id(vrf_id); |
664 | if (!vrf) | |
665 | return NULL; | |
666 | ||
d62a17ae | 667 | p.family = AF_INET6; |
668 | p.prefix = *addr; | |
669 | p.prefixlen = IPV6_MAX_BITLEN; | |
670 | ||
451fda4f | 671 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 672 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
673 | cp = connected->address; | |
674 | ||
675 | if (cp->family == AF_INET6) | |
676 | if (prefix_match(cp, (struct prefix *)&p)) { | |
677 | if (IN6_IS_ADDR_LINKLOCAL( | |
678 | &cp->u.prefix6)) { | |
679 | if (ifindex == ifp->ifindex) | |
680 | return ifp; | |
681 | } else | |
682 | return ifp; | |
683 | } | |
684 | } | |
718e3744 | 685 | } |
d62a17ae | 686 | return NULL; |
718e3744 | 687 | } |
688 | ||
d62a17ae | 689 | struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, |
690 | ifindex_t ifindex, vrf_id_t vrf_id) | |
718e3744 | 691 | { |
f4e14fdb | 692 | struct vrf *vrf; |
d62a17ae | 693 | struct listnode *cnode; |
694 | struct interface *ifp; | |
695 | struct connected *connected; | |
696 | struct prefix *cp; | |
697 | ||
f4e14fdb RW |
698 | vrf = vrf_lookup_by_id(vrf_id); |
699 | if (!vrf) | |
700 | return NULL; | |
701 | ||
451fda4f | 702 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 703 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
704 | cp = connected->address; | |
705 | ||
706 | if (cp->family == AF_INET6) | |
707 | if (IPV6_ADDR_SAME(&cp->u.prefix6, addr)) { | |
708 | if (IN6_IS_ADDR_LINKLOCAL( | |
709 | &cp->u.prefix6)) { | |
710 | if (ifindex == ifp->ifindex) | |
711 | return ifp; | |
712 | } else | |
713 | return ifp; | |
714 | } | |
715 | } | |
718e3744 | 716 | } |
d62a17ae | 717 | return NULL; |
718e3744 | 718 | } |
719 | ||
d62a17ae | 720 | static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr) |
718e3744 | 721 | { |
d62a17ae | 722 | struct listnode *cnode; |
723 | struct connected *connected; | |
724 | struct prefix *cp; | |
725 | ||
726 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
727 | cp = connected->address; | |
728 | ||
729 | if (cp->family == AF_INET6) | |
730 | if (!IN6_IS_ADDR_LINKLOCAL(&cp->u.prefix6)) { | |
731 | memcpy(addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); | |
732 | return 1; | |
733 | } | |
734 | } | |
735 | return 0; | |
718e3744 | 736 | } |
737 | ||
d62a17ae | 738 | static int if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr) |
718e3744 | 739 | { |
d62a17ae | 740 | struct listnode *cnode; |
741 | struct connected *connected; | |
742 | struct prefix *cp; | |
743 | ||
744 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
745 | cp = connected->address; | |
746 | ||
747 | if (cp->family == AF_INET6) | |
748 | if (IN6_IS_ADDR_LINKLOCAL(&cp->u.prefix6)) { | |
749 | memcpy(addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); | |
750 | return 1; | |
751 | } | |
752 | } | |
753 | return 0; | |
718e3744 | 754 | } |
718e3744 | 755 | |
d62a17ae | 756 | static int if_get_ipv4_address(struct interface *ifp, struct in_addr *addr) |
6ee06fa9 | 757 | { |
d62a17ae | 758 | struct listnode *cnode; |
759 | struct connected *connected; | |
760 | struct prefix *cp; | |
761 | ||
762 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
763 | cp = connected->address; | |
764 | if ((cp->family == AF_INET) | |
765 | && !ipv4_martian(&(cp->u.prefix4))) { | |
766 | *addr = cp->u.prefix4; | |
767 | return 1; | |
768 | } | |
769 | } | |
770 | return 0; | |
6ee06fa9 PM |
771 | } |
772 | ||
17cdd31e DS |
773 | |
774 | bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote, | |
775 | struct bgp_nexthop *nexthop, struct peer *peer) | |
718e3744 | 776 | { |
d62a17ae | 777 | int ret = 0; |
778 | struct interface *ifp = NULL; | |
779 | ||
780 | memset(nexthop, 0, sizeof(struct bgp_nexthop)); | |
781 | ||
782 | if (!local) | |
17cdd31e | 783 | return false; |
d62a17ae | 784 | if (!remote) |
17cdd31e | 785 | return false; |
d62a17ae | 786 | |
787 | if (local->sa.sa_family == AF_INET) { | |
788 | nexthop->v4 = local->sin.sin_addr; | |
789 | if (peer->update_if) | |
790 | ifp = if_lookup_by_name(peer->update_if, | |
791 | peer->bgp->vrf_id); | |
792 | else | |
793 | ifp = if_lookup_by_ipv4_exact(&local->sin.sin_addr, | |
794 | peer->bgp->vrf_id); | |
718e3744 | 795 | } |
d62a17ae | 796 | if (local->sa.sa_family == AF_INET6) { |
797 | if (IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr)) { | |
798 | if (peer->conf_if || peer->ifname) | |
799 | ifp = if_lookup_by_name(peer->conf_if | |
800 | ? peer->conf_if | |
801 | : peer->ifname, | |
802 | peer->bgp->vrf_id); | |
803 | } else if (peer->update_if) | |
804 | ifp = if_lookup_by_name(peer->update_if, | |
805 | peer->bgp->vrf_id); | |
806 | else | |
807 | ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr, | |
808 | local->sin6.sin6_scope_id, | |
809 | peer->bgp->vrf_id); | |
718e3744 | 810 | } |
d62a17ae | 811 | |
17cdd31e DS |
812 | if (!ifp) { |
813 | /* | |
814 | * BGP views do not currently get proper data | |
815 | * from zebra( when attached ) to be able to | |
816 | * properly resolve nexthops, so give this | |
817 | * instance type a pass. | |
818 | */ | |
819 | if (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) | |
820 | return true; | |
821 | /* | |
822 | * If we have no interface data but we have established | |
823 | * some connection w/ zebra than something has gone | |
824 | * terribly terribly wrong here, so say this failed | |
825 | * If we do not any zebra connection then not | |
826 | * having a ifp pointer is ok. | |
827 | */ | |
828 | return zclient_num_connects ? false : true; | |
829 | } | |
d62a17ae | 830 | |
831 | nexthop->ifp = ifp; | |
832 | ||
833 | /* IPv4 connection, fetch and store IPv6 local address(es) if any. */ | |
834 | if (local->sa.sa_family == AF_INET) { | |
835 | /* IPv6 nexthop*/ | |
836 | ret = if_get_ipv6_global(ifp, &nexthop->v6_global); | |
837 | ||
838 | if (!ret) { | |
839 | /* There is no global nexthop. Use link-local address as | |
840 | * both the | |
841 | * global and link-local nexthop. In this scenario, the | |
842 | * expectation | |
843 | * for interop is that the network admin would use a | |
844 | * route-map to | |
845 | * specify the global IPv6 nexthop. | |
846 | */ | |
847 | if_get_ipv6_local(ifp, &nexthop->v6_global); | |
848 | memcpy(&nexthop->v6_local, &nexthop->v6_global, | |
849 | IPV6_MAX_BYTELEN); | |
850 | } else | |
851 | if_get_ipv6_local(ifp, &nexthop->v6_local); | |
852 | ||
853 | if (if_lookup_by_ipv4(&remote->sin.sin_addr, peer->bgp->vrf_id)) | |
854 | peer->shared_network = 1; | |
855 | else | |
856 | peer->shared_network = 0; | |
718e3744 | 857 | } |
718e3744 | 858 | |
d62a17ae | 859 | /* IPv6 connection, fetch and store IPv4 local address if any. */ |
860 | if (local->sa.sa_family == AF_INET6) { | |
861 | struct interface *direct = NULL; | |
862 | ||
863 | /* IPv4 nexthop. */ | |
864 | ret = if_get_ipv4_address(ifp, &nexthop->v4); | |
865 | if (!ret && peer->local_id.s_addr) | |
866 | nexthop->v4 = peer->local_id; | |
867 | ||
868 | /* Global address*/ | |
869 | if (!IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr)) { | |
870 | memcpy(&nexthop->v6_global, &local->sin6.sin6_addr, | |
871 | IPV6_MAX_BYTELEN); | |
872 | ||
873 | /* If directory connected set link-local address. */ | |
874 | direct = if_lookup_by_ipv6(&remote->sin6.sin6_addr, | |
875 | remote->sin6.sin6_scope_id, | |
876 | peer->bgp->vrf_id); | |
877 | if (direct) | |
878 | if_get_ipv6_local(ifp, &nexthop->v6_local); | |
879 | } else | |
880 | /* Link-local address. */ | |
881 | { | |
882 | ret = if_get_ipv6_global(ifp, &nexthop->v6_global); | |
883 | ||
884 | /* If there is no global address. Set link-local | |
885 | address as | |
886 | global. I know this break RFC specification... */ | |
887 | /* In this scenario, the expectation for interop is that | |
888 | * the | |
889 | * network admin would use a route-map to specify the | |
890 | * global | |
891 | * IPv6 nexthop. | |
892 | */ | |
893 | if (!ret) | |
894 | memcpy(&nexthop->v6_global, | |
895 | &local->sin6.sin6_addr, | |
896 | IPV6_MAX_BYTELEN); | |
897 | /* Always set the link-local address */ | |
898 | memcpy(&nexthop->v6_local, &local->sin6.sin6_addr, | |
899 | IPV6_MAX_BYTELEN); | |
900 | } | |
901 | ||
902 | if (IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr) | |
903 | || if_lookup_by_ipv6(&remote->sin6.sin6_addr, | |
904 | remote->sin6.sin6_scope_id, | |
905 | peer->bgp->vrf_id)) | |
906 | peer->shared_network = 1; | |
907 | else | |
908 | peer->shared_network = 0; | |
909 | } | |
718e3744 | 910 | |
d62a17ae | 911 | /* KAME stack specific treatment. */ |
718e3744 | 912 | #ifdef KAME |
d62a17ae | 913 | if (IN6_IS_ADDR_LINKLOCAL(&nexthop->v6_global) |
914 | && IN6_LINKLOCAL_IFINDEX(nexthop->v6_global)) { | |
915 | SET_IN6_LINKLOCAL_IFINDEX(nexthop->v6_global, 0); | |
916 | } | |
917 | if (IN6_IS_ADDR_LINKLOCAL(&nexthop->v6_local) | |
918 | && IN6_LINKLOCAL_IFINDEX(nexthop->v6_local)) { | |
919 | SET_IN6_LINKLOCAL_IFINDEX(nexthop->v6_local, 0); | |
920 | } | |
718e3744 | 921 | #endif /* KAME */ |
e33a4880 | 922 | |
d62a17ae | 923 | /* If we have identified the local interface, there is no error for now. |
924 | */ | |
17cdd31e | 925 | return true; |
718e3744 | 926 | } |
927 | ||
18ee8310 | 928 | static struct in6_addr * |
40381db7 | 929 | bgp_path_info_to_ipv6_nexthop(struct bgp_path_info *path, ifindex_t *ifindex) |
73ac8160 | 930 | { |
d62a17ae | 931 | struct in6_addr *nexthop = NULL; |
932 | ||
933 | /* Only global address nexthop exists. */ | |
40381db7 DS |
934 | if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL) { |
935 | nexthop = &path->attr->mp_nexthop_global; | |
77e62f2b | 936 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 937 | *ifindex = path->attr->nh_ifindex; |
77e62f2b | 938 | } |
d62a17ae | 939 | |
940 | /* If both global and link-local address present. */ | |
40381db7 | 941 | if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) { |
d62a17ae | 942 | /* Check if route-map is set to prefer global over link-local */ |
40381db7 DS |
943 | if (path->attr->mp_nexthop_prefer_global) { |
944 | nexthop = &path->attr->mp_nexthop_global; | |
77e62f2b | 945 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 946 | *ifindex = path->attr->nh_ifindex; |
77e62f2b | 947 | } else { |
d62a17ae | 948 | /* Workaround for Cisco's nexthop bug. */ |
949 | if (IN6_IS_ADDR_UNSPECIFIED( | |
40381db7 DS |
950 | &path->attr->mp_nexthop_global) |
951 | && path->peer->su_remote->sa.sa_family | |
59a0f1cb | 952 | == AF_INET6) { |
d62a17ae | 953 | nexthop = |
40381db7 | 954 | &path->peer->su_remote->sin6.sin6_addr; |
77e62f2b | 955 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 956 | *ifindex = path->peer->nexthop.ifp |
59a0f1cb | 957 | ->ifindex; |
77e62f2b | 958 | } else { |
40381db7 | 959 | nexthop = &path->attr->mp_nexthop_local; |
77e62f2b | 960 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 961 | *ifindex = path->attr->nh_lla_ifindex; |
77e62f2b | 962 | } |
d62a17ae | 963 | } |
964 | } | |
965 | ||
966 | return nexthop; | |
73ac8160 DS |
967 | } |
968 | ||
d62a17ae | 969 | static int bgp_table_map_apply(struct route_map *map, struct prefix *p, |
40381db7 | 970 | struct bgp_path_info *path) |
73ac8160 | 971 | { |
b4cb15c6 DL |
972 | route_map_result_t ret; |
973 | ||
40381db7 DS |
974 | ret = route_map_apply(map, p, RMAP_BGP, path); |
975 | bgp_attr_flush(path->attr); | |
b4cb15c6 DL |
976 | |
977 | if (ret != RMAP_DENYMATCH) | |
d62a17ae | 978 | return 1; |
979 | ||
980 | if (bgp_debug_zebra(p)) { | |
981 | if (p->family == AF_INET) { | |
982 | char buf[2][INET_ADDRSTRLEN]; | |
983 | zlog_debug( | |
984 | "Zebra rmap deny: IPv4 route %s/%d nexthop %s", | |
985 | inet_ntop(AF_INET, &p->u.prefix4, buf[0], | |
986 | sizeof(buf[0])), | |
987 | p->prefixlen, | |
40381db7 | 988 | inet_ntop(AF_INET, &path->attr->nexthop, buf[1], |
d62a17ae | 989 | sizeof(buf[1]))); |
990 | } | |
991 | if (p->family == AF_INET6) { | |
992 | char buf[2][INET6_ADDRSTRLEN]; | |
77e62f2b | 993 | ifindex_t ifindex; |
994 | struct in6_addr *nexthop; | |
995 | ||
40381db7 | 996 | nexthop = bgp_path_info_to_ipv6_nexthop(path, &ifindex); |
d62a17ae | 997 | zlog_debug( |
998 | "Zebra rmap deny: IPv6 route %s/%d nexthop %s", | |
999 | inet_ntop(AF_INET6, &p->u.prefix6, buf[0], | |
1000 | sizeof(buf[0])), | |
1001 | p->prefixlen, | |
77e62f2b | 1002 | inet_ntop(AF_INET6, nexthop, |
d62a17ae | 1003 | buf[1], sizeof(buf[1]))); |
1004 | } | |
1005 | } | |
1006 | return 0; | |
73ac8160 DS |
1007 | } |
1008 | ||
b98f7728 PG |
1009 | static struct thread *bgp_tm_thread_connect; |
1010 | static bool bgp_tm_status_connected; | |
31c28cd7 PG |
1011 | static bool bgp_tm_chunk_obtained; |
1012 | #define BGP_FLOWSPEC_TABLE_CHUNK 100000 | |
1013 | static uint32_t bgp_tm_min, bgp_tm_max, bgp_tm_chunk_size; | |
6818e7e5 | 1014 | struct bgp *bgp_tm_bgp; |
b98f7728 PG |
1015 | |
1016 | static int bgp_zebra_tm_connect(struct thread *t) | |
1017 | { | |
1018 | struct zclient *zclient; | |
1019 | int delay = 10, ret = 0; | |
1020 | ||
1021 | zclient = THREAD_ARG(t); | |
1022 | if (bgp_tm_status_connected && zclient->sock > 0) | |
1023 | delay = 60; | |
1024 | else { | |
1025 | bgp_tm_status_connected = false; | |
1026 | ret = tm_table_manager_connect(zclient); | |
1027 | } | |
1028 | if (ret < 0) { | |
b7cd3069 | 1029 | zlog_info("Error connecting to table manager!"); |
b98f7728 PG |
1030 | bgp_tm_status_connected = false; |
1031 | } else { | |
1032 | if (!bgp_tm_status_connected) | |
1033 | zlog_debug("Connecting to table manager. Success"); | |
1034 | bgp_tm_status_connected = true; | |
31c28cd7 PG |
1035 | if (!bgp_tm_chunk_obtained) { |
1036 | if (bgp_zebra_get_table_range(bgp_tm_chunk_size, | |
1037 | &bgp_tm_min, | |
6818e7e5 | 1038 | &bgp_tm_max) >= 0) { |
31c28cd7 | 1039 | bgp_tm_chunk_obtained = true; |
6818e7e5 PG |
1040 | /* parse non installed entries */ |
1041 | bgp_zebra_announce_table(bgp_tm_bgp, AFI_IP, SAFI_FLOWSPEC); | |
1042 | } | |
31c28cd7 | 1043 | } |
b98f7728 PG |
1044 | } |
1045 | thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, | |
1046 | &bgp_tm_thread_connect); | |
1047 | return 0; | |
1048 | } | |
1049 | ||
6818e7e5 PG |
1050 | bool bgp_zebra_tm_chunk_obtained(void) |
1051 | { | |
1052 | return bgp_tm_chunk_obtained; | |
1053 | } | |
1054 | ||
31c28cd7 PG |
1055 | uint32_t bgp_zebra_tm_get_id(void) |
1056 | { | |
1057 | static int table_id; | |
1058 | ||
1059 | if (!bgp_tm_chunk_obtained) | |
1060 | return ++table_id; | |
1061 | return bgp_tm_min++; | |
1062 | } | |
1063 | ||
6818e7e5 | 1064 | void bgp_zebra_init_tm_connect(struct bgp *bgp) |
b98f7728 PG |
1065 | { |
1066 | int delay = 1; | |
1067 | ||
1068 | /* if already set, do nothing | |
1069 | */ | |
1070 | if (bgp_tm_thread_connect != NULL) | |
1071 | return; | |
1072 | bgp_tm_status_connected = false; | |
31c28cd7 PG |
1073 | bgp_tm_chunk_obtained = false; |
1074 | bgp_tm_min = bgp_tm_max = 0; | |
1075 | bgp_tm_chunk_size = BGP_FLOWSPEC_TABLE_CHUNK; | |
6818e7e5 | 1076 | bgp_tm_bgp = bgp; |
b98f7728 PG |
1077 | thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, |
1078 | &bgp_tm_thread_connect); | |
1079 | } | |
1080 | ||
1081 | int bgp_zebra_get_table_range(uint32_t chunk_size, | |
1082 | uint32_t *start, uint32_t *end) | |
1083 | { | |
1084 | int ret; | |
1085 | ||
1086 | if (!bgp_tm_status_connected) | |
1087 | return -1; | |
1088 | ret = tm_get_table_chunk(zclient, chunk_size, start, end); | |
1089 | if (ret < 0) { | |
e50f7cfd | 1090 | flog_err(EC_BGP_TABLE_CHUNK, |
1c50c1c0 | 1091 | "BGP: Error getting table chunk %u", chunk_size); |
b98f7728 PG |
1092 | return -1; |
1093 | } | |
1094 | zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]", | |
1095 | chunk_size, *start, *end); | |
1096 | return 0; | |
1097 | } | |
1098 | ||
77e62f2b | 1099 | static int update_ipv4nh_for_route_install(int nh_othervrf, |
1100 | struct in_addr *nexthop, | |
1101 | struct attr *attr, | |
1102 | bool is_evpn, | |
1103 | struct zapi_nexthop *api_nh) | |
1104 | { | |
1105 | api_nh->gate.ipv4 = *nexthop; | |
1106 | ||
1107 | /* Need to set fields appropriately for EVPN routes imported into | |
1108 | * a VRF (which are programmed as onlink on l3-vni SVI) as well as | |
1109 | * connected routes leaked into a VRF. | |
1110 | */ | |
1111 | if (is_evpn) | |
1112 | api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX; | |
1113 | else if (nh_othervrf && | |
1114 | api_nh->gate.ipv4.s_addr == INADDR_ANY) { | |
1115 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
1116 | api_nh->ifindex = attr->nh_ifindex; | |
1117 | } else | |
1118 | api_nh->type = NEXTHOP_TYPE_IPV4; | |
1119 | ||
1120 | return 1; | |
1121 | } | |
1122 | ||
4b7e6066 DS |
1123 | static int |
1124 | update_ipv6nh_for_route_install(int nh_othervrf, struct in6_addr *nexthop, | |
40381db7 DS |
1125 | ifindex_t ifindex, struct bgp_path_info *pi, |
1126 | struct bgp_path_info *best_pi, bool is_evpn, | |
4b7e6066 | 1127 | struct zapi_nexthop *api_nh) |
77e62f2b | 1128 | { |
1129 | struct attr *attr; | |
1130 | ||
40381db7 | 1131 | attr = pi->attr; |
77e62f2b | 1132 | |
1133 | if (is_evpn) | |
1134 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
1135 | else if (nh_othervrf) { | |
1136 | if (IN6_IS_ADDR_UNSPECIFIED(nexthop)) { | |
1137 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
1138 | api_nh->ifindex = attr->nh_ifindex; | |
1139 | } else if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { | |
1140 | if (ifindex == 0) | |
1141 | return 0; | |
1142 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
1143 | api_nh->ifindex = ifindex; | |
1144 | } else { | |
1145 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
1146 | api_nh->ifindex = 0; | |
1147 | } | |
1148 | } else { | |
1149 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { | |
40381db7 DS |
1150 | if (pi == best_pi |
1151 | && attr->mp_nexthop_len | |
1152 | == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) | |
1153 | if (pi->peer->nexthop.ifp) | |
1154 | ifindex = | |
1155 | pi->peer->nexthop.ifp->ifindex; | |
77e62f2b | 1156 | if (!ifindex) { |
40381db7 DS |
1157 | if (pi->peer->conf_if) |
1158 | ifindex = pi->peer->ifp->ifindex; | |
1159 | else if (pi->peer->ifname) | |
77e62f2b | 1160 | ifindex = ifname2ifindex( |
40381db7 DS |
1161 | pi->peer->ifname, |
1162 | pi->peer->bgp->vrf_id); | |
1163 | else if (pi->peer->nexthop.ifp) | |
1164 | ifindex = | |
1165 | pi->peer->nexthop.ifp->ifindex; | |
77e62f2b | 1166 | } |
1167 | ||
1168 | if (ifindex == 0) | |
1169 | return 0; | |
1170 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
1171 | api_nh->ifindex = ifindex; | |
1172 | } else { | |
1173 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
1174 | api_nh->ifindex = 0; | |
1175 | } | |
1176 | } | |
1177 | api_nh->gate.ipv6 = *nexthop; | |
1178 | ||
1179 | return 1; | |
1180 | } | |
1181 | ||
d62a17ae | 1182 | void bgp_zebra_announce(struct bgp_node *rn, struct prefix *p, |
4b7e6066 | 1183 | struct bgp_path_info *info, struct bgp *bgp, afi_t afi, |
d62a17ae | 1184 | safi_t safi) |
718e3744 | 1185 | { |
9913029c RW |
1186 | struct zapi_route api; |
1187 | struct zapi_nexthop *api_nh; | |
2ad4f093 | 1188 | int nh_family; |
a74e593b | 1189 | unsigned int valid_nh_count = 0; |
2ad4f093 | 1190 | int has_valid_label = 0; |
d7c0a89a | 1191 | uint8_t distance; |
d62a17ae | 1192 | struct peer *peer; |
4b7e6066 | 1193 | struct bgp_path_info *mpinfo; |
d7c0a89a | 1194 | uint32_t metric; |
b4cb15c6 | 1195 | struct attr local_attr; |
4b7e6066 DS |
1196 | struct bgp_path_info local_info; |
1197 | struct bgp_path_info *mpinfo_cp = &local_info; | |
d62a17ae | 1198 | route_tag_t tag; |
1199 | mpls_label_t label; | |
ddb5b488 | 1200 | int nh_othervrf = 0; |
960035b2 | 1201 | char buf_prefix[PREFIX_STRLEN]; /* filled in if we are debugging */ |
3f54c705 | 1202 | bool is_evpn; |
77e62f2b | 1203 | int nh_updated; |
d62a17ae | 1204 | |
1205 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't | |
1206 | * know of this instance. | |
1207 | */ | |
1208 | if (!bgp_install_info_to_zebra(bgp)) | |
1209 | return; | |
1210 | ||
d62a17ae | 1211 | if (bgp->main_zebra_update_hold) |
1212 | return; | |
1213 | ||
960035b2 | 1214 | if (bgp_debug_zebra(p)) |
ba1976db | 1215 | prefix2str(p, buf_prefix, sizeof(buf_prefix)); |
960035b2 | 1216 | |
529efa23 PG |
1217 | if (safi == SAFI_FLOWSPEC) |
1218 | return bgp_pbr_update_entry(bgp, &rn->p, | |
1219 | info, afi, safi, true); | |
1220 | ||
ddb5b488 PZ |
1221 | /* |
1222 | * vrf leaking support (will have only one nexthop) | |
1223 | */ | |
1224 | if (info->extra && info->extra->bgp_orig) | |
1225 | nh_othervrf = 1; | |
1226 | ||
9913029c RW |
1227 | /* Make Zebra API structure. */ |
1228 | memset(&api, 0, sizeof(api)); | |
1229 | api.vrf_id = bgp->vrf_id; | |
1230 | api.type = ZEBRA_ROUTE_BGP; | |
1231 | api.safi = safi; | |
1232 | api.prefix = *p; | |
1233 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); | |
1234 | ||
d62a17ae | 1235 | peer = info->peer; |
1236 | ||
ddb5b488 PZ |
1237 | if (info->type == ZEBRA_ROUTE_BGP |
1238 | && info->sub_type == BGP_ROUTE_IMPORTED) { | |
1239 | ||
1ec90b5e | 1240 | /* Obtain peer from parent */ |
1241 | if (info->extra && info->extra->parent) | |
4b7e6066 DS |
1242 | peer = ((struct bgp_path_info *)(info->extra->parent)) |
1243 | ->peer; | |
ddb5b488 PZ |
1244 | } |
1245 | ||
d62a17ae | 1246 | tag = info->attr->tag; |
1247 | ||
88493076 | 1248 | /* If the route's source is EVPN, flag as such. */ |
77e62f2b | 1249 | is_evpn = is_route_parent_evpn(info); |
1250 | if (is_evpn) | |
90264d64 | 1251 | SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); |
d3135ba3 | 1252 | |
d62a17ae | 1253 | if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED |
1254 | || info->sub_type == BGP_ROUTE_AGGREGATE) { | |
9913029c | 1255 | SET_FLAG(api.flags, ZEBRA_FLAG_IBGP); |
4e8b02f4 | 1256 | SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); |
718e3744 | 1257 | } |
a39275d7 | 1258 | |
d62a17ae | 1259 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != 1) |
1260 | || CHECK_FLAG(peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) | |
1261 | || bgp_flag_check(bgp, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) | |
1262 | ||
4e8b02f4 | 1263 | SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); |
d62a17ae | 1264 | |
2ad4f093 RW |
1265 | /* Metric is currently based on the best-path only */ |
1266 | metric = info->attr->med; | |
18ee8310 | 1267 | for (mpinfo = info; mpinfo; mpinfo = bgp_path_info_mpath_next(mpinfo)) { |
a74e593b RW |
1268 | if (valid_nh_count >= multipath_num) |
1269 | break; | |
1270 | ||
b4cb15c6 DL |
1271 | *mpinfo_cp = *mpinfo; |
1272 | ||
d0d695f4 RW |
1273 | /* Get nexthop address-family */ |
1274 | if (p->family == AF_INET | |
1275 | && !BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp->attr)) | |
1276 | nh_family = AF_INET; | |
1277 | else if (p->family == AF_INET6 | |
1278 | || (p->family == AF_INET | |
1279 | && BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp->attr))) | |
1280 | nh_family = AF_INET6; | |
1281 | else | |
1282 | continue; | |
1283 | ||
1374aec9 | 1284 | api_nh = &api.nexthops[valid_nh_count]; |
a12495e7 DS |
1285 | api_nh->vrf_id = nh_othervrf ? info->extra->bgp_orig->vrf_id |
1286 | : bgp->vrf_id; | |
2ad4f093 | 1287 | if (nh_family == AF_INET) { |
ddb5b488 | 1288 | if (bgp_debug_zebra(&api.prefix)) { |
ddb5b488 PZ |
1289 | if (mpinfo->extra) { |
1290 | zlog_debug( | |
1291 | "%s: p=%s, bgp_is_valid_label: %d", | |
1292 | __func__, buf_prefix, | |
1293 | bgp_is_valid_label( | |
1294 | &mpinfo->extra | |
1295 | ->label[0])); | |
1296 | } else { | |
1297 | zlog_debug( | |
1298 | "%s: p=%s, extra is NULL, no label", | |
1299 | __func__, buf_prefix); | |
1300 | } | |
1301 | } | |
1302 | ||
6c0a6053 | 1303 | if (bgp->table_map[afi][safi].name) { |
d62a17ae | 1304 | /* Copy info and attributes, so the route-map |
b4cb15c6 DL |
1305 | apply doesn't modify the BGP route info. */ |
1306 | local_attr = *mpinfo->attr; | |
1307 | mpinfo_cp->attr = &local_attr; | |
ddb5b488 | 1308 | } |
b4cb15c6 | 1309 | |
ddb5b488 | 1310 | if (bgp->table_map[afi][safi].name) { |
b4cb15c6 | 1311 | if (!bgp_table_map_apply( |
d62a17ae | 1312 | bgp->table_map[afi][safi].map, p, |
b4cb15c6 DL |
1313 | mpinfo_cp)) |
1314 | continue; | |
1315 | ||
1316 | /* metric/tag is only allowed to be | |
1317 | * overridden on 1st nexthop */ | |
1318 | if (mpinfo == info) { | |
1319 | metric = mpinfo_cp->attr->med; | |
1320 | tag = mpinfo_cp->attr->tag; | |
d62a17ae | 1321 | } |
b4cb15c6 | 1322 | } |
d62a17ae | 1323 | |
77e62f2b | 1324 | nh_updated = update_ipv4nh_for_route_install( |
1325 | nh_othervrf, | |
1326 | &mpinfo_cp->attr->nexthop, | |
1327 | mpinfo_cp->attr, is_evpn, api_nh); | |
2ad4f093 | 1328 | } else { |
f220da99 | 1329 | ifindex_t ifindex = IFINDEX_INTERNAL; |
2ad4f093 | 1330 | struct in6_addr *nexthop; |
9913029c | 1331 | |
6c0a6053 | 1332 | if (bgp->table_map[afi][safi].name) { |
ddb5b488 PZ |
1333 | /* Copy info and attributes, so the route-map |
1334 | apply doesn't modify the BGP route info. */ | |
1335 | local_attr = *mpinfo->attr; | |
1336 | mpinfo_cp->attr = &local_attr; | |
ddb5b488 PZ |
1337 | } |
1338 | ||
d62a17ae | 1339 | if (bgp->table_map[afi][safi].name) { |
1340 | /* Copy info and attributes, so the route-map | |
b4cb15c6 DL |
1341 | apply doesn't modify the BGP route info. */ |
1342 | local_attr = *mpinfo->attr; | |
1343 | mpinfo_cp->attr = &local_attr; | |
1344 | ||
1345 | if (!bgp_table_map_apply( | |
d62a17ae | 1346 | bgp->table_map[afi][safi].map, p, |
b4cb15c6 DL |
1347 | mpinfo_cp)) |
1348 | continue; | |
1349 | ||
1350 | /* metric/tag is only allowed to be | |
1351 | * overridden on 1st nexthop */ | |
1352 | if (mpinfo == info) { | |
1353 | metric = mpinfo_cp->attr->med; | |
1354 | tag = mpinfo_cp->attr->tag; | |
d62a17ae | 1355 | } |
b4cb15c6 | 1356 | } |
18ee8310 DS |
1357 | nexthop = bgp_path_info_to_ipv6_nexthop(mpinfo_cp, |
1358 | &ifindex); | |
77e62f2b | 1359 | nh_updated = update_ipv6nh_for_route_install( |
1360 | nh_othervrf, nexthop, ifindex, | |
1361 | mpinfo, info, is_evpn, api_nh); | |
2ad4f093 | 1362 | } |
d62a17ae | 1363 | |
77e62f2b | 1364 | /* Did we get proper nexthop info to update zebra? */ |
1365 | if (!nh_updated) | |
1366 | continue; | |
1367 | ||
a4d82a8a PZ |
1368 | if (mpinfo->extra |
1369 | && bgp_is_valid_label(&mpinfo->extra->label[0]) | |
90264d64 | 1370 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { |
2ad4f093 | 1371 | has_valid_label = 1; |
b57ba6d2 | 1372 | label = label_pton(&mpinfo->extra->label[0]); |
9913029c | 1373 | |
2ad4f093 RW |
1374 | api_nh->label_num = 1; |
1375 | api_nh->labels[0] = label; | |
d62a17ae | 1376 | } |
22e63104 | 1377 | memcpy(&api_nh->rmac, &(mpinfo->attr->rmac), |
1378 | sizeof(struct ethaddr)); | |
2ad4f093 RW |
1379 | valid_nh_count++; |
1380 | } | |
d62a17ae | 1381 | |
77e62f2b | 1382 | |
a89b49cc | 1383 | /* if this is a evpn route we don't have to include the label */ |
a4d82a8a | 1384 | if (has_valid_label && !(CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE))) |
2ad4f093 | 1385 | SET_FLAG(api.message, ZAPI_MESSAGE_LABEL); |
d62a17ae | 1386 | |
5cc347c4 DS |
1387 | /* |
1388 | * When we create an aggregate route we must also | |
1389 | * install a Null0 route in the RIB, so overwrite | |
1390 | * what was written into api with a blackhole route | |
1391 | */ | |
1392 | if (info->sub_type == BGP_ROUTE_AGGREGATE) | |
1393 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); | |
1394 | else | |
2ad4f093 | 1395 | api.nexthop_num = valid_nh_count; |
d62a17ae | 1396 | |
2ad4f093 RW |
1397 | SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); |
1398 | api.metric = metric; | |
d62a17ae | 1399 | |
2ad4f093 RW |
1400 | if (tag) { |
1401 | SET_FLAG(api.message, ZAPI_MESSAGE_TAG); | |
1402 | api.tag = tag; | |
1403 | } | |
d62a17ae | 1404 | |
2ad4f093 RW |
1405 | distance = bgp_distance_apply(p, info, afi, safi, bgp); |
1406 | if (distance) { | |
1407 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); | |
1408 | api.distance = distance; | |
1409 | } | |
d62a17ae | 1410 | |
2ad4f093 RW |
1411 | if (bgp_debug_zebra(p)) { |
1412 | char prefix_buf[PREFIX_STRLEN]; | |
1413 | char nh_buf[INET6_ADDRSTRLEN]; | |
1414 | char label_buf[20]; | |
1415 | int i; | |
1416 | ||
1417 | prefix2str(&api.prefix, prefix_buf, sizeof(prefix_buf)); | |
1418 | zlog_debug("Tx route %s VRF %u %s metric %u tag %" ROUTE_TAG_PRI | |
1419 | " count %d", | |
1420 | valid_nh_count ? "add" : "delete", bgp->vrf_id, | |
1421 | prefix_buf, api.metric, api.tag, api.nexthop_num); | |
1422 | for (i = 0; i < api.nexthop_num; i++) { | |
1423 | api_nh = &api.nexthops[i]; | |
1424 | ||
77e62f2b | 1425 | if (api_nh->type == NEXTHOP_TYPE_IFINDEX) |
1426 | nh_buf[0] = '\0'; | |
1427 | else { | |
1428 | if (api_nh->type == NEXTHOP_TYPE_IPV4) | |
1429 | nh_family = AF_INET; | |
1430 | else | |
1431 | nh_family = AF_INET6; | |
1432 | inet_ntop(nh_family, &api_nh->gate, nh_buf, | |
1433 | sizeof(nh_buf)); | |
1434 | } | |
2ad4f093 RW |
1435 | |
1436 | label_buf[0] = '\0'; | |
a4d82a8a PZ |
1437 | if (has_valid_label |
1438 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) | |
2ad4f093 RW |
1439 | sprintf(label_buf, "label %u", |
1440 | api_nh->labels[0]); | |
77e62f2b | 1441 | zlog_debug(" nhop [%d]: %s if %u VRF %u %s", |
1442 | i + 1, nh_buf, api_nh->ifindex, | |
1443 | api_nh->vrf_id, label_buf); | |
d62a17ae | 1444 | } |
1445 | } | |
2ad4f093 | 1446 | |
960035b2 PZ |
1447 | if (bgp_debug_zebra(p)) { |
1448 | int recursion_flag = 0; | |
1449 | ||
1450 | if (CHECK_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION)) | |
1451 | recursion_flag = 1; | |
1452 | ||
1453 | zlog_debug("%s: %s: announcing to zebra (recursion %sset)", | |
1454 | __func__, buf_prefix, | |
1455 | (recursion_flag ? "" : "NOT ")); | |
1456 | } | |
2ad4f093 RW |
1457 | zclient_route_send(valid_nh_count ? ZEBRA_ROUTE_ADD |
1458 | : ZEBRA_ROUTE_DELETE, | |
1459 | zclient, &api); | |
718e3744 | 1460 | } |
1461 | ||
73ac8160 | 1462 | /* Announce all routes of a table to zebra */ |
d62a17ae | 1463 | void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi) |
73ac8160 | 1464 | { |
d62a17ae | 1465 | struct bgp_node *rn; |
1466 | struct bgp_table *table; | |
40381db7 | 1467 | struct bgp_path_info *pi; |
d62a17ae | 1468 | |
1469 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't | |
1470 | * know of this instance. | |
1471 | */ | |
1472 | if (!bgp_install_info_to_zebra(bgp)) | |
1473 | return; | |
1474 | ||
1475 | table = bgp->rib[afi][safi]; | |
1476 | if (!table) | |
1477 | return; | |
1478 | ||
1479 | for (rn = bgp_table_top(table); rn; rn = bgp_route_next(rn)) | |
40381db7 DS |
1480 | for (pi = rn->info; pi; pi = pi->next) |
1481 | if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && | |
ddb5b488 | 1482 | |
40381db7 DS |
1483 | (pi->type == ZEBRA_ROUTE_BGP |
1484 | && (pi->sub_type == BGP_ROUTE_NORMAL | |
1485 | || pi->sub_type == BGP_ROUTE_IMPORTED))) | |
ddb5b488 | 1486 | |
40381db7 | 1487 | bgp_zebra_announce(rn, &rn->p, pi, bgp, afi, |
d62a17ae | 1488 | safi); |
73ac8160 DS |
1489 | } |
1490 | ||
4b7e6066 | 1491 | void bgp_zebra_withdraw(struct prefix *p, struct bgp_path_info *info, |
568e10ca | 1492 | struct bgp *bgp, safi_t safi) |
718e3744 | 1493 | { |
2ad4f093 | 1494 | struct zapi_route api; |
f7df1907 | 1495 | struct peer *peer; |
ddb5b488 | 1496 | |
d62a17ae | 1497 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't |
1498 | * know of this instance. | |
1499 | */ | |
568e10ca | 1500 | if (!bgp_install_info_to_zebra(bgp)) |
d62a17ae | 1501 | return; |
1502 | ||
f7df1907 PG |
1503 | if (safi == SAFI_FLOWSPEC) { |
1504 | peer = info->peer; | |
529efa23 PG |
1505 | return bgp_pbr_update_entry(peer->bgp, p, |
1506 | info, AFI_IP, safi, false); | |
f7df1907 | 1507 | } |
529efa23 | 1508 | |
2ad4f093 | 1509 | memset(&api, 0, sizeof(api)); |
568e10ca | 1510 | api.vrf_id = bgp->vrf_id; |
2ad4f093 RW |
1511 | api.type = ZEBRA_ROUTE_BGP; |
1512 | api.safi = safi; | |
1513 | api.prefix = *p; | |
d62a17ae | 1514 | |
88493076 | 1515 | /* If the route's source is EVPN, flag as such. */ |
1516 | if (is_route_parent_evpn(info)) | |
90264d64 | 1517 | SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); |
01740ff4 | 1518 | |
2ad4f093 RW |
1519 | if (bgp_debug_zebra(p)) { |
1520 | char buf[PREFIX_STRLEN]; | |
d62a17ae | 1521 | |
2ad4f093 | 1522 | prefix2str(&api.prefix, buf, sizeof(buf)); |
568e10ca | 1523 | zlog_debug("Tx route delete VRF %u %s", bgp->vrf_id, buf); |
d62a17ae | 1524 | } |
d62a17ae | 1525 | |
2ad4f093 | 1526 | zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
718e3744 | 1527 | } |
56c1f7d8 | 1528 | |
d7c0a89a QY |
1529 | struct bgp_redist *bgp_redist_lookup(struct bgp *bgp, afi_t afi, uint8_t type, |
1530 | unsigned short instance) | |
7c8ff89e | 1531 | { |
d62a17ae | 1532 | struct list *red_list; |
1533 | struct listnode *node; | |
1534 | struct bgp_redist *red; | |
7c8ff89e | 1535 | |
d62a17ae | 1536 | red_list = bgp->redist[afi][type]; |
1537 | if (!red_list) | |
1538 | return (NULL); | |
7c8ff89e | 1539 | |
d62a17ae | 1540 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) |
1541 | if (red->instance == instance) | |
1542 | return red; | |
7c8ff89e | 1543 | |
d62a17ae | 1544 | return NULL; |
7c8ff89e DS |
1545 | } |
1546 | ||
d7c0a89a QY |
1547 | struct bgp_redist *bgp_redist_add(struct bgp *bgp, afi_t afi, uint8_t type, |
1548 | unsigned short instance) | |
7c8ff89e | 1549 | { |
d62a17ae | 1550 | struct list *red_list; |
1551 | struct bgp_redist *red; | |
7c8ff89e | 1552 | |
d62a17ae | 1553 | red = bgp_redist_lookup(bgp, afi, type, instance); |
1554 | if (red) | |
1555 | return red; | |
7c8ff89e | 1556 | |
d62a17ae | 1557 | if (!bgp->redist[afi][type]) |
1558 | bgp->redist[afi][type] = list_new(); | |
7c8ff89e | 1559 | |
d62a17ae | 1560 | red_list = bgp->redist[afi][type]; |
1561 | red = (struct bgp_redist *)XCALLOC(MTYPE_BGP_REDIST, | |
1562 | sizeof(struct bgp_redist)); | |
1563 | red->instance = instance; | |
7c8ff89e | 1564 | |
d62a17ae | 1565 | listnode_add(red_list, red); |
7c8ff89e | 1566 | |
d62a17ae | 1567 | return red; |
7c8ff89e DS |
1568 | } |
1569 | ||
d7c0a89a QY |
1570 | static void bgp_redist_del(struct bgp *bgp, afi_t afi, uint8_t type, |
1571 | unsigned short instance) | |
7c8ff89e | 1572 | { |
d62a17ae | 1573 | struct bgp_redist *red; |
1574 | ||
1575 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
1576 | ||
1577 | if (red) { | |
1578 | listnode_delete(bgp->redist[afi][type], red); | |
1579 | XFREE(MTYPE_BGP_REDIST, red); | |
acdf5e25 | 1580 | if (!bgp->redist[afi][type]->count) |
6a154c88 | 1581 | list_delete(&bgp->redist[afi][type]); |
d62a17ae | 1582 | } |
7c8ff89e | 1583 | } |
6b0655a2 | 1584 | |
718e3744 | 1585 | /* Other routes redistribution into BGP. */ |
d7c0a89a | 1586 | int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, |
e923dd62 | 1587 | unsigned short instance, bool changed) |
718e3744 | 1588 | { |
e923dd62 | 1589 | /* If redistribute options are changed call |
1590 | * bgp_redistribute_unreg() to reset the option and withdraw | |
1591 | * the routes | |
1592 | */ | |
1593 | if (changed) | |
1594 | bgp_redistribute_unreg(bgp, afi, type, instance); | |
718e3744 | 1595 | |
d62a17ae | 1596 | /* Return if already redistribute flag is set. */ |
1597 | if (instance) { | |
1598 | if (redist_check_instance(&zclient->mi_redist[afi][type], | |
1599 | instance)) | |
1600 | return CMD_WARNING; | |
718e3744 | 1601 | |
d62a17ae | 1602 | redist_add_instance(&zclient->mi_redist[afi][type], instance); |
1603 | } else { | |
1604 | if (vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) | |
1605 | return CMD_WARNING; | |
7076bb2f | 1606 | |
65efcfce | 1607 | #if ENABLE_BGP_VNC |
d62a17ae | 1608 | if (bgp->vrf_id == VRF_DEFAULT |
1609 | && type == ZEBRA_ROUTE_VNC_DIRECT) { | |
1610 | vnc_export_bgp_enable( | |
1611 | bgp, afi); /* only enables if mode bits cfg'd */ | |
1612 | } | |
65efcfce LB |
1613 | #endif |
1614 | ||
d62a17ae | 1615 | vrf_bitmap_set(zclient->redist[afi][type], bgp->vrf_id); |
1616 | } | |
718e3744 | 1617 | |
ea12cf11 DS |
1618 | /* |
1619 | * Don't try to register if we're not connected to Zebra or Zebra | |
1620 | * doesn't know of this instance. | |
1621 | * | |
1622 | * When we come up later well resend if needed. | |
d62a17ae | 1623 | */ |
1624 | if (!bgp_install_info_to_zebra(bgp)) | |
ea12cf11 | 1625 | return CMD_SUCCESS; |
a39275d7 | 1626 | |
d62a17ae | 1627 | if (BGP_DEBUG(zebra, ZEBRA)) |
1628 | zlog_debug("Tx redistribute add VRF %u afi %d %s %d", | |
1629 | bgp->vrf_id, afi, zebra_route_string(type), | |
1630 | instance); | |
518f0eb1 | 1631 | |
d62a17ae | 1632 | /* Send distribute add message to zebra. */ |
1633 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, | |
1634 | instance, bgp->vrf_id); | |
718e3744 | 1635 | |
d62a17ae | 1636 | return CMD_SUCCESS; |
718e3744 | 1637 | } |
1638 | ||
d62a17ae | 1639 | int bgp_redistribute_resend(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1640 | unsigned short instance) |
518f0eb1 | 1641 | { |
d62a17ae | 1642 | /* Don't try to send if we're not connected to Zebra or Zebra doesn't |
1643 | * know of this instance. | |
1644 | */ | |
1645 | if (!bgp_install_info_to_zebra(bgp)) | |
1646 | return -1; | |
1647 | ||
1648 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1649 | zlog_debug("Tx redistribute del/add VRF %u afi %d %s %d", | |
1650 | bgp->vrf_id, afi, zebra_route_string(type), | |
1651 | instance); | |
1652 | ||
1653 | /* Send distribute add message to zebra. */ | |
1654 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, | |
1655 | instance, bgp->vrf_id); | |
1656 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, | |
1657 | instance, bgp->vrf_id); | |
1658 | ||
1659 | return 0; | |
518f0eb1 DS |
1660 | } |
1661 | ||
718e3744 | 1662 | /* Redistribute with route-map specification. */ |
d62a17ae | 1663 | int bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name) |
718e3744 | 1664 | { |
d62a17ae | 1665 | if (red->rmap.name && (strcmp(red->rmap.name, name) == 0)) |
1666 | return 0; | |
718e3744 | 1667 | |
d62a17ae | 1668 | if (red->rmap.name) |
1669 | XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name); | |
1670 | red->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, name); | |
1671 | red->rmap.map = route_map_lookup_by_name(name); | |
718e3744 | 1672 | |
d62a17ae | 1673 | return 1; |
718e3744 | 1674 | } |
1675 | ||
1676 | /* Redistribute with metric specification. */ | |
d62a17ae | 1677 | int bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, |
d7c0a89a | 1678 | afi_t afi, int type, uint32_t metric) |
718e3744 | 1679 | { |
d62a17ae | 1680 | struct bgp_node *rn; |
40381db7 | 1681 | struct bgp_path_info *pi; |
d62a17ae | 1682 | |
1683 | if (red->redist_metric_flag && red->redist_metric == metric) | |
1684 | return 0; | |
1685 | ||
1686 | red->redist_metric_flag = 1; | |
1687 | red->redist_metric = metric; | |
1688 | ||
1689 | for (rn = bgp_table_top(bgp->rib[afi][SAFI_UNICAST]); rn; | |
1690 | rn = bgp_route_next(rn)) { | |
40381db7 DS |
1691 | for (pi = rn->info; pi; pi = pi->next) { |
1692 | if (pi->sub_type == BGP_ROUTE_REDISTRIBUTE | |
1693 | && pi->type == type | |
1694 | && pi->instance == red->instance) { | |
d62a17ae | 1695 | struct attr *old_attr; |
1696 | struct attr new_attr; | |
1697 | ||
40381db7 | 1698 | bgp_attr_dup(&new_attr, pi->attr); |
d62a17ae | 1699 | new_attr.med = red->redist_metric; |
40381db7 DS |
1700 | old_attr = pi->attr; |
1701 | pi->attr = bgp_attr_intern(&new_attr); | |
d62a17ae | 1702 | bgp_attr_unintern(&old_attr); |
1703 | ||
40381db7 | 1704 | bgp_path_info_set_flag(rn, pi, |
18ee8310 | 1705 | BGP_PATH_ATTR_CHANGED); |
d62a17ae | 1706 | bgp_process(bgp, rn, afi, SAFI_UNICAST); |
1707 | } | |
1708 | } | |
1709 | } | |
1710 | ||
1711 | return 1; | |
718e3744 | 1712 | } |
1713 | ||
1714 | /* Unset redistribution. */ | |
d62a17ae | 1715 | int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1716 | unsigned short instance) |
718e3744 | 1717 | { |
d62a17ae | 1718 | struct bgp_redist *red; |
1719 | ||
1720 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
1721 | if (!red) | |
1722 | return CMD_SUCCESS; | |
1723 | ||
1724 | /* Return if zebra connection is disabled. */ | |
1725 | if (instance) { | |
1726 | if (!redist_check_instance(&zclient->mi_redist[afi][type], | |
1727 | instance)) | |
1728 | return CMD_WARNING; | |
1729 | redist_del_instance(&zclient->mi_redist[afi][type], instance); | |
1730 | } else { | |
1731 | if (!vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) | |
1732 | return CMD_WARNING; | |
1733 | vrf_bitmap_unset(zclient->redist[afi][type], bgp->vrf_id); | |
1734 | } | |
718e3744 | 1735 | |
65efcfce | 1736 | |
d62a17ae | 1737 | if (bgp_install_info_to_zebra(bgp)) { |
1738 | /* Send distribute delete message to zebra. */ | |
1739 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1740 | zlog_debug("Tx redistribute del VRF %u afi %d %s %d", | |
1741 | bgp->vrf_id, afi, zebra_route_string(type), | |
1742 | instance); | |
1743 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, | |
1744 | type, instance, bgp->vrf_id); | |
1745 | } | |
1746 | ||
1747 | /* Withdraw redistributed routes from current BGP's routing table. */ | |
1748 | bgp_redistribute_withdraw(bgp, afi, type, instance); | |
1749 | ||
1750 | return CMD_SUCCESS; | |
718e3744 | 1751 | } |
1752 | ||
6aeb9e78 | 1753 | /* Unset redistribution. */ |
d62a17ae | 1754 | int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1755 | unsigned short instance) |
6aeb9e78 | 1756 | { |
d62a17ae | 1757 | struct bgp_redist *red; |
6aeb9e78 | 1758 | |
ddb5b488 PZ |
1759 | /* |
1760 | * vnc and vpn->vrf checks must be before red check because | |
1761 | * they operate within bgpd irrespective of zebra connection | |
1762 | * status. red lookup fails if there is no zebra connection. | |
1763 | */ | |
1764 | #if ENABLE_BGP_VNC | |
1765 | if (bgp->vrf_id == VRF_DEFAULT && type == ZEBRA_ROUTE_VNC_DIRECT) { | |
1766 | vnc_export_bgp_disable(bgp, afi); | |
1767 | } | |
1768 | #endif | |
ddb5b488 | 1769 | |
d62a17ae | 1770 | red = bgp_redist_lookup(bgp, afi, type, instance); |
1771 | if (!red) | |
1772 | return CMD_SUCCESS; | |
6aeb9e78 | 1773 | |
d62a17ae | 1774 | bgp_redistribute_unreg(bgp, afi, type, instance); |
6aeb9e78 | 1775 | |
d62a17ae | 1776 | /* Unset route-map. */ |
1777 | if (red->rmap.name) | |
1778 | XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name); | |
1779 | red->rmap.name = NULL; | |
1780 | red->rmap.map = NULL; | |
6aeb9e78 | 1781 | |
d62a17ae | 1782 | /* Unset metric. */ |
1783 | red->redist_metric_flag = 0; | |
1784 | red->redist_metric = 0; | |
6aeb9e78 | 1785 | |
d62a17ae | 1786 | bgp_redist_del(bgp, afi, type, instance); |
6aeb9e78 | 1787 | |
d62a17ae | 1788 | return CMD_SUCCESS; |
6aeb9e78 DS |
1789 | } |
1790 | ||
eb117f29 SK |
1791 | /* Update redistribute vrf bitmap during triggers like |
1792 | restart networking or delete/add VRFs */ | |
d62a17ae | 1793 | void bgp_update_redist_vrf_bitmaps(struct bgp *bgp, vrf_id_t old_vrf_id) |
eb117f29 | 1794 | { |
d62a17ae | 1795 | int i; |
1796 | afi_t afi; | |
1797 | ||
1798 | for (afi = AFI_IP; afi < AFI_MAX; afi++) | |
1799 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) | |
48c74f88 DS |
1800 | if ((old_vrf_id == VRF_UNKNOWN) |
1801 | || vrf_bitmap_check(zclient->redist[afi][i], | |
1802 | old_vrf_id)) { | |
d62a17ae | 1803 | vrf_bitmap_unset(zclient->redist[afi][i], |
1804 | old_vrf_id); | |
1805 | vrf_bitmap_set(zclient->redist[afi][i], | |
1806 | bgp->vrf_id); | |
1807 | } | |
1808 | return; | |
eb117f29 SK |
1809 | } |
1810 | ||
d62a17ae | 1811 | void bgp_zclient_reset(void) |
718e3744 | 1812 | { |
d62a17ae | 1813 | zclient_reset(zclient); |
718e3744 | 1814 | } |
1815 | ||
ad4cbda1 | 1816 | /* Register this instance with Zebra. Invoked upon connect (for |
1817 | * default instance) and when other VRFs are learnt (or created and | |
1818 | * already learnt). | |
1819 | */ | |
d62a17ae | 1820 | void bgp_zebra_instance_register(struct bgp *bgp) |
ad4cbda1 | 1821 | { |
d62a17ae | 1822 | /* Don't try to register if we're not connected to Zebra */ |
1823 | if (!zclient || zclient->sock < 0) | |
1824 | return; | |
ad4cbda1 | 1825 | |
d62a17ae | 1826 | if (BGP_DEBUG(zebra, ZEBRA)) |
1827 | zlog_debug("Registering VRF %u", bgp->vrf_id); | |
ad4cbda1 | 1828 | |
d62a17ae | 1829 | /* Register for router-id, interfaces, redistributed routes. */ |
1830 | zclient_send_reg_requests(zclient, bgp->vrf_id); | |
7724c0a1 | 1831 | |
d62a17ae | 1832 | /* For default instance, register to learn about VNIs, if appropriate. |
1833 | */ | |
a4d82a8a | 1834 | if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT && is_evpn_enabled()) |
d62a17ae | 1835 | bgp_zebra_advertise_all_vni(bgp, 1); |
ad4cbda1 | 1836 | } |
1837 | ||
1838 | /* Deregister this instance with Zebra. Invoked upon the instance | |
1839 | * being deleted (default or VRF) and it is already registered. | |
1840 | */ | |
d62a17ae | 1841 | void bgp_zebra_instance_deregister(struct bgp *bgp) |
ad4cbda1 | 1842 | { |
d62a17ae | 1843 | /* Don't try to deregister if we're not connected to Zebra */ |
1844 | if (zclient->sock < 0) | |
1845 | return; | |
ad4cbda1 | 1846 | |
d62a17ae | 1847 | if (BGP_DEBUG(zebra, ZEBRA)) |
1848 | zlog_debug("Deregistering VRF %u", bgp->vrf_id); | |
ad4cbda1 | 1849 | |
d62a17ae | 1850 | /* For default instance, unregister learning about VNIs, if appropriate. |
1851 | */ | |
a4d82a8a | 1852 | if (bgp->inst_type == BGP_INSTANCE_TYPE_DEFAULT && is_evpn_enabled()) |
d62a17ae | 1853 | bgp_zebra_advertise_all_vni(bgp, 0); |
7724c0a1 | 1854 | |
d62a17ae | 1855 | /* Deregister for router-id, interfaces, redistributed routes. */ |
1856 | zclient_send_dereg_requests(zclient, bgp->vrf_id); | |
ad4cbda1 | 1857 | } |
1858 | ||
d62a17ae | 1859 | void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer) |
4a04e5f7 | 1860 | { |
d62a17ae | 1861 | int ra_interval = BGP_UNNUM_DEFAULT_RA_INTERVAL; |
5c81b96a | 1862 | |
d62a17ae | 1863 | /* Don't try to initiate if we're not connected to Zebra */ |
1864 | if (zclient->sock < 0) | |
1865 | return; | |
4a04e5f7 | 1866 | |
d62a17ae | 1867 | if (BGP_DEBUG(zebra, ZEBRA)) |
1868 | zlog_debug("%u: Initiating RA for peer %s", bgp->vrf_id, | |
1869 | peer->host); | |
4a04e5f7 | 1870 | |
d62a17ae | 1871 | zclient_send_interface_radv_req(zclient, bgp->vrf_id, peer->ifp, 1, |
1872 | ra_interval); | |
4a04e5f7 | 1873 | } |
1874 | ||
d62a17ae | 1875 | void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer) |
4a04e5f7 | 1876 | { |
d62a17ae | 1877 | /* Don't try to terminate if we're not connected to Zebra */ |
1878 | if (zclient->sock < 0) | |
1879 | return; | |
4a04e5f7 | 1880 | |
d62a17ae | 1881 | if (BGP_DEBUG(zebra, ZEBRA)) |
1882 | zlog_debug("%u: Terminating RA for peer %s", bgp->vrf_id, | |
1883 | peer->host); | |
4a04e5f7 | 1884 | |
d62a17ae | 1885 | zclient_send_interface_radv_req(zclient, bgp->vrf_id, peer->ifp, 0, 0); |
4a04e5f7 | 1886 | } |
1887 | ||
31310b25 MK |
1888 | int bgp_zebra_advertise_subnet(struct bgp *bgp, int advertise, vni_t vni) |
1889 | { | |
1890 | struct stream *s = NULL; | |
1891 | ||
1892 | /* Check socket. */ | |
1893 | if (!zclient || zclient->sock < 0) | |
1894 | return 0; | |
1895 | ||
1896 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
1897 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
1898 | return 0; | |
1899 | ||
1900 | s = zclient->obuf; | |
1901 | stream_reset(s); | |
1902 | ||
1903 | zclient_create_header(s, ZEBRA_ADVERTISE_SUBNET, bgp->vrf_id); | |
1904 | stream_putc(s, advertise); | |
1905 | stream_put3(s, vni); | |
1906 | stream_putw_at(s, 0, stream_get_endp(s)); | |
1907 | ||
1908 | return zclient_send_message(zclient); | |
1909 | } | |
1910 | ||
1a98c087 MK |
1911 | int bgp_zebra_advertise_gw_macip(struct bgp *bgp, int advertise, vni_t vni) |
1912 | { | |
1913 | struct stream *s = NULL; | |
1914 | ||
1915 | /* Check socket. */ | |
1916 | if (!zclient || zclient->sock < 0) | |
1917 | return 0; | |
1918 | ||
1919 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
1920 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
1921 | return 0; | |
1922 | ||
1923 | s = zclient->obuf; | |
1924 | stream_reset(s); | |
1925 | ||
1926 | zclient_create_header(s, ZEBRA_ADVERTISE_DEFAULT_GW, bgp->vrf_id); | |
1927 | stream_putc(s, advertise); | |
cc6d5476 | 1928 | stream_putl(s, vni); |
1a98c087 MK |
1929 | stream_putw_at(s, 0, stream_get_endp(s)); |
1930 | ||
1931 | return zclient_send_message(zclient); | |
1932 | } | |
1933 | ||
d62a17ae | 1934 | int bgp_zebra_advertise_all_vni(struct bgp *bgp, int advertise) |
7724c0a1 | 1935 | { |
d62a17ae | 1936 | struct stream *s; |
7724c0a1 | 1937 | |
d62a17ae | 1938 | /* Check socket. */ |
1939 | if (!zclient || zclient->sock < 0) | |
1940 | return 0; | |
7724c0a1 | 1941 | |
d62a17ae | 1942 | /* Don't try to register if Zebra doesn't know of this instance. */ |
1943 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
1944 | return 0; | |
7724c0a1 | 1945 | |
d62a17ae | 1946 | s = zclient->obuf; |
1947 | stream_reset(s); | |
7724c0a1 | 1948 | |
d62a17ae | 1949 | zclient_create_header(s, ZEBRA_ADVERTISE_ALL_VNI, bgp->vrf_id); |
1950 | stream_putc(s, advertise); | |
1951 | stream_putw_at(s, 0, stream_get_endp(s)); | |
7724c0a1 | 1952 | |
d62a17ae | 1953 | return zclient_send_message(zclient); |
7724c0a1 | 1954 | } |
1955 | ||
30d50e6d PG |
1956 | static int rule_notify_owner(int command, struct zclient *zclient, |
1957 | zebra_size_t length, vrf_id_t vrf_id) | |
1958 | { | |
1959 | uint32_t seqno, priority, unique; | |
1960 | enum zapi_rule_notify_owner note; | |
1961 | struct bgp_pbr_action *bgp_pbra; | |
1962 | ifindex_t ifi; | |
1963 | ||
1964 | if (!zapi_rule_notify_decode(zclient->ibuf, &seqno, &priority, &unique, | |
1965 | &ifi, ¬e)) | |
1966 | return -1; | |
1967 | ||
70eabd12 | 1968 | bgp_pbra = bgp_pbr_action_rule_lookup(vrf_id, unique); |
30d50e6d PG |
1969 | if (!bgp_pbra) { |
1970 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1971 | zlog_debug("%s: Fail to look BGP rule (%u)", | |
1972 | __PRETTY_FUNCTION__, unique); | |
1973 | return 0; | |
1974 | } | |
1975 | ||
1976 | switch (note) { | |
1977 | case ZAPI_RULE_FAIL_INSTALL: | |
1978 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1979 | zlog_debug("%s: Received RULE_FAIL_INSTALL", | |
1980 | __PRETTY_FUNCTION__); | |
1981 | bgp_pbra->installed = false; | |
1982 | bgp_pbra->install_in_progress = false; | |
1983 | break; | |
1984 | case ZAPI_RULE_INSTALLED: | |
1985 | bgp_pbra->installed = true; | |
1986 | bgp_pbra->install_in_progress = false; | |
1987 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1988 | zlog_debug("%s: Received RULE_INSTALLED", | |
1989 | __PRETTY_FUNCTION__); | |
1990 | break; | |
f18a08f5 | 1991 | case ZAPI_RULE_FAIL_REMOVE: |
30d50e6d PG |
1992 | case ZAPI_RULE_REMOVED: |
1993 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1994 | zlog_debug("%s: Received RULE REMOVED", | |
1995 | __PRETTY_FUNCTION__); | |
1996 | break; | |
1997 | } | |
1998 | ||
1999 | return 0; | |
2000 | } | |
2001 | ||
2002 | static int ipset_notify_owner(int command, struct zclient *zclient, | |
2003 | zebra_size_t length, vrf_id_t vrf_id) | |
2004 | { | |
2005 | uint32_t unique; | |
2006 | enum zapi_ipset_notify_owner note; | |
2007 | struct bgp_pbr_match *bgp_pbim; | |
2008 | ||
2009 | if (!zapi_ipset_notify_decode(zclient->ibuf, | |
2010 | &unique, | |
2011 | ¬e)) | |
2012 | return -1; | |
2013 | ||
2014 | bgp_pbim = bgp_pbr_match_ipset_lookup(vrf_id, unique); | |
2015 | if (!bgp_pbim) { | |
2016 | if (BGP_DEBUG(zebra, ZEBRA)) | |
88055124 | 2017 | zlog_debug("%s: Fail to look BGP match ( %u, ID %u)", |
82e194ed | 2018 | __PRETTY_FUNCTION__, note, unique); |
30d50e6d PG |
2019 | return 0; |
2020 | } | |
2021 | ||
2022 | switch (note) { | |
2023 | case ZAPI_IPSET_FAIL_INSTALL: | |
2024 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2025 | zlog_debug("%s: Received IPSET_FAIL_INSTALL", | |
2026 | __PRETTY_FUNCTION__); | |
2027 | bgp_pbim->installed = false; | |
2028 | bgp_pbim->install_in_progress = false; | |
2029 | break; | |
2030 | case ZAPI_IPSET_INSTALLED: | |
2031 | bgp_pbim->installed = true; | |
2032 | bgp_pbim->install_in_progress = false; | |
2033 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2034 | zlog_debug("%s: Received IPSET_INSTALLED", | |
2035 | __PRETTY_FUNCTION__); | |
2036 | break; | |
f18a08f5 | 2037 | case ZAPI_IPSET_FAIL_REMOVE: |
30d50e6d PG |
2038 | case ZAPI_IPSET_REMOVED: |
2039 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2040 | zlog_debug("%s: Received IPSET REMOVED", | |
2041 | __PRETTY_FUNCTION__); | |
2042 | break; | |
2043 | } | |
2044 | ||
2045 | return 0; | |
2046 | } | |
2047 | ||
2048 | static int ipset_entry_notify_owner(int command, struct zclient *zclient, | |
2049 | zebra_size_t length, vrf_id_t vrf_id) | |
2050 | { | |
2051 | uint32_t unique; | |
2052 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; | |
2053 | enum zapi_ipset_entry_notify_owner note; | |
2054 | struct bgp_pbr_match_entry *bgp_pbime; | |
2055 | ||
2056 | if (!zapi_ipset_entry_notify_decode( | |
2057 | zclient->ibuf, | |
2058 | &unique, | |
2059 | ipset_name, | |
2060 | ¬e)) | |
2061 | return -1; | |
2062 | bgp_pbime = bgp_pbr_match_ipset_entry_lookup(vrf_id, | |
2063 | ipset_name, | |
2064 | unique); | |
2065 | if (!bgp_pbime) { | |
2066 | if (BGP_DEBUG(zebra, ZEBRA)) | |
88055124 | 2067 | zlog_debug("%s: Fail to look BGP match entry (%u, ID %u)", |
82e194ed | 2068 | __PRETTY_FUNCTION__, note, unique); |
30d50e6d PG |
2069 | return 0; |
2070 | } | |
2071 | ||
2072 | switch (note) { | |
2073 | case ZAPI_IPSET_ENTRY_FAIL_INSTALL: | |
2074 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2075 | zlog_debug("%s: Received IPSET_ENTRY_FAIL_INSTALL", | |
2076 | __PRETTY_FUNCTION__); | |
2077 | bgp_pbime->installed = false; | |
2078 | bgp_pbime->install_in_progress = false; | |
2079 | break; | |
2080 | case ZAPI_IPSET_ENTRY_INSTALLED: | |
b588b642 | 2081 | { |
9b6d8fcf | 2082 | struct bgp_path_info *path; |
4b7e6066 DS |
2083 | struct bgp_path_info_extra *extra; |
2084 | ||
2085 | bgp_pbime->installed = true; | |
2086 | bgp_pbime->install_in_progress = false; | |
2087 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2088 | zlog_debug("%s: Received IPSET_ENTRY_INSTALLED", | |
2089 | __PRETTY_FUNCTION__); | |
9b6d8fcf DS |
2090 | /* link bgp_path_info to bpme */ |
2091 | path = (struct bgp_path_info *)bgp_pbime->path; | |
2092 | extra = bgp_path_info_extra_get(path); | |
4b7e6066 DS |
2093 | if (extra->bgp_fs_pbr == NULL) |
2094 | extra->bgp_fs_pbr = list_new(); | |
2095 | listnode_add(extra->bgp_fs_pbr, bgp_pbime); | |
b588b642 | 2096 | } |
30d50e6d | 2097 | break; |
f18a08f5 | 2098 | case ZAPI_IPSET_ENTRY_FAIL_REMOVE: |
30d50e6d PG |
2099 | case ZAPI_IPSET_ENTRY_REMOVED: |
2100 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2101 | zlog_debug("%s: Received IPSET_ENTRY_REMOVED", | |
2102 | __PRETTY_FUNCTION__); | |
2103 | break; | |
2104 | } | |
2105 | return 0; | |
2106 | } | |
2107 | ||
c16a0a62 PG |
2108 | static int iptable_notify_owner(int command, struct zclient *zclient, |
2109 | zebra_size_t length, vrf_id_t vrf_id) | |
2110 | { | |
2111 | uint32_t unique; | |
2112 | enum zapi_iptable_notify_owner note; | |
2113 | struct bgp_pbr_match *bgpm; | |
2114 | ||
2115 | if (!zapi_iptable_notify_decode( | |
2116 | zclient->ibuf, | |
2117 | &unique, | |
2118 | ¬e)) | |
2119 | return -1; | |
2120 | bgpm = bgp_pbr_match_iptable_lookup(vrf_id, unique); | |
2121 | if (!bgpm) { | |
2122 | if (BGP_DEBUG(zebra, ZEBRA)) | |
82e194ed PG |
2123 | zlog_debug("%s: Fail to look BGP iptable (%u %u)", |
2124 | __PRETTY_FUNCTION__, note, unique); | |
c16a0a62 PG |
2125 | return 0; |
2126 | } | |
2127 | switch (note) { | |
2128 | case ZAPI_IPTABLE_FAIL_INSTALL: | |
2129 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2130 | zlog_debug("%s: Received IPTABLE_FAIL_INSTALL", | |
2131 | __PRETTY_FUNCTION__); | |
2132 | bgpm->installed_in_iptable = false; | |
2133 | bgpm->install_iptable_in_progress = false; | |
2134 | break; | |
2135 | case ZAPI_IPTABLE_INSTALLED: | |
2136 | bgpm->installed_in_iptable = true; | |
2137 | bgpm->install_iptable_in_progress = false; | |
2138 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2139 | zlog_debug("%s: Received IPTABLE_INSTALLED", | |
2140 | __PRETTY_FUNCTION__); | |
a6b07429 | 2141 | bgpm->action->refcnt++; |
c16a0a62 | 2142 | break; |
f18a08f5 | 2143 | case ZAPI_IPTABLE_FAIL_REMOVE: |
c16a0a62 PG |
2144 | case ZAPI_IPTABLE_REMOVED: |
2145 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2146 | zlog_debug("%s: Received IPTABLE REMOVED", | |
2147 | __PRETTY_FUNCTION__); | |
2148 | break; | |
2149 | } | |
2150 | return 0; | |
2151 | } | |
2152 | ||
30d50e6d PG |
2153 | static void bgp_encode_pbr_rule_action(struct stream *s, |
2154 | struct bgp_pbr_action *pbra) | |
2155 | { | |
2156 | struct prefix any; | |
2157 | ||
2158 | stream_putl(s, 0); /* seqno unused */ | |
2159 | stream_putl(s, 0); /* ruleno unused */ | |
2160 | ||
2161 | stream_putl(s, pbra->unique); | |
2162 | ||
2163 | memset(&any, 0, sizeof(any)); | |
2164 | any.family = AF_INET; | |
2165 | stream_putc(s, any.family); | |
2166 | stream_putc(s, any.prefixlen); | |
2167 | stream_put(s, &any.u.prefix, prefix_blen(&any)); | |
2168 | ||
2169 | stream_putw(s, 0); /* src port */ | |
2170 | ||
2171 | stream_putc(s, any.family); | |
2172 | stream_putc(s, any.prefixlen); | |
2173 | stream_put(s, &any.u.prefix, prefix_blen(&any)); | |
2174 | ||
2175 | stream_putw(s, 0); /* dst port */ | |
2176 | ||
2177 | stream_putl(s, pbra->fwmark); /* fwmark */ | |
2178 | ||
2179 | stream_putl(s, pbra->table_id); | |
2180 | ||
2181 | stream_putl(s, 0); /* ifindex unused */ | |
2182 | } | |
2183 | ||
2184 | static void bgp_encode_pbr_ipset_match(struct stream *s, | |
2185 | struct bgp_pbr_match *pbim) | |
2186 | { | |
2187 | stream_putl(s, pbim->unique); | |
2188 | stream_putl(s, pbim->type); | |
2189 | ||
2190 | stream_put(s, pbim->ipset_name, | |
2191 | ZEBRA_IPSET_NAME_SIZE); | |
30d50e6d PG |
2192 | } |
2193 | ||
2194 | static void bgp_encode_pbr_ipset_entry_match(struct stream *s, | |
2195 | struct bgp_pbr_match_entry *pbime) | |
2196 | { | |
2197 | stream_putl(s, pbime->unique); | |
2198 | /* check that back pointer is not null */ | |
2199 | stream_put(s, pbime->backpointer->ipset_name, | |
2200 | ZEBRA_IPSET_NAME_SIZE); | |
2201 | ||
2202 | stream_putc(s, pbime->src.family); | |
2203 | stream_putc(s, pbime->src.prefixlen); | |
2204 | stream_put(s, &pbime->src.u.prefix, prefix_blen(&pbime->src)); | |
2205 | ||
2206 | stream_putc(s, pbime->dst.family); | |
2207 | stream_putc(s, pbime->dst.prefixlen); | |
2208 | stream_put(s, &pbime->dst.u.prefix, prefix_blen(&pbime->dst)); | |
f730e566 PG |
2209 | |
2210 | stream_putw(s, pbime->src_port_min); | |
2211 | stream_putw(s, pbime->src_port_max); | |
2212 | stream_putw(s, pbime->dst_port_min); | |
2213 | stream_putw(s, pbime->dst_port_max); | |
2214 | stream_putc(s, pbime->proto); | |
30d50e6d PG |
2215 | } |
2216 | ||
c16a0a62 PG |
2217 | static void bgp_encode_pbr_iptable_match(struct stream *s, |
2218 | struct bgp_pbr_action *bpa, | |
2219 | struct bgp_pbr_match *pbm) | |
2220 | { | |
2221 | stream_putl(s, pbm->unique2); | |
2222 | ||
2223 | stream_putl(s, pbm->type); | |
2224 | ||
2225 | stream_putl(s, pbm->flags); | |
2226 | ||
2227 | /* TODO: correlate with what is contained | |
2228 | * into bgp_pbr_action. | |
2229 | * currently only forward supported | |
2230 | */ | |
2231 | if (bpa->nh.type == NEXTHOP_TYPE_BLACKHOLE) | |
2232 | stream_putl(s, ZEBRA_IPTABLES_DROP); | |
2233 | else | |
2234 | stream_putl(s, ZEBRA_IPTABLES_FORWARD); | |
2235 | stream_putl(s, bpa->fwmark); | |
2236 | stream_put(s, pbm->ipset_name, | |
2237 | ZEBRA_IPSET_NAME_SIZE); | |
83360720 PG |
2238 | stream_putw(s, pbm->pkt_len_min); |
2239 | stream_putw(s, pbm->pkt_len_max); | |
2da7d62e PG |
2240 | stream_putw(s, pbm->tcp_flags); |
2241 | stream_putw(s, pbm->tcp_mask_flags); | |
4977bd6c | 2242 | stream_putc(s, pbm->dscp_value); |
6f5617d8 | 2243 | stream_putc(s, pbm->fragment); |
c16a0a62 PG |
2244 | } |
2245 | ||
ad4cbda1 | 2246 | /* BGP has established connection with Zebra. */ |
d62a17ae | 2247 | static void bgp_zebra_connected(struct zclient *zclient) |
7076bb2f | 2248 | { |
d62a17ae | 2249 | struct bgp *bgp; |
7076bb2f | 2250 | |
d62a17ae | 2251 | zclient_num_connects++; /* increment even if not responding */ |
afbb1c59 | 2252 | |
d62a17ae | 2253 | /* At this point, we may or may not have BGP instances configured, but |
2254 | * we're only interested in the default VRF (others wouldn't have learnt | |
2255 | * the VRF from Zebra yet.) | |
2256 | */ | |
2257 | bgp = bgp_get_default(); | |
2258 | if (!bgp) | |
2259 | return; | |
ad4cbda1 | 2260 | |
d62a17ae | 2261 | bgp_zebra_instance_register(bgp); |
ad4cbda1 | 2262 | |
d62a17ae | 2263 | /* Send the client registration */ |
2264 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER); | |
2376c3f2 | 2265 | |
955bfd98 | 2266 | /* tell label pool that zebra is connected */ |
e70e9f8e | 2267 | bgp_lp_event_zebra_up(); |
955bfd98 | 2268 | |
d62a17ae | 2269 | /* TODO - What if we have peers and networks configured, do we have to |
2270 | * kick-start them? | |
2271 | */ | |
7076bb2f FL |
2272 | } |
2273 | ||
50f74cf1 | 2274 | static int bgp_zebra_process_local_es(int cmd, struct zclient *zclient, |
2275 | zebra_size_t length, vrf_id_t vrf_id) | |
2276 | { | |
2277 | esi_t esi; | |
2278 | struct bgp *bgp = NULL; | |
2279 | struct stream *s = NULL; | |
2280 | char buf[ESI_STR_LEN]; | |
2281 | char buf1[INET6_ADDRSTRLEN]; | |
2282 | struct ipaddr originator_ip; | |
2283 | ||
2284 | memset(&esi, 0, sizeof(esi_t)); | |
2285 | memset(&originator_ip, 0, sizeof(struct ipaddr)); | |
2286 | ||
2287 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2288 | if (!bgp) | |
2289 | return 0; | |
2290 | ||
2291 | s = zclient->ibuf; | |
2292 | stream_get(&esi, s, sizeof(esi_t)); | |
2293 | stream_get(&originator_ip, s, sizeof(struct ipaddr)); | |
2294 | ||
2295 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2296 | zlog_debug("Rx %s ESI %s originator-ip %s", | |
2297 | (cmd == ZEBRA_LOCAL_ES_ADD) ? "add" : "del", | |
2298 | esi_to_str(&esi, buf, sizeof(buf)), | |
2299 | ipaddr2str(&originator_ip, buf1, sizeof(buf1))); | |
2300 | ||
2301 | if (cmd == ZEBRA_LOCAL_ES_ADD) | |
2302 | bgp_evpn_local_es_add(bgp, &esi, &originator_ip); | |
2303 | else | |
2304 | bgp_evpn_local_es_del(bgp, &esi, &originator_ip); | |
2305 | return 0; | |
2306 | } | |
2307 | ||
fe1dc5a3 MK |
2308 | static int bgp_zebra_process_local_l3vni(int cmd, struct zclient *zclient, |
2309 | zebra_size_t length, vrf_id_t vrf_id) | |
2310 | { | |
c48d9f5f | 2311 | int filter = 0; |
fe1dc5a3 | 2312 | char buf[ETHER_ADDR_STRLEN]; |
b67a60d2 | 2313 | vni_t l3vni = 0; |
fe1dc5a3 | 2314 | struct ethaddr rmac; |
b67a60d2 | 2315 | struct in_addr originator_ip; |
fe1dc5a3 MK |
2316 | struct stream *s; |
2317 | ||
2318 | memset(&rmac, 0, sizeof(struct ethaddr)); | |
b67a60d2 | 2319 | memset(&originator_ip, 0, sizeof(struct in_addr)); |
fe1dc5a3 MK |
2320 | s = zclient->ibuf; |
2321 | l3vni = stream_getl(s); | |
b67a60d2 | 2322 | if (cmd == ZEBRA_L3VNI_ADD) { |
fe1dc5a3 | 2323 | stream_get(&rmac, s, sizeof(struct ethaddr)); |
b67a60d2 | 2324 | originator_ip.s_addr = stream_get_ipv4(s); |
c48d9f5f | 2325 | stream_get(&filter, s, sizeof(int)); |
b67a60d2 | 2326 | } |
fe1dc5a3 MK |
2327 | |
2328 | if (BGP_DEBUG(zebra, ZEBRA)) | |
c48d9f5f | 2329 | zlog_debug("Rx L3-VNI %s VRF %s VNI %u RMAC %s filter %s", |
fe1dc5a3 | 2330 | (cmd == ZEBRA_L3VNI_ADD) ? "add" : "del", |
996c9314 | 2331 | vrf_id_to_name(vrf_id), l3vni, |
c48d9f5f MK |
2332 | prefix_mac2str(&rmac, buf, sizeof(buf)), |
2333 | filter ? "prefix-routes-only" : "none"); | |
fe1dc5a3 MK |
2334 | |
2335 | if (cmd == ZEBRA_L3VNI_ADD) | |
c48d9f5f MK |
2336 | bgp_evpn_local_l3vni_add(l3vni, vrf_id, &rmac, originator_ip, |
2337 | filter); | |
fe1dc5a3 MK |
2338 | else |
2339 | bgp_evpn_local_l3vni_del(l3vni, vrf_id); | |
2340 | ||
2341 | return 0; | |
2342 | } | |
2343 | ||
d62a17ae | 2344 | static int bgp_zebra_process_local_vni(int command, struct zclient *zclient, |
2345 | zebra_size_t length, vrf_id_t vrf_id) | |
128ea8ab | 2346 | { |
d62a17ae | 2347 | struct stream *s; |
2348 | vni_t vni; | |
2349 | struct bgp *bgp; | |
a4d82a8a | 2350 | struct in_addr vtep_ip = {INADDR_ANY}; |
29c53922 | 2351 | vrf_id_t tenant_vrf_id = VRF_DEFAULT; |
d62a17ae | 2352 | |
2353 | s = zclient->ibuf; | |
2354 | vni = stream_getl(s); | |
29c53922 | 2355 | if (command == ZEBRA_VNI_ADD) { |
d62a17ae | 2356 | vtep_ip.s_addr = stream_get_ipv4(s); |
29c53922 MK |
2357 | stream_get(&tenant_vrf_id, s, sizeof(vrf_id_t)); |
2358 | } | |
2359 | ||
d62a17ae | 2360 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2361 | if (!bgp) | |
2362 | return 0; | |
2363 | ||
2364 | if (BGP_DEBUG(zebra, ZEBRA)) | |
29c53922 MK |
2365 | zlog_debug("Rx VNI %s VRF %s VNI %u tenant-vrf %s", |
2366 | (command == ZEBRA_VNI_ADD) ? "add" : "del", | |
a4d82a8a PZ |
2367 | vrf_id_to_name(vrf_id), vni, |
2368 | vrf_id_to_name(tenant_vrf_id)); | |
d62a17ae | 2369 | |
2370 | if (command == ZEBRA_VNI_ADD) | |
2371 | return bgp_evpn_local_vni_add( | |
29c53922 MK |
2372 | bgp, vni, vtep_ip.s_addr ? vtep_ip : bgp->router_id, |
2373 | tenant_vrf_id); | |
d62a17ae | 2374 | else |
2375 | return bgp_evpn_local_vni_del(bgp, vni); | |
128ea8ab | 2376 | } |
2377 | ||
d62a17ae | 2378 | static int bgp_zebra_process_local_macip(int command, struct zclient *zclient, |
2379 | zebra_size_t length, vrf_id_t vrf_id) | |
128ea8ab | 2380 | { |
d62a17ae | 2381 | struct stream *s; |
2382 | vni_t vni; | |
2383 | struct bgp *bgp; | |
2384 | struct ethaddr mac; | |
2385 | struct ipaddr ip; | |
2386 | int ipa_len; | |
2387 | char buf[ETHER_ADDR_STRLEN]; | |
2388 | char buf1[INET6_ADDRSTRLEN]; | |
f07e1c99 | 2389 | uint8_t flags = 0; |
2390 | uint32_t seqnum = 0; | |
d62a17ae | 2391 | |
2392 | memset(&ip, 0, sizeof(ip)); | |
2393 | s = zclient->ibuf; | |
2394 | vni = stream_getl(s); | |
28328ea9 | 2395 | stream_get(&mac.octet, s, ETH_ALEN); |
d62a17ae | 2396 | ipa_len = stream_getl(s); |
2397 | if (ipa_len != 0 && ipa_len != IPV4_MAX_BYTELEN | |
2398 | && ipa_len != IPV6_MAX_BYTELEN) { | |
e50f7cfd | 2399 | flog_err(EC_BGP_MACIP_LEN, |
1c50c1c0 QY |
2400 | "%u:Recv MACIP %s with invalid IP addr length %d", |
2401 | vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del", | |
2402 | ipa_len); | |
d62a17ae | 2403 | return -1; |
2404 | } | |
2405 | ||
2406 | if (ipa_len) { | |
2407 | ip.ipa_type = | |
2408 | (ipa_len == IPV4_MAX_BYTELEN) ? IPADDR_V4 : IPADDR_V6; | |
2409 | stream_get(&ip.ip.addr, s, ipa_len); | |
2410 | } | |
f07e1c99 | 2411 | if (command == ZEBRA_MACIP_ADD) { |
2412 | flags = stream_getc(s); | |
2413 | seqnum = stream_getl(s); | |
2414 | } | |
d62a17ae | 2415 | |
2416 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2417 | if (!bgp) | |
2418 | return 0; | |
2419 | ||
2420 | if (BGP_DEBUG(zebra, ZEBRA)) | |
f07e1c99 | 2421 | zlog_debug("%u:Recv MACIP %s flags 0x%x MAC %s IP %s VNI %u seq %u", |
1a98c087 MK |
2422 | vrf_id, (command == ZEBRA_MACIP_ADD) ? "Add" : "Del", |
2423 | flags, prefix_mac2str(&mac, buf, sizeof(buf)), | |
f07e1c99 | 2424 | ipaddr2str(&ip, buf1, sizeof(buf1)), vni, seqnum); |
d62a17ae | 2425 | |
2426 | if (command == ZEBRA_MACIP_ADD) | |
f07e1c99 | 2427 | return bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, |
2428 | flags, seqnum); | |
d62a17ae | 2429 | else |
2430 | return bgp_evpn_local_macip_del(bgp, vni, &mac, &ip); | |
128ea8ab | 2431 | } |
6aeb9e78 | 2432 | |
a4d82a8a | 2433 | static void bgp_zebra_process_local_ip_prefix(int cmd, struct zclient *zclient, |
31310b25 MK |
2434 | zebra_size_t length, |
2435 | vrf_id_t vrf_id) | |
2436 | { | |
2437 | struct stream *s = NULL; | |
2438 | struct bgp *bgp_vrf = NULL; | |
2439 | struct prefix p; | |
2440 | char buf[PREFIX_STRLEN]; | |
2441 | ||
2442 | memset(&p, 0, sizeof(struct prefix)); | |
2443 | s = zclient->ibuf; | |
2444 | stream_get(&p, s, sizeof(struct prefix)); | |
2445 | ||
2446 | bgp_vrf = bgp_lookup_by_vrf_id(vrf_id); | |
2447 | if (!bgp_vrf) | |
2448 | return; | |
2449 | ||
2450 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2451 | zlog_debug("Recv prefix %s %s on vrf %s", | |
2452 | prefix2str(&p, buf, sizeof(buf)), | |
2453 | (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", | |
2454 | vrf_id_to_name(vrf_id)); | |
2455 | ||
2456 | if (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) { | |
2457 | ||
2458 | if (p.family == AF_INET) | |
a4d82a8a PZ |
2459 | return bgp_evpn_advertise_type5_route( |
2460 | bgp_vrf, &p, NULL, AFI_IP, SAFI_UNICAST); | |
31310b25 | 2461 | else |
a4d82a8a PZ |
2462 | return bgp_evpn_advertise_type5_route( |
2463 | bgp_vrf, &p, NULL, AFI_IP6, SAFI_UNICAST); | |
31310b25 MK |
2464 | |
2465 | } else { | |
2466 | if (p.family == AF_INET) | |
a4d82a8a PZ |
2467 | return bgp_evpn_withdraw_type5_route( |
2468 | bgp_vrf, &p, AFI_IP, SAFI_UNICAST); | |
31310b25 | 2469 | else |
a4d82a8a PZ |
2470 | return bgp_evpn_withdraw_type5_route( |
2471 | bgp_vrf, &p, AFI_IP6, SAFI_UNICAST); | |
31310b25 MK |
2472 | } |
2473 | } | |
2474 | ||
955bfd98 PZ |
2475 | static void bgp_zebra_process_label_chunk( |
2476 | int cmd, | |
2477 | struct zclient *zclient, | |
2478 | zebra_size_t length, | |
2479 | vrf_id_t vrf_id) | |
2480 | { | |
2481 | struct stream *s = NULL; | |
2482 | uint8_t response_keep; | |
2483 | uint32_t first; | |
2484 | uint32_t last; | |
aec865e4 FR |
2485 | uint8_t proto; |
2486 | unsigned short instance; | |
955bfd98 PZ |
2487 | |
2488 | s = zclient->ibuf; | |
aec865e4 FR |
2489 | STREAM_GETC(s, proto); |
2490 | STREAM_GETW(s, instance); | |
955bfd98 PZ |
2491 | STREAM_GETC(s, response_keep); |
2492 | STREAM_GETL(s, first); | |
2493 | STREAM_GETL(s, last); | |
2494 | ||
aec865e4 | 2495 | if (zclient->redist_default != proto) { |
e50f7cfd | 2496 | flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong proto %u", |
1c50c1c0 | 2497 | proto); |
aec865e4 FR |
2498 | return; |
2499 | } | |
2500 | if (zclient->instance != instance) { | |
e50f7cfd | 2501 | flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong instance %u", |
1c50c1c0 | 2502 | proto); |
aec865e4 FR |
2503 | return; |
2504 | } | |
2505 | ||
955bfd98 PZ |
2506 | if (first > last || |
2507 | first < MPLS_LABEL_UNRESERVED_MIN || | |
2508 | last > MPLS_LABEL_UNRESERVED_MAX) { | |
2509 | ||
e50f7cfd | 2510 | flog_err(EC_BGP_LM_ERROR, "%s: Invalid Label chunk: %u - %u", |
1c50c1c0 | 2511 | __func__, first, last); |
955bfd98 PZ |
2512 | return; |
2513 | } | |
2514 | if (BGP_DEBUG(zebra, ZEBRA)) { | |
2515 | zlog_debug("Label Chunk assign: %u - %u (%u) ", | |
2516 | first, last, response_keep); | |
2517 | } | |
2518 | ||
e70e9f8e | 2519 | bgp_lp_event_chunk(response_keep, first, last); |
955bfd98 PZ |
2520 | |
2521 | stream_failure: /* for STREAM_GETX */ | |
2522 | return; | |
2523 | } | |
2524 | ||
342213ea DS |
2525 | extern struct zebra_privs_t bgpd_privs; |
2526 | ||
f533be73 | 2527 | void bgp_zebra_init(struct thread_master *master, unsigned short instance) |
718e3744 | 2528 | { |
d62a17ae | 2529 | zclient_num_connects = 0; |
2530 | ||
2531 | /* Set default values. */ | |
e1a1880d | 2532 | zclient = zclient_new_notify(master, &zclient_options_default); |
342213ea | 2533 | zclient_init(zclient, ZEBRA_ROUTE_BGP, 0, &bgpd_privs); |
d62a17ae | 2534 | zclient->zebra_connected = bgp_zebra_connected; |
2535 | zclient->router_id_update = bgp_router_id_update; | |
2536 | zclient->interface_add = bgp_interface_add; | |
2537 | zclient->interface_delete = bgp_interface_delete; | |
2538 | zclient->interface_address_add = bgp_interface_address_add; | |
2539 | zclient->interface_address_delete = bgp_interface_address_delete; | |
2540 | zclient->interface_nbr_address_add = bgp_interface_nbr_address_add; | |
2541 | zclient->interface_nbr_address_delete = | |
2542 | bgp_interface_nbr_address_delete; | |
2543 | zclient->interface_vrf_update = bgp_interface_vrf_update; | |
74489921 RW |
2544 | zclient->redistribute_route_add = zebra_read_route; |
2545 | zclient->redistribute_route_del = zebra_read_route; | |
d62a17ae | 2546 | zclient->interface_up = bgp_interface_up; |
2547 | zclient->interface_down = bgp_interface_down; | |
d62a17ae | 2548 | zclient->nexthop_update = bgp_read_nexthop_update; |
2549 | zclient->import_check_update = bgp_read_import_check_update; | |
2550 | zclient->fec_update = bgp_read_fec_update; | |
50f74cf1 | 2551 | zclient->local_es_add = bgp_zebra_process_local_es; |
2552 | zclient->local_es_del = bgp_zebra_process_local_es; | |
d62a17ae | 2553 | zclient->local_vni_add = bgp_zebra_process_local_vni; |
2554 | zclient->local_vni_del = bgp_zebra_process_local_vni; | |
2555 | zclient->local_macip_add = bgp_zebra_process_local_macip; | |
2556 | zclient->local_macip_del = bgp_zebra_process_local_macip; | |
fe1dc5a3 MK |
2557 | zclient->local_l3vni_add = bgp_zebra_process_local_l3vni; |
2558 | zclient->local_l3vni_del = bgp_zebra_process_local_l3vni; | |
31310b25 MK |
2559 | zclient->local_ip_prefix_add = bgp_zebra_process_local_ip_prefix; |
2560 | zclient->local_ip_prefix_del = bgp_zebra_process_local_ip_prefix; | |
955bfd98 | 2561 | zclient->label_chunk = bgp_zebra_process_label_chunk; |
30d50e6d PG |
2562 | zclient->rule_notify_owner = rule_notify_owner; |
2563 | zclient->ipset_notify_owner = ipset_notify_owner; | |
2564 | zclient->ipset_entry_notify_owner = ipset_entry_notify_owner; | |
c16a0a62 | 2565 | zclient->iptable_notify_owner = iptable_notify_owner; |
f533be73 | 2566 | zclient->instance = instance; |
718e3744 | 2567 | } |
bb86c601 | 2568 | |
d62a17ae | 2569 | void bgp_zebra_destroy(void) |
bb86c601 | 2570 | { |
d62a17ae | 2571 | if (zclient == NULL) |
2572 | return; | |
2573 | zclient_stop(zclient); | |
2574 | zclient_free(zclient); | |
2575 | zclient = NULL; | |
bb86c601 | 2576 | } |
afbb1c59 | 2577 | |
d62a17ae | 2578 | int bgp_zebra_num_connects(void) |
afbb1c59 | 2579 | { |
d62a17ae | 2580 | return zclient_num_connects; |
afbb1c59 | 2581 | } |
30d50e6d PG |
2582 | |
2583 | void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra, bool install) | |
2584 | { | |
2585 | struct stream *s; | |
2586 | ||
2587 | if (pbra->install_in_progress) | |
2588 | return; | |
f0936054 PG |
2589 | if (BGP_DEBUG(zebra, ZEBRA)) |
2590 | zlog_debug("%s: table %d fwmark %d %d", | |
2591 | __PRETTY_FUNCTION__, | |
2592 | pbra->table_id, pbra->fwmark, install); | |
30d50e6d PG |
2593 | s = zclient->obuf; |
2594 | stream_reset(s); | |
2595 | ||
2596 | zclient_create_header(s, | |
2597 | install ? ZEBRA_RULE_ADD : ZEBRA_RULE_DELETE, | |
2598 | VRF_DEFAULT); | |
2599 | stream_putl(s, 1); /* send one pbr action */ | |
2600 | ||
2601 | bgp_encode_pbr_rule_action(s, pbra); | |
2602 | ||
2603 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2604 | if (!zclient_send_message(zclient) && install) | |
2605 | pbra->install_in_progress = true; | |
2606 | } | |
2607 | ||
2608 | void bgp_send_pbr_ipset_match(struct bgp_pbr_match *pbrim, bool install) | |
2609 | { | |
2610 | struct stream *s; | |
2611 | ||
2612 | if (pbrim->install_in_progress) | |
2613 | return; | |
f0936054 | 2614 | if (BGP_DEBUG(zebra, ZEBRA)) |
88055124 | 2615 | zlog_debug("%s: name %s type %d %d, ID %u", |
f0936054 | 2616 | __PRETTY_FUNCTION__, |
88055124 PG |
2617 | pbrim->ipset_name, pbrim->type, |
2618 | install, pbrim->unique); | |
30d50e6d PG |
2619 | s = zclient->obuf; |
2620 | stream_reset(s); | |
2621 | ||
2622 | zclient_create_header(s, | |
2623 | install ? ZEBRA_IPSET_CREATE : | |
2624 | ZEBRA_IPSET_DESTROY, | |
2625 | VRF_DEFAULT); | |
2626 | ||
2627 | stream_putl(s, 1); /* send one pbr action */ | |
2628 | ||
2629 | bgp_encode_pbr_ipset_match(s, pbrim); | |
2630 | ||
2631 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2632 | if (!zclient_send_message(zclient) && install) | |
2633 | pbrim->install_in_progress = true; | |
2634 | } | |
2635 | ||
2636 | void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry *pbrime, | |
2637 | bool install) | |
2638 | { | |
2639 | struct stream *s; | |
2640 | ||
2641 | if (pbrime->install_in_progress) | |
2642 | return; | |
f0936054 | 2643 | if (BGP_DEBUG(zebra, ZEBRA)) |
88055124 | 2644 | zlog_debug("%s: name %s %d %d, ID %u", __PRETTY_FUNCTION__, |
f0936054 | 2645 | pbrime->backpointer->ipset_name, |
88055124 | 2646 | pbrime->unique, install, pbrime->unique); |
30d50e6d PG |
2647 | s = zclient->obuf; |
2648 | stream_reset(s); | |
2649 | ||
2650 | zclient_create_header(s, | |
2651 | install ? ZEBRA_IPSET_ENTRY_ADD : | |
2652 | ZEBRA_IPSET_ENTRY_DELETE, | |
2653 | VRF_DEFAULT); | |
2654 | ||
2655 | stream_putl(s, 1); /* send one pbr action */ | |
2656 | ||
2657 | bgp_encode_pbr_ipset_entry_match(s, pbrime); | |
2658 | ||
2659 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2660 | if (!zclient_send_message(zclient) && install) | |
2661 | pbrime->install_in_progress = true; | |
2662 | } | |
c16a0a62 | 2663 | |
4762c213 PG |
2664 | static void bgp_encode_pbr_interface_list(struct bgp *bgp, struct stream *s) |
2665 | { | |
2666 | struct bgp_pbr_config *bgp_pbr_cfg = bgp->bgp_pbr_cfg; | |
2667 | struct bgp_pbr_interface_head *head; | |
2668 | struct bgp_pbr_interface *pbr_if; | |
2669 | struct interface *ifp; | |
2670 | ||
2671 | if (!bgp_pbr_cfg) | |
2672 | return; | |
2673 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); | |
2674 | ||
2675 | RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { | |
2676 | ifp = if_lookup_by_name(pbr_if->name, bgp->vrf_id); | |
2677 | if (ifp) | |
2678 | stream_putl(s, ifp->ifindex); | |
2679 | } | |
2680 | } | |
2681 | ||
2682 | static int bgp_pbr_get_ifnumber(struct bgp *bgp) | |
2683 | { | |
2684 | struct bgp_pbr_config *bgp_pbr_cfg = bgp->bgp_pbr_cfg; | |
2685 | struct bgp_pbr_interface_head *head; | |
2686 | struct bgp_pbr_interface *pbr_if; | |
2687 | int cnt = 0; | |
2688 | ||
2689 | if (!bgp_pbr_cfg) | |
2690 | return 0; | |
2691 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); | |
2692 | ||
2693 | RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { | |
2694 | if (if_lookup_by_name(pbr_if->name, bgp->vrf_id)) | |
2695 | cnt++; | |
2696 | } | |
2697 | return cnt; | |
2698 | } | |
2699 | ||
c16a0a62 PG |
2700 | void bgp_send_pbr_iptable(struct bgp_pbr_action *pba, |
2701 | struct bgp_pbr_match *pbm, | |
2702 | bool install) | |
2703 | { | |
2704 | struct stream *s; | |
b5c40105 | 2705 | int ret = 0; |
4762c213 | 2706 | int nb_interface; |
c16a0a62 PG |
2707 | |
2708 | if (pbm->install_iptable_in_progress) | |
2709 | return; | |
f0936054 | 2710 | if (BGP_DEBUG(zebra, ZEBRA)) |
88055124 | 2711 | zlog_debug("%s: name %s type %d mark %d %d, ID %u", |
f0936054 | 2712 | __PRETTY_FUNCTION__, pbm->ipset_name, |
88055124 PG |
2713 | pbm->type, pba->fwmark, install, |
2714 | pbm->unique2); | |
c16a0a62 PG |
2715 | s = zclient->obuf; |
2716 | stream_reset(s); | |
2717 | ||
2718 | zclient_create_header(s, | |
2719 | install ? ZEBRA_IPTABLE_ADD : | |
2720 | ZEBRA_IPTABLE_DELETE, | |
2721 | VRF_DEFAULT); | |
2722 | ||
2723 | bgp_encode_pbr_iptable_match(s, pba, pbm); | |
4762c213 PG |
2724 | nb_interface = bgp_pbr_get_ifnumber(pba->bgp); |
2725 | stream_putl(s, nb_interface); | |
2726 | if (nb_interface) | |
2727 | bgp_encode_pbr_interface_list(pba->bgp, s); | |
c16a0a62 | 2728 | stream_putw_at(s, 0, stream_get_endp(s)); |
b5c40105 PG |
2729 | ret = zclient_send_message(zclient); |
2730 | if (install) { | |
2731 | if (ret) | |
2732 | pba->refcnt++; | |
2733 | else | |
2734 | pbm->install_iptable_in_progress = true; | |
a6b07429 | 2735 | } |
c16a0a62 | 2736 | } |
f7df1907 PG |
2737 | |
2738 | /* inject in table <table_id> a default route to: | |
2739 | * - if nexthop IP is present : to this nexthop | |
2740 | * - if vrf is different from local : to the matching VRF | |
2741 | */ | |
2742 | void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh, | |
2743 | afi_t afi, uint32_t table_id, bool announce) | |
2744 | { | |
2745 | struct zapi_nexthop *api_nh; | |
2746 | struct zapi_route api; | |
2747 | struct prefix p; | |
2748 | ||
2749 | if (!nh || nh->type != NEXTHOP_TYPE_IPV4 | |
2750 | || nh->vrf_id == VRF_UNKNOWN) | |
2751 | return; | |
2752 | memset(&p, 0, sizeof(struct prefix)); | |
2753 | /* default route */ | |
2754 | if (afi != AFI_IP) | |
2755 | return; | |
2756 | p.family = AF_INET; | |
2757 | memset(&api, 0, sizeof(api)); | |
2758 | api.vrf_id = bgp->vrf_id; | |
2759 | api.type = ZEBRA_ROUTE_BGP; | |
2760 | api.safi = SAFI_UNICAST; | |
2761 | api.prefix = p; | |
2762 | api.tableid = table_id; | |
2763 | api.nexthop_num = 1; | |
2764 | SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); | |
2765 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); | |
2766 | api_nh = &api.nexthops[0]; | |
2767 | ||
2768 | /* redirect IP */ | |
2769 | if (nh->gate.ipv4.s_addr) { | |
2770 | char buff[PREFIX_STRLEN]; | |
2771 | ||
2772 | api_nh->vrf_id = nh->vrf_id; | |
2773 | api_nh->gate.ipv4 = nh->gate.ipv4; | |
2774 | api_nh->type = NEXTHOP_TYPE_IPV4; | |
2775 | ||
2776 | inet_ntop(AF_INET, &(nh->gate.ipv4), buff, INET_ADDRSTRLEN); | |
2777 | if (BGP_DEBUG(zebra, ZEBRA)) | |
d887503c PG |
2778 | zlog_info("BGP: %s default route to %s table %d (redirect IP)", |
2779 | announce ? "adding" : "withdrawing", | |
f7df1907 PG |
2780 | buff, table_id); |
2781 | zclient_route_send(announce ? ZEBRA_ROUTE_ADD | |
2782 | : ZEBRA_ROUTE_DELETE, | |
2783 | zclient, &api); | |
2784 | } else if (nh->vrf_id != bgp->vrf_id) { | |
2785 | struct vrf *vrf; | |
eb4244f8 | 2786 | struct interface *ifp; |
f7df1907 | 2787 | |
eb4244f8 | 2788 | vrf = vrf_lookup_by_id(nh->vrf_id); |
f7df1907 PG |
2789 | if (!vrf) |
2790 | return; | |
eb4244f8 PG |
2791 | /* create default route with interface <VRF> |
2792 | * with nexthop-vrf <VRF> | |
f7df1907 | 2793 | */ |
eb4244f8 PG |
2794 | ifp = if_lookup_by_name_all_vrf(vrf->name); |
2795 | if (!ifp) | |
2796 | return; | |
2797 | api_nh->vrf_id = nh->vrf_id; | |
2798 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
2799 | api_nh->ifindex = ifp->ifindex; | |
2800 | if (BGP_DEBUG(zebra, ZEBRA)) | |
d887503c PG |
2801 | zlog_info("BGP: %s default route to %s table %d (redirect VRF)", |
2802 | announce ? "adding" : "withdrawing", | |
eb4244f8 PG |
2803 | vrf->name, table_id); |
2804 | zclient_route_send(announce ? ZEBRA_ROUTE_ADD | |
2805 | : ZEBRA_ROUTE_DELETE, | |
2806 | zclient, &api); | |
f7df1907 PG |
2807 | return; |
2808 | } | |
2809 | } |