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