zclient.h 6.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230
  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 zapi_ipv{4,6}. */
  24. #include "prefix.h"
  25. /* For struct interface and struct connected. */
  26. #include "if.h"
  27. /* For vrf_bitmap_t. */
  28. #include "vrf.h"
  29. /* For input/output buffer to zebra. */
  30. #define ZEBRA_MAX_PACKET_SIZ 4096
  31. /* Zebra header size. */
  32. #define ZEBRA_HEADER_SIZE 8
  33. /* Structure for the zebra client. */
  34. struct zclient
  35. {
  36. /* The thread master we schedule ourselves on */
  37. struct thread_master *master;
  38. /* Socket to zebra daemon. */
  39. int sock;
  40. /* Flag of communication to zebra is enabled or not. Default is on.
  41. This flag is disabled by `no router zebra' statement. */
  42. int enable;
  43. /* Connection failure count. */
  44. int fail;
  45. /* Input buffer for zebra message. */
  46. struct stream *ibuf;
  47. /* Output buffer for zebra message. */
  48. struct stream *obuf;
  49. /* Buffer of data waiting to be written to zebra. */
  50. struct buffer *wb;
  51. /* Read and connect thread. */
  52. struct thread *t_read;
  53. struct thread *t_connect;
  54. /* Thread to write buffered data to zebra. */
  55. struct thread *t_write;
  56. /* Redistribute information. */
  57. u_char redist_default;
  58. vrf_bitmap_t redist[ZEBRA_ROUTE_MAX];
  59. /* Redistribute defauilt. */
  60. vrf_bitmap_t default_information;
  61. /* Pointer to the callback functions. */
  62. void (*zebra_connected) (struct zclient *);
  63. int (*router_id_update) (int, struct zclient *, uint16_t, vrf_id_t);
  64. int (*interface_add) (int, struct zclient *, uint16_t, vrf_id_t);
  65. int (*interface_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  66. int (*interface_up) (int, struct zclient *, uint16_t, vrf_id_t);
  67. int (*interface_down) (int, struct zclient *, uint16_t, vrf_id_t);
  68. int (*interface_address_add) (int, struct zclient *, uint16_t, vrf_id_t);
  69. int (*interface_address_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  70. int (*interface_link_params) (int, struct zclient *, uint16_t);
  71. int (*ipv4_route_add) (int, struct zclient *, uint16_t, vrf_id_t);
  72. int (*ipv4_route_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  73. int (*ipv6_route_add) (int, struct zclient *, uint16_t, vrf_id_t);
  74. int (*ipv6_route_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  75. int (*nexthop_update) (int, struct zclient *, uint16_t, vrf_id_t);
  76. };
  77. /* Zebra API message flag. */
  78. #define ZAPI_MESSAGE_NEXTHOP 0x01
  79. #define ZAPI_MESSAGE_IFINDEX 0x02
  80. #define ZAPI_MESSAGE_DISTANCE 0x04
  81. #define ZAPI_MESSAGE_METRIC 0x08
  82. #define ZAPI_MESSAGE_MTU 0x10
  83. #define ZAPI_MESSAGE_TAG 0x20
  84. /* Zserv protocol message header */
  85. struct zserv_header
  86. {
  87. uint16_t length;
  88. uint8_t marker; /* corresponds to command field in old zserv
  89. * always set to 255 in new zserv.
  90. */
  91. uint8_t version;
  92. #define ZSERV_VERSION 3
  93. vrf_id_t vrf_id;
  94. uint16_t command;
  95. };
  96. /* Zebra IPv4 route message API. */
  97. struct zapi_ipv4
  98. {
  99. u_char type;
  100. u_char flags;
  101. u_char message;
  102. safi_t safi;
  103. u_char nexthop_num;
  104. struct in_addr **nexthop;
  105. u_char ifindex_num;
  106. ifindex_t *ifindex;
  107. u_char distance;
  108. route_tag_t tag;
  109. u_int32_t metric;
  110. u_int32_t mtu;
  111. vrf_id_t vrf_id;
  112. };
  113. /* Prototypes of zebra client service functions. */
  114. extern struct zclient *zclient_new (struct thread_master *);
  115. extern void zclient_init (struct zclient *, int);
  116. extern int zclient_start (struct zclient *);
  117. extern void zclient_stop (struct zclient *);
  118. extern void zclient_reset (struct zclient *);
  119. extern void zclient_free (struct zclient *);
  120. extern int zclient_socket_connect (struct zclient *);
  121. extern void zclient_serv_path_set (char *path);
  122. extern const char *zclient_serv_path_get (void);
  123. extern void zclient_send_requests (struct zclient *, vrf_id_t);
  124. /* Send redistribute command to zebra daemon. Do not update zclient state. */
  125. extern int zebra_redistribute_send (int command, struct zclient *, int type,
  126. vrf_id_t vrf_id);
  127. /* If state has changed, update state and call zebra_redistribute_send. */
  128. extern void zclient_redistribute (int command, struct zclient *, int type,
  129. vrf_id_t vrf_id);
  130. /* If state has changed, update state and send the command to zebra. */
  131. extern void zclient_redistribute_default (int command, struct zclient *,
  132. vrf_id_t vrf_id);
  133. /* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
  134. Returns 0 for success or -1 on an I/O error. */
  135. extern int zclient_send_message(struct zclient *);
  136. /* create header for command, length to be filled in by user later */
  137. extern void zclient_create_header (struct stream *, uint16_t, vrf_id_t);
  138. extern int zclient_read_header (struct stream *s, int sock, u_int16_t *size,
  139. u_char *marker, u_char *version,
  140. u_int16_t *vrf_id, u_int16_t *cmd);
  141. extern struct interface *zebra_interface_add_read (struct stream *,
  142. vrf_id_t);
  143. extern struct interface *zebra_interface_state_read (struct stream *,
  144. vrf_id_t);
  145. extern struct connected *zebra_interface_address_read (int, struct stream *,
  146. vrf_id_t);
  147. extern void zebra_interface_if_set_value (struct stream *, struct interface *);
  148. extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
  149. extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *,
  150. struct zapi_ipv4 *);
  151. extern struct interface *zebra_interface_link_params_read (struct stream *);
  152. extern size_t zebra_interface_link_params_write (struct stream *,
  153. struct interface *);
  154. #ifdef HAVE_IPV6
  155. /* IPv6 prefix add and delete function prototype. */
  156. struct zapi_ipv6
  157. {
  158. u_char type;
  159. u_char flags;
  160. u_char message;
  161. safi_t safi;
  162. u_char nexthop_num;
  163. struct in6_addr **nexthop;
  164. u_char ifindex_num;
  165. ifindex_t *ifindex;
  166. u_char distance;
  167. route_tag_t tag;
  168. u_int32_t metric;
  169. u_int32_t mtu;
  170. vrf_id_t vrf_id;
  171. };
  172. extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
  173. struct prefix_ipv6 *p, struct zapi_ipv6 *api);
  174. #endif /* HAVE_IPV6 */
  175. #endif /* _ZEBRA_ZCLIENT_H */