ospf_apiserver.h 7.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. /*
  2. * Server side of OSPF API.
  3. * Copyright (C) 2001, 2002 Ralph Keller
  4. *
  5. * This file is part of GNU Zebra.
  6. *
  7. * GNU Zebra is free software; you can redistribute it and/or modify
  8. * it under the terms of the GNU General Public License as published
  9. * by the Free Software Foundation; either version 2, or (at your
  10. * option) any later version.
  11. *
  12. * GNU Zebra is distributed in the hope that it will be useful, but
  13. * WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU General Public License
  18. * along with GNU Zebra; see the file COPYING. If not, write to the
  19. * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
  20. * Boston, MA 02111-1307, USA.
  21. */
  22. #ifndef _OSPF_APISERVER_H
  23. #define _OSPF_APISERVER_H
  24. /* MTYPE definition is not reflected to "memory.h". */
  25. #define MTYPE_OSPF_APISERVER MTYPE_TMP
  26. #define MTYPE_OSPF_APISERVER_MSGFILTER MTYPE_TMP
  27. /* List of opaque types that application registered */
  28. struct registered_opaque_type
  29. {
  30. u_char lsa_type;
  31. u_char opaque_type;
  32. };
  33. /* Server instance for each accepted client connection. */
  34. struct ospf_apiserver
  35. {
  36. /* Socket connections for synchronous commands and asynchronous
  37. notifications */
  38. int fd_sync; /* synchronous requests */
  39. struct sockaddr_in peer_sync;
  40. int fd_async; /* asynchronous notifications */
  41. struct sockaddr_in peer_async;
  42. /* List of all opaque types that application registers to use. Using
  43. a single connection with the OSPF daemon, multiple
  44. <lsa,opaque_type> pairs can be registered. However, each
  45. combination can only be registered once by all applications. */
  46. struct list *opaque_types; /* of type registered_opaque_type */
  47. /* Temporary storage for LSA instances to be refreshed. */
  48. struct ospf_lsdb reserve;
  49. /* filter for LSA update/delete notifies */
  50. struct lsa_filter_type *filter;
  51. /* Fifo buffers for outgoing messages */
  52. struct msg_fifo *out_sync_fifo;
  53. struct msg_fifo *out_async_fifo;
  54. /* Read and write threads */
  55. struct thread *t_sync_read;
  56. #ifdef USE_ASYNC_READ
  57. struct thread *t_async_read;
  58. #endif /* USE_ASYNC_READ */
  59. struct thread *t_sync_write;
  60. struct thread *t_async_write;
  61. };
  62. enum event
  63. {
  64. OSPF_APISERVER_ACCEPT,
  65. OSPF_APISERVER_SYNC_READ,
  66. #ifdef USE_ASYNC_READ
  67. OSPF_APISERVER_ASYNC_READ,
  68. #endif /* USE_ASYNC_READ */
  69. OSPF_APISERVER_SYNC_WRITE,
  70. OSPF_APISERVER_ASYNC_WRITE
  71. };
  72. /* -----------------------------------------------------------
  73. * Followings are functions to manage client connections.
  74. * -----------------------------------------------------------
  75. */
  76. extern unsigned short ospf_apiserver_getport (void);
  77. extern int ospf_apiserver_init (void);
  78. extern void ospf_apiserver_term (void);
  79. extern struct ospf_apiserver *ospf_apiserver_new (int fd_sync, int fd_async);
  80. extern void ospf_apiserver_free (struct ospf_apiserver *apiserv);
  81. extern void ospf_apiserver_event (enum event event, int fd,
  82. struct ospf_apiserver *apiserv);
  83. extern int ospf_apiserver_serv_sock_family (unsigned short port, int family);
  84. extern int ospf_apiserver_accept (struct thread *thread);
  85. extern int ospf_apiserver_read (struct thread *thread);
  86. extern int ospf_apiserver_sync_write (struct thread *thread);
  87. extern int ospf_apiserver_async_write (struct thread *thread);
  88. extern int ospf_apiserver_send_reply (struct ospf_apiserver *apiserv,
  89. u_int32_t seqnr, u_char rc);
  90. /* -----------------------------------------------------------
  91. * Followings are message handler functions
  92. * -----------------------------------------------------------
  93. */
  94. extern int ospf_apiserver_lsa9_originator (void *arg);
  95. extern int ospf_apiserver_lsa10_originator (void *arg);
  96. extern int ospf_apiserver_lsa11_originator (void *arg);
  97. extern void ospf_apiserver_clients_notify_all (struct msg *msg);
  98. extern void ospf_apiserver_clients_notify_ready_type9 (struct ospf_interface *oi);
  99. extern void ospf_apiserver_clients_notify_ready_type10 (struct ospf_area *area);
  100. extern void ospf_apiserver_clients_notify_ready_type11 (struct ospf *top);
  101. extern void ospf_apiserver_clients_notify_new_if (struct ospf_interface *oi);
  102. extern void ospf_apiserver_clients_notify_del_if (struct ospf_interface *oi);
  103. extern void ospf_apiserver_clients_notify_ism_change (struct ospf_interface *oi);
  104. extern void ospf_apiserver_clients_notify_nsm_change (struct ospf_neighbor *nbr);
  105. extern int ospf_apiserver_is_ready_type9 (struct ospf_interface *oi);
  106. extern int ospf_apiserver_is_ready_type10 (struct ospf_area *area);
  107. extern int ospf_apiserver_is_ready_type11 (struct ospf *ospf);
  108. extern void ospf_apiserver_notify_ready_type9 (struct ospf_apiserver *apiserv);
  109. extern void ospf_apiserver_notify_ready_type10 (struct ospf_apiserver *apiserv);
  110. extern void ospf_apiserver_notify_ready_type11 (struct ospf_apiserver *apiserv);
  111. extern int ospf_apiserver_handle_msg (struct ospf_apiserver *apiserv,
  112. struct msg *msg);
  113. extern int ospf_apiserver_handle_register_opaque_type (struct ospf_apiserver
  114. *apiserv, struct msg *msg);
  115. extern int ospf_apiserver_handle_unregister_opaque_type (struct ospf_apiserver
  116. *apiserv, struct msg *msg);
  117. extern int ospf_apiserver_handle_register_event (struct ospf_apiserver *apiserv,
  118. struct msg *msg);
  119. extern int ospf_apiserver_handle_originate_request (struct ospf_apiserver *apiserv,
  120. struct msg *msg);
  121. extern int ospf_apiserver_handle_delete_request (struct ospf_apiserver *apiserv,
  122. struct msg *msg);
  123. extern int ospf_apiserver_handle_sync_lsdb (struct ospf_apiserver *apiserv,
  124. struct msg *msg);
  125. /* -----------------------------------------------------------
  126. * Followings are functions for LSA origination/deletion
  127. * -----------------------------------------------------------
  128. */
  129. extern int ospf_apiserver_register_opaque_type (struct ospf_apiserver *apiserver,
  130. u_char lsa_type, u_char opaque_type);
  131. extern int ospf_apiserver_unregister_opaque_type (struct ospf_apiserver *apiserver,
  132. u_char lsa_type,
  133. u_char opaque_type);
  134. extern struct ospf_lsa *ospf_apiserver_opaque_lsa_new (struct ospf_area *area,
  135. struct ospf_interface *oi,
  136. struct lsa_header *protolsa);
  137. extern struct ospf_interface *ospf_apiserver_if_lookup_by_addr (struct in_addr
  138. address);
  139. extern struct ospf_interface *ospf_apiserver_if_lookup_by_ifp (struct interface
  140. *ifp);
  141. extern int ospf_apiserver_originate1 (struct ospf_lsa *lsa);
  142. extern void ospf_apiserver_flood_opaque_lsa (struct ospf_lsa *lsa);
  143. /* -----------------------------------------------------------
  144. * Followings are callback functions to handle opaque types
  145. * -----------------------------------------------------------
  146. */
  147. extern int ospf_apiserver_new_if (struct interface *ifp);
  148. extern int ospf_apiserver_del_if (struct interface *ifp);
  149. extern void ospf_apiserver_ism_change (struct ospf_interface *oi, int old_status);
  150. extern void ospf_apiserver_nsm_change (struct ospf_neighbor *nbr, int old_status);
  151. extern void ospf_apiserver_config_write_router (struct vty *vty);
  152. extern void ospf_apiserver_config_write_if (struct vty *vty, struct interface *ifp);
  153. extern void ospf_apiserver_show_info (struct vty *vty, struct ospf_lsa *lsa);
  154. extern int ospf_ospf_apiserver_lsa_originator (void *arg);
  155. extern struct ospf_lsa *ospf_apiserver_lsa_refresher (struct ospf_lsa *lsa);
  156. extern void ospf_apiserver_flush_opaque_lsa (struct ospf_apiserver *apiserv,
  157. u_char lsa_type, u_char opaque_type);
  158. /* -----------------------------------------------------------
  159. * Followings are hooks when LSAs are updated or deleted
  160. * -----------------------------------------------------------
  161. */
  162. /* Hooks that are invoked from ospf opaque module */
  163. extern int ospf_apiserver_lsa_update (struct ospf_lsa *lsa);
  164. extern int ospf_apiserver_lsa_delete (struct ospf_lsa *lsa);
  165. extern void ospf_apiserver_clients_lsa_change_notify (u_char msgtype,
  166. struct ospf_lsa *lsa);
  167. #endif /* _OSPF_APISERVER_H */