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