]> git.proxmox.com Git - mirror_frr.git/blob - lib/zclient.c
Support of BFD status in Quagga
[mirror_frr.git] / lib / zclient.c
1 /* Zebra's client library.
2 * Copyright (C) 1999 Kunihiro Ishiguro
3 * Copyright (C) 2005 Andrew J. Schorr
4 *
5 * This file is part of GNU Zebra.
6 *
7 * GNU Zebra is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published
9 * by the Free Software Foundation; either version 2, or (at your
10 * option) any later version.
11 *
12 * GNU Zebra is distributed in the hope that it will be useful, but
13 * WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with GNU Zebra; see the file COPYING. If not, write to the
19 * Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20 * MA 02111-1307, USA.
21 */
22
23 #include <zebra.h>
24
25 #include "prefix.h"
26 #include "stream.h"
27 #include "buffer.h"
28 #include "network.h"
29 #include "if.h"
30 #include "log.h"
31 #include "thread.h"
32 #include "zclient.h"
33 #include "memory.h"
34 #include "table.h"
35
36 /* Zebra client events. */
37 enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT};
38
39 /* Prototype for event manager. */
40 static void zclient_event (enum event, struct zclient *);
41
42 extern struct thread_master *master;
43
44 char *zclient_serv_path = NULL;
45
46 /* This file local debug flag. */
47 int zclient_debug = 0;
48
49 /* Allocate zclient structure. */
50 struct zclient *
51 zclient_new ()
52 {
53 struct zclient *zclient;
54 zclient = XCALLOC (MTYPE_ZCLIENT, sizeof (struct zclient));
55
56 zclient->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
57 zclient->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ);
58 zclient->wb = buffer_new(0);
59
60 return zclient;
61 }
62
63 /* This function is only called when exiting, because
64 many parts of the code do not check for I/O errors, so they could
65 reference an invalid pointer if the structure was ever freed.
66
67 Free zclient structure. */
68 void
69 zclient_free (struct zclient *zclient)
70 {
71 if (zclient->ibuf)
72 stream_free(zclient->ibuf);
73 if (zclient->obuf)
74 stream_free(zclient->obuf);
75 if (zclient->wb)
76 buffer_free(zclient->wb);
77
78 XFREE (MTYPE_ZCLIENT, zclient);
79 }
80
81 int
82 redist_check_instance (struct redist_proto *red, u_short instance)
83 {
84 struct listnode *node;
85 u_short *id;
86
87 if (!red->instances)
88 return 0;
89
90 for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
91 if (*id == instance)
92 return 1;
93
94 return 0;
95 }
96
97 void
98 redist_add_instance (struct redist_proto *red, u_short instance)
99 {
100 u_short *in;
101
102 red->enabled = 1;
103
104 if (!red->instances)
105 red->instances = list_new();
106
107 in = (u_short *)calloc(1, sizeof(u_short));
108 *in = instance;
109 listnode_add (red->instances, in);
110 }
111
112 void
113 redist_del_instance (struct redist_proto *red, u_short instance)
114 {
115 struct listnode *node;
116 u_short *id = NULL;
117
118 if (!red->instances)
119 return;
120
121 for (ALL_LIST_ELEMENTS_RO (red->instances, node, id))
122 if (*id == instance)
123 break;
124
125 if (id)
126 {
127 listnode_delete(red->instances, id);
128 if (!red->instances->count)
129 {
130 red->enabled = 0;
131 list_free(red->instances);
132 red->instances = NULL;
133 }
134 }
135 }
136
137 /* Stop zebra client services. */
138 void
139 zclient_stop (struct zclient *zclient)
140 {
141 if (zclient_debug)
142 zlog_debug ("zclient stopped");
143
144 /* Stop threads. */
145 THREAD_OFF(zclient->t_read);
146 THREAD_OFF(zclient->t_connect);
147 THREAD_OFF(zclient->t_write);
148
149 /* Reset streams. */
150 stream_reset(zclient->ibuf);
151 stream_reset(zclient->obuf);
152
153 /* Empty the write buffer. */
154 buffer_reset(zclient->wb);
155
156 /* Close socket. */
157 if (zclient->sock >= 0)
158 {
159 close (zclient->sock);
160 zclient->sock = -1;
161 }
162 zclient->fail = 0;
163 }
164
165 void
166 zclient_reset (struct zclient *zclient)
167 {
168 int afi;
169
170 zclient_stop (zclient);
171
172 for (afi = AFI_IP; afi < AFI_MAX; afi++)
173 redist_del_instance (&zclient->redist[afi][zclient->redist_default], zclient->instance);
174
175 zclient_init (zclient, zclient->redist_default, zclient->instance);
176 }
177
178 #ifdef HAVE_TCP_ZEBRA
179
180 /* Make socket to zebra daemon. Return zebra socket. */
181 static int
182 zclient_socket(void)
183 {
184 int sock;
185 int ret;
186 struct sockaddr_in serv;
187
188 /* We should think about IPv6 connection. */
189 sock = socket (AF_INET, SOCK_STREAM, 0);
190 if (sock < 0)
191 return -1;
192
193 /* Make server socket. */
194 memset (&serv, 0, sizeof (struct sockaddr_in));
195 serv.sin_family = AF_INET;
196 serv.sin_port = htons (ZEBRA_PORT);
197 #ifdef HAVE_STRUCT_SOCKADDR_IN_SIN_LEN
198 serv.sin_len = sizeof (struct sockaddr_in);
199 #endif /* HAVE_STRUCT_SOCKADDR_IN_SIN_LEN */
200 serv.sin_addr.s_addr = htonl (INADDR_LOOPBACK);
201
202 /* Connect to zebra. */
203 ret = connect (sock, (struct sockaddr *) &serv, sizeof (serv));
204 if (ret < 0)
205 {
206 close (sock);
207 return -1;
208 }
209 return sock;
210 }
211
212 #else
213
214 /* For sockaddr_un. */
215 #include <sys/un.h>
216
217 static int
218 zclient_socket_un (const char *path)
219 {
220 int ret;
221 int sock, len;
222 struct sockaddr_un addr;
223
224 sock = socket (AF_UNIX, SOCK_STREAM, 0);
225 if (sock < 0)
226 return -1;
227
228 /* Make server socket. */
229 memset (&addr, 0, sizeof (struct sockaddr_un));
230 addr.sun_family = AF_UNIX;
231 strncpy (addr.sun_path, path, strlen (path));
232 #ifdef HAVE_STRUCT_SOCKADDR_UN_SUN_LEN
233 len = addr.sun_len = SUN_LEN(&addr);
234 #else
235 len = sizeof (addr.sun_family) + strlen (addr.sun_path);
236 #endif /* HAVE_STRUCT_SOCKADDR_UN_SUN_LEN */
237
238 ret = connect (sock, (struct sockaddr *) &addr, len);
239 if (ret < 0)
240 {
241 close (sock);
242 return -1;
243 }
244 return sock;
245 }
246
247 #endif /* HAVE_TCP_ZEBRA */
248
249 /**
250 * Connect to zebra daemon.
251 * @param zclient a pointer to zclient structure
252 * @return socket fd just to make sure that connection established
253 * @see zclient_init
254 * @see zclient_new
255 */
256 int
257 zclient_socket_connect (struct zclient *zclient)
258 {
259 #ifdef HAVE_TCP_ZEBRA
260 zclient->sock = zclient_socket ();
261 #else
262 zclient->sock = zclient_socket_un (zclient_serv_path ? zclient_serv_path : ZEBRA_SERV_PATH);
263 #endif
264 return zclient->sock;
265 }
266
267 static int
268 zclient_failed(struct zclient *zclient)
269 {
270 zclient->fail++;
271 zclient_stop(zclient);
272 zclient_event(ZCLIENT_CONNECT, zclient);
273 return -1;
274 }
275
276 static int
277 zclient_flush_data(struct thread *thread)
278 {
279 struct zclient *zclient = THREAD_ARG(thread);
280
281 zclient->t_write = NULL;
282 if (zclient->sock < 0)
283 return -1;
284 switch (buffer_flush_available(zclient->wb, zclient->sock))
285 {
286 case BUFFER_ERROR:
287 zlog_warn("%s: buffer_flush_available failed on zclient fd %d, closing",
288 __func__, zclient->sock);
289 return zclient_failed(zclient);
290 break;
291 case BUFFER_PENDING:
292 zclient->t_write = thread_add_write(master, zclient_flush_data,
293 zclient, zclient->sock);
294 break;
295 case BUFFER_EMPTY:
296 break;
297 }
298 return 0;
299 }
300
301 int
302 zclient_send_message(struct zclient *zclient)
303 {
304 if (zclient->sock < 0)
305 return -1;
306 switch (buffer_write(zclient->wb, zclient->sock, STREAM_DATA(zclient->obuf),
307 stream_get_endp(zclient->obuf)))
308 {
309 case BUFFER_ERROR:
310 zlog_warn("%s: buffer_write failed to zclient fd %d, closing",
311 __func__, zclient->sock);
312 return zclient_failed(zclient);
313 break;
314 case BUFFER_EMPTY:
315 THREAD_OFF(zclient->t_write);
316 break;
317 case BUFFER_PENDING:
318 THREAD_WRITE_ON(master, zclient->t_write,
319 zclient_flush_data, zclient, zclient->sock);
320 break;
321 }
322 return 0;
323 }
324
325 void
326 zclient_create_header (struct stream *s, uint16_t command)
327 {
328 /* length placeholder, caller can update */
329 stream_putw (s, ZEBRA_HEADER_SIZE);
330 stream_putc (s, ZEBRA_HEADER_MARKER);
331 stream_putc (s, ZSERV_VERSION);
332 stream_putw (s, command);
333 }
334
335 /* Send simple Zebra message. */
336 static int
337 zebra_message_send (struct zclient *zclient, int command)
338 {
339 struct stream *s;
340
341 /* Get zclient output buffer. */
342 s = zclient->obuf;
343 stream_reset (s);
344
345 /* Send very simple command only Zebra message. */
346 zclient_create_header (s, command);
347
348 return zclient_send_message(zclient);
349 }
350
351 static int
352 zebra_hello_send (struct zclient *zclient)
353 {
354 struct stream *s;
355
356 if (zclient->redist_default)
357 {
358 s = zclient->obuf;
359 stream_reset (s);
360
361 zclient_create_header (s, ZEBRA_HELLO);
362 stream_putc (s, zclient->redist_default);
363 stream_putw (s, zclient->instance);
364 stream_putw_at (s, 0, stream_get_endp (s));
365 return zclient_send_message(zclient);
366 }
367
368 return 0;
369 }
370
371 /* Make connection to zebra daemon. */
372 int
373 zclient_start (struct zclient *zclient)
374 {
375 int i;
376 afi_t afi;
377
378 /* If already connected to the zebra. */
379 if (zclient->sock >= 0)
380 return 0;
381
382 /* Check connect thread. */
383 if (zclient->t_connect)
384 return 0;
385
386 /* Flush all redistribute request. */
387 for (afi = AFI_IP; afi < AFI_MAX; afi++)
388 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
389 if (zclient->redist[afi][i].enabled)
390 {
391 struct listnode *node;
392 u_short *id;
393
394 for (ALL_LIST_ELEMENTS_RO(zclient->redist[afi][i].instances, node, id))
395 if (!(i == zclient->redist_default && *id == zclient->instance))
396 zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient, afi, i, *id);
397 }
398
399 /* If default information is needed. */
400 if (zclient->default_information)
401 zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD);
402
403 return 0;
404 }
405
406 /* This function is a wrapper function for calling zclient_start from
407 timer or event thread. */
408 static int
409 zclient_connect (struct thread *t)
410 {
411 struct zclient *zclient;
412
413 zclient = THREAD_ARG (t);
414 zclient->t_connect = NULL;
415
416 if (zclient_debug)
417 zlog_debug ("zclient_connect is called");
418
419 return zclient_start (zclient);
420 }
421
422 /* Initialize zebra client. Argument redist_default is unwanted
423 redistribute route type. */
424 void
425 zclient_init (struct zclient *zclient, int redist_default, u_short instance)
426 {
427 int afi, i;
428
429 /* Enable zebra client connection by default. */
430 zclient->enable = 1;
431
432 /* Set -1 to the default socket value. */
433 zclient->sock = -1;
434
435 /* Clear redistribution flags. */
436 for (afi = AFI_IP; afi < AFI_MAX; afi++)
437 for (i = 0; i < ZEBRA_ROUTE_MAX; i++)
438 memset(&zclient->redist[afi][i], 0, sizeof(struct redist_proto));
439
440 /* Set unwanted redistribute route. bgpd does not need BGP route
441 redistribution. */
442 zclient->redist_default = redist_default;
443 zclient->instance = instance;
444 /* Pending: make afi(s) an arg. */
445 for (afi = AFI_IP; afi < AFI_MAX; afi++)
446 redist_add_instance (&zclient->redist[afi][redist_default], instance);
447
448 /* Set default-information redistribute to zero. */
449 zclient->default_information = 0;
450
451 if (zclient_debug)
452 zlog_debug ("zclient_start is called");
453
454 /* zclient is disabled. */
455 if (! zclient->enable)
456 return;
457
458 if (zclient_socket_connect(zclient) < 0)
459 {
460 if (zclient_debug)
461 zlog_debug ("zclient connection fail");
462 zclient->fail++;
463 zclient_event (ZCLIENT_CONNECT, zclient);
464 return;
465 }
466
467 if (set_nonblocking(zclient->sock) < 0)
468 zlog_warn("%s: set_nonblocking(%d) failed", __func__, zclient->sock);
469
470 /* Clear fail count. */
471 zclient->fail = 0;
472 if (zclient_debug)
473 zlog_debug ("zclient connect success with socket [%d]", zclient->sock);
474
475 /* Create read thread. */
476 zclient_event (ZCLIENT_READ, zclient);
477
478 zebra_hello_send (zclient);
479
480 /* We need router-id information. */
481 zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD);
482
483 /* We need interface information. */
484 zebra_message_send (zclient, ZEBRA_INTERFACE_ADD);
485
486 zclient_event (ZCLIENT_SCHEDULE, zclient);
487 }
488
489 /*
490 * "xdr_encode"-like interface that allows daemon (client) to send
491 * a message to zebra server for a route that needs to be
492 * added/deleted to the kernel. Info about the route is specified
493 * by the caller in a struct zapi_ipv4. zapi_ipv4_read() then writes
494 * the info down the zclient socket using the stream_* functions.
495 *
496 * The corresponding read ("xdr_decode") function on the server
497 * side is zread_ipv4_add()/zread_ipv4_delete().
498 *
499 * 0 1 2 3 4 5 6 7 8 9 A B C D E F 0 1 2 3 4 5 6 7 8 9 A B C D E F
500 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
501 * | Length (2) | Command | Route Type |
502 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
503 * | ZEBRA Flags | Message Flags | Prefix length |
504 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
505 * | Destination IPv4 Prefix for route |
506 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
507 * | Nexthop count |
508 * +-+-+-+-+-+-+-+-+
509 *
510 *
511 * A number of IPv4 nexthop(s) or nexthop interface index(es) are then
512 * described, as per the Nexthop count. Each nexthop described as:
513 *
514 * +-+-+-+-+-+-+-+-+
515 * | Nexthop Type | Set to one of ZEBRA_NEXTHOP_*
516 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
517 * | IPv4 Nexthop address or Interface Index number |
518 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
519 *
520 * Alternatively, if the flags field has ZEBRA_FLAG_BLACKHOLE or
521 * ZEBRA_FLAG_REJECT is set then Nexthop count is set to 1, then _no_
522 * nexthop information is provided, and the message describes a prefix
523 * to blackhole or reject route.
524 *
525 * The original struct zapi_ipv4, zapi_ipv4_route() and zread_ipv4_*()
526 * infrastructure was built around the traditional (32-bit "gate OR
527 * ifindex") nexthop data unit. A special encoding can be used to feed
528 * onlink (64-bit "gate AND ifindex") nexthops into zapi_ipv4_route()
529 * using the same zapi_ipv4 structure. This is done by setting zapi_ipv4
530 * fields as follows:
531 * - .message |= ZAPI_MESSAGE_NEXTHOP | ZAPI_MESSAGE_ONLINK
532 * - .nexthop_num == .ifindex_num
533 * - .nexthop and .ifindex are filled with gate and ifindex parts of
534 * each compound nexthop, both in the same order
535 *
536 * zapi_ipv4_route() will produce two nexthop data units for each such
537 * interleaved 64-bit nexthop. On the zserv side of the socket it will be
538 * mapped to a singlle NEXTHOP_TYPE_IPV4_IFINDEX_OL RIB nexthop structure.
539 *
540 * If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1
541 * byte value.
542 *
543 * If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8
544 * byte value.
545 *
546 * If ZAPI_MESSAGE_TAG is set, the tag value is written as a 2 byte value
547 *
548 * XXX: No attention paid to alignment.
549 */
550 int
551 zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p,
552 struct zapi_ipv4 *api)
553 {
554 int i;
555 int psize;
556 struct stream *s;
557
558 /* Reset stream. */
559 s = zclient->obuf;
560 stream_reset (s);
561
562 zclient_create_header (s, cmd);
563
564 /* Put type and nexthop. */
565 stream_putc (s, api->type);
566 stream_putw (s, api->instance);
567 stream_putc (s, api->flags);
568 stream_putc (s, api->message);
569 stream_putw (s, api->safi);
570
571 /* Put prefix information. */
572 psize = PSIZE (p->prefixlen);
573 stream_putc (s, p->prefixlen);
574 stream_write (s, (u_char *) & p->prefix, psize);
575
576 /* Nexthop, ifindex, distance and metric information. */
577 /* ZAPI_MESSAGE_ONLINK implies interleaving */
578 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_ONLINK))
579 {
580 /* ZAPI_MESSAGE_NEXTHOP is required for proper receiving */
581 assert (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP));
582 /* 64-bit data units, interleaved between nexthop[] and ifindex[] */
583 assert (api->nexthop_num == api->ifindex_num);
584 stream_putc (s, api->nexthop_num * 2);
585 for (i = 0; i < api->nexthop_num; i++)
586 {
587 stream_putc (s, ZEBRA_NEXTHOP_IPV4_ONLINK);
588 stream_put_in_addr (s, api->nexthop[i]);
589 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
590 stream_putl (s, api->ifindex[i]);
591 }
592 }
593 else if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
594 {
595 /* traditional 32-bit data units */
596 if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
597 {
598 stream_putc (s, 1);
599 stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
600 /* XXX assert(api->nexthop_num == 0); */
601 /* XXX assert(api->ifindex_num == 0); */
602 }
603 else
604 stream_putc (s, api->nexthop_num + api->ifindex_num);
605
606 for (i = 0; i < api->nexthop_num; i++)
607 {
608 stream_putc (s, ZEBRA_NEXTHOP_IPV4);
609 stream_put_in_addr (s, api->nexthop[i]);
610 }
611 for (i = 0; i < api->ifindex_num; i++)
612 {
613 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
614 stream_putl (s, api->ifindex[i]);
615 }
616 }
617
618 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
619 stream_putc (s, api->distance);
620 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC))
621 stream_putl (s, api->metric);
622 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
623 stream_putw (s, api->tag);
624
625 /* Put length at the first point of the stream. */
626 stream_putw_at (s, 0, stream_get_endp (s));
627
628 return zclient_send_message(zclient);
629 }
630
631 #ifdef HAVE_IPV6
632 int
633 zapi_ipv4_route_ipv6_nexthop (u_char cmd, struct zclient *zclient,
634 struct prefix_ipv4 *p, struct zapi_ipv6 *api)
635 {
636 int i;
637 int psize;
638 struct stream *s;
639
640 /* Reset stream. */
641 s = zclient->obuf;
642 stream_reset (s);
643
644 zclient_create_header (s, cmd);
645
646 /* Put type and nexthop. */
647 stream_putc (s, api->type);
648 stream_putw (s, api->instance);
649 stream_putc (s, api->flags);
650 stream_putc (s, api->message);
651 stream_putw (s, api->safi);
652
653 /* Put prefix information. */
654 psize = PSIZE (p->prefixlen);
655 stream_putc (s, p->prefixlen);
656 stream_write (s, (u_char *) & p->prefix, psize);
657
658 /* Nexthop, ifindex, distance and metric information. */
659 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
660 {
661 if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
662 {
663 stream_putc (s, 1);
664 stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
665 /* XXX assert(api->nexthop_num == 0); */
666 /* XXX assert(api->ifindex_num == 0); */
667 }
668 else
669 stream_putc (s, api->nexthop_num + api->ifindex_num);
670
671 for (i = 0; i < api->nexthop_num; i++)
672 {
673 stream_putc (s, ZEBRA_NEXTHOP_IPV6);
674 stream_write (s, (u_char *)api->nexthop[i], 16);
675 }
676 for (i = 0; i < api->ifindex_num; i++)
677 {
678 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
679 stream_putl (s, api->ifindex[i]);
680 }
681 }
682
683 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
684 stream_putc (s, api->distance);
685 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC))
686 stream_putl (s, api->metric);
687 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
688 stream_putw (s, api->tag);
689
690 /* Put length at the first point of the stream. */
691 stream_putw_at (s, 0, stream_get_endp (s));
692
693 return zclient_send_message(zclient);
694 }
695
696 int
697 zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p,
698 struct zapi_ipv6 *api)
699 {
700 int i;
701 int psize;
702 struct stream *s;
703
704 /* Reset stream. */
705 s = zclient->obuf;
706 stream_reset (s);
707
708 zclient_create_header (s, cmd);
709
710 /* Put type and nexthop. */
711 stream_putc (s, api->type);
712 stream_putw (s, api->instance);
713 stream_putc (s, api->flags);
714 stream_putc (s, api->message);
715 stream_putw (s, api->safi);
716
717 /* Put prefix information. */
718 psize = PSIZE (p->prefixlen);
719 stream_putc (s, p->prefixlen);
720 stream_write (s, (u_char *)&p->prefix, psize);
721
722 /* Nexthop, ifindex, distance and metric information. */
723 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP))
724 {
725 if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE))
726 {
727 stream_putc (s, 1);
728 stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE);
729 /* XXX assert(api->nexthop_num == 0); */
730 /* XXX assert(api->ifindex_num == 0); */
731 }
732 else
733 stream_putc (s, api->nexthop_num + api->ifindex_num);
734
735 for (i = 0; i < api->nexthop_num; i++)
736 {
737 stream_putc (s, ZEBRA_NEXTHOP_IPV6);
738 stream_write (s, (u_char *)api->nexthop[i], 16);
739 }
740 for (i = 0; i < api->ifindex_num; i++)
741 {
742 stream_putc (s, ZEBRA_NEXTHOP_IFINDEX);
743 stream_putl (s, api->ifindex[i]);
744 }
745 }
746
747 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE))
748 stream_putc (s, api->distance);
749 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC))
750 stream_putl (s, api->metric);
751 if (CHECK_FLAG (api->message, ZAPI_MESSAGE_TAG))
752 stream_putw (s, api->tag);
753
754 /* Put length at the first point of the stream. */
755 stream_putw_at (s, 0, stream_get_endp (s));
756
757 return zclient_send_message(zclient);
758 }
759 #endif /* HAVE_IPV6 */
760
761 /*
762 * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE
763 * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will
764 * then set/unset redist[type] in the client handle (a struct zserv) for the
765 * sending client
766 */
767 int
768 zebra_redistribute_send (int command, struct zclient *zclient, afi_t afi, int type,
769 u_short instance)
770 {
771 struct stream *s;
772
773 s = zclient->obuf;
774 stream_reset(s);
775
776 zclient_create_header (s, command);
777 stream_putc (s, afi);
778 stream_putc (s, type);
779 stream_putw (s, instance);
780
781 stream_putw_at (s, 0, stream_get_endp (s));
782
783 return zclient_send_message(zclient);
784 }
785
786 /* Router-id update from zebra daemon. */
787 void
788 zebra_router_id_update_read (struct stream *s, struct prefix *rid)
789 {
790 int plen;
791
792 /* Fetch interface address. */
793 rid->family = stream_getc (s);
794
795 plen = prefix_blen (rid);
796 stream_get (&rid->u.prefix, s, plen);
797 rid->prefixlen = stream_getc (s);
798 }
799
800 /* Interface addition from zebra daemon. */
801 /*
802 * The format of the message sent with type ZEBRA_INTERFACE_ADD or
803 * ZEBRA_INTERFACE_DELETE from zebra to the client is:
804 * 0 1 2 3
805 * 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1
806 * +-+-+-+-+-+-+-+-+
807 * | type |
808 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
809 * | ifname |
810 * | |
811 * | |
812 * | |
813 * | |
814 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
815 * | ifindex |
816 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
817 * | if_flags |
818 * | |
819 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
820 * | metric |
821 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
822 * | ifmtu |
823 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
824 * | ifmtu6 |
825 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
826 * | bandwidth |
827 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
828 * | sockaddr_dl |
829 * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+
830 */
831
832 struct interface *
833 zebra_interface_add_read (struct stream *s)
834 {
835 struct interface *ifp;
836 char ifname_tmp[INTERFACE_NAMSIZ];
837
838 /* Read interface name. */
839 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
840
841 /* Lookup/create interface by name. */
842 ifp = if_get_by_name_len (ifname_tmp, strnlen(ifname_tmp, INTERFACE_NAMSIZ));
843
844 zebra_interface_if_set_value (s, ifp);
845
846 return ifp;
847 }
848
849 /*
850 * Read interface up/down msg (ZEBRA_INTERFACE_UP/ZEBRA_INTERFACE_DOWN)
851 * from zebra server. The format of this message is the same as
852 * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE (see
853 * comments for zebra_interface_add_read), except that no sockaddr_dl
854 * is sent at the tail of the message.
855 */
856 struct interface *
857 zebra_interface_state_read (struct stream *s)
858 {
859 struct interface *ifp;
860 char ifname_tmp[INTERFACE_NAMSIZ];
861
862 /* Read interface name. */
863 stream_get (ifname_tmp, s, INTERFACE_NAMSIZ);
864
865 /* Lookup this by interface index. */
866 ifp = if_lookup_by_name_len (ifname_tmp,
867 strnlen(ifname_tmp, INTERFACE_NAMSIZ));
868
869 /* If such interface does not exist, indicate an error */
870 if (! ifp)
871 return NULL;
872
873 zebra_interface_if_set_value (s, ifp);
874
875 return ifp;
876 }
877
878 /*
879 * format of message for address additon is:
880 * 0
881 * 0 1 2 3 4 5 6 7
882 * +-+-+-+-+-+-+-+-+
883 * | type | ZEBRA_INTERFACE_ADDRESS_ADD or
884 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_ADDRES_DELETE
885 * | |
886 * + +
887 * | ifindex |
888 * + +
889 * | |
890 * + +
891 * | |
892 * +-+-+-+-+-+-+-+-+
893 * | ifc_flags | flags for connected address
894 * +-+-+-+-+-+-+-+-+
895 * | addr_family |
896 * +-+-+-+-+-+-+-+-+
897 * | addr... |
898 * : :
899 * | |
900 * +-+-+-+-+-+-+-+-+
901 * | addr_len | len of addr. E.g., addr_len = 4 for ipv4 addrs.
902 * +-+-+-+-+-+-+-+-+
903 * | daddr.. |
904 * : :
905 * | |
906 * +-+-+-+-+-+-+-+-+
907 *
908 */
909
910 void
911 zebra_interface_if_set_value (struct stream *s, struct interface *ifp)
912 {
913 /* Read interface's index. */
914 ifp->ifindex = stream_getl (s);
915 ifp->status = stream_getc (s);
916
917 /* Read interface's value. */
918 ifp->flags = stream_getq (s);
919 ifp->ptm_enable = stream_getc (s);
920 ifp->ptm_status = stream_getc (s);
921 ifp->metric = stream_getl (s);
922 ifp->mtu = stream_getl (s);
923 ifp->mtu6 = stream_getl (s);
924 ifp->bandwidth = stream_getl (s);
925 #ifdef HAVE_STRUCT_SOCKADDR_DL
926 stream_get (&ifp->sdl, s, sizeof (ifp->sdl_storage));
927 #else
928 ifp->hw_addr_len = stream_getl (s);
929 if (ifp->hw_addr_len)
930 stream_get (ifp->hw_addr, s, ifp->hw_addr_len);
931 #endif /* HAVE_STRUCT_SOCKADDR_DL */
932 }
933
934 static int
935 memconstant(const void *s, int c, size_t n)
936 {
937 const u_char *p = s;
938
939 while (n-- > 0)
940 if (*p++ != c)
941 return 0;
942 return 1;
943 }
944
945
946 struct connected *
947 zebra_interface_address_read (int type, struct stream *s)
948 {
949 unsigned int ifindex;
950 struct interface *ifp;
951 struct connected *ifc;
952 struct prefix p, d;
953 int family;
954 int plen;
955 u_char ifc_flags;
956
957 memset (&p, 0, sizeof(p));
958 memset (&d, 0, sizeof(d));
959
960 /* Get interface index. */
961 ifindex = stream_getl (s);
962
963 /* Lookup index. */
964 ifp = if_lookup_by_index (ifindex);
965 if (ifp == NULL)
966 {
967 zlog_warn ("zebra_interface_address_read(%s): "
968 "Can't find interface by ifindex: %d ",
969 (type == ZEBRA_INTERFACE_ADDRESS_ADD? "ADD" : "DELETE"),
970 ifindex);
971 return NULL;
972 }
973
974 /* Fetch flag. */
975 ifc_flags = stream_getc (s);
976
977 /* Fetch interface address. */
978 family = p.family = stream_getc (s);
979
980 plen = prefix_blen (&p);
981 stream_get (&p.u.prefix, s, plen);
982 p.prefixlen = stream_getc (s);
983
984 /* Fetch destination address. */
985 stream_get (&d.u.prefix, s, plen);
986 d.family = family;
987
988 if (type == ZEBRA_INTERFACE_ADDRESS_ADD)
989 {
990 /* N.B. NULL destination pointers are encoded as all zeroes */
991 ifc = connected_add_by_prefix(ifp, &p,(memconstant(&d.u.prefix,0,plen) ?
992 NULL : &d));
993 if (ifc != NULL)
994 {
995 ifc->flags = ifc_flags;
996 if (ifc->destination)
997 ifc->destination->prefixlen = ifc->address->prefixlen;
998 else if (CHECK_FLAG(ifc->flags, ZEBRA_IFA_PEER))
999 {
1000 /* carp interfaces on OpenBSD with 0.0.0.0/0 as "peer" */
1001 char buf[BUFSIZ];
1002 prefix2str (ifc->address, buf, sizeof(buf));
1003 zlog_warn("warning: interface %s address %s "
1004 "with peer flag set, but no peer address!",
1005 ifp->name, buf);
1006 UNSET_FLAG(ifc->flags, ZEBRA_IFA_PEER);
1007 }
1008 }
1009 }
1010 else
1011 {
1012 assert (type == ZEBRA_INTERFACE_ADDRESS_DELETE);
1013 ifc = connected_delete_by_prefix(ifp, &p);
1014 }
1015
1016 return ifc;
1017 }
1018
1019 /*
1020 * format of message for neighbor connected address is:
1021 * 0
1022 * 0 1 2 3 4 5 6 7
1023 * +-+-+-+-+-+-+-+-+
1024 * | type | ZEBRA_INTERFACE_NBR_ADDRESS_ADD or
1025 * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_NBR_ADDRES_DELETE
1026 * | |
1027 * + +
1028 * | ifindex |
1029 * + +
1030 * | |
1031 * + +
1032 * | |
1033 * +-+-+-+-+-+-+-+-+
1034 * | addr_family |
1035 * +-+-+-+-+-+-+-+-+
1036 * | addr... |
1037 * : :
1038 * | |
1039 * +-+-+-+-+-+-+-+-+
1040 * | addr_len | len of addr.
1041 * +-+-+-+-+-+-+-+-+
1042 */
1043 struct nbr_connected *
1044 zebra_interface_nbr_address_read (int type, struct stream *s)
1045 {
1046 unsigned int ifindex;
1047 struct interface *ifp;
1048 struct prefix p;
1049 struct nbr_connected *ifc;
1050
1051 /* Get interface index. */
1052 ifindex = stream_getl (s);
1053
1054 /* Lookup index. */
1055 ifp = if_lookup_by_index (ifindex);
1056 if (ifp == NULL)
1057 {
1058 zlog_warn ("zebra_nbr_interface_address_read(%s): "
1059 "Can't find interface by ifindex: %d ",
1060 (type == ZEBRA_INTERFACE_NBR_ADDRESS_ADD? "ADD" : "DELETE"),
1061 ifindex);
1062 return NULL;
1063 }
1064
1065 p.family = stream_getc (s);
1066 stream_get (&p.u.prefix, s, prefix_blen (&p));
1067 p.prefixlen = stream_getc (s);
1068
1069 if (type == ZEBRA_INTERFACE_NBR_ADDRESS_ADD)
1070 {
1071 /* Currently only supporting P2P links, so any new RA source address is
1072 considered as the replacement of the previously learnt Link-Local address. */
1073 if (!(ifc = listnode_head(ifp->nbr_connected)))
1074 {
1075 ifc = nbr_connected_new ();
1076 ifc->address = prefix_new ();
1077 ifc->ifp = ifp;
1078 listnode_add (ifp->nbr_connected, ifc);
1079 }
1080
1081 prefix_copy(ifc->address, &p);
1082 }
1083 else
1084 {
1085 assert (type == ZEBRA_INTERFACE_NBR_ADDRESS_DELETE);
1086
1087 ifc = nbr_connected_check(ifp, &p);
1088 if (ifc)
1089 listnode_delete (ifp->nbr_connected, ifc);
1090 }
1091
1092 return ifc;
1093 }
1094
1095 /* Zebra client message read function. */
1096 static int
1097 zclient_read (struct thread *thread)
1098 {
1099 size_t already;
1100 uint16_t length, command;
1101 uint8_t marker, version;
1102 struct zclient *zclient;
1103
1104 /* Get socket to zebra. */
1105 zclient = THREAD_ARG (thread);
1106 zclient->t_read = NULL;
1107
1108 /* Read zebra header (if we don't have it already). */
1109 if ((already = stream_get_endp(zclient->ibuf)) < ZEBRA_HEADER_SIZE)
1110 {
1111 ssize_t nbyte;
1112 if (((nbyte = stream_read_try(zclient->ibuf, zclient->sock,
1113 ZEBRA_HEADER_SIZE-already)) == 0) ||
1114 (nbyte == -1))
1115 {
1116 if (zclient_debug)
1117 zlog_debug ("zclient connection closed socket [%d].", zclient->sock);
1118 return zclient_failed(zclient);
1119 }
1120 if (nbyte != (ssize_t)(ZEBRA_HEADER_SIZE-already))
1121 {
1122 /* Try again later. */
1123 zclient_event (ZCLIENT_READ, zclient);
1124 return 0;
1125 }
1126 already = ZEBRA_HEADER_SIZE;
1127 }
1128
1129 /* Reset to read from the beginning of the incoming packet. */
1130 stream_set_getp(zclient->ibuf, 0);
1131
1132 /* Fetch header values. */
1133 length = stream_getw (zclient->ibuf);
1134 marker = stream_getc (zclient->ibuf);
1135 version = stream_getc (zclient->ibuf);
1136 command = stream_getw (zclient->ibuf);
1137
1138 if (marker != ZEBRA_HEADER_MARKER || version != ZSERV_VERSION)
1139 {
1140 zlog_err("%s: socket %d version mismatch, marker %d, version %d",
1141 __func__, zclient->sock, marker, version);
1142 return zclient_failed(zclient);
1143 }
1144
1145 if (length < ZEBRA_HEADER_SIZE)
1146 {
1147 zlog_err("%s: socket %d message length %u is less than %d ",
1148 __func__, zclient->sock, length, ZEBRA_HEADER_SIZE);
1149 return zclient_failed(zclient);
1150 }
1151
1152 /* Length check. */
1153 if (length > STREAM_SIZE(zclient->ibuf))
1154 {
1155 struct stream *ns;
1156 zlog_warn("%s: message size %u exceeds buffer size %lu, expanding...",
1157 __func__, length, (u_long)STREAM_SIZE(zclient->ibuf));
1158 ns = stream_new(length);
1159 stream_copy(ns, zclient->ibuf);
1160 stream_free (zclient->ibuf);
1161 zclient->ibuf = ns;
1162 }
1163
1164 /* Read rest of zebra packet. */
1165 if (already < length)
1166 {
1167 ssize_t nbyte;
1168 if (((nbyte = stream_read_try(zclient->ibuf, zclient->sock,
1169 length-already)) == 0) ||
1170 (nbyte == -1))
1171 {
1172 if (zclient_debug)
1173 zlog_debug("zclient connection closed socket [%d].", zclient->sock);
1174 return zclient_failed(zclient);
1175 }
1176 if (nbyte != (ssize_t)(length-already))
1177 {
1178 /* Try again later. */
1179 zclient_event (ZCLIENT_READ, zclient);
1180 return 0;
1181 }
1182 }
1183
1184 length -= ZEBRA_HEADER_SIZE;
1185
1186 if (zclient_debug)
1187 zlog_debug("zclient 0x%p command 0x%x \n", zclient, command);
1188
1189 switch (command)
1190 {
1191 case ZEBRA_ROUTER_ID_UPDATE:
1192 if (zclient->router_id_update)
1193 (*zclient->router_id_update) (command, zclient, length);
1194 break;
1195 case ZEBRA_INTERFACE_ADD:
1196 if (zclient->interface_add)
1197 (*zclient->interface_add) (command, zclient, length);
1198 break;
1199 case ZEBRA_INTERFACE_DELETE:
1200 if (zclient->interface_delete)
1201 (*zclient->interface_delete) (command, zclient, length);
1202 break;
1203 case ZEBRA_INTERFACE_ADDRESS_ADD:
1204 if (zclient->interface_address_add)
1205 (*zclient->interface_address_add) (command, zclient, length);
1206 break;
1207 case ZEBRA_INTERFACE_ADDRESS_DELETE:
1208 if (zclient->interface_address_delete)
1209 (*zclient->interface_address_delete) (command, zclient, length);
1210 break;
1211 case ZEBRA_INTERFACE_BFD_DEST_UPDATE:
1212 if (zclient->interface_bfd_dest_update)
1213 (*zclient->interface_bfd_dest_update) (command, zclient, length);
1214 break;
1215 case ZEBRA_INTERFACE_NBR_ADDRESS_ADD:
1216 if (zclient->interface_nbr_address_add)
1217 (*zclient->interface_nbr_address_add) (command, zclient, length);
1218 break;
1219 case ZEBRA_INTERFACE_NBR_ADDRESS_DELETE:
1220 if (zclient->interface_nbr_address_delete)
1221 (*zclient->interface_nbr_address_delete) (command, zclient, length);
1222 break;
1223 case ZEBRA_INTERFACE_UP:
1224 if (zclient->interface_up)
1225 (*zclient->interface_up) (command, zclient, length);
1226 break;
1227 case ZEBRA_INTERFACE_DOWN:
1228 if (zclient->interface_down)
1229 (*zclient->interface_down) (command, zclient, length);
1230 break;
1231 case ZEBRA_IPV4_ROUTE_ADD:
1232 if (zclient->ipv4_route_add)
1233 (*zclient->ipv4_route_add) (command, zclient, length);
1234 break;
1235 case ZEBRA_IPV4_ROUTE_DELETE:
1236 if (zclient->ipv4_route_delete)
1237 (*zclient->ipv4_route_delete) (command, zclient, length);
1238 break;
1239 case ZEBRA_IPV6_ROUTE_ADD:
1240 if (zclient->ipv6_route_add)
1241 (*zclient->ipv6_route_add) (command, zclient, length);
1242 break;
1243 case ZEBRA_IPV6_ROUTE_DELETE:
1244 if (zclient->ipv6_route_delete)
1245 (*zclient->ipv6_route_delete) (command, zclient, length);
1246 break;
1247 case ZEBRA_NEXTHOP_UPDATE:
1248 if (zclient_debug)
1249 zlog_debug("zclient rcvd nexthop update\n");
1250 if (zclient->nexthop_update)
1251 (*zclient->nexthop_update) (command, zclient, length);
1252 break;
1253 case ZEBRA_IMPORT_CHECK_UPDATE:
1254 if (zclient_debug)
1255 zlog_debug("zclient rcvd import check update\n");
1256 if (zclient->import_check_update)
1257 (*zclient->import_check_update) (command, zclient, length);
1258 break;
1259 case ZEBRA_BFD_DEST_REPLAY:
1260 if (zclient->bfd_dest_replay)
1261 (*zclient->bfd_dest_replay) (command, zclient, length);
1262 break;
1263 default:
1264 break;
1265 }
1266
1267 if (zclient->sock < 0)
1268 /* Connection was closed during packet processing. */
1269 return -1;
1270
1271 /* Register read thread. */
1272 stream_reset(zclient->ibuf);
1273 zclient_event (ZCLIENT_READ, zclient);
1274
1275 return 0;
1276 }
1277
1278 void
1279 zclient_redistribute (int command, struct zclient *zclient, afi_t afi, int type,
1280 u_short instance)
1281 {
1282
1283 if (command == ZEBRA_REDISTRIBUTE_ADD)
1284 {
1285 if (redist_check_instance(&zclient->redist[afi][type], instance))
1286 return;
1287 redist_add_instance(&zclient->redist[afi][type], instance);
1288 }
1289 else
1290 {
1291 if (!redist_check_instance(&zclient->redist[afi][type], instance))
1292 return;
1293 redist_del_instance(&zclient->redist[afi][type], instance);
1294 }
1295
1296 if (zclient->sock > 0)
1297 zebra_redistribute_send (command, zclient, afi, type, instance);
1298 }
1299
1300
1301 void
1302 zclient_redistribute_default (int command, struct zclient *zclient)
1303 {
1304
1305 if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD)
1306 {
1307 if (zclient->default_information)
1308 return;
1309 zclient->default_information = 1;
1310 }
1311 else
1312 {
1313 if (!zclient->default_information)
1314 return;
1315 zclient->default_information = 0;
1316 }
1317
1318 if (zclient->sock > 0)
1319 zebra_message_send (zclient, command);
1320 }
1321
1322 static void
1323 zclient_event (enum event event, struct zclient *zclient)
1324 {
1325 switch (event)
1326 {
1327 case ZCLIENT_SCHEDULE:
1328 if (! zclient->t_connect)
1329 zclient->t_connect =
1330 thread_add_event (master, zclient_connect, zclient, 0);
1331 break;
1332 case ZCLIENT_CONNECT:
1333 if (zclient->fail >= 10)
1334 return;
1335 if (zclient_debug)
1336 zlog_debug ("zclient connect schedule interval is %d",
1337 zclient->fail < 3 ? 10 : 60);
1338 if (! zclient->t_connect)
1339 zclient->t_connect =
1340 thread_add_timer (master, zclient_connect, zclient,
1341 zclient->fail < 3 ? 10 : 60);
1342 break;
1343 case ZCLIENT_READ:
1344 zclient->t_read =
1345 thread_add_read (master, zclient_read, zclient, zclient->sock);
1346 break;
1347 }
1348 }
1349
1350 void
1351 zclient_serv_path_set (char *path)
1352 {
1353 struct stat sb;
1354
1355 /* reset */
1356 zclient_serv_path = NULL;
1357
1358 /* test if `path' is socket. don't set it otherwise. */
1359 if (stat(path, &sb) == -1)
1360 {
1361 zlog_warn ("%s: zebra socket `%s' does not exist", __func__, path);
1362 return;
1363 }
1364
1365 if ((sb.st_mode & S_IFMT) != S_IFSOCK)
1366 {
1367 zlog_warn ("%s: `%s' is not unix socket, sir", __func__, path);
1368 return;
1369 }
1370
1371 /* it seems that path is unix socket */
1372 zclient_serv_path = path;
1373 }
1374