]> git.proxmox.com Git - mirror_frr.git/blob - ospfd/ospf_apiserver.h
Merge pull request #12438 from proelbtn/fix-#12349
[mirror_frr.git] / ospfd / ospf_apiserver.h
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 along
18 * with this program; see the file COPYING; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 #ifndef _OSPF_APISERVER_H
23 #define _OSPF_APISERVER_H
24
25 #include <zebra.h>
26 #include "ospf_api.h"
27 #include "ospf_lsdb.h"
28
29 /* List of opaque types that application registered */
30 struct registered_opaque_type {
31 uint8_t lsa_type;
32 uint8_t opaque_type;
33 };
34
35
36 /* Server instance for each accepted client connection. */
37 struct ospf_apiserver {
38 /* Socket connections for synchronous commands and asynchronous
39 notifications */
40 int fd_sync; /* synchronous requests */
41 struct sockaddr_in peer_sync;
42
43 int fd_async; /* asynchronous notifications */
44 struct sockaddr_in peer_async;
45
46 /* List of all opaque types that application registers to use. Using
47 a single connection with the OSPF daemon, multiple
48 <lsa,opaque_type> pairs can be registered. However, each
49 combination can only be registered once by all applications. */
50 struct list *opaque_types; /* of type registered_opaque_type */
51
52 /* Temporary storage for LSA instances to be refreshed. */
53 struct ospf_lsdb reserve;
54
55 /* Sync reachable routers */
56 bool reachable_sync;
57
58 /* filter for LSA update/delete notifies */
59 struct lsa_filter_type *filter;
60
61 /* Fifo buffers for outgoing messages */
62 struct msg_fifo *out_sync_fifo;
63 struct msg_fifo *out_async_fifo;
64
65 /* Read and write threads */
66 struct thread *t_sync_read;
67 #ifdef USE_ASYNC_READ
68 struct thread *t_async_read;
69 #endif /* USE_ASYNC_READ */
70 struct thread *t_sync_write;
71 struct thread *t_async_write;
72 };
73
74 enum ospf_apiserver_event {
75 OSPF_APISERVER_ACCEPT,
76 OSPF_APISERVER_SYNC_READ,
77 #ifdef USE_ASYNC_READ
78 OSPF_APISERVER_ASYNC_READ,
79 #endif /* USE_ASYNC_READ */
80 OSPF_APISERVER_SYNC_WRITE,
81 OSPF_APISERVER_ASYNC_WRITE
82 };
83
84 /* -----------------------------------------------------------
85 * Following are functions to manage client connections.
86 * -----------------------------------------------------------
87 */
88
89 extern unsigned short ospf_apiserver_getport(void);
90 extern int ospf_apiserver_init(void);
91 extern void ospf_apiserver_term(void);
92 extern struct ospf_apiserver *ospf_apiserver_new(int fd_sync, int fd_async);
93 extern void ospf_apiserver_free(struct ospf_apiserver *apiserv);
94 extern void ospf_apiserver_event(enum ospf_apiserver_event event, int fd,
95 struct ospf_apiserver *apiserv);
96 extern int ospf_apiserver_serv_sock_family(unsigned short port, int family);
97 extern void ospf_apiserver_accept(struct thread *thread);
98 extern void ospf_apiserver_read(struct thread *thread);
99 extern void ospf_apiserver_sync_write(struct thread *thread);
100 extern void ospf_apiserver_async_write(struct thread *thread);
101 extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv,
102 uint32_t seqnr, uint8_t rc);
103
104 /* -----------------------------------------------------------
105 * Following are message handler functions
106 * -----------------------------------------------------------
107 */
108
109 extern int ospf_apiserver_lsa9_originator(void *arg);
110 extern int ospf_apiserver_lsa10_originator(void *arg);
111 extern int ospf_apiserver_lsa11_originator(void *arg);
112
113 extern void ospf_apiserver_clients_notify_all(struct msg *msg);
114
115 extern void
116 ospf_apiserver_clients_notify_ready_type9(struct ospf_interface *oi);
117 extern void ospf_apiserver_clients_notify_ready_type10(struct ospf_area *area);
118 extern void ospf_apiserver_clients_notify_ready_type11(struct ospf *top);
119
120 extern void ospf_apiserver_clients_notify_new_if(struct ospf_interface *oi);
121 extern void ospf_apiserver_clients_notify_del_if(struct ospf_interface *oi);
122 extern void ospf_apiserver_clients_notify_ism_change(struct ospf_interface *oi);
123 extern void ospf_apiserver_clients_notify_nsm_change(struct ospf_neighbor *nbr);
124 extern void
125 ospf_apiserver_clients_notify_router_id_change(struct in_addr router_id);
126
127 extern int ospf_apiserver_is_ready_type9(struct ospf_interface *oi);
128 extern int ospf_apiserver_is_ready_type10(struct ospf_area *area);
129 extern int ospf_apiserver_is_ready_type11(struct ospf *ospf);
130
131 extern void ospf_apiserver_notify_ready_type9(struct ospf_apiserver *apiserv);
132 extern void ospf_apiserver_notify_ready_type10(struct ospf_apiserver *apiserv);
133 extern void ospf_apiserver_notify_ready_type11(struct ospf_apiserver *apiserv);
134
135 extern int ospf_apiserver_handle_msg(struct ospf_apiserver *apiserv,
136 struct msg *msg);
137 extern int
138 ospf_apiserver_handle_register_opaque_type(struct ospf_apiserver *apiserv,
139 struct msg *msg);
140 extern int
141 ospf_apiserver_handle_unregister_opaque_type(struct ospf_apiserver *apiserv,
142 struct msg *msg);
143 extern int ospf_apiserver_handle_register_event(struct ospf_apiserver *apiserv,
144 struct msg *msg);
145 extern int
146 ospf_apiserver_handle_originate_request(struct ospf_apiserver *apiserv,
147 struct msg *msg);
148 extern int ospf_apiserver_handle_delete_request(struct ospf_apiserver *apiserv,
149 struct msg *msg);
150 extern int ospf_apiserver_handle_sync_lsdb(struct ospf_apiserver *apiserv,
151 struct msg *msg);
152 extern int ospf_apiserver_handle_sync_reachable(struct ospf_apiserver *apiserv,
153 struct msg *msg);
154 extern int ospf_apiserver_handle_sync_ism(struct ospf_apiserver *apiserv,
155 struct msg *msg);
156 extern int ospf_apiserver_handle_sync_nsm(struct ospf_apiserver *apiserv,
157 struct msg *msg);
158 extern int ospf_apiserver_handle_sync_router_id(struct ospf_apiserver *apiserv,
159 struct msg *msg);
160
161 extern void ospf_apiserver_notify_reachable(struct route_table *ort,
162 struct route_table *nrt);
163
164 /* -----------------------------------------------------------
165 * Following are functions for LSA origination/deletion
166 * -----------------------------------------------------------
167 */
168
169 extern int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserver,
170 uint8_t lsa_type,
171 uint8_t opaque_type);
172 extern int
173 ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserver,
174 uint8_t lsa_type, uint8_t opaque_type);
175 extern struct ospf_lsa *
176 ospf_apiserver_opaque_lsa_new(struct ospf_area *area, struct ospf_interface *oi,
177 struct lsa_header *protolsa);
178 extern struct ospf_interface *
179 ospf_apiserver_if_lookup_by_addr(struct in_addr address);
180 extern struct ospf_interface *
181 ospf_apiserver_if_lookup_by_ifp(struct interface *ifp);
182 extern int ospf_apiserver_originate1(struct ospf_lsa *lsa,
183 struct ospf_lsa *old);
184 extern void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa *lsa);
185
186
187 /* -----------------------------------------------------------
188 * Following are callback functions to handle opaque types
189 * -----------------------------------------------------------
190 */
191
192 extern int ospf_apiserver_new_if(struct interface *ifp);
193 extern int ospf_apiserver_del_if(struct interface *ifp);
194 extern void ospf_apiserver_ism_change(struct ospf_interface *oi,
195 int old_status);
196 extern void ospf_apiserver_nsm_change(struct ospf_neighbor *nbr,
197 int old_status);
198 extern void ospf_apiserver_config_write_router(struct vty *vty);
199 extern void ospf_apiserver_config_write_if(struct vty *vty,
200 struct interface *ifp);
201 extern void ospf_apiserver_show_info(struct vty *vty, struct json_object *json,
202 struct ospf_lsa *lsa);
203 extern int ospf_ospf_apiserver_lsa_originator(void *arg);
204 extern struct ospf_lsa *ospf_apiserver_lsa_refresher(struct ospf_lsa *lsa);
205 extern void ospf_apiserver_flush_opaque_lsa(struct ospf_apiserver *apiserv,
206 uint8_t lsa_type,
207 uint8_t opaque_type);
208
209 /* -----------------------------------------------------------
210 * Following are hooks when LSAs are updated or deleted
211 * -----------------------------------------------------------
212 */
213
214
215 /* Hooks that are invoked from ospf opaque module */
216
217 extern int ospf_apiserver_lsa_update(struct ospf_lsa *lsa);
218 extern int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa);
219
220 #endif /* _OSPF_APISERVER_H */