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