zclient.h 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214
  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 (*ipv4_route_add) (int, struct zclient *, uint16_t, vrf_id_t);
  71. int (*ipv4_route_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  72. int (*ipv6_route_add) (int, struct zclient *, uint16_t, vrf_id_t);
  73. int (*ipv6_route_delete) (int, struct zclient *, uint16_t, vrf_id_t);
  74. };
  75. /* Zebra API message flag. */
  76. #define ZAPI_MESSAGE_NEXTHOP 0x01
  77. #define ZAPI_MESSAGE_IFINDEX 0x02
  78. #define ZAPI_MESSAGE_DISTANCE 0x04
  79. #define ZAPI_MESSAGE_METRIC 0x08
  80. /* Zserv protocol message header */
  81. struct zserv_header
  82. {
  83. uint16_t length;
  84. uint8_t marker; /* corresponds to command field in old zserv
  85. * always set to 255 in new zserv.
  86. */
  87. uint8_t version;
  88. #define ZSERV_VERSION 3
  89. vrf_id_t vrf_id;
  90. uint16_t command;
  91. };
  92. /* Zebra IPv4 route message API. */
  93. struct zapi_ipv4
  94. {
  95. u_char type;
  96. u_char flags;
  97. u_char message;
  98. safi_t safi;
  99. u_char nexthop_num;
  100. struct in_addr **nexthop;
  101. u_char ifindex_num;
  102. unsigned int *ifindex;
  103. u_char distance;
  104. u_int32_t metric;
  105. vrf_id_t vrf_id;
  106. };
  107. /* Prototypes of zebra client service functions. */
  108. extern struct zclient *zclient_new (struct thread_master *);
  109. extern void zclient_init (struct zclient *, int);
  110. extern int zclient_start (struct zclient *);
  111. extern void zclient_stop (struct zclient *);
  112. extern void zclient_reset (struct zclient *);
  113. extern void zclient_free (struct zclient *);
  114. extern int zclient_socket_connect (struct zclient *);
  115. extern void zclient_serv_path_set (char *path);
  116. extern const char *zclient_serv_path_get (void);
  117. extern void zclient_send_requests (struct zclient *, vrf_id_t);
  118. /* Send redistribute command to zebra daemon. Do not update zclient state. */
  119. extern int zebra_redistribute_send (int command, struct zclient *, int type,
  120. vrf_id_t vrf_id);
  121. /* If state has changed, update state and call zebra_redistribute_send. */
  122. extern void zclient_redistribute (int command, struct zclient *, int type,
  123. vrf_id_t vrf_id);
  124. /* If state has changed, update state and send the command to zebra. */
  125. extern void zclient_redistribute_default (int command, struct zclient *,
  126. vrf_id_t vrf_id);
  127. /* Send the message in zclient->obuf to the zebra daemon (or enqueue it).
  128. Returns 0 for success or -1 on an I/O error. */
  129. extern int zclient_send_message(struct zclient *);
  130. /* create header for command, length to be filled in by user later */
  131. extern void zclient_create_header (struct stream *, uint16_t, vrf_id_t);
  132. extern int zclient_read_header (struct stream *s, int sock, u_int16_t *size,
  133. u_char *marker, u_char *version,
  134. u_int16_t *vrf_id, u_int16_t *cmd);
  135. extern struct interface *zebra_interface_add_read (struct stream *,
  136. vrf_id_t);
  137. extern struct interface *zebra_interface_state_read (struct stream *,
  138. vrf_id_t);
  139. extern struct connected *zebra_interface_address_read (int, struct stream *,
  140. vrf_id_t);
  141. extern void zebra_interface_if_set_value (struct stream *, struct interface *);
  142. extern void zebra_router_id_update_read (struct stream *s, struct prefix *rid);
  143. extern int zapi_ipv4_route (u_char, struct zclient *, struct prefix_ipv4 *,
  144. struct zapi_ipv4 *);
  145. #ifdef HAVE_IPV6
  146. /* IPv6 prefix add and delete function prototype. */
  147. struct zapi_ipv6
  148. {
  149. u_char type;
  150. u_char flags;
  151. u_char message;
  152. safi_t safi;
  153. u_char nexthop_num;
  154. struct in6_addr **nexthop;
  155. u_char ifindex_num;
  156. unsigned int *ifindex;
  157. u_char distance;
  158. u_int32_t metric;
  159. vrf_id_t vrf_id;
  160. };
  161. extern int zapi_ipv6_route (u_char cmd, struct zclient *zclient,
  162. struct prefix_ipv6 *p, struct zapi_ipv6 *api);
  163. #endif /* HAVE_IPV6 */
  164. #endif /* _ZEBRA_ZCLIENT_H */