]>
Commit | Line | Data |
---|---|---|
acddc0ed | 1 | // SPDX-License-Identifier: GPL-2.0-or-later |
2d33f157 | 2 | /* |
3 | * Server side of OSPF API. | |
4 | * Copyright (C) 2001, 2002 Ralph Keller | |
2d33f157 | 5 | */ |
6 | ||
7 | #ifndef _OSPF_APISERVER_H | |
8 | #define _OSPF_APISERVER_H | |
9 | ||
149491af CH |
10 | #include <zebra.h> |
11 | #include "ospf_api.h" | |
12 | #include "ospf_lsdb.h" | |
13 | ||
2d33f157 | 14 | /* List of opaque types that application registered */ |
d62a17ae | 15 | struct registered_opaque_type { |
d7c0a89a QY |
16 | uint8_t lsa_type; |
17 | uint8_t opaque_type; | |
2d33f157 | 18 | }; |
19 | ||
20 | ||
21 | /* Server instance for each accepted client connection. */ | |
d62a17ae | 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 | ||
149491af CH |
40 | /* Sync reachable routers */ |
41 | bool reachable_sync; | |
42 | ||
d62a17ae | 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; | |
2d33f157 | 52 | #ifdef USE_ASYNC_READ |
d62a17ae | 53 | struct thread *t_async_read; |
2d33f157 | 54 | #endif /* USE_ASYNC_READ */ |
d62a17ae | 55 | struct thread *t_sync_write; |
56 | struct thread *t_async_write; | |
2d33f157 | 57 | }; |
58 | ||
14416b1f | 59 | enum ospf_apiserver_event { |
d62a17ae | 60 | OSPF_APISERVER_ACCEPT, |
61 | OSPF_APISERVER_SYNC_READ, | |
2d33f157 | 62 | #ifdef USE_ASYNC_READ |
d62a17ae | 63 | OSPF_APISERVER_ASYNC_READ, |
2d33f157 | 64 | #endif /* USE_ASYNC_READ */ |
d62a17ae | 65 | OSPF_APISERVER_SYNC_WRITE, |
66 | OSPF_APISERVER_ASYNC_WRITE | |
2d33f157 | 67 | }; |
68 | ||
69 | /* ----------------------------------------------------------- | |
78dfa0c7 | 70 | * Following are functions to manage client connections. |
2d33f157 | 71 | * ----------------------------------------------------------- |
72 | */ | |
73 | ||
d62a17ae | 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); | |
14416b1f | 79 | extern void ospf_apiserver_event(enum ospf_apiserver_event event, int fd, |
d62a17ae | 80 | struct ospf_apiserver *apiserv); |
81 | extern int ospf_apiserver_serv_sock_family(unsigned short port, int family); | |
cc9f21da DS |
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); | |
d62a17ae | 86 | extern int ospf_apiserver_send_reply(struct ospf_apiserver *apiserv, |
d7c0a89a | 87 | uint32_t seqnr, uint8_t rc); |
2d33f157 | 88 | |
89 | /* ----------------------------------------------------------- | |
78dfa0c7 | 90 | * Following are message handler functions |
2d33f157 | 91 | * ----------------------------------------------------------- |
92 | */ | |
93 | ||
d62a17ae | 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); | |
44038c7a CH |
109 | extern void |
110 | ospf_apiserver_clients_notify_router_id_change(struct in_addr router_id); | |
d62a17ae | 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, | |
2d33f157 | 121 | struct msg *msg); |
d62a17ae | 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); | |
149491af CH |
137 | extern int ospf_apiserver_handle_sync_reachable(struct ospf_apiserver *apiserv, |
138 | struct msg *msg); | |
97355a6d CH |
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); | |
44038c7a CH |
143 | extern int ospf_apiserver_handle_sync_router_id(struct ospf_apiserver *apiserv, |
144 | struct msg *msg); | |
2d33f157 | 145 | |
149491af CH |
146 | extern void ospf_apiserver_notify_reachable(struct route_table *ort, |
147 | struct route_table *nrt); | |
97355a6d | 148 | |
2d33f157 | 149 | /* ----------------------------------------------------------- |
78dfa0c7 | 150 | * Following are functions for LSA origination/deletion |
2d33f157 | 151 | * ----------------------------------------------------------- |
152 | */ | |
153 | ||
d62a17ae | 154 | extern int ospf_apiserver_register_opaque_type(struct ospf_apiserver *apiserver, |
d7c0a89a QY |
155 | uint8_t lsa_type, |
156 | uint8_t opaque_type); | |
d62a17ae | 157 | extern int |
158 | ospf_apiserver_unregister_opaque_type(struct ospf_apiserver *apiserver, | |
d7c0a89a | 159 | uint8_t lsa_type, uint8_t opaque_type); |
d62a17ae | 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); | |
5349121b CH |
167 | extern int ospf_apiserver_originate1(struct ospf_lsa *lsa, |
168 | struct ospf_lsa *old); | |
d62a17ae | 169 | extern void ospf_apiserver_flood_opaque_lsa(struct ospf_lsa *lsa); |
2d33f157 | 170 | |
171 | ||
172 | /* ----------------------------------------------------------- | |
78dfa0c7 | 173 | * Following are callback functions to handle opaque types |
2d33f157 | 174 | * ----------------------------------------------------------- |
175 | */ | |
176 | ||
d62a17ae | 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); | |
3e63092b RW |
186 | extern void ospf_apiserver_show_info(struct vty *vty, struct json_object *json, |
187 | struct ospf_lsa *lsa); | |
d62a17ae | 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, | |
d7c0a89a QY |
191 | uint8_t lsa_type, |
192 | uint8_t opaque_type); | |
2d33f157 | 193 | |
194 | /* ----------------------------------------------------------- | |
78dfa0c7 | 195 | * Following are hooks when LSAs are updated or deleted |
2d33f157 | 196 | * ----------------------------------------------------------- |
197 | */ | |
198 | ||
199 | ||
200 | /* Hooks that are invoked from ospf opaque module */ | |
201 | ||
d62a17ae | 202 | extern int ospf_apiserver_lsa_update(struct ospf_lsa *lsa); |
203 | extern int ospf_apiserver_lsa_delete(struct ospf_lsa *lsa); | |
2d33f157 | 204 | |
2d33f157 | 205 | #endif /* _OSPF_APISERVER_H */ |