zclient.h 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. /* Zebra's client header.
  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 it
  7. * under the terms of the GNU General Public License as published by
  8. * the Free Software Foundation; either version 2, or (at your option)
  9. * 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,
  19. * Boston, MA 02111-1307, USA.
  20. */
  21. #ifndef _ZEBRA_ZCLIENT_H
  22. #define _ZEBRA_ZCLIENT_H
  23. /* For struct interface and struct connected. */
  24. #include "if.h"
  25. /* For input/output buffer to zebra. */
  26. #define ZEBRA_MAX_PACKET_SIZ 4096
  27. /* Zebra header size. */
  28. #define ZEBRA_HEADER_SIZE 6
  29. /* Structure for the zebra client. */
  30. struct zclient
  31. {
  32. /* Socket to zebra daemon. */
  33. int sock;
  34. /* Flag of communication to zebra is enabled or not. Default is on.
  35. This flag is disabled by `no router zebra' statement. */
  36. int enable;
  37. /* Connection failure count. */
  38. int fail;
  39. /* Input buffer for zebra message. */
  40. struct stream *ibuf;
  41. /* Output buffer for zebra message. */
  42. struct stream *obuf;
  43. /* Buffer of data waiting to be written to zebra. */
  44. struct buffer *wb;
  45. /* Read and connect thread. */
  46. struct thread *t_read;
  47. struct thread *t_connect;
  48. /* Thread to write buffered data to zebra. */
  49. struct thread *t_write;
  50. /* Redistribute information. */
  51. u_char redist_default;
  52. u_char redist[ZEBRA_ROUTE_MAX];
  53. /* Redistribute defauilt. */
  54. u_char default_information;
  55. /* Pointer to the callback functions. */
  56. int (*router_id_update) (int, struct zclient *, uint16_t);
  57. int (*interface_add) (int, struct zclient *, uint16_t);
  58. int (*interface_delete) (int, struct zclient *, uint16_t);
  59. int (*interface_up) (int, struct zclient *, uint16_t);
  60. int (*interface_down) (int, struct zclient *, uint16_t);
  61. int (*interface_address_add) (int, struct zclient *, uint16_t);
  62. int (*interface_address_delete) (int, struct zclient *, uint16_t);
  63. int (*ipv4_route_add) (int, struct zclient *, uint16_t);
  64. int (*ipv4_route_delete) (int, struct zclient *, uint16_t);
  65. int (*ipv6_route_add) (int, struct zclient *, uint16_t);
  66. int (*ipv6_route_delete) (int, struct zclient *, uint16_t);
  67. };
  68. /* Zebra API message flag. */
  69. #define ZAPI_MESSAGE_NEXTHOP 0x01
  70. #define ZAPI_MESSAGE_IFINDEX 0x02
  71. #define ZAPI_MESSAGE_DISTANCE 0x04
  72. #define ZAPI_MESSAGE_METRIC 0x08
  73. /* Zserv protocol message header */
  74. struct zserv_header
  75. {
  76. uint16_t length;
  77. uint8_t marker; /* corresponds to command field in old zserv
  78. * always set to 255 in new zserv.
  79. */
  80. uint8_t version;
  81. #define ZSERV_VERSION 1
  82. uint16_t command;
  83. };
  84. /* Zebra IPv4 route message API. */
  85. struct zapi_ipv4
  86. {
  87. u_char type;
  88. u_char flags;
  89. u_char message;
  90. u_char nexthop_num;
  91. struct in_addr **nexthop;
  92. u_char ifindex_num;
  93. unsigned int *ifindex;
  94. u_char distance;
  95. u_int32_t metric;
  96. };
  97. /* Prototypes of zebra client service functions. */
  98. extern struct zclient *zclient_new (void);
  99. extern void zclient_init (struct zclient *, int);
  100. extern int zclient_start (struct zclient *);
  101. extern void zclient_stop (struct zclient *);
  102. extern void zclient_reset (struct zclient *);
  103. extern void zclient_free (struct zclient *);
  104. /* Get TCP socket connection to zebra daemon at loopback address. */
  105. extern int zclient_socket (void);
  106. /* Get unix stream socket connection to zebra daemon at given path. */
  107. extern int zclient_socket_un (const char *);
  108. /* Send redistribute command to zebra daemon. Do not update zclient state. */
  109. extern int zebra_redistribute_send (int command, struct zclient *, int type);
  110. /* If state has changed, update state and call zebra_redistribute_send. */
  111. extern void zclient_redistribute (int command, struct zclient *, int type);
  112. /* If state has changed, update state and send the command to zebra. */
  113. extern void zclient_redistribute_default (int command, struct zclient *);
  114. /* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
  115. Returns 0 for success or -1 on an I/O error. */
  116. extern int zclient_send_message(struct zclient *);
  117. /* create header for command, length to be filled in by user later */
  118. extern void zclient_create_header (struct stream *, uint16_t);
  119. extern struct interface *zebra_interface_add_read (struct stream *);
  120. extern struct interface *zebra_interface_state_read (struct stream *s);
  121. extern struct connected *zebra_interface_address_read (int, struct stream *);
  122. extern void zebra_interface_if_set_value (struct stream *, struct interface *);
  123. extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
  124. extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *,
  125. struct zapi_ipv4 *);
  126. #ifdef HAVE_IPV6
  127. /* IPv6 prefix add and delete function prototype. */
  128. struct zapi_ipv6
  129. {
  130. u_char type;
  131. u_char flags;
  132. u_char message;
  133. u_char nexthop_num;
  134. struct in6_addr **nexthop;
  135. u_char ifindex_num;
  136. unsigned int *ifindex;
  137. u_char distance;
  138. u_int32_t metric;
  139. };
  140. extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
  141. struct prefix_ipv6 *p, struct zapi_ipv6 *api);
  142. #endif /* HAVE_IPV6 */
  143. #endif /* _ZEBRA_ZCLIENT_H */