paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 1 | /* Zebra's client library. |
| 2 | * Copyright (C) 1999 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 |
| 7 | * it under the terms of the GNU General Public License as published |
| 8 | * by the Free Software Foundation; either version 2, or (at your |
| 9 | * option) any 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, Boston, |
| 19 | * MA 02111-1307, USA. |
| 20 | */ |
| 21 | |
| 22 | #include <zebra.h> |
| 23 | |
| 24 | #include "prefix.h" |
| 25 | #include "stream.h" |
| 26 | #include "network.h" |
| 27 | #include "if.h" |
| 28 | #include "log.h" |
| 29 | #include "thread.h" |
| 30 | #include "zclient.h" |
| 31 | #include "memory.h" |
| 32 | #include "table.h" |
| 33 | |
| 34 | #include "zebra/rib.h" |
| 35 | #include "zebra/zserv.h" |
| 36 | |
| 37 | /* Zebra client events. */ |
| 38 | enum event {ZCLIENT_SCHEDULE, ZCLIENT_READ, ZCLIENT_CONNECT}; |
| 39 | |
| 40 | /* Prototype for event manager. */ |
| 41 | static void zclient_event (enum event, struct zclient *); |
| 42 | |
| 43 | /* This file local debug flag. */ |
| 44 | int zclient_debug = 0; |
| 45 | |
| 46 | /* Allocate zclient structure. */ |
| 47 | struct zclient * |
| 48 | zclient_new () |
| 49 | { |
| 50 | struct zclient *zclient; |
| 51 | zclient = XMALLOC (MTYPE_ZCLIENT, sizeof (struct zclient)); |
| 52 | memset (zclient, 0, sizeof (struct zclient)); |
| 53 | |
| 54 | zclient->ibuf = stream_new (ZEBRA_MAX_PACKET_SIZ); |
| 55 | zclient->obuf = stream_new (ZEBRA_MAX_PACKET_SIZ); |
| 56 | |
| 57 | return zclient; |
| 58 | } |
| 59 | |
| 60 | /* Free zclient structure. */ |
| 61 | void |
| 62 | zclient_free (struct zclient *zclient) |
| 63 | { |
| 64 | XFREE (MTYPE_ZCLIENT, zclient); |
| 65 | } |
| 66 | |
| 67 | /* Initialize zebra client. Argument redist_default is unwanted |
| 68 | redistribute route type. */ |
| 69 | void |
| 70 | zclient_init (struct zclient *zclient, int redist_default) |
| 71 | { |
| 72 | int i; |
| 73 | |
| 74 | /* Enable zebra client connection by default. */ |
| 75 | zclient->enable = 1; |
| 76 | |
| 77 | /* Set -1 to the default socket value. */ |
| 78 | zclient->sock = -1; |
| 79 | |
| 80 | /* Clear redistribution flags. */ |
| 81 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 82 | zclient->redist[i] = 0; |
| 83 | |
| 84 | /* Set unwanted redistribute route. bgpd does not need BGP route |
| 85 | redistribution. */ |
| 86 | zclient->redist_default = redist_default; |
| 87 | zclient->redist[redist_default] = 1; |
| 88 | |
| 89 | /* Set default-information redistribute to zero. */ |
| 90 | zclient->default_information = 0; |
| 91 | |
| 92 | /* Schedule first zclient connection. */ |
| 93 | if (zclient_debug) |
| 94 | zlog_info ("zclient start scheduled"); |
| 95 | |
| 96 | zclient_event (ZCLIENT_SCHEDULE, zclient); |
| 97 | } |
| 98 | |
| 99 | /* Stop zebra client services. */ |
| 100 | void |
| 101 | zclient_stop (struct zclient *zclient) |
| 102 | { |
| 103 | if (zclient_debug) |
| 104 | zlog_info ("zclient stopped"); |
| 105 | |
| 106 | /* Stop threads. */ |
| 107 | if (zclient->t_read) |
| 108 | { |
| 109 | thread_cancel (zclient->t_read); |
| 110 | zclient->t_read = NULL; |
| 111 | } |
| 112 | if (zclient->t_connect) |
| 113 | { |
| 114 | thread_cancel (zclient->t_connect); |
| 115 | zclient->t_connect = NULL; |
| 116 | } |
| 117 | |
| 118 | /* Close socket. */ |
| 119 | if (zclient->sock >= 0) |
| 120 | { |
| 121 | close (zclient->sock); |
| 122 | zclient->sock = -1; |
| 123 | } |
| 124 | zclient->fail = 0; |
| 125 | } |
| 126 | |
| 127 | void |
| 128 | zclient_reset (struct zclient *zclient) |
| 129 | { |
| 130 | zclient_stop (zclient); |
| 131 | zclient_init (zclient, zclient->redist_default); |
| 132 | } |
| 133 | |
| 134 | /* Make socket to zebra daemon. Return zebra socket. */ |
| 135 | int |
| 136 | zclient_socket () |
| 137 | { |
| 138 | int sock; |
| 139 | int ret; |
| 140 | struct sockaddr_in serv; |
| 141 | |
| 142 | /* We should think about IPv6 connection. */ |
| 143 | sock = socket (AF_INET, SOCK_STREAM, 0); |
| 144 | if (sock < 0) |
| 145 | return -1; |
| 146 | |
| 147 | /* Make server socket. */ |
| 148 | memset (&serv, 0, sizeof (struct sockaddr_in)); |
| 149 | serv.sin_family = AF_INET; |
| 150 | serv.sin_port = htons (ZEBRA_PORT); |
| 151 | #ifdef HAVE_SIN_LEN |
| 152 | serv.sin_len = sizeof (struct sockaddr_in); |
| 153 | #endif /* HAVE_SIN_LEN */ |
| 154 | serv.sin_addr.s_addr = htonl (INADDR_LOOPBACK); |
| 155 | |
| 156 | /* Connect to zebra. */ |
| 157 | ret = connect (sock, (struct sockaddr *) &serv, sizeof (serv)); |
| 158 | if (ret < 0) |
| 159 | { |
| 160 | close (sock); |
| 161 | return -1; |
| 162 | } |
| 163 | return sock; |
| 164 | } |
| 165 | |
| 166 | /* For sockaddr_un. */ |
| 167 | #include <sys/un.h> |
| 168 | |
| 169 | int |
hasso | 8c328f1 | 2004-10-05 21:01:23 +0000 | [diff] [blame] | 170 | zclient_socket_un (const char *path) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 171 | { |
| 172 | int ret; |
| 173 | int sock, len; |
| 174 | struct sockaddr_un addr; |
| 175 | |
| 176 | sock = socket (AF_UNIX, SOCK_STREAM, 0); |
| 177 | if (sock < 0) |
| 178 | return -1; |
| 179 | |
| 180 | /* Make server socket. */ |
| 181 | memset (&addr, 0, sizeof (struct sockaddr_un)); |
| 182 | addr.sun_family = AF_UNIX; |
| 183 | strncpy (addr.sun_path, path, strlen (path)); |
| 184 | #ifdef HAVE_SUN_LEN |
| 185 | len = addr.sun_len = SUN_LEN(&addr); |
| 186 | #else |
| 187 | len = sizeof (addr.sun_family) + strlen (addr.sun_path); |
| 188 | #endif /* HAVE_SUN_LEN */ |
| 189 | |
| 190 | ret = connect (sock, (struct sockaddr *) &addr, len); |
| 191 | if (ret < 0) |
| 192 | { |
| 193 | close (sock); |
| 194 | return -1; |
| 195 | } |
| 196 | return sock; |
| 197 | } |
| 198 | |
| 199 | /* Send simple Zebra message. */ |
| 200 | int |
| 201 | zebra_message_send (struct zclient *zclient, int command) |
| 202 | { |
| 203 | struct stream *s; |
| 204 | |
| 205 | /* Get zclient output buffer. */ |
| 206 | s = zclient->obuf; |
| 207 | stream_reset (s); |
| 208 | |
| 209 | /* Send very simple command only Zebra message. */ |
| 210 | stream_putw (s, 3); |
| 211 | stream_putc (s, command); |
| 212 | |
| 213 | return writen (zclient->sock, s->data, 3); |
| 214 | } |
| 215 | |
| 216 | /* Make connection to zebra daemon. */ |
| 217 | int |
| 218 | zclient_start (struct zclient *zclient) |
| 219 | { |
| 220 | int i; |
| 221 | |
| 222 | if (zclient_debug) |
| 223 | zlog_info ("zclient_start is called"); |
| 224 | |
| 225 | /* zclient is disabled. */ |
| 226 | if (! zclient->enable) |
| 227 | return 0; |
| 228 | |
| 229 | /* If already connected to the zebra. */ |
| 230 | if (zclient->sock >= 0) |
| 231 | return 0; |
| 232 | |
| 233 | /* Check connect thread. */ |
| 234 | if (zclient->t_connect) |
| 235 | return 0; |
| 236 | |
| 237 | /* Make socket. */ |
| 238 | #ifdef HAVE_TCP_ZEBRA |
| 239 | zclient->sock = zclient_socket (); |
| 240 | #else |
| 241 | zclient->sock = zclient_socket_un (ZEBRA_SERV_PATH); |
| 242 | #endif /* HAVE_TCP_ZEBRA */ |
| 243 | if (zclient->sock < 0) |
| 244 | { |
| 245 | if (zclient_debug) |
| 246 | zlog_info ("zclient connection fail"); |
| 247 | zclient->fail++; |
| 248 | zclient_event (ZCLIENT_CONNECT, zclient); |
| 249 | return -1; |
| 250 | } |
| 251 | |
| 252 | /* Clear fail count. */ |
| 253 | zclient->fail = 0; |
| 254 | if (zclient_debug) |
| 255 | zlog_info ("zclient connect success with socket [%d]", zclient->sock); |
| 256 | |
| 257 | /* Create read thread. */ |
| 258 | zclient_event (ZCLIENT_READ, zclient); |
| 259 | |
| 260 | /* We need interface information. */ |
| 261 | zebra_message_send (zclient, ZEBRA_INTERFACE_ADD); |
| 262 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 263 | /* We need router-id information. */ |
| 264 | zebra_message_send (zclient, ZEBRA_ROUTER_ID_ADD); |
| 265 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 266 | /* Flush all redistribute request. */ |
| 267 | for (i = 0; i < ZEBRA_ROUTE_MAX; i++) |
| 268 | if (i != zclient->redist_default && zclient->redist[i]) |
| 269 | zebra_redistribute_send (ZEBRA_REDISTRIBUTE_ADD, zclient->sock, i); |
| 270 | |
| 271 | /* If default information is needed. */ |
| 272 | if (zclient->default_information) |
| 273 | zebra_message_send (zclient, ZEBRA_REDISTRIBUTE_DEFAULT_ADD); |
| 274 | |
| 275 | return 0; |
| 276 | } |
| 277 | |
| 278 | /* This function is a wrapper function for calling zclient_start from |
| 279 | timer or event thread. */ |
| 280 | int |
| 281 | zclient_connect (struct thread *t) |
| 282 | { |
| 283 | struct zclient *zclient; |
| 284 | |
| 285 | zclient = THREAD_ARG (t); |
| 286 | zclient->t_connect = NULL; |
| 287 | |
| 288 | if (zclient_debug) |
| 289 | zlog_info ("zclient_connect is called"); |
| 290 | |
| 291 | return zclient_start (zclient); |
| 292 | } |
| 293 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 294 | /* |
| 295 | * "xdr_encode"-like interface that allows daemon (client) to send |
| 296 | * a message to zebra server for a route that needs to be |
| 297 | * added/deleted to the kernel. Info about the route is specified |
| 298 | * by the caller in a struct zapi_ipv4. zapi_ipv4_read() then writes |
| 299 | * the info down the zclient socket using the stream_* functions. |
| 300 | * |
| 301 | * The corresponding read ("xdr_decode") function on the server |
| 302 | * side is zread_ipv4_add()/zread_ipv4_delete(). |
| 303 | * |
| 304 | * 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 |
| 305 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 306 | * | Length (2) | Command | Route Type | |
| 307 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 308 | * | ZEBRA Flags | Message Flags | Prefix length | |
| 309 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 310 | * | Destination IPv4 Prefix for route | |
| 311 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 312 | * | Nexthop count | |
| 313 | * +-+-+-+-+-+-+-+-+ |
| 314 | * |
| 315 | * |
| 316 | * A number of IPv4 nexthop(s) or nexthop interface index(es) are then |
| 317 | * described, as per the Nexthop count. Each nexthop described as: |
| 318 | * |
| 319 | * +-+-+-+-+-+-+-+-+ |
| 320 | * | Nexthop Type | Set to one of ZEBRA_NEXTHOP_* |
| 321 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 322 | * | IPv4 Nexthop address or Interface Index number | |
| 323 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 324 | * |
| 325 | * Alternatively, if the flags field has ZEBRA_FLAG_BLACKHOLE or |
| 326 | * ZEBRA_FLAG_REJECT is set then Nexthop count is set to 1, then _no_ |
| 327 | * nexthop information is provided, and the message describes a prefix |
| 328 | * to blackhole or reject route. |
| 329 | * |
| 330 | * If ZAPI_MESSAGE_DISTANCE is set, the distance value is written as a 1 |
| 331 | * byte value. |
| 332 | * |
| 333 | * If ZAPI_MESSAGE_METRIC is set, the metric value is written as an 8 |
| 334 | * byte value. |
| 335 | * |
| 336 | * XXX: No attention paid to alignment. |
| 337 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 338 | int |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 339 | zapi_ipv4_route (u_char cmd, struct zclient *zclient, struct prefix_ipv4 *p, |
| 340 | struct zapi_ipv4 *api) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 341 | { |
| 342 | int i; |
| 343 | int psize; |
| 344 | struct stream *s; |
| 345 | |
| 346 | /* Reset stream. */ |
| 347 | s = zclient->obuf; |
| 348 | stream_reset (s); |
| 349 | |
| 350 | /* Length place holder. */ |
| 351 | stream_putw (s, 0); |
| 352 | |
| 353 | /* Put command, type and nexthop. */ |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 354 | stream_putc (s, cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 355 | stream_putc (s, api->type); |
| 356 | stream_putc (s, api->flags); |
| 357 | stream_putc (s, api->message); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 358 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 359 | /* Put prefix information. */ |
| 360 | psize = PSIZE (p->prefixlen); |
| 361 | stream_putc (s, p->prefixlen); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 362 | stream_write (s, (u_char *) & p->prefix, psize); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 363 | |
| 364 | /* Nexthop, ifindex, distance and metric information. */ |
| 365 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP)) |
| 366 | { |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 367 | if (CHECK_FLAG (api->flags, ZEBRA_FLAG_BLACKHOLE)) |
| 368 | { |
| 369 | stream_putc (s, 1); |
| 370 | stream_putc (s, ZEBRA_NEXTHOP_BLACKHOLE); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 371 | /* XXX assert(api->nexthop_num == 0); */ |
| 372 | /* XXX assert(api->ifindex_num == 0); */ |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 373 | } |
| 374 | else |
| 375 | stream_putc (s, api->nexthop_num + api->ifindex_num); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 376 | |
| 377 | for (i = 0; i < api->nexthop_num; i++) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 378 | { |
| 379 | stream_putc (s, ZEBRA_NEXTHOP_IPV4); |
| 380 | stream_put_in_addr (s, api->nexthop[i]); |
| 381 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 382 | for (i = 0; i < api->ifindex_num; i++) |
paul | 595db7f | 2003-05-25 21:35:06 +0000 | [diff] [blame] | 383 | { |
| 384 | stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); |
| 385 | stream_putl (s, api->ifindex[i]); |
| 386 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 387 | } |
| 388 | |
| 389 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE)) |
| 390 | stream_putc (s, api->distance); |
| 391 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC)) |
| 392 | stream_putl (s, api->metric); |
| 393 | |
| 394 | /* Put length at the first point of the stream. */ |
| 395 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 396 | |
| 397 | return writen (zclient->sock, s->data, stream_get_endp (s)); |
| 398 | } |
| 399 | |
| 400 | #ifdef HAVE_IPV6 |
| 401 | int |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 402 | zapi_ipv6_route (u_char cmd, struct zclient *zclient, struct prefix_ipv6 *p, |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 403 | struct zapi_ipv6 *api) |
| 404 | { |
| 405 | int i; |
| 406 | int psize; |
| 407 | struct stream *s; |
| 408 | |
| 409 | /* Reset stream. */ |
| 410 | s = zclient->obuf; |
| 411 | stream_reset (s); |
| 412 | |
| 413 | /* Length place holder. */ |
| 414 | stream_putw (s, 0); |
| 415 | |
| 416 | /* Put command, type and nexthop. */ |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 417 | stream_putc (s, cmd); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 418 | stream_putc (s, api->type); |
| 419 | stream_putc (s, api->flags); |
| 420 | stream_putc (s, api->message); |
| 421 | |
| 422 | /* Put prefix information. */ |
| 423 | psize = PSIZE (p->prefixlen); |
| 424 | stream_putc (s, p->prefixlen); |
| 425 | stream_write (s, (u_char *)&p->prefix, psize); |
| 426 | |
| 427 | /* Nexthop, ifindex, distance and metric information. */ |
| 428 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_NEXTHOP)) |
| 429 | { |
| 430 | stream_putc (s, api->nexthop_num + api->ifindex_num); |
| 431 | |
| 432 | for (i = 0; i < api->nexthop_num; i++) |
| 433 | { |
| 434 | stream_putc (s, ZEBRA_NEXTHOP_IPV6); |
| 435 | stream_write (s, (u_char *)api->nexthop[i], 16); |
| 436 | } |
| 437 | for (i = 0; i < api->ifindex_num; i++) |
| 438 | { |
| 439 | stream_putc (s, ZEBRA_NEXTHOP_IFINDEX); |
| 440 | stream_putl (s, api->ifindex[i]); |
| 441 | } |
| 442 | } |
| 443 | |
| 444 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_DISTANCE)) |
| 445 | stream_putc (s, api->distance); |
| 446 | if (CHECK_FLAG (api->message, ZAPI_MESSAGE_METRIC)) |
| 447 | stream_putl (s, api->metric); |
| 448 | |
| 449 | /* Put length at the first point of the stream. */ |
| 450 | stream_putw_at (s, 0, stream_get_endp (s)); |
| 451 | |
| 452 | return writen (zclient->sock, s->data, stream_get_endp (s)); |
| 453 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 454 | #endif /* HAVE_IPV6 */ |
| 455 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 456 | /* |
| 457 | * send a ZEBRA_REDISTRIBUTE_ADD or ZEBRA_REDISTRIBUTE_DELETE |
| 458 | * for the route type (ZEBRA_ROUTE_KERNEL etc.). The zebra server will |
| 459 | * then set/unset redist[type] in the client handle (a struct zserv) for the |
| 460 | * sending client |
| 461 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 462 | int |
| 463 | zebra_redistribute_send (int command, int sock, int type) |
| 464 | { |
| 465 | int ret; |
| 466 | struct stream *s; |
| 467 | |
| 468 | s = stream_new (ZEBRA_MAX_PACKET_SIZ); |
| 469 | |
| 470 | /* Total length of the messages. */ |
| 471 | stream_putw (s, 4); |
| 472 | |
| 473 | stream_putc (s, command); |
| 474 | stream_putc (s, type); |
| 475 | |
| 476 | ret = writen (sock, s->data, 4); |
| 477 | |
| 478 | stream_free (s); |
| 479 | |
| 480 | return ret; |
| 481 | } |
| 482 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 483 | /* Router-id update from zebra daemon. */ |
| 484 | void |
| 485 | zebra_router_id_update_read (struct stream *s, struct prefix *rid) |
| 486 | { |
| 487 | int plen; |
| 488 | |
| 489 | /* Fetch interface address. */ |
| 490 | rid->family = stream_getc (s); |
| 491 | |
| 492 | plen = prefix_blen (rid); |
| 493 | stream_get (&rid->u.prefix, s, plen); |
| 494 | rid->prefixlen = stream_getc (s); |
| 495 | } |
| 496 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 497 | /* Interface addition from zebra daemon. */ |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 498 | /* |
| 499 | * The format of the message sent with type ZEBRA_INTERFACE_ADD or |
| 500 | * ZEBRA_INTERFACE_DELETE from zebra to the client is: |
| 501 | * 0 1 2 3 |
| 502 | * 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 |
| 503 | * +-+-+-+-+-+-+-+-+ |
| 504 | * | type | |
| 505 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 506 | * | ifname | |
| 507 | * | | |
| 508 | * | | |
| 509 | * | | |
| 510 | * | | |
| 511 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 512 | * | ifindex | |
| 513 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 514 | * | if_flags | |
| 515 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 516 | * | metric | |
| 517 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 518 | * | ifmtu | |
| 519 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 520 | * | ifmtu6 | |
| 521 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 522 | * | bandwidth | |
| 523 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 524 | * | sockaddr_dl | |
| 525 | * +-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+-+ |
| 526 | */ |
| 527 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 528 | struct interface * |
| 529 | zebra_interface_add_read (struct stream *s) |
| 530 | { |
| 531 | struct interface *ifp; |
paul | 02ff83c | 2004-06-11 11:27:03 +0000 | [diff] [blame] | 532 | char ifname_tmp[INTERFACE_NAMSIZ]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 533 | |
| 534 | /* Read interface name. */ |
| 535 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); |
| 536 | |
| 537 | /* Lookup this by interface name. */ |
| 538 | ifp = if_lookup_by_name (ifname_tmp); |
| 539 | |
| 540 | /* If such interface does not exist, make new one. */ |
| 541 | if (! ifp) |
paul | 106d2fd | 2003-08-01 00:24:13 +0000 | [diff] [blame] | 542 | ifp = if_create (ifname_tmp, INTERFACE_NAMSIZ); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 543 | |
| 544 | /* Read interface's index. */ |
| 545 | ifp->ifindex = stream_getl (s); |
| 546 | |
| 547 | /* Read interface's value. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 548 | ifp->status = stream_getc (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 549 | ifp->flags = stream_getl (s); |
| 550 | ifp->metric = stream_getl (s); |
| 551 | ifp->mtu = stream_getl (s); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 552 | ifp->mtu6 = stream_getl (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 553 | ifp->bandwidth = stream_getl (s); |
| 554 | #ifdef HAVE_SOCKADDR_DL |
| 555 | stream_get (&ifp->sdl, s, sizeof (ifp->sdl)); |
| 556 | #else |
| 557 | ifp->hw_addr_len = stream_getl (s); |
| 558 | if (ifp->hw_addr_len) |
| 559 | stream_get (ifp->hw_addr, s, ifp->hw_addr_len); |
| 560 | #endif /* HAVE_SOCKADDR_DL */ |
| 561 | |
| 562 | return ifp; |
| 563 | } |
| 564 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 565 | /* |
| 566 | * Read interface up/down msg (ZEBRA_INTERFACE_UP/ZEBRA_INTERFACE_DOWN) |
| 567 | * from zebra server. The format of this message is the same as |
| 568 | * that sent for ZEBRA_INTERFACE_ADD/ZEBRA_INTERFACE_DELETE (see |
| 569 | * comments for zebra_interface_add_read), except that no sockaddr_dl |
| 570 | * is sent at the tail of the message. |
| 571 | */ |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 572 | struct interface * |
| 573 | zebra_interface_state_read (struct stream *s) |
| 574 | { |
| 575 | struct interface *ifp; |
paul | 02ff83c | 2004-06-11 11:27:03 +0000 | [diff] [blame] | 576 | char ifname_tmp[INTERFACE_NAMSIZ]; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 577 | |
| 578 | /* Read interface name. */ |
| 579 | stream_get (ifname_tmp, s, INTERFACE_NAMSIZ); |
| 580 | |
| 581 | /* Lookup this by interface index. */ |
| 582 | ifp = if_lookup_by_name (ifname_tmp); |
| 583 | |
| 584 | /* If such interface does not exist, indicate an error */ |
| 585 | if (! ifp) |
| 586 | return NULL; |
| 587 | |
| 588 | /* Read interface's index. */ |
| 589 | ifp->ifindex = stream_getl (s); |
| 590 | |
| 591 | /* Read interface's value. */ |
paul | 2e3b2e4 | 2002-12-13 21:03:13 +0000 | [diff] [blame] | 592 | ifp->status = stream_getc (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 593 | ifp->flags = stream_getl (s); |
| 594 | ifp->metric = stream_getl (s); |
| 595 | ifp->mtu = stream_getl (s); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 596 | ifp->mtu6 = stream_getl (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 597 | ifp->bandwidth = stream_getl (s); |
| 598 | |
| 599 | return ifp; |
| 600 | } |
| 601 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 602 | /* |
| 603 | * format of message for address additon is: |
| 604 | * 0 |
| 605 | * 0 1 2 3 4 5 6 7 |
| 606 | * +-+-+-+-+-+-+-+-+ |
| 607 | * | type | ZEBRA_INTERFACE_ADDRESS_ADD or |
| 608 | * +-+-+-+-+-+-+-+-+ ZEBRA_INTERFACE_ADDRES_DELETE |
| 609 | * | | |
| 610 | * + + |
| 611 | * | ifindex | |
| 612 | * + + |
| 613 | * | | |
| 614 | * + + |
| 615 | * | | |
| 616 | * +-+-+-+-+-+-+-+-+ |
| 617 | * | ifc_flags | flags for connected address |
| 618 | * +-+-+-+-+-+-+-+-+ |
| 619 | * | addr_family | |
| 620 | * +-+-+-+-+-+-+-+-+ |
| 621 | * | addr... | |
| 622 | * : : |
| 623 | * | | |
| 624 | * +-+-+-+-+-+-+-+-+ |
| 625 | * | addr_len | len of addr. E.g., addr_len = 4 for ipv4 addrs. |
| 626 | * +-+-+-+-+-+-+-+-+ |
| 627 | * | daddr.. | |
| 628 | * : : |
| 629 | * | | |
| 630 | * +-+-+-+-+-+-+-+-+ |
| 631 | * |
| 632 | */ |
| 633 | |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 634 | void |
| 635 | zebra_interface_if_set_value (struct stream *s, struct interface *ifp) |
| 636 | { |
| 637 | /* Read interface's index. */ |
| 638 | ifp->ifindex = stream_getl (s); |
| 639 | |
| 640 | /* Read interface's value. */ |
| 641 | ifp->flags = stream_getl (s); |
| 642 | ifp->metric = stream_getl (s); |
| 643 | ifp->mtu = stream_getl (s); |
| 644 | ifp->bandwidth = stream_getl (s); |
| 645 | } |
| 646 | |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 647 | static int |
| 648 | memconstant(const void *s, int c, size_t n) |
| 649 | { |
| 650 | const u_char *p = s; |
| 651 | |
| 652 | while (n-- > 0) |
| 653 | if (*p++ != c) |
| 654 | return 0; |
| 655 | return 1; |
| 656 | } |
| 657 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 658 | struct connected * |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 659 | zebra_interface_address_read (int type, struct stream *s) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 660 | { |
| 661 | unsigned int ifindex; |
| 662 | struct interface *ifp; |
| 663 | struct connected *ifc; |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 664 | struct prefix p, d; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 665 | int family; |
| 666 | int plen; |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 667 | u_char ifc_flags; |
| 668 | |
| 669 | memset (&p, 0, sizeof(p)); |
| 670 | memset (&d, 0, sizeof(d)); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 671 | |
| 672 | /* Get interface index. */ |
| 673 | ifindex = stream_getl (s); |
| 674 | |
| 675 | /* Lookup index. */ |
| 676 | ifp = if_lookup_by_index (ifindex); |
| 677 | if (ifp == NULL) |
| 678 | { |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 679 | zlog_warn ("zebra_interface_address_read(%s): " |
| 680 | "Can't find interface by ifindex: %d ", |
| 681 | (type == ZEBRA_INTERFACE_ADDRESS_ADD? "ADD" : "DELETE"), |
| 682 | ifindex); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 683 | return NULL; |
| 684 | } |
| 685 | |
| 686 | /* Fetch flag. */ |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 687 | ifc_flags = stream_getc (s); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 688 | |
| 689 | /* Fetch interface address. */ |
| 690 | family = p.family = stream_getc (s); |
| 691 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 692 | plen = prefix_blen (&p); |
| 693 | stream_get (&p.u.prefix, s, plen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 694 | p.prefixlen = stream_getc (s); |
| 695 | |
| 696 | /* Fetch destination address. */ |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 697 | stream_get (&d.u.prefix, s, plen); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 698 | d.family = family; |
| 699 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 700 | if (type == ZEBRA_INTERFACE_ADDRESS_ADD) |
| 701 | { |
hasso | 3fb9cd6 | 2004-10-19 19:44:43 +0000 | [diff] [blame] | 702 | /* N.B. NULL destination pointers are encoded as all zeroes */ |
| 703 | ifc = connected_add_by_prefix(ifp, &p,(memconstant(&d.u.prefix,0,plen) ? |
| 704 | NULL : &d)); |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 705 | if (ifc != NULL) |
| 706 | ifc->flags = ifc_flags; |
| 707 | } |
| 708 | else |
| 709 | { |
| 710 | assert (type == ZEBRA_INTERFACE_ADDRESS_DELETE); |
| 711 | ifc = connected_delete_by_prefix(ifp, &p); |
| 712 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 713 | |
| 714 | return ifc; |
| 715 | } |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 716 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 717 | |
| 718 | /* Zebra client message read function. */ |
| 719 | int |
| 720 | zclient_read (struct thread *thread) |
| 721 | { |
| 722 | int ret; |
| 723 | int nbytes; |
| 724 | int sock; |
| 725 | zebra_size_t length; |
| 726 | zebra_command_t command; |
| 727 | struct zclient *zclient; |
| 728 | |
| 729 | /* Get socket to zebra. */ |
| 730 | sock = THREAD_FD (thread); |
| 731 | zclient = THREAD_ARG (thread); |
| 732 | zclient->t_read = NULL; |
| 733 | |
| 734 | /* Clear input buffer. */ |
| 735 | stream_reset (zclient->ibuf); |
| 736 | |
| 737 | /* Read zebra header. */ |
| 738 | nbytes = stream_read (zclient->ibuf, sock, ZEBRA_HEADER_SIZE); |
| 739 | |
| 740 | /* zebra socket is closed. */ |
| 741 | if (nbytes == 0) |
| 742 | { |
| 743 | if (zclient_debug) |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 744 | zlog_info ("zclient connection closed socket [%d].", sock); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 745 | zclient->fail++; |
| 746 | zclient_stop (zclient); |
| 747 | zclient_event (ZCLIENT_CONNECT, zclient); |
| 748 | return -1; |
| 749 | } |
| 750 | |
| 751 | /* zebra read error. */ |
| 752 | if (nbytes < 0 || nbytes != ZEBRA_HEADER_SIZE) |
| 753 | { |
| 754 | if (zclient_debug) |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 755 | zlog_info ("Can't read all packet (length %d).", nbytes); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 756 | zclient->fail++; |
| 757 | zclient_stop (zclient); |
| 758 | zclient_event (ZCLIENT_CONNECT, zclient); |
| 759 | return -1; |
| 760 | } |
| 761 | |
| 762 | /* Fetch length and command. */ |
| 763 | length = stream_getw (zclient->ibuf); |
| 764 | command = stream_getc (zclient->ibuf); |
| 765 | |
| 766 | /* Length check. */ |
| 767 | if (length >= zclient->ibuf->size) |
| 768 | { |
| 769 | stream_free (zclient->ibuf); |
| 770 | zclient->ibuf = stream_new (length + 1); |
| 771 | } |
| 772 | length -= ZEBRA_HEADER_SIZE; |
| 773 | |
| 774 | /* Read rest of zebra packet. */ |
| 775 | nbytes = stream_read (zclient->ibuf, sock, length); |
| 776 | if (nbytes != length) |
| 777 | { |
| 778 | if (zclient_debug) |
| 779 | zlog_info ("zclient connection closed socket [%d].", sock); |
| 780 | zclient->fail++; |
| 781 | zclient_stop (zclient); |
| 782 | zclient_event (ZCLIENT_CONNECT, zclient); |
| 783 | return -1; |
| 784 | } |
| 785 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 786 | if (zclient_debug) |
| 787 | zlog_info("zclient 0x%p command 0x%x \n", zclient, command); |
| 788 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 789 | switch (command) |
| 790 | { |
hasso | 18a6dce | 2004-10-03 18:18:34 +0000 | [diff] [blame] | 791 | case ZEBRA_ROUTER_ID_UPDATE: |
| 792 | if (zclient->router_id_update) |
| 793 | ret = (*zclient->router_id_update) (command, zclient, length); |
| 794 | break; |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 795 | case ZEBRA_INTERFACE_ADD: |
| 796 | if (zclient->interface_add) |
| 797 | ret = (*zclient->interface_add) (command, zclient, length); |
| 798 | break; |
| 799 | case ZEBRA_INTERFACE_DELETE: |
| 800 | if (zclient->interface_delete) |
| 801 | ret = (*zclient->interface_delete) (command, zclient, length); |
| 802 | break; |
| 803 | case ZEBRA_INTERFACE_ADDRESS_ADD: |
| 804 | if (zclient->interface_address_add) |
| 805 | ret = (*zclient->interface_address_add) (command, zclient, length); |
| 806 | break; |
| 807 | case ZEBRA_INTERFACE_ADDRESS_DELETE: |
| 808 | if (zclient->interface_address_delete) |
| 809 | ret = (*zclient->interface_address_delete) (command, zclient, length); |
| 810 | break; |
| 811 | case ZEBRA_INTERFACE_UP: |
| 812 | if (zclient->interface_up) |
| 813 | ret = (*zclient->interface_up) (command, zclient, length); |
| 814 | break; |
| 815 | case ZEBRA_INTERFACE_DOWN: |
| 816 | if (zclient->interface_down) |
| 817 | ret = (*zclient->interface_down) (command, zclient, length); |
| 818 | break; |
| 819 | case ZEBRA_IPV4_ROUTE_ADD: |
| 820 | if (zclient->ipv4_route_add) |
| 821 | ret = (*zclient->ipv4_route_add) (command, zclient, length); |
| 822 | break; |
| 823 | case ZEBRA_IPV4_ROUTE_DELETE: |
| 824 | if (zclient->ipv4_route_delete) |
| 825 | ret = (*zclient->ipv4_route_delete) (command, zclient, length); |
| 826 | break; |
| 827 | case ZEBRA_IPV6_ROUTE_ADD: |
| 828 | if (zclient->ipv6_route_add) |
| 829 | ret = (*zclient->ipv6_route_add) (command, zclient, length); |
| 830 | break; |
| 831 | case ZEBRA_IPV6_ROUTE_DELETE: |
| 832 | if (zclient->ipv6_route_delete) |
| 833 | ret = (*zclient->ipv6_route_delete) (command, zclient, length); |
| 834 | break; |
| 835 | default: |
| 836 | break; |
| 837 | } |
| 838 | |
| 839 | /* Register read thread. */ |
| 840 | zclient_event (ZCLIENT_READ, zclient); |
| 841 | |
| 842 | return 0; |
| 843 | } |
| 844 | |
| 845 | void |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 846 | zclient_redistribute (int command, struct zclient *zclient, int type) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 847 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 848 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 849 | if (command == ZEBRA_REDISTRIBUTE_ADD) |
| 850 | { |
| 851 | if (zclient->redist[type]) |
| 852 | return; |
| 853 | zclient->redist[type] = 1; |
| 854 | } |
| 855 | else |
| 856 | { |
| 857 | if (!zclient->redist[type]) |
| 858 | return; |
| 859 | zclient->redist[type] = 0; |
| 860 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 861 | |
| 862 | if (zclient->sock > 0) |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 863 | zebra_redistribute_send (command, zclient->sock, type); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 864 | } |
| 865 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 866 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 867 | void |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 868 | zclient_redistribute_default (int command, struct zclient *zclient) |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 869 | { |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 870 | |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 871 | if (command == ZEBRA_REDISTRIBUTE_DEFAULT_ADD) |
| 872 | { |
| 873 | if (zclient->default_information) |
| 874 | return; |
| 875 | zclient->default_information = 1; |
| 876 | } |
| 877 | else |
| 878 | { |
| 879 | if (!zclient->default_information) |
| 880 | return; |
| 881 | zclient->default_information = 0; |
| 882 | } |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 883 | |
| 884 | if (zclient->sock > 0) |
paul | 0a58935 | 2004-05-08 11:48:26 +0000 | [diff] [blame] | 885 | zebra_message_send (zclient, command); |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 886 | } |
| 887 | |
paul | 718e374 | 2002-12-13 20:15:29 +0000 | [diff] [blame] | 888 | |
| 889 | extern struct thread_master *master; |
| 890 | |
| 891 | static void |
| 892 | zclient_event (enum event event, struct zclient *zclient) |
| 893 | { |
| 894 | switch (event) |
| 895 | { |
| 896 | case ZCLIENT_SCHEDULE: |
| 897 | if (! zclient->t_connect) |
| 898 | zclient->t_connect = |
| 899 | thread_add_event (master, zclient_connect, zclient, 0); |
| 900 | break; |
| 901 | case ZCLIENT_CONNECT: |
| 902 | if (zclient->fail >= 10) |
| 903 | return; |
| 904 | if (zclient_debug) |
| 905 | zlog_info ("zclient connect schedule interval is %d", |
| 906 | zclient->fail < 3 ? 10 : 60); |
| 907 | if (! zclient->t_connect) |
| 908 | zclient->t_connect = |
| 909 | thread_add_timer (master, zclient_connect, zclient, |
| 910 | zclient->fail < 3 ? 10 : 60); |
| 911 | break; |
| 912 | case ZCLIENT_READ: |
| 913 | zclient->t_read = |
| 914 | thread_add_read (master, zclient_read, zclient, zclient->sock); |
| 915 | break; |
| 916 | } |
| 917 | } |