]> git.proxmox.com Git - mirror_frr.git/blob - zebra/zserv.c
Merge pull request #104 from opensourcerouting/time-cleanup
[mirror_frr.git] / zebra / zserv.c
1 /* Zebra daemon server routine.
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
17 * along with GNU Zebra; see the file COPYING. If not, write to the
18 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
19 * Boston, MA 02111-1307, USA.
20 */
21
22 #include <zebra.h>
23
24 #include "prefix.h"
25 #include "command.h"
26 #include "if.h"
27 #include "thread.h"
28 #include "stream.h"
29 #include "memory.h"
30 #include "zebra_memory.h"
31 #include "table.h"
32 #include "rib.h"
33 #include "network.h"
34 #include "sockunion.h"
35 #include "log.h"
36 #include "zclient.h"
37 #include "privs.h"
38 #include "network.h"
39 #include "buffer.h"
40 #include "nexthop.h"
41 #include "vrf.h"
42
43 #include "zebra/zserv.h"
44 #include "zebra/zebra_ns.h"
45 #include "zebra/zebra_vrf.h"
46 #include "zebra/router-id.h"
47 #include "zebra/redistribute.h"
48 #include "zebra/debug.h"
49 #include "zebra/ipforward.h"
50 #include "zebra/zebra_rnh.h"
51 #include "zebra/rt_netlink.h"
52 #include "zebra/interface.h"
53 #include "zebra/zebra_ptm.h"
54 #include "zebra/rtadv.h"
55 #include "zebra/zebra_mpls.h"
56 #include "zebra/zebra_fpm.h"
57 #include "zebra/zebra_mroute.h"
58
59 /* Event list of zebra. */
60 enum event { ZEBRA_SERV, ZEBRA_READ, ZEBRA_WRITE };
61
62 static void zebra_event (enum event event, int sock, struct zserv *client);
63
64 extern struct zebra_privs_t zserv_privs;
65
66 static void zebra_client_close (struct zserv *client);
67
68 static int
69 zserv_delayed_close(struct thread *thread)
70 {
71 struct zserv *client = THREAD_ARG(thread);
72
73 client->t_suicide = NULL;
74 zebra_client_close(client);
75 return 0;
76 }
77
78 static int
79 zserv_flush_data(struct thread *thread)
80 {
81 struct zserv *client = THREAD_ARG(thread);
82
83 client->t_write = NULL;
84 if (client->t_suicide)
85 {
86 zebra_client_close(client);
87 return -1;
88 }
89 switch (buffer_flush_available(client->wb, client->sock))
90 {
91 case BUFFER_ERROR:
92 zlog_warn("%s: buffer_flush_available failed on zserv client fd %d, "
93 "closing", __func__, client->sock);
94 zebra_client_close(client);
95 break;
96 case BUFFER_PENDING:
97 client->t_write = thread_add_write(zebrad.master, zserv_flush_data,
98 client, client->sock);
99 break;
100 case BUFFER_EMPTY:
101 break;
102 }
103
104 client->last_write_time = monotime(NULL);
105 return 0;
106 }
107
108 int
109 zebra_server_send_message(struct zserv *client)
110 {
111 if (client->t_suicide)
112 return -1;
113
114 stream_set_getp(client->obuf, 0);
115 client->last_write_cmd = stream_getw_from(client->obuf, 6);
116 switch (buffer_write(client->wb, client->sock, STREAM_DATA(client->obuf),
117 stream_get_endp(client->obuf)))
118 {
119 case BUFFER_ERROR:
120 zlog_warn("%s: buffer_write failed to zserv client fd %d, closing",
121 __func__, client->sock);
122 /* Schedule a delayed close since many of the functions that call this
123 one do not check the return code. They do not allow for the
124 possibility that an I/O error may have caused the client to be
125 deleted. */
126 client->t_suicide = thread_add_event(zebrad.master, zserv_delayed_close,
127 client, 0);
128 return -1;
129 case BUFFER_EMPTY:
130 THREAD_OFF(client->t_write);
131 break;
132 case BUFFER_PENDING:
133 THREAD_WRITE_ON(zebrad.master, client->t_write,
134 zserv_flush_data, client, client->sock);
135 break;
136 }
137
138 client->last_write_time = monotime(NULL);
139 return 0;
140 }
141
142 void
143 zserv_create_header (struct stream *s, uint16_t cmd, vrf_id_t vrf_id)
144 {
145 /* length placeholder, caller can update */
146 stream_putw (s, ZEBRA_HEADER_SIZE);
147 stream_putc (s, ZEBRA_HEADER_MARKER);
148 stream_putc (s, ZSERV_VERSION);
149 stream_putw (s, vrf_id);
150 stream_putw (s, cmd);
151 }
152
153 static void
154 zserv_encode_interface (struct stream *s, struct interface *ifp)
155 {
156 /* Interface information. */
157 stream_put (s, ifp->name, INTERFACE_NAMSIZ);
158 stream_putl (s, ifp->ifindex);
159 stream_putc (s, ifp->status);
160 stream_putq (s, ifp->flags);
161 stream_putc (s, ifp->ptm_enable);
162 stream_putc (s, ifp->ptm_status);
163 stream_putl (s, ifp->metric);
164 stream_putl (s, ifp->mtu);
165 stream_putl (s, ifp->mtu6);
166 stream_putl (s, ifp->bandwidth);
167 stream_putl (s, ifp->ll_type);
168 stream_putl (s, ifp->hw_addr_len);
169 if (ifp->hw_addr_len)
170 stream_put (s, ifp->hw_addr, ifp->hw_addr_len);
171
172 /* Then, Traffic Engineering parameters if any */
173 if (HAS_LINK_PARAMS(ifp) && IS_LINK_PARAMS_SET(ifp->link_params))
174 {
175 stream_putc (s, 1);
176 zebra_interface_link_params_write (s, ifp);
177 }
178 else
179 stream_putc (s, 0);
180
181 /* Write packet size. */
182 stream_putw_at (s, 0, stream_get_endp (s));
183 }
184
185 static void
186 zserv_encode_vrf (struct stream *s, struct zebra_vrf *zvrf)
187 {
188 /* Interface information. */
189 stream_put (s, zvrf_name (zvrf), VRF_NAMSIZ);
190
191 /* Write packet size. */
192 stream_putw_at (s, 0, stream_get_endp (s));
193 }
194
195 /* Interface is added. Send ZEBRA_INTERFACE_ADD to client. */
196 /*
197 * This function is called in the following situations:
198 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
199 * from the client.
200 * - at startup, when zebra figures out the available interfaces
201 * - when an interface is added (where support for
202 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
203 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
204 * received)
205 */
206 int
207 zsend_interface_add (struct zserv *client, struct interface *ifp)
208 {
209 struct stream *s;
210
211 s = client->obuf;
212 stream_reset (s);
213
214 zserv_create_header (s, ZEBRA_INTERFACE_ADD, ifp->vrf_id);
215 zserv_encode_interface (s, ifp);
216
217 client->ifadd_cnt++;
218 return zebra_server_send_message(client);
219 }
220
221 /* Interface deletion from zebra daemon. */
222 int
223 zsend_interface_delete (struct zserv *client, struct interface *ifp)
224 {
225 struct stream *s;
226
227 s = client->obuf;
228 stream_reset (s);
229
230 zserv_create_header (s, ZEBRA_INTERFACE_DELETE, ifp->vrf_id);
231 zserv_encode_interface (s, ifp);
232
233 client->ifdel_cnt++;
234 return zebra_server_send_message (client);
235 }
236
237 int
238 zsend_vrf_add (struct zserv *client, struct zebra_vrf *zvrf)
239 {
240 struct stream *s;
241
242 s = client->obuf;
243 stream_reset (s);
244
245 zserv_create_header (s, ZEBRA_VRF_ADD, zvrf_id (zvrf));
246 zserv_encode_vrf (s, zvrf);
247
248 client->vrfadd_cnt++;
249 return zebra_server_send_message(client);
250 }
251
252 /* VRF deletion from zebra daemon. */
253 int
254 zsend_vrf_delete (struct zserv *client, struct zebra_vrf *zvrf)
255 {
256 struct stream *s;
257
258 s = client->obuf;
259 stream_reset (s);
260
261 zserv_create_header (s, ZEBRA_VRF_DELETE, zvrf_id (zvrf));
262 zserv_encode_vrf (s, zvrf);
263
264 client->vrfdel_cnt++;
265 return zebra_server_send_message (client);
266 }
267
268 int
269 zsend_interface_link_params (struct zserv *client, struct interface *ifp)
270 {
271 struct stream *s;
272
273 /* Check this client need interface information. */
274 if (! client->ifinfo)
275 return 0;
276
277 if (!ifp->link_params)
278 return 0;
279 s = client->obuf;
280 stream_reset (s);
281
282 zserv_create_header (s, ZEBRA_INTERFACE_LINK_PARAMS, ifp->vrf_id);
283
284 /* Add Interface Index */
285 stream_putl (s, ifp->ifindex);
286
287 /* Then TE Link Parameters */
288 if (zebra_interface_link_params_write (s, ifp) == 0)
289 return 0;
290
291 /* Write packet size. */
292 stream_putw_at (s, 0, stream_get_endp (s));
293
294 return zebra_server_send_message (client);
295 }
296
297 /* Interface address is added/deleted. Send ZEBRA_INTERFACE_ADDRESS_ADD or
298 * ZEBRA_INTERFACE_ADDRESS_DELETE to the client.
299 *
300 * A ZEBRA_INTERFACE_ADDRESS_ADD is sent in the following situations:
301 * - in response to a 3-byte ZEBRA_INTERFACE_ADD request
302 * from the client, after the ZEBRA_INTERFACE_ADD has been
303 * sent from zebra to the client
304 * - redistribute new address info to all clients in the following situations
305 * - at startup, when zebra figures out the available interfaces
306 * - when an interface is added (where support for
307 * RTM_IFANNOUNCE or AF_NETLINK sockets is available), or when
308 * an interface is marked IFF_UP (i.e., an RTM_IFINFO message is
309 * received)
310 * - for the vty commands "ip address A.B.C.D/M [<secondary>|<label LINE>]"
311 * and "no bandwidth <1-10000000>", "ipv6 address X:X::X:X/M"
312 * - when an RTM_NEWADDR message is received from the kernel,
313 *
314 * The call tree that triggers ZEBRA_INTERFACE_ADDRESS_DELETE:
315 *
316 * zsend_interface_address(DELETE)
317 * ^
318 * |
319 * zebra_interface_address_delete_update
320 * ^ ^ ^
321 * | | if_delete_update
322 * | |
323 * ip_address_uninstall connected_delete_ipv4
324 * [ipv6_addresss_uninstall] [connected_delete_ipv6]
325 * ^ ^
326 * | |
327 * | RTM_NEWADDR on routing/netlink socket
328 * |
329 * vty commands:
330 * "no ip address A.B.C.D/M [label LINE]"
331 * "no ip address A.B.C.D/M secondary"
332 * ["no ipv6 address X:X::X:X/M"]
333 *
334 */
335 int
336 zsend_interface_address (int cmd, struct zserv *client,
337 struct interface *ifp, struct connected *ifc)
338 {
339 int blen;
340 struct stream *s;
341 struct prefix *p;
342
343 s = client->obuf;
344 stream_reset (s);
345
346 zserv_create_header (s, cmd, ifp->vrf_id);
347 stream_putl (s, ifp->ifindex);
348
349 /* Interface address flag. */
350 stream_putc (s, ifc->flags);
351
352 /* Prefix information. */
353 p = ifc->address;
354 stream_putc (s, p->family);
355 blen = prefix_blen (p);
356 stream_put (s, &p->u.prefix, blen);
357
358 /*
359 * XXX gnu version does not send prefixlen for ZEBRA_INTERFACE_ADDRESS_DELETE
360 * but zebra_interface_address_delete_read() in the gnu version
361 * expects to find it
362 */
363 stream_putc (s, p->prefixlen);
364
365 /* Destination. */
366 p = ifc->destination;
367 if (p)
368 stream_put (s, &p->u.prefix, blen);
369 else
370 stream_put (s, NULL, blen);
371
372 /* Write packet size. */
373 stream_putw_at (s, 0, stream_get_endp (s));
374
375 client->connected_rt_add_cnt++;
376 return zebra_server_send_message(client);
377 }
378
379 static int
380 zsend_interface_nbr_address (int cmd, struct zserv *client,
381 struct interface *ifp, struct nbr_connected *ifc)
382 {
383 int blen;
384 struct stream *s;
385 struct prefix *p;
386
387 s = client->obuf;
388 stream_reset (s);
389
390 zserv_create_header (s, cmd, ifp->vrf_id);
391 stream_putl (s, ifp->ifindex);
392
393 /* Prefix information. */
394 p = ifc->address;
395 stream_putc (s, p->family);
396 blen = prefix_blen (p);
397 stream_put (s, &p->u.prefix, blen);
398
399 /*
400 * XXX gnu version does not send prefixlen for ZEBRA_INTERFACE_ADDRESS_DELETE
401 * but zebra_interface_address_delete_read() in the gnu version
402 * expects to find it
403 */
404 stream_putc (s, p->prefixlen);
405
406 /* Write packet size. */
407 stream_putw_at (s, 0, stream_get_endp (s));
408
409 return zebra_server_send_message(client);
410 }
411
412 /* Interface address addition. */
413 static void
414 zebra_interface_nbr_address_add_update (struct interface *ifp,
415 struct nbr_connected *ifc)
416 {
417 struct listnode *node, *nnode;
418 struct zserv *client;
419 struct prefix *p;
420
421 if (IS_ZEBRA_DEBUG_EVENT)
422 {
423 char buf[INET6_ADDRSTRLEN];
424
425 p = ifc->address;
426 zlog_debug ("MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_ADD %s/%d on %s",
427 inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),
428 p->prefixlen, ifc->ifp->name);
429 }
430
431 for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
432 zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD, client, ifp, ifc);
433 }
434
435 /* Interface address deletion. */
436 static void
437 zebra_interface_nbr_address_delete_update (struct interface *ifp,
438 struct nbr_connected *ifc)
439 {
440 struct listnode *node, *nnode;
441 struct zserv *client;
442 struct prefix *p;
443
444 if (IS_ZEBRA_DEBUG_EVENT)
445 {
446 char buf[INET6_ADDRSTRLEN];
447
448 p = ifc->address;
449 zlog_debug ("MESSAGE: ZEBRA_INTERFACE_NBR_ADDRESS_DELETE %s/%d on %s",
450 inet_ntop (p->family, &p->u.prefix, buf, INET6_ADDRSTRLEN),
451 p->prefixlen, ifc->ifp->name);
452 }
453
454 for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
455 zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_DELETE, client, ifp, ifc);
456 }
457
458 /* Send addresses on interface to client */
459 int
460 zsend_interface_addresses (struct zserv *client, struct interface *ifp)
461 {
462 struct listnode *cnode, *cnnode;
463 struct connected *c;
464 struct nbr_connected *nc;
465
466 /* Send interface addresses. */
467 for (ALL_LIST_ELEMENTS (ifp->connected, cnode, cnnode, c))
468 {
469 if (!CHECK_FLAG (c->conf, ZEBRA_IFC_REAL))
470 continue;
471
472 if (zsend_interface_address (ZEBRA_INTERFACE_ADDRESS_ADD, client,
473 ifp, c) < 0)
474 return -1;
475 }
476
477 /* Send interface neighbors. */
478 for (ALL_LIST_ELEMENTS (ifp->nbr_connected, cnode, cnnode, nc))
479 {
480 if (zsend_interface_nbr_address (ZEBRA_INTERFACE_NBR_ADDRESS_ADD,
481 client, ifp, nc) < 0)
482 return -1;
483 }
484
485 return 0;
486 }
487
488 /* Notify client about interface moving from one VRF to another.
489 * Whether client is interested in old and new VRF is checked by caller.
490 */
491 int
492 zsend_interface_vrf_update (struct zserv *client, struct interface *ifp,
493 vrf_id_t vrf_id)
494 {
495 struct stream *s;
496
497 s = client->obuf;
498 stream_reset (s);
499
500 zserv_create_header (s, ZEBRA_INTERFACE_VRF_UPDATE, ifp->vrf_id);
501
502 /* Fill in the ifIndex of the interface and its new VRF (id) */
503 stream_putl (s, ifp->ifindex);
504 stream_putw (s, vrf_id);
505
506 /* Write packet size. */
507 stream_putw_at (s, 0, stream_get_endp (s));
508
509 client->if_vrfchg_cnt++;
510 return zebra_server_send_message(client);
511 }
512
513 /* Add new nbr connected IPv6 address */
514 void
515 nbr_connected_add_ipv6 (struct interface *ifp, struct in6_addr *address)
516 {
517 struct nbr_connected *ifc;
518 struct prefix p;
519
520 p.family = AF_INET6;
521 IPV6_ADDR_COPY (&p.u.prefix, address);
522 p.prefixlen = IPV6_MAX_PREFIXLEN;
523
524 if (!(ifc = listnode_head(ifp->nbr_connected)))
525 {
526 /* new addition */
527 ifc = nbr_connected_new ();
528 ifc->address = prefix_new();
529 ifc->ifp = ifp;
530 listnode_add (ifp->nbr_connected, ifc);
531 }
532
533 prefix_copy(ifc->address, &p);
534
535 zebra_interface_nbr_address_add_update (ifp, ifc);
536
537 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, address, 1);
538 }
539
540 void
541 nbr_connected_delete_ipv6 (struct interface *ifp, struct in6_addr *address)
542 {
543 struct nbr_connected *ifc;
544 struct prefix p;
545
546 p.family = AF_INET6;
547 IPV6_ADDR_COPY (&p.u.prefix, address);
548 p.prefixlen = IPV6_MAX_PREFIXLEN;
549
550 ifc = nbr_connected_check(ifp, &p);
551 if (!ifc)
552 return;
553
554 listnode_delete (ifp->nbr_connected, ifc);
555
556 zebra_interface_nbr_address_delete_update (ifp, ifc);
557
558 if_nbr_ipv6ll_to_ipv4ll_neigh_update (ifp, address, 0);
559
560 nbr_connected_free (ifc);
561 }
562
563 /*
564 * The cmd passed to zsend_interface_update may be ZEBRA_INTERFACE_UP or
565 * ZEBRA_INTERFACE_DOWN.
566 *
567 * The ZEBRA_INTERFACE_UP message is sent from the zebra server to
568 * the clients in one of 2 situations:
569 * - an if_up is detected e.g., as a result of an RTM_IFINFO message
570 * - a vty command modifying the bandwidth of an interface is received.
571 * The ZEBRA_INTERFACE_DOWN message is sent when an if_down is detected.
572 */
573 int
574 zsend_interface_update (int cmd, struct zserv *client, struct interface *ifp)
575 {
576 struct stream *s;
577
578 s = client->obuf;
579 stream_reset (s);
580
581 zserv_create_header (s, cmd, ifp->vrf_id);
582 zserv_encode_interface (s, ifp);
583
584 if (cmd == ZEBRA_INTERFACE_UP)
585 client->ifup_cnt++;
586 else
587 client->ifdown_cnt++;
588
589 return zebra_server_send_message(client);
590 }
591
592 /*
593 * This is the new function to announce and withdraw redistributed routes, used
594 * by Zebra. This is the old zsend_route_multipath() function. That function
595 * was duplicating code to send a lot of information that was essentially thrown
596 * away or ignored by the receiver. This is the leaner function that is not a
597 * duplicate of the zapi_ipv4_route_add/del.
598 *
599 * The primary difference is that this function merely sends a single NH instead of
600 * all the nexthops.
601 */
602 int
603 zsend_redistribute_route (int add, struct zserv *client, struct prefix *p,
604 struct rib *rib)
605 {
606 afi_t afi;
607 int cmd;
608 int psize;
609 struct stream *s;
610 struct nexthop *nexthop;
611 unsigned long nhnummark = 0, messmark = 0;
612 int nhnum = 0;
613 u_char zapi_flags = 0;
614 struct nexthop dummy_nh;
615
616 afi = family2afi (p->family);
617 if (add)
618 {
619 switch (afi)
620 {
621 case AFI_IP:
622 cmd = ZEBRA_REDISTRIBUTE_IPV4_ADD;
623 client->redist_v4_add_cnt++;
624 break;
625 case AFI_IP6:
626 cmd = ZEBRA_REDISTRIBUTE_IPV6_ADD;
627 client->redist_v6_add_cnt++;
628 break;
629 default:
630 return -1;
631 }
632 }
633 else
634 {
635 switch (afi)
636 {
637 case AFI_IP:
638 cmd = ZEBRA_REDISTRIBUTE_IPV4_DEL;
639 client->redist_v4_del_cnt++;
640 break;
641 case AFI_IP6:
642 cmd = ZEBRA_REDISTRIBUTE_IPV6_DEL;
643 client->redist_v6_del_cnt++;
644 break;
645 default:
646 return -1;
647 }
648 }
649
650 s = client->obuf;
651 stream_reset (s);
652 memset(&dummy_nh, 0, sizeof(struct nexthop));
653
654 zserv_create_header (s, cmd, rib->vrf_id);
655
656 /* Put type and nexthop. */
657 stream_putc (s, rib->type);
658 stream_putw (s, rib->instance);
659 stream_putl (s, rib->flags);
660
661 /* marker for message flags field */
662 messmark = stream_get_endp (s);
663 stream_putc (s, 0);
664
665 /* Prefix. */
666 psize = PSIZE (p->prefixlen);
667 stream_putc (s, p->prefixlen);
668 stream_write (s, (u_char *) & p->u.prefix, psize);
669
670 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
671 {
672 /* We don't send any nexthops when there's a multipath */
673 if (rib->nexthop_active_num > 1 && client->proto != ZEBRA_ROUTE_LDP)
674 {
675 SET_FLAG (zapi_flags, ZAPI_MESSAGE_NEXTHOP);
676 SET_FLAG (zapi_flags, ZAPI_MESSAGE_IFINDEX);
677
678 stream_putc(s, 1);
679 if (p->family == AF_INET)
680 {
681 stream_put_in_addr (s, &dummy_nh.gate.ipv4);
682 }
683 else if (p->family == AF_INET6)
684 {
685 stream_write (s, (u_char *) &dummy_nh.gate.ipv6, 16);
686 }
687 else
688 {
689 /* We don't handle anything else now, abort */
690 zlog_err("%s: Unable to redistribute route of unknown family, %d\n",
691 __func__, p->family);
692 return -1;
693 }
694 stream_putc (s, 1);
695 stream_putl (s, 0); /* dummy ifindex */
696 break;
697 }
698
699 if (CHECK_FLAG(nexthop->flags, NEXTHOP_FLAG_ACTIVE))
700 {
701 SET_FLAG (zapi_flags, ZAPI_MESSAGE_NEXTHOP);
702 SET_FLAG (zapi_flags, ZAPI_MESSAGE_IFINDEX);
703 if (nhnummark == 0)
704 {
705 nhnummark = stream_get_endp (s);
706 stream_putc (s, 1); /* placeholder */
707 }
708 nhnum++;
709
710 switch(nexthop->type)
711 {
712 case NEXTHOP_TYPE_IPV4:
713 case NEXTHOP_TYPE_IPV4_IFINDEX:
714 stream_put_in_addr (s, &nexthop->gate.ipv4);
715 break;
716 case NEXTHOP_TYPE_IPV6:
717 case NEXTHOP_TYPE_IPV6_IFINDEX:
718 /* Only BGP supports IPv4 prefix with IPv6 NH, so kill this */
719 if (p->family == AF_INET)
720 stream_put_in_addr(s, &dummy_nh.gate.ipv4);
721 else
722 stream_write (s, (u_char *) &nexthop->gate.ipv6, 16);
723 break;
724 default:
725 if (cmd == ZEBRA_REDISTRIBUTE_IPV4_ADD
726 || cmd == ZEBRA_REDISTRIBUTE_IPV4_DEL)
727 {
728 struct in_addr empty;
729 memset (&empty, 0, sizeof (struct in_addr));
730 stream_write (s, (u_char *) &empty, IPV4_MAX_BYTELEN);
731 }
732 else
733 {
734 struct in6_addr empty;
735 memset (&empty, 0, sizeof (struct in6_addr));
736 stream_write (s, (u_char *) &empty, IPV6_MAX_BYTELEN);
737 }
738 }
739
740 /* Interface index. */
741 stream_putc (s, 1);
742 stream_putl (s, nexthop->ifindex);
743
744 /* ldpd needs all nexthops */
745 if (client->proto != ZEBRA_ROUTE_LDP)
746 break;
747 }
748 }
749
750 /* Distance */
751 SET_FLAG (zapi_flags, ZAPI_MESSAGE_DISTANCE);
752 stream_putc (s, rib->distance);
753
754 /* Metric */
755 SET_FLAG (zapi_flags, ZAPI_MESSAGE_METRIC);
756 stream_putl (s, rib->metric);
757
758 /* Tag */
759 if (rib->tag)
760 {
761 SET_FLAG(zapi_flags, ZAPI_MESSAGE_TAG);
762 stream_putl(s, rib->tag);
763 }
764
765 /* MTU */
766 SET_FLAG (zapi_flags, ZAPI_MESSAGE_MTU);
767 stream_putl (s, rib->mtu);
768
769 /* write real message flags value */
770 stream_putc_at (s, messmark, zapi_flags);
771
772 /* Write next-hop number */
773 if (nhnummark)
774 stream_putc_at (s, nhnummark, nhnum);
775
776 /* Write packet size. */
777 stream_putw_at (s, 0, stream_get_endp (s));
778
779 return zebra_server_send_message(client);
780 }
781
782 static int
783 zsend_write_nexthop (struct stream *s, struct nexthop *nexthop)
784 {
785 stream_putc (s, nexthop->type);
786 switch (nexthop->type)
787 {
788 case NEXTHOP_TYPE_IPV4:
789 case NEXTHOP_TYPE_IPV4_IFINDEX:
790 stream_put_in_addr (s, &nexthop->gate.ipv4);
791 stream_putl (s, nexthop->ifindex);
792 break;
793 case NEXTHOP_TYPE_IPV6:
794 stream_put (s, &nexthop->gate.ipv6, 16);
795 break;
796 case NEXTHOP_TYPE_IPV6_IFINDEX:
797 stream_put (s, &nexthop->gate.ipv6, 16);
798 stream_putl (s, nexthop->ifindex);
799 break;
800 case NEXTHOP_TYPE_IFINDEX:
801 stream_putl (s, nexthop->ifindex);
802 break;
803 default:
804 /* do nothing */
805 break;
806 }
807 return 1;
808 }
809
810 /* Nexthop register */
811 static int
812 zserv_rnh_register (struct zserv *client, int sock, u_short length,
813 rnh_type_t type, struct zebra_vrf *zvrf)
814 {
815 struct rnh *rnh;
816 struct stream *s;
817 struct prefix p;
818 u_short l = 0;
819 u_char flags = 0;
820
821 if (IS_ZEBRA_DEBUG_NHT)
822 zlog_debug("rnh_register msg from client %s: length=%d, type=%s\n",
823 zebra_route_string(client->proto), length,
824 (type == RNH_NEXTHOP_TYPE) ? "nexthop" : "route");
825
826 s = client->ibuf;
827
828 client->nh_reg_time = monotime(NULL);
829
830 while (l < length)
831 {
832 flags = stream_getc(s);
833 p.family = stream_getw(s);
834 p.prefixlen = stream_getc(s);
835 l += 4;
836 if (p.family == AF_INET)
837 {
838 p.u.prefix4.s_addr = stream_get_ipv4(s);
839 l += IPV4_MAX_BYTELEN;
840 }
841 else if (p.family == AF_INET6)
842 {
843 stream_get(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
844 l += IPV6_MAX_BYTELEN;
845 }
846 else
847 {
848 zlog_err("rnh_register: Received unknown family type %d\n",
849 p.family);
850 return -1;
851 }
852 rnh = zebra_add_rnh(&p, zvrf_id (zvrf), type);
853 if (type == RNH_NEXTHOP_TYPE)
854 {
855 if (flags && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
856 SET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
857 else if (!flags && CHECK_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED))
858 UNSET_FLAG(rnh->flags, ZEBRA_NHT_CONNECTED);
859 }
860 else if (type == RNH_IMPORT_CHECK_TYPE)
861 {
862 if (flags && !CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH))
863 SET_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH);
864 else if (!flags && CHECK_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH))
865 UNSET_FLAG(rnh->flags, ZEBRA_NHT_EXACT_MATCH);
866 }
867
868 zebra_add_rnh_client(rnh, client, type, zvrf_id (zvrf));
869 /* Anything not AF_INET/INET6 has been filtered out above */
870 zebra_evaluate_rnh(zvrf_id (zvrf), p.family, 1, type, &p);
871 }
872 return 0;
873 }
874
875 /* Nexthop register */
876 static int
877 zserv_rnh_unregister (struct zserv *client, int sock, u_short length,
878 rnh_type_t type, struct zebra_vrf *zvrf)
879 {
880 struct rnh *rnh;
881 struct stream *s;
882 struct prefix p;
883 u_short l = 0;
884
885 if (IS_ZEBRA_DEBUG_NHT)
886 zlog_debug("rnh_unregister msg from client %s: length=%d\n",
887 zebra_route_string(client->proto), length);
888
889 s = client->ibuf;
890
891 while (l < length)
892 {
893 (void)stream_getc(s); //Connected or not. Not used in this function
894 p.family = stream_getw(s);
895 p.prefixlen = stream_getc(s);
896 l += 4;
897 if (p.family == AF_INET)
898 {
899 p.u.prefix4.s_addr = stream_get_ipv4(s);
900 l += IPV4_MAX_BYTELEN;
901 }
902 else if (p.family == AF_INET6)
903 {
904 stream_get(&p.u.prefix6, s, IPV6_MAX_BYTELEN);
905 l += IPV6_MAX_BYTELEN;
906 }
907 else
908 {
909 zlog_err("rnh_register: Received unknown family type %d\n",
910 p.family);
911 return -1;
912 }
913 rnh = zebra_lookup_rnh(&p, zvrf_id (zvrf), type);
914 if (rnh)
915 {
916 client->nh_dereg_time = monotime(NULL);
917 zebra_remove_rnh_client(rnh, client, type);
918 }
919 }
920 return 0;
921 }
922
923 /*
924 Modified version of zsend_ipv4_nexthop_lookup():
925 Query unicast rib if nexthop is not found on mrib.
926 Returns both route metric and protocol distance.
927 */
928 static int
929 zsend_ipv4_nexthop_lookup_mrib (struct zserv *client, struct in_addr addr, struct rib *rib, struct zebra_vrf *zvrf)
930 {
931 struct stream *s;
932 unsigned long nump;
933 u_char num;
934 struct nexthop *nexthop;
935
936 /* Get output stream. */
937 s = client->obuf;
938 stream_reset (s);
939
940 /* Fill in result. */
941 zserv_create_header (s, ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB, zvrf_id (zvrf));
942 stream_put_in_addr (s, &addr);
943
944 if (rib)
945 {
946 stream_putc (s, rib->distance);
947 stream_putl (s, rib->metric);
948 num = 0;
949 nump = stream_get_endp(s); /* remember position for nexthop_num */
950 stream_putc (s, 0); /* reserve room for nexthop_num */
951 /* Only non-recursive routes are elegible to resolve the nexthop we
952 * are looking up. Therefore, we will just iterate over the top
953 * chain of nexthops. */
954 for (nexthop = rib->nexthop; nexthop; nexthop = nexthop->next)
955 if (CHECK_FLAG (nexthop->flags, NEXTHOP_FLAG_ACTIVE))
956 num += zsend_write_nexthop (s, nexthop);
957
958 stream_putc_at (s, nump, num); /* store nexthop_num */
959 }
960 else
961 {
962 stream_putc (s, 0); /* distance */
963 stream_putl (s, 0); /* metric */
964 stream_putc (s, 0); /* nexthop_num */
965 }
966
967 stream_putw_at (s, 0, stream_get_endp (s));
968
969 return zebra_server_send_message(client);
970 }
971
972 /* Router-id is updated. Send ZEBRA_ROUTER_ID_ADD to client. */
973 int
974 zsend_router_id_update (struct zserv *client, struct prefix *p,
975 vrf_id_t vrf_id)
976 {
977 struct stream *s;
978 int blen;
979
980 /* Check this client need interface information. */
981 if (! vrf_bitmap_check (client->ridinfo, vrf_id))
982 return 0;
983
984 s = client->obuf;
985 stream_reset (s);
986
987 /* Message type. */
988 zserv_create_header (s, ZEBRA_ROUTER_ID_UPDATE, vrf_id);
989
990 /* Prefix information. */
991 stream_putc (s, p->family);
992 blen = prefix_blen (p);
993 stream_put (s, &p->u.prefix, blen);
994 stream_putc (s, p->prefixlen);
995
996 /* Write packet size. */
997 stream_putw_at (s, 0, stream_get_endp (s));
998
999 return zebra_server_send_message(client);
1000 }
1001
1002 /* Register zebra server interface information. Send current all
1003 interface and address information. */
1004 static int
1005 zread_interface_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1006 {
1007 struct vrf *vrf;
1008 struct listnode *ifnode, *ifnnode;
1009 struct interface *ifp;
1010
1011 /* Interface information is needed. */
1012 vrf_bitmap_set (client->ifinfo, zvrf_id (zvrf));
1013
1014 RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id)
1015 {
1016 for (ALL_LIST_ELEMENTS (vrf->iflist, ifnode, ifnnode, ifp))
1017 {
1018 /* Skip pseudo interface. */
1019 if (! CHECK_FLAG (ifp->status, ZEBRA_INTERFACE_ACTIVE))
1020 continue;
1021
1022 if (zsend_interface_add (client, ifp) < 0)
1023 return -1;
1024
1025 if (zsend_interface_addresses (client, ifp) < 0)
1026 return -1;
1027 }
1028 }
1029 return 0;
1030 }
1031
1032 /* Unregister zebra server interface information. */
1033 static int
1034 zread_interface_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1035 {
1036 vrf_bitmap_unset (client->ifinfo, zvrf_id (zvrf));
1037 return 0;
1038 }
1039
1040 void
1041 zserv_nexthop_num_warn (const char *caller, const struct prefix *p, const unsigned int nexthop_num)
1042 {
1043 if (nexthop_num > MULTIPATH_NUM)
1044 {
1045 char buff[PREFIX2STR_BUFFER];
1046 prefix2str(p, buff, sizeof (buff));
1047 zlog_warn("%s: Prefix %s has %d nexthops, but we can only use the first %d",
1048 caller, buff, nexthop_num, MULTIPATH_NUM);
1049 }
1050 }
1051
1052 /* This function support multiple nexthop. */
1053 /*
1054 * Parse the ZEBRA_IPV4_ROUTE_ADD sent from client. Update rib and
1055 * add kernel route.
1056 */
1057 static int
1058 zread_ipv4_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1059 {
1060 int i;
1061 struct rib *rib;
1062 struct prefix p;
1063 u_char message;
1064 struct in_addr nexthop;
1065 u_char nexthop_num;
1066 u_char nexthop_type;
1067 struct stream *s;
1068 ifindex_t ifindex;
1069 safi_t safi;
1070 int ret;
1071
1072 /* Get input stream. */
1073 s = client->ibuf;
1074
1075 /* Allocate new rib. */
1076 rib = XCALLOC (MTYPE_RIB, sizeof (struct rib));
1077
1078 /* Type, flags, message. */
1079 rib->type = stream_getc (s);
1080 rib->instance = stream_getw (s);
1081 rib->flags = stream_getl (s);
1082 message = stream_getc (s);
1083 safi = stream_getw (s);
1084 rib->uptime = time (NULL);
1085
1086 /* IPv4 prefix. */
1087 memset (&p, 0, sizeof (struct prefix_ipv4));
1088 p.family = AF_INET;
1089 p.prefixlen = stream_getc (s);
1090 stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen));
1091
1092 /* VRF ID */
1093 rib->vrf_id = zvrf_id (zvrf);
1094
1095 /* Nexthop parse. */
1096 if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
1097 {
1098 nexthop_num = stream_getc (s);
1099 zserv_nexthop_num_warn(__func__, (const struct prefix *)&p, nexthop_num);
1100
1101 for (i = 0; i < nexthop_num; i++)
1102 {
1103 nexthop_type = stream_getc (s);
1104
1105 switch (nexthop_type)
1106 {
1107 case NEXTHOP_TYPE_IFINDEX:
1108 ifindex = stream_getl (s);
1109 rib_nexthop_ifindex_add (rib, ifindex);
1110 break;
1111 case NEXTHOP_TYPE_IPV4:
1112 nexthop.s_addr = stream_get_ipv4 (s);
1113 rib_nexthop_ipv4_add (rib, &nexthop, NULL);
1114 break;
1115 case NEXTHOP_TYPE_IPV4_IFINDEX:
1116 nexthop.s_addr = stream_get_ipv4 (s);
1117 ifindex = stream_getl (s);
1118 rib_nexthop_ipv4_ifindex_add (rib, &nexthop, NULL, ifindex);
1119 break;
1120 case NEXTHOP_TYPE_IPV6:
1121 stream_forward_getp (s, IPV6_MAX_BYTELEN);
1122 break;
1123 case NEXTHOP_TYPE_BLACKHOLE:
1124 rib_nexthop_blackhole_add (rib);
1125 break;
1126 }
1127 }
1128 }
1129
1130 /* Distance. */
1131 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
1132 rib->distance = stream_getc (s);
1133
1134 /* Metric. */
1135 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
1136 rib->metric = stream_getl (s);
1137
1138 /* Tag */
1139 if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
1140 rib->tag = stream_getl (s);
1141 else
1142 rib->tag = 0;
1143
1144 if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU))
1145 rib->mtu = stream_getl (s);
1146 else
1147 rib->mtu = 0;
1148
1149 /* Table */
1150 rib->table = zvrf->table_id;
1151
1152 ret = rib_add_multipath (AFI_IP, safi, &p, rib);
1153
1154 /* Stats */
1155 if (ret > 0)
1156 client->v4_route_add_cnt++;
1157 else if (ret < 0)
1158 client->v4_route_upd8_cnt++;
1159 return 0;
1160 }
1161
1162 /* Zebra server IPv4 prefix delete function. */
1163 static int
1164 zread_ipv4_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1165 {
1166 int i;
1167 struct stream *s;
1168 struct zapi_ipv4 api;
1169 struct in_addr nexthop;
1170 union g_addr *nexthop_p;
1171 unsigned long ifindex;
1172 struct prefix p;
1173 u_char nexthop_num;
1174 u_char nexthop_type;
1175 u_int32_t table_id;
1176
1177 s = client->ibuf;
1178 ifindex = 0;
1179 nexthop.s_addr = 0;
1180 nexthop_p = NULL;
1181
1182 /* Type, flags, message. */
1183 api.type = stream_getc (s);
1184 api.instance = stream_getw (s);
1185 api.flags = stream_getl (s);
1186 api.message = stream_getc (s);
1187 api.safi = stream_getw (s);
1188
1189 /* IPv4 prefix. */
1190 memset (&p, 0, sizeof (struct prefix_ipv4));
1191 p.family = AF_INET;
1192 p.prefixlen = stream_getc (s);
1193 stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen));
1194
1195 /* Nexthop, ifindex, distance, metric. */
1196 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
1197 {
1198 nexthop_num = stream_getc (s);
1199
1200 for (i = 0; i < nexthop_num; i++)
1201 {
1202 nexthop_type = stream_getc (s);
1203
1204 switch (nexthop_type)
1205 {
1206 case NEXTHOP_TYPE_IFINDEX:
1207 ifindex = stream_getl (s);
1208 break;
1209 case NEXTHOP_TYPE_IPV4:
1210 nexthop.s_addr = stream_get_ipv4 (s);
1211 nexthop_p = (union g_addr *)&nexthop;
1212 break;
1213 case NEXTHOP_TYPE_IPV4_IFINDEX:
1214 nexthop.s_addr = stream_get_ipv4 (s);
1215 nexthop_p = (union g_addr *)&nexthop;
1216 ifindex = stream_getl (s);
1217 break;
1218 case NEXTHOP_TYPE_IPV6:
1219 stream_forward_getp (s, IPV6_MAX_BYTELEN);
1220 break;
1221 }
1222 }
1223 }
1224
1225 /* Distance. */
1226 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
1227 api.distance = stream_getc (s);
1228 else
1229 api.distance = 0;
1230
1231 /* Metric. */
1232 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
1233 api.metric = stream_getl (s);
1234 else
1235 api.metric = 0;
1236
1237 /* tag */
1238 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
1239 api.tag = stream_getl (s);
1240 else
1241 api.tag = 0;
1242
1243 table_id = zvrf->table_id;
1244
1245 rib_delete (AFI_IP, api.safi, zvrf_id (zvrf), api.type, api.instance,
1246 api.flags, &p, nexthop_p, ifindex, table_id);
1247 client->v4_route_del_cnt++;
1248 return 0;
1249 }
1250
1251 /* MRIB Nexthop lookup for IPv4. */
1252 static int
1253 zread_ipv4_nexthop_lookup_mrib (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1254 {
1255 struct in_addr addr;
1256 struct rib *rib;
1257
1258 addr.s_addr = stream_get_ipv4 (client->ibuf);
1259 rib = rib_match_ipv4_multicast (zvrf_id (zvrf), addr, NULL);
1260 return zsend_ipv4_nexthop_lookup_mrib (client, addr, rib, zvrf);
1261 }
1262
1263 /* Zebra server IPv6 prefix add function. */
1264 static int
1265 zread_ipv4_route_ipv6_nexthop_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1266 {
1267 int i;
1268 struct stream *s;
1269 struct in6_addr nexthop;
1270 struct rib *rib;
1271 u_char message;
1272 u_char nexthop_num;
1273 u_char nexthop_type;
1274 struct prefix p;
1275 safi_t safi;
1276 static struct in6_addr nexthops[MULTIPATH_NUM];
1277 static unsigned int ifindices[MULTIPATH_NUM];
1278 int ret;
1279
1280 /* Get input stream. */
1281 s = client->ibuf;
1282
1283 memset (&nexthop, 0, sizeof (struct in6_addr));
1284
1285 /* Allocate new rib. */
1286 rib = XCALLOC (MTYPE_RIB, sizeof (struct rib));
1287
1288 /* Type, flags, message. */
1289 rib->type = stream_getc (s);
1290 rib->instance = stream_getw (s);
1291 rib->flags = stream_getl (s);
1292 message = stream_getc (s);
1293 safi = stream_getw (s);
1294 rib->uptime = time (NULL);
1295
1296 /* IPv4 prefix. */
1297 memset (&p, 0, sizeof (struct prefix_ipv4));
1298 p.family = AF_INET;
1299 p.prefixlen = stream_getc (s);
1300 stream_get (&p.u.prefix4, s, PSIZE (p.prefixlen));
1301
1302 /* VRF ID */
1303 rib->vrf_id = zvrf_id (zvrf);
1304
1305 /* We need to give nh-addr, nh-ifindex with the same next-hop object
1306 * to the rib to ensure that IPv6 multipathing works; need to coalesce
1307 * these. Clients should send the same number of paired set of
1308 * next-hop-addr/next-hop-ifindices. */
1309 if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
1310 {
1311 int nh_count = 0;
1312 int if_count = 0;
1313 int max_nh_if = 0;
1314
1315 nexthop_num = stream_getc (s);
1316 zserv_nexthop_num_warn(__func__, (const struct prefix *)&p, nexthop_num);
1317 for (i = 0; i < nexthop_num; i++)
1318 {
1319 nexthop_type = stream_getc (s);
1320
1321 switch (nexthop_type)
1322 {
1323 case NEXTHOP_TYPE_IPV6:
1324 stream_get (&nexthop, s, 16);
1325 if (nh_count < MULTIPATH_NUM) {
1326 nexthops[nh_count++] = nexthop;
1327 }
1328 break;
1329 case NEXTHOP_TYPE_IFINDEX:
1330 if (if_count < MULTIPATH_NUM) {
1331 ifindices[if_count++] = stream_getl (s);
1332 }
1333 break;
1334 case NEXTHOP_TYPE_BLACKHOLE:
1335 rib_nexthop_blackhole_add (rib);
1336 break;
1337 }
1338 }
1339
1340 max_nh_if = (nh_count > if_count) ? nh_count : if_count;
1341 for (i = 0; i < max_nh_if; i++)
1342 {
1343 if ((i < nh_count) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops[i])) {
1344 if ((i < if_count) && ifindices[i]) {
1345 rib_nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]);
1346 }
1347 else {
1348 rib_nexthop_ipv6_add (rib, &nexthops[i]);
1349 }
1350 }
1351 else {
1352 if ((i < if_count) && ifindices[i]) {
1353 rib_nexthop_ifindex_add (rib, ifindices[i]);
1354 }
1355 }
1356 }
1357 }
1358
1359 /* Distance. */
1360 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
1361 rib->distance = stream_getc (s);
1362
1363 /* Metric. */
1364 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
1365 rib->metric = stream_getl (s);
1366
1367 /* Tag */
1368 if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
1369 rib->tag = stream_getl (s);
1370 else
1371 rib->tag = 0;
1372
1373 if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU))
1374 rib->mtu = stream_getl (s);
1375 else
1376 rib->mtu = 0;
1377
1378 /* Table */
1379 rib->table = zvrf->table_id;
1380
1381 ret = rib_add_multipath (AFI_IP6, safi, &p, rib);
1382 /* Stats */
1383 if (ret > 0)
1384 client->v4_route_add_cnt++;
1385 else if (ret < 0)
1386 client->v4_route_upd8_cnt++;
1387
1388 return 0;
1389 }
1390
1391 static int
1392 zread_ipv6_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1393 {
1394 int i;
1395 struct stream *s;
1396 struct in6_addr nexthop;
1397 struct rib *rib;
1398 u_char message;
1399 u_char nexthop_num;
1400 u_char nexthop_type;
1401 struct prefix p;
1402 safi_t safi;
1403 static struct in6_addr nexthops[MULTIPATH_NUM];
1404 static unsigned int ifindices[MULTIPATH_NUM];
1405 int ret;
1406
1407 /* Get input stream. */
1408 s = client->ibuf;
1409
1410 memset (&nexthop, 0, sizeof (struct in6_addr));
1411
1412 /* Allocate new rib. */
1413 rib = XCALLOC (MTYPE_RIB, sizeof (struct rib));
1414
1415 /* Type, flags, message. */
1416 rib->type = stream_getc (s);
1417 rib->instance = stream_getw (s);
1418 rib->flags = stream_getl (s);
1419 message = stream_getc (s);
1420 safi = stream_getw (s);
1421 rib->uptime = time (NULL);
1422
1423 /* IPv6 prefix. */
1424 memset (&p, 0, sizeof (struct prefix_ipv6));
1425 p.family = AF_INET6;
1426 p.prefixlen = stream_getc (s);
1427 stream_get (&p.u.prefix6, s, PSIZE (p.prefixlen));
1428
1429 /* We need to give nh-addr, nh-ifindex with the same next-hop object
1430 * to the rib to ensure that IPv6 multipathing works; need to coalesce
1431 * these. Clients should send the same number of paired set of
1432 * next-hop-addr/next-hop-ifindices. */
1433 if (CHECK_FLAG (message, ZAPI_MESSAGE_NEXTHOP))
1434 {
1435 int nh_count = 0;
1436 int if_count = 0;
1437 int max_nh_if = 0;
1438
1439 nexthop_num = stream_getc (s);
1440 zserv_nexthop_num_warn(__func__, (const struct prefix *)&p, nexthop_num);
1441 for (i = 0; i < nexthop_num; i++)
1442 {
1443 nexthop_type = stream_getc (s);
1444
1445 switch (nexthop_type)
1446 {
1447 case NEXTHOP_TYPE_IPV6:
1448 stream_get (&nexthop, s, 16);
1449 if (nh_count < MULTIPATH_NUM) {
1450 nexthops[nh_count++] = nexthop;
1451 }
1452 break;
1453 case NEXTHOP_TYPE_IFINDEX:
1454 if (if_count < MULTIPATH_NUM) {
1455 ifindices[if_count++] = stream_getl (s);
1456 }
1457 break;
1458 case NEXTHOP_TYPE_BLACKHOLE:
1459 rib_nexthop_blackhole_add (rib);
1460 break;
1461 }
1462 }
1463
1464 max_nh_if = (nh_count > if_count) ? nh_count : if_count;
1465 for (i = 0; i < max_nh_if; i++)
1466 {
1467 if ((i < nh_count) && !IN6_IS_ADDR_UNSPECIFIED (&nexthops[i])) {
1468 if ((i < if_count) && ifindices[i])
1469 rib_nexthop_ipv6_ifindex_add (rib, &nexthops[i], ifindices[i]);
1470 else
1471 rib_nexthop_ipv6_add (rib, &nexthops[i]);
1472 }
1473 else {
1474 if ((i < if_count) && ifindices[i])
1475 rib_nexthop_ifindex_add (rib, ifindices[i]);
1476 }
1477 }
1478 }
1479
1480 /* Distance. */
1481 if (CHECK_FLAG (message, ZAPI_MESSAGE_DISTANCE))
1482 rib->distance = stream_getc (s);
1483
1484 /* Metric. */
1485 if (CHECK_FLAG (message, ZAPI_MESSAGE_METRIC))
1486 rib->metric = stream_getl (s);
1487
1488 /* Tag */
1489 if (CHECK_FLAG (message, ZAPI_MESSAGE_TAG))
1490 rib->tag = stream_getl (s);
1491 else
1492 rib->tag = 0;
1493
1494 if (CHECK_FLAG (message, ZAPI_MESSAGE_MTU))
1495 rib->mtu = stream_getl (s);
1496 else
1497 rib->mtu = 0;
1498
1499 /* VRF ID */
1500 rib->vrf_id = zvrf_id (zvrf);
1501 rib->table = zvrf->table_id;
1502
1503 ret = rib_add_multipath (AFI_IP6, safi, &p, rib);
1504 /* Stats */
1505 if (ret > 0)
1506 client->v6_route_add_cnt++;
1507 else if (ret < 0)
1508 client->v6_route_upd8_cnt++;
1509
1510 return 0;
1511 }
1512
1513 /* Zebra server IPv6 prefix delete function. */
1514 static int
1515 zread_ipv6_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1516 {
1517 int i;
1518 struct stream *s;
1519 struct zapi_ipv6 api;
1520 struct in6_addr nexthop;
1521 union g_addr *pnexthop = NULL;
1522 unsigned long ifindex;
1523 struct prefix p;
1524
1525 s = client->ibuf;
1526 ifindex = 0;
1527 memset (&nexthop, 0, sizeof (struct in6_addr));
1528
1529 /* Type, flags, message. */
1530 api.type = stream_getc (s);
1531 api.instance = stream_getw (s);
1532 api.flags = stream_getl (s);
1533 api.message = stream_getc (s);
1534 api.safi = stream_getw (s);
1535
1536 /* IPv4 prefix. */
1537 memset (&p, 0, sizeof (struct prefix_ipv6));
1538 p.family = AF_INET6;
1539 p.prefixlen = stream_getc (s);
1540 stream_get (&p.u.prefix6, s, PSIZE (p.prefixlen));
1541
1542 /* Nexthop, ifindex, distance, metric. */
1543 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_NEXTHOP))
1544 {
1545 u_char nexthop_type;
1546
1547 api.nexthop_num = stream_getc (s);
1548 for (i = 0; i < api.nexthop_num; i++)
1549 {
1550 nexthop_type = stream_getc (s);
1551
1552 switch (nexthop_type)
1553 {
1554 case NEXTHOP_TYPE_IPV6:
1555 stream_get (&nexthop, s, 16);
1556 pnexthop = (union g_addr *)&nexthop;
1557 break;
1558 case NEXTHOP_TYPE_IFINDEX:
1559 ifindex = stream_getl (s);
1560 break;
1561 }
1562 }
1563 }
1564
1565 /* Distance. */
1566 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_DISTANCE))
1567 api.distance = stream_getc (s);
1568 else
1569 api.distance = 0;
1570
1571 /* Metric. */
1572 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_METRIC))
1573 api.metric = stream_getl (s);
1574 else
1575 api.metric = 0;
1576
1577 /* tag */
1578 if (CHECK_FLAG (api.message, ZAPI_MESSAGE_TAG))
1579 api.tag = stream_getl (s);
1580 else
1581 api.tag = 0;
1582
1583 if (IN6_IS_ADDR_UNSPECIFIED (&nexthop))
1584 rib_delete (AFI_IP6, api.safi, zvrf_id (zvrf), api.type, api.instance,
1585 api.flags, &p, NULL, ifindex, client->rtm_table);
1586 else
1587 rib_delete (AFI_IP6, api.safi, zvrf_id (zvrf), api.type, api.instance,
1588 api.flags, &p, pnexthop, ifindex, client->rtm_table);
1589
1590 client->v6_route_del_cnt++;
1591 return 0;
1592 }
1593
1594 /* Register zebra server router-id information. Send current router-id */
1595 static int
1596 zread_router_id_add (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1597 {
1598 struct prefix p;
1599
1600 /* Router-id information is needed. */
1601 vrf_bitmap_set (client->ridinfo, zvrf_id (zvrf));
1602
1603 router_id_get (&p, zvrf_id (zvrf));
1604
1605 return zsend_router_id_update (client, &p, zvrf_id (zvrf));
1606 }
1607
1608 /* Unregister zebra server router-id information. */
1609 static int
1610 zread_router_id_delete (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1611 {
1612 vrf_bitmap_unset (client->ridinfo, zvrf_id (zvrf));
1613 return 0;
1614 }
1615
1616 /* Tie up route-type and client->sock */
1617 static void
1618 zread_hello (struct zserv *client)
1619 {
1620 /* type of protocol (lib/zebra.h) */
1621 u_char proto;
1622 u_short instance;
1623
1624 proto = stream_getc (client->ibuf);
1625 instance = stream_getw (client->ibuf);
1626
1627 /* accept only dynamic routing protocols */
1628 if ((proto < ZEBRA_ROUTE_MAX)
1629 && (proto > ZEBRA_ROUTE_STATIC))
1630 {
1631 zlog_notice ("client %d says hello and bids fair to announce only %s routes",
1632 client->sock, zebra_route_string(proto));
1633 if (instance)
1634 zlog_notice ("client protocol instance %d", instance);
1635
1636 client->proto = proto;
1637 client->instance = instance;
1638 }
1639 }
1640
1641 /* Unregister all information in a VRF. */
1642 static int
1643 zread_vrf_unregister (struct zserv *client, u_short length, struct zebra_vrf *zvrf)
1644 {
1645 int i;
1646 afi_t afi;
1647
1648 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1649 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1650 vrf_bitmap_unset (client->redist[afi][i], zvrf_id (zvrf));
1651 vrf_bitmap_unset (client->redist_default, zvrf_id (zvrf));
1652 vrf_bitmap_unset (client->ifinfo, zvrf_id (zvrf));
1653 vrf_bitmap_unset (client->ridinfo, zvrf_id (zvrf));
1654
1655 return 0;
1656 }
1657
1658 static void
1659 zread_mpls_labels (int command, struct zserv *client, u_short length,
1660 vrf_id_t vrf_id)
1661 {
1662 struct stream *s;
1663 enum lsp_types_t type;
1664 struct prefix prefix;
1665 enum nexthop_types_t gtype;
1666 union g_addr gate;
1667 ifindex_t ifindex;
1668 mpls_label_t in_label, out_label;
1669 u_int8_t distance;
1670 struct zebra_vrf *zvrf;
1671
1672 zvrf = vrf_info_lookup (vrf_id);
1673 if (!zvrf)
1674 return;
1675
1676 /* Get input stream. */
1677 s = client->ibuf;
1678
1679 /* Get data. */
1680 type = stream_getc (s);
1681 prefix.family = stream_getl (s);
1682 switch (prefix.family)
1683 {
1684 case AF_INET:
1685 prefix.u.prefix4.s_addr = stream_get_ipv4 (s);
1686 prefix.prefixlen = stream_getc (s);
1687 gate.ipv4.s_addr = stream_get_ipv4 (s);
1688 break;
1689 case AF_INET6:
1690 stream_get (&prefix.u.prefix6, s, 16);
1691 prefix.prefixlen = stream_getc (s);
1692 stream_get (&gate.ipv6, s, 16);
1693 break;
1694 default:
1695 return;
1696 }
1697 ifindex = stream_getl (s);
1698 distance = stream_getc (s);
1699 in_label = stream_getl (s);
1700 out_label = stream_getl (s);
1701
1702 switch (prefix.family)
1703 {
1704 case AF_INET:
1705 if (ifindex)
1706 gtype = NEXTHOP_TYPE_IPV4_IFINDEX;
1707 else
1708 gtype = NEXTHOP_TYPE_IPV4;
1709 break;
1710 case AF_INET6:
1711 if (ifindex)
1712 gtype = NEXTHOP_TYPE_IPV6_IFINDEX;
1713 else
1714 gtype = NEXTHOP_TYPE_IPV6;
1715 break;
1716 default:
1717 return;
1718 }
1719
1720 if (! mpls_enabled)
1721 return;
1722
1723 if (command == ZEBRA_MPLS_LABELS_ADD)
1724 {
1725 mpls_lsp_install (zvrf, type, in_label, out_label, gtype, &gate,
1726 NULL, ifindex);
1727 if (out_label != MPLS_IMP_NULL_LABEL)
1728 mpls_ftn_update (1, zvrf, type, &prefix, gtype, &gate, ifindex,
1729 distance, out_label);
1730 }
1731 else if (command == ZEBRA_MPLS_LABELS_DELETE)
1732 {
1733 mpls_lsp_uninstall (zvrf, type, in_label, gtype, &gate, NULL, ifindex);
1734 if (out_label != MPLS_IMP_NULL_LABEL)
1735 mpls_ftn_update (0, zvrf, type, &prefix, gtype, &gate, ifindex,
1736 distance, out_label);
1737 }
1738 }
1739
1740 /* Cleanup registered nexthops (across VRFs) upon client disconnect. */
1741 static void
1742 zebra_client_close_cleanup_rnh (struct zserv *client)
1743 {
1744 struct vrf *vrf;
1745 struct zebra_vrf *zvrf;
1746
1747 RB_FOREACH (vrf, vrf_id_head, &vrfs_by_id)
1748 {
1749 if ((zvrf = vrf->info) != NULL)
1750 {
1751 zebra_cleanup_rnh_client(zvrf_id (zvrf), AF_INET, client, RNH_NEXTHOP_TYPE);
1752 zebra_cleanup_rnh_client(zvrf_id (zvrf), AF_INET6, client, RNH_NEXTHOP_TYPE);
1753 zebra_cleanup_rnh_client(zvrf_id (zvrf), AF_INET, client, RNH_IMPORT_CHECK_TYPE);
1754 zebra_cleanup_rnh_client(zvrf_id (zvrf), AF_INET6, client, RNH_IMPORT_CHECK_TYPE);
1755 if (client->proto == ZEBRA_ROUTE_LDP)
1756 {
1757 hash_iterate(zvrf->lsp_table, mpls_ldp_lsp_uninstall_all,
1758 zvrf->lsp_table);
1759 mpls_ldp_ftn_uninstall_all (zvrf, AFI_IP);
1760 mpls_ldp_ftn_uninstall_all (zvrf, AFI_IP6);
1761 }
1762 }
1763 }
1764 }
1765
1766 /* Close zebra client. */
1767 static void
1768 zebra_client_close (struct zserv *client)
1769 {
1770 /* Send client de-registration to BFD */
1771 zebra_ptm_bfd_client_deregister(client->proto);
1772
1773 /* Cleanup any registered nexthops - across all VRFs. */
1774 zebra_client_close_cleanup_rnh (client);
1775
1776 /* Close file descriptor. */
1777 if (client->sock)
1778 {
1779 unsigned long nroutes;
1780
1781 close (client->sock);
1782 nroutes = rib_score_proto (client->proto, client->instance);
1783 zlog_notice ("client %d disconnected. %lu %s routes removed from the rib",
1784 client->sock, nroutes, zebra_route_string (client->proto));
1785 client->sock = -1;
1786 }
1787
1788 /* Free stream buffers. */
1789 if (client->ibuf)
1790 stream_free (client->ibuf);
1791 if (client->obuf)
1792 stream_free (client->obuf);
1793 if (client->wb)
1794 buffer_free(client->wb);
1795
1796 /* Release threads. */
1797 if (client->t_read)
1798 thread_cancel (client->t_read);
1799 if (client->t_write)
1800 thread_cancel (client->t_write);
1801 if (client->t_suicide)
1802 thread_cancel (client->t_suicide);
1803
1804 /* Free client structure. */
1805 listnode_delete (zebrad.client_list, client);
1806 XFREE (MTYPE_TMP, client);
1807 }
1808
1809 /* Make new client. */
1810 static void
1811 zebra_client_create (int sock)
1812 {
1813 struct zserv *client;
1814 int i;
1815 afi_t afi;
1816
1817 client = XCALLOC (MTYPE_TMP, sizeof (struct zserv));
1818
1819 /* Make client input/output buffer. */
1820 client->sock = sock;
1821 client->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
1822 client->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
1823 client->wb = buffer_new(0);
1824
1825 /* Set table number. */
1826 client->rtm_table = zebrad.rtm_table_default;
1827
1828 client->connect_time = monotime(NULL);
1829 /* Initialize flags */
1830 for (afi = AFI_IP; afi < AFI_MAX; afi++)
1831 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
1832 client->redist[afi][i] = vrf_bitmap_init ();
1833 client->redist_default = vrf_bitmap_init ();
1834 client->ifinfo = vrf_bitmap_init ();
1835 client->ridinfo = vrf_bitmap_init ();
1836
1837 /* Add this client to linked list. */
1838 listnode_add (zebrad.client_list, client);
1839
1840 /* Make new read thread. */
1841 zebra_event (ZEBRA_READ, sock, client);
1842
1843 zebra_vrf_update_all (client);
1844 }
1845
1846 /* Handler of zebra service request. */
1847 static int
1848 zebra_client_read (struct thread *thread)
1849 {
1850 int sock;
1851 struct zserv *client;
1852 size_t already;
1853 uint16_t length, command;
1854 uint8_t marker, version;
1855 vrf_id_t vrf_id;
1856 struct zebra_vrf *zvrf;
1857
1858 /* Get thread data. Reset reading thread because I'm running. */
1859 sock = THREAD_FD (thread);
1860 client = THREAD_ARG (thread);
1861 client->t_read = NULL;
1862
1863 if (client->t_suicide)
1864 {
1865 zebra_client_close(client);
1866 return -1;
1867 }
1868
1869 /* Read length and command (if we don't have it already). */
1870 if ((already = stream_get_endp(client->ibuf)) < ZEBRA_HEADER_SIZE)
1871 {
1872 ssize_t nbyte;
1873 if (((nbyte = stream_read_try (client->ibuf, sock,
1874 ZEBRA_HEADER_SIZE-already)) == 0) ||
1875 (nbyte == -1))
1876 {
1877 if (IS_ZEBRA_DEBUG_EVENT)
1878 zlog_debug ("connection closed socket [%d]", sock);
1879 zebra_client_close (client);
1880 return -1;
1881 }
1882 if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE-already))
1883 {
1884 /* Try again later. */
1885 zebra_event (ZEBRA_READ, sock, client);
1886 return 0;
1887 }
1888 already = ZEBRA_HEADER_SIZE;
1889 }
1890
1891 /* Reset to read from the beginning of the incoming packet. */
1892 stream_set_getp(client->ibuf, 0);
1893
1894 /* Fetch header values */
1895 length = stream_getw (client->ibuf);
1896 marker = stream_getc (client->ibuf);
1897 version = stream_getc (client->ibuf);
1898 vrf_id = stream_getw (client->ibuf);
1899 command = stream_getw (client->ibuf);
1900
1901 if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION)
1902 {
1903 zlog_err("%s: socket %d version mismatch, marker %d, version %d",
1904 __func__, sock, marker, version);
1905 zebra_client_close (client);
1906 return -1;
1907 }
1908 if (length < ZEBRA_HEADER_SIZE)
1909 {
1910 zlog_warn("%s: socket %d message length %u is less than header size %d",
1911 __func__, sock, length, ZEBRA_HEADER_SIZE);
1912 zebra_client_close (client);
1913 return -1;
1914 }
1915 if (length > STREAM_SIZE(client->ibuf))
1916 {
1917 zlog_warn("%s: socket %d message length %u exceeds buffer size %lu",
1918 __func__, sock, length, (u_long)STREAM_SIZE(client->ibuf));
1919 zebra_client_close (client);
1920 return -1;
1921 }
1922
1923 /* Read rest of data. */
1924 if (already < length)
1925 {
1926 ssize_t nbyte;
1927 if (((nbyte = stream_read_try (client->ibuf, sock,
1928 length-already)) == 0) ||
1929 (nbyte == -1))
1930 {
1931 if (IS_ZEBRA_DEBUG_EVENT)
1932 zlog_debug ("connection closed [%d] when reading zebra data", sock);
1933 zebra_client_close (client);
1934 return -1;
1935 }
1936 if (nbyte != (ssize_t)(length-already))
1937 {
1938 /* Try again later. */
1939 zebra_event (ZEBRA_READ, sock, client);
1940 return 0;
1941 }
1942 }
1943
1944 length -= ZEBRA_HEADER_SIZE;
1945
1946 /* Debug packet information. */
1947 if (IS_ZEBRA_DEBUG_EVENT)
1948 zlog_debug ("zebra message comes from socket [%d]", sock);
1949
1950 if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
1951 zlog_debug ("zebra message received [%s] %d in VRF %u",
1952 zserv_command_string (command), length, vrf_id);
1953
1954 client->last_read_time = monotime(NULL);
1955 client->last_read_cmd = command;
1956
1957 zvrf = zebra_vrf_lookup_by_id (vrf_id);
1958 if (!zvrf)
1959 {
1960 if (IS_ZEBRA_DEBUG_PACKET && IS_ZEBRA_DEBUG_RECV)
1961 zlog_debug ("zebra received unknown VRF[%u]", vrf_id);
1962 goto zclient_read_out;
1963 }
1964
1965 switch (command)
1966 {
1967 case ZEBRA_ROUTER_ID_ADD:
1968 zread_router_id_add (client, length, zvrf);
1969 break;
1970 case ZEBRA_ROUTER_ID_DELETE:
1971 zread_router_id_delete (client, length, zvrf);
1972 break;
1973 case ZEBRA_INTERFACE_ADD:
1974 zread_interface_add (client, length, zvrf);
1975 break;
1976 case ZEBRA_INTERFACE_DELETE:
1977 zread_interface_delete (client, length, zvrf);
1978 break;
1979 case ZEBRA_IPV4_ROUTE_ADD:
1980 zread_ipv4_add (client, length, zvrf);
1981 break;
1982 case ZEBRA_IPV4_ROUTE_DELETE:
1983 zread_ipv4_delete (client, length, zvrf);
1984 break;
1985 case ZEBRA_IPV4_ROUTE_IPV6_NEXTHOP_ADD:
1986 zread_ipv4_route_ipv6_nexthop_add (client, length, zvrf);
1987 break;
1988 case ZEBRA_IPV4_NEXTHOP_ADD:
1989 zread_ipv4_add(client, length, zvrf); /* LB: r1.0 merge - id was 1 */
1990 break;
1991 case ZEBRA_IPV4_NEXTHOP_DELETE:
1992 zread_ipv4_delete(client, length, zvrf); /* LB: r1.0 merge - id was 1 */
1993 break;
1994 case ZEBRA_IPV6_ROUTE_ADD:
1995 zread_ipv6_add (client, length, zvrf);
1996 break;
1997 case ZEBRA_IPV6_ROUTE_DELETE:
1998 zread_ipv6_delete (client, length, zvrf);
1999 break;
2000 case ZEBRA_REDISTRIBUTE_ADD:
2001 zebra_redistribute_add (command, client, length, zvrf);
2002 break;
2003 case ZEBRA_REDISTRIBUTE_DELETE:
2004 zebra_redistribute_delete (command, client, length, zvrf);
2005 break;
2006 case ZEBRA_REDISTRIBUTE_DEFAULT_ADD:
2007 zebra_redistribute_default_add (command, client, length, zvrf);
2008 break;
2009 case ZEBRA_REDISTRIBUTE_DEFAULT_DELETE:
2010 zebra_redistribute_default_delete (command, client, length, zvrf);
2011 break;
2012 case ZEBRA_IPV4_NEXTHOP_LOOKUP_MRIB:
2013 zread_ipv4_nexthop_lookup_mrib (client, length, zvrf);
2014 break;
2015 case ZEBRA_HELLO:
2016 zread_hello (client);
2017 break;
2018 case ZEBRA_NEXTHOP_REGISTER:
2019 zserv_rnh_register(client, sock, length, RNH_NEXTHOP_TYPE, zvrf);
2020 break;
2021 case ZEBRA_NEXTHOP_UNREGISTER:
2022 zserv_rnh_unregister(client, sock, length, RNH_NEXTHOP_TYPE, zvrf);
2023 break;
2024 case ZEBRA_IMPORT_ROUTE_REGISTER:
2025 zserv_rnh_register(client, sock, length, RNH_IMPORT_CHECK_TYPE, zvrf);
2026 break;
2027 case ZEBRA_IMPORT_ROUTE_UNREGISTER:
2028 zserv_rnh_unregister(client, sock, length, RNH_IMPORT_CHECK_TYPE, zvrf);
2029 break;
2030 case ZEBRA_BFD_DEST_UPDATE:
2031 case ZEBRA_BFD_DEST_REGISTER:
2032 zebra_ptm_bfd_dst_register(client, sock, length, command, zvrf);
2033 break;
2034 case ZEBRA_BFD_DEST_DEREGISTER:
2035 zebra_ptm_bfd_dst_deregister(client, sock, length, zvrf);
2036 break;
2037 case ZEBRA_VRF_UNREGISTER:
2038 zread_vrf_unregister (client, length, zvrf);
2039 break;
2040 case ZEBRA_BFD_CLIENT_REGISTER:
2041 zebra_ptm_bfd_client_register(client, sock, length);
2042 break;
2043 case ZEBRA_INTERFACE_ENABLE_RADV:
2044 zebra_interface_radv_set (client, sock, length, zvrf, 1);
2045 break;
2046 case ZEBRA_INTERFACE_DISABLE_RADV:
2047 zebra_interface_radv_set (client, sock, length, zvrf, 0);
2048 break;
2049 case ZEBRA_MPLS_LABELS_ADD:
2050 case ZEBRA_MPLS_LABELS_DELETE:
2051 zread_mpls_labels (command, client, length, vrf_id);
2052 break;
2053 case ZEBRA_IPMR_ROUTE_STATS:
2054 zebra_ipmr_route_stats (client, sock, length, zvrf);
2055 break;
2056 default:
2057 zlog_info ("Zebra received unknown command %d", command);
2058 break;
2059 }
2060
2061 if (client->t_suicide)
2062 {
2063 /* No need to wait for thread callback, just kill immediately. */
2064 zebra_client_close(client);
2065 return -1;
2066 }
2067
2068 zclient_read_out:
2069 stream_reset (client->ibuf);
2070 zebra_event (ZEBRA_READ, sock, client);
2071 return 0;
2072 }
2073
2074
2075 /* Accept code of zebra server socket. */
2076 static int
2077 zebra_accept (struct thread *thread)
2078 {
2079 int accept_sock;
2080 int client_sock;
2081 struct sockaddr_in client;
2082 socklen_t len;
2083
2084 accept_sock = THREAD_FD (thread);
2085
2086 /* Reregister myself. */
2087 zebra_event (ZEBRA_SERV, accept_sock, NULL);
2088
2089 len = sizeof (struct sockaddr_in);
2090 client_sock = accept (accept_sock, (struct sockaddr *) &client, &len);
2091
2092 if (client_sock < 0)
2093 {
2094 zlog_warn ("Can't accept zebra socket: %s", safe_strerror (errno));
2095 return -1;
2096 }
2097
2098 /* Make client socket non-blocking. */
2099 set_nonblocking(client_sock);
2100
2101 /* Create new zebra client. */
2102 zebra_client_create (client_sock);
2103
2104 return 0;
2105 }
2106
2107 #ifdef HAVE_TCP_ZEBRA
2108 /* Make zebra's server socket. */
2109 static void
2110 zebra_serv ()
2111 {
2112 int ret;
2113 int accept_sock;
2114 struct sockaddr_in addr;
2115
2116 accept_sock = socket (AF_INET, SOCK_STREAM, 0);
2117
2118 if (accept_sock < 0)
2119 {
2120 zlog_warn ("Can't create zserv stream socket: %s",
2121 safe_strerror (errno));
2122 zlog_warn ("zebra can't provice full functionality due to above error");
2123 return;
2124 }
2125
2126 memset (&addr, 0, sizeof (struct sockaddr_in));
2127 addr.sin_family = AF_INET;
2128 addr.sin_port = htons (ZEBRA_PORT);
2129 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
2130 addr.sin_len = sizeof (struct sockaddr_in);
2131 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
2132 addr.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
2133
2134 sockopt_reuseaddr (accept_sock);
2135 sockopt_reuseport (accept_sock);
2136
2137 if ( zserv_privs.change(ZPRIVS_RAISE) )
2138 zlog (NULL, LOG_ERR, "Can't raise privileges");
2139
2140 ret = bind (accept_sock, (struct sockaddr *)&addr,
2141 sizeof (struct sockaddr_in));
2142 if (ret < 0)
2143 {
2144 zlog_warn ("Can't bind to stream socket: %s",
2145 safe_strerror (errno));
2146 zlog_warn ("zebra can't provice full functionality due to above error");
2147 close (accept_sock); /* Avoid sd leak. */
2148 return;
2149 }
2150
2151 if ( zserv_privs.change(ZPRIVS_LOWER) )
2152 zlog (NULL, LOG_ERR, "Can't lower privileges");
2153
2154 ret = listen (accept_sock, 1);
2155 if (ret < 0)
2156 {
2157 zlog_warn ("Can't listen to stream socket: %s",
2158 safe_strerror (errno));
2159 zlog_warn ("zebra can't provice full functionality due to above error");
2160 close (accept_sock); /* Avoid sd leak. */
2161 return;
2162 }
2163
2164 zebra_event (ZEBRA_SERV, accept_sock, NULL);
2165 }
2166 #else /* HAVE_TCP_ZEBRA */
2167
2168 /* For sockaddr_un. */
2169 #include <sys/un.h>
2170
2171 /* zebra server UNIX domain socket. */
2172 static void
2173 zebra_serv_un (const char *path)
2174 {
2175 int ret;
2176 int sock, len;
2177 struct sockaddr_un serv;
2178 mode_t old_mask;
2179
2180 /* First of all, unlink existing socket */
2181 unlink (path);
2182
2183 /* Set umask */
2184 old_mask = umask (0077);
2185
2186 /* Make UNIX domain socket. */
2187 sock = socket (AF_UNIX, SOCK_STREAM, 0);
2188 if (sock < 0)
2189 {
2190 zlog_warn ("Can't create zserv unix socket: %s",
2191 safe_strerror (errno));
2192 zlog_warn ("zebra can't provide full functionality due to above error");
2193 return;
2194 }
2195
2196 /* Make server socket. */
2197 memset (&serv, 0, sizeof (struct sockaddr_un));
2198 serv.sun_family = AF_UNIX;
2199 strncpy (serv.sun_path, path, strlen (path));
2200 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
2201 len = serv.sun_len = SUN_LEN(&serv);
2202 #else
2203 len = sizeof (serv.sun_family) + strlen (serv.sun_path);
2204 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
2205
2206 ret = bind (sock, (struct sockaddr *) &serv, len);
2207 if (ret < 0)
2208 {
2209 zlog_warn ("Can't bind to unix socket %s: %s",
2210 path, safe_strerror (errno));
2211 zlog_warn ("zebra can't provide full functionality due to above error");
2212 close (sock);
2213 return;
2214 }
2215
2216 ret = listen (sock, 5);
2217 if (ret < 0)
2218 {
2219 zlog_warn ("Can't listen to unix socket %s: %s",
2220 path, safe_strerror (errno));
2221 zlog_warn ("zebra can't provide full functionality due to above error");
2222 close (sock);
2223 return;
2224 }
2225
2226 umask (old_mask);
2227
2228 zebra_event (ZEBRA_SERV, sock, NULL);
2229 }
2230 #endif /* HAVE_TCP_ZEBRA */
2231
2232
2233 static void
2234 zebra_event (enum event event, int sock, struct zserv *client)
2235 {
2236 switch (event)
2237 {
2238 case ZEBRA_SERV:
2239 thread_add_read (zebrad.master, zebra_accept, client, sock);
2240 break;
2241 case ZEBRA_READ:
2242 client->t_read =
2243 thread_add_read (zebrad.master, zebra_client_read, client, sock);
2244 break;
2245 case ZEBRA_WRITE:
2246 /**/
2247 break;
2248 }
2249 }
2250
2251 #define ZEBRA_TIME_BUF 32
2252 static char *
2253 zserv_time_buf(time_t *time1, char *buf, int buflen)
2254 {
2255 struct tm *tm;
2256 time_t now;
2257
2258 assert (buf != NULL);
2259 assert (buflen >= ZEBRA_TIME_BUF);
2260 assert (time1 != NULL);
2261
2262 if (!*time1)
2263 {
2264 snprintf(buf, buflen, "never ");
2265 return (buf);
2266 }
2267
2268 now = monotime(NULL);
2269 now -= *time1;
2270 tm = gmtime(&now);
2271
2272 /* Making formatted timer strings. */
2273 #define ONE_DAY_SECOND 60*60*24
2274 #define ONE_WEEK_SECOND 60*60*24*7
2275
2276 if (now < ONE_DAY_SECOND)
2277 snprintf (buf, buflen, "%02d:%02d:%02d",
2278 tm->tm_hour, tm->tm_min, tm->tm_sec);
2279 else if (now < ONE_WEEK_SECOND)
2280 snprintf (buf, buflen, "%dd%02dh%02dm",
2281 tm->tm_yday, tm->tm_hour, tm->tm_min);
2282 else
2283 snprintf (buf, buflen, "%02dw%dd%02dh",
2284 tm->tm_yday/7, tm->tm_yday - ((tm->tm_yday/7) * 7), tm->tm_hour);
2285 return buf;
2286 }
2287
2288 static void
2289 zebra_show_client_detail (struct vty *vty, struct zserv *client)
2290 {
2291 char cbuf[ZEBRA_TIME_BUF], rbuf[ZEBRA_TIME_BUF];
2292 char wbuf[ZEBRA_TIME_BUF], nhbuf[ZEBRA_TIME_BUF], mbuf[ZEBRA_TIME_BUF];
2293
2294 vty_out (vty, "Client: %s", zebra_route_string(client->proto));
2295 if (client->instance)
2296 vty_out (vty, " Instance: %d", client->instance);
2297 vty_out (vty, "%s", VTY_NEWLINE);
2298
2299 vty_out (vty, "------------------------ %s", VTY_NEWLINE);
2300 vty_out (vty, "FD: %d %s", client->sock, VTY_NEWLINE);
2301 vty_out (vty, "Route Table ID: %d %s", client->rtm_table, VTY_NEWLINE);
2302
2303 vty_out (vty, "Connect Time: %s %s",
2304 zserv_time_buf(&client->connect_time, cbuf, ZEBRA_TIME_BUF),
2305 VTY_NEWLINE);
2306 if (client->nh_reg_time)
2307 {
2308 vty_out (vty, "Nexthop Registry Time: %s %s",
2309 zserv_time_buf(&client->nh_reg_time, nhbuf, ZEBRA_TIME_BUF),
2310 VTY_NEWLINE);
2311 if (client->nh_last_upd_time)
2312 vty_out (vty, "Nexthop Last Update Time: %s %s",
2313 zserv_time_buf(&client->nh_last_upd_time, mbuf, ZEBRA_TIME_BUF),
2314 VTY_NEWLINE);
2315 else
2316 vty_out (vty, "No Nexthop Update sent%s", VTY_NEWLINE);
2317 }
2318 else
2319 vty_out (vty, "Not registered for Nexthop Updates%s", VTY_NEWLINE);
2320
2321 vty_out (vty, "Last Msg Rx Time: %s %s",
2322 zserv_time_buf(&client->last_read_time, rbuf, ZEBRA_TIME_BUF),
2323 VTY_NEWLINE);
2324 vty_out (vty, "Last Msg Tx Time: %s %s",
2325 zserv_time_buf(&client->last_write_time, wbuf, ZEBRA_TIME_BUF),
2326 VTY_NEWLINE);
2327 if (client->last_read_time)
2328 vty_out (vty, "Last Rcvd Cmd: %s %s",
2329 zserv_command_string(client->last_read_cmd), VTY_NEWLINE);
2330 if (client->last_write_time)
2331 vty_out (vty, "Last Sent Cmd: %s %s",
2332 zserv_command_string(client->last_write_cmd), VTY_NEWLINE);
2333 vty_out (vty, "%s", VTY_NEWLINE);
2334
2335 vty_out (vty, "Type Add Update Del %s", VTY_NEWLINE);
2336 vty_out (vty, "================================================== %s", VTY_NEWLINE);
2337 vty_out (vty, "IPv4 %-12d%-12d%-12d%s", client->v4_route_add_cnt,
2338 client->v4_route_upd8_cnt, client->v4_route_del_cnt, VTY_NEWLINE);
2339 vty_out (vty, "IPv6 %-12d%-12d%-12d%s", client->v6_route_add_cnt,
2340 client->v6_route_upd8_cnt, client->v6_route_del_cnt, VTY_NEWLINE);
2341 vty_out (vty, "Redist:v4 %-12d%-12d%-12d%s", client->redist_v4_add_cnt, 0,
2342 client->redist_v4_del_cnt, VTY_NEWLINE);
2343 vty_out (vty, "Redist:v6 %-12d%-12d%-12d%s", client->redist_v6_add_cnt, 0,
2344 client->redist_v6_del_cnt, VTY_NEWLINE);
2345 vty_out (vty, "Connected %-12d%-12d%-12d%s", client->ifadd_cnt, 0,
2346 client->ifdel_cnt, VTY_NEWLINE);
2347 vty_out (vty, "BFD peer %-12d%-12d%-12d%s", client->bfd_peer_add_cnt,
2348 client->bfd_peer_upd8_cnt, client->bfd_peer_del_cnt, VTY_NEWLINE);
2349 vty_out (vty, "Interface Up Notifications: %d%s", client->ifup_cnt,
2350 VTY_NEWLINE);
2351 vty_out (vty, "Interface Down Notifications: %d%s", client->ifdown_cnt,
2352 VTY_NEWLINE);
2353
2354 vty_out (vty, "%s", VTY_NEWLINE);
2355 return;
2356 }
2357
2358 static void
2359 zebra_show_client_brief (struct vty *vty, struct zserv *client)
2360 {
2361 char cbuf[ZEBRA_TIME_BUF], rbuf[ZEBRA_TIME_BUF];
2362 char wbuf[ZEBRA_TIME_BUF];
2363
2364 vty_out (vty, "%-8s%12s %12s%12s%8d/%-8d%8d/%-8d%s",
2365 zebra_route_string(client->proto),
2366 zserv_time_buf(&client->connect_time, cbuf, ZEBRA_TIME_BUF),
2367 zserv_time_buf(&client->last_read_time, rbuf, ZEBRA_TIME_BUF),
2368 zserv_time_buf(&client->last_write_time, wbuf, ZEBRA_TIME_BUF),
2369 client->v4_route_add_cnt+client->v4_route_upd8_cnt,
2370 client->v4_route_del_cnt,
2371 client->v6_route_add_cnt+client->v6_route_upd8_cnt,
2372 client->v6_route_del_cnt, VTY_NEWLINE);
2373
2374 }
2375
2376 struct zserv *
2377 zebra_find_client (u_char proto)
2378 {
2379 struct listnode *node, *nnode;
2380 struct zserv *client;
2381
2382 for (ALL_LIST_ELEMENTS (zebrad.client_list, node, nnode, client))
2383 {
2384 if (client->proto == proto)
2385 return client;
2386 }
2387
2388 return NULL;
2389 }
2390
2391 #ifdef HAVE_NETLINK
2392 /* Display default rtm_table for all clients. */
2393 DEFUN (show_table,
2394 show_table_cmd,
2395 "show table",
2396 SHOW_STR
2397 "default routing table to use for all clients\n")
2398 {
2399 vty_out (vty, "table %d%s", zebrad.rtm_table_default,
2400 VTY_NEWLINE);
2401 return CMD_SUCCESS;
2402 }
2403
2404 DEFUN (config_table,
2405 config_table_cmd,
2406 "table TABLENO",
2407 "Configure target kernel routing table\n"
2408 "TABLE integer\n")
2409 {
2410 zebrad.rtm_table_default = strtol (argv[1]->arg, (char**)0, 10);
2411 return CMD_SUCCESS;
2412 }
2413
2414 DEFUN (no_config_table,
2415 no_config_table_cmd,
2416 "no table [TABLENO]",
2417 NO_STR
2418 "Configure target kernel routing table\n"
2419 "TABLE integer\n")
2420 {
2421 zebrad.rtm_table_default = 0;
2422 return CMD_SUCCESS;
2423 }
2424 #endif
2425
2426 DEFUN (ip_forwarding,
2427 ip_forwarding_cmd,
2428 "ip forwarding",
2429 IP_STR
2430 "Turn on IP forwarding")
2431 {
2432 int ret;
2433
2434 ret = ipforward ();
2435 if (ret == 0)
2436 ret = ipforward_on ();
2437
2438 if (ret == 0)
2439 {
2440 vty_out (vty, "Can't turn on IP forwarding%s", VTY_NEWLINE);
2441 return CMD_WARNING;
2442 }
2443
2444 return CMD_SUCCESS;
2445 }
2446
2447 DEFUN (no_ip_forwarding,
2448 no_ip_forwarding_cmd,
2449 "no ip forwarding",
2450 NO_STR
2451 IP_STR
2452 "Turn off IP forwarding")
2453 {
2454 int ret;
2455
2456 ret = ipforward ();
2457 if (ret != 0)
2458 ret = ipforward_off ();
2459
2460 if (ret != 0)
2461 {
2462 vty_out (vty, "Can't turn off IP forwarding%s", VTY_NEWLINE);
2463 return CMD_WARNING;
2464 }
2465
2466 return CMD_SUCCESS;
2467 }
2468
2469 /* This command is for debugging purpose. */
2470 DEFUN (show_zebra_client,
2471 show_zebra_client_cmd,
2472 "show zebra client",
2473 SHOW_STR
2474 "Zebra information\n"
2475 "Client information")
2476 {
2477 struct listnode *node;
2478 struct zserv *client;
2479
2480 for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client))
2481 zebra_show_client_detail(vty, client);
2482
2483 return CMD_SUCCESS;
2484 }
2485
2486 /* This command is for debugging purpose. */
2487 DEFUN (show_zebra_client_summary,
2488 show_zebra_client_summary_cmd,
2489 "show zebra client summary",
2490 SHOW_STR
2491 "Zebra information brief"
2492 "Client information brief")
2493 {
2494 struct listnode *node;
2495 struct zserv *client;
2496
2497 vty_out (vty, "Name Connect Time Last Read Last Write IPv4 Routes IPv6 Routes %s",
2498 VTY_NEWLINE);
2499 vty_out (vty,"--------------------------------------------------------------------------------%s",
2500 VTY_NEWLINE);
2501
2502 for (ALL_LIST_ELEMENTS_RO (zebrad.client_list, node, client))
2503 zebra_show_client_brief(vty, client);
2504
2505 vty_out (vty, "Routes column shows (added+updated)/deleted%s", VTY_NEWLINE);
2506 return CMD_SUCCESS;
2507 }
2508
2509 /* Table configuration write function. */
2510 static int
2511 config_write_table (struct vty *vty)
2512 {
2513 if (zebrad.rtm_table_default)
2514 vty_out (vty, "table %d%s", zebrad.rtm_table_default,
2515 VTY_NEWLINE);
2516 return 0;
2517 }
2518
2519 /* table node for routing tables. */
2520 static struct cmd_node table_node =
2521 {
2522 TABLE_NODE,
2523 "", /* This node has no interface. */
2524 1
2525 };
2526
2527 /* Only display ip forwarding is enabled or not. */
2528 DEFUN (show_ip_forwarding,
2529 show_ip_forwarding_cmd,
2530 "show ip forwarding",
2531 SHOW_STR
2532 IP_STR
2533 "IP forwarding status\n")
2534 {
2535 int ret;
2536
2537 ret = ipforward ();
2538
2539 if (ret == 0)
2540 vty_out (vty, "IP forwarding is off%s", VTY_NEWLINE);
2541 else
2542 vty_out (vty, "IP forwarding is on%s", VTY_NEWLINE);
2543 return CMD_SUCCESS;
2544 }
2545
2546 /* Only display ipv6 forwarding is enabled or not. */
2547 DEFUN (show_ipv6_forwarding,
2548 show_ipv6_forwarding_cmd,
2549 "show ipv6 forwarding",
2550 SHOW_STR
2551 "IPv6 information\n"
2552 "Forwarding status\n")
2553 {
2554 int ret;
2555
2556 ret = ipforward_ipv6 ();
2557
2558 switch (ret)
2559 {
2560 case -1:
2561 vty_out (vty, "ipv6 forwarding is unknown%s", VTY_NEWLINE);
2562 break;
2563 case 0:
2564 vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE);
2565 break;
2566 case 1:
2567 vty_out (vty, "ipv6 forwarding is %s%s", "on", VTY_NEWLINE);
2568 break;
2569 default:
2570 vty_out (vty, "ipv6 forwarding is %s%s", "off", VTY_NEWLINE);
2571 break;
2572 }
2573 return CMD_SUCCESS;
2574 }
2575
2576 DEFUN (ipv6_forwarding,
2577 ipv6_forwarding_cmd,
2578 "ipv6 forwarding",
2579 IPV6_STR
2580 "Turn on IPv6 forwarding")
2581 {
2582 int ret;
2583
2584 ret = ipforward_ipv6 ();
2585 if (ret == 0)
2586 ret = ipforward_ipv6_on ();
2587
2588 if (ret == 0)
2589 {
2590 vty_out (vty, "Can't turn on IPv6 forwarding%s", VTY_NEWLINE);
2591 return CMD_WARNING;
2592 }
2593
2594 return CMD_SUCCESS;
2595 }
2596
2597 DEFUN (no_ipv6_forwarding,
2598 no_ipv6_forwarding_cmd,
2599 "no ipv6 forwarding",
2600 NO_STR
2601 IPV6_STR
2602 "Turn off IPv6 forwarding")
2603 {
2604 int ret;
2605
2606 ret = ipforward_ipv6 ();
2607 if (ret != 0)
2608 ret = ipforward_ipv6_off ();
2609
2610 if (ret != 0)
2611 {
2612 vty_out (vty, "Can't turn off IPv6 forwarding%s", VTY_NEWLINE);
2613 return CMD_WARNING;
2614 }
2615
2616 return CMD_SUCCESS;
2617 }
2618
2619 /* IPForwarding configuration write function. */
2620 static int
2621 config_write_forwarding (struct vty *vty)
2622 {
2623 /* FIXME: Find better place for that. */
2624 router_id_write (vty);
2625
2626 if (!ipforward ())
2627 vty_out (vty, "no ip forwarding%s", VTY_NEWLINE);
2628 if (!ipforward_ipv6 ())
2629 vty_out (vty, "no ipv6 forwarding%s", VTY_NEWLINE);
2630 vty_out (vty, "!%s", VTY_NEWLINE);
2631 return 0;
2632 }
2633
2634 /* table node for routing tables. */
2635 static struct cmd_node forwarding_node =
2636 {
2637 FORWARDING_NODE,
2638 "", /* This node has no interface. */
2639 1
2640 };
2641
2642 #ifdef HAVE_FPM
2643 /* function to write the fpm config info */
2644 static int
2645 config_write_fpm (struct vty *vty)
2646 {
2647 return
2648 fpm_remote_srv_write (vty);
2649 }
2650
2651 /* Zebra node */
2652 static struct cmd_node zebra_node =
2653 {
2654 ZEBRA_NODE,
2655 "",
2656 1
2657 };
2658 #endif
2659
2660
2661 /* Initialisation of zebra and installation of commands. */
2662 void
2663 zebra_init (void)
2664 {
2665 /* Client list init. */
2666 zebrad.client_list = list_new ();
2667
2668 /* Install configuration write function. */
2669 install_node (&table_node, config_write_table);
2670 install_node (&forwarding_node, config_write_forwarding);
2671 #ifdef HAVE_FPM
2672 install_node (&zebra_node, config_write_fpm);
2673 #endif
2674
2675 install_element (VIEW_NODE, &show_ip_forwarding_cmd);
2676 install_element (CONFIG_NODE, &ip_forwarding_cmd);
2677 install_element (CONFIG_NODE, &no_ip_forwarding_cmd);
2678 install_element (ENABLE_NODE, &show_zebra_client_cmd);
2679 install_element (ENABLE_NODE, &show_zebra_client_summary_cmd);
2680
2681 #ifdef HAVE_NETLINK
2682 install_element (VIEW_NODE, &show_table_cmd);
2683 install_element (CONFIG_NODE, &config_table_cmd);
2684 install_element (CONFIG_NODE, &no_config_table_cmd);
2685 #endif /* HAVE_NETLINK */
2686
2687 install_element (VIEW_NODE, &show_ipv6_forwarding_cmd);
2688 install_element (CONFIG_NODE, &ipv6_forwarding_cmd);
2689 install_element (CONFIG_NODE, &no_ipv6_forwarding_cmd);
2690
2691 /* Route-map */
2692 zebra_route_map_init ();
2693 }
2694
2695 /* Make zebra server socket, wiping any existing one (see bug #403). */
2696 void
2697 zebra_zserv_socket_init (char *path)
2698 {
2699 #ifdef HAVE_TCP_ZEBRA
2700 zebra_serv ();
2701 #else
2702 zebra_serv_un (path ? path : ZEBRA_SERV_PATH);
2703 #endif /* HAVE_TCP_ZEBRA */
2704 }