]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zapi_msg.c
zebra: Move rules_hash to zrouter
[mirror_frr.git] / zebra / zapi_msg.c
1 /*
2 * Zebra API message creation & consumption.
3 * Portions:
4 * Copyright (C) 1997-1999 Kunihiro Ishiguro
5 * Copyright (C) 2015-2018 Cumulus Networks, Inc.
6 * et al.
7 *
8 * This program is free software; you can redistribute it and/or modify it
9 * under the terms of the GNU General Public License as published by the Free
10 * Software Foundation; either version 2 of the License, or (at your option)
11 * any later version.
12 *
13 * This program is distributed in the hope that it will be useful, but WITHOUT
14 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
15 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
16 * more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; see the file COPYING; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23 #include <zebra.h>
24 #include <libgen.h>
25
26 #include "lib/prefix.h"
27 #include "lib/command.h"
28 #include "lib/if.h"
29 #include "lib/thread.h"
30 #include "lib/stream.h"
31 #include "lib/memory.h"
32 #include "lib/table.h"
33 #include "lib/network.h"
34 #include "lib/sockunion.h"
35 #include "lib/log.h"
36 #include "lib/zclient.h"
37 #include "lib/privs.h"
38 #include "lib/network.h"
39 #include "lib/buffer.h"
40 #include "lib/nexthop.h"
41 #include "lib/vrf.h"
42 #include "lib/libfrr.h"
43 #include "lib/sockopt.h"
44
45 #include "zebra/rib.h"
46 #include "zebra/zebra_memory.h"
47 #include "zebra/zebra_ns.h"
48 #include "zebra/zebra_vrf.h"
49 #include "zebra/router-id.h"
50 #include "zebra/redistribute.h"
51 #include "zebra/debug.h"
52 #include "zebra/zebra_rnh.h"
53 #include "zebra/rt_netlink.h"
54 #include "zebra/interface.h"
55 #include "zebra/zebra_ptm.h"
56 #include "zebra/rtadv.h"
57 #include "zebra/zebra_mpls.h"
58 #include "zebra/zebra_mroute.h"
59 #include "zebra/label_manager.h"
60 #include "zebra/zebra_vxlan.h"
61 #include "zebra/rt.h"
62 #include "zebra/zebra_pbr.h"
63 #include "zebra/table_manager.h"
64 #include "zebra/zapi_msg.h"
65 #include "zebra/zebra_errors.h"
66
67 /* Encoding helpers -------------------------------------------------------- */
68
69 static void zserv_encode_interface(struct stream *s, struct interface *ifp)
70 {
71 /* Interface information. */
72 stream_put(s, ifp->name, INTERFACE_NAMSIZ);
73 stream_putl(s, ifp->ifindex);
74 stream_putc(s, ifp->status);
75 stream_putq(s, ifp->flags);
76 stream_putc(s, ifp->ptm_enable);
77 stream_putc(s, ifp->ptm_status);
78 stream_putl(s, ifp->metric);
79 stream_putl(s, ifp->speed);
80 stream_putl(s, ifp->mtu);
81 stream_putl(s, ifp->mtu6);
82 stream_putl(s, ifp->bandwidth);
83 stream_putl(s, ifp->ll_type);
84 stream_putl(s, ifp->hw_addr_len);
85 if (ifp->hw_addr_len)
86 stream_put(s, ifp->hw_addr, ifp->hw_addr_len);
87
88 /* Then, Traffic Engineering parameters if any */
89 if (HAS_LINK_PARAMS(ifp) && IS_LINK_PARAMS_SET(ifp->link_params)) {
90 stream_putc(s, 1);
91 zebra_interface_link_params_write(s, ifp);
92 } else
93 stream_putc(s, 0);
94
95 /* Write packet size. */
96 stream_putw_at(s, 0, stream_get_endp(s));
97 }
98
99 static void zserv_encode_vrf(struct stream *s, struct zebra_vrf *zvrf)
100 {
101 struct vrf_data data;
102 const char *netns_name = zvrf_ns_name(zvrf);
103
104 data.l.table_id = zvrf->table_id;
105
106 if (netns_name)
107 strlcpy(data.l.netns_name, basename((char *)netns_name),
108 NS_NAMSIZ);
109 else
110 memset(data.l.netns_name, 0, NS_NAMSIZ);
111 /* Pass the tableid and the netns NAME */
112 stream_put(s, &data, sizeof(struct vrf_data));
113 /* Interface information. */
114 stream_put(s, zvrf_name(zvrf), VRF_NAMSIZ);
115 /* Write packet size. */
116 stream_putw_at(s, 0, stream_get_endp(s));
117 }
118
119 static int zserv_encode_nexthop(struct stream *s, struct nexthop *nexthop)
120 {
121 stream_putc(s, nexthop->type);
122 switch (nexthop->type) {
123 case NEXTHOP_TYPE_IPV4:
124 case NEXTHOP_TYPE_IPV4_IFINDEX:
125 stream_put_in_addr(s, &nexthop->gate.ipv4);
126 stream_putl(s, nexthop->ifindex);
127 break;
128 case NEXTHOP_TYPE_IPV6:
129 stream_put(s, &nexthop->gate.ipv6, 16);
130 break;
131 case NEXTHOP_TYPE_IPV6_IFINDEX:
132 stream_put(s, &nexthop->gate.ipv6, 16);
133 stream_putl(s, nexthop->ifindex);
134 break;
135 case NEXTHOP_TYPE_IFINDEX:
136 stream_putl(s, nexthop->ifindex);
137 break;
138 default:
139 /* do nothing */
140 break;
141 }
142 return 1;
143 }
144
145 /* Send handlers ----------------------------------------------------------- */
146
147 /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */
148 /*
149 * This function is called in the following situations:
150 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
151 * from the client.
152 * - at startup, when zebra figures out the available interfaces
153 * - when an interface is added (where support for
154 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
155 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
156 * received)
157 */
158 int zsend_interface_add(struct zserv *client, struct interface *ifp)
159 {
160 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
161
162 zclient_create_header(s, ZEBRA_INTERFACE_ADD, ifp->vrf_id);
163 zserv_encode_interface(s, ifp);
164
165 client->ifadd_cnt++;
166 return zserv_send_message(client, s);
167 }
168
169 /* Interface deletion from zebra daemon. */
170 int zsend_interface_delete(struct zserv *client, struct interface *ifp)
171 {
172 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
173
174 zclient_create_header(s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id);
175 zserv_encode_interface(s, ifp);
176
177 client->ifdel_cnt++;
178 return zserv_send_message(client, s);
179 }
180
181 int zsend_vrf_add(struct zserv *client, struct zebra_vrf *zvrf)
182 {
183 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
184
185 zclient_create_header(s, ZEBRA_VRF_ADD, zvrf_id(zvrf));
186 zserv_encode_vrf(s, zvrf);
187
188 client->vrfadd_cnt++;
189 return zserv_send_message(client, s);
190 }
191
192 /* VRF deletion from zebra daemon. */
193 int zsend_vrf_delete(struct zserv *client, struct zebra_vrf *zvrf)
194
195 {
196 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
197
198 zclient_create_header(s, ZEBRA_VRF_DELETE, zvrf_id(zvrf));
199 zserv_encode_vrf(s, zvrf);
200
201 client->vrfdel_cnt++;
202 return zserv_send_message(client, s);
203 }
204
205 int zsend_interface_link_params(struct zserv *client, struct interface *ifp)
206 {
207 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
208
209 /* Check this client need interface information. */
210 if (!client->ifinfo) {
211 stream_free(s);
212 return 0;
213 }
214
215 if (!ifp->link_params) {
216 stream_free(s);
217 return 0;
218 }
219
220 zclient_create_header(s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id);
221
222 /* Add Interface Index */
223 stream_putl(s, ifp->ifindex);
224
225 /* Then TE Link Parameters */
226 if (zebra_interface_link_params_write(s, ifp) == 0) {
227 stream_free(s);
228 return 0;
229 }
230
231 /* Write packet size. */
232 stream_putw_at(s, 0, stream_get_endp(s));
233
234 return zserv_send_message(client, s);
235 }
236
237 /* Interface address is added/deleted. Send ZEBRA_INTERFACE_ADDRESS_ADD or
238 * ZEBRA_INTERFACE_ADDRESS_DELETE to the client.
239 *
240 * A ZEBRA_INTERFACE_ADDRESS_ADD is sent in the following situations:
241 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
242 * from the client, after the ZEBRA_INTERFACE_ADD has been
243 * sent from zebra to the client
244 * - redistribute new address info to all clients in the following situations
245 * - at startup, when zebra figures out the available interfaces
246 * - when an interface is added (where support for
247 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
248 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
249 * received)
250 * - for the vty commands "ip address A.B.C.D/M [<secondary>|<label LINE>]"
251 * and "no bandwidth <1-10000000>", "ipv6 address X:X::X:X/M"
252 * - when an RTM_NEWADDR message is received from the kernel,
253 *
254 * The call tree that triggers ZEBRA_INTERFACE_ADDRESS_DELETE:
255 *
256 * zsend_interface_address(DELETE)
257 * ^
258 * |
259 * zebra_interface_address_delete_update
260 * ^ ^ ^
261 * | | if_delete_update
262 * | |
263 * ip_address_uninstall connected_delete_ipv4
264 * [ipv6_addresss_uninstall] [connected_delete_ipv6]
265 * ^ ^
266 * | |
267 * | RTM_NEWADDR on routing/netlink socket
268 * |
269 * vty commands:
270 * "no ip address A.B.C.D/M [label LINE]"
271 * "no ip address A.B.C.D/M secondary"
272 * ["no ipv6 address X:X::X:X/M"]
273 *
274 */
275 int zsend_interface_address(int cmd, struct zserv *client,
276 struct interface *ifp, struct connected *ifc)
277 {
278 int blen;
279 struct prefix *p;
280 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
281
282 zclient_create_header(s, cmd, ifp->vrf_id);
283 stream_putl(s, ifp->ifindex);
284
285 /* Interface address flag. */
286 stream_putc(s, ifc->flags);
287
288 /* Prefix information. */
289 p = ifc->address;
290 stream_putc(s, p->family);
291 blen = prefix_blen(p);
292 stream_put(s, &p->u.prefix, blen);
293
294 /*
295 * XXX gnu version does not send prefixlen for
296 * ZEBRA_INTERFACE_ADDRESS_DELETE
297 * but zebra_interface_address_delete_read() in the gnu version
298 * expects to find it
299 */
300 stream_putc(s, p->prefixlen);
301
302 /* Destination. */
303 p = ifc->destination;
304 if (p)
305 stream_put(s, &p->u.prefix, blen);
306 else
307 stream_put(s, NULL, blen);
308
309 /* Write packet size. */
310 stream_putw_at(s, 0, stream_get_endp(s));
311
312 client->connected_rt_add_cnt++;
313 return zserv_send_message(client, s);
314 }
315
316 static int zsend_interface_nbr_address(int cmd, struct zserv *client,
317 struct interface *ifp,
318 struct nbr_connected *ifc)
319 {
320 int blen;
321 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
322 struct prefix *p;
323
324 zclient_create_header(s, cmd, ifp->vrf_id);
325 stream_putl(s, ifp->ifindex);
326
327 /* Prefix information. */
328 p = ifc->address;
329 stream_putc(s, p->family);
330 blen = prefix_blen(p);
331 stream_put(s, &p->u.prefix, blen);
332
333 /*
334 * XXX gnu version does not send prefixlen for
335 * ZEBRA_INTERFACE_ADDRESS_DELETE
336 * but zebra_interface_address_delete_read() in the gnu version
337 * expects to find it
338 */
339 stream_putc(s, p->prefixlen);
340
341 /* Write packet size. */
342 stream_putw_at(s, 0, stream_get_endp(s));
343
344 return zserv_send_message(client, s);
345 }
346
347 /* Interface address addition. */
348 static void zebra_interface_nbr_address_add_update(struct interface *ifp,
349 struct nbr_connected *ifc)
350 {
351 struct listnode *node, *nnode;
352 struct zserv *client;
353 struct prefix *p;
354
355 if (IS_ZEBRA_DEBUG_EVENT) {
356 char buf[INET6_ADDRSTRLEN];
357
358 p = ifc->address;
359 zlog_debug(
360 "MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_ADD %s/%d on %s",
361 inet_ntop(p->family, &p->u.prefix, buf,
362 INET6_ADDRSTRLEN),
363 p->prefixlen, ifc->ifp->name);
364 }
365
366 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
367 zsend_interface_nbr_address(ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
368 client, ifp, ifc);
369 }
370
371 /* Interface address deletion. */
372 static void zebra_interface_nbr_address_delete_update(struct interface *ifp,
373 struct nbr_connected *ifc)
374 {
375 struct listnode *node, *nnode;
376 struct zserv *client;
377 struct prefix *p;
378
379 if (IS_ZEBRA_DEBUG_EVENT) {
380 char buf[INET6_ADDRSTRLEN];
381
382 p = ifc->address;
383 zlog_debug(
384 "MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_DELETE %s/%d on %s",
385 inet_ntop(p->family, &p->u.prefix, buf,
386 INET6_ADDRSTRLEN),
387 p->prefixlen, ifc->ifp->name);
388 }
389
390 for (ALL_LIST_ELEMENTS(zebrad.client_list, node, nnode, client))
391 zsend_interface_nbr_address(ZEBRA_INTERFACE_NBR_ADDRESS_DELETE,
392 client, ifp, ifc);
393 }
394
395 /* Send addresses on interface to client */
396 int zsend_interface_addresses(struct zserv *client, struct interface *ifp)
397 {
398 struct listnode *cnode, *cnnode;
399 struct connected *c;
400 struct nbr_connected *nc;
401
402 /* Send interface addresses. */
403 for (ALL_LIST_ELEMENTS(ifp->connected, cnode, cnnode, c)) {
404 if (!CHECK_FLAG(c->conf, ZEBRA_IFC_REAL))
405 continue;
406
407 if (zsend_interface_address(ZEBRA_INTERFACE_ADDRESS_ADD, client,
408 ifp, c)
409 < 0)
410 return -1;
411 }
412
413 /* Send interface neighbors. */
414 for (ALL_LIST_ELEMENTS(ifp->nbr_connected, cnode, cnnode, nc)) {
415 if (zsend_interface_nbr_address(ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
416 client, ifp, nc)
417 < 0)
418 return -1;
419 }
420
421 return 0;
422 }
423
424 /* Notify client about interface moving from one VRF to another.
425 * Whether client is interested in old and new VRF is checked by caller.
426 */
427 int zsend_interface_vrf_update(struct zserv *client, struct interface *ifp,
428 vrf_id_t vrf_id)
429 {
430 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
431
432 zclient_create_header(s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id);
433
434 /* Fill in the ifIndex of the interface and its new VRF (id) */
435 stream_putl(s, ifp->ifindex);
436 stream_putl(s, vrf_id);
437
438 /* Write packet size. */
439 stream_putw_at(s, 0, stream_get_endp(s));
440
441 client->if_vrfchg_cnt++;
442 return zserv_send_message(client, s);
443 }
444
445 /* Add new nbr connected IPv6 address */
446 void nbr_connected_add_ipv6(struct interface *ifp, struct in6_addr *address)
447 {
448 struct nbr_connected *ifc;
449 struct prefix p;
450
451 p.family = AF_INET6;
452 IPV6_ADDR_COPY(&p.u.prefix6, address);
453 p.prefixlen = IPV6_MAX_PREFIXLEN;
454
455 ifc = listnode_head(ifp->nbr_connected);
456 if (!ifc) {
457 /* new addition */
458 ifc = nbr_connected_new();
459 ifc->address = prefix_new();
460 ifc->ifp = ifp;
461 listnode_add(ifp->nbr_connected, ifc);
462 }
463
464 prefix_copy(ifc->address, &p);
465
466 zebra_interface_nbr_address_add_update(ifp, ifc);
467
468 if_nbr_ipv6ll_to_ipv4ll_neigh_update(ifp, address, 1);
469 }
470
471 void nbr_connected_delete_ipv6(struct interface *ifp, struct in6_addr *address)
472 {
473 struct nbr_connected *ifc;
474 struct prefix p;
475
476 p.family = AF_INET6;
477 IPV6_ADDR_COPY(&p.u.prefix6, address);
478 p.prefixlen = IPV6_MAX_PREFIXLEN;
479
480 ifc = nbr_connected_check(ifp, &p);
481 if (!ifc)
482 return;
483
484 listnode_delete(ifp->nbr_connected, ifc);
485
486 zebra_interface_nbr_address_delete_update(ifp, ifc);
487
488 if_nbr_ipv6ll_to_ipv4ll_neigh_update(ifp, address, 0);
489
490 nbr_connected_free(ifc);
491 }
492
493 /*
494 * The cmd passed to zsend_interface_update may be ZEBRA_INTERFACE_UP or
495 * ZEBRA_INTERFACE_DOWN.
496 *
497 * The ZEBRA_INTERFACE_UP message is sent from the zebra server to
498 * the clients in one of 2 situations:
499 * - an if_up is detected e.g., as a result of an RTM_IFINFO message
500 * - a vty command modifying the bandwidth of an interface is received.
501 * The ZEBRA_INTERFACE_DOWN message is sent when an if_down is detected.
502 */
503 int zsend_interface_update(int cmd, struct zserv *client, struct interface *ifp)
504 {
505 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
506
507 zclient_create_header(s, cmd, ifp->vrf_id);
508 zserv_encode_interface(s, ifp);
509
510 if (cmd == ZEBRA_INTERFACE_UP)
511 client->ifup_cnt++;
512 else
513 client->ifdown_cnt++;
514
515 return zserv_send_message(client, s);
516 }
517
518 int zsend_redistribute_route(int cmd, struct zserv *client,
519 const struct prefix *p,
520 const struct prefix *src_p, struct route_entry *re)
521 {
522 struct zapi_route api;
523 struct zapi_nexthop *api_nh;
524 struct nexthop *nexthop;
525 int count = 0;
526 afi_t afi;
527
528 memset(&api, 0, sizeof(api));
529 api.vrf_id = re->vrf_id;
530 api.type = re->type;
531 api.instance = re->instance;
532 api.flags = re->flags;
533
534 afi = family2afi(p->family);
535 switch (afi) {
536 case AFI_IP:
537 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
538 client->redist_v4_add_cnt++;
539 else
540 client->redist_v4_del_cnt++;
541 break;
542 case AFI_IP6:
543 if (cmd == ZEBRA_REDISTRIBUTE_ROUTE_ADD)
544 client->redist_v6_add_cnt++;
545 else
546 client->redist_v6_del_cnt++;
547 break;
548 default:
549 break;
550 }
551
552 /* Prefix. */
553 api.prefix = *p;
554 if (src_p) {
555 SET_FLAG(api.message, ZAPI_MESSAGE_SRCPFX);
556 memcpy(&api.src_prefix, src_p, sizeof(api.src_prefix));
557 }
558
559 /* Nexthops. */
560 if (re->nexthop_active_num) {
561 SET_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP);
562 api.nexthop_num = re->nexthop_active_num;
563 }
564 for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next) {
565 if (!CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
566 continue;
567
568 api_nh = &api.nexthops[count];
569 api_nh->vrf_id = nexthop->vrf_id;
570 api_nh->type = nexthop->type;
571 switch (nexthop->type) {
572 case NEXTHOP_TYPE_BLACKHOLE:
573 api_nh->bh_type = nexthop->bh_type;
574 break;
575 case NEXTHOP_TYPE_IPV4:
576 api_nh->gate.ipv4 = nexthop->gate.ipv4;
577 break;
578 case NEXTHOP_TYPE_IPV4_IFINDEX:
579 api_nh->gate.ipv4 = nexthop->gate.ipv4;
580 api_nh->ifindex = nexthop->ifindex;
581 break;
582 case NEXTHOP_TYPE_IFINDEX:
583 api_nh->ifindex = nexthop->ifindex;
584 break;
585 case NEXTHOP_TYPE_IPV6:
586 api_nh->gate.ipv6 = nexthop->gate.ipv6;
587 break;
588 case NEXTHOP_TYPE_IPV6_IFINDEX:
589 api_nh->gate.ipv6 = nexthop->gate.ipv6;
590 api_nh->ifindex = nexthop->ifindex;
591 }
592 count++;
593 }
594
595 /* Attributes. */
596 SET_FLAG(api.message, ZAPI_MESSAGE_DISTANCE);
597 api.distance = re->distance;
598 SET_FLAG(api.message, ZAPI_MESSAGE_METRIC);
599 api.metric = re->metric;
600 if (re->tag) {
601 SET_FLAG(api.message, ZAPI_MESSAGE_TAG);
602 api.tag = re->tag;
603 }
604 SET_FLAG(api.message, ZAPI_MESSAGE_MTU);
605 api.mtu = re->mtu;
606
607 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
608
609 /* Encode route and send. */
610 if (zapi_route_encode(cmd, s, &api) < 0) {
611 stream_free(s);
612 return -1;
613 }
614
615 if (IS_ZEBRA_DEBUG_SEND) {
616 char buf_prefix[PREFIX_STRLEN];
617
618 prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix));
619
620 zlog_debug("%s: %s to client %s: type %s, vrf_id %d, p %s",
621 __func__, zserv_command_string(cmd),
622 zebra_route_string(client->proto),
623 zebra_route_string(api.type), api.vrf_id,
624 buf_prefix);
625 }
626 return zserv_send_message(client, s);
627 }
628
629 /*
630 * Modified version of zsend_ipv4_nexthop_lookup(): Query unicast rib if
631 * nexthop is not found on mrib. Returns both route metric and protocol
632 * distance.
633 */
634 static int zsend_ipv4_nexthop_lookup_mrib(struct zserv *client,
635 struct in_addr addr,
636 struct route_entry *re,
637 struct zebra_vrf *zvrf)
638 {
639 struct stream *s;
640 unsigned long nump;
641 uint8_t num;
642 struct nexthop *nexthop;
643
644 /* Get output stream. */
645 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
646 stream_reset(s);
647
648 /* Fill in result. */
649 zclient_create_header(s, ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, zvrf_id(zvrf));
650 stream_put_in_addr(s, &addr);
651
652 if (re) {
653 stream_putc(s, re->distance);
654 stream_putl(s, re->metric);
655 num = 0;
656 /* remember position for nexthop_num */
657 nump = stream_get_endp(s);
658 /* reserve room for nexthop_num */
659 stream_putc(s, 0);
660 /*
661 * Only non-recursive routes are elegible to resolve the
662 * nexthop we are looking up. Therefore, we will just iterate
663 * over the top chain of nexthops.
664 */
665 for (nexthop = re->ng.nexthop; nexthop; nexthop = nexthop->next)
666 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
667 num += zserv_encode_nexthop(s, nexthop);
668
669 /* store nexthop_num */
670 stream_putc_at(s, nump, num);
671 } else {
672 stream_putc(s, 0); /* distance */
673 stream_putl(s, 0); /* metric */
674 stream_putc(s, 0); /* nexthop_num */
675 }
676
677 stream_putw_at(s, 0, stream_get_endp(s));
678
679 return zserv_send_message(client, s);
680 }
681
682 /*
683 * Common utility send route notification, called from a path using a
684 * route_entry and from a path using a dataplane context.
685 */
686 static int route_notify_internal(const struct prefix *p, int type,
687 uint16_t instance, vrf_id_t vrf_id,
688 uint32_t table_id,
689 enum zapi_route_notify_owner note)
690 {
691 struct zserv *client;
692 struct stream *s;
693 uint8_t blen;
694
695 client = zserv_find_client(type, instance);
696 if (!client || !client->notify_owner) {
697 if (IS_ZEBRA_DEBUG_PACKET) {
698 char buff[PREFIX_STRLEN];
699
700 zlog_debug(
701 "Not Notifying Owner: %u about prefix %s(%u) %d vrf: %u",
702 type, prefix2str(p, buff, sizeof(buff)),
703 table_id, note, vrf_id);
704 }
705 return 0;
706 }
707
708 if (IS_ZEBRA_DEBUG_PACKET) {
709 char buff[PREFIX_STRLEN];
710
711 zlog_debug("Notifying Owner: %u about prefix %s(%u) %d vrf: %u",
712 type, prefix2str(p, buff, sizeof(buff)),
713 table_id, note, vrf_id);
714 }
715
716 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
717 stream_reset(s);
718
719 zclient_create_header(s, ZEBRA_ROUTE_NOTIFY_OWNER, vrf_id);
720
721 stream_put(s, &note, sizeof(note));
722
723 stream_putc(s, p->family);
724
725 blen = prefix_blen(p);
726 stream_putc(s, p->prefixlen);
727 stream_put(s, &p->u.prefix, blen);
728
729 stream_putl(s, table_id);
730
731 stream_putw_at(s, 0, stream_get_endp(s));
732
733 return zserv_send_message(client, s);
734 }
735
736 int zsend_route_notify_owner(struct route_entry *re, const struct prefix *p,
737 enum zapi_route_notify_owner note)
738 {
739 return (route_notify_internal(p, re->type, re->instance, re->vrf_id,
740 re->table, note));
741 }
742
743 void zsend_rule_notify_owner(struct zebra_pbr_rule *rule,
744 enum zapi_rule_notify_owner note)
745 {
746 struct listnode *node;
747 struct zserv *client;
748 struct stream *s;
749
750 if (IS_ZEBRA_DEBUG_PACKET)
751 zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__,
752 rule->rule.unique);
753
754 for (ALL_LIST_ELEMENTS_RO(zebrad.client_list, node, client)) {
755 if (rule->sock == client->sock)
756 break;
757 }
758
759 if (!client)
760 return;
761
762 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
763
764 zclient_create_header(s, ZEBRA_RULE_NOTIFY_OWNER, VRF_DEFAULT);
765 stream_put(s, &note, sizeof(note));
766 stream_putl(s, rule->rule.seq);
767 stream_putl(s, rule->rule.priority);
768 stream_putl(s, rule->rule.unique);
769 if (rule->ifp)
770 stream_putl(s, rule->ifp->ifindex);
771 else
772 stream_putl(s, 0);
773
774 stream_putw_at(s, 0, stream_get_endp(s));
775
776 zserv_send_message(client, s);
777 }
778
779 void zsend_ipset_notify_owner(struct zebra_pbr_ipset *ipset,
780 enum zapi_ipset_notify_owner note)
781 {
782 struct listnode *node;
783 struct zserv *client;
784 struct stream *s;
785
786 if (IS_ZEBRA_DEBUG_PACKET)
787 zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__,
788 ipset->unique);
789
790 for (ALL_LIST_ELEMENTS_RO(zebrad.client_list, node, client)) {
791 if (ipset->sock == client->sock)
792 break;
793 }
794
795 if (!client)
796 return;
797
798 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
799
800 zclient_create_header(s, ZEBRA_IPSET_NOTIFY_OWNER, VRF_DEFAULT);
801 stream_put(s, &note, sizeof(note));
802 stream_putl(s, ipset->unique);
803 stream_put(s, ipset->ipset_name, ZEBRA_IPSET_NAME_SIZE);
804 stream_putw_at(s, 0, stream_get_endp(s));
805
806 zserv_send_message(client, s);
807 }
808
809 void zsend_ipset_entry_notify_owner(struct zebra_pbr_ipset_entry *ipset,
810 enum zapi_ipset_entry_notify_owner note)
811 {
812 struct listnode *node;
813 struct zserv *client;
814 struct stream *s;
815
816 if (IS_ZEBRA_DEBUG_PACKET)
817 zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__,
818 ipset->unique);
819
820 for (ALL_LIST_ELEMENTS_RO(zebrad.client_list, node, client)) {
821 if (ipset->sock == client->sock)
822 break;
823 }
824
825 if (!client)
826 return;
827
828 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
829
830 zclient_create_header(s, ZEBRA_IPSET_ENTRY_NOTIFY_OWNER, VRF_DEFAULT);
831 stream_put(s, &note, sizeof(note));
832 stream_putl(s, ipset->unique);
833 stream_put(s, ipset->backpointer->ipset_name, ZEBRA_IPSET_NAME_SIZE);
834 stream_putw_at(s, 0, stream_get_endp(s));
835
836 zserv_send_message(client, s);
837 }
838
839 void zsend_iptable_notify_owner(struct zebra_pbr_iptable *iptable,
840 enum zapi_iptable_notify_owner note)
841 {
842 struct listnode *node;
843 struct zserv *client;
844 struct stream *s;
845
846 if (IS_ZEBRA_DEBUG_PACKET)
847 zlog_debug("%s: Notifying %u", __PRETTY_FUNCTION__,
848 iptable->unique);
849
850 for (ALL_LIST_ELEMENTS_RO(zebrad.client_list, node, client)) {
851 if (iptable->sock == client->sock)
852 break;
853 }
854
855 if (!client)
856 return;
857
858 s = stream_new(ZEBRA_MAX_PACKET_SIZ);
859
860 zclient_create_header(s, ZEBRA_IPTABLE_NOTIFY_OWNER, VRF_DEFAULT);
861 stream_put(s, &note, sizeof(note));
862 stream_putl(s, iptable->unique);
863 stream_putw_at(s, 0, stream_get_endp(s));
864
865 zserv_send_message(client, s);
866 }
867
868 /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
869 int zsend_router_id_update(struct zserv *client, struct prefix *p,
870 vrf_id_t vrf_id)
871 {
872 int blen;
873
874 /* Check this client need interface information. */
875 if (!vrf_bitmap_check(client->ridinfo, vrf_id))
876 return 0;
877
878 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
879
880 /* Message type. */
881 zclient_create_header(s, ZEBRA_ROUTER_ID_UPDATE, vrf_id);
882
883 /* Prefix information. */
884 stream_putc(s, p->family);
885 blen = prefix_blen(p);
886 stream_put(s, &p->u.prefix, blen);
887 stream_putc(s, p->prefixlen);
888
889 /* Write packet size. */
890 stream_putw_at(s, 0, stream_get_endp(s));
891
892 return zserv_send_message(client, s);
893 }
894
895 /*
896 * Function used by Zebra to send a PW status update to LDP daemon
897 */
898 int zsend_pw_update(struct zserv *client, struct zebra_pw *pw)
899 {
900 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
901
902 zclient_create_header(s, ZEBRA_PW_STATUS_UPDATE, pw->vrf_id);
903 stream_write(s, pw->ifname, IF_NAMESIZE);
904 stream_putl(s, pw->ifindex);
905 stream_putl(s, pw->status);
906
907 /* Put length at the first point of the stream. */
908 stream_putw_at(s, 0, stream_get_endp(s));
909
910 return zserv_send_message(client, s);
911 }
912
913 /* Send response to a get label chunk request to client */
914 static int zsend_assign_label_chunk_response(struct zserv *client,
915 vrf_id_t vrf_id,
916 struct label_manager_chunk *lmc)
917 {
918 int ret;
919 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
920
921 zclient_create_header(s, ZEBRA_GET_LABEL_CHUNK, vrf_id);
922
923 if (lmc) {
924 /* proto */
925 stream_putc(s, lmc->proto);
926 /* instance */
927 stream_putw(s, lmc->instance);
928 /* keep */
929 stream_putc(s, lmc->keep);
930 /* start and end labels */
931 stream_putl(s, lmc->start);
932 stream_putl(s, lmc->end);
933 }
934
935 /* Write packet size. */
936 stream_putw_at(s, 0, stream_get_endp(s));
937
938 ret = writen(client->sock, s->data, stream_get_endp(s));
939 stream_free(s);
940 return ret;
941 }
942
943 /* Send response to a label manager connect request to client */
944 static int zsend_label_manager_connect_response(struct zserv *client,
945 vrf_id_t vrf_id,
946 unsigned short result)
947 {
948 int ret;
949 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
950
951 zclient_create_header(s, ZEBRA_LABEL_MANAGER_CONNECT, vrf_id);
952
953 /* proto */
954 stream_putc(s, client->proto);
955
956 /* instance */
957 stream_putw(s, client->instance);
958
959 /* result */
960 stream_putc(s, result);
961
962 /* Write packet size. */
963 stream_putw_at(s, 0, stream_get_endp(s));
964
965 ret = writen(client->sock, s->data, stream_get_endp(s));
966 stream_free(s);
967
968 return ret;
969 }
970
971 /* Send response to a get table chunk request to client */
972 static int zsend_assign_table_chunk_response(struct zserv *client,
973 vrf_id_t vrf_id,
974 struct table_manager_chunk *tmc)
975 {
976 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
977
978 zclient_create_header(s, ZEBRA_GET_TABLE_CHUNK, vrf_id);
979
980 if (tmc) {
981 /* start and end labels */
982 stream_putl(s, tmc->start);
983 stream_putl(s, tmc->end);
984 }
985
986 /* Write packet size. */
987 stream_putw_at(s, 0, stream_get_endp(s));
988
989 return zserv_send_message(client, s);
990 }
991
992 static int zsend_table_manager_connect_response(struct zserv *client,
993 vrf_id_t vrf_id,
994 uint16_t result)
995 {
996 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
997
998 zclient_create_header(s, ZEBRA_TABLE_MANAGER_CONNECT, vrf_id);
999
1000 /* result */
1001 stream_putc(s, result);
1002
1003 stream_putw_at(s, 0, stream_get_endp(s));
1004
1005 return zserv_send_message(client, s);
1006 }
1007
1008 /* Inbound message handling ------------------------------------------------ */
1009
1010 int cmd2type[] = {
1011 [ZEBRA_NEXTHOP_REGISTER] = RNH_NEXTHOP_TYPE,
1012 [ZEBRA_NEXTHOP_UNREGISTER] = RNH_NEXTHOP_TYPE,
1013 [ZEBRA_IMPORT_ROUTE_REGISTER] = RNH_IMPORT_CHECK_TYPE,
1014 [ZEBRA_IMPORT_ROUTE_UNREGISTER] = RNH_IMPORT_CHECK_TYPE,
1015 };
1016
1017 /* Nexthop register */
1018 static void zread_rnh_register(ZAPI_HANDLER_ARGS)
1019 {
1020 struct rnh *rnh;
1021 struct stream *s;
1022 struct prefix p;
1023 unsigned short l = 0;
1024 uint8_t flags = 0;
1025 uint16_t type = cmd2type[hdr->command];
1026 bool exist;
1027
1028 if (IS_ZEBRA_DEBUG_NHT)
1029 zlog_debug(
1030 "rnh_register msg from client %s: hdr->length=%d, type=%s vrf=%u\n",
1031 zebra_route_string(client->proto), hdr->length,
1032 (type == RNH_NEXTHOP_TYPE) ? "nexthop" : "route",
1033 zvrf->vrf->vrf_id);
1034
1035 s = msg;
1036
1037 client->nh_reg_time = monotime(NULL);
1038
1039 while (l < hdr->length) {
1040 STREAM_GETC(s, flags);
1041 STREAM_GETW(s, p.family);
1042 STREAM_GETC(s, p.prefixlen);
1043 l += 4;
1044 if (p.family == AF_INET) {
1045 if (p.prefixlen > IPV4_MAX_BITLEN) {
1046 zlog_debug(
1047 "%s: Specified prefix hdr->length %d is too large for a v4 address",
1048 __PRETTY_FUNCTION__, p.prefixlen);
1049 return;
1050 }
1051 STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN);
1052 l += IPV4_MAX_BYTELEN;
1053 } else if (p.family == AF_INET6) {
1054 if (p.prefixlen > IPV6_MAX_BITLEN) {
1055 zlog_debug(
1056 "%s: Specified prefix hdr->length %d is to large for a v6 address",
1057 __PRETTY_FUNCTION__, p.prefixlen);
1058 return;
1059 }
1060 STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
1061 l += IPV6_MAX_BYTELEN;
1062 } else {
1063 flog_err(
1064 EC_ZEBRA_UNKNOWN_FAMILY,
1065 "rnh_register: Received unknown family type %d\n",
1066 p.family);
1067 return;
1068 }
1069 rnh = zebra_add_rnh(&p, zvrf_id(zvrf), type, &exist);
1070 if (!rnh)
1071 return;
1072
1073 if (type == RNH_NEXTHOP_TYPE) {
1074 if (flags
1075 && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
1076 SET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
1077 else if (!flags
1078 && CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
1079 UNSET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
1080 } else if (type == RNH_IMPORT_CHECK_TYPE) {
1081 if (flags
1082 && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH))
1083 SET_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH);
1084 else if (!flags
1085 && CHECK_FLAG(rnh->flags,
1086 ZEBRA_NHT_EXACT_MATCH))
1087 UNSET_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH);
1088 }
1089
1090 zebra_add_rnh_client(rnh, client, type, zvrf_id(zvrf));
1091 /* Anything not AF_INET/INET6 has been filtered out above */
1092 if (!exist)
1093 zebra_evaluate_rnh(zvrf, p.family, 1, type, &p);
1094 }
1095
1096 stream_failure:
1097 return;
1098 }
1099
1100 /* Nexthop register */
1101 static void zread_rnh_unregister(ZAPI_HANDLER_ARGS)
1102 {
1103 struct rnh *rnh;
1104 struct stream *s;
1105 struct prefix p;
1106 unsigned short l = 0;
1107 uint16_t type = cmd2type[hdr->command];
1108
1109 if (IS_ZEBRA_DEBUG_NHT)
1110 zlog_debug(
1111 "rnh_unregister msg from client %s: hdr->length=%d vrf: %u\n",
1112 zebra_route_string(client->proto), hdr->length,
1113 zvrf->vrf->vrf_id);
1114
1115 s = msg;
1116
1117 while (l < hdr->length) {
1118 uint8_t flags;
1119
1120 STREAM_GETC(s, flags);
1121 if (flags != 0)
1122 goto stream_failure;
1123
1124 STREAM_GETW(s, p.family);
1125 STREAM_GETC(s, p.prefixlen);
1126 l += 4;
1127 if (p.family == AF_INET) {
1128 if (p.prefixlen > IPV4_MAX_BITLEN) {
1129 zlog_debug(
1130 "%s: Specified prefix hdr->length %d is to large for a v4 address",
1131 __PRETTY_FUNCTION__, p.prefixlen);
1132 return;
1133 }
1134 STREAM_GET(&p.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN);
1135 l += IPV4_MAX_BYTELEN;
1136 } else if (p.family == AF_INET6) {
1137 if (p.prefixlen > IPV6_MAX_BITLEN) {
1138 zlog_debug(
1139 "%s: Specified prefix hdr->length %d is to large for a v6 address",
1140 __PRETTY_FUNCTION__, p.prefixlen);
1141 return;
1142 }
1143 STREAM_GET(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
1144 l += IPV6_MAX_BYTELEN;
1145 } else {
1146 flog_err(
1147 EC_ZEBRA_UNKNOWN_FAMILY,
1148 "rnh_register: Received unknown family type %d\n",
1149 p.family);
1150 return;
1151 }
1152 rnh = zebra_lookup_rnh(&p, zvrf_id(zvrf), type);
1153 if (rnh) {
1154 client->nh_dereg_time = monotime(NULL);
1155 zebra_remove_rnh_client(rnh, client, type);
1156 }
1157 }
1158 stream_failure:
1159 return;
1160 }
1161
1162 #define ZEBRA_MIN_FEC_LENGTH 5
1163
1164 /* FEC register */
1165 static void zread_fec_register(ZAPI_HANDLER_ARGS)
1166 {
1167 struct stream *s;
1168 unsigned short l = 0;
1169 struct prefix p;
1170 uint16_t flags;
1171 uint32_t label_index = MPLS_INVALID_LABEL_INDEX;
1172
1173 s = msg;
1174 zvrf = vrf_info_lookup(VRF_DEFAULT);
1175 if (!zvrf)
1176 return;
1177
1178 /*
1179 * The minimum amount of data that can be sent for one fec
1180 * registration
1181 */
1182 if (hdr->length < ZEBRA_MIN_FEC_LENGTH) {
1183 flog_err(
1184 EC_ZEBRA_IRDP_LEN_MISMATCH,
1185 "fec_register: Received a fec register of hdr->length %d, it is of insufficient size to properly decode",
1186 hdr->length);
1187 return;
1188 }
1189
1190 while (l < hdr->length) {
1191 STREAM_GETW(s, flags);
1192 memset(&p, 0, sizeof(p));
1193 STREAM_GETW(s, p.family);
1194 if (p.family != AF_INET && p.family != AF_INET6) {
1195 flog_err(
1196 EC_ZEBRA_UNKNOWN_FAMILY,
1197 "fec_register: Received unknown family type %d\n",
1198 p.family);
1199 return;
1200 }
1201 STREAM_GETC(s, p.prefixlen);
1202 if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN)
1203 || (p.family == AF_INET6
1204 && p.prefixlen > IPV6_MAX_BITLEN)) {
1205 zlog_debug(
1206 "%s: Specified prefix hdr->length: %d is to long for %d",
1207 __PRETTY_FUNCTION__, p.prefixlen, p.family);
1208 return;
1209 }
1210 l += 5;
1211 STREAM_GET(&p.u.prefix, s, PSIZE(p.prefixlen));
1212 l += PSIZE(p.prefixlen);
1213 if (flags & ZEBRA_FEC_REGISTER_LABEL_INDEX) {
1214 STREAM_GETL(s, label_index);
1215 l += 4;
1216 } else
1217 label_index = MPLS_INVALID_LABEL_INDEX;
1218 zebra_mpls_fec_register(zvrf, &p, label_index, client);
1219 }
1220
1221 stream_failure:
1222 return;
1223 }
1224
1225 /* FEC unregister */
1226 static void zread_fec_unregister(ZAPI_HANDLER_ARGS)
1227 {
1228 struct stream *s;
1229 unsigned short l = 0;
1230 struct prefix p;
1231 uint16_t flags;
1232
1233 s = msg;
1234 zvrf = vrf_info_lookup(VRF_DEFAULT);
1235 if (!zvrf)
1236 return;
1237
1238 /*
1239 * The minimum amount of data that can be sent for one
1240 * fec unregistration
1241 */
1242 if (hdr->length < ZEBRA_MIN_FEC_LENGTH) {
1243 flog_err(
1244 EC_ZEBRA_IRDP_LEN_MISMATCH,
1245 "fec_unregister: Received a fec unregister of hdr->length %d, it is of insufficient size to properly decode",
1246 hdr->length);
1247 return;
1248 }
1249
1250 while (l < hdr->length) {
1251 STREAM_GETW(s, flags);
1252 if (flags != 0)
1253 goto stream_failure;
1254
1255 memset(&p, 0, sizeof(p));
1256 STREAM_GETW(s, p.family);
1257 if (p.family != AF_INET && p.family != AF_INET6) {
1258 flog_err(
1259 EC_ZEBRA_UNKNOWN_FAMILY,
1260 "fec_unregister: Received unknown family type %d\n",
1261 p.family);
1262 return;
1263 }
1264 STREAM_GETC(s, p.prefixlen);
1265 if ((p.family == AF_INET && p.prefixlen > IPV4_MAX_BITLEN)
1266 || (p.family == AF_INET6
1267 && p.prefixlen > IPV6_MAX_BITLEN)) {
1268 zlog_debug(
1269 "%s: Received prefix hdr->length %d which is greater than %d can support",
1270 __PRETTY_FUNCTION__, p.prefixlen, p.family);
1271 return;
1272 }
1273 l += 5;
1274 STREAM_GET(&p.u.prefix, s, PSIZE(p.prefixlen));
1275 l += PSIZE(p.prefixlen);
1276 zebra_mpls_fec_unregister(zvrf, &p, client);
1277 }
1278
1279 stream_failure:
1280 return;
1281 }
1282
1283
1284 /*
1285 * Register zebra server interface information.
1286 * Send current all interface and address information.
1287 */
1288 static void zread_interface_add(ZAPI_HANDLER_ARGS)
1289 {
1290 struct vrf *vrf;
1291 struct interface *ifp;
1292
1293 /* Interface information is needed. */
1294 vrf_bitmap_set(client->ifinfo, zvrf_id(zvrf));
1295
1296 RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id) {
1297 FOR_ALL_INTERFACES (vrf, ifp) {
1298 /* Skip pseudo interface. */
1299 if (!CHECK_FLAG(ifp->status, ZEBRA_INTERFACE_ACTIVE))
1300 continue;
1301
1302 zsend_interface_add(client, ifp);
1303 zsend_interface_addresses(client, ifp);
1304 }
1305 }
1306 }
1307
1308 /* Unregister zebra server interface information. */
1309 static void zread_interface_delete(ZAPI_HANDLER_ARGS)
1310 {
1311 vrf_bitmap_unset(client->ifinfo, zvrf_id(zvrf));
1312 }
1313
1314 void zserv_nexthop_num_warn(const char *caller, const struct prefix *p,
1315 const unsigned int nexthop_num)
1316 {
1317 if (nexthop_num > multipath_num) {
1318 char buff[PREFIX2STR_BUFFER];
1319
1320 prefix2str(p, buff, sizeof(buff));
1321 flog_warn(
1322 EC_ZEBRA_MORE_NH_THAN_MULTIPATH,
1323 "%s: Prefix %s has %d nexthops, but we can only use the first %d",
1324 caller, buff, nexthop_num, multipath_num);
1325 }
1326 }
1327
1328 static void zread_route_add(ZAPI_HANDLER_ARGS)
1329 {
1330 struct stream *s;
1331 struct zapi_route api;
1332 struct zapi_nexthop *api_nh;
1333 afi_t afi;
1334 struct prefix_ipv6 *src_p = NULL;
1335 struct route_entry *re;
1336 struct nexthop *nexthop = NULL;
1337 int i, ret;
1338 vrf_id_t vrf_id = 0;
1339 struct ipaddr vtep_ip;
1340
1341 s = msg;
1342 if (zapi_route_decode(s, &api) < 0) {
1343 if (IS_ZEBRA_DEBUG_RECV)
1344 zlog_debug("%s: Unable to decode zapi_route sent",
1345 __PRETTY_FUNCTION__);
1346 return;
1347 }
1348
1349 if (IS_ZEBRA_DEBUG_RECV) {
1350 char buf_prefix[PREFIX_STRLEN];
1351
1352 prefix2str(&api.prefix, buf_prefix, sizeof(buf_prefix));
1353 zlog_debug("%s: p=%s, ZAPI_MESSAGE_LABEL: %sset, flags=0x%x",
1354 __func__, buf_prefix,
1355 (CHECK_FLAG(api.message, ZAPI_MESSAGE_LABEL) ? ""
1356 : "un"),
1357 api.flags);
1358 }
1359
1360 /* Allocate new route. */
1361 vrf_id = zvrf_id(zvrf);
1362 re = XCALLOC(MTYPE_RE, sizeof(struct route_entry));
1363 re->type = api.type;
1364 re->instance = api.instance;
1365 re->flags = api.flags;
1366 re->uptime = time(NULL);
1367 re->vrf_id = vrf_id;
1368 if (api.tableid && vrf_id == VRF_DEFAULT)
1369 re->table = api.tableid;
1370 else
1371 re->table = zvrf->table_id;
1372
1373 /*
1374 * TBD should _all_ of the nexthop add operations use
1375 * api_nh->vrf_id instead of re->vrf_id ? I only changed
1376 * for cases NEXTHOP_TYPE_IPV4 and NEXTHOP_TYPE_IPV6.
1377 */
1378 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_NEXTHOP))
1379 for (i = 0; i < api.nexthop_num; i++) {
1380 api_nh = &api.nexthops[i];
1381 ifindex_t ifindex = 0;
1382
1383 if (IS_ZEBRA_DEBUG_RECV)
1384 zlog_debug("nh type %d", api_nh->type);
1385
1386 switch (api_nh->type) {
1387 case NEXTHOP_TYPE_IFINDEX:
1388 nexthop = route_entry_nexthop_ifindex_add(
1389 re, api_nh->ifindex, api_nh->vrf_id);
1390 break;
1391 case NEXTHOP_TYPE_IPV4:
1392 if (IS_ZEBRA_DEBUG_RECV) {
1393 char nhbuf[INET6_ADDRSTRLEN] = {0};
1394
1395 inet_ntop(AF_INET, &api_nh->gate.ipv4,
1396 nhbuf, INET6_ADDRSTRLEN);
1397 zlog_debug("%s: nh=%s, vrf_id=%d",
1398 __func__, nhbuf,
1399 api_nh->vrf_id);
1400 }
1401 nexthop = route_entry_nexthop_ipv4_add(
1402 re, &api_nh->gate.ipv4, NULL,
1403 api_nh->vrf_id);
1404 break;
1405 case NEXTHOP_TYPE_IPV4_IFINDEX:
1406
1407 memset(&vtep_ip, 0, sizeof(struct ipaddr));
1408 if (CHECK_FLAG(api.flags,
1409 ZEBRA_FLAG_EVPN_ROUTE)) {
1410 ifindex = get_l3vni_svi_ifindex(vrf_id);
1411 } else {
1412 ifindex = api_nh->ifindex;
1413 }
1414
1415 if (IS_ZEBRA_DEBUG_RECV) {
1416 char nhbuf[INET6_ADDRSTRLEN] = {0};
1417
1418 inet_ntop(AF_INET, &api_nh->gate.ipv4,
1419 nhbuf, INET6_ADDRSTRLEN);
1420 zlog_debug(
1421 "%s: nh=%s, vrf_id=%d (re->vrf_id=%d), ifindex=%d",
1422 __func__, nhbuf, api_nh->vrf_id,
1423 re->vrf_id, ifindex);
1424 }
1425 nexthop = route_entry_nexthop_ipv4_ifindex_add(
1426 re, &api_nh->gate.ipv4, NULL, ifindex,
1427 api_nh->vrf_id);
1428
1429 /* if this an EVPN route entry,
1430 * program the nh as neigh
1431 */
1432 if (CHECK_FLAG(api.flags,
1433 ZEBRA_FLAG_EVPN_ROUTE)) {
1434 SET_FLAG(nexthop->flags,
1435 NEXTHOP_FLAG_EVPN_RVTEP);
1436 vtep_ip.ipa_type = IPADDR_V4;
1437 memcpy(&(vtep_ip.ipaddr_v4),
1438 &(api_nh->gate.ipv4),
1439 sizeof(struct in_addr));
1440 zebra_vxlan_evpn_vrf_route_add(
1441 vrf_id, &api_nh->rmac, &vtep_ip,
1442 &api.prefix);
1443 }
1444 break;
1445 case NEXTHOP_TYPE_IPV6:
1446 nexthop = route_entry_nexthop_ipv6_add(
1447 re, &api_nh->gate.ipv6, api_nh->vrf_id);
1448 break;
1449 case NEXTHOP_TYPE_IPV6_IFINDEX:
1450 memset(&vtep_ip, 0, sizeof(struct ipaddr));
1451 if (CHECK_FLAG(api.flags,
1452 ZEBRA_FLAG_EVPN_ROUTE)) {
1453 ifindex = get_l3vni_svi_ifindex(vrf_id);
1454 } else {
1455 ifindex = api_nh->ifindex;
1456 }
1457
1458 nexthop = route_entry_nexthop_ipv6_ifindex_add(
1459 re, &api_nh->gate.ipv6, ifindex,
1460 api_nh->vrf_id);
1461
1462 /* if this an EVPN route entry,
1463 * program the nh as neigh
1464 */
1465 if (CHECK_FLAG(api.flags,
1466 ZEBRA_FLAG_EVPN_ROUTE)) {
1467 SET_FLAG(nexthop->flags,
1468 NEXTHOP_FLAG_EVPN_RVTEP);
1469 vtep_ip.ipa_type = IPADDR_V6;
1470 memcpy(&vtep_ip.ipaddr_v6,
1471 &(api_nh->gate.ipv6),
1472 sizeof(struct in6_addr));
1473 zebra_vxlan_evpn_vrf_route_add(
1474 vrf_id, &api_nh->rmac, &vtep_ip,
1475 &api.prefix);
1476 }
1477 break;
1478 case NEXTHOP_TYPE_BLACKHOLE:
1479 nexthop = route_entry_nexthop_blackhole_add(
1480 re, api_nh->bh_type);
1481 break;
1482 }
1483
1484 if (!nexthop) {
1485 flog_warn(
1486 EC_ZEBRA_NEXTHOP_CREATION_FAILED,
1487 "%s: Nexthops Specified: %d but we failed to properly create one",
1488 __PRETTY_FUNCTION__, api.nexthop_num);
1489 nexthops_free(re->ng.nexthop);
1490 XFREE(MTYPE_RE, re);
1491 return;
1492 }
1493 /* MPLS labels for BGP-LU or Segment Routing */
1494 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_LABEL)
1495 && api_nh->type != NEXTHOP_TYPE_IFINDEX
1496 && api_nh->type != NEXTHOP_TYPE_BLACKHOLE) {
1497 enum lsp_types_t label_type;
1498
1499 label_type =
1500 lsp_type_from_re_type(client->proto);
1501
1502 if (IS_ZEBRA_DEBUG_RECV) {
1503 zlog_debug(
1504 "%s: adding %d labels of type %d (1st=%u)",
1505 __func__, api_nh->label_num,
1506 label_type, api_nh->labels[0]);
1507 }
1508
1509 nexthop_add_labels(nexthop, label_type,
1510 api_nh->label_num,
1511 &api_nh->labels[0]);
1512 }
1513 }
1514
1515 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_DISTANCE))
1516 re->distance = api.distance;
1517 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_METRIC))
1518 re->metric = api.metric;
1519 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_TAG))
1520 re->tag = api.tag;
1521 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_MTU))
1522 re->mtu = api.mtu;
1523
1524 afi = family2afi(api.prefix.family);
1525 if (afi != AFI_IP6 && CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) {
1526 flog_warn(EC_ZEBRA_RX_SRCDEST_WRONG_AFI,
1527 "%s: Received SRC Prefix but afi is not v6",
1528 __PRETTY_FUNCTION__);
1529 nexthops_free(re->ng.nexthop);
1530 XFREE(MTYPE_RE, re);
1531 return;
1532 }
1533 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
1534 src_p = &api.src_prefix;
1535
1536 ret = rib_add_multipath(afi, api.safi, &api.prefix, src_p, re);
1537
1538 /* Stats */
1539 switch (api.prefix.family) {
1540 case AF_INET:
1541 if (ret > 0)
1542 client->v4_route_add_cnt++;
1543 else if (ret < 0)
1544 client->v4_route_upd8_cnt++;
1545 break;
1546 case AF_INET6:
1547 if (ret > 0)
1548 client->v6_route_add_cnt++;
1549 else if (ret < 0)
1550 client->v6_route_upd8_cnt++;
1551 break;
1552 }
1553 }
1554
1555 static void zread_route_del(ZAPI_HANDLER_ARGS)
1556 {
1557 struct stream *s;
1558 struct zapi_route api;
1559 afi_t afi;
1560 struct prefix_ipv6 *src_p = NULL;
1561 uint32_t table_id;
1562
1563 s = msg;
1564 if (zapi_route_decode(s, &api) < 0)
1565 return;
1566
1567 afi = family2afi(api.prefix.family);
1568 if (afi != AFI_IP6 && CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX)) {
1569 flog_warn(EC_ZEBRA_RX_SRCDEST_WRONG_AFI,
1570 "%s: Received a src prefix while afi is not v6",
1571 __PRETTY_FUNCTION__);
1572 return;
1573 }
1574 if (CHECK_FLAG(api.message, ZAPI_MESSAGE_SRCPFX))
1575 src_p = &api.src_prefix;
1576
1577 if (api.vrf_id == VRF_DEFAULT && api.tableid != 0)
1578 table_id = api.tableid;
1579 else
1580 table_id = zvrf->table_id;
1581
1582 rib_delete(afi, api.safi, zvrf_id(zvrf), api.type, api.instance,
1583 api.flags, &api.prefix, src_p, NULL, table_id, api.metric,
1584 api.distance, false);
1585
1586 /* Stats */
1587 switch (api.prefix.family) {
1588 case AF_INET:
1589 client->v4_route_del_cnt++;
1590 break;
1591 case AF_INET6:
1592 client->v6_route_del_cnt++;
1593 break;
1594 }
1595 }
1596
1597 /* MRIB Nexthop lookup for IPv4. */
1598 static void zread_ipv4_nexthop_lookup_mrib(ZAPI_HANDLER_ARGS)
1599 {
1600 struct in_addr addr;
1601 struct route_entry *re;
1602
1603 STREAM_GET(&addr.s_addr, msg, IPV4_MAX_BYTELEN);
1604 re = rib_match_ipv4_multicast(zvrf_id(zvrf), addr, NULL);
1605 zsend_ipv4_nexthop_lookup_mrib(client, addr, re, zvrf);
1606
1607 stream_failure:
1608 return;
1609 }
1610
1611 /* Register zebra server router-id information. Send current router-id */
1612 static void zread_router_id_add(ZAPI_HANDLER_ARGS)
1613 {
1614 struct prefix p;
1615
1616 /* Router-id information is needed. */
1617 vrf_bitmap_set(client->ridinfo, zvrf_id(zvrf));
1618
1619 router_id_get(&p, zvrf_id(zvrf));
1620
1621 zsend_router_id_update(client, &p, zvrf_id(zvrf));
1622 }
1623
1624 /* Unregister zebra server router-id information. */
1625 static void zread_router_id_delete(ZAPI_HANDLER_ARGS)
1626 {
1627 vrf_bitmap_unset(client->ridinfo, zvrf_id(zvrf));
1628 }
1629
1630 static void zsend_capabilities(struct zserv *client, struct zebra_vrf *zvrf)
1631 {
1632 struct stream *s = stream_new(ZEBRA_MAX_PACKET_SIZ);
1633
1634 zclient_create_header(s, ZEBRA_CAPABILITIES, zvrf->vrf->vrf_id);
1635 stream_putc(s, mpls_enabled);
1636 stream_putl(s, multipath_num);
1637
1638 stream_putw_at(s, 0, stream_get_endp(s));
1639 zserv_send_message(client, s);
1640 }
1641
1642 /* Tie up route-type and client->sock */
1643 static void zread_hello(ZAPI_HANDLER_ARGS)
1644 {
1645 /* type of protocol (lib/zebra.h) */
1646 uint8_t proto;
1647 unsigned short instance;
1648 uint8_t notify;
1649
1650 STREAM_GETC(msg, proto);
1651 STREAM_GETW(msg, instance);
1652 STREAM_GETC(msg, notify);
1653 if (notify)
1654 client->notify_owner = true;
1655
1656 /* accept only dynamic routing protocols */
1657 if ((proto < ZEBRA_ROUTE_MAX) && (proto > ZEBRA_ROUTE_CONNECT)) {
1658 zlog_notice(
1659 "client %d says hello and bids fair to announce only %s routes vrf=%u",
1660 client->sock, zebra_route_string(proto),
1661 zvrf->vrf->vrf_id);
1662 if (instance)
1663 zlog_notice("client protocol instance %d", instance);
1664
1665 client->proto = proto;
1666 client->instance = instance;
1667 }
1668
1669 zsend_capabilities(client, zvrf);
1670 stream_failure:
1671 return;
1672 }
1673
1674 /* Unregister all information in a VRF. */
1675 static void zread_vrf_unregister(ZAPI_HANDLER_ARGS)
1676 {
1677 int i;
1678 afi_t afi;
1679
1680 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1681 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1682 vrf_bitmap_unset(client->redist[afi][i], zvrf_id(zvrf));
1683 vrf_bitmap_unset(client->redist_default, zvrf_id(zvrf));
1684 vrf_bitmap_unset(client->ifinfo, zvrf_id(zvrf));
1685 vrf_bitmap_unset(client->ridinfo, zvrf_id(zvrf));
1686 }
1687
1688 static void zread_mpls_labels(ZAPI_HANDLER_ARGS)
1689 {
1690 struct stream *s;
1691 enum lsp_types_t type;
1692 struct prefix prefix;
1693 enum nexthop_types_t gtype;
1694 union g_addr gate;
1695 ifindex_t ifindex;
1696 mpls_label_t in_label, out_label;
1697 uint8_t distance;
1698
1699 /* Get input stream. */
1700 s = msg;
1701
1702 /* Get data. */
1703 STREAM_GETC(s, type);
1704 STREAM_GETL(s, prefix.family);
1705 switch (prefix.family) {
1706 case AF_INET:
1707 STREAM_GET(&prefix.u.prefix4.s_addr, s, IPV4_MAX_BYTELEN);
1708 STREAM_GETC(s, prefix.prefixlen);
1709 if (prefix.prefixlen > IPV4_MAX_BITLEN) {
1710 zlog_debug(
1711 "%s: Specified prefix length %d is greater than a v4 address can support",
1712 __PRETTY_FUNCTION__, prefix.prefixlen);
1713 return;
1714 }
1715 STREAM_GET(&gate.ipv4.s_addr, s, IPV4_MAX_BYTELEN);
1716 break;
1717 case AF_INET6:
1718 STREAM_GET(&prefix.u.prefix6, s, 16);
1719 STREAM_GETC(s, prefix.prefixlen);
1720 if (prefix.prefixlen > IPV6_MAX_BITLEN) {
1721 zlog_debug(
1722 "%s: Specified prefix length %d is greater than a v6 address can support",
1723 __PRETTY_FUNCTION__, prefix.prefixlen);
1724 return;
1725 }
1726 STREAM_GET(&gate.ipv6, s, 16);
1727 break;
1728 default:
1729 zlog_debug("%s: Specified AF %d is not supported for this call",
1730 __PRETTY_FUNCTION__, prefix.family);
1731 return;
1732 }
1733 STREAM_GETL(s, ifindex);
1734 STREAM_GETC(s, distance);
1735 STREAM_GETL(s, in_label);
1736 STREAM_GETL(s, out_label);
1737
1738 switch (prefix.family) {
1739 case AF_INET:
1740 if (ifindex)
1741 gtype = NEXTHOP_TYPE_IPV4_IFINDEX;
1742 else
1743 gtype = NEXTHOP_TYPE_IPV4;
1744 break;
1745 case AF_INET6:
1746 if (ifindex)
1747 gtype = NEXTHOP_TYPE_IPV6_IFINDEX;
1748 else
1749 gtype = NEXTHOP_TYPE_IPV6;
1750 break;
1751 default:
1752 return;
1753 }
1754
1755 if (!mpls_enabled)
1756 return;
1757
1758 if (hdr->command == ZEBRA_MPLS_LABELS_ADD) {
1759 mpls_lsp_install(zvrf, type, in_label, out_label, gtype, &gate,
1760 ifindex);
1761 mpls_ftn_update(1, zvrf, type, &prefix, gtype, &gate, ifindex,
1762 distance, out_label);
1763 } else if (hdr->command == ZEBRA_MPLS_LABELS_DELETE) {
1764 mpls_lsp_uninstall(zvrf, type, in_label, gtype, &gate, ifindex);
1765 mpls_ftn_update(0, zvrf, type, &prefix, gtype, &gate, ifindex,
1766 distance, out_label);
1767 }
1768 stream_failure:
1769 return;
1770 }
1771
1772 /* Send response to a table manager connect request to client */
1773 static void zread_table_manager_connect(struct zserv *client,
1774 struct stream *msg, vrf_id_t vrf_id)
1775 {
1776 struct stream *s;
1777 uint8_t proto;
1778 uint16_t instance;
1779
1780 s = msg;
1781
1782 /* Get data. */
1783 STREAM_GETC(s, proto);
1784 STREAM_GETW(s, instance);
1785
1786 /* accept only dynamic routing protocols */
1787 if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) {
1788 flog_err(EC_ZEBRA_TM_WRONG_PROTO,
1789 "client %d has wrong protocol %s", client->sock,
1790 zebra_route_string(proto));
1791 zsend_table_manager_connect_response(client, vrf_id, 1);
1792 return;
1793 }
1794 zlog_notice("client %d with vrf %u instance %u connected as %s",
1795 client->sock, vrf_id, instance, zebra_route_string(proto));
1796 client->proto = proto;
1797 client->instance = instance;
1798
1799 /*
1800 * Release previous labels of same protocol and instance.
1801 * This is done in case it restarted from an unexpected shutdown.
1802 */
1803 release_daemon_table_chunks(client);
1804
1805 zsend_table_manager_connect_response(client, vrf_id, 0);
1806
1807 stream_failure:
1808 return;
1809 }
1810
1811 static void zread_label_manager_connect(struct zserv *client,
1812 struct stream *msg, vrf_id_t vrf_id)
1813 {
1814 struct stream *s;
1815 /* type of protocol (lib/zebra.h) */
1816 uint8_t proto;
1817 unsigned short instance;
1818
1819 /* Get input stream. */
1820 s = msg;
1821
1822 /* Get data. */
1823 STREAM_GETC(s, proto);
1824 STREAM_GETW(s, instance);
1825
1826 /* accept only dynamic routing protocols */
1827 if ((proto >= ZEBRA_ROUTE_MAX) || (proto <= ZEBRA_ROUTE_STATIC)) {
1828 flog_err(EC_ZEBRA_TM_WRONG_PROTO,
1829 "client %d has wrong protocol %s", client->sock,
1830 zebra_route_string(proto));
1831 if (client->is_synchronous)
1832 zsend_label_manager_connect_response(client, vrf_id, 1);
1833 return;
1834 }
1835 zlog_notice("client %d with vrf %u instance %u connected as %s",
1836 client->sock, vrf_id, instance, zebra_route_string(proto));
1837 client->proto = proto;
1838 client->instance = instance;
1839
1840 /*
1841 * Release previous labels of same protocol and instance.
1842 * This is done in case it restarted from an unexpected shutdown.
1843 */
1844 release_daemon_label_chunks(client);
1845
1846 zlog_debug(
1847 " Label Manager client connected: sock %d, proto %s, vrf %u instance %u",
1848 client->sock, zebra_route_string(proto), vrf_id, instance);
1849 /* send response back */
1850 if (client->is_synchronous)
1851 zsend_label_manager_connect_response(client, vrf_id, 0);
1852
1853 stream_failure:
1854 return;
1855 }
1856
1857 static void zread_get_label_chunk(struct zserv *client, struct stream *msg,
1858 vrf_id_t vrf_id)
1859 {
1860 struct stream *s;
1861 uint8_t keep;
1862 uint32_t size;
1863 struct label_manager_chunk *lmc;
1864 uint8_t proto;
1865 unsigned short instance;
1866
1867 /* Get input stream. */
1868 s = msg;
1869
1870 /* Get data. */
1871 STREAM_GETC(s, proto);
1872 STREAM_GETW(s, instance);
1873 STREAM_GETC(s, keep);
1874 STREAM_GETL(s, size);
1875
1876 lmc = assign_label_chunk(proto, instance, keep, size);
1877 if (!lmc)
1878 flog_err(
1879 EC_ZEBRA_LM_CANNOT_ASSIGN_CHUNK,
1880 "Unable to assign Label Chunk of size %u to %s instance %u",
1881 size, zebra_route_string(proto), instance);
1882 else
1883 zlog_debug("Assigned Label Chunk %u - %u to %s instance %u",
1884 lmc->start, lmc->end,
1885 zebra_route_string(proto), instance);
1886 /* send response back */
1887 zsend_assign_label_chunk_response(client, vrf_id, lmc);
1888
1889 stream_failure:
1890 return;
1891 }
1892
1893 static void zread_release_label_chunk(struct zserv *client, struct stream *msg)
1894 {
1895 struct stream *s;
1896 uint32_t start, end;
1897 uint8_t proto;
1898 unsigned short instance;
1899
1900 /* Get input stream. */
1901 s = msg;
1902
1903 /* Get data. */
1904 STREAM_GETC(s, proto);
1905 STREAM_GETW(s, instance);
1906 STREAM_GETL(s, start);
1907 STREAM_GETL(s, end);
1908
1909 release_label_chunk(proto, instance, start, end);
1910
1911 stream_failure:
1912 return;
1913 }
1914 static void zread_label_manager_request(ZAPI_HANDLER_ARGS)
1915 {
1916 /* to avoid sending other messages like ZERBA_INTERFACE_UP */
1917 client->is_synchronous = hdr->command ==
1918 ZEBRA_LABEL_MANAGER_CONNECT;
1919
1920 /* external label manager */
1921 if (lm_is_external)
1922 zread_relay_label_manager_request(hdr->command, client, msg,
1923 zvrf_id(zvrf));
1924 /* this is a label manager */
1925 else {
1926 if (hdr->command == ZEBRA_LABEL_MANAGER_CONNECT ||
1927 hdr->command == ZEBRA_LABEL_MANAGER_CONNECT_ASYNC)
1928 zread_label_manager_connect(client, msg, zvrf_id(zvrf));
1929 else {
1930 if (hdr->command == ZEBRA_GET_LABEL_CHUNK)
1931 zread_get_label_chunk(client, msg,
1932 zvrf_id(zvrf));
1933 else if (hdr->command == ZEBRA_RELEASE_LABEL_CHUNK)
1934 zread_release_label_chunk(client, msg);
1935 }
1936 }
1937 }
1938
1939 static void zread_get_table_chunk(struct zserv *client, struct stream *msg,
1940 vrf_id_t vrf_id)
1941 {
1942 struct stream *s;
1943 uint32_t size;
1944 struct table_manager_chunk *tmc;
1945
1946 /* Get input stream. */
1947 s = msg;
1948
1949 /* Get data. */
1950 STREAM_GETL(s, size);
1951
1952 tmc = assign_table_chunk(client->proto, client->instance, size);
1953 if (!tmc)
1954 flog_err(EC_ZEBRA_TM_CANNOT_ASSIGN_CHUNK,
1955 "%s: Unable to assign Table Chunk of size %u",
1956 __func__, size);
1957 else
1958 zlog_debug("Assigned Table Chunk %u - %u", tmc->start,
1959 tmc->end);
1960 /* send response back */
1961 zsend_assign_table_chunk_response(client, vrf_id, tmc);
1962
1963 stream_failure:
1964 return;
1965 }
1966
1967 static void zread_release_table_chunk(struct zserv *client, struct stream *msg)
1968 {
1969 struct stream *s;
1970 uint32_t start, end;
1971
1972 /* Get input stream. */
1973 s = msg;
1974
1975 /* Get data. */
1976 STREAM_GETL(s, start);
1977 STREAM_GETL(s, end);
1978
1979 release_table_chunk(client->proto, client->instance, start, end);
1980
1981 stream_failure:
1982 return;
1983 }
1984
1985 static void zread_table_manager_request(ZAPI_HANDLER_ARGS)
1986 {
1987 /* to avoid sending other messages like ZERBA_INTERFACE_UP */
1988 if (hdr->command == ZEBRA_TABLE_MANAGER_CONNECT)
1989 zread_table_manager_connect(client, msg, zvrf_id(zvrf));
1990 else {
1991 /* Sanity: don't allow 'unidentified' requests */
1992 if (!client->proto) {
1993 flog_err(
1994 EC_ZEBRA_TM_ALIENS,
1995 "Got table request from an unidentified client");
1996 return;
1997 }
1998 if (hdr->command == ZEBRA_GET_TABLE_CHUNK)
1999 zread_get_table_chunk(client, msg, zvrf_id(zvrf));
2000 else if (hdr->command == ZEBRA_RELEASE_TABLE_CHUNK)
2001 zread_release_table_chunk(client, msg);
2002 }
2003 }
2004
2005 static void zread_pseudowire(ZAPI_HANDLER_ARGS)
2006 {
2007 struct stream *s;
2008 char ifname[IF_NAMESIZE];
2009 ifindex_t ifindex;
2010 int type;
2011 int af;
2012 union g_addr nexthop;
2013 uint32_t local_label;
2014 uint32_t remote_label;
2015 uint8_t flags;
2016 union pw_protocol_fields data;
2017 uint8_t protocol;
2018 struct zebra_pw *pw;
2019
2020 /* Get input stream. */
2021 s = msg;
2022
2023 /* Get data. */
2024 STREAM_GET(ifname, s, IF_NAMESIZE);
2025 STREAM_GETL(s, ifindex);
2026 STREAM_GETL(s, type);
2027 STREAM_GETL(s, af);
2028 switch (af) {
2029 case AF_INET:
2030 STREAM_GET(&nexthop.ipv4.s_addr, s, IPV4_MAX_BYTELEN);
2031 break;
2032 case AF_INET6:
2033 STREAM_GET(&nexthop.ipv6, s, 16);
2034 break;
2035 default:
2036 return;
2037 }
2038 STREAM_GETL(s, local_label);
2039 STREAM_GETL(s, remote_label);
2040 STREAM_GETC(s, flags);
2041 STREAM_GET(&data, s, sizeof(data));
2042 protocol = client->proto;
2043
2044 pw = zebra_pw_find(zvrf, ifname);
2045 switch (hdr->command) {
2046 case ZEBRA_PW_ADD:
2047 if (pw) {
2048 flog_warn(EC_ZEBRA_PSEUDOWIRE_EXISTS,
2049 "%s: pseudowire %s already exists [%s]",
2050 __func__, ifname,
2051 zserv_command_string(hdr->command));
2052 return;
2053 }
2054
2055 zebra_pw_add(zvrf, ifname, protocol, client);
2056 break;
2057 case ZEBRA_PW_DELETE:
2058 if (!pw) {
2059 flog_warn(EC_ZEBRA_PSEUDOWIRE_NONEXISTENT,
2060 "%s: pseudowire %s not found [%s]", __func__,
2061 ifname, zserv_command_string(hdr->command));
2062 return;
2063 }
2064
2065 zebra_pw_del(zvrf, pw);
2066 break;
2067 case ZEBRA_PW_SET:
2068 case ZEBRA_PW_UNSET:
2069 if (!pw) {
2070 flog_warn(EC_ZEBRA_PSEUDOWIRE_NONEXISTENT,
2071 "%s: pseudowire %s not found [%s]", __func__,
2072 ifname, zserv_command_string(hdr->command));
2073 return;
2074 }
2075
2076 switch (hdr->command) {
2077 case ZEBRA_PW_SET:
2078 pw->enabled = 1;
2079 break;
2080 case ZEBRA_PW_UNSET:
2081 pw->enabled = 0;
2082 break;
2083 }
2084
2085 zebra_pw_change(pw, ifindex, type, af, &nexthop, local_label,
2086 remote_label, flags, &data);
2087 break;
2088 }
2089
2090 stream_failure:
2091 return;
2092 }
2093
2094 static void zread_interface_set_master(ZAPI_HANDLER_ARGS)
2095 {
2096 struct interface *master;
2097 struct interface *slave;
2098 struct stream *s = msg;
2099 int ifindex;
2100 vrf_id_t vrf_id;
2101
2102 STREAM_GETL(s, vrf_id);
2103 STREAM_GETL(s, ifindex);
2104 master = if_lookup_by_index(ifindex, vrf_id);
2105
2106 STREAM_GETL(s, vrf_id);
2107 STREAM_GETL(s, ifindex);
2108 slave = if_lookup_by_index(ifindex, vrf_id);
2109
2110 if (!master || !slave)
2111 return;
2112
2113 kernel_interface_set_master(master, slave);
2114
2115 stream_failure:
2116 return;
2117 }
2118
2119
2120 static void zread_vrf_label(ZAPI_HANDLER_ARGS)
2121 {
2122 struct interface *ifp;
2123 mpls_label_t nlabel;
2124 afi_t afi;
2125 struct stream *s;
2126 struct zebra_vrf *def_zvrf;
2127 enum lsp_types_t ltype;
2128
2129 s = msg;
2130 STREAM_GETL(s, nlabel);
2131 STREAM_GETC(s, afi);
2132 if (nlabel == zvrf->label[afi]) {
2133 /*
2134 * Nothing to do here move along
2135 */
2136 return;
2137 }
2138
2139 STREAM_GETC(s, ltype);
2140
2141 if (zvrf->vrf->vrf_id != VRF_DEFAULT)
2142 ifp = if_lookup_by_name(zvrf->vrf->name, zvrf->vrf->vrf_id);
2143 else
2144 ifp = if_lookup_by_name("lo", VRF_DEFAULT);
2145
2146 if (!ifp) {
2147 zlog_debug("Unable to find specified Interface for %s",
2148 zvrf->vrf->name);
2149 return;
2150 }
2151
2152 def_zvrf = zebra_vrf_lookup_by_id(VRF_DEFAULT);
2153
2154 if (zvrf->label[afi] != MPLS_LABEL_NONE) {
2155 afi_t scrubber;
2156 bool really_remove;
2157
2158 really_remove = true;
2159 for (scrubber = AFI_IP; scrubber < AFI_MAX; scrubber++) {
2160 if (scrubber == afi)
2161 continue;
2162
2163 if (zvrf->label[scrubber] == MPLS_LABEL_NONE)
2164 continue;
2165
2166 if (zvrf->label[afi] == zvrf->label[scrubber]) {
2167 really_remove = false;
2168 break;
2169 }
2170 }
2171
2172 if (really_remove)
2173 mpls_lsp_uninstall(def_zvrf, ltype, zvrf->label[afi],
2174 NEXTHOP_TYPE_IFINDEX, NULL,
2175 ifp->ifindex);
2176 }
2177
2178 if (nlabel != MPLS_LABEL_NONE)
2179 mpls_lsp_install(def_zvrf, ltype, nlabel,
2180 MPLS_LABEL_IMPLICIT_NULL, NEXTHOP_TYPE_IFINDEX,
2181 NULL, ifp->ifindex);
2182
2183 zvrf->label[afi] = nlabel;
2184 stream_failure:
2185 return;
2186 }
2187
2188 static inline void zread_rule(ZAPI_HANDLER_ARGS)
2189 {
2190 struct zebra_pbr_rule zpr;
2191 struct stream *s;
2192 uint32_t total, i;
2193 ifindex_t ifindex;
2194
2195 s = msg;
2196 STREAM_GETL(s, total);
2197
2198 for (i = 0; i < total; i++) {
2199 memset(&zpr, 0, sizeof(zpr));
2200
2201 zpr.sock = client->sock;
2202 zpr.rule.vrf_id = hdr->vrf_id;
2203 STREAM_GETL(s, zpr.rule.seq);
2204 STREAM_GETL(s, zpr.rule.priority);
2205 STREAM_GETL(s, zpr.rule.unique);
2206 STREAM_GETC(s, zpr.rule.filter.src_ip.family);
2207 STREAM_GETC(s, zpr.rule.filter.src_ip.prefixlen);
2208 STREAM_GET(&zpr.rule.filter.src_ip.u.prefix, s,
2209 prefix_blen(&zpr.rule.filter.src_ip));
2210 STREAM_GETW(s, zpr.rule.filter.src_port);
2211 STREAM_GETC(s, zpr.rule.filter.dst_ip.family);
2212 STREAM_GETC(s, zpr.rule.filter.dst_ip.prefixlen);
2213 STREAM_GET(&zpr.rule.filter.dst_ip.u.prefix, s,
2214 prefix_blen(&zpr.rule.filter.dst_ip));
2215 STREAM_GETW(s, zpr.rule.filter.dst_port);
2216 STREAM_GETL(s, zpr.rule.filter.fwmark);
2217 STREAM_GETL(s, zpr.rule.action.table);
2218 STREAM_GETL(s, ifindex);
2219
2220 if (ifindex) {
2221 zpr.ifp = if_lookup_by_index_per_ns(
2222 zvrf->zns,
2223 ifindex);
2224 if (!zpr.ifp) {
2225 zlog_debug("Failed to lookup ifindex: %u",
2226 ifindex);
2227 return;
2228 }
2229 }
2230
2231 if (!is_default_prefix(&zpr.rule.filter.src_ip))
2232 zpr.rule.filter.filter_bm |= PBR_FILTER_SRC_IP;
2233
2234 if (!is_default_prefix(&zpr.rule.filter.dst_ip))
2235 zpr.rule.filter.filter_bm |= PBR_FILTER_DST_IP;
2236
2237 if (zpr.rule.filter.src_port)
2238 zpr.rule.filter.filter_bm |= PBR_FILTER_SRC_PORT;
2239
2240 if (zpr.rule.filter.dst_port)
2241 zpr.rule.filter.filter_bm |= PBR_FILTER_DST_PORT;
2242
2243 if (zpr.rule.filter.fwmark)
2244 zpr.rule.filter.filter_bm |= PBR_FILTER_FWMARK;
2245
2246 zpr.vrf_id = zvrf->vrf->vrf_id;
2247 if (hdr->command == ZEBRA_RULE_ADD)
2248 zebra_pbr_add_rule(&zpr);
2249 else
2250 zebra_pbr_del_rule(&zpr);
2251 }
2252
2253 stream_failure:
2254 return;
2255 }
2256
2257 static inline void zread_ipset(ZAPI_HANDLER_ARGS)
2258 {
2259 struct zebra_pbr_ipset zpi;
2260 struct stream *s;
2261 uint32_t total, i;
2262
2263 s = msg;
2264 STREAM_GETL(s, total);
2265
2266 for (i = 0; i < total; i++) {
2267 memset(&zpi, 0, sizeof(zpi));
2268
2269 zpi.sock = client->sock;
2270 zpi.vrf_id = zvrf->vrf->vrf_id;
2271 STREAM_GETL(s, zpi.unique);
2272 STREAM_GETL(s, zpi.type);
2273 STREAM_GET(&zpi.ipset_name, s, ZEBRA_IPSET_NAME_SIZE);
2274
2275 if (hdr->command == ZEBRA_IPSET_CREATE)
2276 zebra_pbr_create_ipset(zvrf->zns, &zpi);
2277 else
2278 zebra_pbr_destroy_ipset(zvrf->zns, &zpi);
2279 }
2280
2281 stream_failure:
2282 return;
2283 }
2284
2285 static inline void zread_ipset_entry(ZAPI_HANDLER_ARGS)
2286 {
2287 struct zebra_pbr_ipset_entry zpi;
2288 struct zebra_pbr_ipset ipset;
2289 struct stream *s;
2290 uint32_t total, i;
2291
2292 s = msg;
2293 STREAM_GETL(s, total);
2294
2295 for (i = 0; i < total; i++) {
2296 memset(&zpi, 0, sizeof(zpi));
2297 memset(&ipset, 0, sizeof(ipset));
2298
2299 zpi.sock = client->sock;
2300 STREAM_GETL(s, zpi.unique);
2301 STREAM_GET(&ipset.ipset_name, s, ZEBRA_IPSET_NAME_SIZE);
2302 STREAM_GETC(s, zpi.src.family);
2303 STREAM_GETC(s, zpi.src.prefixlen);
2304 STREAM_GET(&zpi.src.u.prefix, s, prefix_blen(&zpi.src));
2305 STREAM_GETC(s, zpi.dst.family);
2306 STREAM_GETC(s, zpi.dst.prefixlen);
2307 STREAM_GET(&zpi.dst.u.prefix, s, prefix_blen(&zpi.dst));
2308
2309 STREAM_GETW(s, zpi.src_port_min);
2310 STREAM_GETW(s, zpi.src_port_max);
2311 STREAM_GETW(s, zpi.dst_port_min);
2312 STREAM_GETW(s, zpi.dst_port_max);
2313 STREAM_GETC(s, zpi.proto);
2314 if (!is_default_prefix(&zpi.src))
2315 zpi.filter_bm |= PBR_FILTER_SRC_IP;
2316
2317 if (!is_default_prefix(&zpi.dst))
2318 zpi.filter_bm |= PBR_FILTER_DST_IP;
2319 if (zpi.dst_port_min != 0 || zpi.proto == IPPROTO_ICMP)
2320 zpi.filter_bm |= PBR_FILTER_DST_PORT;
2321 if (zpi.src_port_min != 0 || zpi.proto == IPPROTO_ICMP)
2322 zpi.filter_bm |= PBR_FILTER_SRC_PORT;
2323 if (zpi.dst_port_max != 0)
2324 zpi.filter_bm |= PBR_FILTER_DST_PORT_RANGE;
2325 if (zpi.src_port_max != 0)
2326 zpi.filter_bm |= PBR_FILTER_SRC_PORT_RANGE;
2327 if (zpi.proto != 0)
2328 zpi.filter_bm |= PBR_FILTER_PROTO;
2329
2330 /* calculate backpointer */
2331 zpi.backpointer = zebra_pbr_lookup_ipset_pername(
2332 zvrf->zns, ipset.ipset_name);
2333 if (hdr->command == ZEBRA_IPSET_ENTRY_ADD)
2334 zebra_pbr_add_ipset_entry(zvrf->zns, &zpi);
2335 else
2336 zebra_pbr_del_ipset_entry(zvrf->zns, &zpi);
2337 }
2338
2339 stream_failure:
2340 return;
2341 }
2342
2343 static inline void zread_iptable(ZAPI_HANDLER_ARGS)
2344 {
2345 struct zebra_pbr_iptable zpi;
2346 struct stream *s;
2347
2348 s = msg;
2349
2350 memset(&zpi, 0, sizeof(zpi));
2351
2352 zpi.interface_name_list = list_new();
2353 zpi.sock = client->sock;
2354 zpi.vrf_id = zvrf->vrf->vrf_id;
2355 STREAM_GETL(s, zpi.unique);
2356 STREAM_GETL(s, zpi.type);
2357 STREAM_GETL(s, zpi.filter_bm);
2358 STREAM_GETL(s, zpi.action);
2359 STREAM_GETL(s, zpi.fwmark);
2360 STREAM_GET(&zpi.ipset_name, s, ZEBRA_IPSET_NAME_SIZE);
2361 STREAM_GETW(s, zpi.pkt_len_min);
2362 STREAM_GETW(s, zpi.pkt_len_max);
2363 STREAM_GETW(s, zpi.tcp_flags);
2364 STREAM_GETW(s, zpi.tcp_mask_flags);
2365 STREAM_GETC(s, zpi.dscp_value);
2366 STREAM_GETC(s, zpi.fragment);
2367 STREAM_GETL(s, zpi.nb_interface);
2368 zebra_pbr_iptable_update_interfacelist(s, &zpi);
2369
2370 if (hdr->command == ZEBRA_IPTABLE_ADD)
2371 zebra_pbr_add_iptable(zvrf->zns, &zpi);
2372 else
2373 zebra_pbr_del_iptable(zvrf->zns, &zpi);
2374 stream_failure:
2375 return;
2376 }
2377
2378 void (*zserv_handlers[])(ZAPI_HANDLER_ARGS) = {
2379 [ZEBRA_ROUTER_ID_ADD] = zread_router_id_add,
2380 [ZEBRA_ROUTER_ID_DELETE] = zread_router_id_delete,
2381 [ZEBRA_INTERFACE_ADD] = zread_interface_add,
2382 [ZEBRA_INTERFACE_DELETE] = zread_interface_delete,
2383 [ZEBRA_ROUTE_ADD] = zread_route_add,
2384 [ZEBRA_ROUTE_DELETE] = zread_route_del,
2385 [ZEBRA_REDISTRIBUTE_ADD] = zebra_redistribute_add,
2386 [ZEBRA_REDISTRIBUTE_DELETE] = zebra_redistribute_delete,
2387 [ZEBRA_REDISTRIBUTE_DEFAULT_ADD] = zebra_redistribute_default_add,
2388 [ZEBRA_REDISTRIBUTE_DEFAULT_DELETE] = zebra_redistribute_default_delete,
2389 [ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB] = zread_ipv4_nexthop_lookup_mrib,
2390 [ZEBRA_HELLO] = zread_hello,
2391 [ZEBRA_NEXTHOP_REGISTER] = zread_rnh_register,
2392 [ZEBRA_NEXTHOP_UNREGISTER] = zread_rnh_unregister,
2393 [ZEBRA_IMPORT_ROUTE_REGISTER] = zread_rnh_register,
2394 [ZEBRA_IMPORT_ROUTE_UNREGISTER] = zread_rnh_unregister,
2395 [ZEBRA_BFD_DEST_UPDATE] = zebra_ptm_bfd_dst_register,
2396 [ZEBRA_BFD_DEST_REGISTER] = zebra_ptm_bfd_dst_register,
2397 [ZEBRA_BFD_DEST_DEREGISTER] = zebra_ptm_bfd_dst_deregister,
2398 #if HAVE_BFDD > 0
2399 [ZEBRA_BFD_DEST_REPLAY] = zebra_ptm_bfd_dst_replay,
2400 #endif /* HAVE_BFDD */
2401 [ZEBRA_VRF_UNREGISTER] = zread_vrf_unregister,
2402 [ZEBRA_VRF_LABEL] = zread_vrf_label,
2403 [ZEBRA_BFD_CLIENT_REGISTER] = zebra_ptm_bfd_client_register,
2404 #if defined(HAVE_RTADV)
2405 [ZEBRA_INTERFACE_ENABLE_RADV] = zebra_interface_radv_enable,
2406 [ZEBRA_INTERFACE_DISABLE_RADV] = zebra_interface_radv_disable,
2407 #else
2408 [ZEBRA_INTERFACE_ENABLE_RADV] = NULL,
2409 [ZEBRA_INTERFACE_DISABLE_RADV] = NULL,
2410 #endif
2411 [ZEBRA_MPLS_LABELS_ADD] = zread_mpls_labels,
2412 [ZEBRA_MPLS_LABELS_DELETE] = zread_mpls_labels,
2413 [ZEBRA_IPMR_ROUTE_STATS] = zebra_ipmr_route_stats,
2414 [ZEBRA_LABEL_MANAGER_CONNECT] = zread_label_manager_request,
2415 [ZEBRA_LABEL_MANAGER_CONNECT_ASYNC] = zread_label_manager_request,
2416 [ZEBRA_GET_LABEL_CHUNK] = zread_label_manager_request,
2417 [ZEBRA_RELEASE_LABEL_CHUNK] = zread_label_manager_request,
2418 [ZEBRA_FEC_REGISTER] = zread_fec_register,
2419 [ZEBRA_FEC_UNREGISTER] = zread_fec_unregister,
2420 [ZEBRA_ADVERTISE_DEFAULT_GW] = zebra_vxlan_advertise_gw_macip,
2421 [ZEBRA_ADVERTISE_SUBNET] = zebra_vxlan_advertise_subnet,
2422 [ZEBRA_ADVERTISE_ALL_VNI] = zebra_vxlan_advertise_all_vni,
2423 [ZEBRA_REMOTE_VTEP_ADD] = zebra_vxlan_remote_vtep_add,
2424 [ZEBRA_REMOTE_VTEP_DEL] = zebra_vxlan_remote_vtep_del,
2425 [ZEBRA_REMOTE_MACIP_ADD] = zebra_vxlan_remote_macip_add,
2426 [ZEBRA_REMOTE_MACIP_DEL] = zebra_vxlan_remote_macip_del,
2427 [ZEBRA_INTERFACE_SET_MASTER] = zread_interface_set_master,
2428 [ZEBRA_PW_ADD] = zread_pseudowire,
2429 [ZEBRA_PW_DELETE] = zread_pseudowire,
2430 [ZEBRA_PW_SET] = zread_pseudowire,
2431 [ZEBRA_PW_UNSET] = zread_pseudowire,
2432 [ZEBRA_RULE_ADD] = zread_rule,
2433 [ZEBRA_RULE_DELETE] = zread_rule,
2434 [ZEBRA_TABLE_MANAGER_CONNECT] = zread_table_manager_request,
2435 [ZEBRA_GET_TABLE_CHUNK] = zread_table_manager_request,
2436 [ZEBRA_RELEASE_TABLE_CHUNK] = zread_table_manager_request,
2437 [ZEBRA_IPSET_CREATE] = zread_ipset,
2438 [ZEBRA_IPSET_DESTROY] = zread_ipset,
2439 [ZEBRA_IPSET_ENTRY_ADD] = zread_ipset_entry,
2440 [ZEBRA_IPSET_ENTRY_DELETE] = zread_ipset_entry,
2441 [ZEBRA_IPTABLE_ADD] = zread_iptable,
2442 [ZEBRA_IPTABLE_DELETE] = zread_iptable,
2443 [ZEBRA_VXLAN_FLOOD_CONTROL] = zebra_vxlan_flood_control,
2444 };
2445
2446 #if defined(HANDLE_ZAPI_FUZZING)
2447 extern struct zebra_privs_t zserv_privs;
2448
2449 static void zserv_write_incoming(struct stream *orig, uint16_t command)
2450 {
2451 char fname[MAXPATHLEN];
2452 struct stream *copy;
2453 int fd = -1;
2454
2455 copy = stream_dup(orig);
2456 stream_set_getp(copy, 0);
2457
2458 snprintf(fname, MAXPATHLEN, "%s/%u", DAEMON_VTY_DIR, command);
2459
2460 frr_elevate_privs(&zserv_privs) {
2461 fd = open(fname, O_CREAT | O_WRONLY | O_EXCL, 0644);
2462 }
2463 stream_flush(copy, fd);
2464 close(fd);
2465 stream_free(copy);
2466 }
2467 #endif
2468
2469 void zserv_handle_commands(struct zserv *client, struct stream *msg)
2470 {
2471 struct zmsghdr hdr;
2472 struct zebra_vrf *zvrf;
2473
2474 zapi_parse_header(msg, &hdr);
2475
2476 #if defined(HANDLE_ZAPI_FUZZING)
2477 zserv_write_incoming(msg, hdr.command);
2478 #endif
2479
2480 hdr.length -= ZEBRA_HEADER_SIZE;
2481
2482 /* lookup vrf */
2483 zvrf = zebra_vrf_lookup_by_id(hdr.vrf_id);
2484 if (!zvrf) {
2485 if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
2486 zlog_debug("ZAPI message specifies unknown VRF: %d",
2487 hdr.vrf_id);
2488 return;
2489 }
2490
2491 if (hdr.command >= array_size(zserv_handlers)
2492 || zserv_handlers[hdr.command] == NULL)
2493 zlog_info("Zebra received unknown command %d", hdr.command);
2494 else
2495 zserv_handlers[hdr.command](client, &hdr, msg, zvrf);
2496 }