]>
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" |
94effaf0 | 36 | #include "lib/route_opaque.h" |
039f3a34 | 37 | #include "filter.h" |
cd1964ff | 38 | #include "mpls.h" |
128ea8ab | 39 | #include "vxlan.h" |
6cfe5d15 | 40 | #include "pbr.h" |
718e3744 | 41 | |
42 | #include "bgpd/bgpd.h" | |
43 | #include "bgpd/bgp_route.h" | |
44 | #include "bgpd/bgp_attr.h" | |
e46723a5 | 45 | #include "bgpd/bgp_aspath.h" |
718e3744 | 46 | #include "bgpd/bgp_nexthop.h" |
47 | #include "bgpd/bgp_zebra.h" | |
48 | #include "bgpd/bgp_fsm.h" | |
a39275d7 | 49 | #include "bgpd/bgp_debug.h" |
14454c9f | 50 | #include "bgpd/bgp_errors.h" |
8196f13d | 51 | #include "bgpd/bgp_mpath.h" |
fb018d25 | 52 | #include "bgpd/bgp_nexthop.h" |
ffd0c037 | 53 | #include "bgpd/bgp_nht.h" |
8c4f6381 | 54 | #include "bgpd/bgp_bfd.h" |
cd1964ff | 55 | #include "bgpd/bgp_label.h" |
49e5a4a0 | 56 | #ifdef ENABLE_BGP_VNC |
d62a17ae | 57 | #include "bgpd/rfapi/rfapi_backend.h" |
58 | #include "bgpd/rfapi/vnc_export_bgp.h" | |
65efcfce | 59 | #endif |
128ea8ab | 60 | #include "bgpd/bgp_evpn.h" |
ddb5b488 | 61 | #include "bgpd/bgp_mplsvpn.h" |
955bfd98 | 62 | #include "bgpd/bgp_labelpool.h" |
30d50e6d | 63 | #include "bgpd/bgp_pbr.h" |
0b9d9cd0 | 64 | #include "bgpd/bgp_evpn_private.h" |
c44ab6f1 | 65 | #include "bgpd/bgp_evpn_mh.h" |
6a69ac51 | 66 | #include "bgpd/bgp_mac.h" |
a383bfc7 | 67 | #include "bgpd/bgp_trace.h" |
6b0655a2 | 68 | |
718e3744 | 69 | /* All information about zebra. */ |
228da428 | 70 | struct zclient *zclient = NULL; |
718e3744 | 71 | |
0d020cd6 PR |
72 | /* hook to indicate vrf status change for SNMP */ |
73 | DEFINE_HOOK(bgp_vrf_status_changed, (struct bgp *bgp, struct interface *ifp), | |
8451921b | 74 | (bgp, ifp)); |
0d020cd6 | 75 | |
ad4cbda1 | 76 | /* Can we install into zebra? */ |
3dc339cd | 77 | static inline bool bgp_install_info_to_zebra(struct bgp *bgp) |
ad4cbda1 | 78 | { |
d62a17ae | 79 | if (zclient->sock <= 0) |
3dc339cd | 80 | return false; |
ad4cbda1 | 81 | |
bb4ef1ae | 82 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { |
15569c58 DA |
83 | zlog_debug( |
84 | "%s: No zebra instance to talk to, not installing information", | |
85 | __func__); | |
3dc339cd | 86 | return false; |
bb4ef1ae | 87 | } |
ad4cbda1 | 88 | |
3dc339cd | 89 | return true; |
ad4cbda1 | 90 | } |
91 | ||
afbb1c59 LB |
92 | int zclient_num_connects; |
93 | ||
18a6dce6 | 94 | /* Router-id update message from zebra. */ |
121f9dee | 95 | static int bgp_router_id_update(ZAPI_CALLBACK_ARGS) |
718e3744 | 96 | { |
d62a17ae | 97 | struct prefix router_id; |
718e3744 | 98 | |
d62a17ae | 99 | zebra_router_id_update_read(zclient->ibuf, &router_id); |
a39275d7 | 100 | |
2dbe669b DA |
101 | if (BGP_DEBUG(zebra, ZEBRA)) |
102 | zlog_debug("Rx Router Id update VRF %u Id %pFX", vrf_id, | |
103 | &router_id); | |
a39275d7 | 104 | |
d62a17ae | 105 | bgp_router_id_zebra_bump(vrf_id, &router_id); |
106 | return 0; | |
718e3744 | 107 | } |
108 | ||
fb018d25 | 109 | /* Nexthop update message from zebra. */ |
121f9dee | 110 | static int bgp_read_nexthop_update(ZAPI_CALLBACK_ARGS) |
fb018d25 | 111 | { |
121f9dee | 112 | bgp_parse_nexthop_update(cmd, vrf_id); |
d62a17ae | 113 | return 0; |
078430f6 DS |
114 | } |
115 | ||
4a04e5f7 | 116 | /* Set or clear interface on which unnumbered neighbor is configured. This |
117 | * would in turn cause BGP to initiate or turn off IPv6 RAs on this | |
118 | * interface. | |
119 | */ | |
d62a17ae | 120 | static void bgp_update_interface_nbrs(struct bgp *bgp, struct interface *ifp, |
121 | struct interface *upd_ifp) | |
4a04e5f7 | 122 | { |
d62a17ae | 123 | struct listnode *node, *nnode; |
124 | struct peer *peer; | |
125 | ||
126 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
127 | if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0)) { | |
128 | if (upd_ifp) { | |
129 | peer->ifp = upd_ifp; | |
130 | bgp_zebra_initiate_radv(bgp, peer); | |
131 | } else { | |
132 | bgp_zebra_terminate_radv(bgp, peer); | |
133 | peer->ifp = upd_ifp; | |
134 | } | |
135 | } | |
136 | } | |
4a04e5f7 | 137 | } |
138 | ||
a243d1db | 139 | static int bgp_read_fec_update(ZAPI_CALLBACK_ARGS) |
cd1964ff | 140 | { |
d62a17ae | 141 | bgp_parse_fec_update(); |
142 | return 0; | |
cd1964ff DS |
143 | } |
144 | ||
d62a17ae | 145 | static void bgp_start_interface_nbrs(struct bgp *bgp, struct interface *ifp) |
a80beece | 146 | { |
d62a17ae | 147 | struct listnode *node, *nnode; |
148 | struct peer *peer; | |
149 | ||
150 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
151 | if (peer->conf_if && (strcmp(peer->conf_if, ifp->name) == 0) | |
feb17238 | 152 | && !peer_established(peer)) { |
d62a17ae | 153 | if (peer_active(peer)) |
154 | BGP_EVENT_ADD(peer, BGP_Stop); | |
155 | BGP_EVENT_ADD(peer, BGP_Start); | |
156 | } | |
157 | } | |
a80beece DS |
158 | } |
159 | ||
d62a17ae | 160 | static void bgp_nbr_connected_add(struct bgp *bgp, struct nbr_connected *ifc) |
a197c47c | 161 | { |
d62a17ae | 162 | struct listnode *node; |
163 | struct connected *connected; | |
164 | struct interface *ifp; | |
165 | struct prefix *p; | |
166 | ||
167 | /* Kick-off the FSM for any relevant peers only if there is a | |
168 | * valid local address on the interface. | |
169 | */ | |
170 | ifp = ifc->ifp; | |
171 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, node, connected)) { | |
172 | p = connected->address; | |
173 | if (p->family == AF_INET6 | |
174 | && IN6_IS_ADDR_LINKLOCAL(&p->u.prefix6)) | |
175 | break; | |
176 | } | |
177 | if (!connected) | |
178 | return; | |
179 | ||
180 | bgp_start_interface_nbrs(bgp, ifp); | |
a197c47c DS |
181 | } |
182 | ||
d62a17ae | 183 | static void bgp_nbr_connected_delete(struct bgp *bgp, struct nbr_connected *ifc, |
184 | int del) | |
a80beece | 185 | { |
d62a17ae | 186 | struct listnode *node, *nnode; |
187 | struct peer *peer; | |
188 | struct interface *ifp; | |
189 | ||
190 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
191 | if (peer->conf_if | |
192 | && (strcmp(peer->conf_if, ifc->ifp->name) == 0)) { | |
193 | peer->last_reset = PEER_DOWN_NBR_ADDR_DEL; | |
194 | BGP_EVENT_ADD(peer, BGP_Stop); | |
195 | } | |
196 | } | |
197 | /* Free neighbor also, if we're asked to. */ | |
198 | if (del) { | |
199 | ifp = ifc->ifp; | |
200 | listnode_delete(ifp->nbr_connected, ifc); | |
201 | nbr_connected_free(ifc); | |
202 | } | |
a80beece DS |
203 | } |
204 | ||
3c3c3252 | 205 | static int bgp_ifp_destroy(struct interface *ifp) |
718e3744 | 206 | { |
d62a17ae | 207 | struct bgp *bgp; |
718e3744 | 208 | |
3c3c3252 | 209 | bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); |
a4499b83 | 210 | |
d62a17ae | 211 | if (BGP_DEBUG(zebra, ZEBRA)) |
3835984f | 212 | zlog_debug("Rx Intf del VRF %u IF %s", ifp->vrf_id, ifp->name); |
a39275d7 | 213 | |
0d020cd6 | 214 | if (bgp) { |
85751d1d | 215 | bgp_update_interface_nbrs(bgp, ifp, NULL); |
0d020cd6 PR |
216 | hook_call(bgp_vrf_status_changed, bgp, ifp); |
217 | } | |
64745052 | 218 | |
6a69ac51 DS |
219 | bgp_mac_del_mac_entry(ifp); |
220 | ||
d62a17ae | 221 | return 0; |
718e3744 | 222 | } |
223 | ||
ddbf3e60 | 224 | static int bgp_ifp_up(struct interface *ifp) |
718e3744 | 225 | { |
d62a17ae | 226 | struct connected *c; |
227 | struct nbr_connected *nc; | |
228 | struct listnode *node, *nnode; | |
229 | struct bgp *bgp; | |
6aeb9e78 | 230 | |
ddbf3e60 | 231 | bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); |
718e3744 | 232 | |
6a69ac51 DS |
233 | bgp_mac_add_mac_entry(ifp); |
234 | ||
d62a17ae | 235 | if (BGP_DEBUG(zebra, ZEBRA)) |
ddbf3e60 | 236 | zlog_debug("Rx Intf up VRF %u IF %s", ifp->vrf_id, ifp->name); |
ad4cbda1 | 237 | |
85751d1d DS |
238 | if (!bgp) |
239 | return 0; | |
240 | ||
d62a17ae | 241 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
242 | bgp_connected_add(bgp, c); | |
718e3744 | 243 | |
d62a17ae | 244 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
245 | bgp_nbr_connected_add(bgp, nc); | |
a80beece | 246 | |
0d020cd6 | 247 | hook_call(bgp_vrf_status_changed, bgp, ifp); |
8761cd6d DS |
248 | bgp_nht_ifp_up(ifp); |
249 | ||
d62a17ae | 250 | return 0; |
718e3744 | 251 | } |
252 | ||
b0b69e59 | 253 | static int bgp_ifp_down(struct interface *ifp) |
718e3744 | 254 | { |
d62a17ae | 255 | struct connected *c; |
256 | struct nbr_connected *nc; | |
257 | struct listnode *node, *nnode; | |
258 | struct bgp *bgp; | |
c19fe3c7 | 259 | struct peer *peer; |
6aeb9e78 | 260 | |
b0b69e59 | 261 | bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); |
718e3744 | 262 | |
6a69ac51 DS |
263 | bgp_mac_del_mac_entry(ifp); |
264 | ||
d62a17ae | 265 | if (BGP_DEBUG(zebra, ZEBRA)) |
b0b69e59 | 266 | zlog_debug("Rx Intf down VRF %u IF %s", ifp->vrf_id, ifp->name); |
ad4cbda1 | 267 | |
85751d1d DS |
268 | if (!bgp) |
269 | return 0; | |
270 | ||
d62a17ae | 271 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
272 | bgp_connected_delete(bgp, c); | |
718e3744 | 273 | |
d62a17ae | 274 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
275 | bgp_nbr_connected_delete(bgp, nc, 1); | |
a80beece | 276 | |
d62a17ae | 277 | /* Fast external-failover */ |
c19fe3c7 | 278 | if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { |
718e3744 | 279 | |
d62a17ae | 280 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { |
50bd8995 | 281 | /* Take down directly connected peers. */ |
c8d6f0d6 | 282 | if ((peer->ttl != BGP_DEFAULT_TTL) |
e2521429 | 283 | && (peer->gtsm_hops != BGP_GTSM_HOPS_CONNECTED)) |
d62a17ae | 284 | continue; |
718e3744 | 285 | |
d62a17ae | 286 | if (ifp == peer->nexthop.ifp) { |
287 | BGP_EVENT_ADD(peer, BGP_Stop); | |
288 | peer->last_reset = PEER_DOWN_IF_DOWN; | |
289 | } | |
290 | } | |
291 | } | |
718e3744 | 292 | |
0d020cd6 | 293 | hook_call(bgp_vrf_status_changed, bgp, ifp); |
8761cd6d DS |
294 | bgp_nht_ifp_down(ifp); |
295 | ||
d62a17ae | 296 | return 0; |
718e3744 | 297 | } |
298 | ||
121f9dee | 299 | static int bgp_interface_address_add(ZAPI_CALLBACK_ARGS) |
718e3744 | 300 | { |
d62a17ae | 301 | struct connected *ifc; |
2f9123e0 DS |
302 | struct bgp *bgp; |
303 | ||
304 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
d62a17ae | 305 | |
121f9dee | 306 | ifc = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id); |
d62a17ae | 307 | |
308 | if (ifc == NULL) | |
309 | return 0; | |
310 | ||
2dbe669b DA |
311 | if (bgp_debug_zebra(ifc->address)) |
312 | zlog_debug("Rx Intf address add VRF %u IF %s addr %pFX", vrf_id, | |
313 | ifc->ifp->name, ifc->address); | |
d62a17ae | 314 | |
85751d1d DS |
315 | if (!bgp) |
316 | return 0; | |
317 | ||
d62a17ae | 318 | if (if_is_operative(ifc->ifp)) { |
d62a17ae | 319 | bgp_connected_add(bgp, ifc); |
2f9123e0 | 320 | |
d62a17ae | 321 | /* If we have learnt of any neighbors on this interface, |
322 | * check to kick off any BGP interface-based neighbors, | |
323 | * but only if this is a link-local address. | |
324 | */ | |
325 | if (IN6_IS_ADDR_LINKLOCAL(&ifc->address->u.prefix6) | |
326 | && !list_isempty(ifc->ifp->nbr_connected)) | |
327 | bgp_start_interface_nbrs(bgp, ifc->ifp); | |
328 | } | |
329 | ||
330 | return 0; | |
718e3744 | 331 | } |
332 | ||
121f9dee | 333 | static int bgp_interface_address_delete(ZAPI_CALLBACK_ARGS) |
718e3744 | 334 | { |
f3d20a2a | 335 | struct listnode *node, *nnode; |
d62a17ae | 336 | struct connected *ifc; |
f3d20a2a | 337 | struct peer *peer; |
d62a17ae | 338 | struct bgp *bgp; |
f3d20a2a | 339 | struct prefix *addr; |
6aeb9e78 | 340 | |
2f9123e0 | 341 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2f9123e0 | 342 | |
121f9dee | 343 | ifc = zebra_interface_address_read(cmd, zclient->ibuf, vrf_id); |
718e3744 | 344 | |
d62a17ae | 345 | if (ifc == NULL) |
346 | return 0; | |
718e3744 | 347 | |
2dbe669b DA |
348 | if (bgp_debug_zebra(ifc->address)) |
349 | zlog_debug("Rx Intf address del VRF %u IF %s addr %pFX", vrf_id, | |
350 | ifc->ifp->name, ifc->address); | |
a39275d7 | 351 | |
85751d1d | 352 | if (bgp && if_is_operative(ifc->ifp)) { |
2f9123e0 | 353 | bgp_connected_delete(bgp, ifc); |
d62a17ae | 354 | } |
718e3744 | 355 | |
f3d20a2a DS |
356 | addr = ifc->address; |
357 | ||
358 | if (bgp) { | |
359 | /* | |
360 | * When we are using the v6 global as part of the peering | |
361 | * nexthops and we are removing it, then we need to | |
362 | * clear the peer data saved for that nexthop and | |
363 | * cause a re-announcement of the route. Since | |
364 | * we do not want the peering to bounce. | |
365 | */ | |
366 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
367 | afi_t afi; | |
368 | safi_t safi; | |
369 | ||
370 | if (addr->family == AF_INET) | |
371 | continue; | |
372 | ||
373 | if (!IN6_IS_ADDR_LINKLOCAL(&addr->u.prefix6) | |
374 | && memcmp(&peer->nexthop.v6_global, | |
375 | &addr->u.prefix6, 16) | |
376 | == 0) { | |
377 | memset(&peer->nexthop.v6_global, 0, 16); | |
378 | FOREACH_AFI_SAFI (afi, safi) | |
379 | bgp_announce_route(peer, afi, safi, | |
380 | true); | |
381 | } | |
382 | } | |
383 | } | |
384 | ||
721c0857 | 385 | connected_free(&ifc); |
718e3744 | 386 | |
d62a17ae | 387 | return 0; |
718e3744 | 388 | } |
389 | ||
121f9dee | 390 | static int bgp_interface_nbr_address_add(ZAPI_CALLBACK_ARGS) |
a80beece | 391 | { |
d62a17ae | 392 | struct nbr_connected *ifc = NULL; |
393 | struct bgp *bgp; | |
394 | ||
121f9dee | 395 | ifc = zebra_interface_nbr_address_read(cmd, zclient->ibuf, vrf_id); |
d62a17ae | 396 | |
397 | if (ifc == NULL) | |
398 | return 0; | |
399 | ||
2dbe669b DA |
400 | if (bgp_debug_zebra(ifc->address)) |
401 | zlog_debug("Rx Intf neighbor add VRF %u IF %s addr %pFX", | |
402 | vrf_id, ifc->ifp->name, ifc->address); | |
d62a17ae | 403 | |
404 | if (if_is_operative(ifc->ifp)) { | |
405 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
406 | if (bgp) | |
407 | bgp_nbr_connected_add(bgp, ifc); | |
408 | } | |
409 | ||
410 | return 0; | |
a80beece DS |
411 | } |
412 | ||
121f9dee | 413 | static int bgp_interface_nbr_address_delete(ZAPI_CALLBACK_ARGS) |
a80beece | 414 | { |
d62a17ae | 415 | struct nbr_connected *ifc = NULL; |
416 | struct bgp *bgp; | |
6aeb9e78 | 417 | |
121f9dee | 418 | ifc = zebra_interface_nbr_address_read(cmd, zclient->ibuf, vrf_id); |
a80beece | 419 | |
d62a17ae | 420 | if (ifc == NULL) |
421 | return 0; | |
a80beece | 422 | |
2dbe669b DA |
423 | if (bgp_debug_zebra(ifc->address)) |
424 | zlog_debug("Rx Intf neighbor del VRF %u IF %s addr %pFX", | |
425 | vrf_id, ifc->ifp->name, ifc->address); | |
a80beece | 426 | |
d62a17ae | 427 | if (if_is_operative(ifc->ifp)) { |
428 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
429 | if (bgp) | |
430 | bgp_nbr_connected_delete(bgp, ifc, 0); | |
431 | } | |
a80beece | 432 | |
d62a17ae | 433 | nbr_connected_free(ifc); |
a80beece | 434 | |
d62a17ae | 435 | return 0; |
a80beece DS |
436 | } |
437 | ||
bfcd43b2 | 438 | /* VRF update for an interface. */ |
121f9dee | 439 | static int bgp_interface_vrf_update(ZAPI_CALLBACK_ARGS) |
bfcd43b2 | 440 | { |
d62a17ae | 441 | struct interface *ifp; |
442 | vrf_id_t new_vrf_id; | |
443 | struct connected *c; | |
444 | struct nbr_connected *nc; | |
445 | struct listnode *node, *nnode; | |
446 | struct bgp *bgp; | |
c19fe3c7 | 447 | struct peer *peer; |
bfcd43b2 | 448 | |
d62a17ae | 449 | ifp = zebra_interface_vrf_update_read(zclient->ibuf, vrf_id, |
450 | &new_vrf_id); | |
451 | if (!ifp) | |
452 | return 0; | |
bfcd43b2 | 453 | |
d62a17ae | 454 | if (BGP_DEBUG(zebra, ZEBRA) && ifp) |
455 | zlog_debug("Rx Intf VRF change VRF %u IF %s NewVRF %u", vrf_id, | |
456 | ifp->name, new_vrf_id); | |
bfcd43b2 | 457 | |
d62a17ae | 458 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
bfcd43b2 | 459 | |
85751d1d DS |
460 | if (bgp) { |
461 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) | |
462 | bgp_connected_delete(bgp, c); | |
bfcd43b2 | 463 | |
85751d1d DS |
464 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
465 | bgp_nbr_connected_delete(bgp, nc, 1); | |
bfcd43b2 | 466 | |
85751d1d DS |
467 | /* Fast external-failover */ |
468 | if (!CHECK_FLAG(bgp->flags, BGP_FLAG_NO_FAST_EXT_FAILOVER)) { | |
469 | for (ALL_LIST_ELEMENTS(bgp->peer, node, nnode, peer)) { | |
c8d6f0d6 | 470 | if ((peer->ttl != BGP_DEFAULT_TTL) |
e2521429 DA |
471 | && (peer->gtsm_hops |
472 | != BGP_GTSM_HOPS_CONNECTED)) | |
85751d1d | 473 | continue; |
bfcd43b2 | 474 | |
85751d1d DS |
475 | if (ifp == peer->nexthop.ifp) |
476 | BGP_EVENT_ADD(peer, BGP_Stop); | |
477 | } | |
d62a17ae | 478 | } |
479 | } | |
bfcd43b2 | 480 | |
a36898e7 | 481 | if_update_to_new_vrf(ifp, new_vrf_id); |
bfcd43b2 | 482 | |
d62a17ae | 483 | bgp = bgp_lookup_by_vrf_id(new_vrf_id); |
484 | if (!bgp) | |
485 | return 0; | |
bfcd43b2 | 486 | |
d62a17ae | 487 | for (ALL_LIST_ELEMENTS(ifp->connected, node, nnode, c)) |
488 | bgp_connected_add(bgp, c); | |
bfcd43b2 | 489 | |
d62a17ae | 490 | for (ALL_LIST_ELEMENTS(ifp->nbr_connected, node, nnode, nc)) |
491 | bgp_nbr_connected_add(bgp, nc); | |
0d020cd6 PR |
492 | |
493 | hook_call(bgp_vrf_status_changed, bgp, ifp); | |
d62a17ae | 494 | return 0; |
bfcd43b2 | 495 | } |
496 | ||
718e3744 | 497 | /* Zebra route add and delete treatment. */ |
121f9dee | 498 | static int zebra_read_route(ZAPI_CALLBACK_ARGS) |
718e3744 | 499 | { |
9de1f7ff | 500 | enum nexthop_types_t nhtype; |
0789eb69 | 501 | enum blackhole_type bhtype = BLACKHOLE_UNSPEC; |
74489921 | 502 | struct zapi_route api; |
0789eb69 | 503 | union g_addr nexthop = {}; |
9de1f7ff | 504 | ifindex_t ifindex; |
74489921 | 505 | int add, i; |
d62a17ae | 506 | struct bgp *bgp; |
507 | ||
508 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
509 | if (!bgp) | |
510 | return 0; | |
511 | ||
74489921 RW |
512 | if (zapi_route_decode(zclient->ibuf, &api) < 0) |
513 | return -1; | |
d62a17ae | 514 | |
74489921 RW |
515 | /* we completely ignore srcdest routes for now. */ |
516 | if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) | |
517 | return 0; | |
d62a17ae | 518 | |
74489921 RW |
519 | /* ignore link-local address. */ |
520 | if (api.prefix.family == AF_INET6 | |
521 | && IN6_IS_ADDR_LINKLOCAL(&api.prefix.u.prefix6)) | |
522 | return 0; | |
d62a17ae | 523 | |
74489921 | 524 | ifindex = api.nexthops[0].ifindex; |
9de1f7ff | 525 | nhtype = api.nexthops[0].type; |
d62a17ae | 526 | |
0789eb69 KM |
527 | /* api_nh structure has union of gate and bh_type */ |
528 | if (nhtype == NEXTHOP_TYPE_BLACKHOLE) { | |
529 | /* bh_type is only applicable if NEXTHOP_TYPE_BLACKHOLE*/ | |
530 | bhtype = api.nexthops[0].bh_type; | |
531 | } else | |
532 | nexthop = api.nexthops[0].gate; | |
533 | ||
121f9dee | 534 | add = (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD); |
74489921 | 535 | if (add) { |
d62a17ae | 536 | /* |
537 | * The ADD message is actually an UPDATE and there is no | |
538 | * explicit DEL | |
539 | * for a prior redistributed route, if any. So, perform an | |
540 | * implicit | |
541 | * DEL processing for the same redistributed route from any | |
542 | * other | |
543 | * source type. | |
544 | */ | |
545 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
546 | if (i != api.type) | |
74489921 | 547 | bgp_redistribute_delete(bgp, &api.prefix, i, |
d62a17ae | 548 | api.instance); |
549 | } | |
550 | ||
551 | /* Now perform the add/update. */ | |
74489921 | 552 | bgp_redistribute_add(bgp, &api.prefix, &nexthop, ifindex, |
0789eb69 KM |
553 | nhtype, bhtype, api.distance, api.metric, |
554 | api.type, api.instance, api.tag); | |
d62a17ae | 555 | } else { |
74489921 RW |
556 | bgp_redistribute_delete(bgp, &api.prefix, api.type, |
557 | api.instance); | |
a39275d7 | 558 | } |
d62a17ae | 559 | |
74489921 | 560 | if (bgp_debug_zebra(&api.prefix)) { |
2dbe669b | 561 | char buf[PREFIX_STRLEN]; |
74489921 | 562 | |
77e62f2b | 563 | if (add) { |
2dbe669b DA |
564 | inet_ntop(api.prefix.family, &nexthop, buf, |
565 | sizeof(buf)); | |
77e62f2b | 566 | zlog_debug( |
801bb996 | 567 | "Rx route ADD VRF %u %s[%d] %pFX nexthop %s (type %d if %u) metric %u distance %u tag %" ROUTE_TAG_PRI, |
77e62f2b | 568 | vrf_id, zebra_route_string(api.type), |
2dbe669b | 569 | api.instance, &api.prefix, buf, nhtype, ifindex, |
801bb996 | 570 | api.metric, api.distance, api.tag); |
77e62f2b | 571 | } else { |
6bdbcbf1 | 572 | zlog_debug("Rx route DEL VRF %u %s[%d] %pFX", vrf_id, |
2dbe669b | 573 | zebra_route_string(api.type), api.instance, |
6bdbcbf1 | 574 | &api.prefix); |
77e62f2b | 575 | } |
d62a17ae | 576 | } |
577 | ||
578 | return 0; | |
718e3744 | 579 | } |
6b0655a2 | 580 | |
d62a17ae | 581 | struct interface *if_lookup_by_ipv4(struct in_addr *addr, vrf_id_t vrf_id) |
718e3744 | 582 | { |
f4e14fdb | 583 | struct vrf *vrf; |
d62a17ae | 584 | struct listnode *cnode; |
585 | struct interface *ifp; | |
586 | struct connected *connected; | |
587 | struct prefix_ipv4 p; | |
588 | struct prefix *cp; | |
589 | ||
f4e14fdb RW |
590 | vrf = vrf_lookup_by_id(vrf_id); |
591 | if (!vrf) | |
592 | return NULL; | |
593 | ||
d62a17ae | 594 | p.family = AF_INET; |
595 | p.prefix = *addr; | |
596 | p.prefixlen = IPV4_MAX_BITLEN; | |
597 | ||
451fda4f | 598 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 599 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
600 | cp = connected->address; | |
601 | ||
602 | if (cp->family == AF_INET) | |
603 | if (prefix_match(cp, (struct prefix *)&p)) | |
604 | return ifp; | |
605 | } | |
718e3744 | 606 | } |
d62a17ae | 607 | return NULL; |
718e3744 | 608 | } |
609 | ||
d62a17ae | 610 | struct interface *if_lookup_by_ipv4_exact(struct in_addr *addr, vrf_id_t vrf_id) |
718e3744 | 611 | { |
f4e14fdb | 612 | struct vrf *vrf; |
d62a17ae | 613 | struct listnode *cnode; |
614 | struct interface *ifp; | |
615 | struct connected *connected; | |
616 | struct prefix *cp; | |
617 | ||
f4e14fdb RW |
618 | vrf = vrf_lookup_by_id(vrf_id); |
619 | if (!vrf) | |
620 | return NULL; | |
621 | ||
451fda4f | 622 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 623 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
624 | cp = connected->address; | |
625 | ||
626 | if (cp->family == AF_INET) | |
627 | if (IPV4_ADDR_SAME(&cp->u.prefix4, addr)) | |
628 | return ifp; | |
629 | } | |
718e3744 | 630 | } |
d62a17ae | 631 | return NULL; |
718e3744 | 632 | } |
633 | ||
d62a17ae | 634 | struct interface *if_lookup_by_ipv6(struct in6_addr *addr, ifindex_t ifindex, |
635 | vrf_id_t vrf_id) | |
718e3744 | 636 | { |
f4e14fdb | 637 | struct vrf *vrf; |
d62a17ae | 638 | struct listnode *cnode; |
639 | struct interface *ifp; | |
640 | struct connected *connected; | |
641 | struct prefix_ipv6 p; | |
642 | struct prefix *cp; | |
643 | ||
f4e14fdb RW |
644 | vrf = vrf_lookup_by_id(vrf_id); |
645 | if (!vrf) | |
646 | return NULL; | |
647 | ||
d62a17ae | 648 | p.family = AF_INET6; |
649 | p.prefix = *addr; | |
650 | p.prefixlen = IPV6_MAX_BITLEN; | |
651 | ||
451fda4f | 652 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 653 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
654 | cp = connected->address; | |
655 | ||
656 | if (cp->family == AF_INET6) | |
657 | if (prefix_match(cp, (struct prefix *)&p)) { | |
658 | if (IN6_IS_ADDR_LINKLOCAL( | |
659 | &cp->u.prefix6)) { | |
660 | if (ifindex == ifp->ifindex) | |
661 | return ifp; | |
662 | } else | |
663 | return ifp; | |
664 | } | |
665 | } | |
718e3744 | 666 | } |
d62a17ae | 667 | return NULL; |
718e3744 | 668 | } |
669 | ||
d62a17ae | 670 | struct interface *if_lookup_by_ipv6_exact(struct in6_addr *addr, |
671 | ifindex_t ifindex, vrf_id_t vrf_id) | |
718e3744 | 672 | { |
f4e14fdb | 673 | struct vrf *vrf; |
d62a17ae | 674 | struct listnode *cnode; |
675 | struct interface *ifp; | |
676 | struct connected *connected; | |
677 | struct prefix *cp; | |
678 | ||
f4e14fdb RW |
679 | vrf = vrf_lookup_by_id(vrf_id); |
680 | if (!vrf) | |
681 | return NULL; | |
682 | ||
451fda4f | 683 | FOR_ALL_INTERFACES (vrf, ifp) { |
d62a17ae | 684 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { |
685 | cp = connected->address; | |
686 | ||
687 | if (cp->family == AF_INET6) | |
688 | if (IPV6_ADDR_SAME(&cp->u.prefix6, addr)) { | |
689 | if (IN6_IS_ADDR_LINKLOCAL( | |
690 | &cp->u.prefix6)) { | |
691 | if (ifindex == ifp->ifindex) | |
692 | return ifp; | |
693 | } else | |
694 | return ifp; | |
695 | } | |
696 | } | |
718e3744 | 697 | } |
d62a17ae | 698 | return NULL; |
718e3744 | 699 | } |
700 | ||
d62a17ae | 701 | static int if_get_ipv6_global(struct interface *ifp, struct in6_addr *addr) |
718e3744 | 702 | { |
d62a17ae | 703 | struct listnode *cnode; |
704 | struct connected *connected; | |
705 | struct prefix *cp; | |
706 | ||
707 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
708 | cp = connected->address; | |
709 | ||
710 | if (cp->family == AF_INET6) | |
711 | if (!IN6_IS_ADDR_LINKLOCAL(&cp->u.prefix6)) { | |
712 | memcpy(addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); | |
713 | return 1; | |
714 | } | |
715 | } | |
716 | return 0; | |
718e3744 | 717 | } |
718 | ||
dac42f2e | 719 | static bool if_get_ipv6_local(struct interface *ifp, struct in6_addr *addr) |
718e3744 | 720 | { |
d62a17ae | 721 | struct listnode *cnode; |
722 | struct connected *connected; | |
723 | struct prefix *cp; | |
724 | ||
725 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
726 | cp = connected->address; | |
727 | ||
728 | if (cp->family == AF_INET6) | |
729 | if (IN6_IS_ADDR_LINKLOCAL(&cp->u.prefix6)) { | |
730 | memcpy(addr, &cp->u.prefix6, IPV6_MAX_BYTELEN); | |
dac42f2e | 731 | return true; |
d62a17ae | 732 | } |
733 | } | |
dac42f2e | 734 | return false; |
718e3744 | 735 | } |
718e3744 | 736 | |
d62a17ae | 737 | static int if_get_ipv4_address(struct interface *ifp, struct in_addr *addr) |
6ee06fa9 | 738 | { |
d62a17ae | 739 | struct listnode *cnode; |
740 | struct connected *connected; | |
741 | struct prefix *cp; | |
742 | ||
743 | for (ALL_LIST_ELEMENTS_RO(ifp->connected, cnode, connected)) { | |
744 | cp = connected->address; | |
745 | if ((cp->family == AF_INET) | |
746 | && !ipv4_martian(&(cp->u.prefix4))) { | |
747 | *addr = cp->u.prefix4; | |
748 | return 1; | |
749 | } | |
750 | } | |
751 | return 0; | |
6ee06fa9 PM |
752 | } |
753 | ||
17cdd31e DS |
754 | |
755 | bool bgp_zebra_nexthop_set(union sockunion *local, union sockunion *remote, | |
756 | struct bgp_nexthop *nexthop, struct peer *peer) | |
718e3744 | 757 | { |
d62a17ae | 758 | int ret = 0; |
759 | struct interface *ifp = NULL; | |
dac42f2e | 760 | bool v6_ll_avail = true; |
d62a17ae | 761 | |
762 | memset(nexthop, 0, sizeof(struct bgp_nexthop)); | |
763 | ||
764 | if (!local) | |
17cdd31e | 765 | return false; |
d62a17ae | 766 | if (!remote) |
17cdd31e | 767 | return false; |
d62a17ae | 768 | |
769 | if (local->sa.sa_family == AF_INET) { | |
770 | nexthop->v4 = local->sin.sin_addr; | |
771 | if (peer->update_if) | |
772 | ifp = if_lookup_by_name(peer->update_if, | |
a36898e7 | 773 | peer->bgp->vrf_id); |
d62a17ae | 774 | else |
775 | ifp = if_lookup_by_ipv4_exact(&local->sin.sin_addr, | |
776 | peer->bgp->vrf_id); | |
718e3744 | 777 | } |
d62a17ae | 778 | if (local->sa.sa_family == AF_INET6) { |
8f2b2139 | 779 | memcpy(&nexthop->v6_global, &local->sin6.sin6_addr, IPV6_MAX_BYTELEN); |
d62a17ae | 780 | if (IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr)) { |
781 | if (peer->conf_if || peer->ifname) | |
782 | ifp = if_lookup_by_name(peer->conf_if | |
783 | ? peer->conf_if | |
784 | : peer->ifname, | |
a36898e7 | 785 | peer->bgp->vrf_id); |
abe68054 PG |
786 | else if (peer->update_if) |
787 | ifp = if_lookup_by_name(peer->update_if, | |
788 | peer->bgp->vrf_id); | |
d62a17ae | 789 | } else if (peer->update_if) |
790 | ifp = if_lookup_by_name(peer->update_if, | |
a36898e7 | 791 | peer->bgp->vrf_id); |
d62a17ae | 792 | else |
793 | ifp = if_lookup_by_ipv6_exact(&local->sin6.sin6_addr, | |
794 | local->sin6.sin6_scope_id, | |
795 | peer->bgp->vrf_id); | |
718e3744 | 796 | } |
d62a17ae | 797 | |
17cdd31e DS |
798 | if (!ifp) { |
799 | /* | |
800 | * BGP views do not currently get proper data | |
801 | * from zebra( when attached ) to be able to | |
802 | * properly resolve nexthops, so give this | |
803 | * instance type a pass. | |
804 | */ | |
805 | if (peer->bgp->inst_type == BGP_INSTANCE_TYPE_VIEW) | |
806 | return true; | |
807 | /* | |
808 | * If we have no interface data but we have established | |
809 | * some connection w/ zebra than something has gone | |
810 | * terribly terribly wrong here, so say this failed | |
811 | * If we do not any zebra connection then not | |
812 | * having a ifp pointer is ok. | |
813 | */ | |
814 | return zclient_num_connects ? false : true; | |
815 | } | |
d62a17ae | 816 | |
817 | nexthop->ifp = ifp; | |
818 | ||
819 | /* IPv4 connection, fetch and store IPv6 local address(es) if any. */ | |
820 | if (local->sa.sa_family == AF_INET) { | |
821 | /* IPv6 nexthop*/ | |
822 | ret = if_get_ipv6_global(ifp, &nexthop->v6_global); | |
823 | ||
824 | if (!ret) { | |
825 | /* There is no global nexthop. Use link-local address as | |
826 | * both the | |
827 | * global and link-local nexthop. In this scenario, the | |
828 | * expectation | |
829 | * for interop is that the network admin would use a | |
830 | * route-map to | |
831 | * specify the global IPv6 nexthop. | |
832 | */ | |
dac42f2e DS |
833 | v6_ll_avail = |
834 | if_get_ipv6_local(ifp, &nexthop->v6_global); | |
d62a17ae | 835 | memcpy(&nexthop->v6_local, &nexthop->v6_global, |
836 | IPV6_MAX_BYTELEN); | |
837 | } else | |
dac42f2e DS |
838 | v6_ll_avail = |
839 | if_get_ipv6_local(ifp, &nexthop->v6_local); | |
d62a17ae | 840 | |
dac42f2e DS |
841 | /* |
842 | * If we are a v4 connection and we are not doing unnumbered | |
843 | * not having a v6 LL address is ok | |
844 | */ | |
845 | if (!v6_ll_avail && !peer->conf_if) | |
846 | v6_ll_avail = true; | |
d62a17ae | 847 | if (if_lookup_by_ipv4(&remote->sin.sin_addr, peer->bgp->vrf_id)) |
848 | peer->shared_network = 1; | |
849 | else | |
850 | peer->shared_network = 0; | |
718e3744 | 851 | } |
718e3744 | 852 | |
d62a17ae | 853 | /* IPv6 connection, fetch and store IPv4 local address if any. */ |
854 | if (local->sa.sa_family == AF_INET6) { | |
855 | struct interface *direct = NULL; | |
856 | ||
857 | /* IPv4 nexthop. */ | |
858 | ret = if_get_ipv4_address(ifp, &nexthop->v4); | |
975a328e | 859 | if (!ret && peer->local_id.s_addr != INADDR_ANY) |
d62a17ae | 860 | nexthop->v4 = peer->local_id; |
861 | ||
862 | /* Global address*/ | |
863 | if (!IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr)) { | |
864 | memcpy(&nexthop->v6_global, &local->sin6.sin6_addr, | |
865 | IPV6_MAX_BYTELEN); | |
866 | ||
867 | /* If directory connected set link-local address. */ | |
868 | direct = if_lookup_by_ipv6(&remote->sin6.sin6_addr, | |
869 | remote->sin6.sin6_scope_id, | |
870 | peer->bgp->vrf_id); | |
871 | if (direct) | |
dac42f2e DS |
872 | v6_ll_avail = if_get_ipv6_local( |
873 | ifp, &nexthop->v6_local); | |
2ebb354c IR |
874 | /* |
875 | * It's fine to not have a v6 LL when using | |
876 | * update-source loopback/vrf | |
877 | */ | |
878 | if (!v6_ll_avail && if_is_loopback_or_vrf(ifp)) | |
879 | v6_ll_avail = true; | |
d62a17ae | 880 | } else |
881 | /* Link-local address. */ | |
882 | { | |
883 | ret = if_get_ipv6_global(ifp, &nexthop->v6_global); | |
884 | ||
885 | /* If there is no global address. Set link-local | |
886 | address as | |
887 | global. I know this break RFC specification... */ | |
888 | /* In this scenario, the expectation for interop is that | |
889 | * the | |
890 | * network admin would use a route-map to specify the | |
891 | * global | |
892 | * IPv6 nexthop. | |
893 | */ | |
894 | if (!ret) | |
895 | memcpy(&nexthop->v6_global, | |
896 | &local->sin6.sin6_addr, | |
897 | IPV6_MAX_BYTELEN); | |
898 | /* Always set the link-local address */ | |
899 | memcpy(&nexthop->v6_local, &local->sin6.sin6_addr, | |
900 | IPV6_MAX_BYTELEN); | |
901 | } | |
902 | ||
903 | if (IN6_IS_ADDR_LINKLOCAL(&local->sin6.sin6_addr) | |
904 | || if_lookup_by_ipv6(&remote->sin6.sin6_addr, | |
905 | remote->sin6.sin6_scope_id, | |
906 | peer->bgp->vrf_id)) | |
907 | peer->shared_network = 1; | |
908 | else | |
909 | peer->shared_network = 0; | |
910 | } | |
718e3744 | 911 | |
d62a17ae | 912 | /* KAME stack specific treatment. */ |
718e3744 | 913 | #ifdef KAME |
d62a17ae | 914 | if (IN6_IS_ADDR_LINKLOCAL(&nexthop->v6_global) |
915 | && IN6_LINKLOCAL_IFINDEX(nexthop->v6_global)) { | |
916 | SET_IN6_LINKLOCAL_IFINDEX(nexthop->v6_global, 0); | |
917 | } | |
918 | if (IN6_IS_ADDR_LINKLOCAL(&nexthop->v6_local) | |
919 | && IN6_LINKLOCAL_IFINDEX(nexthop->v6_local)) { | |
920 | SET_IN6_LINKLOCAL_IFINDEX(nexthop->v6_local, 0); | |
921 | } | |
718e3744 | 922 | #endif /* KAME */ |
e33a4880 | 923 | |
d62a17ae | 924 | /* If we have identified the local interface, there is no error for now. |
925 | */ | |
dac42f2e | 926 | return v6_ll_avail; |
718e3744 | 927 | } |
928 | ||
18ee8310 | 929 | static struct in6_addr * |
40381db7 | 930 | bgp_path_info_to_ipv6_nexthop(struct bgp_path_info *path, ifindex_t *ifindex) |
73ac8160 | 931 | { |
d62a17ae | 932 | struct in6_addr *nexthop = NULL; |
933 | ||
934 | /* Only global address nexthop exists. */ | |
dc94fe42 RW |
935 | if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL |
936 | || path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_VPNV6_GLOBAL) { | |
40381db7 | 937 | nexthop = &path->attr->mp_nexthop_global; |
77e62f2b | 938 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 939 | *ifindex = path->attr->nh_ifindex; |
77e62f2b | 940 | } |
d62a17ae | 941 | |
942 | /* If both global and link-local address present. */ | |
dc94fe42 RW |
943 | if (path->attr->mp_nexthop_len == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL |
944 | || path->attr->mp_nexthop_len | |
945 | == BGP_ATTR_NHLEN_VPNV6_GLOBAL_AND_LL) { | |
d62a17ae | 946 | /* Check if route-map is set to prefer global over link-local */ |
40381db7 DS |
947 | if (path->attr->mp_nexthop_prefer_global) { |
948 | nexthop = &path->attr->mp_nexthop_global; | |
77e62f2b | 949 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 950 | *ifindex = path->attr->nh_ifindex; |
77e62f2b | 951 | } else { |
d62a17ae | 952 | /* Workaround for Cisco's nexthop bug. */ |
953 | if (IN6_IS_ADDR_UNSPECIFIED( | |
40381db7 | 954 | &path->attr->mp_nexthop_global) |
ab0e0f73 | 955 | && path->peer->su_remote |
40381db7 | 956 | && path->peer->su_remote->sa.sa_family |
59a0f1cb | 957 | == AF_INET6) { |
d62a17ae | 958 | nexthop = |
40381db7 | 959 | &path->peer->su_remote->sin6.sin6_addr; |
77e62f2b | 960 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 961 | *ifindex = path->peer->nexthop.ifp |
59a0f1cb | 962 | ->ifindex; |
77e62f2b | 963 | } else { |
40381db7 | 964 | nexthop = &path->attr->mp_nexthop_local; |
77e62f2b | 965 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) |
40381db7 | 966 | *ifindex = path->attr->nh_lla_ifindex; |
77e62f2b | 967 | } |
d62a17ae | 968 | } |
969 | } | |
970 | ||
971 | return nexthop; | |
73ac8160 DS |
972 | } |
973 | ||
b8685f9b | 974 | static bool bgp_table_map_apply(struct route_map *map, const struct prefix *p, |
3dc339cd | 975 | struct bgp_path_info *path) |
73ac8160 | 976 | { |
b4cb15c6 DL |
977 | route_map_result_t ret; |
978 | ||
1782514f | 979 | ret = route_map_apply(map, p, path); |
40381db7 | 980 | bgp_attr_flush(path->attr); |
b4cb15c6 DL |
981 | |
982 | if (ret != RMAP_DENYMATCH) | |
3dc339cd | 983 | return true; |
d62a17ae | 984 | |
985 | if (bgp_debug_zebra(p)) { | |
986 | if (p->family == AF_INET) { | |
d62a17ae | 987 | zlog_debug( |
c0d72166 DS |
988 | "Zebra rmap deny: IPv4 route %pFX nexthop %pI4", |
989 | p, &path->attr->nexthop); | |
d62a17ae | 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( |
8228a9a7 DS |
998 | "Zebra rmap deny: IPv6 route %pFX nexthop %s", |
999 | p, | |
6b9265a3 DA |
1000 | nexthop ? inet_ntop(AF_INET6, nexthop, buf[1], |
1001 | sizeof(buf[1])) | |
1002 | : inet_ntop(AF_INET, | |
1003 | &path->attr->nexthop, | |
1004 | buf[1], sizeof(buf[1]))); | |
d62a17ae | 1005 | } |
1006 | } | |
3dc339cd | 1007 | return false; |
73ac8160 DS |
1008 | } |
1009 | ||
b98f7728 PG |
1010 | static struct thread *bgp_tm_thread_connect; |
1011 | static bool bgp_tm_status_connected; | |
31c28cd7 PG |
1012 | static bool bgp_tm_chunk_obtained; |
1013 | #define BGP_FLOWSPEC_TABLE_CHUNK 100000 | |
1014 | static uint32_t bgp_tm_min, bgp_tm_max, bgp_tm_chunk_size; | |
6818e7e5 | 1015 | struct bgp *bgp_tm_bgp; |
b98f7728 PG |
1016 | |
1017 | static int bgp_zebra_tm_connect(struct thread *t) | |
1018 | { | |
1019 | struct zclient *zclient; | |
1020 | int delay = 10, ret = 0; | |
1021 | ||
1022 | zclient = THREAD_ARG(t); | |
1023 | if (bgp_tm_status_connected && zclient->sock > 0) | |
1024 | delay = 60; | |
1025 | else { | |
1026 | bgp_tm_status_connected = false; | |
1027 | ret = tm_table_manager_connect(zclient); | |
1028 | } | |
1029 | if (ret < 0) { | |
b7cd3069 | 1030 | zlog_info("Error connecting to table manager!"); |
b98f7728 PG |
1031 | bgp_tm_status_connected = false; |
1032 | } else { | |
1033 | if (!bgp_tm_status_connected) | |
1034 | zlog_debug("Connecting to table manager. Success"); | |
1035 | bgp_tm_status_connected = true; | |
31c28cd7 PG |
1036 | if (!bgp_tm_chunk_obtained) { |
1037 | if (bgp_zebra_get_table_range(bgp_tm_chunk_size, | |
1038 | &bgp_tm_min, | |
6818e7e5 | 1039 | &bgp_tm_max) >= 0) { |
31c28cd7 | 1040 | bgp_tm_chunk_obtained = true; |
6818e7e5 PG |
1041 | /* parse non installed entries */ |
1042 | bgp_zebra_announce_table(bgp_tm_bgp, AFI_IP, SAFI_FLOWSPEC); | |
1043 | } | |
31c28cd7 | 1044 | } |
b98f7728 PG |
1045 | } |
1046 | thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, | |
1047 | &bgp_tm_thread_connect); | |
1048 | return 0; | |
1049 | } | |
1050 | ||
6818e7e5 PG |
1051 | bool bgp_zebra_tm_chunk_obtained(void) |
1052 | { | |
1053 | return bgp_tm_chunk_obtained; | |
1054 | } | |
1055 | ||
31c28cd7 PG |
1056 | uint32_t bgp_zebra_tm_get_id(void) |
1057 | { | |
1058 | static int table_id; | |
1059 | ||
1060 | if (!bgp_tm_chunk_obtained) | |
1061 | return ++table_id; | |
1062 | return bgp_tm_min++; | |
1063 | } | |
1064 | ||
6818e7e5 | 1065 | void bgp_zebra_init_tm_connect(struct bgp *bgp) |
b98f7728 PG |
1066 | { |
1067 | int delay = 1; | |
1068 | ||
1069 | /* if already set, do nothing | |
1070 | */ | |
1071 | if (bgp_tm_thread_connect != NULL) | |
1072 | return; | |
1073 | bgp_tm_status_connected = false; | |
31c28cd7 PG |
1074 | bgp_tm_chunk_obtained = false; |
1075 | bgp_tm_min = bgp_tm_max = 0; | |
1076 | bgp_tm_chunk_size = BGP_FLOWSPEC_TABLE_CHUNK; | |
6818e7e5 | 1077 | bgp_tm_bgp = bgp; |
b98f7728 PG |
1078 | thread_add_timer(bm->master, bgp_zebra_tm_connect, zclient, delay, |
1079 | &bgp_tm_thread_connect); | |
1080 | } | |
1081 | ||
1082 | int bgp_zebra_get_table_range(uint32_t chunk_size, | |
1083 | uint32_t *start, uint32_t *end) | |
1084 | { | |
1085 | int ret; | |
1086 | ||
1087 | if (!bgp_tm_status_connected) | |
1088 | return -1; | |
1089 | ret = tm_get_table_chunk(zclient, chunk_size, start, end); | |
1090 | if (ret < 0) { | |
e50f7cfd | 1091 | flog_err(EC_BGP_TABLE_CHUNK, |
1c50c1c0 | 1092 | "BGP: Error getting table chunk %u", chunk_size); |
b98f7728 PG |
1093 | return -1; |
1094 | } | |
1095 | zlog_info("BGP: Table Manager returns range from chunk %u is [%u %u]", | |
1096 | chunk_size, *start, *end); | |
1097 | return 0; | |
1098 | } | |
1099 | ||
3dc339cd DA |
1100 | static bool update_ipv4nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, |
1101 | struct in_addr *nexthop, | |
1102 | struct attr *attr, bool is_evpn, | |
1103 | struct zapi_nexthop *api_nh) | |
77e62f2b | 1104 | { |
1105 | api_nh->gate.ipv4 = *nexthop; | |
e1e71450 | 1106 | api_nh->vrf_id = nh_bgp->vrf_id; |
77e62f2b | 1107 | |
1108 | /* Need to set fields appropriately for EVPN routes imported into | |
1109 | * a VRF (which are programmed as onlink on l3-vni SVI) as well as | |
1110 | * connected routes leaked into a VRF. | |
1111 | */ | |
0789eb69 KM |
1112 | if (attr->nh_type == NEXTHOP_TYPE_BLACKHOLE) { |
1113 | api_nh->type = attr->nh_type; | |
1114 | api_nh->bh_type = attr->bh_type; | |
1115 | } else if (is_evpn) { | |
a2299aba AD |
1116 | /* |
1117 | * If the nexthop is EVPN overlay index gateway IP, | |
1118 | * treat the nexthop as NEXTHOP_TYPE_IPV4 | |
1119 | * Else, mark the nexthop as onlink. | |
1120 | */ | |
1121 | if (attr->evpn_overlay.type == OVERLAY_INDEX_GATEWAY_IP) | |
1122 | api_nh->type = NEXTHOP_TYPE_IPV4; | |
1123 | else { | |
1124 | api_nh->type = NEXTHOP_TYPE_IPV4_IFINDEX; | |
1125 | SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_ONLINK); | |
1126 | api_nh->ifindex = nh_bgp->l3vni_svi_ifindex; | |
1127 | } | |
0789eb69 | 1128 | } else if (nh_othervrf && api_nh->gate.ipv4.s_addr == INADDR_ANY) { |
77e62f2b | 1129 | api_nh->type = NEXTHOP_TYPE_IFINDEX; |
1130 | api_nh->ifindex = attr->nh_ifindex; | |
1131 | } else | |
1132 | api_nh->type = NEXTHOP_TYPE_IPV4; | |
1133 | ||
3dc339cd | 1134 | return true; |
77e62f2b | 1135 | } |
1136 | ||
3dc339cd DA |
1137 | static bool update_ipv6nh_for_route_install(int nh_othervrf, struct bgp *nh_bgp, |
1138 | struct in6_addr *nexthop, | |
1139 | ifindex_t ifindex, | |
1140 | struct bgp_path_info *pi, | |
1141 | struct bgp_path_info *best_pi, | |
1142 | bool is_evpn, | |
1143 | struct zapi_nexthop *api_nh) | |
77e62f2b | 1144 | { |
1145 | struct attr *attr; | |
1146 | ||
40381db7 | 1147 | attr = pi->attr; |
e1e71450 | 1148 | api_nh->vrf_id = nh_bgp->vrf_id; |
77e62f2b | 1149 | |
0789eb69 KM |
1150 | if (attr->nh_type == NEXTHOP_TYPE_BLACKHOLE) { |
1151 | api_nh->type = attr->nh_type; | |
1152 | api_nh->bh_type = attr->bh_type; | |
1153 | } else if (is_evpn) { | |
a2299aba AD |
1154 | /* |
1155 | * If the nexthop is EVPN overlay index gateway IP, | |
1156 | * treat the nexthop as NEXTHOP_TYPE_IPV4 | |
1157 | * Else, mark the nexthop as onlink. | |
1158 | */ | |
1159 | if (attr->evpn_overlay.type == OVERLAY_INDEX_GATEWAY_IP) | |
1160 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
1161 | else { | |
1162 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; | |
1163 | SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_ONLINK); | |
1164 | api_nh->ifindex = nh_bgp->l3vni_svi_ifindex; | |
1165 | } | |
e1e71450 | 1166 | } else if (nh_othervrf) { |
77e62f2b | 1167 | if (IN6_IS_ADDR_UNSPECIFIED(nexthop)) { |
1168 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
1169 | api_nh->ifindex = attr->nh_ifindex; | |
1170 | } else if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { | |
1171 | if (ifindex == 0) | |
3dc339cd | 1172 | return false; |
77e62f2b | 1173 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; |
1174 | api_nh->ifindex = ifindex; | |
1175 | } else { | |
1176 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
1177 | api_nh->ifindex = 0; | |
1178 | } | |
1179 | } else { | |
1180 | if (IN6_IS_ADDR_LINKLOCAL(nexthop)) { | |
40381db7 DS |
1181 | if (pi == best_pi |
1182 | && attr->mp_nexthop_len | |
1183 | == BGP_ATTR_NHLEN_IPV6_GLOBAL_AND_LL) | |
1184 | if (pi->peer->nexthop.ifp) | |
1185 | ifindex = | |
1186 | pi->peer->nexthop.ifp->ifindex; | |
77e62f2b | 1187 | if (!ifindex) { |
40381db7 DS |
1188 | if (pi->peer->conf_if) |
1189 | ifindex = pi->peer->ifp->ifindex; | |
1190 | else if (pi->peer->ifname) | |
77e62f2b | 1191 | ifindex = ifname2ifindex( |
40381db7 DS |
1192 | pi->peer->ifname, |
1193 | pi->peer->bgp->vrf_id); | |
1194 | else if (pi->peer->nexthop.ifp) | |
1195 | ifindex = | |
1196 | pi->peer->nexthop.ifp->ifindex; | |
77e62f2b | 1197 | } |
1198 | ||
1199 | if (ifindex == 0) | |
3dc339cd | 1200 | return false; |
77e62f2b | 1201 | api_nh->type = NEXTHOP_TYPE_IPV6_IFINDEX; |
1202 | api_nh->ifindex = ifindex; | |
1203 | } else { | |
1204 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
1205 | api_nh->ifindex = 0; | |
1206 | } | |
1207 | } | |
0789eb69 KM |
1208 | /* api_nh structure has union of gate and bh_type */ |
1209 | if (nexthop && api_nh->type != NEXTHOP_TYPE_BLACKHOLE) | |
c2ca3e25 | 1210 | api_nh->gate.ipv6 = *nexthop; |
77e62f2b | 1211 | |
3dc339cd | 1212 | return true; |
77e62f2b | 1213 | } |
1214 | ||
f7e1c681 | 1215 | static bool bgp_zebra_use_nhop_weighted(struct bgp *bgp, struct attr *attr, |
1216 | uint64_t tot_bw, uint32_t *nh_weight) | |
4e30bc2b | 1217 | { |
f7e1c681 | 1218 | uint32_t bw; |
1219 | uint64_t tmp; | |
1220 | ||
1221 | bw = attr->link_bw; | |
1222 | /* zero link-bandwidth and link-bandwidth not present are treated | |
1223 | * as the same situation. | |
1224 | */ | |
1225 | if (!bw) { | |
1226 | /* the only situations should be if we're either told | |
1227 | * to skip or use default weight. | |
1228 | */ | |
1229 | if (bgp->lb_handling == BGP_LINK_BW_SKIP_MISSING) | |
1230 | return false; | |
1231 | *nh_weight = BGP_ZEBRA_DEFAULT_NHOP_WEIGHT; | |
1232 | } else { | |
1233 | tmp = (uint64_t)bw * 100; | |
1234 | *nh_weight = ((uint32_t)(tmp / tot_bw)); | |
1235 | } | |
1236 | ||
1237 | return true; | |
4e30bc2b | 1238 | } |
1239 | ||
9bcb3eef | 1240 | void bgp_zebra_announce(struct bgp_dest *dest, const struct prefix *p, |
4b7e6066 | 1241 | struct bgp_path_info *info, struct bgp *bgp, afi_t afi, |
d62a17ae | 1242 | safi_t safi) |
718e3744 | 1243 | { |
7cc27d41 | 1244 | struct zapi_route api = { 0 }; |
9913029c | 1245 | struct zapi_nexthop *api_nh; |
2ad4f093 | 1246 | int nh_family; |
a74e593b | 1247 | unsigned int valid_nh_count = 0; |
1a9cb083 | 1248 | bool allow_recursion = false; |
d7c0a89a | 1249 | uint8_t distance; |
d62a17ae | 1250 | struct peer *peer; |
4b7e6066 | 1251 | struct bgp_path_info *mpinfo; |
d7c0a89a | 1252 | uint32_t metric; |
b4cb15c6 | 1253 | struct attr local_attr; |
4b7e6066 DS |
1254 | struct bgp_path_info local_info; |
1255 | struct bgp_path_info *mpinfo_cp = &local_info; | |
d62a17ae | 1256 | route_tag_t tag; |
1257 | mpls_label_t label; | |
ddb5b488 | 1258 | int nh_othervrf = 0; |
3f54c705 | 1259 | bool is_evpn; |
06f16b2c | 1260 | bool nh_updated = false; |
4e30bc2b | 1261 | bool do_wt_ecmp; |
1262 | uint64_t cum_bw = 0; | |
6348981a AK |
1263 | uint32_t nhg_id = 0; |
1264 | bool is_add; | |
d62a17ae | 1265 | |
1266 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't | |
1267 | * know of this instance. | |
1268 | */ | |
1269 | if (!bgp_install_info_to_zebra(bgp)) | |
1270 | return; | |
1271 | ||
d62a17ae | 1272 | if (bgp->main_zebra_update_hold) |
1273 | return; | |
1274 | ||
d90b788e | 1275 | if (safi == SAFI_FLOWSPEC) { |
9bcb3eef DS |
1276 | bgp_pbr_update_entry(bgp, bgp_dest_get_prefix(dest), info, afi, |
1277 | safi, true); | |
d90b788e A |
1278 | return; |
1279 | } | |
529efa23 | 1280 | |
ddb5b488 PZ |
1281 | /* |
1282 | * vrf leaking support (will have only one nexthop) | |
1283 | */ | |
1284 | if (info->extra && info->extra->bgp_orig) | |
1285 | nh_othervrf = 1; | |
1286 | ||
9913029c | 1287 | /* Make Zebra API structure. */ |
9913029c RW |
1288 | api.vrf_id = bgp->vrf_id; |
1289 | api.type = ZEBRA_ROUTE_BGP; | |
1290 | api.safi = safi; | |
1291 | api.prefix = *p; | |
1292 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); | |
1293 | ||
d62a17ae | 1294 | peer = info->peer; |
1295 | ||
ddb5b488 PZ |
1296 | if (info->type == ZEBRA_ROUTE_BGP |
1297 | && info->sub_type == BGP_ROUTE_IMPORTED) { | |
1298 | ||
1ec90b5e | 1299 | /* Obtain peer from parent */ |
1300 | if (info->extra && info->extra->parent) | |
4b7e6066 DS |
1301 | peer = ((struct bgp_path_info *)(info->extra->parent)) |
1302 | ->peer; | |
ddb5b488 PZ |
1303 | } |
1304 | ||
d62a17ae | 1305 | tag = info->attr->tag; |
1306 | ||
88493076 | 1307 | /* If the route's source is EVPN, flag as such. */ |
77e62f2b | 1308 | is_evpn = is_route_parent_evpn(info); |
1309 | if (is_evpn) | |
90264d64 | 1310 | SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); |
d3135ba3 | 1311 | |
d62a17ae | 1312 | if (peer->sort == BGP_PEER_IBGP || peer->sort == BGP_PEER_CONFED |
1313 | || info->sub_type == BGP_ROUTE_AGGREGATE) { | |
9913029c | 1314 | SET_FLAG(api.flags, ZEBRA_FLAG_IBGP); |
4e8b02f4 | 1315 | SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); |
718e3744 | 1316 | } |
a39275d7 | 1317 | |
c8d6f0d6 | 1318 | if ((peer->sort == BGP_PEER_EBGP && peer->ttl != BGP_DEFAULT_TTL) |
d62a17ae | 1319 | || CHECK_FLAG(peer->flags, PEER_FLAG_DISABLE_CONNECTED_CHECK) |
892fedb6 | 1320 | || CHECK_FLAG(bgp->flags, BGP_FLAG_DISABLE_NH_CONNECTED_CHK)) |
d62a17ae | 1321 | |
1a9cb083 | 1322 | allow_recursion = true; |
d62a17ae | 1323 | |
951745bd PG |
1324 | if (info->attr->rmap_table_id) { |
1325 | SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); | |
1326 | api.tableid = info->attr->rmap_table_id; | |
1327 | } | |
1328 | ||
ef3e0d04 SM |
1329 | if (CHECK_FLAG(info->attr->flag, ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) |
1330 | SET_FLAG(api.message, ZAPI_MESSAGE_SRTE); | |
1331 | ||
2ad4f093 RW |
1332 | /* Metric is currently based on the best-path only */ |
1333 | metric = info->attr->med; | |
4e30bc2b | 1334 | |
1335 | /* Determine if we're doing weighted ECMP or not */ | |
f7e1c681 | 1336 | do_wt_ecmp = bgp_path_info_mpath_chkwtd(bgp, info); |
4e30bc2b | 1337 | if (do_wt_ecmp) |
1338 | cum_bw = bgp_path_info_mpath_cumbw(info); | |
1339 | ||
6348981a | 1340 | /* EVPN MAC-IP routes are installed with a L3 NHG id */ |
8bcb09a1 | 1341 | if (bgp_evpn_path_es_use_nhg(bgp, info, &nhg_id)) { |
6348981a | 1342 | mpinfo = NULL; |
8bcb09a1 AK |
1343 | api.nhgid = nhg_id; |
1344 | if (nhg_id) | |
1345 | SET_FLAG(api.message, ZAPI_MESSAGE_NHG); | |
1346 | } else { | |
6348981a | 1347 | mpinfo = info; |
8bcb09a1 | 1348 | } |
6348981a AK |
1349 | |
1350 | for (; mpinfo; mpinfo = bgp_path_info_mpath_next(mpinfo)) { | |
f7e1c681 | 1351 | uint32_t nh_weight; |
1352 | ||
a74e593b RW |
1353 | if (valid_nh_count >= multipath_num) |
1354 | break; | |
1355 | ||
b4cb15c6 | 1356 | *mpinfo_cp = *mpinfo; |
f7e1c681 | 1357 | nh_weight = 0; |
b4cb15c6 | 1358 | |
d0d695f4 RW |
1359 | /* Get nexthop address-family */ |
1360 | if (p->family == AF_INET | |
1361 | && !BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp->attr)) | |
1362 | nh_family = AF_INET; | |
1363 | else if (p->family == AF_INET6 | |
1364 | || (p->family == AF_INET | |
1365 | && BGP_ATTR_NEXTHOP_AFI_IP6(mpinfo_cp->attr))) | |
1366 | nh_family = AF_INET6; | |
1367 | else | |
1368 | continue; | |
1369 | ||
f7e1c681 | 1370 | /* If processing for weighted ECMP, determine the next hop's |
1371 | * weight. Based on user setting, we may skip the next hop | |
1372 | * in some situations. | |
1373 | */ | |
1374 | if (do_wt_ecmp) { | |
1375 | if (!bgp_zebra_use_nhop_weighted(bgp, mpinfo->attr, | |
1376 | cum_bw, &nh_weight)) | |
1377 | continue; | |
1378 | } | |
1374aec9 | 1379 | api_nh = &api.nexthops[valid_nh_count]; |
ef3e0d04 SM |
1380 | |
1381 | if (CHECK_FLAG(info->attr->flag, | |
1382 | ATTR_FLAG_BIT(BGP_ATTR_SRTE_COLOR))) | |
1383 | api_nh->srte_color = info->attr->srte_color; | |
1384 | ||
257b7b6e DS |
1385 | if (bgp_debug_zebra(&api.prefix)) { |
1386 | if (mpinfo->extra) { | |
70492dea DS |
1387 | zlog_debug("%s: p=%pFX, bgp_is_valid_label: %d", |
1388 | __func__, p, | |
257b7b6e DS |
1389 | bgp_is_valid_label( |
1390 | &mpinfo->extra->label[0])); | |
1391 | } else { | |
70492dea DS |
1392 | zlog_debug( |
1393 | "%s: p=%pFX, extra is NULL, no label", | |
1394 | __func__, p); | |
ddb5b488 | 1395 | } |
257b7b6e | 1396 | } |
ddb5b488 | 1397 | |
257b7b6e DS |
1398 | if (bgp->table_map[afi][safi].name) { |
1399 | /* Copy info and attributes, so the route-map | |
1400 | apply doesn't modify the BGP route info. */ | |
1401 | local_attr = *mpinfo->attr; | |
1402 | mpinfo_cp->attr = &local_attr; | |
1403 | if (!bgp_table_map_apply(bgp->table_map[afi][safi].map, | |
1404 | p, mpinfo_cp)) | |
1405 | continue; | |
b4cb15c6 | 1406 | |
257b7b6e DS |
1407 | /* metric/tag is only allowed to be |
1408 | * overridden on 1st nexthop */ | |
1409 | if (mpinfo == info) { | |
1410 | metric = mpinfo_cp->attr->med; | |
1411 | tag = mpinfo_cp->attr->tag; | |
b4cb15c6 | 1412 | } |
257b7b6e | 1413 | } |
d62a17ae | 1414 | |
257b7b6e | 1415 | if (nh_family == AF_INET) { |
77e62f2b | 1416 | nh_updated = update_ipv4nh_for_route_install( |
1417 | nh_othervrf, | |
e1e71450 | 1418 | nh_othervrf ? |
1419 | info->extra->bgp_orig : bgp, | |
77e62f2b | 1420 | &mpinfo_cp->attr->nexthop, |
1421 | mpinfo_cp->attr, is_evpn, api_nh); | |
2ad4f093 | 1422 | } else { |
f220da99 | 1423 | ifindex_t ifindex = IFINDEX_INTERNAL; |
2ad4f093 | 1424 | struct in6_addr *nexthop; |
9913029c | 1425 | |
18ee8310 DS |
1426 | nexthop = bgp_path_info_to_ipv6_nexthop(mpinfo_cp, |
1427 | &ifindex); | |
00c10664 DA |
1428 | |
1429 | if (!nexthop) | |
1430 | nh_updated = update_ipv4nh_for_route_install( | |
1431 | nh_othervrf, | |
1432 | nh_othervrf ? info->extra->bgp_orig | |
1433 | : bgp, | |
1434 | &mpinfo_cp->attr->nexthop, | |
1435 | mpinfo_cp->attr, is_evpn, api_nh); | |
1436 | else | |
1437 | nh_updated = update_ipv6nh_for_route_install( | |
1438 | nh_othervrf, | |
1439 | nh_othervrf ? info->extra->bgp_orig | |
1440 | : bgp, | |
1441 | nexthop, ifindex, mpinfo, info, is_evpn, | |
1442 | api_nh); | |
2ad4f093 | 1443 | } |
d62a17ae | 1444 | |
77e62f2b | 1445 | /* Did we get proper nexthop info to update zebra? */ |
1446 | if (!nh_updated) | |
1447 | continue; | |
1448 | ||
1a9cb083 JM |
1449 | /* Allow recursion if it is a multipath group with both |
1450 | * eBGP and iBGP paths. | |
1451 | */ | |
1452 | if (!allow_recursion | |
1453 | && CHECK_FLAG(bgp->flags, BGP_FLAG_PEERTYPE_MULTIPATH_RELAX) | |
1454 | && (mpinfo->peer->sort == BGP_PEER_IBGP | |
1455 | || mpinfo->peer->sort == BGP_PEER_CONFED)) | |
1456 | allow_recursion = true; | |
1457 | ||
a4d82a8a PZ |
1458 | if (mpinfo->extra |
1459 | && bgp_is_valid_label(&mpinfo->extra->label[0]) | |
90264d64 | 1460 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { |
b57ba6d2 | 1461 | label = label_pton(&mpinfo->extra->label[0]); |
9913029c | 1462 | |
68a02e06 MS |
1463 | SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL); |
1464 | ||
2ad4f093 RW |
1465 | api_nh->label_num = 1; |
1466 | api_nh->labels[0] = label; | |
d62a17ae | 1467 | } |
a2299aba AD |
1468 | |
1469 | if (is_evpn | |
1470 | && mpinfo->attr->evpn_overlay.type | |
1471 | != OVERLAY_INDEX_GATEWAY_IP) | |
1472 | memcpy(&api_nh->rmac, &(mpinfo->attr->rmac), | |
1473 | sizeof(struct ethaddr)); | |
1474 | ||
f7e1c681 | 1475 | api_nh->weight = nh_weight; |
4e30bc2b | 1476 | |
16f3db2d | 1477 | if (mpinfo->extra && !sid_zero(&mpinfo->extra->sid[0].sid) |
53a4de82 | 1478 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { |
16f3db2d | 1479 | memcpy(&api_nh->seg6_segs, &mpinfo->extra->sid[0].sid, |
53a4de82 | 1480 | sizeof(api_nh->seg6_segs)); |
09e06fcf RS |
1481 | |
1482 | SET_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6); | |
53a4de82 HS |
1483 | } |
1484 | ||
2ad4f093 RW |
1485 | valid_nh_count++; |
1486 | } | |
d62a17ae | 1487 | |
6348981a AK |
1488 | is_add = (valid_nh_count || nhg_id) ? true : false; |
1489 | ||
ec0acb80 | 1490 | if (is_add && CHECK_FLAG(bm->flags, BM_FLAG_SEND_EXTRA_DATA_TO_ZEBRA)) { |
94effaf0 | 1491 | struct bgp_zebra_opaque bzo = {}; |
1d7260a1 DA |
1492 | const char *reason = |
1493 | bgp_path_selection_reason2str(dest->reason); | |
94effaf0 DA |
1494 | |
1495 | strlcpy(bzo.aspath, info->attr->aspath->str, | |
1496 | sizeof(bzo.aspath)); | |
1497 | ||
1498 | if (info->attr->flag & ATTR_FLAG_BIT(BGP_ATTR_COMMUNITIES)) | |
1499 | strlcpy(bzo.community, info->attr->community->str, | |
1500 | sizeof(bzo.community)); | |
1501 | ||
1502 | if (info->attr->flag | |
1503 | & ATTR_FLAG_BIT(BGP_ATTR_LARGE_COMMUNITIES)) | |
1504 | strlcpy(bzo.lcommunity, info->attr->lcommunity->str, | |
1505 | sizeof(bzo.lcommunity)); | |
e46723a5 | 1506 | |
1d7260a1 DA |
1507 | strlcpy(bzo.selection_reason, reason, |
1508 | sizeof(bzo.selection_reason)); | |
1509 | ||
e46723a5 | 1510 | SET_FLAG(api.message, ZAPI_MESSAGE_OPAQUE); |
94effaf0 DA |
1511 | api.opaque.length = MIN(sizeof(struct bgp_zebra_opaque), |
1512 | ZAPI_MESSAGE_OPAQUE_LENGTH); | |
1513 | memcpy(api.opaque.data, &bzo, api.opaque.length); | |
e46723a5 DS |
1514 | } |
1515 | ||
1a9cb083 JM |
1516 | if (allow_recursion) |
1517 | SET_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION); | |
1518 | ||
5cc347c4 DS |
1519 | /* |
1520 | * When we create an aggregate route we must also | |
1521 | * install a Null0 route in the RIB, so overwrite | |
1522 | * what was written into api with a blackhole route | |
1523 | */ | |
1524 | if (info->sub_type == BGP_ROUTE_AGGREGATE) | |
1525 | zapi_route_set_blackhole(&api, BLACKHOLE_NULL); | |
1526 | else | |
2ad4f093 | 1527 | api.nexthop_num = valid_nh_count; |
d62a17ae | 1528 | |
2ad4f093 RW |
1529 | SET_FLAG(api.message, ZAPI_MESSAGE_METRIC); |
1530 | api.metric = metric; | |
d62a17ae | 1531 | |
2ad4f093 RW |
1532 | if (tag) { |
1533 | SET_FLAG(api.message, ZAPI_MESSAGE_TAG); | |
1534 | api.tag = tag; | |
1535 | } | |
d62a17ae | 1536 | |
2ad4f093 RW |
1537 | distance = bgp_distance_apply(p, info, afi, safi, bgp); |
1538 | if (distance) { | |
1539 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); | |
1540 | api.distance = distance; | |
1541 | } | |
d62a17ae | 1542 | |
2ad4f093 | 1543 | if (bgp_debug_zebra(p)) { |
2ad4f093 | 1544 | char nh_buf[INET6_ADDRSTRLEN]; |
d8744f72 CS |
1545 | char eth_buf[ETHER_ADDR_STRLEN + 7] = {'\0'}; |
1546 | char buf1[ETHER_ADDR_STRLEN]; | |
2ad4f093 | 1547 | char label_buf[20]; |
53a4de82 HS |
1548 | char sid_buf[20]; |
1549 | char segs_buf[256]; | |
2ad4f093 RW |
1550 | int i; |
1551 | ||
2dbe669b DA |
1552 | zlog_debug( |
1553 | "Tx route %s VRF %u %pFX metric %u tag %" ROUTE_TAG_PRI | |
6348981a | 1554 | " count %d nhg %d", |
2dbe669b | 1555 | valid_nh_count ? "add" : "delete", bgp->vrf_id, |
6348981a AK |
1556 | &api.prefix, api.metric, api.tag, api.nexthop_num, |
1557 | nhg_id); | |
2ad4f093 RW |
1558 | for (i = 0; i < api.nexthop_num; i++) { |
1559 | api_nh = &api.nexthops[i]; | |
1560 | ||
1ee069db CS |
1561 | switch (api_nh->type) { |
1562 | case NEXTHOP_TYPE_IFINDEX: | |
77e62f2b | 1563 | nh_buf[0] = '\0'; |
1ee069db CS |
1564 | break; |
1565 | case NEXTHOP_TYPE_IPV4: | |
1566 | case NEXTHOP_TYPE_IPV4_IFINDEX: | |
1567 | nh_family = AF_INET; | |
77e62f2b | 1568 | inet_ntop(nh_family, &api_nh->gate, nh_buf, |
1569 | sizeof(nh_buf)); | |
1ee069db CS |
1570 | break; |
1571 | case NEXTHOP_TYPE_IPV6: | |
1572 | case NEXTHOP_TYPE_IPV6_IFINDEX: | |
1573 | nh_family = AF_INET6; | |
1574 | inet_ntop(nh_family, &api_nh->gate, nh_buf, | |
1575 | sizeof(nh_buf)); | |
1576 | break; | |
1577 | case NEXTHOP_TYPE_BLACKHOLE: | |
1578 | strlcpy(nh_buf, "blackhole", sizeof(nh_buf)); | |
1579 | break; | |
1580 | default: | |
1581 | /* Note: add new nexthop case */ | |
1582 | assert(0); | |
1583 | break; | |
77e62f2b | 1584 | } |
2ad4f093 RW |
1585 | |
1586 | label_buf[0] = '\0'; | |
d8744f72 | 1587 | eth_buf[0] = '\0'; |
bbf32574 | 1588 | segs_buf[0] = '\0'; |
cd18af00 | 1589 | if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_LABEL) |
a4d82a8a | 1590 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) |
a7799788 CS |
1591 | snprintf(label_buf, sizeof(label_buf), |
1592 | "label %u", api_nh->labels[0]); | |
09e06fcf | 1593 | if (CHECK_FLAG(api_nh->flags, ZAPI_NEXTHOP_FLAG_SEG6) |
53a4de82 HS |
1594 | && !CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE)) { |
1595 | inet_ntop(AF_INET6, &api_nh->seg6_segs, | |
1596 | sid_buf, sizeof(sid_buf)); | |
1597 | snprintf(segs_buf, sizeof(segs_buf), "segs %s", | |
1598 | sid_buf); | |
1599 | } | |
d8744f72 CS |
1600 | if (CHECK_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE) |
1601 | && !is_zero_mac(&api_nh->rmac)) | |
a7799788 CS |
1602 | snprintf(eth_buf, sizeof(eth_buf), " RMAC %s", |
1603 | prefix_mac2str(&api_nh->rmac, | |
1604 | buf1, sizeof(buf1))); | |
53a4de82 | 1605 | zlog_debug(" nhop [%d]: %s if %u VRF %u wt %u %s %s %s", |
77e62f2b | 1606 | i + 1, nh_buf, api_nh->ifindex, |
4e30bc2b | 1607 | api_nh->vrf_id, api_nh->weight, |
53a4de82 | 1608 | label_buf, segs_buf, eth_buf); |
d62a17ae | 1609 | } |
2ad4f093 | 1610 | |
960035b2 PZ |
1611 | int recursion_flag = 0; |
1612 | ||
1613 | if (CHECK_FLAG(api.flags, ZEBRA_FLAG_ALLOW_RECURSION)) | |
1614 | recursion_flag = 1; | |
1615 | ||
70492dea DS |
1616 | zlog_debug("%s: %pFX: announcing to zebra (recursion %sset)", |
1617 | __func__, p, (recursion_flag ? "" : "NOT ")); | |
960035b2 | 1618 | } |
6348981a | 1619 | zclient_route_send(is_add ? ZEBRA_ROUTE_ADD : ZEBRA_ROUTE_DELETE, |
2ad4f093 | 1620 | zclient, &api); |
718e3744 | 1621 | } |
1622 | ||
73ac8160 | 1623 | /* Announce all routes of a table to zebra */ |
d62a17ae | 1624 | void bgp_zebra_announce_table(struct bgp *bgp, afi_t afi, safi_t safi) |
73ac8160 | 1625 | { |
9bcb3eef | 1626 | struct bgp_dest *dest; |
d62a17ae | 1627 | struct bgp_table *table; |
40381db7 | 1628 | struct bgp_path_info *pi; |
d62a17ae | 1629 | |
1630 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't | |
1631 | * know of this instance. | |
1632 | */ | |
1633 | if (!bgp_install_info_to_zebra(bgp)) | |
1634 | return; | |
1635 | ||
1636 | table = bgp->rib[afi][safi]; | |
1637 | if (!table) | |
1638 | return; | |
1639 | ||
9bcb3eef DS |
1640 | for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) |
1641 | for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) | |
40381db7 | 1642 | if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && |
ddb5b488 | 1643 | |
40381db7 DS |
1644 | (pi->type == ZEBRA_ROUTE_BGP |
1645 | && (pi->sub_type == BGP_ROUTE_NORMAL | |
1646 | || pi->sub_type == BGP_ROUTE_IMPORTED))) | |
ddb5b488 | 1647 | |
9bcb3eef DS |
1648 | bgp_zebra_announce(dest, |
1649 | bgp_dest_get_prefix(dest), | |
b54892e0 | 1650 | pi, bgp, afi, safi); |
73ac8160 DS |
1651 | } |
1652 | ||
c163f297 DS |
1653 | /* Announce routes of any bgp subtype of a table to zebra */ |
1654 | void bgp_zebra_announce_table_all_subtypes(struct bgp *bgp, afi_t afi, | |
1655 | safi_t safi) | |
1656 | { | |
1657 | struct bgp_dest *dest; | |
1658 | struct bgp_table *table; | |
1659 | struct bgp_path_info *pi; | |
1660 | ||
1661 | if (!bgp_install_info_to_zebra(bgp)) | |
1662 | return; | |
1663 | ||
1664 | table = bgp->rib[afi][safi]; | |
1665 | if (!table) | |
1666 | return; | |
1667 | ||
1668 | for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) | |
1669 | for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) | |
1670 | if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) && | |
1671 | pi->type == ZEBRA_ROUTE_BGP) | |
1672 | bgp_zebra_announce(dest, | |
1673 | bgp_dest_get_prefix(dest), | |
1674 | pi, bgp, afi, safi); | |
1675 | } | |
1676 | ||
5a1ae2c2 | 1677 | void bgp_zebra_withdraw(const struct prefix *p, struct bgp_path_info *info, |
568e10ca | 1678 | struct bgp *bgp, safi_t safi) |
718e3744 | 1679 | { |
2ad4f093 | 1680 | struct zapi_route api; |
f7df1907 | 1681 | struct peer *peer; |
ddb5b488 | 1682 | |
d62a17ae | 1683 | /* Don't try to install if we're not connected to Zebra or Zebra doesn't |
1684 | * know of this instance. | |
1685 | */ | |
568e10ca | 1686 | if (!bgp_install_info_to_zebra(bgp)) |
d62a17ae | 1687 | return; |
1688 | ||
f7df1907 PG |
1689 | if (safi == SAFI_FLOWSPEC) { |
1690 | peer = info->peer; | |
d90b788e A |
1691 | bgp_pbr_update_entry(peer->bgp, p, info, AFI_IP, safi, false); |
1692 | return; | |
f7df1907 | 1693 | } |
529efa23 | 1694 | |
2ad4f093 | 1695 | memset(&api, 0, sizeof(api)); |
568e10ca | 1696 | api.vrf_id = bgp->vrf_id; |
2ad4f093 RW |
1697 | api.type = ZEBRA_ROUTE_BGP; |
1698 | api.safi = safi; | |
1699 | api.prefix = *p; | |
d62a17ae | 1700 | |
1276ce38 PG |
1701 | if (info->attr->rmap_table_id) { |
1702 | SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); | |
1703 | api.tableid = info->attr->rmap_table_id; | |
1704 | } | |
1705 | ||
88493076 | 1706 | /* If the route's source is EVPN, flag as such. */ |
1707 | if (is_route_parent_evpn(info)) | |
90264d64 | 1708 | SET_FLAG(api.flags, ZEBRA_FLAG_EVPN_ROUTE); |
01740ff4 | 1709 | |
2dbe669b DA |
1710 | if (bgp_debug_zebra(p)) |
1711 | zlog_debug("Tx route delete VRF %u %pFX", bgp->vrf_id, | |
1712 | &api.prefix); | |
d62a17ae | 1713 | |
2ad4f093 | 1714 | zclient_route_send(ZEBRA_ROUTE_DELETE, zclient, &api); |
718e3744 | 1715 | } |
56c1f7d8 | 1716 | |
c163f297 DS |
1717 | /* Withdraw all entries in a BGP instances RIB table from Zebra */ |
1718 | void bgp_zebra_withdraw_table_all_subtypes(struct bgp *bgp, afi_t afi, safi_t safi) | |
1719 | { | |
1720 | struct bgp_dest *dest; | |
1721 | struct bgp_table *table; | |
1722 | struct bgp_path_info *pi; | |
1723 | ||
1724 | if (!bgp_install_info_to_zebra(bgp)) | |
1725 | return; | |
1726 | ||
1727 | table = bgp->rib[afi][safi]; | |
1728 | if (!table) | |
1729 | return; | |
1730 | ||
1731 | for (dest = bgp_table_top(table); dest; dest = bgp_route_next(dest)) { | |
1732 | for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { | |
1733 | if (CHECK_FLAG(pi->flags, BGP_PATH_SELECTED) | |
1734 | && (pi->type == ZEBRA_ROUTE_BGP)) | |
1735 | bgp_zebra_withdraw(bgp_dest_get_prefix(dest), | |
1736 | pi, bgp, safi); | |
1737 | } | |
1738 | } | |
1739 | } | |
1740 | ||
d7c0a89a QY |
1741 | struct bgp_redist *bgp_redist_lookup(struct bgp *bgp, afi_t afi, uint8_t type, |
1742 | unsigned short instance) | |
7c8ff89e | 1743 | { |
d62a17ae | 1744 | struct list *red_list; |
1745 | struct listnode *node; | |
1746 | struct bgp_redist *red; | |
7c8ff89e | 1747 | |
d62a17ae | 1748 | red_list = bgp->redist[afi][type]; |
1749 | if (!red_list) | |
1750 | return (NULL); | |
7c8ff89e | 1751 | |
d62a17ae | 1752 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) |
1753 | if (red->instance == instance) | |
1754 | return red; | |
7c8ff89e | 1755 | |
d62a17ae | 1756 | return NULL; |
7c8ff89e DS |
1757 | } |
1758 | ||
d7c0a89a QY |
1759 | struct bgp_redist *bgp_redist_add(struct bgp *bgp, afi_t afi, uint8_t type, |
1760 | unsigned short instance) | |
7c8ff89e | 1761 | { |
d62a17ae | 1762 | struct list *red_list; |
1763 | struct bgp_redist *red; | |
7c8ff89e | 1764 | |
d62a17ae | 1765 | red = bgp_redist_lookup(bgp, afi, type, instance); |
1766 | if (red) | |
1767 | return red; | |
7c8ff89e | 1768 | |
d62a17ae | 1769 | if (!bgp->redist[afi][type]) |
1770 | bgp->redist[afi][type] = list_new(); | |
7c8ff89e | 1771 | |
d62a17ae | 1772 | red_list = bgp->redist[afi][type]; |
9f5dc319 | 1773 | red = XCALLOC(MTYPE_BGP_REDIST, sizeof(struct bgp_redist)); |
d62a17ae | 1774 | red->instance = instance; |
7c8ff89e | 1775 | |
d62a17ae | 1776 | listnode_add(red_list, red); |
7c8ff89e | 1777 | |
d62a17ae | 1778 | return red; |
7c8ff89e DS |
1779 | } |
1780 | ||
d7c0a89a QY |
1781 | static void bgp_redist_del(struct bgp *bgp, afi_t afi, uint8_t type, |
1782 | unsigned short instance) | |
7c8ff89e | 1783 | { |
d62a17ae | 1784 | struct bgp_redist *red; |
1785 | ||
1786 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
1787 | ||
1788 | if (red) { | |
1789 | listnode_delete(bgp->redist[afi][type], red); | |
1790 | XFREE(MTYPE_BGP_REDIST, red); | |
acdf5e25 | 1791 | if (!bgp->redist[afi][type]->count) |
6a154c88 | 1792 | list_delete(&bgp->redist[afi][type]); |
d62a17ae | 1793 | } |
7c8ff89e | 1794 | } |
6b0655a2 | 1795 | |
718e3744 | 1796 | /* Other routes redistribution into BGP. */ |
d7c0a89a | 1797 | int bgp_redistribute_set(struct bgp *bgp, afi_t afi, int type, |
e923dd62 | 1798 | unsigned short instance, bool changed) |
718e3744 | 1799 | { |
e923dd62 | 1800 | /* If redistribute options are changed call |
1801 | * bgp_redistribute_unreg() to reset the option and withdraw | |
1802 | * the routes | |
1803 | */ | |
1804 | if (changed) | |
1805 | bgp_redistribute_unreg(bgp, afi, type, instance); | |
718e3744 | 1806 | |
d62a17ae | 1807 | /* Return if already redistribute flag is set. */ |
1808 | if (instance) { | |
1809 | if (redist_check_instance(&zclient->mi_redist[afi][type], | |
1810 | instance)) | |
1811 | return CMD_WARNING; | |
718e3744 | 1812 | |
d62a17ae | 1813 | redist_add_instance(&zclient->mi_redist[afi][type], instance); |
1814 | } else { | |
d9083050 IR |
1815 | if (vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) |
1816 | return CMD_WARNING; | |
1817 | ||
49e5a4a0 | 1818 | #ifdef ENABLE_BGP_VNC |
f920dd6d | 1819 | if (EVPN_ENABLED(bgp) && type == ZEBRA_ROUTE_VNC_DIRECT) { |
d62a17ae | 1820 | vnc_export_bgp_enable( |
1821 | bgp, afi); /* only enables if mode bits cfg'd */ | |
1822 | } | |
65efcfce LB |
1823 | #endif |
1824 | ||
d62a17ae | 1825 | vrf_bitmap_set(zclient->redist[afi][type], bgp->vrf_id); |
1826 | } | |
718e3744 | 1827 | |
ea12cf11 DS |
1828 | /* |
1829 | * Don't try to register if we're not connected to Zebra or Zebra | |
1830 | * doesn't know of this instance. | |
1831 | * | |
1832 | * When we come up later well resend if needed. | |
d62a17ae | 1833 | */ |
1834 | if (!bgp_install_info_to_zebra(bgp)) | |
ea12cf11 | 1835 | return CMD_SUCCESS; |
a39275d7 | 1836 | |
d62a17ae | 1837 | if (BGP_DEBUG(zebra, ZEBRA)) |
1838 | zlog_debug("Tx redistribute add VRF %u afi %d %s %d", | |
1839 | bgp->vrf_id, afi, zebra_route_string(type), | |
1840 | instance); | |
518f0eb1 | 1841 | |
d62a17ae | 1842 | /* Send distribute add message to zebra. */ |
1843 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, | |
1844 | instance, bgp->vrf_id); | |
718e3744 | 1845 | |
d62a17ae | 1846 | return CMD_SUCCESS; |
718e3744 | 1847 | } |
1848 | ||
d62a17ae | 1849 | int bgp_redistribute_resend(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1850 | unsigned short instance) |
518f0eb1 | 1851 | { |
d62a17ae | 1852 | /* Don't try to send if we're not connected to Zebra or Zebra doesn't |
1853 | * know of this instance. | |
1854 | */ | |
1855 | if (!bgp_install_info_to_zebra(bgp)) | |
1856 | return -1; | |
1857 | ||
1858 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1859 | zlog_debug("Tx redistribute del/add VRF %u afi %d %s %d", | |
1860 | bgp->vrf_id, afi, zebra_route_string(type), | |
1861 | instance); | |
1862 | ||
1863 | /* Send distribute add message to zebra. */ | |
1864 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, type, | |
1865 | instance, bgp->vrf_id); | |
1866 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_ADD, zclient, afi, type, | |
1867 | instance, bgp->vrf_id); | |
1868 | ||
1869 | return 0; | |
518f0eb1 DS |
1870 | } |
1871 | ||
718e3744 | 1872 | /* Redistribute with route-map specification. */ |
3dc339cd DA |
1873 | bool bgp_redistribute_rmap_set(struct bgp_redist *red, const char *name, |
1874 | struct route_map *route_map) | |
718e3744 | 1875 | { |
d62a17ae | 1876 | if (red->rmap.name && (strcmp(red->rmap.name, name) == 0)) |
3dc339cd | 1877 | return false; |
718e3744 | 1878 | |
0a22ddfb | 1879 | XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name); |
b4897fa5 | 1880 | /* Decrement the count for existing routemap and |
1881 | * increment the count for new route map. | |
1882 | */ | |
1883 | route_map_counter_decrement(red->rmap.map); | |
d62a17ae | 1884 | red->rmap.name = XSTRDUP(MTYPE_ROUTE_MAP_NAME, name); |
1de27621 | 1885 | red->rmap.map = route_map; |
b4897fa5 | 1886 | route_map_counter_increment(red->rmap.map); |
718e3744 | 1887 | |
3dc339cd | 1888 | return true; |
718e3744 | 1889 | } |
1890 | ||
1891 | /* Redistribute with metric specification. */ | |
3dc339cd DA |
1892 | bool bgp_redistribute_metric_set(struct bgp *bgp, struct bgp_redist *red, |
1893 | afi_t afi, int type, uint32_t metric) | |
718e3744 | 1894 | { |
9bcb3eef | 1895 | struct bgp_dest *dest; |
40381db7 | 1896 | struct bgp_path_info *pi; |
d62a17ae | 1897 | |
1898 | if (red->redist_metric_flag && red->redist_metric == metric) | |
3dc339cd | 1899 | return false; |
d62a17ae | 1900 | |
1901 | red->redist_metric_flag = 1; | |
1902 | red->redist_metric = metric; | |
1903 | ||
9bcb3eef DS |
1904 | for (dest = bgp_table_top(bgp->rib[afi][SAFI_UNICAST]); dest; |
1905 | dest = bgp_route_next(dest)) { | |
1906 | for (pi = bgp_dest_get_bgp_path_info(dest); pi; pi = pi->next) { | |
40381db7 DS |
1907 | if (pi->sub_type == BGP_ROUTE_REDISTRIBUTE |
1908 | && pi->type == type | |
1909 | && pi->instance == red->instance) { | |
d62a17ae | 1910 | struct attr *old_attr; |
1911 | struct attr new_attr; | |
1912 | ||
6f4f49b2 | 1913 | new_attr = *pi->attr; |
d62a17ae | 1914 | new_attr.med = red->redist_metric; |
40381db7 DS |
1915 | old_attr = pi->attr; |
1916 | pi->attr = bgp_attr_intern(&new_attr); | |
d62a17ae | 1917 | bgp_attr_unintern(&old_attr); |
1918 | ||
9bcb3eef | 1919 | bgp_path_info_set_flag(dest, pi, |
18ee8310 | 1920 | BGP_PATH_ATTR_CHANGED); |
9bcb3eef | 1921 | bgp_process(bgp, dest, afi, SAFI_UNICAST); |
d62a17ae | 1922 | } |
1923 | } | |
1924 | } | |
1925 | ||
3dc339cd | 1926 | return true; |
718e3744 | 1927 | } |
1928 | ||
1929 | /* Unset redistribution. */ | |
d62a17ae | 1930 | int bgp_redistribute_unreg(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1931 | unsigned short instance) |
718e3744 | 1932 | { |
d62a17ae | 1933 | struct bgp_redist *red; |
1934 | ||
1935 | red = bgp_redist_lookup(bgp, afi, type, instance); | |
1936 | if (!red) | |
1937 | return CMD_SUCCESS; | |
1938 | ||
1939 | /* Return if zebra connection is disabled. */ | |
1940 | if (instance) { | |
1941 | if (!redist_check_instance(&zclient->mi_redist[afi][type], | |
1942 | instance)) | |
1943 | return CMD_WARNING; | |
1944 | redist_del_instance(&zclient->mi_redist[afi][type], instance); | |
1945 | } else { | |
1946 | if (!vrf_bitmap_check(zclient->redist[afi][type], bgp->vrf_id)) | |
1947 | return CMD_WARNING; | |
1948 | vrf_bitmap_unset(zclient->redist[afi][type], bgp->vrf_id); | |
1949 | } | |
718e3744 | 1950 | |
d62a17ae | 1951 | if (bgp_install_info_to_zebra(bgp)) { |
1952 | /* Send distribute delete message to zebra. */ | |
1953 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1954 | zlog_debug("Tx redistribute del VRF %u afi %d %s %d", | |
1955 | bgp->vrf_id, afi, zebra_route_string(type), | |
1956 | instance); | |
1957 | zebra_redistribute_send(ZEBRA_REDISTRIBUTE_DELETE, zclient, afi, | |
1958 | type, instance, bgp->vrf_id); | |
1959 | } | |
1960 | ||
1961 | /* Withdraw redistributed routes from current BGP's routing table. */ | |
1962 | bgp_redistribute_withdraw(bgp, afi, type, instance); | |
1963 | ||
1964 | return CMD_SUCCESS; | |
718e3744 | 1965 | } |
1966 | ||
6aeb9e78 | 1967 | /* Unset redistribution. */ |
d62a17ae | 1968 | int bgp_redistribute_unset(struct bgp *bgp, afi_t afi, int type, |
d7c0a89a | 1969 | unsigned short instance) |
6aeb9e78 | 1970 | { |
d62a17ae | 1971 | struct bgp_redist *red; |
6aeb9e78 | 1972 | |
ddb5b488 PZ |
1973 | /* |
1974 | * vnc and vpn->vrf checks must be before red check because | |
1975 | * they operate within bgpd irrespective of zebra connection | |
1976 | * status. red lookup fails if there is no zebra connection. | |
1977 | */ | |
49e5a4a0 | 1978 | #ifdef ENABLE_BGP_VNC |
f920dd6d | 1979 | if (EVPN_ENABLED(bgp) && type == ZEBRA_ROUTE_VNC_DIRECT) { |
ddb5b488 PZ |
1980 | vnc_export_bgp_disable(bgp, afi); |
1981 | } | |
1982 | #endif | |
ddb5b488 | 1983 | |
d62a17ae | 1984 | red = bgp_redist_lookup(bgp, afi, type, instance); |
1985 | if (!red) | |
1986 | return CMD_SUCCESS; | |
6aeb9e78 | 1987 | |
d62a17ae | 1988 | bgp_redistribute_unreg(bgp, afi, type, instance); |
6aeb9e78 | 1989 | |
d62a17ae | 1990 | /* Unset route-map. */ |
0a22ddfb | 1991 | XFREE(MTYPE_ROUTE_MAP_NAME, red->rmap.name); |
b4897fa5 | 1992 | route_map_counter_decrement(red->rmap.map); |
d62a17ae | 1993 | red->rmap.map = NULL; |
6aeb9e78 | 1994 | |
d62a17ae | 1995 | /* Unset metric. */ |
1996 | red->redist_metric_flag = 0; | |
1997 | red->redist_metric = 0; | |
6aeb9e78 | 1998 | |
d62a17ae | 1999 | bgp_redist_del(bgp, afi, type, instance); |
6aeb9e78 | 2000 | |
d62a17ae | 2001 | return CMD_SUCCESS; |
6aeb9e78 DS |
2002 | } |
2003 | ||
fc2408ec DS |
2004 | void bgp_redistribute_redo(struct bgp *bgp) |
2005 | { | |
2006 | afi_t afi; | |
2007 | int i; | |
2008 | struct list *red_list; | |
2009 | struct listnode *node; | |
2010 | struct bgp_redist *red; | |
2011 | ||
2012 | for (afi = AFI_IP; afi < AFI_MAX; afi++) { | |
2013 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) { | |
2014 | ||
2015 | red_list = bgp->redist[afi][i]; | |
2016 | if (!red_list) | |
2017 | continue; | |
2018 | ||
2019 | for (ALL_LIST_ELEMENTS_RO(red_list, node, red)) { | |
2020 | bgp_redistribute_resend(bgp, afi, i, | |
2021 | red->instance); | |
2022 | } | |
2023 | } | |
2024 | } | |
2025 | } | |
2026 | ||
d62a17ae | 2027 | void bgp_zclient_reset(void) |
718e3744 | 2028 | { |
d62a17ae | 2029 | zclient_reset(zclient); |
718e3744 | 2030 | } |
2031 | ||
ad4cbda1 | 2032 | /* Register this instance with Zebra. Invoked upon connect (for |
2033 | * default instance) and when other VRFs are learnt (or created and | |
2034 | * already learnt). | |
2035 | */ | |
d62a17ae | 2036 | void bgp_zebra_instance_register(struct bgp *bgp) |
ad4cbda1 | 2037 | { |
d62a17ae | 2038 | /* Don't try to register if we're not connected to Zebra */ |
2039 | if (!zclient || zclient->sock < 0) | |
2040 | return; | |
ad4cbda1 | 2041 | |
d62a17ae | 2042 | if (BGP_DEBUG(zebra, ZEBRA)) |
2043 | zlog_debug("Registering VRF %u", bgp->vrf_id); | |
ad4cbda1 | 2044 | |
d62a17ae | 2045 | /* Register for router-id, interfaces, redistributed routes. */ |
2046 | zclient_send_reg_requests(zclient, bgp->vrf_id); | |
7724c0a1 | 2047 | |
e2f3a930 T |
2048 | /* For EVPN instance, register to learn about VNIs, if appropriate. */ |
2049 | if (bgp->advertise_all_vni) | |
d62a17ae | 2050 | bgp_zebra_advertise_all_vni(bgp, 1); |
1ee0a2df DS |
2051 | |
2052 | bgp_nht_register_nexthops(bgp); | |
ad4cbda1 | 2053 | } |
2054 | ||
2055 | /* Deregister this instance with Zebra. Invoked upon the instance | |
2056 | * being deleted (default or VRF) and it is already registered. | |
2057 | */ | |
d62a17ae | 2058 | void bgp_zebra_instance_deregister(struct bgp *bgp) |
ad4cbda1 | 2059 | { |
d62a17ae | 2060 | /* Don't try to deregister if we're not connected to Zebra */ |
2061 | if (zclient->sock < 0) | |
2062 | return; | |
ad4cbda1 | 2063 | |
d62a17ae | 2064 | if (BGP_DEBUG(zebra, ZEBRA)) |
2065 | zlog_debug("Deregistering VRF %u", bgp->vrf_id); | |
ad4cbda1 | 2066 | |
e2f3a930 T |
2067 | /* For EVPN instance, unregister learning about VNIs, if appropriate. */ |
2068 | if (bgp->advertise_all_vni) | |
d62a17ae | 2069 | bgp_zebra_advertise_all_vni(bgp, 0); |
7724c0a1 | 2070 | |
d62a17ae | 2071 | /* Deregister for router-id, interfaces, redistributed routes. */ |
2072 | zclient_send_dereg_requests(zclient, bgp->vrf_id); | |
ad4cbda1 | 2073 | } |
2074 | ||
d62a17ae | 2075 | void bgp_zebra_initiate_radv(struct bgp *bgp, struct peer *peer) |
4a04e5f7 | 2076 | { |
bbad0276 | 2077 | uint32_t ra_interval = BGP_UNNUM_DEFAULT_RA_INTERVAL; |
5c81b96a | 2078 | |
d62a17ae | 2079 | /* Don't try to initiate if we're not connected to Zebra */ |
2080 | if (zclient->sock < 0) | |
2081 | return; | |
4a04e5f7 | 2082 | |
d62a17ae | 2083 | if (BGP_DEBUG(zebra, ZEBRA)) |
2084 | zlog_debug("%u: Initiating RA for peer %s", bgp->vrf_id, | |
2085 | peer->host); | |
4a04e5f7 | 2086 | |
b3a3290e DS |
2087 | /* |
2088 | * If unnumbered peer (peer->ifp) call thru zapi to start RAs. | |
2089 | * If we don't have an ifp pointer, call function to find the | |
2090 | * ifps for a numbered enhe peer to turn RAs on. | |
2091 | */ | |
2092 | peer->ifp ? zclient_send_interface_radv_req(zclient, bgp->vrf_id, | |
2093 | peer->ifp, 1, ra_interval) | |
2094 | : bgp_nht_reg_enhe_cap_intfs(peer); | |
4a04e5f7 | 2095 | } |
2096 | ||
d62a17ae | 2097 | void bgp_zebra_terminate_radv(struct bgp *bgp, struct peer *peer) |
4a04e5f7 | 2098 | { |
d62a17ae | 2099 | /* Don't try to terminate if we're not connected to Zebra */ |
2100 | if (zclient->sock < 0) | |
2101 | return; | |
4a04e5f7 | 2102 | |
d62a17ae | 2103 | if (BGP_DEBUG(zebra, ZEBRA)) |
2104 | zlog_debug("%u: Terminating RA for peer %s", bgp->vrf_id, | |
2105 | peer->host); | |
4a04e5f7 | 2106 | |
b3a3290e DS |
2107 | /* |
2108 | * If unnumbered peer (peer->ifp) call thru zapi to stop RAs. | |
2109 | * If we don't have an ifp pointer, call function to find the | |
2110 | * ifps for a numbered enhe peer to turn RAs off. | |
2111 | */ | |
2112 | peer->ifp ? zclient_send_interface_radv_req(zclient, bgp->vrf_id, | |
2113 | peer->ifp, 0, 0) | |
2114 | : bgp_nht_dereg_enhe_cap_intfs(peer); | |
4a04e5f7 | 2115 | } |
2116 | ||
31310b25 MK |
2117 | int bgp_zebra_advertise_subnet(struct bgp *bgp, int advertise, vni_t vni) |
2118 | { | |
2119 | struct stream *s = NULL; | |
2120 | ||
2121 | /* Check socket. */ | |
2122 | if (!zclient || zclient->sock < 0) | |
2123 | return 0; | |
2124 | ||
2125 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
bb4ef1ae DS |
2126 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { |
2127 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 DA |
2128 | zlog_debug( |
2129 | "%s: No zebra instance to talk to, cannot advertise subnet", | |
2130 | __func__); | |
31310b25 | 2131 | return 0; |
bb4ef1ae | 2132 | } |
31310b25 MK |
2133 | |
2134 | s = zclient->obuf; | |
2135 | stream_reset(s); | |
2136 | ||
2137 | zclient_create_header(s, ZEBRA_ADVERTISE_SUBNET, bgp->vrf_id); | |
2138 | stream_putc(s, advertise); | |
2139 | stream_put3(s, vni); | |
2140 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2141 | ||
2142 | return zclient_send_message(zclient); | |
2143 | } | |
2144 | ||
a8016157 CS |
2145 | int bgp_zebra_advertise_svi_macip(struct bgp *bgp, int advertise, vni_t vni) |
2146 | { | |
2147 | struct stream *s = NULL; | |
2148 | ||
2149 | /* Check socket. */ | |
2150 | if (!zclient || zclient->sock < 0) | |
2151 | return 0; | |
2152 | ||
2153 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
2154 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
2155 | return 0; | |
2156 | ||
2157 | s = zclient->obuf; | |
2158 | stream_reset(s); | |
2159 | ||
2160 | zclient_create_header(s, ZEBRA_ADVERTISE_SVI_MACIP, bgp->vrf_id); | |
2161 | stream_putc(s, advertise); | |
2162 | stream_putl(s, vni); | |
2163 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2164 | ||
2165 | return zclient_send_message(zclient); | |
2166 | } | |
2167 | ||
1a98c087 MK |
2168 | int bgp_zebra_advertise_gw_macip(struct bgp *bgp, int advertise, vni_t vni) |
2169 | { | |
2170 | struct stream *s = NULL; | |
2171 | ||
2172 | /* Check socket. */ | |
2173 | if (!zclient || zclient->sock < 0) | |
2174 | return 0; | |
2175 | ||
2176 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
bb4ef1ae DS |
2177 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { |
2178 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 DA |
2179 | zlog_debug( |
2180 | "%s: No zebra instance to talk to, not installing gw_macip", | |
2181 | __func__); | |
1a98c087 | 2182 | return 0; |
bb4ef1ae | 2183 | } |
1a98c087 MK |
2184 | |
2185 | s = zclient->obuf; | |
2186 | stream_reset(s); | |
2187 | ||
2188 | zclient_create_header(s, ZEBRA_ADVERTISE_DEFAULT_GW, bgp->vrf_id); | |
2189 | stream_putc(s, advertise); | |
cc6d5476 | 2190 | stream_putl(s, vni); |
1a98c087 MK |
2191 | stream_putw_at(s, 0, stream_get_endp(s)); |
2192 | ||
2193 | return zclient_send_message(zclient); | |
2194 | } | |
2195 | ||
fd069644 DS |
2196 | int bgp_zebra_vxlan_flood_control(struct bgp *bgp, |
2197 | enum vxlan_flood_control flood_ctrl) | |
2198 | { | |
2199 | struct stream *s; | |
2200 | ||
2201 | /* Check socket. */ | |
2202 | if (!zclient || zclient->sock < 0) | |
2203 | return 0; | |
2204 | ||
2205 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
bb4ef1ae DS |
2206 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) { |
2207 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 DA |
2208 | zlog_debug( |
2209 | "%s: No zebra instance to talk to, not installing all vni", | |
2210 | __func__); | |
fd069644 | 2211 | return 0; |
bb4ef1ae | 2212 | } |
fd069644 DS |
2213 | |
2214 | s = zclient->obuf; | |
2215 | stream_reset(s); | |
2216 | ||
2217 | zclient_create_header(s, ZEBRA_VXLAN_FLOOD_CONTROL, bgp->vrf_id); | |
2218 | stream_putc(s, flood_ctrl); | |
2219 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2220 | ||
2221 | return zclient_send_message(zclient); | |
2222 | } | |
2223 | ||
d62a17ae | 2224 | int bgp_zebra_advertise_all_vni(struct bgp *bgp, int advertise) |
7724c0a1 | 2225 | { |
d62a17ae | 2226 | struct stream *s; |
7724c0a1 | 2227 | |
d62a17ae | 2228 | /* Check socket. */ |
2229 | if (!zclient || zclient->sock < 0) | |
2230 | return 0; | |
7724c0a1 | 2231 | |
d62a17ae | 2232 | /* Don't try to register if Zebra doesn't know of this instance. */ |
2233 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
2234 | return 0; | |
7724c0a1 | 2235 | |
d62a17ae | 2236 | s = zclient->obuf; |
2237 | stream_reset(s); | |
7724c0a1 | 2238 | |
d62a17ae | 2239 | zclient_create_header(s, ZEBRA_ADVERTISE_ALL_VNI, bgp->vrf_id); |
2240 | stream_putc(s, advertise); | |
fbac9605 DS |
2241 | /* Also inform current BUM handling setting. This is really |
2242 | * relevant only when 'advertise' is set. | |
2243 | */ | |
fd069644 | 2244 | stream_putc(s, bgp->vxlan_flood_ctrl); |
d62a17ae | 2245 | stream_putw_at(s, 0, stream_get_endp(s)); |
7724c0a1 | 2246 | |
d62a17ae | 2247 | return zclient_send_message(zclient); |
7724c0a1 | 2248 | } |
2249 | ||
0b9d9cd0 CS |
2250 | int bgp_zebra_dup_addr_detection(struct bgp *bgp) |
2251 | { | |
2252 | struct stream *s; | |
2253 | ||
2254 | /* Check socket. */ | |
2255 | if (!zclient || zclient->sock < 0) | |
2256 | return 0; | |
2257 | ||
2258 | /* Don't try to register if Zebra doesn't know of this instance. */ | |
2259 | if (!IS_BGP_INST_KNOWN_TO_ZEBRA(bgp)) | |
2260 | return 0; | |
2261 | ||
2262 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2263 | zlog_debug("dup addr detect %s max_moves %u time %u freeze %s freeze_time %u", | |
2264 | bgp->evpn_info->dup_addr_detect ? | |
2265 | "enable" : "disable", | |
2266 | bgp->evpn_info->dad_max_moves, | |
2267 | bgp->evpn_info->dad_time, | |
2268 | bgp->evpn_info->dad_freeze ? | |
2269 | "enable" : "disable", | |
2270 | bgp->evpn_info->dad_freeze_time); | |
2271 | ||
2272 | s = zclient->obuf; | |
2273 | stream_reset(s); | |
2274 | zclient_create_header(s, ZEBRA_DUPLICATE_ADDR_DETECTION, | |
2275 | bgp->vrf_id); | |
2276 | stream_putl(s, bgp->evpn_info->dup_addr_detect); | |
2277 | stream_putl(s, bgp->evpn_info->dad_time); | |
2278 | stream_putl(s, bgp->evpn_info->dad_max_moves); | |
2279 | stream_putl(s, bgp->evpn_info->dad_freeze); | |
2280 | stream_putl(s, bgp->evpn_info->dad_freeze_time); | |
2281 | stream_putw_at(s, 0, stream_get_endp(s)); | |
2282 | ||
2283 | return zclient_send_message(zclient); | |
2284 | } | |
2285 | ||
121f9dee | 2286 | static int rule_notify_owner(ZAPI_CALLBACK_ARGS) |
30d50e6d PG |
2287 | { |
2288 | uint32_t seqno, priority, unique; | |
2289 | enum zapi_rule_notify_owner note; | |
2290 | struct bgp_pbr_action *bgp_pbra; | |
ffee150e | 2291 | struct bgp_pbr_rule *bgp_pbr = NULL; |
58a1d249 | 2292 | char ifname[INTERFACE_NAMSIZ + 1]; |
30d50e6d PG |
2293 | |
2294 | if (!zapi_rule_notify_decode(zclient->ibuf, &seqno, &priority, &unique, | |
58a1d249 | 2295 | ifname, ¬e)) |
30d50e6d PG |
2296 | return -1; |
2297 | ||
70eabd12 | 2298 | bgp_pbra = bgp_pbr_action_rule_lookup(vrf_id, unique); |
30d50e6d | 2299 | if (!bgp_pbra) { |
ffee150e PG |
2300 | /* look in bgp pbr rule */ |
2301 | bgp_pbr = bgp_pbr_rule_lookup(vrf_id, unique); | |
2302 | if (!bgp_pbr && note != ZAPI_RULE_REMOVED) { | |
2303 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2304 | zlog_debug("%s: Fail to look BGP rule (%u)", | |
15569c58 | 2305 | __func__, unique); |
ffee150e PG |
2306 | return 0; |
2307 | } | |
30d50e6d PG |
2308 | } |
2309 | ||
2310 | switch (note) { | |
2311 | case ZAPI_RULE_FAIL_INSTALL: | |
2312 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2313 | zlog_debug("%s: Received RULE_FAIL_INSTALL", __func__); |
ffee150e PG |
2314 | if (bgp_pbra) { |
2315 | bgp_pbra->installed = false; | |
2316 | bgp_pbra->install_in_progress = false; | |
2317 | } else { | |
2318 | bgp_pbr->installed = false; | |
2319 | bgp_pbr->install_in_progress = false; | |
2320 | } | |
30d50e6d PG |
2321 | break; |
2322 | case ZAPI_RULE_INSTALLED: | |
ffee150e PG |
2323 | if (bgp_pbra) { |
2324 | bgp_pbra->installed = true; | |
2325 | bgp_pbra->install_in_progress = false; | |
2326 | } else { | |
ce3c0614 PG |
2327 | struct bgp_path_info *path; |
2328 | struct bgp_path_info_extra *extra; | |
2329 | ||
ffee150e PG |
2330 | bgp_pbr->installed = true; |
2331 | bgp_pbr->install_in_progress = false; | |
2332 | bgp_pbr->action->refcnt++; | |
ce3c0614 PG |
2333 | /* link bgp_info to bgp_pbr */ |
2334 | path = (struct bgp_path_info *)bgp_pbr->path; | |
2335 | extra = bgp_path_info_extra_get(path); | |
f5925234 PG |
2336 | listnode_add_force(&extra->bgp_fs_iprule, |
2337 | bgp_pbr); | |
ffee150e | 2338 | } |
30d50e6d | 2339 | if (BGP_DEBUG(zebra, ZEBRA)) |
15569c58 | 2340 | zlog_debug("%s: Received RULE_INSTALLED", __func__); |
30d50e6d | 2341 | break; |
f18a08f5 | 2342 | case ZAPI_RULE_FAIL_REMOVE: |
30d50e6d PG |
2343 | case ZAPI_RULE_REMOVED: |
2344 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2345 | zlog_debug("%s: Received RULE REMOVED", __func__); |
30d50e6d PG |
2346 | break; |
2347 | } | |
2348 | ||
2349 | return 0; | |
2350 | } | |
2351 | ||
121f9dee | 2352 | static int ipset_notify_owner(ZAPI_CALLBACK_ARGS) |
30d50e6d PG |
2353 | { |
2354 | uint32_t unique; | |
2355 | enum zapi_ipset_notify_owner note; | |
2356 | struct bgp_pbr_match *bgp_pbim; | |
2357 | ||
2358 | if (!zapi_ipset_notify_decode(zclient->ibuf, | |
2359 | &unique, | |
2360 | ¬e)) | |
2361 | return -1; | |
2362 | ||
2363 | bgp_pbim = bgp_pbr_match_ipset_lookup(vrf_id, unique); | |
2364 | if (!bgp_pbim) { | |
2365 | if (BGP_DEBUG(zebra, ZEBRA)) | |
88055124 | 2366 | zlog_debug("%s: Fail to look BGP match ( %u, ID %u)", |
15569c58 | 2367 | __func__, note, unique); |
30d50e6d PG |
2368 | return 0; |
2369 | } | |
2370 | ||
2371 | switch (note) { | |
2372 | case ZAPI_IPSET_FAIL_INSTALL: | |
2373 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2374 | zlog_debug("%s: Received IPSET_FAIL_INSTALL", __func__); |
30d50e6d PG |
2375 | bgp_pbim->installed = false; |
2376 | bgp_pbim->install_in_progress = false; | |
2377 | break; | |
2378 | case ZAPI_IPSET_INSTALLED: | |
2379 | bgp_pbim->installed = true; | |
2380 | bgp_pbim->install_in_progress = false; | |
2381 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2382 | zlog_debug("%s: Received IPSET_INSTALLED", __func__); |
30d50e6d | 2383 | break; |
f18a08f5 | 2384 | case ZAPI_IPSET_FAIL_REMOVE: |
30d50e6d PG |
2385 | case ZAPI_IPSET_REMOVED: |
2386 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2387 | zlog_debug("%s: Received IPSET REMOVED", __func__); |
30d50e6d PG |
2388 | break; |
2389 | } | |
2390 | ||
2391 | return 0; | |
2392 | } | |
2393 | ||
121f9dee | 2394 | static int ipset_entry_notify_owner(ZAPI_CALLBACK_ARGS) |
30d50e6d PG |
2395 | { |
2396 | uint32_t unique; | |
2397 | char ipset_name[ZEBRA_IPSET_NAME_SIZE]; | |
2398 | enum zapi_ipset_entry_notify_owner note; | |
2399 | struct bgp_pbr_match_entry *bgp_pbime; | |
2400 | ||
2401 | if (!zapi_ipset_entry_notify_decode( | |
2402 | zclient->ibuf, | |
2403 | &unique, | |
2404 | ipset_name, | |
2405 | ¬e)) | |
2406 | return -1; | |
2407 | bgp_pbime = bgp_pbr_match_ipset_entry_lookup(vrf_id, | |
2408 | ipset_name, | |
2409 | unique); | |
2410 | if (!bgp_pbime) { | |
2411 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 DA |
2412 | zlog_debug( |
2413 | "%s: Fail to look BGP match entry (%u, ID %u)", | |
2414 | __func__, note, unique); | |
30d50e6d PG |
2415 | return 0; |
2416 | } | |
2417 | ||
2418 | switch (note) { | |
2419 | case ZAPI_IPSET_ENTRY_FAIL_INSTALL: | |
2420 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2421 | zlog_debug("%s: Received IPSET_ENTRY_FAIL_INSTALL", | |
15569c58 | 2422 | __func__); |
30d50e6d PG |
2423 | bgp_pbime->installed = false; |
2424 | bgp_pbime->install_in_progress = false; | |
2425 | break; | |
2426 | case ZAPI_IPSET_ENTRY_INSTALLED: | |
b588b642 | 2427 | { |
9b6d8fcf | 2428 | struct bgp_path_info *path; |
4b7e6066 DS |
2429 | struct bgp_path_info_extra *extra; |
2430 | ||
2431 | bgp_pbime->installed = true; | |
2432 | bgp_pbime->install_in_progress = false; | |
2433 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2434 | zlog_debug("%s: Received IPSET_ENTRY_INSTALLED", | |
15569c58 | 2435 | __func__); |
9b6d8fcf DS |
2436 | /* link bgp_path_info to bpme */ |
2437 | path = (struct bgp_path_info *)bgp_pbime->path; | |
2438 | extra = bgp_path_info_extra_get(path); | |
f5925234 | 2439 | listnode_add_force(&extra->bgp_fs_pbr, bgp_pbime); |
b588b642 | 2440 | } |
30d50e6d | 2441 | break; |
f18a08f5 | 2442 | case ZAPI_IPSET_ENTRY_FAIL_REMOVE: |
30d50e6d PG |
2443 | case ZAPI_IPSET_ENTRY_REMOVED: |
2444 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2445 | zlog_debug("%s: Received IPSET_ENTRY_REMOVED", | |
15569c58 | 2446 | __func__); |
30d50e6d PG |
2447 | break; |
2448 | } | |
2449 | return 0; | |
2450 | } | |
2451 | ||
121f9dee | 2452 | static int iptable_notify_owner(ZAPI_CALLBACK_ARGS) |
c16a0a62 PG |
2453 | { |
2454 | uint32_t unique; | |
2455 | enum zapi_iptable_notify_owner note; | |
2456 | struct bgp_pbr_match *bgpm; | |
2457 | ||
2458 | if (!zapi_iptable_notify_decode( | |
2459 | zclient->ibuf, | |
2460 | &unique, | |
2461 | ¬e)) | |
2462 | return -1; | |
2463 | bgpm = bgp_pbr_match_iptable_lookup(vrf_id, unique); | |
2464 | if (!bgpm) { | |
2465 | if (BGP_DEBUG(zebra, ZEBRA)) | |
82e194ed | 2466 | zlog_debug("%s: Fail to look BGP iptable (%u %u)", |
15569c58 | 2467 | __func__, note, unique); |
c16a0a62 PG |
2468 | return 0; |
2469 | } | |
2470 | switch (note) { | |
2471 | case ZAPI_IPTABLE_FAIL_INSTALL: | |
2472 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2473 | zlog_debug("%s: Received IPTABLE_FAIL_INSTALL", | |
15569c58 | 2474 | __func__); |
c16a0a62 PG |
2475 | bgpm->installed_in_iptable = false; |
2476 | bgpm->install_iptable_in_progress = false; | |
2477 | break; | |
2478 | case ZAPI_IPTABLE_INSTALLED: | |
2479 | bgpm->installed_in_iptable = true; | |
2480 | bgpm->install_iptable_in_progress = false; | |
2481 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2482 | zlog_debug("%s: Received IPTABLE_INSTALLED", __func__); |
a6b07429 | 2483 | bgpm->action->refcnt++; |
c16a0a62 | 2484 | break; |
f18a08f5 | 2485 | case ZAPI_IPTABLE_FAIL_REMOVE: |
c16a0a62 PG |
2486 | case ZAPI_IPTABLE_REMOVED: |
2487 | if (BGP_DEBUG(zebra, ZEBRA)) | |
15569c58 | 2488 | zlog_debug("%s: Received IPTABLE REMOVED", __func__); |
c16a0a62 PG |
2489 | break; |
2490 | } | |
2491 | return 0; | |
2492 | } | |
2493 | ||
a77e2f4b S |
2494 | /* Process route notification messages from RIB */ |
2495 | static int bgp_zebra_route_notify_owner(int command, struct zclient *zclient, | |
2496 | zebra_size_t length, vrf_id_t vrf_id) | |
2497 | { | |
2498 | struct prefix p; | |
2499 | enum zapi_route_notify_owner note; | |
2500 | uint32_t table_id; | |
a77e2f4b S |
2501 | afi_t afi; |
2502 | safi_t safi; | |
2503 | struct bgp_dest *dest; | |
2504 | struct bgp *bgp; | |
2505 | struct bgp_path_info *pi, *new_select; | |
2506 | ||
2507 | if (!zapi_route_notify_decode(zclient->ibuf, &p, &table_id, ¬e, | |
2508 | &afi, &safi)) { | |
cc42c4f0 | 2509 | zlog_err("%s : error in msg decode", __func__); |
a77e2f4b S |
2510 | return -1; |
2511 | } | |
2512 | ||
2513 | /* Get the bgp instance */ | |
2514 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2515 | if (!bgp) { | |
2516 | flog_err(EC_BGP_INVALID_BGP_INSTANCE, | |
cc42c4f0 DS |
2517 | "%s : bgp instance not found vrf %d", __func__, |
2518 | vrf_id); | |
a77e2f4b S |
2519 | return -1; |
2520 | } | |
2521 | ||
a77e2f4b S |
2522 | /* Find the bgp route node */ |
2523 | dest = bgp_afi_node_lookup(bgp->rib[afi][safi], afi, safi, &p, | |
2524 | &bgp->vrf_prd); | |
2525 | if (!dest) | |
2526 | return -1; | |
2527 | ||
a77e2f4b S |
2528 | switch (note) { |
2529 | case ZAPI_ROUTE_INSTALLED: | |
2530 | new_select = NULL; | |
2531 | /* Clear the flags so that route can be processed */ | |
2532 | if (CHECK_FLAG(dest->flags, | |
2533 | BGP_NODE_FIB_INSTALL_PENDING)) { | |
2534 | UNSET_FLAG(dest->flags, | |
2535 | BGP_NODE_FIB_INSTALL_PENDING); | |
2536 | SET_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED); | |
2537 | if (BGP_DEBUG(zebra, ZEBRA)) | |
1a3519b6 | 2538 | zlog_debug("route %pRN : INSTALLED", dest); |
a77e2f4b S |
2539 | /* Find the best route */ |
2540 | for (pi = dest->info; pi; pi = pi->next) { | |
2541 | /* Process aggregate route */ | |
2542 | bgp_aggregate_increment(bgp, &p, pi, | |
2543 | afi, safi); | |
2544 | if (CHECK_FLAG(pi->flags, | |
2545 | BGP_PATH_SELECTED)) | |
2546 | new_select = pi; | |
2547 | } | |
2548 | /* Advertise the route */ | |
2549 | if (new_select) | |
2550 | group_announce_route(bgp, afi, safi, | |
2551 | dest, new_select); | |
2552 | else { | |
2553 | flog_err(EC_BGP_INVALID_ROUTE, | |
1a3519b6 DS |
2554 | "selected route %pRN not found", |
2555 | dest); | |
e71ad4b6 DA |
2556 | |
2557 | bgp_dest_unlock_node(dest); | |
a77e2f4b S |
2558 | return -1; |
2559 | } | |
2560 | } | |
2561 | break; | |
2562 | case ZAPI_ROUTE_REMOVED: | |
2563 | /* Route deleted from dataplane, reset the installed flag | |
2564 | * so that route can be reinstalled when client sends | |
2565 | * route add later | |
2566 | */ | |
2567 | UNSET_FLAG(dest->flags, BGP_NODE_FIB_INSTALLED); | |
1a3519b6 DS |
2568 | if (BGP_DEBUG(zebra, ZEBRA)) |
2569 | zlog_debug("route %pRN: Removed from Fib", dest); | |
a77e2f4b S |
2570 | break; |
2571 | case ZAPI_ROUTE_FAIL_INSTALL: | |
1a3519b6 DS |
2572 | if (BGP_DEBUG(zebra, ZEBRA)) |
2573 | zlog_debug("route: %pRN Failed to Install into Fib", | |
2574 | dest); | |
a77e2f4b S |
2575 | /* Error will be logged by zebra module */ |
2576 | break; | |
2577 | case ZAPI_ROUTE_BETTER_ADMIN_WON: | |
1a3519b6 DS |
2578 | if (BGP_DEBUG(zebra, ZEBRA)) |
2579 | zlog_debug("route: %pRN removed due to better admin won", | |
2580 | dest); | |
a77e2f4b S |
2581 | /* No action required */ |
2582 | break; | |
2583 | case ZAPI_ROUTE_REMOVE_FAIL: | |
1a3519b6 DS |
2584 | zlog_warn("%s: Route %pRN failure to remove", |
2585 | __func__, dest); | |
a77e2f4b S |
2586 | break; |
2587 | } | |
e71ad4b6 DA |
2588 | |
2589 | bgp_dest_unlock_node(dest); | |
a77e2f4b S |
2590 | return 0; |
2591 | } | |
2592 | ||
6cfe5d15 PG |
2593 | /* this function is used to forge ip rule, |
2594 | * - either for iptable/ipset using fwmark id | |
121f9dee | 2595 | * - or for sample ip rule cmd |
6cfe5d15 | 2596 | */ |
30d50e6d | 2597 | static void bgp_encode_pbr_rule_action(struct stream *s, |
6cfe5d15 PG |
2598 | struct bgp_pbr_action *pbra, |
2599 | struct bgp_pbr_rule *pbr) | |
30d50e6d | 2600 | { |
6cfe5d15 | 2601 | struct prefix pfx; |
f01e580f | 2602 | uint8_t fam = AF_INET; |
e95666cb | 2603 | char ifname[INTERFACE_NAMSIZ]; |
30d50e6d | 2604 | |
9f1f03ec | 2605 | if (pbra->nh.type == NEXTHOP_TYPE_IPV6) |
f01e580f | 2606 | fam = AF_INET6; |
30d50e6d | 2607 | stream_putl(s, 0); /* seqno unused */ |
8112a7a0 PG |
2608 | if (pbr) |
2609 | stream_putl(s, pbr->priority); | |
2610 | else | |
2611 | stream_putl(s, 0); | |
2612 | /* ruleno unused - priority change | |
2613 | * ruleno permits distinguishing various FS PBR entries | |
2614 | * - FS PBR entries based on ipset/iptables | |
2615 | * - FS PBR entries based on iprule | |
2616 | * the latter may contain default routing information injected by FS | |
2617 | */ | |
6cfe5d15 PG |
2618 | if (pbr) |
2619 | stream_putl(s, pbr->unique); | |
2620 | else | |
2621 | stream_putl(s, pbra->unique); | |
f56697ef | 2622 | stream_putc(s, 0); /* ip protocol being used */ |
6cfe5d15 PG |
2623 | if (pbr && pbr->flags & MATCH_IP_SRC_SET) |
2624 | memcpy(&pfx, &(pbr->src), sizeof(struct prefix)); | |
2625 | else { | |
2626 | memset(&pfx, 0, sizeof(pfx)); | |
f01e580f | 2627 | pfx.family = fam; |
6cfe5d15 PG |
2628 | } |
2629 | stream_putc(s, pfx.family); | |
2630 | stream_putc(s, pfx.prefixlen); | |
2631 | stream_put(s, &pfx.u.prefix, prefix_blen(&pfx)); | |
30d50e6d PG |
2632 | |
2633 | stream_putw(s, 0); /* src port */ | |
2634 | ||
6cfe5d15 PG |
2635 | if (pbr && pbr->flags & MATCH_IP_DST_SET) |
2636 | memcpy(&pfx, &(pbr->dst), sizeof(struct prefix)); | |
2637 | else { | |
2638 | memset(&pfx, 0, sizeof(pfx)); | |
f01e580f | 2639 | pfx.family = fam; |
6cfe5d15 PG |
2640 | } |
2641 | stream_putc(s, pfx.family); | |
2642 | stream_putc(s, pfx.prefixlen); | |
2643 | stream_put(s, &pfx.u.prefix, prefix_blen(&pfx)); | |
30d50e6d PG |
2644 | |
2645 | stream_putw(s, 0); /* dst port */ | |
e95666cb | 2646 | stream_putc(s, 0); /* dsfield */ |
6cfe5d15 PG |
2647 | /* if pbr present, fwmark is not used */ |
2648 | if (pbr) | |
2649 | stream_putl(s, 0); | |
2650 | else | |
2651 | stream_putl(s, pbra->fwmark); /* fwmark */ | |
30d50e6d PG |
2652 | |
2653 | stream_putl(s, pbra->table_id); | |
2654 | ||
e95666cb DS |
2655 | memset(ifname, 0, sizeof(ifname)); |
2656 | stream_put(s, ifname, INTERFACE_NAMSIZ); /* ifname unused */ | |
30d50e6d PG |
2657 | } |
2658 | ||
2659 | static void bgp_encode_pbr_ipset_match(struct stream *s, | |
2660 | struct bgp_pbr_match *pbim) | |
2661 | { | |
2662 | stream_putl(s, pbim->unique); | |
2663 | stream_putl(s, pbim->type); | |
a60b7031 | 2664 | stream_putc(s, pbim->family); |
30d50e6d PG |
2665 | stream_put(s, pbim->ipset_name, |
2666 | ZEBRA_IPSET_NAME_SIZE); | |
30d50e6d PG |
2667 | } |
2668 | ||
2669 | static void bgp_encode_pbr_ipset_entry_match(struct stream *s, | |
2670 | struct bgp_pbr_match_entry *pbime) | |
2671 | { | |
2672 | stream_putl(s, pbime->unique); | |
2673 | /* check that back pointer is not null */ | |
2674 | stream_put(s, pbime->backpointer->ipset_name, | |
2675 | ZEBRA_IPSET_NAME_SIZE); | |
2676 | ||
2677 | stream_putc(s, pbime->src.family); | |
2678 | stream_putc(s, pbime->src.prefixlen); | |
2679 | stream_put(s, &pbime->src.u.prefix, prefix_blen(&pbime->src)); | |
2680 | ||
2681 | stream_putc(s, pbime->dst.family); | |
2682 | stream_putc(s, pbime->dst.prefixlen); | |
2683 | stream_put(s, &pbime->dst.u.prefix, prefix_blen(&pbime->dst)); | |
f730e566 PG |
2684 | |
2685 | stream_putw(s, pbime->src_port_min); | |
2686 | stream_putw(s, pbime->src_port_max); | |
2687 | stream_putw(s, pbime->dst_port_min); | |
2688 | stream_putw(s, pbime->dst_port_max); | |
2689 | stream_putc(s, pbime->proto); | |
30d50e6d PG |
2690 | } |
2691 | ||
c16a0a62 PG |
2692 | static void bgp_encode_pbr_iptable_match(struct stream *s, |
2693 | struct bgp_pbr_action *bpa, | |
2694 | struct bgp_pbr_match *pbm) | |
2695 | { | |
2696 | stream_putl(s, pbm->unique2); | |
2697 | ||
2698 | stream_putl(s, pbm->type); | |
2699 | ||
2700 | stream_putl(s, pbm->flags); | |
2701 | ||
2702 | /* TODO: correlate with what is contained | |
2703 | * into bgp_pbr_action. | |
2704 | * currently only forward supported | |
2705 | */ | |
2706 | if (bpa->nh.type == NEXTHOP_TYPE_BLACKHOLE) | |
2707 | stream_putl(s, ZEBRA_IPTABLES_DROP); | |
2708 | else | |
2709 | stream_putl(s, ZEBRA_IPTABLES_FORWARD); | |
2710 | stream_putl(s, bpa->fwmark); | |
2711 | stream_put(s, pbm->ipset_name, | |
2712 | ZEBRA_IPSET_NAME_SIZE); | |
a60b7031 | 2713 | stream_putc(s, pbm->family); |
83360720 PG |
2714 | stream_putw(s, pbm->pkt_len_min); |
2715 | stream_putw(s, pbm->pkt_len_max); | |
2da7d62e PG |
2716 | stream_putw(s, pbm->tcp_flags); |
2717 | stream_putw(s, pbm->tcp_mask_flags); | |
4977bd6c | 2718 | stream_putc(s, pbm->dscp_value); |
6f5617d8 | 2719 | stream_putc(s, pbm->fragment); |
f449d223 | 2720 | stream_putc(s, pbm->protocol); |
a60b7031 | 2721 | stream_putw(s, pbm->flow_label); |
c16a0a62 PG |
2722 | } |
2723 | ||
ad4cbda1 | 2724 | /* BGP has established connection with Zebra. */ |
d62a17ae | 2725 | static void bgp_zebra_connected(struct zclient *zclient) |
7076bb2f | 2726 | { |
d62a17ae | 2727 | struct bgp *bgp; |
7076bb2f | 2728 | |
d62a17ae | 2729 | zclient_num_connects++; /* increment even if not responding */ |
afbb1c59 | 2730 | |
6bfcd0f1 IR |
2731 | /* Send the client registration */ |
2732 | bfd_client_sendmsg(zclient, ZEBRA_BFD_CLIENT_REGISTER, VRF_DEFAULT); | |
2733 | ||
d62a17ae | 2734 | /* At this point, we may or may not have BGP instances configured, but |
2735 | * we're only interested in the default VRF (others wouldn't have learnt | |
2736 | * the VRF from Zebra yet.) | |
2737 | */ | |
2738 | bgp = bgp_get_default(); | |
2739 | if (!bgp) | |
2740 | return; | |
ad4cbda1 | 2741 | |
d62a17ae | 2742 | bgp_zebra_instance_register(bgp); |
ad4cbda1 | 2743 | |
955bfd98 | 2744 | /* tell label pool that zebra is connected */ |
e70e9f8e | 2745 | bgp_lp_event_zebra_up(); |
955bfd98 | 2746 | |
d62a17ae | 2747 | /* TODO - What if we have peers and networks configured, do we have to |
2748 | * kick-start them? | |
2749 | */ | |
85ef4179 | 2750 | BGP_GR_ROUTER_DETECT_AND_SEND_CAPABILITY_TO_ZEBRA(bgp, bgp->peer); |
7076bb2f FL |
2751 | } |
2752 | ||
c44ab6f1 AK |
2753 | static int bgp_zebra_process_local_es_add(ZAPI_CALLBACK_ARGS) |
2754 | { | |
2755 | esi_t esi; | |
2756 | struct bgp *bgp = NULL; | |
2757 | struct stream *s = NULL; | |
2758 | char buf[ESI_STR_LEN]; | |
2759 | struct in_addr originator_ip; | |
2760 | uint8_t active; | |
74be8313 | 2761 | uint8_t bypass; |
74e2bd89 | 2762 | uint16_t df_pref; |
c44ab6f1 AK |
2763 | |
2764 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2765 | if (!bgp) | |
2766 | return 0; | |
2767 | ||
2768 | s = zclient->ibuf; | |
2769 | stream_get(&esi, s, sizeof(esi_t)); | |
2770 | originator_ip.s_addr = stream_get_ipv4(s); | |
2771 | active = stream_getc(s); | |
74e2bd89 | 2772 | df_pref = stream_getw(s); |
74be8313 | 2773 | bypass = stream_getc(s); |
c44ab6f1 AK |
2774 | |
2775 | if (BGP_DEBUG(zebra, ZEBRA)) | |
74e2bd89 | 2776 | zlog_debug( |
74be8313 AK |
2777 | "Rx add ESI %s originator-ip %pI4 active %u df_pref %u %s", |
2778 | esi_to_str(&esi, buf, sizeof(buf)), &originator_ip, | |
2779 | active, df_pref, bypass ? "bypass" : ""); | |
c44ab6f1 | 2780 | |
a383bfc7 AK |
2781 | frrtrace(5, frr_bgp, evpn_mh_local_es_add_zrecv, &esi, originator_ip, |
2782 | active, bypass, df_pref); | |
2783 | ||
74be8313 AK |
2784 | bgp_evpn_local_es_add(bgp, &esi, originator_ip, active, df_pref, |
2785 | !!bypass); | |
c44ab6f1 AK |
2786 | |
2787 | return 0; | |
2788 | } | |
2789 | ||
2790 | static int bgp_zebra_process_local_es_del(ZAPI_CALLBACK_ARGS) | |
50f74cf1 | 2791 | { |
2792 | esi_t esi; | |
2793 | struct bgp *bgp = NULL; | |
2794 | struct stream *s = NULL; | |
2795 | char buf[ESI_STR_LEN]; | |
50f74cf1 | 2796 | |
2797 | memset(&esi, 0, sizeof(esi_t)); | |
c44ab6f1 AK |
2798 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2799 | if (!bgp) | |
2800 | return 0; | |
2801 | ||
2802 | s = zclient->ibuf; | |
2803 | stream_get(&esi, s, sizeof(esi_t)); | |
2804 | ||
2805 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2806 | zlog_debug("Rx del ESI %s", | |
2807 | esi_to_str(&esi, buf, sizeof(buf))); | |
2808 | ||
a383bfc7 AK |
2809 | frrtrace(1, frr_bgp, evpn_mh_local_es_del_zrecv, &esi); |
2810 | ||
c44ab6f1 AK |
2811 | bgp_evpn_local_es_del(bgp, &esi); |
2812 | ||
2813 | return 0; | |
2814 | } | |
2815 | ||
2816 | static int bgp_zebra_process_local_es_evi(ZAPI_CALLBACK_ARGS) | |
2817 | { | |
2818 | esi_t esi; | |
2819 | vni_t vni; | |
2820 | struct bgp *bgp; | |
2821 | struct stream *s; | |
2822 | char buf[ESI_STR_LEN]; | |
50f74cf1 | 2823 | |
2824 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2825 | if (!bgp) | |
2826 | return 0; | |
2827 | ||
2828 | s = zclient->ibuf; | |
2829 | stream_get(&esi, s, sizeof(esi_t)); | |
c44ab6f1 | 2830 | vni = stream_getl(s); |
50f74cf1 | 2831 | |
2832 | if (BGP_DEBUG(zebra, ZEBRA)) | |
c44ab6f1 AK |
2833 | zlog_debug("Rx %s ESI %s VNI %u", |
2834 | ZEBRA_VNI_ADD ? "add" : "del", | |
2835 | esi_to_str(&esi, buf, sizeof(buf)), vni); | |
50f74cf1 | 2836 | |
a383bfc7 AK |
2837 | if (cmd == ZEBRA_LOCAL_ES_EVI_ADD) { |
2838 | frrtrace(2, frr_bgp, evpn_mh_local_es_evi_add_zrecv, &esi, vni); | |
2839 | ||
c44ab6f1 | 2840 | bgp_evpn_local_es_evi_add(bgp, &esi, vni); |
a383bfc7 AK |
2841 | } else { |
2842 | frrtrace(2, frr_bgp, evpn_mh_local_es_evi_del_zrecv, &esi, vni); | |
2843 | ||
c44ab6f1 | 2844 | bgp_evpn_local_es_evi_del(bgp, &esi, vni); |
a383bfc7 | 2845 | } |
c44ab6f1 | 2846 | |
50f74cf1 | 2847 | return 0; |
2848 | } | |
2849 | ||
121f9dee | 2850 | static int bgp_zebra_process_local_l3vni(ZAPI_CALLBACK_ARGS) |
fe1dc5a3 | 2851 | { |
c48d9f5f | 2852 | int filter = 0; |
b67a60d2 | 2853 | vni_t l3vni = 0; |
14e814ea | 2854 | struct ethaddr svi_rmac, vrr_rmac = {.octet = {0} }; |
b67a60d2 | 2855 | struct in_addr originator_ip; |
fe1dc5a3 | 2856 | struct stream *s; |
0483af6e | 2857 | ifindex_t svi_ifindex; |
14e814ea | 2858 | bool is_anycast_mac = false; |
fe1dc5a3 | 2859 | |
14e814ea | 2860 | memset(&svi_rmac, 0, sizeof(struct ethaddr)); |
b67a60d2 | 2861 | memset(&originator_ip, 0, sizeof(struct in_addr)); |
fe1dc5a3 MK |
2862 | s = zclient->ibuf; |
2863 | l3vni = stream_getl(s); | |
b67a60d2 | 2864 | if (cmd == ZEBRA_L3VNI_ADD) { |
14e814ea | 2865 | stream_get(&svi_rmac, s, sizeof(struct ethaddr)); |
b67a60d2 | 2866 | originator_ip.s_addr = stream_get_ipv4(s); |
c48d9f5f | 2867 | stream_get(&filter, s, sizeof(int)); |
0483af6e | 2868 | svi_ifindex = stream_getl(s); |
14e814ea CS |
2869 | stream_get(&vrr_rmac, s, sizeof(struct ethaddr)); |
2870 | is_anycast_mac = stream_getl(s); | |
fe1dc5a3 | 2871 | |
0483af6e | 2872 | if (BGP_DEBUG(zebra, ZEBRA)) |
c0d72166 DS |
2873 | zlog_debug( |
2874 | "Rx L3-VNI ADD VRF %s VNI %u RMAC svi-mac %pEA vrr-mac %pEA filter %s svi-if %u", | |
2875 | vrf_id_to_name(vrf_id), l3vni, &svi_rmac, | |
2876 | &vrr_rmac, | |
2877 | filter ? "prefix-routes-only" : "none", | |
2878 | svi_ifindex); | |
fe1dc5a3 | 2879 | |
a383bfc7 AK |
2880 | frrtrace(8, frr_bgp, evpn_local_l3vni_add_zrecv, l3vni, vrf_id, |
2881 | &svi_rmac, &vrr_rmac, filter, originator_ip, | |
2882 | svi_ifindex, is_anycast_mac); | |
2883 | ||
14e814ea CS |
2884 | bgp_evpn_local_l3vni_add(l3vni, vrf_id, &svi_rmac, &vrr_rmac, |
2885 | originator_ip, filter, svi_ifindex, | |
2886 | is_anycast_mac); | |
0483af6e | 2887 | } else { |
2888 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2889 | zlog_debug("Rx L3-VNI DEL VRF %s VNI %u", | |
2890 | vrf_id_to_name(vrf_id), l3vni); | |
2891 | ||
a383bfc7 AK |
2892 | frrtrace(2, frr_bgp, evpn_local_l3vni_del_zrecv, l3vni, vrf_id); |
2893 | ||
fe1dc5a3 | 2894 | bgp_evpn_local_l3vni_del(l3vni, vrf_id); |
0483af6e | 2895 | } |
fe1dc5a3 MK |
2896 | |
2897 | return 0; | |
2898 | } | |
2899 | ||
121f9dee | 2900 | static int bgp_zebra_process_local_vni(ZAPI_CALLBACK_ARGS) |
128ea8ab | 2901 | { |
d62a17ae | 2902 | struct stream *s; |
2903 | vni_t vni; | |
2904 | struct bgp *bgp; | |
a4d82a8a | 2905 | struct in_addr vtep_ip = {INADDR_ANY}; |
29c53922 | 2906 | vrf_id_t tenant_vrf_id = VRF_DEFAULT; |
76d07c7a | 2907 | struct in_addr mcast_grp = {INADDR_ANY}; |
9daa5d47 | 2908 | ifindex_t svi_ifindex = 0; |
d62a17ae | 2909 | |
2910 | s = zclient->ibuf; | |
2911 | vni = stream_getl(s); | |
121f9dee | 2912 | if (cmd == ZEBRA_VNI_ADD) { |
d62a17ae | 2913 | vtep_ip.s_addr = stream_get_ipv4(s); |
29c53922 | 2914 | stream_get(&tenant_vrf_id, s, sizeof(vrf_id_t)); |
76d07c7a | 2915 | mcast_grp.s_addr = stream_get_ipv4(s); |
9daa5d47 | 2916 | stream_get(&svi_ifindex, s, sizeof(ifindex_t)); |
29c53922 MK |
2917 | } |
2918 | ||
d62a17ae | 2919 | bgp = bgp_lookup_by_vrf_id(vrf_id); |
2920 | if (!bgp) | |
2921 | return 0; | |
2922 | ||
2923 | if (BGP_DEBUG(zebra, ZEBRA)) | |
9daa5d47 AD |
2924 | zlog_debug( |
2925 | "Rx VNI %s VRF %s VNI %u tenant-vrf %s SVI ifindex %u", | |
2926 | (cmd == ZEBRA_VNI_ADD) ? "add" : "del", | |
2927 | vrf_id_to_name(vrf_id), vni, | |
2928 | vrf_id_to_name(tenant_vrf_id), svi_ifindex); | |
d62a17ae | 2929 | |
a383bfc7 AK |
2930 | if (cmd == ZEBRA_VNI_ADD) { |
2931 | frrtrace(4, frr_bgp, evpn_local_vni_add_zrecv, vni, vtep_ip, | |
2932 | tenant_vrf_id, mcast_grp); | |
2933 | ||
d62a17ae | 2934 | return bgp_evpn_local_vni_add( |
975a328e DA |
2935 | bgp, vni, |
2936 | vtep_ip.s_addr != INADDR_ANY ? vtep_ip : bgp->router_id, | |
9daa5d47 | 2937 | tenant_vrf_id, mcast_grp, svi_ifindex); |
a383bfc7 AK |
2938 | } else { |
2939 | frrtrace(1, frr_bgp, evpn_local_vni_del_zrecv, vni); | |
2940 | ||
d62a17ae | 2941 | return bgp_evpn_local_vni_del(bgp, vni); |
a383bfc7 | 2942 | } |
128ea8ab | 2943 | } |
2944 | ||
121f9dee | 2945 | static int bgp_zebra_process_local_macip(ZAPI_CALLBACK_ARGS) |
128ea8ab | 2946 | { |
d62a17ae | 2947 | struct stream *s; |
2948 | vni_t vni; | |
2949 | struct bgp *bgp; | |
2950 | struct ethaddr mac; | |
2951 | struct ipaddr ip; | |
2952 | int ipa_len; | |
f07e1c99 | 2953 | uint8_t flags = 0; |
2954 | uint32_t seqnum = 0; | |
ec0ab544 | 2955 | int state = 0; |
c44ab6f1 AK |
2956 | char buf2[ESI_STR_LEN]; |
2957 | esi_t esi; | |
d62a17ae | 2958 | |
2959 | memset(&ip, 0, sizeof(ip)); | |
2960 | s = zclient->ibuf; | |
2961 | vni = stream_getl(s); | |
28328ea9 | 2962 | stream_get(&mac.octet, s, ETH_ALEN); |
d62a17ae | 2963 | ipa_len = stream_getl(s); |
2964 | if (ipa_len != 0 && ipa_len != IPV4_MAX_BYTELEN | |
2965 | && ipa_len != IPV6_MAX_BYTELEN) { | |
e50f7cfd | 2966 | flog_err(EC_BGP_MACIP_LEN, |
1c50c1c0 | 2967 | "%u:Recv MACIP %s with invalid IP addr length %d", |
121f9dee | 2968 | vrf_id, (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", |
1c50c1c0 | 2969 | ipa_len); |
d62a17ae | 2970 | return -1; |
2971 | } | |
2972 | ||
2973 | if (ipa_len) { | |
2974 | ip.ipa_type = | |
2975 | (ipa_len == IPV4_MAX_BYTELEN) ? IPADDR_V4 : IPADDR_V6; | |
2976 | stream_get(&ip.ip.addr, s, ipa_len); | |
2977 | } | |
121f9dee | 2978 | if (cmd == ZEBRA_MACIP_ADD) { |
f07e1c99 | 2979 | flags = stream_getc(s); |
2980 | seqnum = stream_getl(s); | |
c44ab6f1 | 2981 | stream_get(&esi, s, sizeof(esi_t)); |
ec0ab544 AK |
2982 | } else { |
2983 | state = stream_getl(s); | |
35fb444b | 2984 | memset(&esi, 0, sizeof(esi_t)); |
f07e1c99 | 2985 | } |
d62a17ae | 2986 | |
2987 | bgp = bgp_lookup_by_vrf_id(vrf_id); | |
2988 | if (!bgp) | |
2989 | return 0; | |
2990 | ||
2991 | if (BGP_DEBUG(zebra, ZEBRA)) | |
c0d72166 | 2992 | zlog_debug( |
2dd0dde7 | 2993 | "%u:Recv MACIP %s f 0x%x MAC %pEA IP %pIA VNI %u seq %u state %d ESI %s", |
c0d72166 DS |
2994 | vrf_id, (cmd == ZEBRA_MACIP_ADD) ? "Add" : "Del", flags, |
2995 | &mac, &ip, vni, seqnum, state, | |
2996 | esi_to_str(&esi, buf2, sizeof(buf2))); | |
d62a17ae | 2997 | |
a383bfc7 AK |
2998 | if (cmd == ZEBRA_MACIP_ADD) { |
2999 | frrtrace(6, frr_bgp, evpn_local_macip_add_zrecv, vni, &mac, &ip, | |
3000 | flags, seqnum, &esi); | |
3001 | ||
f07e1c99 | 3002 | return bgp_evpn_local_macip_add(bgp, vni, &mac, &ip, |
c44ab6f1 | 3003 | flags, seqnum, &esi); |
a383bfc7 AK |
3004 | } else { |
3005 | frrtrace(4, frr_bgp, evpn_local_macip_del_zrecv, vni, &mac, &ip, | |
3006 | state); | |
3007 | ||
ec0ab544 | 3008 | return bgp_evpn_local_macip_del(bgp, vni, &mac, &ip, state); |
a383bfc7 | 3009 | } |
128ea8ab | 3010 | } |
6aeb9e78 | 3011 | |
a243d1db | 3012 | static int bgp_zebra_process_local_ip_prefix(ZAPI_CALLBACK_ARGS) |
31310b25 MK |
3013 | { |
3014 | struct stream *s = NULL; | |
3015 | struct bgp *bgp_vrf = NULL; | |
3016 | struct prefix p; | |
31310b25 MK |
3017 | |
3018 | memset(&p, 0, sizeof(struct prefix)); | |
3019 | s = zclient->ibuf; | |
3020 | stream_get(&p, s, sizeof(struct prefix)); | |
3021 | ||
3022 | bgp_vrf = bgp_lookup_by_vrf_id(vrf_id); | |
3023 | if (!bgp_vrf) | |
a243d1db | 3024 | return 0; |
31310b25 MK |
3025 | |
3026 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2dbe669b | 3027 | zlog_debug("Recv prefix %pFX %s on vrf %s", &p, |
31310b25 MK |
3028 | (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) ? "ADD" : "DEL", |
3029 | vrf_id_to_name(vrf_id)); | |
3030 | ||
3031 | if (cmd == ZEBRA_IP_PREFIX_ROUTE_ADD) { | |
3032 | ||
3033 | if (p.family == AF_INET) | |
d90b788e A |
3034 | bgp_evpn_advertise_type5_route(bgp_vrf, &p, NULL, |
3035 | AFI_IP, SAFI_UNICAST); | |
31310b25 | 3036 | else |
d90b788e A |
3037 | bgp_evpn_advertise_type5_route(bgp_vrf, &p, NULL, |
3038 | AFI_IP6, SAFI_UNICAST); | |
31310b25 MK |
3039 | |
3040 | } else { | |
3041 | if (p.family == AF_INET) | |
d90b788e A |
3042 | bgp_evpn_withdraw_type5_route(bgp_vrf, &p, AFI_IP, |
3043 | SAFI_UNICAST); | |
31310b25 | 3044 | else |
d90b788e A |
3045 | bgp_evpn_withdraw_type5_route(bgp_vrf, &p, AFI_IP6, |
3046 | SAFI_UNICAST); | |
31310b25 | 3047 | } |
a243d1db | 3048 | return 0; |
31310b25 MK |
3049 | } |
3050 | ||
a243d1db | 3051 | static int bgp_zebra_process_label_chunk(ZAPI_CALLBACK_ARGS) |
955bfd98 PZ |
3052 | { |
3053 | struct stream *s = NULL; | |
3054 | uint8_t response_keep; | |
3055 | uint32_t first; | |
3056 | uint32_t last; | |
aec865e4 FR |
3057 | uint8_t proto; |
3058 | unsigned short instance; | |
955bfd98 PZ |
3059 | |
3060 | s = zclient->ibuf; | |
aec865e4 FR |
3061 | STREAM_GETC(s, proto); |
3062 | STREAM_GETW(s, instance); | |
955bfd98 PZ |
3063 | STREAM_GETC(s, response_keep); |
3064 | STREAM_GETL(s, first); | |
3065 | STREAM_GETL(s, last); | |
3066 | ||
aec865e4 | 3067 | if (zclient->redist_default != proto) { |
e50f7cfd | 3068 | flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong proto %u", |
1c50c1c0 | 3069 | proto); |
a243d1db | 3070 | return 0; |
aec865e4 FR |
3071 | } |
3072 | if (zclient->instance != instance) { | |
e50f7cfd | 3073 | flog_err(EC_BGP_LM_ERROR, "Got LM msg with wrong instance %u", |
1c50c1c0 | 3074 | proto); |
a243d1db | 3075 | return 0; |
aec865e4 FR |
3076 | } |
3077 | ||
955bfd98 PZ |
3078 | if (first > last || |
3079 | first < MPLS_LABEL_UNRESERVED_MIN || | |
3080 | last > MPLS_LABEL_UNRESERVED_MAX) { | |
3081 | ||
e50f7cfd | 3082 | flog_err(EC_BGP_LM_ERROR, "%s: Invalid Label chunk: %u - %u", |
1c50c1c0 | 3083 | __func__, first, last); |
a243d1db | 3084 | return 0; |
955bfd98 PZ |
3085 | } |
3086 | if (BGP_DEBUG(zebra, ZEBRA)) { | |
3087 | zlog_debug("Label Chunk assign: %u - %u (%u) ", | |
3088 | first, last, response_keep); | |
3089 | } | |
3090 | ||
e70e9f8e | 3091 | bgp_lp_event_chunk(response_keep, first, last); |
955bfd98 | 3092 | |
a243d1db DL |
3093 | return 0; |
3094 | ||
955bfd98 | 3095 | stream_failure: /* for STREAM_GETX */ |
a243d1db | 3096 | return -1; |
955bfd98 PZ |
3097 | } |
3098 | ||
342213ea DS |
3099 | extern struct zebra_privs_t bgpd_privs; |
3100 | ||
138c5a74 DS |
3101 | static int bgp_ifp_create(struct interface *ifp) |
3102 | { | |
ef7bd2a3 DS |
3103 | struct bgp *bgp; |
3104 | ||
3105 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3106 | zlog_debug("Rx Intf add VRF %u IF %s", ifp->vrf_id, ifp->name); | |
3107 | ||
3108 | bgp = bgp_lookup_by_vrf_id(ifp->vrf_id); | |
3109 | if (!bgp) | |
3110 | return 0; | |
3111 | ||
3112 | bgp_mac_add_mac_entry(ifp); | |
3113 | ||
3114 | bgp_update_interface_nbrs(bgp, ifp, ifp); | |
0d020cd6 | 3115 | hook_call(bgp_vrf_status_changed, bgp, ifp); |
138c5a74 DS |
3116 | return 0; |
3117 | } | |
3118 | ||
a243d1db | 3119 | static int bgp_zebra_process_srv6_locator_chunk(ZAPI_CALLBACK_ARGS) |
a0281b2e HS |
3120 | { |
3121 | struct stream *s = NULL; | |
7de4c885 HS |
3122 | struct bgp *bgp = bgp_get_default(); |
3123 | struct listnode *node; | |
3124 | struct prefix_ipv6 *c; | |
1bda3e62 | 3125 | struct srv6_locator_chunk s6c = {}; |
3a0220e4 | 3126 | struct prefix_ipv6 *chunk = NULL; |
a0281b2e HS |
3127 | |
3128 | s = zclient->ibuf; | |
3a0220e4 | 3129 | zapi_srv6_locator_chunk_decode(s, &s6c); |
a0281b2e | 3130 | |
3a0220e4 HS |
3131 | if (strcmp(bgp->srv6_locator_name, s6c.locator_name) != 0) { |
3132 | zlog_err("%s: Locator name unmatch %s:%s", __func__, | |
3133 | bgp->srv6_locator_name, s6c.locator_name); | |
a243d1db | 3134 | return 0; |
a0281b2e HS |
3135 | } |
3136 | ||
a0281b2e | 3137 | for (ALL_LIST_ELEMENTS_RO(bgp->srv6_locator_chunks, node, c)) { |
3a0220e4 | 3138 | if (!prefix_cmp(c, &s6c.prefix)) |
a243d1db | 3139 | return 0; |
a0281b2e HS |
3140 | } |
3141 | ||
3a0220e4 HS |
3142 | chunk = prefix_ipv6_new(); |
3143 | *chunk = s6c.prefix; | |
a0281b2e HS |
3144 | listnode_add(bgp->srv6_locator_chunks, chunk); |
3145 | vpn_leak_postchange_all(); | |
a243d1db | 3146 | return 0; |
a0281b2e HS |
3147 | } |
3148 | ||
d79ff732 HS |
3149 | static int bgp_zebra_process_srv6_locator_add(ZAPI_CALLBACK_ARGS) |
3150 | { | |
3151 | struct srv6_locator loc = {}; | |
3152 | struct bgp *bgp = bgp_get_default(); | |
3153 | const char *loc_name = bgp->srv6_locator_name; | |
3154 | ||
3155 | if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0) | |
3156 | return -1; | |
3157 | ||
3158 | if (!bgp || !bgp->srv6_enabled) | |
3159 | return 0; | |
3160 | ||
3161 | if (bgp_zebra_srv6_manager_get_locator_chunk(loc_name) < 0) | |
3162 | return -1; | |
3163 | ||
3164 | return 0; | |
3165 | } | |
3166 | ||
3167 | static int bgp_zebra_process_srv6_locator_delete(ZAPI_CALLBACK_ARGS) | |
3168 | { | |
3169 | struct srv6_locator loc = {}; | |
3170 | struct bgp *bgp = bgp_get_default(); | |
3171 | struct listnode *node, *nnode; | |
3172 | struct prefix_ipv6 *chunk; | |
3173 | struct bgp_srv6_function *func; | |
3174 | struct bgp *bgp_vrf; | |
3175 | struct in6_addr *tovpn_sid; | |
3176 | struct prefix_ipv6 tmp_prefi; | |
3177 | ||
3178 | if (zapi_srv6_locator_decode(zclient->ibuf, &loc) < 0) | |
3179 | return -1; | |
3180 | ||
3181 | // refresh chunks | |
3182 | for (ALL_LIST_ELEMENTS(bgp->srv6_locator_chunks, node, nnode, chunk)) | |
3183 | if (prefix_match((struct prefix *)&loc.prefix, | |
3184 | (struct prefix *)chunk)) | |
3185 | listnode_delete(bgp->srv6_locator_chunks, chunk); | |
3186 | ||
3187 | // refresh functions | |
3188 | for (ALL_LIST_ELEMENTS(bgp->srv6_functions, node, nnode, func)) { | |
3189 | tmp_prefi.family = AF_INET6; | |
3190 | tmp_prefi.prefixlen = 128; | |
3191 | tmp_prefi.prefix = func->sid; | |
3192 | if (prefix_match((struct prefix *)&loc.prefix, | |
3193 | (struct prefix *)&tmp_prefi)) | |
3194 | listnode_delete(bgp->srv6_functions, func); | |
3195 | } | |
3196 | ||
3197 | // refresh tovpn_sid | |
3198 | for (ALL_LIST_ELEMENTS_RO(bm->bgp, node, bgp_vrf)) { | |
3199 | if (bgp_vrf->inst_type != BGP_INSTANCE_TYPE_VRF) | |
3200 | continue; | |
3201 | ||
3202 | // refresh vpnv4 tovpn_sid | |
3203 | tovpn_sid = bgp_vrf->vpn_policy[AFI_IP].tovpn_sid; | |
3204 | if (tovpn_sid) { | |
3205 | tmp_prefi.family = AF_INET6; | |
3206 | tmp_prefi.prefixlen = 128; | |
3207 | tmp_prefi.prefix = *tovpn_sid; | |
3208 | if (prefix_match((struct prefix *)&loc.prefix, | |
3209 | (struct prefix *)&tmp_prefi)) | |
3210 | XFREE(MTYPE_BGP_SRV6_SID, | |
3211 | bgp_vrf->vpn_policy[AFI_IP].tovpn_sid); | |
3212 | } | |
3213 | ||
3214 | // refresh vpnv6 tovpn_sid | |
3215 | tovpn_sid = bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid; | |
3216 | if (tovpn_sid) { | |
3217 | tmp_prefi.family = AF_INET6; | |
3218 | tmp_prefi.prefixlen = 128; | |
3219 | tmp_prefi.prefix = *tovpn_sid; | |
3220 | if (prefix_match((struct prefix *)&loc.prefix, | |
3221 | (struct prefix *)&tmp_prefi)) | |
3222 | XFREE(MTYPE_BGP_SRV6_SID, | |
3223 | bgp_vrf->vpn_policy[AFI_IP6].tovpn_sid); | |
3224 | } | |
3225 | } | |
3226 | ||
3227 | vpn_leak_postchange_all(); | |
3228 | return 0; | |
3229 | } | |
3230 | ||
a243d1db DL |
3231 | static zclient_handler *const bgp_handlers[] = { |
3232 | [ZEBRA_ROUTER_ID_UPDATE] = bgp_router_id_update, | |
3233 | [ZEBRA_INTERFACE_ADDRESS_ADD] = bgp_interface_address_add, | |
3234 | [ZEBRA_INTERFACE_ADDRESS_DELETE] = bgp_interface_address_delete, | |
3235 | [ZEBRA_INTERFACE_NBR_ADDRESS_ADD] = bgp_interface_nbr_address_add, | |
3236 | [ZEBRA_INTERFACE_NBR_ADDRESS_DELETE] = bgp_interface_nbr_address_delete, | |
3237 | [ZEBRA_INTERFACE_VRF_UPDATE] = bgp_interface_vrf_update, | |
3238 | [ZEBRA_REDISTRIBUTE_ROUTE_ADD] = zebra_read_route, | |
3239 | [ZEBRA_REDISTRIBUTE_ROUTE_DEL] = zebra_read_route, | |
3240 | [ZEBRA_NEXTHOP_UPDATE] = bgp_read_nexthop_update, | |
3241 | [ZEBRA_FEC_UPDATE] = bgp_read_fec_update, | |
3242 | [ZEBRA_LOCAL_ES_ADD] = bgp_zebra_process_local_es_add, | |
3243 | [ZEBRA_LOCAL_ES_DEL] = bgp_zebra_process_local_es_del, | |
3244 | [ZEBRA_VNI_ADD] = bgp_zebra_process_local_vni, | |
3245 | [ZEBRA_LOCAL_ES_EVI_ADD] = bgp_zebra_process_local_es_evi, | |
3246 | [ZEBRA_LOCAL_ES_EVI_DEL] = bgp_zebra_process_local_es_evi, | |
3247 | [ZEBRA_VNI_DEL] = bgp_zebra_process_local_vni, | |
3248 | [ZEBRA_MACIP_ADD] = bgp_zebra_process_local_macip, | |
3249 | [ZEBRA_MACIP_DEL] = bgp_zebra_process_local_macip, | |
3250 | [ZEBRA_L3VNI_ADD] = bgp_zebra_process_local_l3vni, | |
3251 | [ZEBRA_L3VNI_DEL] = bgp_zebra_process_local_l3vni, | |
3252 | [ZEBRA_IP_PREFIX_ROUTE_ADD] = bgp_zebra_process_local_ip_prefix, | |
3253 | [ZEBRA_IP_PREFIX_ROUTE_DEL] = bgp_zebra_process_local_ip_prefix, | |
3254 | [ZEBRA_GET_LABEL_CHUNK] = bgp_zebra_process_label_chunk, | |
3255 | [ZEBRA_RULE_NOTIFY_OWNER] = rule_notify_owner, | |
3256 | [ZEBRA_IPSET_NOTIFY_OWNER] = ipset_notify_owner, | |
3257 | [ZEBRA_IPSET_ENTRY_NOTIFY_OWNER] = ipset_entry_notify_owner, | |
3258 | [ZEBRA_IPTABLE_NOTIFY_OWNER] = iptable_notify_owner, | |
3259 | [ZEBRA_ROUTE_NOTIFY_OWNER] = bgp_zebra_route_notify_owner, | |
3260 | [ZEBRA_SRV6_LOCATOR_ADD] = bgp_zebra_process_srv6_locator_add, | |
3261 | [ZEBRA_SRV6_LOCATOR_DELETE] = bgp_zebra_process_srv6_locator_delete, | |
3262 | [ZEBRA_SRV6_MANAGER_GET_LOCATOR_CHUNK] = | |
3263 | bgp_zebra_process_srv6_locator_chunk, | |
3264 | }; | |
3265 | ||
f533be73 | 3266 | void bgp_zebra_init(struct thread_master *master, unsigned short instance) |
718e3744 | 3267 | { |
d62a17ae | 3268 | zclient_num_connects = 0; |
3269 | ||
138c5a74 DS |
3270 | if_zapi_callbacks(bgp_ifp_create, bgp_ifp_up, |
3271 | bgp_ifp_down, bgp_ifp_destroy); | |
3272 | ||
d62a17ae | 3273 | /* Set default values. */ |
a243d1db DL |
3274 | zclient = zclient_new(master, &zclient_options_default, bgp_handlers, |
3275 | array_size(bgp_handlers)); | |
342213ea | 3276 | zclient_init(zclient, ZEBRA_ROUTE_BGP, 0, &bgpd_privs); |
d62a17ae | 3277 | zclient->zebra_connected = bgp_zebra_connected; |
f533be73 | 3278 | zclient->instance = instance; |
718e3744 | 3279 | } |
bb86c601 | 3280 | |
d62a17ae | 3281 | void bgp_zebra_destroy(void) |
bb86c601 | 3282 | { |
d62a17ae | 3283 | if (zclient == NULL) |
3284 | return; | |
3285 | zclient_stop(zclient); | |
3286 | zclient_free(zclient); | |
3287 | zclient = NULL; | |
bb86c601 | 3288 | } |
afbb1c59 | 3289 | |
d62a17ae | 3290 | int bgp_zebra_num_connects(void) |
afbb1c59 | 3291 | { |
d62a17ae | 3292 | return zclient_num_connects; |
afbb1c59 | 3293 | } |
30d50e6d | 3294 | |
6cfe5d15 PG |
3295 | void bgp_send_pbr_rule_action(struct bgp_pbr_action *pbra, |
3296 | struct bgp_pbr_rule *pbr, | |
3297 | bool install) | |
30d50e6d PG |
3298 | { |
3299 | struct stream *s; | |
3300 | ||
6cfe5d15 | 3301 | if (pbra->install_in_progress && !pbr) |
30d50e6d | 3302 | return; |
6cfe5d15 PG |
3303 | if (pbr && pbr->install_in_progress) |
3304 | return; | |
3305 | if (BGP_DEBUG(zebra, ZEBRA)) { | |
3306 | if (pbr) | |
15569c58 | 3307 | zlog_debug("%s: table %d (ip rule) %d", __func__, |
6cfe5d15 PG |
3308 | pbra->table_id, install); |
3309 | else | |
15569c58 | 3310 | zlog_debug("%s: table %d fwmark %d %d", __func__, |
6cfe5d15 PG |
3311 | pbra->table_id, pbra->fwmark, install); |
3312 | } | |
30d50e6d PG |
3313 | s = zclient->obuf; |
3314 | stream_reset(s); | |
3315 | ||
3316 | zclient_create_header(s, | |
3317 | install ? ZEBRA_RULE_ADD : ZEBRA_RULE_DELETE, | |
3318 | VRF_DEFAULT); | |
3319 | stream_putl(s, 1); /* send one pbr action */ | |
3320 | ||
6cfe5d15 | 3321 | bgp_encode_pbr_rule_action(s, pbra, pbr); |
30d50e6d PG |
3322 | |
3323 | stream_putw_at(s, 0, stream_get_endp(s)); | |
8a3f8f2e DS |
3324 | if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) |
3325 | && install) { | |
6cfe5d15 PG |
3326 | if (!pbr) |
3327 | pbra->install_in_progress = true; | |
3328 | else | |
3329 | pbr->install_in_progress = true; | |
3330 | } | |
30d50e6d PG |
3331 | } |
3332 | ||
3333 | void bgp_send_pbr_ipset_match(struct bgp_pbr_match *pbrim, bool install) | |
3334 | { | |
3335 | struct stream *s; | |
3336 | ||
3337 | if (pbrim->install_in_progress) | |
3338 | return; | |
f0936054 | 3339 | if (BGP_DEBUG(zebra, ZEBRA)) |
15569c58 DA |
3340 | zlog_debug("%s: name %s type %d %d, ID %u", __func__, |
3341 | pbrim->ipset_name, pbrim->type, install, | |
3342 | pbrim->unique); | |
30d50e6d PG |
3343 | s = zclient->obuf; |
3344 | stream_reset(s); | |
3345 | ||
3346 | zclient_create_header(s, | |
3347 | install ? ZEBRA_IPSET_CREATE : | |
3348 | ZEBRA_IPSET_DESTROY, | |
3349 | VRF_DEFAULT); | |
3350 | ||
3351 | stream_putl(s, 1); /* send one pbr action */ | |
3352 | ||
3353 | bgp_encode_pbr_ipset_match(s, pbrim); | |
3354 | ||
3355 | stream_putw_at(s, 0, stream_get_endp(s)); | |
8a3f8f2e | 3356 | if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) && install) |
30d50e6d PG |
3357 | pbrim->install_in_progress = true; |
3358 | } | |
3359 | ||
3360 | void bgp_send_pbr_ipset_entry_match(struct bgp_pbr_match_entry *pbrime, | |
3361 | bool install) | |
3362 | { | |
3363 | struct stream *s; | |
3364 | ||
3365 | if (pbrime->install_in_progress) | |
3366 | return; | |
f0936054 | 3367 | if (BGP_DEBUG(zebra, ZEBRA)) |
15569c58 DA |
3368 | zlog_debug("%s: name %s %d %d, ID %u", __func__, |
3369 | pbrime->backpointer->ipset_name, pbrime->unique, | |
3370 | install, pbrime->unique); | |
30d50e6d PG |
3371 | s = zclient->obuf; |
3372 | stream_reset(s); | |
3373 | ||
3374 | zclient_create_header(s, | |
3375 | install ? ZEBRA_IPSET_ENTRY_ADD : | |
3376 | ZEBRA_IPSET_ENTRY_DELETE, | |
3377 | VRF_DEFAULT); | |
3378 | ||
3379 | stream_putl(s, 1); /* send one pbr action */ | |
3380 | ||
3381 | bgp_encode_pbr_ipset_entry_match(s, pbrime); | |
3382 | ||
3383 | stream_putw_at(s, 0, stream_get_endp(s)); | |
8a3f8f2e | 3384 | if ((zclient_send_message(zclient) != ZCLIENT_SEND_FAILURE) && install) |
30d50e6d PG |
3385 | pbrime->install_in_progress = true; |
3386 | } | |
c16a0a62 | 3387 | |
8f242187 PG |
3388 | static void bgp_encode_pbr_interface_list(struct bgp *bgp, struct stream *s, |
3389 | uint8_t family) | |
4762c213 PG |
3390 | { |
3391 | struct bgp_pbr_config *bgp_pbr_cfg = bgp->bgp_pbr_cfg; | |
3392 | struct bgp_pbr_interface_head *head; | |
3393 | struct bgp_pbr_interface *pbr_if; | |
3394 | struct interface *ifp; | |
3395 | ||
3396 | if (!bgp_pbr_cfg) | |
3397 | return; | |
8f242187 PG |
3398 | if (family == AF_INET) |
3399 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); | |
3400 | else | |
3401 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv6); | |
4762c213 | 3402 | RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { |
a36898e7 | 3403 | ifp = if_lookup_by_name(pbr_if->name, bgp->vrf_id); |
4762c213 PG |
3404 | if (ifp) |
3405 | stream_putl(s, ifp->ifindex); | |
3406 | } | |
3407 | } | |
3408 | ||
8f242187 | 3409 | static int bgp_pbr_get_ifnumber(struct bgp *bgp, uint8_t family) |
4762c213 PG |
3410 | { |
3411 | struct bgp_pbr_config *bgp_pbr_cfg = bgp->bgp_pbr_cfg; | |
3412 | struct bgp_pbr_interface_head *head; | |
3413 | struct bgp_pbr_interface *pbr_if; | |
3414 | int cnt = 0; | |
3415 | ||
3416 | if (!bgp_pbr_cfg) | |
3417 | return 0; | |
8f242187 PG |
3418 | if (family == AF_INET) |
3419 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv4); | |
3420 | else | |
3421 | head = &(bgp_pbr_cfg->ifaces_by_name_ipv6); | |
4762c213 | 3422 | RB_FOREACH (pbr_if, bgp_pbr_interface_head, head) { |
a36898e7 | 3423 | if (if_lookup_by_name(pbr_if->name, bgp->vrf_id)) |
4762c213 PG |
3424 | cnt++; |
3425 | } | |
3426 | return cnt; | |
3427 | } | |
3428 | ||
c16a0a62 PG |
3429 | void bgp_send_pbr_iptable(struct bgp_pbr_action *pba, |
3430 | struct bgp_pbr_match *pbm, | |
3431 | bool install) | |
3432 | { | |
3433 | struct stream *s; | |
b5c40105 | 3434 | int ret = 0; |
4762c213 | 3435 | int nb_interface; |
c16a0a62 PG |
3436 | |
3437 | if (pbm->install_iptable_in_progress) | |
3438 | return; | |
f0936054 | 3439 | if (BGP_DEBUG(zebra, ZEBRA)) |
15569c58 DA |
3440 | zlog_debug("%s: name %s type %d mark %d %d, ID %u", __func__, |
3441 | pbm->ipset_name, pbm->type, pba->fwmark, install, | |
88055124 | 3442 | pbm->unique2); |
c16a0a62 PG |
3443 | s = zclient->obuf; |
3444 | stream_reset(s); | |
3445 | ||
3446 | zclient_create_header(s, | |
3447 | install ? ZEBRA_IPTABLE_ADD : | |
3448 | ZEBRA_IPTABLE_DELETE, | |
3449 | VRF_DEFAULT); | |
3450 | ||
3451 | bgp_encode_pbr_iptable_match(s, pba, pbm); | |
8f242187 | 3452 | nb_interface = bgp_pbr_get_ifnumber(pba->bgp, pbm->family); |
4762c213 PG |
3453 | stream_putl(s, nb_interface); |
3454 | if (nb_interface) | |
8f242187 | 3455 | bgp_encode_pbr_interface_list(pba->bgp, s, pbm->family); |
c16a0a62 | 3456 | stream_putw_at(s, 0, stream_get_endp(s)); |
b5c40105 PG |
3457 | ret = zclient_send_message(zclient); |
3458 | if (install) { | |
8a3f8f2e | 3459 | if (ret != ZCLIENT_SEND_FAILURE) |
b5c40105 PG |
3460 | pba->refcnt++; |
3461 | else | |
3462 | pbm->install_iptable_in_progress = true; | |
a6b07429 | 3463 | } |
c16a0a62 | 3464 | } |
f7df1907 PG |
3465 | |
3466 | /* inject in table <table_id> a default route to: | |
3467 | * - if nexthop IP is present : to this nexthop | |
3468 | * - if vrf is different from local : to the matching VRF | |
3469 | */ | |
3470 | void bgp_zebra_announce_default(struct bgp *bgp, struct nexthop *nh, | |
3471 | afi_t afi, uint32_t table_id, bool announce) | |
3472 | { | |
3473 | struct zapi_nexthop *api_nh; | |
3474 | struct zapi_route api; | |
3475 | struct prefix p; | |
3476 | ||
f01e580f PG |
3477 | if (!nh || (nh->type != NEXTHOP_TYPE_IPV4 |
3478 | && nh->type != NEXTHOP_TYPE_IPV6) | |
f7df1907 PG |
3479 | || nh->vrf_id == VRF_UNKNOWN) |
3480 | return; | |
7afeaffa PG |
3481 | |
3482 | /* in vrf-lite, no default route has to be announced | |
3483 | * the table id of vrf is directly used to divert traffic | |
3484 | */ | |
3485 | if (!vrf_is_backend_netns() && bgp->vrf_id != nh->vrf_id) | |
3486 | return; | |
3487 | ||
f7df1907 | 3488 | memset(&p, 0, sizeof(struct prefix)); |
f01e580f | 3489 | if (afi != AFI_IP && afi != AFI_IP6) |
f7df1907 | 3490 | return; |
f01e580f | 3491 | p.family = afi2family(afi); |
f7df1907 PG |
3492 | memset(&api, 0, sizeof(api)); |
3493 | api.vrf_id = bgp->vrf_id; | |
3494 | api.type = ZEBRA_ROUTE_BGP; | |
3495 | api.safi = SAFI_UNICAST; | |
3496 | api.prefix = p; | |
3497 | api.tableid = table_id; | |
3498 | api.nexthop_num = 1; | |
3499 | SET_FLAG(api.message, ZAPI_MESSAGE_TABLEID); | |
3500 | SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP); | |
3501 | api_nh = &api.nexthops[0]; | |
3502 | ||
38a8c751 DS |
3503 | api.distance = ZEBRA_EBGP_DISTANCE_DEFAULT; |
3504 | SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE); | |
3505 | ||
f7df1907 | 3506 | /* redirect IP */ |
f01e580f | 3507 | if (afi == AFI_IP && nh->gate.ipv4.s_addr != INADDR_ANY) { |
f7df1907 PG |
3508 | char buff[PREFIX_STRLEN]; |
3509 | ||
3510 | api_nh->vrf_id = nh->vrf_id; | |
3511 | api_nh->gate.ipv4 = nh->gate.ipv4; | |
3512 | api_nh->type = NEXTHOP_TYPE_IPV4; | |
3513 | ||
3514 | inet_ntop(AF_INET, &(nh->gate.ipv4), buff, INET_ADDRSTRLEN); | |
3515 | if (BGP_DEBUG(zebra, ZEBRA)) | |
f01e580f PG |
3516 | zlog_debug("BGP: %s default route to %s table %d (redirect IP)", |
3517 | announce ? "adding" : "withdrawing", | |
3518 | buff, table_id); | |
3519 | zclient_route_send(announce ? ZEBRA_ROUTE_ADD | |
3520 | : ZEBRA_ROUTE_DELETE, | |
3521 | zclient, &api); | |
3522 | } else if (afi == AFI_IP6 && | |
3523 | memcmp(&nh->gate.ipv6, | |
3524 | &in6addr_any, sizeof(struct in6_addr))) { | |
3525 | char buff[PREFIX_STRLEN]; | |
3526 | ||
3527 | api_nh->vrf_id = nh->vrf_id; | |
3528 | memcpy(&api_nh->gate.ipv6, &nh->gate.ipv6, | |
3529 | sizeof(struct in6_addr)); | |
3530 | api_nh->type = NEXTHOP_TYPE_IPV6; | |
3531 | ||
3532 | inet_ntop(AF_INET6, &(nh->gate.ipv6), buff, INET_ADDRSTRLEN); | |
3533 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3534 | zlog_debug("BGP: %s default route to %s table %d (redirect IP)", | |
d887503c | 3535 | announce ? "adding" : "withdrawing", |
f7df1907 PG |
3536 | buff, table_id); |
3537 | zclient_route_send(announce ? ZEBRA_ROUTE_ADD | |
3538 | : ZEBRA_ROUTE_DELETE, | |
3539 | zclient, &api); | |
3540 | } else if (nh->vrf_id != bgp->vrf_id) { | |
3541 | struct vrf *vrf; | |
eb4244f8 | 3542 | struct interface *ifp; |
f7df1907 | 3543 | |
eb4244f8 | 3544 | vrf = vrf_lookup_by_id(nh->vrf_id); |
f7df1907 PG |
3545 | if (!vrf) |
3546 | return; | |
eb4244f8 PG |
3547 | /* create default route with interface <VRF> |
3548 | * with nexthop-vrf <VRF> | |
f7df1907 | 3549 | */ |
eb4244f8 PG |
3550 | ifp = if_lookup_by_name_all_vrf(vrf->name); |
3551 | if (!ifp) | |
3552 | return; | |
3553 | api_nh->vrf_id = nh->vrf_id; | |
3554 | api_nh->type = NEXTHOP_TYPE_IFINDEX; | |
3555 | api_nh->ifindex = ifp->ifindex; | |
3556 | if (BGP_DEBUG(zebra, ZEBRA)) | |
d887503c PG |
3557 | zlog_info("BGP: %s default route to %s table %d (redirect VRF)", |
3558 | announce ? "adding" : "withdrawing", | |
eb4244f8 PG |
3559 | vrf->name, table_id); |
3560 | zclient_route_send(announce ? ZEBRA_ROUTE_ADD | |
3561 | : ZEBRA_ROUTE_DELETE, | |
3562 | zclient, &api); | |
f7df1907 PG |
3563 | return; |
3564 | } | |
3565 | } | |
85ef4179 | 3566 | |
3567 | /* Send capabilities to RIB */ | |
3568 | int bgp_zebra_send_capabilities(struct bgp *bgp, bool disable) | |
3569 | { | |
3570 | struct zapi_cap api; | |
3571 | int ret = BGP_GR_SUCCESS; | |
3572 | ||
3573 | if (zclient == NULL) { | |
3574 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3575 | zlog_debug("zclient invalid"); | |
3576 | return BGP_GR_FAILURE; | |
3577 | } | |
3578 | ||
3579 | /* Check if the client is connected */ | |
3580 | if ((zclient->sock < 0) || (zclient->t_connect)) { | |
3581 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3582 | zlog_debug("client not connected"); | |
3583 | return BGP_GR_FAILURE; | |
3584 | } | |
3585 | ||
3586 | /* Check if capability is already sent. If the flag force is set | |
3587 | * send the capability since this can be initial bgp configuration | |
3588 | */ | |
3589 | memset(&api, 0, sizeof(struct zapi_cap)); | |
3590 | if (disable) { | |
3591 | api.cap = ZEBRA_CLIENT_GR_DISABLE; | |
3592 | api.vrf_id = bgp->vrf_id; | |
3593 | } else { | |
3594 | api.cap = ZEBRA_CLIENT_GR_CAPABILITIES; | |
3595 | api.stale_removal_time = bgp->rib_stale_time; | |
3596 | api.vrf_id = bgp->vrf_id; | |
3597 | } | |
3598 | ||
36235319 | 3599 | if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api) |
7cfdb485 | 3600 | == ZCLIENT_SEND_FAILURE) { |
2ba1fe69 | 3601 | zlog_err("error sending capability"); |
85ef4179 | 3602 | ret = BGP_GR_FAILURE; |
3603 | } else { | |
3604 | if (disable) | |
3605 | bgp->present_zebra_gr_state = ZEBRA_GR_DISABLE; | |
3606 | else | |
3607 | bgp->present_zebra_gr_state = ZEBRA_GR_ENABLE; | |
3608 | ||
3609 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3610 | zlog_debug("send capabilty success"); | |
3611 | ret = BGP_GR_SUCCESS; | |
3612 | } | |
3613 | return ret; | |
3614 | } | |
3615 | ||
3616 | /* Send route update pesding or completed status to RIB for the | |
3617 | * specific AFI, SAFI | |
3618 | */ | |
3619 | int bgp_zebra_update(afi_t afi, safi_t safi, vrf_id_t vrf_id, int type) | |
3620 | { | |
2ba1fe69 | 3621 | struct zapi_cap api = {0}; |
85ef4179 | 3622 | |
3623 | if (zclient == NULL) { | |
3624 | if (BGP_DEBUG(zebra, ZEBRA)) | |
2ba1fe69 | 3625 | zlog_debug("zclient == NULL, invalid"); |
85ef4179 | 3626 | return BGP_GR_FAILURE; |
3627 | } | |
3628 | ||
3629 | /* Check if the client is connected */ | |
3630 | if ((zclient->sock < 0) || (zclient->t_connect)) { | |
3631 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3632 | zlog_debug("client not connected"); | |
3633 | return BGP_GR_FAILURE; | |
3634 | } | |
3635 | ||
85ef4179 | 3636 | api.afi = afi; |
3637 | api.safi = safi; | |
3638 | api.vrf_id = vrf_id; | |
3639 | api.cap = type; | |
3640 | ||
36235319 | 3641 | if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api) |
7cfdb485 | 3642 | == ZCLIENT_SEND_FAILURE) { |
85ef4179 | 3643 | if (BGP_DEBUG(zebra, ZEBRA)) |
3644 | zlog_debug("error sending capability"); | |
3645 | return BGP_GR_FAILURE; | |
3646 | } | |
3647 | return BGP_GR_SUCCESS; | |
3648 | } | |
3649 | ||
3650 | ||
85ef4179 | 3651 | /* Send RIB stale timer update */ |
3652 | int bgp_zebra_stale_timer_update(struct bgp *bgp) | |
3653 | { | |
3654 | struct zapi_cap api; | |
3655 | ||
3656 | if (zclient == NULL) { | |
3657 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3658 | zlog_debug("zclient invalid"); | |
3659 | return BGP_GR_FAILURE; | |
3660 | } | |
3661 | ||
3662 | /* Check if the client is connected */ | |
3663 | if ((zclient->sock < 0) || (zclient->t_connect)) { | |
3664 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3665 | zlog_debug("client not connected"); | |
3666 | return BGP_GR_FAILURE; | |
3667 | } | |
3668 | ||
3669 | memset(&api, 0, sizeof(struct zapi_cap)); | |
3670 | api.cap = ZEBRA_CLIENT_RIB_STALE_TIME; | |
3671 | api.stale_removal_time = bgp->rib_stale_time; | |
3672 | api.vrf_id = bgp->vrf_id; | |
36235319 | 3673 | if (zclient_capabilities_send(ZEBRA_CLIENT_CAPABILITIES, zclient, &api) |
7cfdb485 | 3674 | == ZCLIENT_SEND_FAILURE) { |
85ef4179 | 3675 | if (BGP_DEBUG(zebra, ZEBRA)) |
3676 | zlog_debug("error sending capability"); | |
3677 | return BGP_GR_FAILURE; | |
3678 | } | |
3679 | if (BGP_DEBUG(zebra, ZEBRA)) | |
3680 | zlog_debug("send capabilty success"); | |
3681 | return BGP_GR_SUCCESS; | |
3682 | } | |
a0281b2e HS |
3683 | |
3684 | int bgp_zebra_srv6_manager_get_locator_chunk(const char *name) | |
3685 | { | |
3686 | return srv6_manager_get_locator_chunk(zclient, name); | |
3687 | } | |
0249b8b6 HS |
3688 | |
3689 | int bgp_zebra_srv6_manager_release_locator_chunk(const char *name) | |
3690 | { | |
3691 | return srv6_manager_release_locator_chunk(zclient, name); | |
3692 | } |