zclient.h 6.0 KB

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